Fix MAC for Messages

This commit is contained in:
Florian Märkl 2019-04-04 22:15:25 +02:00
commit 77c11cadbc
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
3 changed files with 5 additions and 1 deletions

View file

@ -189,6 +189,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_gkcrypt_gmac(ChiakiGKCrypt *gkcrypt, size_t
uint8_t *gmac_key = gkcrypt->key_gmac_current;
uint8_t gmac_key_tmp[CHIAKI_GKCRYPT_BLOCK_SIZE];
uint64_t key_index = key_pos / CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_KEY_POS;
// TODO: what to do if (key_pos / CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_KEY_POS) != ((key_pos + buf_size) / CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_KEY_POS)?
if(key_index > gkcrypt->key_gmac_index_current)
{
chiaki_gkcrypt_gen_new_gmac_key(gkcrypt, key_index);

View file

@ -401,6 +401,9 @@ static ChiakiErrorCode takion_handle_packet_mac(ChiakiTakion *takion, uint8_t ba
}
uint32_t key_pos = ntohl(*((uint32_t *)(buf + key_pos_offset)));
if(base_type == TAKION_PACKET_TYPE_MESSAGE)
memset(buf + key_pos_offset, 0, sizeof(uint32_t));
uint8_t mac[CHIAKI_GKCRYPT_GMAC_SIZE];
memcpy(mac, buf + mac_offset, sizeof(mac));
memset(buf + mac_offset, 0, sizeof(mac));

View file

@ -184,7 +184,7 @@ static MunitResult test_gmac(const MunitParameter params[], void *user)
memcpy(gkcrypt.iv, gkcrypt_iv, sizeof(gkcrypt.iv));
gkcrypt.key_buf = NULL;
gkcrypt.key_buf_size = 0;
gkcrypt.key_gmac_index_next = 1;
gkcrypt.key_gmac_index_current = 0;
uint8_t gmac[CHIAKI_GKCRYPT_GMAC_SIZE];
ChiakiErrorCode err = chiaki_gkcrypt_gmac(&gkcrypt, key_pos, buf, sizeof(buf), gmac);