diff options
author | Jussi Kivilinna <jussi.kivilinna@mbnet.fi> | 2012-10-26 07:48:56 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2012-11-09 04:32:31 -0500 |
commit | cf582ccedad02eb9bfdcdb25adfc800dd117b428 (patch) | |
tree | 61337d49d10f40440da57a3ce49355b2b015124b /arch/x86/crypto | |
parent | bf9c5181865f1cc12f934eac182bbd06438ffecc (diff) |
crypto: camellia-x86_64 - share common functions and move structures and function definitions to header file
Prepare camellia-x86_64 functions to be reused from AVX/AESNI implementation
module.
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'arch/x86/crypto')
-rw-r--r-- | arch/x86/crypto/camellia_glue.c | 80 |
1 files changed, 23 insertions, 57 deletions
diff --git a/arch/x86/crypto/camellia_glue.c b/arch/x86/crypto/camellia_glue.c index 021a0086186b..5cb86ccd4acb 100644 --- a/arch/x86/crypto/camellia_glue.c +++ b/arch/x86/crypto/camellia_glue.c | |||
@@ -32,53 +32,24 @@ | |||
32 | #include <crypto/algapi.h> | 32 | #include <crypto/algapi.h> |
33 | #include <crypto/lrw.h> | 33 | #include <crypto/lrw.h> |
34 | #include <crypto/xts.h> | 34 | #include <crypto/xts.h> |
35 | #include <asm/crypto/camellia.h> | ||
35 | #include <asm/crypto/glue_helper.h> | 36 | #include <asm/crypto/glue_helper.h> |
36 | 37 | ||
37 | #define CAMELLIA_MIN_KEY_SIZE 16 | ||
38 | #define CAMELLIA_MAX_KEY_SIZE 32 | ||
39 | #define CAMELLIA_BLOCK_SIZE 16 | ||
40 | #define CAMELLIA_TABLE_BYTE_LEN 272 | ||
41 | |||
42 | struct camellia_ctx { | ||
43 | u64 key_table[CAMELLIA_TABLE_BYTE_LEN / sizeof(u64)]; | ||
44 | u32 key_length; | ||
45 | }; | ||
46 | |||
47 | /* regular block cipher functions */ | 38 | /* regular block cipher functions */ |
48 | asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst, | 39 | asmlinkage void __camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst, |
49 | const u8 *src, bool xor); | 40 | const u8 *src, bool xor); |
41 | EXPORT_SYMBOL_GPL(__camellia_enc_blk); | ||
50 | asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst, | 42 | asmlinkage void camellia_dec_blk(struct camellia_ctx *ctx, u8 *dst, |
51 | const u8 *src); | 43 | const u8 *src); |
44 | EXPORT_SYMBOL_GPL(camellia_dec_blk); | ||
52 | 45 | ||
53 | /* 2-way parallel cipher functions */ | 46 | /* 2-way parallel cipher functions */ |
54 | asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst, | 47 | asmlinkage void __camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst, |
55 | const u8 *src, bool xor); | 48 | const u8 *src, bool xor); |
49 | EXPORT_SYMBOL_GPL(__camellia_enc_blk_2way); | ||
56 | asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst, | 50 | asmlinkage void camellia_dec_blk_2way(struct camellia_ctx *ctx, u8 *dst, |
57 | const u8 *src); | 51 | const u8 *src); |
58 | 52 | EXPORT_SYMBOL_GPL(camellia_dec_blk_2way); | |
59 | static inline void camellia_enc_blk(struct camellia_ctx *ctx, u8 *dst, | ||
60 | const u8 *src) | ||
61 | { | ||
62 | __camellia_enc_blk(ctx, dst, src, false); | ||
63 | } | ||
64 | |||
65 | static inline void camellia_enc_blk_xor(struct camellia_ctx *ctx, u8 *dst, | ||
66 | const u8 *src) | ||
67 | { | ||
68 | __camellia_enc_blk(ctx, dst, src, true); | ||
69 | } | ||
70 | |||
71 | static inline void camellia_enc_blk_2way(struct camellia_ctx *ctx, u8 *dst, | ||
72 | const u8 *src) | ||
73 | { | ||
74 | __camellia_enc_blk_2way(ctx, dst, src, false); | ||
75 | } | ||
76 | |||
77 | static inline void camellia_enc_blk_xor_2way(struct camellia_ctx *ctx, u8 *dst, | ||
78 | const u8 *src) | ||
79 | { | ||
80 | __camellia_enc_blk_2way(ctx, dst, src, true); | ||
81 | } | ||
82 | 53 | ||
83 | static void camellia_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) | 54 | static void camellia_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) |
84 | { | 55 | { |
@@ -1275,9 +1246,8 @@ static void camellia_setup192(const unsigned char *key, u64 *subkey) | |||
1275 | camellia_setup256(kk, subkey); | 1246 | camellia_setup256(kk, subkey); |
1276 | } | 1247 | } |
1277 | 1248 | ||
1278 | static int __camellia_setkey(struct camellia_ctx *cctx, | 1249 | int __camellia_setkey(struct camellia_ctx *cctx, const unsigned char *key, |
1279 | const unsigned char *key, | 1250 | unsigned int key_len, u32 *flags) |
1280 | unsigned int key_len, u32 *flags) | ||
1281 | { | 1251 | { |
1282 | if (key_len != 16 && key_len != 24 && key_len != 32) { | 1252 | if (key_len != 16 && key_len != 24 && key_len != 32) { |
1283 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; | 1253 | *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN; |
@@ -1300,6 +1270,7 @@ static int __camellia_setkey(struct camellia_ctx *cctx, | |||
1300 | 1270 | ||
1301 | return 0; | 1271 | return 0; |
1302 | } | 1272 | } |
1273 | EXPORT_SYMBOL_GPL(__camellia_setkey); | ||
1303 | 1274 | ||
1304 | static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, | 1275 | static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, |
1305 | unsigned int key_len) | 1276 | unsigned int key_len) |
@@ -1308,7 +1279,7 @@ static int camellia_setkey(struct crypto_tfm *tfm, const u8 *in_key, | |||
1308 | &tfm->crt_flags); | 1279 | &tfm->crt_flags); |
1309 | } | 1280 | } |
1310 | 1281 | ||
1311 | static void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src) | 1282 | void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src) |
1312 | { | 1283 | { |
1313 | u128 iv = *src; | 1284 | u128 iv = *src; |
1314 | 1285 | ||
@@ -1316,8 +1287,9 @@ static void camellia_decrypt_cbc_2way(void *ctx, u128 *dst, const u128 *src) | |||
1316 | 1287 | ||
1317 | u128_xor(&dst[1], &dst[1], &iv); | 1288 | u128_xor(&dst[1], &dst[1], &iv); |
1318 | } | 1289 | } |
1290 | EXPORT_SYMBOL_GPL(camellia_decrypt_cbc_2way); | ||
1319 | 1291 | ||
1320 | static void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) | 1292 | void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
1321 | { | 1293 | { |
1322 | be128 ctrblk; | 1294 | be128 ctrblk; |
1323 | 1295 | ||
@@ -1329,9 +1301,9 @@ static void camellia_crypt_ctr(void *ctx, u128 *dst, const u128 *src, le128 *iv) | |||
1329 | 1301 | ||
1330 | camellia_enc_blk_xor(ctx, (u8 *)dst, (u8 *)&ctrblk); | 1302 | camellia_enc_blk_xor(ctx, (u8 *)dst, (u8 *)&ctrblk); |
1331 | } | 1303 | } |
1304 | EXPORT_SYMBOL_GPL(camellia_crypt_ctr); | ||
1332 | 1305 | ||
1333 | static void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src, | 1306 | void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src, le128 *iv) |
1334 | le128 *iv) | ||
1335 | { | 1307 | { |
1336 | be128 ctrblks[2]; | 1308 | be128 ctrblks[2]; |
1337 | 1309 | ||
@@ -1347,6 +1319,7 @@ static void camellia_crypt_ctr_2way(void *ctx, u128 *dst, const u128 *src, | |||
1347 | 1319 | ||
1348 | camellia_enc_blk_xor_2way(ctx, (u8 *)dst, (u8 *)ctrblks); | 1320 | camellia_enc_blk_xor_2way(ctx, (u8 *)dst, (u8 *)ctrblks); |
1349 | } | 1321 | } |
1322 | EXPORT_SYMBOL_GPL(camellia_crypt_ctr_2way); | ||
1350 | 1323 | ||
1351 | static const struct common_glue_ctx camellia_enc = { | 1324 | static const struct common_glue_ctx camellia_enc = { |
1352 | .num_funcs = 2, | 1325 | .num_funcs = 2, |
@@ -1464,13 +1437,8 @@ static void decrypt_callback(void *priv, u8 *srcdst, unsigned int nbytes) | |||
1464 | camellia_dec_blk(ctx, srcdst, srcdst); | 1437 | camellia_dec_blk(ctx, srcdst, srcdst); |
1465 | } | 1438 | } |
1466 | 1439 | ||
1467 | struct camellia_lrw_ctx { | 1440 | int lrw_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, |
1468 | struct lrw_table_ctx lrw_table; | 1441 | unsigned int keylen) |
1469 | struct camellia_ctx camellia_ctx; | ||
1470 | }; | ||
1471 | |||
1472 | static int lrw_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
1473 | unsigned int keylen) | ||
1474 | { | 1442 | { |
1475 | struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm); | 1443 | struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm); |
1476 | int err; | 1444 | int err; |
@@ -1484,6 +1452,7 @@ static int lrw_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
1484 | return lrw_init_table(&ctx->lrw_table, | 1452 | return lrw_init_table(&ctx->lrw_table, |
1485 | key + keylen - CAMELLIA_BLOCK_SIZE); | 1453 | key + keylen - CAMELLIA_BLOCK_SIZE); |
1486 | } | 1454 | } |
1455 | EXPORT_SYMBOL_GPL(lrw_camellia_setkey); | ||
1487 | 1456 | ||
1488 | static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | 1457 | static int lrw_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, |
1489 | struct scatterlist *src, unsigned int nbytes) | 1458 | struct scatterlist *src, unsigned int nbytes) |
@@ -1519,20 +1488,16 @@ static int lrw_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | |||
1519 | return lrw_crypt(desc, dst, src, nbytes, &req); | 1488 | return lrw_crypt(desc, dst, src, nbytes, &req); |
1520 | } | 1489 | } |
1521 | 1490 | ||
1522 | static void lrw_exit_tfm(struct crypto_tfm *tfm) | 1491 | void lrw_camellia_exit_tfm(struct crypto_tfm *tfm) |
1523 | { | 1492 | { |
1524 | struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm); | 1493 | struct camellia_lrw_ctx *ctx = crypto_tfm_ctx(tfm); |
1525 | 1494 | ||
1526 | lrw_free_table(&ctx->lrw_table); | 1495 | lrw_free_table(&ctx->lrw_table); |
1527 | } | 1496 | } |
1497 | EXPORT_SYMBOL_GPL(lrw_camellia_exit_tfm); | ||
1528 | 1498 | ||
1529 | struct camellia_xts_ctx { | 1499 | int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, |
1530 | struct camellia_ctx tweak_ctx; | 1500 | unsigned int keylen) |
1531 | struct camellia_ctx crypt_ctx; | ||
1532 | }; | ||
1533 | |||
1534 | static int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, | ||
1535 | unsigned int keylen) | ||
1536 | { | 1501 | { |
1537 | struct camellia_xts_ctx *ctx = crypto_tfm_ctx(tfm); | 1502 | struct camellia_xts_ctx *ctx = crypto_tfm_ctx(tfm); |
1538 | u32 *flags = &tfm->crt_flags; | 1503 | u32 *flags = &tfm->crt_flags; |
@@ -1555,6 +1520,7 @@ static int xts_camellia_setkey(struct crypto_tfm *tfm, const u8 *key, | |||
1555 | return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, | 1520 | return __camellia_setkey(&ctx->tweak_ctx, key + keylen / 2, keylen / 2, |
1556 | flags); | 1521 | flags); |
1557 | } | 1522 | } |
1523 | EXPORT_SYMBOL_GPL(xts_camellia_setkey); | ||
1558 | 1524 | ||
1559 | static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, | 1525 | static int xts_encrypt(struct blkcipher_desc *desc, struct scatterlist *dst, |
1560 | struct scatterlist *src, unsigned int nbytes) | 1526 | struct scatterlist *src, unsigned int nbytes) |
@@ -1679,7 +1645,7 @@ static struct crypto_alg camellia_algs[6] = { { | |||
1679 | .cra_alignmask = 0, | 1645 | .cra_alignmask = 0, |
1680 | .cra_type = &crypto_blkcipher_type, | 1646 | .cra_type = &crypto_blkcipher_type, |
1681 | .cra_module = THIS_MODULE, | 1647 | .cra_module = THIS_MODULE, |
1682 | .cra_exit = lrw_exit_tfm, | 1648 | .cra_exit = lrw_camellia_exit_tfm, |
1683 | .cra_u = { | 1649 | .cra_u = { |
1684 | .blkcipher = { | 1650 | .blkcipher = { |
1685 | .min_keysize = CAMELLIA_MIN_KEY_SIZE + | 1651 | .min_keysize = CAMELLIA_MIN_KEY_SIZE + |