Skip to content

Commit 56fc5bb

Browse files
committed
Dtls13GetRnMask: Correctly get chacha counter on BE systems
The issue was that BIG_ENDIAN is defined in endian.h (on linux). Our define is BIG_ENDIAN_ORDER.
1 parent d320260 commit 56fc5bb

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

src/dtls13.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,7 @@ static int Dtls13GetRnMask(WOLFSSL* ssl, const byte* ciphertext, byte* mask,
274274
if (c->chacha == NULL)
275275
return BAD_STATE_E;
276276

277-
/* assuming CIPHER[0..3] should be interpreted as little endian 32-bits
278-
integer. The draft rfc isn't really clear on that. See sec 4.2.3 of
279-
the draft. See also Section 2.3 of the Chacha RFC. */
280-
XMEMCPY(&counter, ciphertext, sizeof(counter));
281-
#ifdef BIG_ENDIAN
282-
counter = ByteReverseWord32(counter);
283-
#endif /* BIG_ENDIAN */
277+
ato32le(ciphertext, &counter);
284278

285279
ret = wc_Chacha_SetIV(c->chacha, &ciphertext[4], counter);
286280
if (ret != 0)

wolfcrypt/src/misc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,15 @@ WC_MISC_STATIC WC_INLINE void ato32(const byte* c, word32* wc_u32)
472472
(word32)c[3];
473473
}
474474

475+
/* convert opaque to 32 bit integer. Interpret as little endian. */
476+
WC_MISC_STATIC WC_INLINE void ato32le(const byte* c, word32* wc_u32)
477+
{
478+
*wc_u32 = (word32)c[0] |
479+
((word32)c[1] << 8) |
480+
((word32)c[2] << 16) |
481+
((word32)c[3] << 24);
482+
}
483+
475484

476485
WC_MISC_STATIC WC_INLINE word32 btoi(byte b)
477486
{

wolfssl/wolfcrypt/misc.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ void ByteReverseWords64(word64* out, const word64* in, word32 byteCount);
102102

103103

104104
void c32to24(word32 in, word24 out);
105-
void c16toa(word16 u16, byte* c);
106-
void c32toa(word32 u32, byte* c);
107-
void c24to32(const word24 u24, word32* u32);
108-
void ato16(const byte* c, word16* u16);
109-
void ato24(const byte* c, word32* u24);
110-
void ato32(const byte* c, word32* u32);
105+
void c16toa(word16 wc_u16, byte* c);
106+
void c32toa(word32 wc_u32, byte* c);
107+
void c24to32(const word24 wc_u24, word32* wc_u32);
108+
void ato16(const byte* c, word16* wc_u16);
109+
void ato24(const byte* c, word32* wc_u24);
110+
void ato32(const byte* c, word32* wc_u32);
111+
void ato32le(const byte* c, word32* wc_u32);
111112
word32 btoi(byte b);
112113

113114
WOLFSSL_LOCAL signed char HexCharToByte(char ch);

0 commit comments

Comments
 (0)