/src/gnutls/lib/accelerated/x86/aes-gcm-aead.h
Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef GNUTLS_LIB_ACCELERATED_X86_AES_GCM_AEAD_H |
2 | | #define GNUTLS_LIB_ACCELERATED_X86_AES_GCM_AEAD_H |
3 | | |
4 | | static int aes_gcm_aead_encrypt(void *ctx, const void *nonce, size_t nonce_size, |
5 | | const void *auth, size_t auth_size, |
6 | | size_t tag_size, const void *plain, |
7 | | size_t plain_size, void *encr, size_t encr_size) |
8 | 0 | { |
9 | 0 | int ret; |
10 | | |
11 | | /* proper AEAD cipher */ |
12 | 0 | if (unlikely(encr_size - tag_size < plain_size)) |
13 | 0 | return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER); |
14 | | |
15 | 0 | ret = aes_gcm_setiv(ctx, nonce, nonce_size); |
16 | 0 | if (ret < 0) { |
17 | 0 | return gnutls_assert_val(ret); |
18 | 0 | } |
19 | | |
20 | | /* Always succeeds in this call sequence. */ |
21 | 0 | (void)aes_gcm_auth(ctx, auth, auth_size); |
22 | |
|
23 | 0 | aes_gcm_encrypt(ctx, plain, plain_size, encr, encr_size); |
24 | |
|
25 | 0 | aes_gcm_tag(ctx, ((uint8_t *)encr) + plain_size, tag_size); |
26 | 0 | return 0; |
27 | 0 | } Unexecuted instantiation: aes-gcm-padlock.c:aes_gcm_aead_encrypt Unexecuted instantiation: aes-gcm-x86-aesni.c:aes_gcm_aead_encrypt Unexecuted instantiation: aes-gcm-x86-pclmul.c:aes_gcm_aead_encrypt Unexecuted instantiation: aes-gcm-x86-ssse3.c:aes_gcm_aead_encrypt |
28 | | |
29 | | static int aes_gcm_aead_decrypt(void *ctx, const void *nonce, size_t nonce_size, |
30 | | const void *auth, size_t auth_size, |
31 | | size_t tag_size, const void *encr, |
32 | | size_t encr_size, void *plain, |
33 | | size_t plain_size) |
34 | 0 | { |
35 | 0 | uint8_t tag[MAX_HASH_SIZE]; |
36 | 0 | int ret; |
37 | |
|
38 | 0 | if (unlikely(encr_size < tag_size)) |
39 | 0 | return gnutls_assert_val(GNUTLS_E_DECRYPTION_FAILED); |
40 | | |
41 | 0 | if (unlikely(plain_size < encr_size - tag_size)) |
42 | 0 | return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER); |
43 | | |
44 | 0 | ret = aes_gcm_setiv(ctx, nonce, nonce_size); |
45 | 0 | if (ret < 0) { |
46 | 0 | return gnutls_assert_val(ret); |
47 | 0 | } |
48 | | |
49 | | /* Always succeeds in this call sequence. */ |
50 | 0 | (void)aes_gcm_auth(ctx, auth, auth_size); |
51 | |
|
52 | 0 | encr_size -= tag_size; |
53 | 0 | aes_gcm_decrypt(ctx, encr, encr_size, plain, plain_size); |
54 | |
|
55 | 0 | aes_gcm_tag(ctx, tag, tag_size); |
56 | |
|
57 | 0 | if (gnutls_memcmp(((uint8_t *)encr) + encr_size, tag, tag_size) != 0) |
58 | 0 | return gnutls_assert_val(GNUTLS_E_DECRYPTION_FAILED); |
59 | | |
60 | 0 | return 0; |
61 | 0 | } Unexecuted instantiation: aes-gcm-padlock.c:aes_gcm_aead_decrypt Unexecuted instantiation: aes-gcm-x86-aesni.c:aes_gcm_aead_decrypt Unexecuted instantiation: aes-gcm-x86-pclmul.c:aes_gcm_aead_decrypt Unexecuted instantiation: aes-gcm-x86-ssse3.c:aes_gcm_aead_decrypt |
62 | | |
63 | | #endif /* GNUTLS_LIB_ACCELERATED_X86_AES_GCM_AEAD_H */ |