diff options
Diffstat (limited to 'src/methods/generic_gcm/generic_gcm.c')
-rw-r--r-- | src/methods/generic_gcm/generic_gcm.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/src/methods/generic_gcm/generic_gcm.c b/src/methods/generic_gcm/generic_gcm.c index 9c31ec4..a35a6c9 100644 --- a/src/methods/generic_gcm/generic_gcm.c +++ b/src/methods/generic_gcm/generic_gcm.c @@ -34,7 +34,6 @@ struct fastd_method_session_state { const fastd_cipher_t *cipher; const fastd_cipher_context_t *cipher_ctx; fastd_cipher_state_t *cipher_state; - size_t ivlen; const fastd_mac_t *ghash; const fastd_mac_context_t *ghash_ctx; @@ -77,30 +76,13 @@ static size_t method_max_packet_size(fastd_context_t *ctx) { } -static size_t method_min_encrypt_head_space(fastd_context_t *ctx UNUSED) { - return sizeof(fastd_block128_t); -} - -static size_t method_min_decrypt_head_space(fastd_context_t *ctx UNUSED) { - return 0; -} - -static size_t method_min_encrypt_tail_space(fastd_context_t *ctx UNUSED) { - return (sizeof(fastd_block128_t)-1); -} - -static size_t method_min_decrypt_tail_space(fastd_context_t *ctx UNUSED) { - return (2*sizeof(fastd_block128_t)-1); -} - - static size_t method_key_length(fastd_context_t *ctx, const char *name) { const fastd_cipher_t *cipher = NULL; const fastd_cipher_context_t *cctx; if (!cipher_get(ctx, name, &cipher, &cctx)) exit_bug(ctx, "generic-gcm: can't get cipher key length"); - return cipher->key_length(ctx, cctx); + return cipher->key_length; } static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, const char *name, const uint8_t *secret, bool initiator) { @@ -116,12 +98,11 @@ static fastd_method_session_state_t* method_session_init(fastd_context_t *ctx, c static const fastd_block128_t zeroblock = {}; fastd_block128_t H; - session->ivlen = session->cipher->iv_length(ctx, session->cipher_state); - if (session->ivlen <= COMMON_NONCEBYTES) + if (session->cipher->iv_length <= COMMON_NONCEBYTES) exit_bug(ctx, "generic-gcm: iv_length to small"); - uint8_t zeroiv[session->ivlen]; - memset(zeroiv, 0, session->ivlen); + uint8_t zeroiv[session->cipher->iv_length]; + memset(zeroiv, 0, session->cipher->iv_length); session->cipher->crypt(ctx, session->cipher_state, &H, &zeroblock, sizeof(fastd_block128_t), zeroiv); @@ -185,10 +166,10 @@ static bool method_encrypt(fastd_context_t *ctx, fastd_peer_t *peer UNUSED, fast if (tail_len) memset(in.data+in.len, 0, tail_len); - uint8_t nonce[session->ivlen]; - memset(nonce, 0, session->ivlen); + uint8_t nonce[session->cipher->iv_length]; + memset(nonce, 0, session->cipher->iv_length); memcpy(nonce, session->common.send_nonce, COMMON_NONCEBYTES); - nonce[session->ivlen-1] = 1; + nonce[session->cipher->iv_length-1] = 1; int n_blocks = block_count(in.len, sizeof(fastd_block128_t)); @@ -238,10 +219,10 @@ static bool method_decrypt(fastd_context_t *ctx, fastd_peer_t *peer, fastd_metho if (((const uint8_t*)in.data)[COMMON_NONCEBYTES]) /* flags */ return false; - uint8_t nonce[session->ivlen]; - memset(nonce, 0, session->ivlen); + uint8_t nonce[session->cipher->iv_length]; + memset(nonce, 0, session->cipher->iv_length); memcpy(nonce, in.data, COMMON_NONCEBYTES); - nonce[session->ivlen-1] = 1; + nonce[session->cipher->iv_length-1] = 1; int64_t age; if (!fastd_method_is_nonce_valid(ctx, &session->common, nonce, &age)) @@ -290,10 +271,10 @@ const fastd_method_t fastd_method_generic_gcm = { .provides = method_provides, .max_packet_size = method_max_packet_size, - .min_encrypt_head_space = method_min_encrypt_head_space, - .min_decrypt_head_space = method_min_decrypt_head_space, - .min_encrypt_tail_space = method_min_encrypt_tail_space, - .min_decrypt_tail_space = method_min_decrypt_tail_space, + .min_encrypt_head_space = sizeof(fastd_block128_t), + .min_decrypt_head_space = 0, + .min_encrypt_tail_space = sizeof(fastd_block128_t)-1, + .min_decrypt_tail_space = 2*sizeof(fastd_block128_t)-1, .key_length = method_key_length, .session_init = method_session_init, |