Skip to content

Commit 5accb8e

Browse files
committed
🚧 Work in progress
1 parent cee3672 commit 5accb8e

12 files changed

Lines changed: 13 additions & 10 deletions

src/gcm/aes_gcm.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ static aes_status_t aes_gcm_crypt(aes_gcm_counter_t *out, const iv_t nonce, cons
155155
uint32_t *cnt = NULL;
156156
size_t NR = 0, blocks = 0, i = 0;
157157

158-
// Copie locale du nonce pour pouvoir incrémenter le compteur
159158
memcpy(nonce_local, nonce, 16);
160159

161160
cnt = (uint32_t *)(nonce_local + 0xC);
@@ -168,18 +167,15 @@ static aes_status_t aes_gcm_crypt(aes_gcm_counter_t *out, const iv_t nonce, cons
168167

169168
hash_subkey = create_hash_subkey(NR, ctx);
170169

171-
// Calculer E(K, J0) pour le tag
172170
feedback = _mm_loadu_si128((__m128i*)nonce_local);
173171
j0_encrypted = aes_block_enc(feedback, &ctx->key, NR);
174172

175173
*cnt += 0x01000000;
176174

177-
// Chiffrer/Déchiffrer les données avec J1, J2, J3, ...
178175
blocks = (i_sz & 0xF ? -~(i_sz >> 0x4) : (i_sz >> 0x4));
179176

180177
for (i = 0; i < blocks; i++) {
181178

182-
// Prefetching
183179
_mm_prefetch((__m128i*)(in + 0x20), _MM_HINT_T0);
184180

185181
state = _mm_loadu_si128( &((__m128i*)in)[i]);
@@ -193,13 +189,10 @@ static aes_status_t aes_gcm_crypt(aes_gcm_counter_t *out, const iv_t nonce, cons
193189

194190
_mm_storeu_si128(&((__m128i*)out->out)[i], state);
195191

196-
// Incrémenter pour le prochain bloc (big endian)
192+
// Incrément counter (big endian)
197193
*cnt += 0x01000000;
198194
}
199195

200-
// Calculer GHASH sur le ciphertext (toujours)
201-
// Pour encryption: ciphertext = out->out (résultat du CTR)
202-
// Pour decryption: ciphertext = in (entrée)
203196
ghash = compute_ghash(hash_subkey, aad, aad_len, is_decrypt ? in : out->out, i_sz);
204197

205198
// Tag final = GHASH XOR E(K, J0)
@@ -216,5 +209,4 @@ aes_status_t aes_gcm_enc(aes_gcm_counter_t *out, const iv_t nonce, const byte_t
216209
aes_status_t aes_gcm_dec(aes_gcm_counter_t *out, const iv_t nonce, const byte_t *restrict aad, size_t aad_len, const byte_t *restrict in, size_t i_sz, const aes_ctx_t *ctx)
217210
{
218211
return (aes_gcm_crypt(out, nonce, aad, aad_len, in, i_sz, ctx, TRUE));
219-
}
220-
212+
}

tests/README_TESTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,4 @@ Les tests `aes_128_gcm_test1` et `aes_128_gcm_test2` utilisent des vecteurs offi
152152
- Intel AES-NI White Papers
153153

154154

155+

tests/aes_cbc/aes_256_cbc_two.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ int main(void)
101101
}
102102

103103

104+

tests/aes_cfb/aes_256_cfb_two.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,4 @@ int main(void)
9696
}
9797

9898

99+

tests/aes_ecb/aes_128_ecb_two.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,4 @@ int main(void)
9393
}
9494

9595

96+

tests/aes_gcm/aes_128_gcm_test3_aad.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ int main(void)
113113
}
114114

115115

116+

tests/aes_gcm/aes_128_gcm_test4_multiblock.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@ int main(void)
123123
}
124124

125125

126+

tests/aes_gcm/aes_128_gcm_test5_partial_block.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ int main(void)
118118
}
119119

120120

121+

tests/aes_gcm/aes_192_gcm_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ int main(void)
113113
}
114114

115115

116+

tests/aes_gcm/aes_256_gcm_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ int main(void)
118118
}
119119

120120

121+

0 commit comments

Comments
 (0)