From 1bb09fb97a4b47c98ec756bf1e73ea5a7d41fda2 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Mon, 3 Mar 2014 14:51:57 -0800 Subject: [PATCH] Added epoch to sequence number for AES-CCM with DTLS encrypt/decrypt. --- src/internal.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/internal.c b/src/internal.c index 1adabdd4a..5fd9b96ff 100644 --- a/src/internal.c +++ b/src/internal.c @@ -4134,8 +4134,10 @@ static INLINE int Encrypt(CYASSL* ssl, byte* out, const byte* input, word16 sz) /* Store the type, version. Unfortunately, they are in * the input buffer ahead of the plaintext. */ #ifdef CYASSL_DTLS - if (ssl->options.dtls) + if (ssl->options.dtls) { + c16toa(ssl->keys.dtls_epoch, additional); additionalSrc -= DTLS_HANDSHAKE_EXTRA; + } #endif XMEMCPY(additional + AEAD_TYPE_OFFSET, additionalSrc, 3); @@ -4271,7 +4273,12 @@ static INLINE int Decrypt(CYASSL* ssl, byte* plain, const byte* input, /* sequence number field is 64-bits, we only use 32-bits */ c32toa(GetSEQIncrement(ssl, 1), additional + AEAD_SEQ_OFFSET); - + + #ifdef CYASSL_DTLS + if (ssl->options.dtls) + c16toa(ssl->keys.dtls_state.curEpoch, additional); + #endif + additional[AEAD_TYPE_OFFSET] = ssl->curRL.type; additional[AEAD_VMAJ_OFFSET] = ssl->curRL.pvMajor; additional[AEAD_VMIN_OFFSET] = ssl->curRL.pvMinor;