Commit ac254845 by Enrico Pozzobon

gcm tests ok

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