projects
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Revert my earlier CRYPTO_THREADID commit, I will commit a reworked
[openssl.git]
/
crypto
/
ecdsa
/
ecdsatest.c
diff --git
a/crypto/ecdsa/ecdsatest.c
b/crypto/ecdsa/ecdsatest.c
index d58e9a63f0581183f5cf276b858070836b7757f4..b07e31252b9b39971f126f05f254db4a127c952d 100644
(file)
--- a/
crypto/ecdsa/ecdsatest.c
+++ b/
crypto/ecdsa/ecdsatest.c
@@
-3,7
+3,7
@@
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
* Written by Nils Larsch for the OpenSSL project.
*/
/* ====================================================================
- * Copyright (c) 2000-200
2
The OpenSSL Project. All rights reserved.
+ * Copyright (c) 2000-200
5
The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@
-69,12
+69,6
@@
*
*/
*
*/
-/* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-92,9
+86,13
@@
int main(int argc, char * argv[])
#include <openssl/crypto.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/crypto.h>
#include <openssl/bio.h>
#include <openssl/evp.h>
+#include <openssl/bn.h>
#include <openssl/ecdsa.h>
#include <openssl/ecdsa.h>
+#ifndef OPENSSL_NO_ENGINE
#include <openssl/engine.h>
#include <openssl/engine.h>
+#endif
#include <openssl/err.h>
#include <openssl/err.h>
+#include <openssl/rand.h>
static const char rnd_seed[] = "string to make the random number generator "
"think it has entropy";
static const char rnd_seed[] = "string to make the random number generator "
"think it has entropy";
@@
-200,20
+198,18
@@
int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in)
BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));
/* create the key */
BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));
/* 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 = EC_KEY_new_by_curve_name(nid)) == NULL)
goto x962_int_err;
if (!EC_KEY_generate_key(key))
goto x962_int_err;
BIO_printf(out, ".");
goto x962_int_err;
if (!EC_KEY_generate_key(key))
goto x962_int_err;
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* create the signature */
signature = ECDSA_do_sign(digest, 20, key);
if (signature == NULL)
goto x962_int_err;
BIO_printf(out, ".");
/* create the signature */
signature = ECDSA_do_sign(digest, 20, key);
if (signature == NULL)
goto x962_int_err;
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* compare the created signature with the expected signature */
if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)
goto x962_int_err;
/* compare the created signature with the expected signature */
if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)
goto x962_int_err;
@@
-223,12
+219,12
@@
int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in)
if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s))
goto x962_int_err;
BIO_printf(out, ".");
if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s))
goto x962_int_err;
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* verify the signature */
if (ECDSA_do_verify(digest, 20, signature, key) != 1)
goto x962_int_err;
BIO_printf(out, ".");
/* verify the signature */
if (ECDSA_do_verify(digest, 20, signature, key) != 1)
goto x962_int_err;
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
BIO_printf(out, " ok\n");
ret = 1;
BIO_printf(out, " ok\n");
ret = 1;
@@
-290,6
+286,7
@@
int test_builtin(BIO *out)
EC_builtin_curve *curves = NULL;
size_t crv_len = 0, n = 0;
EC_KEY *eckey = NULL, *wrong_eckey = NULL;
EC_builtin_curve *curves = NULL;
size_t crv_len = 0, n = 0;
EC_KEY *eckey = NULL, *wrong_eckey = NULL;
+ EC_GROUP *group;
unsigned char digest[20], wrong_digest[20];
unsigned char *signature = NULL;
unsigned int sig_len;
unsigned char digest[20], wrong_digest[20];
unsigned char *signature = NULL;
unsigned int sig_len;
@@
-336,9
+333,13
@@
int test_builtin(BIO *out)
/* create new ecdsa key (== EC_KEY) */
if ((eckey = EC_KEY_new()) == NULL)
goto builtin_err;
/* 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)
+ group = EC_GROUP_new_by_curve_name(nid);
+ if (group == NULL)
+ goto builtin_err;
+ if (EC_KEY_set_group(eckey, group) == 0)
goto builtin_err;
goto builtin_err;
- if (EC_GROUP_get_degree(eckey->group) < 160)
+ EC_GROUP_free(group);
+ if (EC_GROUP_get_degree(EC_KEY_get0_group(eckey)) < 160)
/* drop the curve */
{
EC_KEY_free(eckey);
/* drop the curve */
{
EC_KEY_free(eckey);
@@
-355,8
+356,12
@@
int test_builtin(BIO *out)
/* create second key */
if ((wrong_eckey = EC_KEY_new()) == NULL)
goto builtin_err;
/* create second key */
if ((wrong_eckey = EC_KEY_new()) == NULL)
goto builtin_err;
- if ((wrong_eckey->group = EC_GROUP_new_by_nid(nid)) == NULL)
+ group = EC_GROUP_new_by_curve_name(nid);
+ if (group == NULL)
goto builtin_err;
goto builtin_err;
+ if (EC_KEY_set_group(wrong_eckey, group) == 0)
+ goto builtin_err;
+ EC_GROUP_free(group);
if (!EC_KEY_generate_key(wrong_eckey))
{
BIO_printf(out, " failed\n");
if (!EC_KEY_generate_key(wrong_eckey))
{
BIO_printf(out, " failed\n");
@@
-364,7
+369,7
@@
int test_builtin(BIO *out)
}
BIO_printf(out, ".");
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* check key */
if (!EC_KEY_check_key(eckey))
{
/* check key */
if (!EC_KEY_check_key(eckey))
{
@@
-372,7
+377,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* create signature */
sig_len = ECDSA_size(eckey);
if ((signature = OPENSSL_malloc(sig_len)) == NULL)
/* create signature */
sig_len = ECDSA_size(eckey);
if ((signature = OPENSSL_malloc(sig_len)) == NULL)
@@
-383,7
+388,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* verify signature */
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
{
/* verify signature */
if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
{
@@
-391,7
+396,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* verify signature with the wrong key */
if (ECDSA_verify(0, digest, 20, signature, sig_len,
wrong_eckey) == 1)
/* verify signature with the wrong key */
if (ECDSA_verify(0, digest, 20, signature, sig_len,
wrong_eckey) == 1)
@@
-400,7
+405,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* wrong digest */
if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len,
eckey) == 1)
/* wrong digest */
if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len,
eckey) == 1)
@@
-409,7
+414,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
/* modify a single byte of the signature */
offset = signature[10] % sig_len;
dirt = signature[11];
/* modify a single byte of the signature */
offset = signature[10] % sig_len;
dirt = signature[11];
@@
-420,7
+425,7
@@
int test_builtin(BIO *out)
goto builtin_err;
}
BIO_printf(out, ".");
goto builtin_err;
}
BIO_printf(out, ".");
- BIO_flush(out);
+
(void)
BIO_flush(out);
BIO_printf(out, " ok\n");
/* cleanup */
BIO_printf(out, " ok\n");
/* cleanup */
@@
-438,7
+443,7
@@
builtin_err:
EC_KEY_free(eckey);
if (wrong_eckey)
EC_KEY_free(wrong_eckey);
EC_KEY_free(eckey);
if (wrong_eckey)
EC_KEY_free(wrong_eckey);
- if (signature)
;
+ if (signature)
OPENSSL_free(signature);
if (curves)
OPENSSL_free(curves);
OPENSSL_free(signature);
if (curves)
OPENSSL_free(curves);
@@
-448,7
+453,7
@@
builtin_err:
int main(void)
{
int main(void)
{
- int ret =
0
;
+ int ret =
1
;
BIO *out;
out = BIO_new_fp(stdout, BIO_NOCLOSE);
BIO *out;
out = BIO_new_fp(stdout, BIO_NOCLOSE);
@@
-476,13
+481,13
@@
int main(void)
if (!x9_62_tests(out)) goto err;
if (!test_builtin(out)) goto err;
if (!x9_62_tests(out)) goto err;
if (!test_builtin(out)) goto err;
- ret =
1
;
+ ret =
0
;
err:
err:
- if (
!ret)
+ if (
ret)
BIO_printf(out, "\nECDSA test failed\n");
else
BIO_printf(out, "\nECDSA test passed\n");
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);
ERR_print_errors(out);
CRYPTO_cleanup_all_ex_data();
ERR_remove_state(0);
@@
-490,6
+495,6
@@
err:
CRYPTO_mem_leaks(out);
if (out != NULL)
BIO_free(out);
CRYPTO_mem_leaks(out);
if (out != NULL)
BIO_free(out);
- return
(0)
;
+ return
ret
;
}
#endif
}
#endif