diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2011-10-17 17:03:08 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2011-11-08 22:43:00 -0500 |
commit | bc83b8299cb4ac2a9f64215a04854e4c934d1510 (patch) | |
tree | 706503a1a84e12d0c5de95600ff65fa11cc799e8 | |
parent | 7fb7fe4469d0b870a031a5d33676343979b80625 (diff) |
crypto: serpent - export common functions for x86_64/i386-sse2 assembler implementations
Serpent SSE2 assembler implementations only provide 4-way/8-way parallel
functions and need setkey and one-block encrypt/decrypt functions.
CC: Dag Arne Osvik <osvik@ii.uib.no>
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/serpent.c | 41 | ||||
-rw-r--r-- | include/crypto/serpent.h | 25 |
2 files changed, 47 insertions, 19 deletions
diff --git a/crypto/serpent.c b/crypto/serpent.c index b651a55fa569..867ca93ebb63 100644 --- a/crypto/serpent.c +++ b/crypto/serpent.c | |||
@@ -21,16 +21,12 @@ | |||
21 | #include <asm/byteorder.h> | 21 | #include <asm/byteorder.h> |
22 | #include <linux/crypto.h> | 22 | #include <linux/crypto.h> |
23 | #include <linux/types.h> | 23 | #include <linux/types.h> |
24 | #include <crypto/serpent.h> | ||
24 | 25 | ||
25 | /* Key is padded to the maximum of 256 bits before round key generation. | 26 | /* Key is padded to the maximum of 256 bits before round key generation. |
26 | * Any key length <= 256 bits (32 bytes) is allowed by the algorithm. | 27 | * Any key length <= 256 bits (32 bytes) is allowed by the algorithm. |
27 | */ | 28 | */ |
28 | 29 | ||
29 | #define SERPENT_MIN_KEY_SIZE 0 | ||
30 | #define SERPENT_MAX_KEY_SIZE 32 | ||
31 | #define SERPENT_EXPKEY_WORDS 132 | ||
32 | #define SERPENT_BLOCK_SIZE 16 | ||
33 | |||
34 | #define PHI 0x9e3779b9UL | 30 | #define PHI 0x9e3779b9UL |
35 | 31 | ||
36 | #define keyiter(a,b,c,d,i,j) \ | 32 | #define keyiter(a,b,c,d,i,j) \ |
@@ -210,13 +206,7 @@ | |||
210 | x1 ^= x4; x3 ^= x4; x4 &= x0; \ | 206 | x1 ^= x4; x3 ^= x4; x4 &= x0; \ |
211 | x4 ^= x2; | 207 | x4 ^= x2; |
212 | 208 | ||
213 | struct serpent_ctx { | 209 | int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen) |
214 | u32 expkey[SERPENT_EXPKEY_WORDS]; | ||
215 | }; | ||
216 | |||
217 | |||
218 | static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
219 | unsigned int keylen) | ||
220 | { | 210 | { |
221 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); | 211 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); |
222 | u32 *k = ctx->expkey; | 212 | u32 *k = ctx->expkey; |
@@ -359,12 +349,11 @@ static int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
359 | 349 | ||
360 | return 0; | 350 | return 0; |
361 | } | 351 | } |
352 | EXPORT_SYMBOL_GPL(serpent_setkey); | ||
362 | 353 | ||
363 | static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 354 | void __serpent_encrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src) |
364 | { | 355 | { |
365 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); | 356 | const u32 *k = ctx->expkey; |
366 | const u32 | ||
367 | *k = ctx->expkey; | ||
368 | const __le32 *s = (const __le32 *)src; | 357 | const __le32 *s = (const __le32 *)src; |
369 | __le32 *d = (__le32 *)dst; | 358 | __le32 *d = (__le32 *)dst; |
370 | u32 r0, r1, r2, r3, r4; | 359 | u32 r0, r1, r2, r3, r4; |
@@ -418,12 +407,18 @@ static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
418 | d[2] = cpu_to_le32(r2); | 407 | d[2] = cpu_to_le32(r2); |
419 | d[3] = cpu_to_le32(r3); | 408 | d[3] = cpu_to_le32(r3); |
420 | } | 409 | } |
410 | EXPORT_SYMBOL_GPL(__serpent_encrypt); | ||
421 | 411 | ||
422 | static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 412 | static void serpent_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
423 | { | 413 | { |
424 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); | 414 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); |
425 | const u32 | 415 | |
426 | *k = ((struct serpent_ctx *)ctx)->expkey; | 416 | __serpent_encrypt(ctx, dst, src); |
417 | } | ||
418 | |||
419 | void __serpent_decrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src) | ||
420 | { | ||
421 | const u32 *k = ctx->expkey; | ||
427 | const __le32 *s = (const __le32 *)src; | 422 | const __le32 *s = (const __le32 *)src; |
428 | __le32 *d = (__le32 *)dst; | 423 | __le32 *d = (__le32 *)dst; |
429 | u32 r0, r1, r2, r3, r4; | 424 | u32 r0, r1, r2, r3, r4; |
@@ -472,6 +467,14 @@ static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | |||
472 | d[2] = cpu_to_le32(r1); | 467 | d[2] = cpu_to_le32(r1); |
473 | d[3] = cpu_to_le32(r4); | 468 | d[3] = cpu_to_le32(r4); |
474 | } | 469 | } |
470 | EXPORT_SYMBOL_GPL(__serpent_decrypt); | ||
471 | |||
472 | static void serpent_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | ||
473 | { | ||
474 | struct serpent_ctx *ctx = crypto_tfm_ctx(tfm); | ||
475 | |||
476 | __serpent_decrypt(ctx, dst, src); | ||
477 | } | ||
475 | 478 | ||
476 | static struct crypto_alg serpent_alg = { | 479 | static struct crypto_alg serpent_alg = { |
477 | .cra_name = "serpent", | 480 | .cra_name = "serpent", |
diff --git a/include/crypto/serpent.h b/include/crypto/serpent.h new file mode 100644 index 000000000000..40df885f9d1f --- /dev/null +++ b/include/crypto/serpent.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * Common values for serpent algorithms | ||
3 | */ | ||
4 | |||
5 | #ifndef _CRYPTO_SERPENT_H | ||
6 | #define _CRYPTO_SERPENT_H | ||
7 | |||
8 | #include <linux/types.h> | ||
9 | #include <linux/crypto.h> | ||
10 | |||
11 | #define SERPENT_MIN_KEY_SIZE 0 | ||
12 | #define SERPENT_MAX_KEY_SIZE 32 | ||
13 | #define SERPENT_EXPKEY_WORDS 132 | ||
14 | #define SERPENT_BLOCK_SIZE 16 | ||
15 | |||
16 | struct serpent_ctx { | ||
17 | u32 expkey[SERPENT_EXPKEY_WORDS]; | ||
18 | }; | ||
19 | |||
20 | int serpent_setkey(struct crypto_tfm *tfm, const u8 *key, unsigned int keylen); | ||
21 | |||
22 | void __serpent_encrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src); | ||
23 | void __serpent_decrypt(struct serpent_ctx *ctx, u8 *dst, const u8 *src); | ||
24 | |||
25 | #endif | ||