Commit 1abba6a8 authored by Niels Möller's avatar Niels Möller

(test_aead): New function, replacing

test_gcm_aes and before that test_cipher_gcm.

Rev: nettle/testsuite/testutils.c:1.14
Rev: nettle/testsuite/testutils.h:1.8
parent 73b85dd0
......@@ -4,8 +4,8 @@
#include "cbc.h"
#include "ctr.h"
#include "gcm.h"
#include "knuth-lfib.h"
#include "nettle-internal.h"
#include <ctype.h>
#include <stdio.h>
......@@ -362,6 +362,66 @@ test_cipher_stream(const struct nettle_cipher *cipher,
free(data);
}
void
test_aead(const struct nettle_aead *aead,
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 *ctx = xalloc(aead->context_size);
uint8_t *data = xalloc(length);
uint8_t *buffer = xalloc(aead->block_size);
/* encryption */
memset(buffer, 0, aead->block_size);
aead->set_key(ctx, key_length, key);
aead->set_iv(ctx, iv_length, iv);
if (auth_length)
aead->update(ctx, auth_length, authtext);
if (length)
aead->encrypt(ctx, length, data, cleartext);
aead->digest(ctx, aead->block_size, buffer);
if (!MEMEQ(length, data, ciphertext))
FAIL();
if (!MEMEQ(aead->block_size, buffer, digest))
FAIL();
/* decryption */
memset(buffer, 0, aead->block_size);
aead->set_iv(ctx, iv_length, iv);
if (auth_length)
aead->update(ctx, auth_length, authtext);
if (length)
aead->decrypt(ctx, length, data, data);
aead->digest(ctx, aead->block_size, buffer);
if (!MEMEQ(length, data, cleartext))
FAIL();
if (!MEMEQ(aead->block_size, buffer, digest))
FAIL();
free(ctx);
free(data);
free(buffer);
}
void
test_hash(const struct nettle_hash *hash,
unsigned length,
......
......@@ -22,6 +22,9 @@
#include "nettle-meta.h"
/* Forward declare */
struct nettle_aead;
#ifdef __cplusplus
extern "C" {
#endif
......@@ -113,6 +116,19 @@ test_cipher_stream(const struct nettle_cipher *cipher,
const uint8_t *cleartext,
const uint8_t *ciphertext);
void
test_aead(const struct nettle_aead *aead,
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_hash(const struct nettle_hash *hash,
unsigned 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