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

crypto: aria - prepare generic module for optimized implementations

It renames aria to aria_generic and exports some functions such as
aria_set_key(), aria_encrypt(), and aria_decrypt() to be able to be
used by aria-avx implementation.

Signed-off-by: Taehee Yoo <ap420073@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Taehee Yoo and committed by
Herbert Xu
a9b0838d 4532f1cf

+40 -18
+1 -1
crypto/Makefile
··· 149 149 obj-$(CONFIG_CRYPTO_KHAZAD) += khazad.o 150 150 obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o 151 151 obj-$(CONFIG_CRYPTO_SEED) += seed.o 152 - obj-$(CONFIG_CRYPTO_ARIA) += aria.o 152 + obj-$(CONFIG_CRYPTO_ARIA) += aria_generic.o 153 153 obj-$(CONFIG_CRYPTO_CHACHA20) += chacha_generic.o 154 154 obj-$(CONFIG_CRYPTO_POLY1305) += poly1305_generic.o 155 155 obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
+32 -7
crypto/aria.c crypto/aria_generic.c
··· 16 16 17 17 #include <crypto/aria.h> 18 18 19 + static const u32 key_rc[20] = { 20 + 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0, 21 + 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0, 22 + 0xdb92371d, 0x2126e970, 0x03249775, 0x04e8c90e, 23 + 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0, 24 + 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 25 + }; 26 + 19 27 static void aria_set_encrypt_key(struct aria_ctx *ctx, const u8 *in_key, 20 28 unsigned int key_len) 21 29 { ··· 33 25 const u32 *ck; 34 26 int rkidx = 0; 35 27 36 - ck = &key_rc[(key_len - 16) / 8][0]; 28 + ck = &key_rc[(key_len - 16) / 2]; 37 29 38 30 w0[0] = be32_to_cpu(key[0]); 39 31 w0[1] = be32_to_cpu(key[1]); ··· 171 163 } 172 164 } 173 165 174 - static int aria_set_key(struct crypto_tfm *tfm, const u8 *in_key, 175 - unsigned int key_len) 166 + int aria_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len) 176 167 { 177 168 struct aria_ctx *ctx = crypto_tfm_ctx(tfm); 178 169 ··· 186 179 187 180 return 0; 188 181 } 182 + EXPORT_SYMBOL_GPL(aria_set_key); 189 183 190 184 static void __aria_crypt(struct aria_ctx *ctx, u8 *out, const u8 *in, 191 185 u32 key[][ARIA_RD_KEY_WORDS]) ··· 243 235 dst[3] = cpu_to_be32(reg3); 244 236 } 245 237 246 - static void aria_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 238 + void aria_encrypt(void *_ctx, u8 *out, const u8 *in) 239 + { 240 + struct aria_ctx *ctx = (struct aria_ctx *)_ctx; 241 + 242 + __aria_crypt(ctx, out, in, ctx->enc_key); 243 + } 244 + EXPORT_SYMBOL_GPL(aria_encrypt); 245 + 246 + void aria_decrypt(void *_ctx, u8 *out, const u8 *in) 247 + { 248 + struct aria_ctx *ctx = (struct aria_ctx *)_ctx; 249 + 250 + __aria_crypt(ctx, out, in, ctx->dec_key); 251 + } 252 + EXPORT_SYMBOL_GPL(aria_decrypt); 253 + 254 + static void __aria_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 247 255 { 248 256 struct aria_ctx *ctx = crypto_tfm_ctx(tfm); 249 257 250 258 __aria_crypt(ctx, out, in, ctx->enc_key); 251 259 } 252 260 253 - static void aria_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 261 + static void __aria_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in) 254 262 { 255 263 struct aria_ctx *ctx = crypto_tfm_ctx(tfm); 256 264 ··· 287 263 .cia_min_keysize = ARIA_MIN_KEY_SIZE, 288 264 .cia_max_keysize = ARIA_MAX_KEY_SIZE, 289 265 .cia_setkey = aria_set_key, 290 - .cia_encrypt = aria_encrypt, 291 - .cia_decrypt = aria_decrypt 266 + .cia_encrypt = __aria_encrypt, 267 + .cia_decrypt = __aria_decrypt 292 268 } 293 269 } 294 270 }; ··· 310 286 MODULE_LICENSE("GPL"); 311 287 MODULE_AUTHOR("Taehee Yoo <ap420073@gmail.com>"); 312 288 MODULE_ALIAS_CRYPTO("aria"); 289 + MODULE_ALIAS_CRYPTO("aria-generic");
+7 -10
include/crypto/aria.h
··· 32 32 #define ARIA_RD_KEY_WORDS (ARIA_BLOCK_SIZE / sizeof(u32)) 33 33 34 34 struct aria_ctx { 35 - int key_length; 36 - int rounds; 37 35 u32 enc_key[ARIA_MAX_RD_KEYS][ARIA_RD_KEY_WORDS]; 38 36 u32 dec_key[ARIA_MAX_RD_KEYS][ARIA_RD_KEY_WORDS]; 39 - }; 40 - 41 - static const u32 key_rc[5][4] = { 42 - { 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0 }, 43 - { 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 }, 44 - { 0xdb92371d, 0x2126e970, 0x03249775, 0x04e8c90e }, 45 - { 0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0 }, 46 - { 0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0 } 37 + int rounds; 38 + int key_length; 47 39 }; 48 40 49 41 static const u32 s1[256] = { ··· 449 457 ((y[(q + 3) % 4]) >> r) ^ 450 458 ((y[(q + 2) % 4]) << (32 - r)); 451 459 } 460 + 461 + void aria_encrypt(void *ctx, u8 *out, const u8 *in); 462 + void aria_decrypt(void *ctx, u8 *out, const u8 *in); 463 + int aria_set_key(struct crypto_tfm *tfm, const u8 *in_key, 464 + unsigned int key_len); 452 465 453 466 #endif