F-6155: remove redundant wc_ecc_init from ECC raw import wrappers
parent
b95503fbaf
commit
ade193cf93
|
|
@ -1469,11 +1469,6 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1import_1private_1
|
|||
}
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
/* Initialize ECC key structure */
|
||||
ret = wc_ecc_init(ecc);
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_import_private_key_ex(privKey, privKeySz, NULL, 0,
|
||||
ecc, curveId);
|
||||
|
|
@ -1545,10 +1540,6 @@ JNIEXPORT void JNICALL Java_com_wolfssl_wolfcrypt_Ecc_wc_1ecc_1import_1public_1r
|
|||
ret = BAD_FUNC_ARG;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_init(ecc);
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = wc_ecc_import_unsigned(ecc, x, y, NULL, curveId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -441,6 +441,57 @@ public class EccTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eccImportPublicRawVerifiesSignature() {
|
||||
|
||||
/* secp256r1 key pair, x and y are the public point coordinates
|
||||
* from the pubKey used in signatureShouldMatchDecodingKeys */
|
||||
byte[] prvKey = Util.h2b("30770201010420F8CF92"
|
||||
+ "6BBD1E28F1A8ABA1234F3274188850AD7EC7EC92"
|
||||
+ "F88F974DAF568965C7A00A06082A8648CE3D0301"
|
||||
+ "07A1440342000455BFF40F44509A3DCE9BB7F0C5"
|
||||
+ "4DF5707BD4EC248E1980EC5A4CA22403622C9BDA"
|
||||
+ "EFA2351243847616C6569506CC01A9BDF6751A42"
|
||||
+ "F7BDA9B236225FC75D7FB4");
|
||||
|
||||
byte[] x = Util.h2b("55BFF40F44509A3DCE9BB7"
|
||||
+ "F0C54DF5707BD4EC248E1980EC5A4CA22403622C9B");
|
||||
byte[] y = Util.h2b("DAEFA2351243847616C656"
|
||||
+ "9506CC01A9BDF6751A42F7BDA9B236225FC75D7FB4");
|
||||
|
||||
byte[] hash =
|
||||
"Everyone gets Friday off. ecc p".getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
Ecc alice = new Ecc();
|
||||
Ecc bob = new Ecc();
|
||||
|
||||
try {
|
||||
alice.privateKeyDecode(prvKey);
|
||||
|
||||
byte[] signature = null;
|
||||
synchronized (rngLock) {
|
||||
signature = alice.sign(hash, rng);
|
||||
}
|
||||
|
||||
bob.importPublicRaw(x, y, "secp256r1");
|
||||
assertTrue(bob.verify(hash, signature));
|
||||
|
||||
/* coordinate size not matching curve must be rejected */
|
||||
Ecc shortX = new Ecc();
|
||||
try {
|
||||
shortX.importPublicRaw(Arrays.copyOf(x, 16), y, "secp256r1");
|
||||
fail("importPublicRaw with short x coordinate should fail");
|
||||
} catch (WolfCryptException e) {
|
||||
/* expected */
|
||||
} finally {
|
||||
shortX.releaseNativeStruct();
|
||||
}
|
||||
} finally {
|
||||
alice.releaseNativeStruct();
|
||||
bob.releaseNativeStruct();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEccCurveNameFromSpec()
|
||||
throws InvalidAlgorithmParameterException, NoSuchAlgorithmException {
|
||||
|
|
|
|||
Loading…
Reference in New Issue