Date: Mon, 18 Jan 2021 22:08:18 GMT From: Mark Johnston <markj@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 098c902b5202 - main - aesni: Ensure that key schedules are aligned Message-ID: <202101182208.10IM8IVm039290@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=098c902b52022a8ed53600727cca2f06086305c0 commit 098c902b52022a8ed53600727cca2f06086305c0 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2021-01-18 22:07:56 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2021-01-18 22:07:56 +0000 aesni: Ensure that key schedules are aligned Rather than depending on malloc() returning 16-byte aligned chunks, allocate some extra pad bytes and ensure that key schedules are appropriately aligned. Reviewed by: kib MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC (Netgate) Differential Revision: https://reviews.freebsd.org/D28157 --- sys/crypto/aesni/aesni.c | 7 +++++++ sys/crypto/aesni/aesni.h | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sys/crypto/aesni/aesni.c b/sys/crypto/aesni/aesni.c index 709d1558ee84..4debbae12c2b 100644 --- a/sys/crypto/aesni/aesni.c +++ b/sys/crypto/aesni/aesni.c @@ -560,8 +560,15 @@ aesni_cipher_setup(struct aesni_session *ses, const struct crypto_session_params *csp) { struct fpu_kern_ctx *ctx; + uint8_t *schedbase; int kt, ctxidx, error; + schedbase = (uint8_t *)roundup2((uintptr_t)ses->schedules, + AES_SCHED_ALIGN); + ses->enc_schedule = schedbase; + ses->dec_schedule = schedbase + AES_SCHED_LEN; + ses->xts_schedule = schedbase + AES_SCHED_LEN * 2; + switch (csp->csp_auth_alg) { case CRYPTO_SHA1_HMAC: ses->hmac = true; diff --git a/sys/crypto/aesni/aesni.h b/sys/crypto/aesni/aesni.h index ef1a6635f6ad..284bf6fba0fc 100644 --- a/sys/crypto/aesni/aesni.h +++ b/sys/crypto/aesni/aesni.h @@ -47,11 +47,13 @@ #define AES192_ROUNDS 12 #define AES256_ROUNDS 14 #define AES_SCHED_LEN ((AES256_ROUNDS + 1) * AES_BLOCK_LEN) +#define AES_SCHED_ALIGN 16 struct aesni_session { - uint8_t enc_schedule[AES_SCHED_LEN] __aligned(16); - uint8_t dec_schedule[AES_SCHED_LEN] __aligned(16); - uint8_t xts_schedule[AES_SCHED_LEN] __aligned(16); + uint8_t schedules[3 * AES_SCHED_LEN + AES_SCHED_ALIGN]; + uint8_t *enc_schedule; + uint8_t *dec_schedule; + uint8_t *xts_schedule; int rounds; /* uint8_t *ses_ictx; */ /* uint8_t *ses_octx; */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101182208.10IM8IVm039290>