Commit 31acdada authored by Niels Möller's avatar Niels Möller
Browse files

* testsuite/gcm-test.c (test_gcm_aes): New function, replacing

test_cipher_gcm and using the new gcm_aes interface.
(test_main): Updated to use test_gcm_aes.
* testsuite/testutils.c (test_cipher_gcm): Deleted function.

Rev: nettle/testsuite/gcm-test.c:1.2
Rev: nettle/testsuite/testutils.c:1.13
Rev: nettle/testsuite/testutils.h:1.7
parent 51994758
......@@ -2,6 +2,64 @@
#include "aes.h"
#include "gcm.h"
static void
test_gcm_aes(unsigned key_length,
const uint8_t *key,
unsigned auth_length,
const uint8_t *authtext,
unsigned length,
const uint8_t *cleartext,
const uint8_t *ciphertext,
unsigned iv_length,
const uint8_t *iv,
const uint8_t *digest)
{
struct gcm_aes_ctx ctx;
uint8_t *data = xalloc(length);
uint8_t buffer[GCM_BLOCK_SIZE];
/* encryption */
memset(buffer, 0, sizeof(buffer));
gcm_aes_set_key(&ctx, key_length, key);
gcm_aes_set_iv(&ctx, iv_length, iv);
if (auth_length)
gcm_aes_auth(&ctx, auth_length, authtext);
if (length)
gcm_aes_encrypt(&ctx, length, data, cleartext);
gcm_aes_digest(&ctx, GCM_BLOCK_SIZE, buffer);
if (!MEMEQ(length, data, ciphertext))
FAIL();
if (!MEMEQ(GCM_BLOCK_SIZE, buffer, digest))
FAIL();
/* decryption */
memset(buffer, 0, sizeof(buffer));
gcm_aes_set_iv(&ctx, iv_length, iv);
if (auth_length)
gcm_aes_auth(&ctx, auth_length, authtext);
if (length)
gcm_aes_decrypt(&ctx, length, data, data);
gcm_aes_digest(&ctx, GCM_BLOCK_SIZE, buffer);
if (!MEMEQ(length, data, cleartext))
FAIL();
if (!MEMEQ(GCM_BLOCK_SIZE, buffer, digest))
FAIL();
free(data);
}
int
test_main(void)
{
......@@ -11,8 +69,7 @@ test_main(void)
*/
/* Test case 1 */
test_cipher_gcm(&nettle_aes128,
/* key */HL("00000000000000000000000000000000"),
test_gcm_aes(/* key */HL("00000000000000000000000000000000"),
/* auth data */ HL(""),
/* plaintext */HL(""),
/* ciphertext*/H(""),
......@@ -20,8 +77,7 @@ test_main(void)
/* tag */H("58e2fccefa7e3061367f1d57a4e7455a"));
/* Test case 2 */
test_cipher_gcm(&nettle_aes128,
HL("00000000000000000000000000000000"),
test_gcm_aes(HL("00000000000000000000000000000000"),
HL(""),
HL("00000000000000000000000000000000"),
H("0388dace60b6a392f328c2b971b2fe78"),
......@@ -29,8 +85,7 @@ test_main(void)
H("ab6e47d42cec13bdf53a67b21257bddf"));
/* Test case 3 */
test_cipher_gcm(&nettle_aes128,
HL("feffe9928665731c6d6a8f9467308308"),
test_gcm_aes(HL("feffe9928665731c6d6a8f9467308308"),
HL(""),
HL("d9313225f88406e5a55909c5aff5269a"
"86a7a9531534f7da2e4c303d8a318a72"
......@@ -44,8 +99,7 @@ test_main(void)
H("4d5c2af327cd64a62cf35abd2ba6fab4"));
/* Test case 4 */
test_cipher_gcm(&nettle_aes128,
HL("feffe9928665731c6d6a8f9467308308"),
test_gcm_aes(HL("feffe9928665731c6d6a8f9467308308"),
HL("feedfacedeadbeeffeedfacedeadbeef"
"abaddad2"),
HL("d9313225f88406e5a55909c5aff5269a"
......@@ -62,8 +116,7 @@ test_main(void)
#if 0
/* Unsupported IV size. */
/* Test case 5 */
test_cipher_gcm(&nettle_aes128,
HL("feffe9928665731c6d6a8f9467308308"),
test_gcm_aes(HL("feffe9928665731c6d6a8f9467308308"),
HL("feedfacedeadbeeffeedfacedeadbeef"
"abaddad2"),
HL("d9313225f88406e5a55909c5aff5269a"
......@@ -78,8 +131,7 @@ test_main(void)
H("3612d2e79e3b0785561be14aaca2fccb"));
/* Test case 6 */
test_cipher_gcm(&nettle_aes128,
HL("feffe9928665731c6d6a8f9467308308"),
test_gcm_aes(HL("feffe9928665731c6d6a8f9467308308"),
HL("feedfacedeadbeeffeedfacedeadbeef"
"abaddad2"),
HL("d9313225f88406e5a55909c5aff5269a"
......
......@@ -296,71 +296,6 @@ test_cipher_ctr(const struct nettle_cipher *cipher,
free(ctr);
}
void
test_cipher_gcm(const struct nettle_cipher *cipher,
unsigned key_length,
const uint8_t *key,
unsigned auth_length,
const uint8_t *authtext,
unsigned length,
const uint8_t *cleartext,
const uint8_t *ciphertext,
unsigned iv_length,
const uint8_t *iv,
const uint8_t *digest)
{
struct gcm_ctx gctx;
void *cipher_ctx = xalloc(cipher->context_size);
uint8_t *data = xalloc(length);
uint8_t buffer[GCM_BLOCK_SIZE];
/* encryption */
memset(buffer, 0, sizeof(buffer));
cipher->set_encrypt_key(cipher_ctx, key_length, key);
gcm_set_key(&gctx, cipher_ctx, cipher->encrypt);
gcm_set_iv(&gctx, iv_length, iv);
if (auth_length)
gcm_auth(&gctx, auth_length, authtext);
if (length)
gcm_encrypt(&gctx, cipher_ctx, cipher->encrypt,
length, data, cleartext);
gcm_digest(&gctx, cipher_ctx, cipher->encrypt,
GCM_BLOCK_SIZE, buffer);
if (!MEMEQ(length, data, ciphertext))
FAIL();
if (!MEMEQ(GCM_BLOCK_SIZE, buffer, digest))
FAIL();
/* decryption */
memset(buffer, 0, sizeof(buffer));
gcm_set_iv(&gctx, iv_length, iv);
if (auth_length)
gcm_auth(&gctx, auth_length, authtext);
if (length)
gcm_decrypt(&gctx, cipher_ctx, cipher->encrypt,
length, data, data);
gcm_digest(&gctx, cipher_ctx, cipher->encrypt,
GCM_BLOCK_SIZE, buffer);
if (!MEMEQ(length, data, cleartext))
FAIL();
if (!MEMEQ(GCM_BLOCK_SIZE, buffer, digest))
FAIL();
free(cipher_ctx);
free(data);
}
void
test_cipher_stream(const struct nettle_cipher *cipher,
unsigned key_length,
......
......@@ -105,19 +105,6 @@ test_cipher_ctr(const struct nettle_cipher *cipher,
const uint8_t *ciphertext,
const uint8_t *iv);
void
test_cipher_gcm(const struct nettle_cipher *cipher,
unsigned key_length,
const uint8_t *key,
unsigned auth_length,
const uint8_t *authtext,
unsigned length,
const uint8_t *cleartext,
const uint8_t *ciphertext,
unsigned iv_length,
const uint8_t *iv,
const uint8_t *digest);
void
test_cipher_stream(const struct nettle_cipher *cipher,
unsigned key_length,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment