diff options
author | Mark Haines <mjark@negativecurvature.net> | 2016-09-13 16:45:54 +0100 |
---|---|---|
committer | Mark Haines <mjark@negativecurvature.net> | 2016-09-13 16:45:54 +0100 |
commit | 5926a8fd29ecb997e6c4609e2195e68274d1f9df (patch) | |
tree | 0792dfed9ade4caee9f359a5455e3c8c1c8d5618 /src | |
parent | d62e344db708672dee58238be330382b2c903b5b (diff) |
Comment on the encoding of the message counter.
Diffstat (limited to 'src')
-rw-r--r-- | src/inbound_group_session.c | 8 | ||||
-rw-r--r-- | src/outbound_group_session.c | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/inbound_group_session.c b/src/inbound_group_session.c index f2a310a..82ff66f 100644 --- a/src/inbound_group_session.c +++ b/src/inbound_group_session.c @@ -88,10 +88,10 @@ static size_t _init_group_session_keys( } uint32_t counter = 0; - counter <<= 8; counter |= *ptr++; - counter <<= 8; counter |= *ptr++; - counter <<= 8; counter |= *ptr++; - counter <<= 8; counter |= *ptr++; + // Decode counter as a big endian 32-bit number. + for (unsigned i = 0; i < 4; i++) { + counter <<= 8; counter |= *ptr++; + } megolm_init(&session->initial_ratchet, ptr, counter); megolm_init(&session->latest_ratchet, ptr, counter); diff --git a/src/outbound_group_session.c b/src/outbound_group_session.c index 7116547..8686993 100644 --- a/src/outbound_group_session.c +++ b/src/outbound_group_session.c @@ -337,10 +337,10 @@ size_t olm_outbound_group_session_key( *ptr++ = SESSION_KEY_VERSION; uint32_t counter = session->ratchet.counter; - *ptr++ = 0xFF & (counter >> 24); counter <<= 8; - *ptr++ = 0xFF & (counter >> 24); counter <<= 8; - *ptr++ = 0xFF & (counter >> 24); counter <<= 8; - *ptr++ = 0xFF & (counter >> 24); counter <<= 8; + // Encode counter as a big endian 32-bit number. + if (unsigned i = 0; i < 4; i++) { + *ptr++ = 0xFF & (counter >> 24); counter <<= 8; + } memcpy(ptr, megolm_get_data(&session->ratchet), MEGOLM_RATCHET_LENGTH); ptr += MEGOLM_RATCHET_LENGTH; |