Skip to content

Commit 0243299

Browse files
Merge pull request wolfSSL#8210 from night1rider/devcrypto-authtag-error
/dev/crypto auth error fix/adjustment for benchmark
2 parents 71abfa3 + 02e6ec0 commit 0243299

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

wolfcrypt/benchmark/benchmark.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,11 @@ static const char* bench_result_words2[][5] = {
19921992
#endif
19931993

19941994

1995+
1996+
#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
1997+
#warning Large/Unalligned AuthSz could result in errors with /dev/crypto
1998+
#endif
1999+
19952000
/* use kB instead of mB for embedded benchmarking */
19962001
#ifdef BENCH_EMBEDDED
19972002
#ifndef BENCH_NTIMES
@@ -4799,6 +4804,14 @@ void bench_gmac(int useDeviceID)
47994804
const char* gmacStr = "GMAC Default";
48004805
#endif
48014806

4807+
/* Implementations of /Dev/Crypto will error out if the size of Auth in is */
4808+
/* greater than the system's page size */
4809+
#if defined(WOLFSSL_DEVCRYPTO) && defined(WOLFSSL_AUTHSZ_BENCH)
4810+
bench_size = WOLFSSL_AUTHSZ_BENCH;
4811+
#elif defined(WOLFSSL_DEVCRYPTO)
4812+
bench_size = sysconf(_SC_PAGESIZE);
4813+
#endif
4814+
48024815
/* init keys */
48034816
XMEMSET(bench_plain, 0, bench_size);
48044817
XMEMSET(tag, 0, sizeof(tag));
@@ -4829,7 +4842,13 @@ void bench_gmac(int useDeviceID)
48294842
#ifdef MULTI_VALUE_STATISTICS
48304843
bench_multi_value_stats(max, min, sum, squareSum, runs);
48314844
#endif
4832-
4845+
#if defined(WOLFSSL_DEVCRYPTO)
4846+
if (ret != 0 && (bench_size > sysconf(_SC_PAGESIZE))) {
4847+
printf("authIn Buffer Size[%d] greater than System Page Size[%ld]\n",
4848+
bench_size, sysconf(_SC_PAGESIZE));
4849+
}
4850+
bench_size = BENCH_SIZE;
4851+
#endif
48334852
}
48344853

48354854
#endif /* HAVE_AESGCM */

wolfcrypt/src/port/devcrypto/devcrypto_aes.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ static int wc_DevCrypto_AesGcm(Aes* aes, byte* out, byte* in, word32 sz,
324324
dir, (byte*)authIn, authInSz, authTag, authTagSz);
325325
ret = ioctl(aes->ctx.cfd, CIOCAUTHCRYPT, &crt);
326326
if (ret != 0) {
327+
#ifdef WOLFSSL_DEBUG
328+
if (authInSz > sysconf(_SC_PAGESIZE)) {
329+
WOLFSSL_MSG("authIn Buffer greater than System Page Size");
330+
}
331+
#endif
327332
if (dir == COP_DECRYPT) {
328333
return AES_GCM_AUTH_E;
329334
}

0 commit comments

Comments
 (0)