]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: anubis - stop using cra_alignmask
authorEric Biggers <ebiggers@google.com>
Sat, 7 Dec 2024 19:57:45 +0000 (11:57 -0800)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 14 Dec 2024 09:21:43 +0000 (17:21 +0800)
Instead of specifying a nonzero alignmask, use the unaligned access
helpers.  This eliminates unnecessary alignment operations on most CPUs,
which can handle unaligned accesses efficiently, and brings us a step
closer to eventually removing support for the alignmask field.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/anubis.c

index 9f0cf61bbc6e2638140045f3954a69e77498a4ea..886e7c91368864eeab7a435081041e11c96e9594 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/mm.h>
-#include <asm/byteorder.h>
+#include <linux/unaligned.h>
 #include <linux/types.h>
 
 #define ANUBIS_MIN_KEY_SIZE    16
@@ -463,7 +463,6 @@ static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
                         unsigned int key_len)
 {
        struct anubis_ctx *ctx = crypto_tfm_ctx(tfm);
-       const __be32 *key = (const __be32 *)in_key;
        int N, R, i, r;
        u32 kappa[ANUBIS_MAX_N];
        u32 inter[ANUBIS_MAX_N];
@@ -482,7 +481,7 @@ static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
 
        /* * map cipher key to initial key state (mu): */
        for (i = 0; i < N; i++)
-               kappa[i] = be32_to_cpu(key[i]);
+               kappa[i] = get_unaligned_be32(&in_key[4 * i]);
 
        /*
         * generate R + 1 round keys:
@@ -570,10 +569,8 @@ static int anubis_setkey(struct crypto_tfm *tfm, const u8 *in_key,
 }
 
 static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
-               u8 *ciphertext, const u8 *plaintext, const int R)
+                        u8 *dst, const u8 *src, const int R)
 {
-       const __be32 *src = (const __be32 *)plaintext;
-       __be32 *dst = (__be32 *)ciphertext;
        int i, r;
        u32 state[4];
        u32 inter[4];
@@ -583,7 +580,7 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
         * and add initial round key (sigma[K^0]):
         */
        for (i = 0; i < 4; i++)
-               state[i] = be32_to_cpu(src[i]) ^ roundKey[0][i];
+               state[i] = get_unaligned_be32(&src[4 * i]) ^ roundKey[0][i];
 
        /*
         * R - 1 full rounds:
@@ -654,7 +651,7 @@ static void anubis_crypt(u32 roundKey[ANUBIS_MAX_ROUNDS + 1][4],
         */
 
        for (i = 0; i < 4; i++)
-               dst[i] = cpu_to_be32(inter[i]);
+               put_unaligned_be32(inter[i], &dst[4 * i]);
 }
 
 static void anubis_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
@@ -675,7 +672,6 @@ static struct crypto_alg anubis_alg = {
        .cra_flags              =       CRYPTO_ALG_TYPE_CIPHER,
        .cra_blocksize          =       ANUBIS_BLOCK_SIZE,
        .cra_ctxsize            =       sizeof (struct anubis_ctx),
-       .cra_alignmask          =       3,
        .cra_module             =       THIS_MODULE,
        .cra_u                  =       { .cipher = {
        .cia_min_keysize        =       ANUBIS_MIN_KEY_SIZE,