make sure poly1305 and chacha defined for chacha-poly aead mode

This commit is contained in:
toddouska
2015-02-19 14:33:21 -08:00
parent 42b58bd05b
commit d5b249754b
3 changed files with 30 additions and 35 deletions

View File

@ -5302,7 +5302,7 @@ static INLINE void AeadIncrementExpIV(WOLFSSL* ssl)
} }
#ifdef HAVE_POLY1305 #if defined(HAVE_POLY1305) && defined(HAVE_CHACHA)
/*more recent rfc's concatonate input for poly1305 differently*/ /*more recent rfc's concatonate input for poly1305 differently*/
static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out, static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out,
byte* cipher, word16 sz, byte* tag) byte* cipher, word16 sz, byte* tag)
@ -5416,10 +5416,8 @@ static int Poly1305TagOld(WOLFSSL* ssl, byte* additional, const byte* out,
return ret; return ret;
} }
#endif /*HAVE_POLY1305*/
#ifdef HAVE_CHACHA
static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input, static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input,
word16 sz) word16 sz)
{ {
@ -5484,19 +5482,17 @@ static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input,
sz - ssl->specs.aead_mac_size)) != 0) sz - ssl->specs.aead_mac_size)) != 0)
return ret; return ret;
#ifdef HAVE_POLY1305 /* get the tag : future use of hmac could go here*/
/* get the tag : future use of hmac could go here*/ if (ssl->options.oldPoly == 1) {
if (ssl->options.oldPoly == 1) { if ((ret = Poly1305TagOld(ssl, additional, (const byte* )out,
if ((ret = Poly1305TagOld(ssl, additional, (const byte* )out, cipher, sz, tag)) != 0)
cipher, sz, tag)) != 0) return ret;
return ret; }
} else {
else { if ((ret = Poly1305Tag(ssl, additional, (const byte* )out,
if ((ret = Poly1305Tag(ssl, additional, (const byte* )out, cipher, sz, tag)) != 0)
cipher, sz, tag)) != 0) return ret;
return ret; }
}
#endif
/* append tag to ciphertext */ /* append tag to ciphertext */
XMEMCPY(out + sz - ssl->specs.aead_mac_size, tag, sizeof(tag)); XMEMCPY(out + sz - ssl->specs.aead_mac_size, tag, sizeof(tag));
@ -5583,19 +5579,17 @@ static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input,
cipher, sizeof(cipher))) != 0) cipher, sizeof(cipher))) != 0)
return ret; return ret;
#ifdef HAVE_POLY1305 /* get the tag : future use of hmac could go here*/
/* get the tag : future use of hmac could go here*/ if (ssl->options.oldPoly == 1) {
if (ssl->options.oldPoly == 1) { if ((ret = Poly1305TagOld(ssl, additional, input, cipher,
if ((ret = Poly1305TagOld(ssl, additional, input, cipher, sz, tag)) != 0)
sz, tag)) != 0) return ret;
return ret; }
} else {
else { if ((ret = Poly1305Tag(ssl, additional, input, cipher,
if ((ret = Poly1305Tag(ssl, additional, input, cipher, sz, tag)) != 0)
sz, tag)) != 0) return ret;
return ret; }
}
#endif
/* check mac sent along with packet */ /* check mac sent along with packet */
ret = 0; ret = 0;
@ -5628,8 +5622,8 @@ static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input,
return ret; return ret;
} }
#endif /* HAVE_CHACHA */ #endif /* HAVE_CHACHA && HAVE_POLY1305 */
#endif #endif /* HAVE_AEAD */
static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz) static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz)
@ -5772,7 +5766,7 @@ static INLINE int Encrypt(WOLFSSL* ssl, byte* out, const byte* input, word16 sz)
return wc_RabbitProcess(ssl->encrypt.rabbit, out, input, sz); return wc_RabbitProcess(ssl->encrypt.rabbit, out, input, sz);
#endif #endif
#ifdef HAVE_CHACHA #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
case wolfssl_chacha: case wolfssl_chacha:
return ChachaAEADEncrypt(ssl, out, input, sz); return ChachaAEADEncrypt(ssl, out, input, sz);
#endif #endif
@ -5922,7 +5916,7 @@ static INLINE int Decrypt(WOLFSSL* ssl, byte* plain, const byte* input,
return wc_RabbitProcess(ssl->decrypt.rabbit, plain, input, sz); return wc_RabbitProcess(ssl->decrypt.rabbit, plain, input, sz);
#endif #endif
#ifdef HAVE_CHACHA #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
case wolfssl_chacha: case wolfssl_chacha:
return ChachaAEADDecrypt(ssl, plain, input, sz); return ChachaAEADDecrypt(ssl, plain, input, sz);
#endif #endif

View File

@ -1870,7 +1870,7 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs,
#endif #endif
#ifdef HAVE_CHACHA #if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
if (specs->bulk_cipher_algorithm == wolfssl_chacha) { if (specs->bulk_cipher_algorithm == wolfssl_chacha) {
int chachaRet; int chachaRet;
if (enc && enc->chacha == NULL) if (enc && enc->chacha == NULL)

View File

@ -512,7 +512,8 @@ typedef byte word24[3];
#endif /* end of ChaCha - Poly AEAD suites */ #endif /* end of ChaCha - Poly AEAD suites */
#endif #endif
#if defined(BUILD_AESGCM) || defined(HAVE_AESCCM) || defined(HAVE_CHACHA) #if defined(BUILD_AESGCM) || defined(HAVE_AESCCM) || \
(defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
#define HAVE_AEAD #define HAVE_AEAD
#endif #endif