From 3bfd0bbf3be5bbd4be9a290b3a6fd5ed8dbe024a Mon Sep 17 00:00:00 2001 From: toddouska Date: Mon, 21 Jul 2014 16:20:17 -0700 Subject: [PATCH] fixup some chacah-poly suite things including a valgrind error --- ctaocrypt/benchmark/benchmark.c | 2 +- cyassl/internal.h | 4 +--- examples/client/client.c | 2 +- src/internal.c | 18 ++++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ctaocrypt/benchmark/benchmark.c b/ctaocrypt/benchmark/benchmark.c index 4f4131a30..e8ae08851 100644 --- a/ctaocrypt/benchmark/benchmark.c +++ b/ctaocrypt/benchmark/benchmark.c @@ -464,7 +464,7 @@ void bench_poly1305() persec = persec / 1024; #endif - printf("POLY1305 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, + printf("POLY1305 %d %s took %5.3f seconds, %7.3f MB/s\n", numBlocks, blockType, total, persec); } #endif /* HAVE_POLY1305 */ diff --git a/cyassl/internal.h b/cyassl/internal.h index d36a43db6..3780821a4 100644 --- a/cyassl/internal.h +++ b/cyassl/internal.h @@ -474,9 +474,7 @@ void c32to24(word32 in, word24 out); #if !defined(NO_RSA) #define BUILD_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 #endif - #if !defined(NO_DSA) - #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 - #endif + #define BUILD_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 #endif #if !defined(NO_DH) && !defined(NO_RSA) #define BUILD_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 diff --git a/examples/client/client.c b/examples/client/client.c index 29ab46f42..bdc08e03a 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -625,7 +625,7 @@ THREAD_RETURN CYASSL_THREAD client_test(void* args) #ifdef HAVE_POLY1305 /* use old poly to connect with google server */ - if (!XMEMCMP(domain, "www.google.com", 15)) { + if (!XSTRNCMP(domain, "www.google.com", 14)) { if (CyaSSL_use_old_poly(ssl, 1) != 0) err_sys("unable to set to old poly"); } diff --git a/src/internal.c b/src/internal.c index 2dabff2ee..7c0239011 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1672,6 +1672,9 @@ int InitSSL(CYASSL* ssl, CYASSL_CTX* ctx) ssl->options.groupMessages = ctx->groupMessages; ssl->options.usingNonblock = 0; ssl->options.saveArrays = 0; +#ifdef HAVE_POLY1305 + ssl->options.oldPoly = 0; +#endif #ifndef NO_CERTS /* ctx still owns certificate, certChain, key, dh, and cm */ @@ -4876,13 +4879,12 @@ static int Poly1305TagOld(CYASSL* ssl, byte* additional, const byte* out, static int ChachaAEADEncrypt(CYASSL* ssl, byte* out, const byte* input, word16 sz) { - int offset = 5; /*where to find type,version in record header */ - const byte* additionalSrc = input - offset; - int ret = 0; - byte tag[ssl->specs.aead_mac_size]; + const byte* additionalSrc = input - RECORD_HEADER_SZ; + int ret = 0; + byte tag[POLY1305_AUTH_SZ]; byte additional[CHACHA20_BLOCK_SIZE]; byte nonce[AEAD_NONCE_SZ]; - byte cipher[32]; /* generated key for poly1305 */ + byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for poly1305 */ XMEMSET(tag, 0, sizeof(tag)); XMEMSET(nonce, 0, AEAD_NONCE_SZ); @@ -4928,7 +4930,7 @@ static int ChachaAEADEncrypt(CYASSL* ssl, byte* out, const byte* input, return ret; if ((ret = Chacha_Process(ssl->encrypt.chacha, cipher, - cipher, 32)) != 0) + cipher, sizeof(cipher))) != 0) return ret; /* encrypt the plain text */ @@ -4981,8 +4983,8 @@ static int ChachaAEADDecrypt(CYASSL* ssl, byte* plain, const byte* input, { byte additional[CHACHA20_BLOCK_SIZE]; byte nonce[AEAD_NONCE_SZ]; - byte tag[ssl->specs.aead_mac_size]; - byte cipher[32]; /* generated key for mac */ + byte tag[POLY1305_AUTH_SZ]; + byte cipher[CHACHA20_256_KEY_SIZE]; /* generated key for mac */ int i; int ret = 0;