From 6d4cb08acd70ed5a4fec99185afbcf8f927d053b Mon Sep 17 00:00:00 2001 From: Douglas Stebila Date: Thu, 20 Jun 2019 20:59:40 -0400 Subject: [PATCH 1/2] Update to PQClean AES release context --- src/common/pqclean_shims/aes.h | 18 ++++++++---------- .../pqclean_frodokem1344aes_clean/matrix_aes.c | 2 ++ .../pqclean_frodokem640aes_clean/matrix_aes.c | 2 ++ .../pqclean_frodokem976aes_clean/matrix_aes.c | 2 ++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/common/pqclean_shims/aes.h b/src/common/pqclean_shims/aes.h index 70c116b8c..fa801fec5 100644 --- a/src/common/pqclean_shims/aes.h +++ b/src/common/pqclean_shims/aes.h @@ -14,16 +14,14 @@ typedef void * aes128ctx; -static void aes128_keyexp(aes128ctx *r, const unsigned char *key) { - OQS_AES128_load_schedule(key, r, 1); -} +#define aes128_keyexp(r, key) OQS_AES128_load_schedule((key), (r), 1); +#define aes128_ecb(out, in, nblocks, ctx) OQS_AES128_ECB_enc_sch((in), (nblocks) * AES_BLOCKBYTES, *(ctx), (out)); +#define aes128_ctx_release(ctx) OQS_AES128_free_schedule(*(ctx)); -static void aes128_ecb(unsigned char *out, const unsigned char *in, size_t nblocks, aes128ctx *ctx) { - OQS_AES128_ECB_enc_sch(in, nblocks * AES_BLOCKBYTES, *ctx, out); - OQS_AES128_free_schedule(*ctx); - // FIXME: PQClean AES API expects that aes128_ecb can be called multiple - // times with the same key schedule, but this instantiation does not, since - // it frees the key schedule immediately -} +typedef void * aes256ctx; + +#define aes256_keyexp(r, key) OQS_AES256_load_schedule((key), (r), 1); +#define aes256_ecb(out, in, nblocks, ctx) OQS_AES256_ECB_enc_sch((in), (nblocks) * AES_BLOCKBYTES, *(ctx), (out)); +#define aes256_ctx_release(ctx) OQS_AES256_free_schedule(*(ctx)); #endif diff --git a/src/kem/frodokem/pqclean_frodokem1344aes_clean/matrix_aes.c b/src/kem/frodokem/pqclean_frodokem1344aes_clean/matrix_aes.c index 645901b05..7b9a830a7 100644 --- a/src/kem/frodokem/pqclean_frodokem1344aes_clean/matrix_aes.c +++ b/src/kem/frodokem/pqclean_frodokem1344aes_clean/matrix_aes.c @@ -33,6 +33,7 @@ int PQCLEAN_FRODOKEM1344AES_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16_ } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM1344AES_CLEAN_LE_TO_UINT16(A[i]); @@ -73,6 +74,7 @@ int PQCLEAN_FRODOKEM1344AES_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16_ } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM1344AES_CLEAN_LE_TO_UINT16(A[i]); diff --git a/src/kem/frodokem/pqclean_frodokem640aes_clean/matrix_aes.c b/src/kem/frodokem/pqclean_frodokem640aes_clean/matrix_aes.c index 65344e3d9..1858b7549 100644 --- a/src/kem/frodokem/pqclean_frodokem640aes_clean/matrix_aes.c +++ b/src/kem/frodokem/pqclean_frodokem640aes_clean/matrix_aes.c @@ -33,6 +33,7 @@ int PQCLEAN_FRODOKEM640AES_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16_t } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM640AES_CLEAN_LE_TO_UINT16(A[i]); @@ -73,6 +74,7 @@ int PQCLEAN_FRODOKEM640AES_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16_t } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM640AES_CLEAN_LE_TO_UINT16(A[i]); diff --git a/src/kem/frodokem/pqclean_frodokem976aes_clean/matrix_aes.c b/src/kem/frodokem/pqclean_frodokem976aes_clean/matrix_aes.c index 2596fc25d..f02ffb708 100644 --- a/src/kem/frodokem/pqclean_frodokem976aes_clean/matrix_aes.c +++ b/src/kem/frodokem/pqclean_frodokem976aes_clean/matrix_aes.c @@ -33,6 +33,7 @@ int PQCLEAN_FRODOKEM976AES_CLEAN_mul_add_as_plus_e(uint16_t *out, const uint16_t } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM976AES_CLEAN_LE_TO_UINT16(A[i]); @@ -73,6 +74,7 @@ int PQCLEAN_FRODOKEM976AES_CLEAN_mul_add_sa_plus_e(uint16_t *out, const uint16_t } aes128_ecb((uint8_t *) A, (uint8_t *) A, PARAMS_N * PARAMS_N * sizeof(int16_t) / AES_BLOCKBYTES, &ctx128); + aes128_ctx_release(&ctx128); for (i = 0; i < PARAMS_N * PARAMS_N; i++) { A[i] = PQCLEAN_FRODOKEM976AES_CLEAN_LE_TO_UINT16(A[i]); From e1d3335dd8026090a89968596ec41436bc95447a Mon Sep 17 00:00:00 2001 From: Douglas Stebila Date: Thu, 20 Jun 2019 21:17:17 -0400 Subject: [PATCH 2/2] Use oqs.h since oqsconfig.h not present on Windows --- src/crypto/aes/aes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/aes/aes.c b/src/crypto/aes/aes.c index b2d0efb3f..8df52c376 100644 --- a/src/crypto/aes/aes.c +++ b/src/crypto/aes/aes.c @@ -1,6 +1,6 @@ #include -#include +#include #include "aes.h" #include "aes_local.h"