Commit 92460565 by Sebastian Renner

Working on GCM

parent 4c3abfbd
...@@ -156,7 +156,7 @@ def main(argv): ...@@ -156,7 +156,7 @@ def main(argv):
try: try:
b = build(d, template_dir) b = build(d, template_dir)
test_script.write("echo \"TESTING %s\"\n" % d) test_script.write("echo \"TESTING %s\"\n" % d)
test_script.write("./test.py %s %s 2> %s | tee %s\n" % ( test_script.write("./test.py %s %s 2> %s | tee %s\n" %
t, t,
os.path.join(b, 'test'), os.path.join(b, 'test'),
os.path.join(b, 'test_stderr.log'), os.path.join(b, 'test_stderr.log'),
......
This source diff could not be displayed because it is too large. You can view the blob instead.
#define CRYPTO_KEYBYTES 16 #define CRYPTO_KEYBYTES 16
#define CRYPTO_NSECBYTES 0 #define CRYPTO_NSECBYTES 0
#define CRYPTO_NPUBBYTES 12 #define CRYPTO_NPUBBYTES 12
#define CRYPTO_ABYTES 0 #define CRYPTO_ABYTES 16
#define CRYPTO_NOOVERLAP 1 #define CRYPTO_NOOVERLAP 1
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#if defined(MBEDTLS_GCM_C) #if defined(MBEDTLS_GCM_C)
#include "gcm.h" #include "gcm.h"
#include "api.h"
#include "crypto_aead.h" #include "crypto_aead.h"
#include "platform_util.h" #include "platform_util.h"
...@@ -87,7 +88,6 @@ ...@@ -87,7 +88,6 @@
} }
#endif #endif
unsigned char tag_buf[16];
/* /*
...@@ -113,12 +113,16 @@ int crypto_aead_encrypt( ...@@ -113,12 +113,16 @@ int crypto_aead_encrypt(
{ {
mbedtls_gcm_context ctx; mbedtls_gcm_context ctx;
int ret; int ret;
unsigned long long mask = 15;
unsigned long long mlenp = (mlen + mask) & (~mask);
unsigned char tag_buf[CRYPTO_ABYTES];
*clen = mlenp + CRYPTO_ABYTES;
mbedtls_gcm_init( &ctx ); mbedtls_gcm_init( &ctx );
ret = mbedtls_gcm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, k, 128); ret = mbedtls_gcm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, k, 128);
ret = mbedtls_gcm_crypt_and_tag( &ctx, 1, mlen, npub, 12, ad, adlen, m, c, 16, tag_buf ); ret = mbedtls_gcm_crypt_and_tag( &ctx, 1, mlen, npub, 12, ad, adlen, m, c, 16, tag_buf );
mbedtls_gcm_free( &ctx ); mbedtls_gcm_free( &ctx );
memcpy(c + mlenp, tag_buf, CRYPTO_ABYTES);
return ret; return ret;
} }
...@@ -133,6 +137,11 @@ int crypto_aead_decrypt( ...@@ -133,6 +137,11 @@ int crypto_aead_decrypt(
{ {
mbedtls_gcm_context ctx; mbedtls_gcm_context ctx;
int ret; int ret;
unsigned char tag_buf[CRYPTO_ABYTES];
clen -= CRYPTO_ABYTES;
memcpy(tag_buf, c + clen, CRYPTO_ABYTES);
*mlen = clen;
mbedtls_gcm_init( &ctx ); mbedtls_gcm_init( &ctx );
ret = mbedtls_gcm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, k, 128); ret = mbedtls_gcm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, k, 128);
...@@ -830,7 +839,7 @@ int mbedtls_gcm_self_test( int verbose ) ...@@ -830,7 +839,7 @@ int mbedtls_gcm_self_test( int verbose )
{ {
mbedtls_gcm_context ctx; mbedtls_gcm_context ctx;
unsigned char buf[64]; unsigned char buf[64];
//unsigned char tag_buf[16]; unsigned char tag_buf[CRYPTO_ABYTES];
int i, j, ret; int i, j, ret;
mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES; mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
......
...@@ -84,7 +84,6 @@ int generate_test_vectors() ...@@ -84,7 +84,6 @@ int generate_test_vectors()
init_buffer(nonce, sizeof(nonce)); init_buffer(nonce, sizeof(nonce));
init_buffer(msg, sizeof(msg)); init_buffer(msg, sizeof(msg));
init_buffer(ad, sizeof(ad)); init_buffer(ad, sizeof(ad));
init_buffer(ct, sizeof(ct));
sprintf(fileName, "LWC_AEAD_KAT_%d_%d.txt", (CRYPTO_KEYBYTES * 8), (CRYPTO_NPUBBYTES * 8)); sprintf(fileName, "LWC_AEAD_KAT_%d_%d.txt", (CRYPTO_KEYBYTES * 8), (CRYPTO_NPUBBYTES * 8));
...@@ -97,7 +96,6 @@ int generate_test_vectors() ...@@ -97,7 +96,6 @@ int generate_test_vectors()
for (unsigned long long adlen = 0; adlen <= MAX_ASSOCIATED_DATA_LENGTH; adlen++) { for (unsigned long long adlen = 0; adlen <= MAX_ASSOCIATED_DATA_LENGTH; adlen++) {
clen = mlen;
fprintf(fp, "Count = %d\n", count++); fprintf(fp, "Count = %d\n", count++);
...@@ -119,10 +117,11 @@ int generate_test_vectors() ...@@ -119,10 +117,11 @@ int generate_test_vectors()
fprintf(fp, "\n"); fprintf(fp, "\n");
mlen2 = clen;
if ((func_ret = crypto_aead_decrypt(msg2, &mlen2, NULL, ct, clen, ad, adlen, nonce, key)) != 0) { if ((func_ret = crypto_aead_decrypt(msg2, &mlen2, NULL, ct, clen, ad, adlen, nonce, key)) != 0) {
fprintf(fp, "crypto_aead_decrypt returned <%d>\n", func_ret); fprintf(fp, "crypto_aead_decrypt returned <%d>\n", func_ret);
ret_val = KAT_CRYPTO_FAILURE; ret_val = KAT_CRYPTO_FAILURE;
fprint_bstr(fp, "PT = ", msg2, mlen2);
break; break;
} }
......
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