Comment on the encoding of the message counter.

This commit is contained in:
Mark Haines 2016-09-13 16:45:54 +01:00
parent d62e344db7
commit 5926a8fd29
2 changed files with 8 additions and 8 deletions

View file

@ -88,10 +88,10 @@ static size_t _init_group_session_keys(
} }
uint32_t counter = 0; uint32_t counter = 0;
counter <<= 8; counter |= *ptr++; // Decode counter as a big endian 32-bit number.
counter <<= 8; counter |= *ptr++; for (unsigned i = 0; i < 4; i++) {
counter <<= 8; counter |= *ptr++; counter <<= 8; counter |= *ptr++;
counter <<= 8; counter |= *ptr++; }
megolm_init(&session->initial_ratchet, ptr, counter); megolm_init(&session->initial_ratchet, ptr, counter);
megolm_init(&session->latest_ratchet, ptr, counter); megolm_init(&session->latest_ratchet, ptr, counter);

View file

@ -337,10 +337,10 @@ size_t olm_outbound_group_session_key(
*ptr++ = SESSION_KEY_VERSION; *ptr++ = SESSION_KEY_VERSION;
uint32_t counter = session->ratchet.counter; uint32_t counter = session->ratchet.counter;
*ptr++ = 0xFF & (counter >> 24); counter <<= 8; // Encode counter as a big endian 32-bit number.
*ptr++ = 0xFF & (counter >> 24); counter <<= 8; if (unsigned i = 0; i < 4; i++) {
*ptr++ = 0xFF & (counter >> 24); counter <<= 8; *ptr++ = 0xFF & (counter >> 24); counter <<= 8;
*ptr++ = 0xFF & (counter >> 24); counter <<= 8; }
memcpy(ptr, megolm_get_data(&session->ratchet), MEGOLM_RATCHET_LENGTH); memcpy(ptr, megolm_get_data(&session->ratchet), MEGOLM_RATCHET_LENGTH);
ptr += MEGOLM_RATCHET_LENGTH; ptr += MEGOLM_RATCHET_LENGTH;