From 02e6ec0c8696cbdcef1d1a4cd9b5969e4293bb43 Mon Sep 17 00:00:00 2001 From: night1rider Date: Thu, 21 Nov 2024 16:19:22 -0700 Subject: [PATCH] devcrypto auth error fix/adjustment --- wolfcrypt/benchmark/benchmark.c | 21 +++++++++++++++++++- wolfcrypt/src/port/devcrypto/devcrypto_aes.c | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index 8c29bc4329..55ba279725 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1991,6 +1991,11 @@ static const char* bench_result_words2[][5] = { #endif + +#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH) + #warning Large/Unalligned AuthSz could result in errors with /dev/crypto +#endif + /* use kB instead of mB for embedded benchmarking */ #ifdef BENCH_EMBEDDED #ifndef BENCH_NTIMES @@ -4798,6 +4803,14 @@ void bench_gmac(int useDeviceID) const char* gmacStr = "GMAC Default"; #endif +/* Implementations of /Dev/Crypto will error out if the size of Auth in is */ +/* greater than the system's page size */ +#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH) + bench_size = WOLFSSL_AUTHSZ_BENCH; +#elif defined(WOLFSSL_DEVCRYPTO) + bench_size = sysconf(_SC_PAGESIZE); +#endif + /* init keys */ XMEMSET(bench_plain, 0, bench_size); XMEMSET(tag, 0, sizeof(tag)); @@ -4828,7 +4841,13 @@ void bench_gmac(int useDeviceID) #ifdef MULTI_VALUE_STATISTICS bench_multi_value_stats(max, min, sum, squareSum, runs); #endif - +#if defined(WOLFSSL_DEVCRYPTO) + if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) { + printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n", + bench_size, sysconf(_SC_PAGESIZE)); + } + bench_size = BENCH_SIZE; +#endif } #endif /* HAVE_AESGCM */ diff --git a/wolfcrypt/src/port/devcrypto/devcrypto_aes.c b/wolfcrypt/src/port/devcrypto/devcrypto_aes.c index e2f7d6c444..6f5d9c7431 100644 --- a/wolfcrypt/src/port/devcrypto/devcrypto_aes.c +++ b/wolfcrypt/src/port/devcrypto/devcrypto_aes.c @@ -324,6 +324,11 @@ static int wc_DevCrypto_AesGcm(Aes* aes, byte* out, byte* in, word32 sz, dir, (byte*)authIn, authInSz, authTag, authTagSz); ret = ioctl(aes->ctx.cfd, CIOCAUTHCRYPT, &crt); if (ret != 0) { + #ifdef WOLFSSL_DEBUG + if (authInSz > sysconf(_SC_PAGESIZE)) { + WOLFSSL_MSG("authIn Buffer greater than System Page Size"); + } + #endif if (dir == COP_DECRYPT) { return AES_GCM_AUTH_E; }