Skip to content

Commit 02e6ec0

Browse files
night1ridermsi-debian
authored andcommitted
devcrypto auth error fix/adjustment
1 parent 92f587c commit 02e6ec0

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
@@ -1991,6 +1991,11 @@ static const char* bench_result_words2[][5] = {
19911991
#endif
19921992

19931993

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

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

48344853
#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)