mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8277233: Improve ECDSA signature support
Reviewed-by: ascarpino, ahgross, rhalade
This commit is contained in:
parent
f0f0ddbf6d
commit
e2f8ce9c3f
2 changed files with 14 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -362,7 +362,8 @@ abstract class DSA extends SignatureSpi {
|
||||||
s = new BigInteger(1, s.toByteArray());
|
s = new BigInteger(1, s.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r.compareTo(presetQ) == -1) && (s.compareTo(presetQ) == -1)) {
|
if ((r.compareTo(presetQ) == -1) && (s.compareTo(presetQ) == -1)
|
||||||
|
&& r.signum() > 0 && s.signum() > 0) {
|
||||||
BigInteger w = generateW(presetP, presetQ, presetG, s);
|
BigInteger w = generateW(presetP, presetQ, presetG, s);
|
||||||
BigInteger v = generateV(presetY, presetP, presetQ, presetG, w, r);
|
BigInteger v = generateV(presetY, presetP, presetQ, presetG, w, r);
|
||||||
return v.equals(r);
|
return v.equals(r);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -30,6 +30,7 @@ import sun.security.util.ArrayUtil;
|
||||||
import sun.security.util.math.*;
|
import sun.security.util.math.*;
|
||||||
import static sun.security.ec.ECOperations.IntermediateValueException;
|
import static sun.security.ec.ECOperations.IntermediateValueException;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.security.ProviderException;
|
import java.security.ProviderException;
|
||||||
import java.security.spec.*;
|
import java.security.spec.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -200,7 +201,8 @@ public class ECDSAOperations {
|
||||||
|
|
||||||
IntegerFieldModuloP field = ecOps.getField();
|
IntegerFieldModuloP field = ecOps.getField();
|
||||||
IntegerFieldModuloP orderField = ecOps.getOrderField();
|
IntegerFieldModuloP orderField = ecOps.getOrderField();
|
||||||
int length = (orderField.getSize().bitLength() + 7) / 8;
|
BigInteger mod = orderField.getSize();
|
||||||
|
int length = (mod.bitLength() + 7) / 8;
|
||||||
|
|
||||||
byte[] r;
|
byte[] r;
|
||||||
byte[] s;
|
byte[] s;
|
||||||
|
@ -218,6 +220,13 @@ public class ECDSAOperations {
|
||||||
System.arraycopy(sig, encodeLength, s, length - encodeLength, encodeLength);
|
System.arraycopy(sig, encodeLength, s, length - encodeLength, encodeLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BigInteger rb = new BigInteger(1, r);
|
||||||
|
BigInteger sb = new BigInteger(1, s);
|
||||||
|
if (rb.signum() == 0 || sb.signum() == 0
|
||||||
|
|| rb.compareTo(mod) >= 0 || sb.compareTo(mod) >= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ArrayUtil.reverse(r);
|
ArrayUtil.reverse(r);
|
||||||
ArrayUtil.reverse(s);
|
ArrayUtil.reverse(s);
|
||||||
IntegerModuloP ri = orderField.getElement(r);
|
IntegerModuloP ri = orderField.getElement(r);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue