Skip to content
Snippets Groups Projects
Commit d61ae2d8 authored by Nikos Mavrogiannopoulos's avatar Nikos Mavrogiannopoulos Committed by Niels Möller
Browse files

(test_cipher_gcm): New function, contributed by Nikos

Mavrogiannopoulos.

Rev: nettle/testsuite/testutils.c:1.12
Rev: nettle/testsuite/testutils.h:1.6
parent a02f87ec
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@
#include "cbc.h"
#include "ctr.h"
#include "gcm.h"
#include "knuth-lfib.h"
#include <ctype.h>
......@@ -295,6 +296,71 @@ 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,6 +105,19 @@ 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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment