X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fecdsa%2Fecdsatest.c;h=5315d90dd2c3d26af32c39785554b01b61e373f4;hp=3f284125a2be5b2e52df9f6475a89f42376e116c;hb=8b15c740180725e3e1e71ff619151840cdec46a5;hpb=2b32b2819187564e450539f94d5ae9716a11c757 diff --git a/crypto/ecdsa/ecdsatest.c b/crypto/ecdsa/ecdsatest.c index 3f284125a2..5315d90dd2 100644 --- a/crypto/ecdsa/ecdsatest.c +++ b/crypto/ecdsa/ecdsatest.c @@ -69,10 +69,18 @@ * */ +/* Until the key-gen callbacks are modified to use newer prototypes, we allow + * deprecated functions for openssl-internal code */ +#ifdef OPENSSL_NO_DEPRECATED +#undef OPENSSL_NO_DEPRECATED +#endif + #include #include #include +#include /* To see if OPENSSL_NO_ECDSA is defined */ + #ifdef OPENSSL_NO_ECDSA int main(int argc, char * argv[]) { @@ -87,6 +95,7 @@ int main(int argc, char * argv[]) #include #include #include +#include static const char rnd_seed[] = "string to make the random number generator " "think it has entropy"; @@ -116,7 +125,7 @@ int change_rand(void) fake_rand.status = old_rand->status; /* use own random function */ fake_rand.bytes = fbytes; - fake_rand.pseudorand = fbytes; + fake_rand.pseudorand = old_rand->bytes; /* set new RAND_METHOD */ if (!RAND_set_rand_method(&fake_rand)) return 0; @@ -194,7 +203,7 @@ int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in) /* create the key */ if ((key = EC_KEY_new()) == NULL) goto x962_int_err; - if ((key->group = EC_GROUP_new_by_nid(nid)) == NULL) + if ((key->group = EC_GROUP_new_by_curve_name(nid)) == NULL) goto x962_int_err; if (!EC_KEY_generate_key(key)) goto x962_int_err; @@ -283,7 +292,7 @@ int test_builtin(BIO *out) size_t crv_len = 0, n = 0; EC_KEY *eckey = NULL, *wrong_eckey = NULL; unsigned char digest[20], wrong_digest[20]; - unsigned char *signature; + unsigned char *signature = NULL; unsigned int sig_len; int nid, ret = 0; @@ -320,11 +329,15 @@ int test_builtin(BIO *out) /* now create and verify a signature for every curve */ for (n = 0; n < crv_len; n++) { + unsigned char dirt, offset; + nid = curves[n].nid; + if (nid == NID_ipsec4) + continue; /* create new ecdsa key (== EC_KEY) */ if ((eckey = EC_KEY_new()) == NULL) goto builtin_err; - if ((eckey->group = EC_GROUP_new_by_nid(nid)) == NULL) + if ((eckey->group = EC_GROUP_new_by_curve_name(nid)) == NULL) goto builtin_err; if (EC_GROUP_get_degree(eckey->group) < 160) /* drop the curve */ @@ -343,7 +356,7 @@ int test_builtin(BIO *out) /* create second key */ if ((wrong_eckey = EC_KEY_new()) == NULL) goto builtin_err; - if ((wrong_eckey->group = EC_GROUP_new_by_nid(nid)) == NULL) + if ((wrong_eckey->group = EC_GROUP_new_by_curve_name(nid)) == NULL) goto builtin_err; if (!EC_KEY_generate_key(wrong_eckey)) { @@ -398,9 +411,10 @@ int test_builtin(BIO *out) } BIO_printf(out, "."); BIO_flush(out); - /* modify signature */ - signature[((int)signature[0])%sig_len] ^= - signature[((int)signature[1])%sig_len]; + /* modify a single byte of the signature */ + offset = signature[10] % sig_len; + dirt = signature[11]; + signature[offset] ^= dirt ? dirt : 1; if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) { BIO_printf(out, " failed\n"); @@ -435,7 +449,7 @@ builtin_err: int main(void) { - int ret = 0; + int ret = 1; BIO *out; out = BIO_new_fp(stdout, BIO_NOCLOSE); @@ -463,13 +477,13 @@ int main(void) if (!x9_62_tests(out)) goto err; if (!test_builtin(out)) goto err; - ret = 1; + ret = 0; err: - if (!ret) + if (ret) BIO_printf(out, "\nECDSA test failed\n"); else BIO_printf(out, "\nECDSA test passed\n"); - if (!ret) + if (ret) ERR_print_errors(out); CRYPTO_cleanup_all_ex_data(); ERR_remove_state(0); @@ -477,6 +491,6 @@ err: CRYPTO_mem_leaks(out); if (out != NULL) BIO_free(out); - return(0); + return ret; } #endif