Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: tea - stop using cra_alignmask

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>

authored by

Eric Biggers and committed by
Herbert Xu
5e252f49 6c178fd6

+33 -50
+33 -50
crypto/tea.c
··· 18 18 #include <linux/init.h> 19 19 #include <linux/module.h> 20 20 #include <linux/mm.h> 21 - #include <asm/byteorder.h> 21 + #include <linux/unaligned.h> 22 22 #include <linux/types.h> 23 23 24 24 #define TEA_KEY_SIZE 16 ··· 43 43 unsigned int key_len) 44 44 { 45 45 struct tea_ctx *ctx = crypto_tfm_ctx(tfm); 46 - const __le32 *key = (const __le32 *)in_key; 47 46 48 - ctx->KEY[0] = le32_to_cpu(key[0]); 49 - ctx->KEY[1] = le32_to_cpu(key[1]); 50 - ctx->KEY[2] = le32_to_cpu(key[2]); 51 - ctx->KEY[3] = le32_to_cpu(key[3]); 47 + ctx->KEY[0] = get_unaligned_le32(&in_key[0]); 48 + ctx->KEY[1] = get_unaligned_le32(&in_key[4]); 49 + ctx->KEY[2] = get_unaligned_le32(&in_key[8]); 50 + ctx->KEY[3] = get_unaligned_le32(&in_key[12]); 52 51 53 52 return 0; 54 53 ··· 58 59 u32 y, z, n, sum = 0; 59 60 u32 k0, k1, k2, k3; 60 61 struct tea_ctx *ctx = crypto_tfm_ctx(tfm); 61 - const __le32 *in = (const __le32 *)src; 62 - __le32 *out = (__le32 *)dst; 63 62 64 - y = le32_to_cpu(in[0]); 65 - z = le32_to_cpu(in[1]); 63 + y = get_unaligned_le32(&src[0]); 64 + z = get_unaligned_le32(&src[4]); 66 65 67 66 k0 = ctx->KEY[0]; 68 67 k1 = ctx->KEY[1]; ··· 75 78 z += ((y << 4) + k2) ^ (y + sum) ^ ((y >> 5) + k3); 76 79 } 77 80 78 - out[0] = cpu_to_le32(y); 79 - out[1] = cpu_to_le32(z); 81 + put_unaligned_le32(y, &dst[0]); 82 + put_unaligned_le32(z, &dst[4]); 80 83 } 81 84 82 85 static void tea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) ··· 84 87 u32 y, z, n, sum; 85 88 u32 k0, k1, k2, k3; 86 89 struct tea_ctx *ctx = crypto_tfm_ctx(tfm); 87 - const __le32 *in = (const __le32 *)src; 88 - __le32 *out = (__le32 *)dst; 89 90 90 - y = le32_to_cpu(in[0]); 91 - z = le32_to_cpu(in[1]); 91 + y = get_unaligned_le32(&src[0]); 92 + z = get_unaligned_le32(&src[4]); 92 93 93 94 k0 = ctx->KEY[0]; 94 95 k1 = ctx->KEY[1]; ··· 103 108 sum -= TEA_DELTA; 104 109 } 105 110 106 - out[0] = cpu_to_le32(y); 107 - out[1] = cpu_to_le32(z); 111 + put_unaligned_le32(y, &dst[0]); 112 + put_unaligned_le32(z, &dst[4]); 108 113 } 109 114 110 115 static int xtea_setkey(struct crypto_tfm *tfm, const u8 *in_key, 111 116 unsigned int key_len) 112 117 { 113 118 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm); 114 - const __le32 *key = (const __le32 *)in_key; 115 119 116 - ctx->KEY[0] = le32_to_cpu(key[0]); 117 - ctx->KEY[1] = le32_to_cpu(key[1]); 118 - ctx->KEY[2] = le32_to_cpu(key[2]); 119 - ctx->KEY[3] = le32_to_cpu(key[3]); 120 + ctx->KEY[0] = get_unaligned_le32(&in_key[0]); 121 + ctx->KEY[1] = get_unaligned_le32(&in_key[4]); 122 + ctx->KEY[2] = get_unaligned_le32(&in_key[8]); 123 + ctx->KEY[3] = get_unaligned_le32(&in_key[12]); 120 124 121 125 return 0; 122 126 ··· 126 132 u32 y, z, sum = 0; 127 133 u32 limit = XTEA_DELTA * XTEA_ROUNDS; 128 134 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm); 129 - const __le32 *in = (const __le32 *)src; 130 - __le32 *out = (__le32 *)dst; 131 135 132 - y = le32_to_cpu(in[0]); 133 - z = le32_to_cpu(in[1]); 136 + y = get_unaligned_le32(&src[0]); 137 + z = get_unaligned_le32(&src[4]); 134 138 135 139 while (sum != limit) { 136 140 y += ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum&3]); ··· 136 144 z += ((y << 4 ^ y >> 5) + y) ^ (sum + ctx->KEY[sum>>11 &3]); 137 145 } 138 146 139 - out[0] = cpu_to_le32(y); 140 - out[1] = cpu_to_le32(z); 147 + put_unaligned_le32(y, &dst[0]); 148 + put_unaligned_le32(z, &dst[4]); 141 149 } 142 150 143 151 static void xtea_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 144 152 { 145 153 u32 y, z, sum; 146 154 struct tea_ctx *ctx = crypto_tfm_ctx(tfm); 147 - const __le32 *in = (const __le32 *)src; 148 - __le32 *out = (__le32 *)dst; 149 155 150 - y = le32_to_cpu(in[0]); 151 - z = le32_to_cpu(in[1]); 156 + y = get_unaligned_le32(&src[0]); 157 + z = get_unaligned_le32(&src[4]); 152 158 153 159 sum = XTEA_DELTA * XTEA_ROUNDS; 154 160 ··· 156 166 y -= ((z << 4 ^ z >> 5) + z) ^ (sum + ctx->KEY[sum & 3]); 157 167 } 158 168 159 - out[0] = cpu_to_le32(y); 160 - out[1] = cpu_to_le32(z); 169 + put_unaligned_le32(y, &dst[0]); 170 + put_unaligned_le32(z, &dst[4]); 161 171 } 162 172 163 173 ··· 166 176 u32 y, z, sum = 0; 167 177 u32 limit = XTEA_DELTA * XTEA_ROUNDS; 168 178 struct xtea_ctx *ctx = crypto_tfm_ctx(tfm); 169 - const __le32 *in = (const __le32 *)src; 170 - __le32 *out = (__le32 *)dst; 171 179 172 - y = le32_to_cpu(in[0]); 173 - z = le32_to_cpu(in[1]); 180 + y = get_unaligned_le32(&src[0]); 181 + z = get_unaligned_le32(&src[4]); 174 182 175 183 while (sum != limit) { 176 184 y += (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum&3]; ··· 176 188 z += (y << 4 ^ y >> 5) + (y ^ sum) + ctx->KEY[sum>>11 &3]; 177 189 } 178 190 179 - out[0] = cpu_to_le32(y); 180 - out[1] = cpu_to_le32(z); 191 + put_unaligned_le32(y, &dst[0]); 192 + put_unaligned_le32(z, &dst[4]); 181 193 } 182 194 183 195 static void xeta_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 184 196 { 185 197 u32 y, z, sum; 186 198 struct tea_ctx *ctx = crypto_tfm_ctx(tfm); 187 - const __le32 *in = (const __le32 *)src; 188 - __le32 *out = (__le32 *)dst; 189 199 190 - y = le32_to_cpu(in[0]); 191 - z = le32_to_cpu(in[1]); 200 + y = get_unaligned_le32(&src[0]); 201 + z = get_unaligned_le32(&src[4]); 192 202 193 203 sum = XTEA_DELTA * XTEA_ROUNDS; 194 204 ··· 196 210 y -= (z << 4 ^ z >> 5) + (z ^ sum) + ctx->KEY[sum & 3]; 197 211 } 198 212 199 - out[0] = cpu_to_le32(y); 200 - out[1] = cpu_to_le32(z); 213 + put_unaligned_le32(y, &dst[0]); 214 + put_unaligned_le32(z, &dst[4]); 201 215 } 202 216 203 217 static struct crypto_alg tea_algs[3] = { { ··· 206 220 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 207 221 .cra_blocksize = TEA_BLOCK_SIZE, 208 222 .cra_ctxsize = sizeof (struct tea_ctx), 209 - .cra_alignmask = 3, 210 223 .cra_module = THIS_MODULE, 211 224 .cra_u = { .cipher = { 212 225 .cia_min_keysize = TEA_KEY_SIZE, ··· 219 234 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 220 235 .cra_blocksize = XTEA_BLOCK_SIZE, 221 236 .cra_ctxsize = sizeof (struct xtea_ctx), 222 - .cra_alignmask = 3, 223 237 .cra_module = THIS_MODULE, 224 238 .cra_u = { .cipher = { 225 239 .cia_min_keysize = XTEA_KEY_SIZE, ··· 232 248 .cra_flags = CRYPTO_ALG_TYPE_CIPHER, 233 249 .cra_blocksize = XTEA_BLOCK_SIZE, 234 250 .cra_ctxsize = sizeof (struct xtea_ctx), 235 - .cra_alignmask = 3, 236 251 .cra_module = THIS_MODULE, 237 252 .cra_u = { .cipher = { 238 253 .cia_min_keysize = XTEA_KEY_SIZE,