Commit ac254845 by Enrico Pozzobon

gcm tests ok

parent 639a1a89
This source diff could not be displayed because it is too large. You can view the blob instead.
CC=gcc
NISTGCCFLAGS=-std=c99 -Wall -Wextra -Wshadow -O2
NISTGCCFLAGS=-std=c99 -Wall -Wextra -Wshadow -fsanitize=address,undefined -O2
LFLAGS=-lm
all: gcm
......@@ -10,5 +11,6 @@ gcm: gcm.c genkat_aead.c aes.c cipher.c cipher_wrap.c platform.c platform_util.c
.PHONY: clean
clean:
rm -rf *.o
rm -rf gcm
......@@ -111,6 +111,7 @@ int crypto_aead_encrypt(
const unsigned char *k
)
{
(void) nsec;
mbedtls_gcm_context ctx;
int ret;
unsigned long long mask = 15;
......@@ -135,6 +136,7 @@ int crypto_aead_decrypt(
const unsigned char *k
)
{
(void) nsec;
mbedtls_gcm_context ctx;
int ret;
unsigned char tag_buf[CRYPTO_ABYTES];
......
......@@ -73,6 +73,7 @@ int generate_test_vectors()
unsigned char key[CRYPTO_KEYBYTES];
unsigned char nonce[CRYPTO_NPUBBYTES];
unsigned char msg[MAX_MESSAGE_LENGTH];
unsigned char msgbuf[MAX_MESSAGE_LENGTH];
unsigned char ct[MAX_MESSAGE_LENGTH + CRYPTO_ABYTES];
unsigned char msg2[MAX_MESSAGE_LENGTH];
unsigned char ad[MAX_ASSOCIATED_DATA_LENGTH];
......@@ -103,11 +104,16 @@ int generate_test_vectors()
fprint_bstr(fp, "Nonce = ", nonce, CRYPTO_NPUBBYTES);
fprint_bstr(fp, "PT = ", msg, mlen);
unsigned long long mlenp = ((mlen + 15) >> 4) << 4;
memset(msgbuf, 0, mlenp);
memcpy(msgbuf, msg, mlen);
fprint_bstr(fp, "PT = ", msgbuf, mlenp);
fprint_bstr(fp, "AD = ", ad, adlen);
if ((func_ret = crypto_aead_encrypt(ct, &clen, msg, mlen, ad, adlen, NULL, nonce, key)) != 0) {
if ((func_ret = crypto_aead_encrypt(ct, &clen, msgbuf, mlenp, ad, adlen, NULL, nonce, key)) != 0) {
fprintf(fp, "crypto_aead_encrypt returned <%d>\n", func_ret);
ret_val = KAT_CRYPTO_FAILURE;
break;
......@@ -125,13 +131,13 @@ int generate_test_vectors()
break;
}
if (mlen != mlen2) {
fprintf(fp, "crypto_aead_decrypt returned bad 'mlen': Got <%llu>, expected <%llu>\n", mlen2, mlen);
if (mlenp != mlen2) {
fprintf(fp, "crypto_aead_decrypt returned bad 'mlen': Got <%llu>, expected <%llu>\n", mlen2, mlenp);
ret_val = KAT_CRYPTO_FAILURE;
break;
}
if (memcmp(msg, msg2, mlen)) {
if (memcmp(msgbuf, msg2, mlenp)) {
fprintf(fp, "crypto_aead_decrypt did not recover the plaintext\n");
ret_val = KAT_CRYPTO_FAILURE;
break;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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 sign in to comment