The branch main has been updated by markj:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=098c902b52022a8ed53600727cca2f06086305c0

commit 098c902b52022a8ed53600727cca2f06086305c0
Author:     Mark Johnston <ma...@freebsd.org>
AuthorDate: 2021-01-18 22:07:56 +0000
Commit:     Mark Johnston <ma...@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; */
_______________________________________________
dev-commits-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "dev-commits-src-all-unsubscr...@freebsd.org"

Reply via email to