Skip to content

Commit 0792e37

Browse files
committed
GCM allow skipping gcm_add_aad and gcm_process
1 parent dd5996d commit 0792e37

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/encauth/gcm/gcm_done.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ int gcm_done(gcm_state *gcm,
4040
return err;
4141
}
4242

43+
if (gcm->mode == LTC_GCM_MODE_IV) {
44+
/* let's process the IV */
45+
if ((err = gcm_add_aad(gcm, NULL, 0)) != CRYPT_OK) return err;
46+
}
47+
48+
if (gcm->mode == LTC_GCM_MODE_AAD) {
49+
/* let's process the AAD */
50+
if ((err = gcm_process(gcm, NULL, 0, NULL, 0)) != CRYPT_OK) return err;
51+
}
4352

4453
if (gcm->mode != LTC_GCM_MODE_TEXT) {
4554
return CRYPT_INVALID_ARG;

src/encauth/gcm/gcm_process.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ int gcm_process(gcm_state *gcm,
5252
return CRYPT_INVALID_ARG;
5353
}
5454

55+
if (gcm->mode == LTC_GCM_MODE_IV) {
56+
/* let's process the IV */
57+
if ((err = gcm_add_aad(gcm, NULL, 0)) != CRYPT_OK) return err;
58+
}
59+
5560
/* in AAD mode? */
5661
if (gcm->mode == LTC_GCM_MODE_AAD) {
5762
/* let's process the AAD */

src/encauth/gcm/gcm_test.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ int gcm_test(void)
325325
int idx, err;
326326
unsigned long x, y;
327327
unsigned char out[2][128], T[2][16];
328+
gcm_state gcm;
328329

329330
/* find aes */
330331
idx = find_cipher("aes");
@@ -335,6 +336,15 @@ int gcm_test(void)
335336
}
336337
}
337338

339+
/* Special test case for empty AAD + empty PT */
340+
y = sizeof(T[0]);
341+
if ((err = gcm_init(&gcm, idx, tests[0].K, tests[0].keylen)) != CRYPT_OK) return err;
342+
if ((err = gcm_add_iv(&gcm, tests[0].IV, tests[0].IVlen)) != CRYPT_OK) return err;
343+
/* intentionally skip gcm_add_aad + gcm_process */
344+
if ((err = gcm_done(&gcm, T[0], &y)) != CRYPT_OK) return err;
345+
if (compare_testvector(out[0], 0, tests[0].C, tests[0].ptlen, "GCM CT-special", 0)) return CRYPT_FAIL_TESTVECTOR;
346+
if (compare_testvector(T[0], y, tests[0].T, 16, "GCM Encrypt Tag-special", 0)) return CRYPT_FAIL_TESTVECTOR;
347+
338348
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
339349
y = sizeof(T[0]);
340350
if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen,

0 commit comments

Comments
 (0)