From 91e3957fb0e38a5d5649f82e5d9f89dd0e85666f Mon Sep 17 00:00:00 2001 From: Mike DePaulo Date: Sat, 28 Mar 2015 09:50:31 -0400 Subject: Update openssl to version openssl-1.0.1m Conflicts: openssl/Makefile openssl/Makefile.bak openssl/crypto/cryptlib.c --- openssl/crypto/ecdh/ecdhtest.c | 582 ++++++++++++++++++++++------------------- 1 file changed, 309 insertions(+), 273 deletions(-) (limited to 'openssl/crypto/ecdh/ecdhtest.c') diff --git a/openssl/crypto/ecdh/ecdhtest.c b/openssl/crypto/ecdh/ecdhtest.c index 823d7baa6..996321d1e 100644 --- a/openssl/crypto/ecdh/ecdhtest.c +++ b/openssl/crypto/ecdh/ecdhtest.c @@ -21,7 +21,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -73,7 +73,7 @@ #include "../e_os.h" -#include /* for OPENSSL_NO_ECDH */ +#include /* for OPENSSL_NO_ECDH */ #include #include #include @@ -86,289 +86,325 @@ int main(int argc, char *argv[]) { printf("No ECDH support\n"); - return(0); + return (0); } #else -#include -#include +# include +# include -#ifdef OPENSSL_SYS_WIN16 -#define MS_CALLBACK _far _loadds -#else -#define MS_CALLBACK -#endif +# ifdef OPENSSL_SYS_WIN16 +# define MS_CALLBACK _far _loadds +# else +# define MS_CALLBACK +# endif -#if 0 +# if 0 static void MS_CALLBACK cb(int p, int n, void *arg); -#endif - -static const char rnd_seed[] = "string to make the random number generator think it has entropy"; +# endif +static const char rnd_seed[] = + "string to make the random number generator think it has entropy"; static const int KDF1_SHA1_len = 20; -static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) - { -#ifndef OPENSSL_NO_SHA - if (*outlen < SHA_DIGEST_LENGTH) - return NULL; - else - *outlen = SHA_DIGEST_LENGTH; - return SHA1(in, inlen, out); -#else - return NULL; -#endif - } - +static void *KDF1_SHA1(const void *in, size_t inlen, void *out, + size_t *outlen) +{ +# ifndef OPENSSL_NO_SHA + if (*outlen < SHA_DIGEST_LENGTH) + return NULL; + else + *outlen = SHA_DIGEST_LENGTH; + return SHA1(in, inlen, out); +# else + return NULL; +# endif +} static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) - { - EC_KEY *a=NULL; - EC_KEY *b=NULL; - BIGNUM *x_a=NULL, *y_a=NULL, - *x_b=NULL, *y_b=NULL; - char buf[12]; - unsigned char *abuf=NULL,*bbuf=NULL; - int i,alen,blen,aout,bout,ret=0; - const EC_GROUP *group; - - a = EC_KEY_new_by_curve_name(nid); - b = EC_KEY_new_by_curve_name(nid); - if (a == NULL || b == NULL) - goto err; - - group = EC_KEY_get0_group(a); - - if ((x_a=BN_new()) == NULL) goto err; - if ((y_a=BN_new()) == NULL) goto err; - if ((x_b=BN_new()) == NULL) goto err; - if ((y_b=BN_new()) == NULL) goto err; - - BIO_puts(out,"Testing key generation with "); - BIO_puts(out,text); -#ifdef NOISY - BIO_puts(out,"\n"); -#else - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(a)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; - } -#endif -#ifdef NOISY - BIO_puts(out," pri 1="); - BN_print(out,a->priv_key); - BIO_puts(out,"\n pub 1="); - BN_print(out,x_a); - BIO_puts(out,","); - BN_print(out,y_a); - BIO_puts(out,"\n"); -#else - BIO_printf(out," ."); - (void)BIO_flush(out); -#endif - - if (!EC_KEY_generate_key(b)) goto err; - - if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field) - { - if (!EC_POINT_get_affine_coordinates_GFp(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#ifndef OPENSSL_NO_EC2M - else - { - if (!EC_POINT_get_affine_coordinates_GF2m(group, - EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; - } -#endif - -#ifdef NOISY - BIO_puts(out," pri 2="); - BN_print(out,b->priv_key); - BIO_puts(out,"\n pub 2="); - BN_print(out,x_b); - BIO_puts(out,","); - BN_print(out,y_b); - BIO_puts(out,"\n"); -#else - BIO_printf(out,"."); - (void)BIO_flush(out); -#endif - - alen=KDF1_SHA1_len; - abuf=(unsigned char *)OPENSSL_malloc(alen); - aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1); - -#ifdef NOISY - BIO_puts(out," key1 ="); - for (i=0; i