Skip to content

Commit d5b2497

Browse files
committed
make sure poly1305 and chacha defined for chacha-poly aead mode
1 parent 42b58bd commit d5b2497

3 files changed

Lines changed: 30 additions & 35 deletions

File tree

‎src/internal.c‎

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,7 +5302,7 @@ static INLINE void AeadIncrementExpIV(WOLFSSL* ssl)
53025302
}
53035303

53045304

5305-
#ifdef HAVE_POLY1305
5305+
#if defined(HAVE_POLY1305) && defined(HAVE_CHACHA)
53065306
/*more recent rfc's concatonate input for poly1305 differently*/
53075307
static int Poly1305Tag(WOLFSSL* ssl, byte* additional, const byte* out,
53085308
byte* cipher, word16 sz, byte* tag)
@@ -5416,10 +5416,8 @@ static int Poly1305TagOld(WOLFSSL* ssl, byte* additional, const byte* out,
54165416

54175417
return ret;
54185418
}
5419-
#endif /*HAVE_POLY1305*/
54205419

54215420

5422-
#ifdef HAVE_CHACHA
54235421
static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input,
54245422
word16 sz)
54255423
{
@@ -5484,19 +5482,17 @@ static int ChachaAEADEncrypt(WOLFSSL* ssl, byte* out, const byte* input,
54845482
sz - ssl->specs.aead_mac_size)) != 0)
54855483
return ret;
54865484

5487-
#ifdef HAVE_POLY1305
5488-
/* get the tag : future use of hmac could go here*/
5489-
if (ssl->options.oldPoly == 1) {
5490-
if ((ret = Poly1305TagOld(ssl, additional, (const byte* )out,
5491-
cipher, sz, tag)) != 0)
5492-
return ret;
5493-
}
5494-
else {
5495-
if ((ret = Poly1305Tag(ssl, additional, (const byte* )out,
5496-
cipher, sz, tag)) != 0)
5497-
return ret;
5498-
}
5499-
#endif
5485+
/* get the tag : future use of hmac could go here*/
5486+
if (ssl->options.oldPoly == 1) {
5487+
if ((ret = Poly1305TagOld(ssl, additional, (const byte* )out,
5488+
cipher, sz, tag)) != 0)
5489+
return ret;
5490+
}
5491+
else {
5492+
if ((ret = Poly1305Tag(ssl, additional, (const byte* )out,
5493+
cipher, sz, tag)) != 0)
5494+
return ret;
5495+
}
55005496

55015497
/* append tag to ciphertext */
55025498
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,
55835579
cipher, sizeof(cipher))) != 0)
55845580
return ret;
55855581

5586-
#ifdef HAVE_POLY1305
5587-
/* get the tag : future use of hmac could go here*/
5588-
if (ssl->options.oldPoly == 1) {
5589-
if ((ret = Poly1305TagOld(ssl, additional, input, cipher,
5590-
sz, tag)) != 0)
5591-
return ret;
5592-
}
5593-
else {
5594-
if ((ret = Poly1305Tag(ssl, additional, input, cipher,
5595-
sz, tag)) != 0)
5596-
return ret;
5597-
}
5598-
#endif
5582+
/* get the tag : future use of hmac could go here*/
5583+
if (ssl->options.oldPoly == 1) {
5584+
if ((ret = Poly1305TagOld(ssl, additional, input, cipher,
5585+
sz, tag)) != 0)
5586+
return ret;
5587+
}
5588+
else {
5589+
if ((ret = Poly1305Tag(ssl, additional, input, cipher,
5590+
sz, tag)) != 0)
5591+
return ret;
5592+
}
55995593

56005594
/* check mac sent along with packet */
56015595
ret = 0;
@@ -5628,8 +5622,8 @@ static int ChachaAEADDecrypt(WOLFSSL* ssl, byte* plain, const byte* input,
56285622

56295623
return ret;
56305624
}
5631-
#endif /* HAVE_CHACHA */
5632-
#endif
5625+
#endif /* HAVE_CHACHA && HAVE_POLY1305 */
5626+
#endif /* HAVE_AEAD */
56335627

56345628

56355629
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)
57725766
return wc_RabbitProcess(ssl->encrypt.rabbit, out, input, sz);
57735767
#endif
57745768

5775-
#ifdef HAVE_CHACHA
5769+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
57765770
case wolfssl_chacha:
57775771
return ChachaAEADEncrypt(ssl, out, input, sz);
57785772
#endif
@@ -5922,7 +5916,7 @@ static INLINE int Decrypt(WOLFSSL* ssl, byte* plain, const byte* input,
59225916
return wc_RabbitProcess(ssl->decrypt.rabbit, plain, input, sz);
59235917
#endif
59245918

5925-
#ifdef HAVE_CHACHA
5919+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
59265920
case wolfssl_chacha:
59275921
return ChachaAEADDecrypt(ssl, plain, input, sz);
59285922
#endif

‎src/keys.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ static int SetKeys(Ciphers* enc, Ciphers* dec, Keys* keys, CipherSpecs* specs,
18701870
#endif
18711871

18721872

1873-
#ifdef HAVE_CHACHA
1873+
#if defined(HAVE_CHACHA) && defined(HAVE_POLY1305)
18741874
if (specs->bulk_cipher_algorithm == wolfssl_chacha) {
18751875
int chachaRet;
18761876
if (enc && enc->chacha == NULL)

‎wolfssl/internal.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ typedef byte word24[3];
512512
#endif /* end of ChaCha - Poly AEAD suites */
513513
#endif
514514

515-
#if defined(BUILD_AESGCM) || defined(HAVE_AESCCM) || defined(HAVE_CHACHA)
515+
#if defined(BUILD_AESGCM) || defined(HAVE_AESCCM) || \
516+
(defined(HAVE_CHACHA) && defined(HAVE_POLY1305))
516517
#define HAVE_AEAD
517518
#endif
518519

0 commit comments

Comments
 (0)