Merge git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto update from Herbert Xu: "* sha512 bug fixes (already in your tree). * SHA224/SHA384 AEAD support in caam. * X86-64 optimised version of Camellia. * Tegra AES support. * Bulk algorithm registration interface to make driver registration easier. * padata race fixes. * Misc fixes." * git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (31 commits) padata: Fix race on sequence number wrap padata: Fix race in the serialization path crypto: camellia - add assembler implementation for x86_64 crypto: camellia - rename camellia.c to camellia_generic.c crypto: camellia - fix checkpatch warnings crypto: camellia - rename camellia module to camellia_generic crypto: tcrypt - add more camellia tests crypto: testmgr - add more camellia test vectors crypto: camellia - simplify key setup and CAMELLIA_ROUNDSM macro crypto: twofish-x86_64/i586 - set alignmask to zero crypto: blowfish-x86_64 - set alignmask to zero crypto: serpent-sse2 - combine ablk_*_init functions crypto: blowfish-x86_64 - use crypto_[un]register_algs crypto: twofish-x86_64-3way - use crypto_[un]register_algs crypto: serpent-sse2 - use crypto_[un]register_algs crypto: serpent-sse2 - remove dead code from serpent_sse2_glue.c::serpent_sse2_init() crypto: twofish-x86 - Remove dead code from twofish_glue_3way.c::init() crypto: In crypto_add_alg(), 'exact' wants to be initialized to 0 crypto: caam - fix gcc 4.6 warning crypto: Add bulk algorithm registration interface ...
This commit is contained in:
@@ -654,6 +654,24 @@ config CRYPTO_CAMELLIA
|
||||
See also:
|
||||
<https://info.isl.ntt.co.jp/crypt/eng/camellia/index_s.html>
|
||||
|
||||
config CRYPTO_CAMELLIA_X86_64
|
||||
tristate "Camellia cipher algorithm (x86_64)"
|
||||
depends on (X86 || UML_X86) && 64BIT
|
||||
depends on CRYPTO
|
||||
select CRYPTO_ALGAPI
|
||||
select CRYPTO_LRW
|
||||
select CRYPTO_XTS
|
||||
help
|
||||
Camellia cipher algorithm module (x86_64).
|
||||
|
||||
Camellia is a symmetric key block cipher developed jointly
|
||||
at NTT and Mitsubishi Electric Corporation.
|
||||
|
||||
The Camellia specifies three key sizes: 128, 192 and 256 bits.
|
||||
|
||||
See also:
|
||||
<https://info.isl.ntt.co.jp/crypt/eng/camellia/index_s.html>
|
||||
|
||||
config CRYPTO_CAST5
|
||||
tristate "CAST5 (CAST-128) cipher algorithm"
|
||||
select CRYPTO_ALGAPI
|
||||
|
@@ -67,7 +67,7 @@ obj-$(CONFIG_CRYPTO_TWOFISH) += twofish_generic.o
|
||||
obj-$(CONFIG_CRYPTO_TWOFISH_COMMON) += twofish_common.o
|
||||
obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
|
||||
obj-$(CONFIG_CRYPTO_AES) += aes_generic.o
|
||||
obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia.o
|
||||
obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o
|
||||
obj-$(CONFIG_CRYPTO_CAST5) += cast5.o
|
||||
obj-$(CONFIG_CRYPTO_CAST6) += cast6.o
|
||||
obj-$(CONFIG_CRYPTO_ARC4) += arc4.o
|
||||
|
@@ -405,6 +405,41 @@ int crypto_unregister_alg(struct crypto_alg *alg)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_unregister_alg);
|
||||
|
||||
int crypto_register_algs(struct crypto_alg *algs, int count)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ret = crypto_register_alg(&algs[i]);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
for (--i; i >= 0; --i)
|
||||
crypto_unregister_alg(&algs[i]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_register_algs);
|
||||
|
||||
int crypto_unregister_algs(struct crypto_alg *algs, int count)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ret = crypto_unregister_alg(&algs[i]);
|
||||
if (ret)
|
||||
pr_err("Failed to unregister %s %s: %d\n",
|
||||
algs[i].cra_driver_name, algs[i].cra_name, ret);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_unregister_algs);
|
||||
|
||||
int crypto_register_template(struct crypto_template *tmpl)
|
||||
{
|
||||
struct crypto_template *q;
|
||||
|
@@ -337,43 +337,40 @@ static const u32 camellia_sp4404[256] = {
|
||||
/*
|
||||
* macros
|
||||
*/
|
||||
#define ROLDQ(ll, lr, rl, rr, w0, w1, bits) \
|
||||
do { \
|
||||
#define ROLDQ(ll, lr, rl, rr, w0, w1, bits) ({ \
|
||||
w0 = ll; \
|
||||
ll = (ll << bits) + (lr >> (32 - bits)); \
|
||||
lr = (lr << bits) + (rl >> (32 - bits)); \
|
||||
rl = (rl << bits) + (rr >> (32 - bits)); \
|
||||
rr = (rr << bits) + (w0 >> (32 - bits)); \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
#define ROLDQo32(ll, lr, rl, rr, w0, w1, bits) \
|
||||
do { \
|
||||
#define ROLDQo32(ll, lr, rl, rr, w0, w1, bits) ({ \
|
||||
w0 = ll; \
|
||||
w1 = lr; \
|
||||
ll = (lr << (bits - 32)) + (rl >> (64 - bits)); \
|
||||
lr = (rl << (bits - 32)) + (rr >> (64 - bits)); \
|
||||
rl = (rr << (bits - 32)) + (w0 >> (64 - bits)); \
|
||||
rr = (w0 << (bits - 32)) + (w1 >> (64 - bits)); \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) \
|
||||
do { \
|
||||
#define CAMELLIA_F(xl, xr, kl, kr, yl, yr, il, ir, t0, t1) ({ \
|
||||
il = xl ^ kl; \
|
||||
ir = xr ^ kr; \
|
||||
t0 = il >> 16; \
|
||||
t1 = ir >> 16; \
|
||||
yl = camellia_sp1110[(u8)(ir )] \
|
||||
^ camellia_sp0222[ (t1 >> 8)] \
|
||||
^ camellia_sp3033[(u8)(t1 )] \
|
||||
yl = camellia_sp1110[(u8)(ir)] \
|
||||
^ camellia_sp0222[(u8)(t1 >> 8)] \
|
||||
^ camellia_sp3033[(u8)(t1)] \
|
||||
^ camellia_sp4404[(u8)(ir >> 8)]; \
|
||||
yr = camellia_sp1110[ (t0 >> 8)] \
|
||||
^ camellia_sp0222[(u8)(t0 )] \
|
||||
yr = camellia_sp1110[(u8)(t0 >> 8)] \
|
||||
^ camellia_sp0222[(u8)(t0)] \
|
||||
^ camellia_sp3033[(u8)(il >> 8)] \
|
||||
^ camellia_sp4404[(u8)(il )]; \
|
||||
^ camellia_sp4404[(u8)(il)]; \
|
||||
yl ^= yr; \
|
||||
yr = ror32(yr, 8); \
|
||||
yr ^= yl; \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
#define SUBKEY_L(INDEX) (subkey[(INDEX)*2])
|
||||
#define SUBKEY_R(INDEX) (subkey[(INDEX)*2 + 1])
|
||||
@@ -382,7 +379,6 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
|
||||
{
|
||||
u32 dw, tl, tr;
|
||||
u32 kw4l, kw4r;
|
||||
int i;
|
||||
|
||||
/* absorb kw2 to other subkeys */
|
||||
/* round 2 */
|
||||
@@ -557,24 +553,6 @@ static void camellia_setup_tail(u32 *subkey, u32 *subL, u32 *subR, int max)
|
||||
SUBKEY_L(32) = subL[32] ^ subL[31]; /* kw3 */
|
||||
SUBKEY_R(32) = subR[32] ^ subR[31];
|
||||
}
|
||||
|
||||
/* apply the inverse of the last half of P-function */
|
||||
i = 2;
|
||||
do {
|
||||
dw = SUBKEY_L(i + 0) ^ SUBKEY_R(i + 0); dw = rol32(dw, 8);/* round 1 */
|
||||
SUBKEY_R(i + 0) = SUBKEY_L(i + 0) ^ dw; SUBKEY_L(i + 0) = dw;
|
||||
dw = SUBKEY_L(i + 1) ^ SUBKEY_R(i + 1); dw = rol32(dw, 8);/* round 2 */
|
||||
SUBKEY_R(i + 1) = SUBKEY_L(i + 1) ^ dw; SUBKEY_L(i + 1) = dw;
|
||||
dw = SUBKEY_L(i + 2) ^ SUBKEY_R(i + 2); dw = rol32(dw, 8);/* round 3 */
|
||||
SUBKEY_R(i + 2) = SUBKEY_L(i + 2) ^ dw; SUBKEY_L(i + 2) = dw;
|
||||
dw = SUBKEY_L(i + 3) ^ SUBKEY_R(i + 3); dw = rol32(dw, 8);/* round 4 */
|
||||
SUBKEY_R(i + 3) = SUBKEY_L(i + 3) ^ dw; SUBKEY_L(i + 3) = dw;
|
||||
dw = SUBKEY_L(i + 4) ^ SUBKEY_R(i + 4); dw = rol32(dw, 8);/* round 5 */
|
||||
SUBKEY_R(i + 4) = SUBKEY_L(i + 4) ^ dw; SUBKEY_L(i + 4) = dw;
|
||||
dw = SUBKEY_L(i + 5) ^ SUBKEY_R(i + 5); dw = rol32(dw, 8);/* round 6 */
|
||||
SUBKEY_R(i + 5) = SUBKEY_L(i + 5) ^ dw; SUBKEY_L(i + 5) = dw;
|
||||
i += 8;
|
||||
} while (i < max);
|
||||
}
|
||||
|
||||
static void camellia_setup128(const unsigned char *key, u32 *subkey)
|
||||
@@ -851,8 +829,7 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey)
|
||||
/*
|
||||
* Encrypt/decrypt
|
||||
*/
|
||||
#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) \
|
||||
do { \
|
||||
#define CAMELLIA_FLS(ll, lr, rl, rr, kll, klr, krl, krr, t0, t1, t2, t3) ({ \
|
||||
t0 = kll; \
|
||||
t2 = krr; \
|
||||
t0 &= ll; \
|
||||
@@ -865,23 +842,23 @@ static void camellia_setup192(const unsigned char *key, u32 *subkey)
|
||||
t1 |= lr; \
|
||||
ll ^= t1; \
|
||||
rr ^= rol32(t3, 1); \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir) \
|
||||
do { \
|
||||
#define CAMELLIA_ROUNDSM(xl, xr, kl, kr, yl, yr, il, ir) ({ \
|
||||
yl ^= kl; \
|
||||
yr ^= kr; \
|
||||
ir = camellia_sp1110[(u8)xr]; \
|
||||
il = camellia_sp1110[ (xl >> 24)]; \
|
||||
ir ^= camellia_sp0222[ (xr >> 24)]; \
|
||||
il = camellia_sp1110[(u8)(xl >> 24)]; \
|
||||
ir ^= camellia_sp0222[(u8)(xr >> 24)]; \
|
||||
il ^= camellia_sp0222[(u8)(xl >> 16)]; \
|
||||
ir ^= camellia_sp3033[(u8)(xr >> 16)]; \
|
||||
il ^= camellia_sp3033[(u8)(xl >> 8)]; \
|
||||
ir ^= camellia_sp4404[(u8)(xr >> 8)]; \
|
||||
il ^= camellia_sp4404[(u8)xl]; \
|
||||
il ^= kl; \
|
||||
ir ^= il ^ kr; \
|
||||
ir ^= il; \
|
||||
yl ^= ir; \
|
||||
yr ^= ror32(il, 8) ^ ir; \
|
||||
} while (0)
|
||||
yr ^= ror32(il, 8) ^ ir; \
|
||||
})
|
||||
|
||||
/* max = 24: 128bit encrypt, max = 32: 256bit encrypt */
|
||||
static void camellia_do_encrypt(const u32 *subkey, u32 *io, unsigned max)
|
||||
@@ -893,7 +870,7 @@ static void camellia_do_encrypt(const u32 *subkey, u32 *io, unsigned max)
|
||||
io[1] ^= SUBKEY_R(0);
|
||||
|
||||
/* main iteration */
|
||||
#define ROUNDS(i) do { \
|
||||
#define ROUNDS(i) ({ \
|
||||
CAMELLIA_ROUNDSM(io[0], io[1], \
|
||||
SUBKEY_L(i + 2), SUBKEY_R(i + 2), \
|
||||
io[2], io[3], il, ir); \
|
||||
@@ -912,13 +889,13 @@ static void camellia_do_encrypt(const u32 *subkey, u32 *io, unsigned max)
|
||||
CAMELLIA_ROUNDSM(io[2], io[3], \
|
||||
SUBKEY_L(i + 7), SUBKEY_R(i + 7), \
|
||||
io[0], io[1], il, ir); \
|
||||
} while (0)
|
||||
#define FLS(i) do { \
|
||||
})
|
||||
#define FLS(i) ({ \
|
||||
CAMELLIA_FLS(io[0], io[1], io[2], io[3], \
|
||||
SUBKEY_L(i + 0), SUBKEY_R(i + 0), \
|
||||
SUBKEY_L(i + 1), SUBKEY_R(i + 1), \
|
||||
t0, t1, il, ir); \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
ROUNDS(0);
|
||||
FLS(8);
|
||||
@@ -948,7 +925,7 @@ static void camellia_do_decrypt(const u32 *subkey, u32 *io, unsigned i)
|
||||
io[1] ^= SUBKEY_R(i);
|
||||
|
||||
/* main iteration */
|
||||
#define ROUNDS(i) do { \
|
||||
#define ROUNDS(i) ({ \
|
||||
CAMELLIA_ROUNDSM(io[0], io[1], \
|
||||
SUBKEY_L(i + 7), SUBKEY_R(i + 7), \
|
||||
io[2], io[3], il, ir); \
|
||||
@@ -967,13 +944,13 @@ static void camellia_do_decrypt(const u32 *subkey, u32 *io, unsigned i)
|
||||
CAMELLIA_ROUNDSM(io[2], io[3], \
|
||||
SUBKEY_L(i + 2), SUBKEY_R(i + 2), \
|
||||
io[0], io[1], il, ir); \
|
||||
} while (0)
|
||||
#define FLS(i) do { \
|
||||
})
|
||||
#define FLS(i) ({ \
|
||||
CAMELLIA_FLS(io[0], io[1], io[2], io[3], \
|
||||
SUBKEY_L(i + 1), SUBKEY_R(i + 1), \
|
||||
SUBKEY_L(i + 0), SUBKEY_R(i + 0), \
|
||||
t0, t1, il, ir); \
|
||||
} while (0)
|
||||
})
|
||||
|
||||
if (i == 32) {
|
||||
ROUNDS(24);
|
||||
@@ -1035,6 +1012,7 @@ static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
|
||||
const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
|
||||
const __be32 *src = (const __be32 *)in;
|
||||
__be32 *dst = (__be32 *)out;
|
||||
unsigned int max;
|
||||
|
||||
u32 tmp[4];
|
||||
|
||||
@@ -1043,9 +1021,12 @@ static void camellia_encrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
|
||||
tmp[2] = be32_to_cpu(src[2]);
|
||||
tmp[3] = be32_to_cpu(src[3]);
|
||||
|
||||
camellia_do_encrypt(cctx->key_table, tmp,
|
||||
cctx->key_length == 16 ? 24 : 32 /* for key lengths of 24 and 32 */
|
||||
);
|
||||
if (cctx->key_length == 16)
|
||||
max = 24;
|
||||
else
|
||||
max = 32; /* for key lengths of 24 and 32 */
|
||||
|
||||
camellia_do_encrypt(cctx->key_table, tmp, max);
|
||||
|
||||
/* do_encrypt returns 0,1 swapped with 2,3 */
|
||||
dst[0] = cpu_to_be32(tmp[2]);
|
||||
@@ -1059,6 +1040,7 @@ static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
|
||||
const struct camellia_ctx *cctx = crypto_tfm_ctx(tfm);
|
||||
const __be32 *src = (const __be32 *)in;
|
||||
__be32 *dst = (__be32 *)out;
|
||||
unsigned int max;
|
||||
|
||||
u32 tmp[4];
|
||||
|
||||
@@ -1067,9 +1049,12 @@ static void camellia_decrypt(struct crypto_tfm *tfm, u8 *out, const u8 *in)
|
||||
tmp[2] = be32_to_cpu(src[2]);
|
||||
tmp[3] = be32_to_cpu(src[3]);
|
||||
|
||||
camellia_do_decrypt(cctx->key_table, tmp,
|
||||
cctx->key_length == 16 ? 24 : 32 /* for key lengths of 24 and 32 */
|
||||
);
|
||||
if (cctx->key_length == 16)
|
||||
max = 24;
|
||||
else
|
||||
max = 32; /* for key lengths of 24 and 32 */
|
||||
|
||||
camellia_do_decrypt(cctx->key_table, tmp, max);
|
||||
|
||||
/* do_decrypt returns 0,1 swapped with 2,3 */
|
||||
dst[0] = cpu_to_be32(tmp[2]);
|
||||
@@ -1114,3 +1099,4 @@ module_exit(camellia_fini);
|
||||
|
||||
MODULE_DESCRIPTION("Camellia Cipher Algorithm");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS("camellia");
|
@@ -304,7 +304,7 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
|
||||
struct nlattr **attrs)
|
||||
{
|
||||
int exact;
|
||||
int exact = 0;
|
||||
const char *name;
|
||||
struct crypto_alg *alg;
|
||||
struct crypto_user_alg *p = nlmsg_data(nlh);
|
||||
|
@@ -1297,6 +1297,18 @@ static int do_test(int m)
|
||||
speed_template_16_24_32);
|
||||
test_cipher_speed("cbc(camellia)", DECRYPT, sec, NULL, 0,
|
||||
speed_template_16_24_32);
|
||||
test_cipher_speed("ctr(camellia)", ENCRYPT, sec, NULL, 0,
|
||||
speed_template_16_24_32);
|
||||
test_cipher_speed("ctr(camellia)", DECRYPT, sec, NULL, 0,
|
||||
speed_template_16_24_32);
|
||||
test_cipher_speed("lrw(camellia)", ENCRYPT, sec, NULL, 0,
|
||||
speed_template_32_40_48);
|
||||
test_cipher_speed("lrw(camellia)", DECRYPT, sec, NULL, 0,
|
||||
speed_template_32_40_48);
|
||||
test_cipher_speed("xts(camellia)", ENCRYPT, sec, NULL, 0,
|
||||
speed_template_32_48_64);
|
||||
test_cipher_speed("xts(camellia)", DECRYPT, sec, NULL, 0,
|
||||
speed_template_32_48_64);
|
||||
break;
|
||||
|
||||
case 206:
|
||||
|
@@ -1845,6 +1845,21 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "ctr(camellia)",
|
||||
.test = alg_test_skcipher,
|
||||
.suite = {
|
||||
.cipher = {
|
||||
.enc = {
|
||||
.vecs = camellia_ctr_enc_tv_template,
|
||||
.count = CAMELLIA_CTR_ENC_TEST_VECTORS
|
||||
},
|
||||
.dec = {
|
||||
.vecs = camellia_ctr_dec_tv_template,
|
||||
.count = CAMELLIA_CTR_DEC_TEST_VECTORS
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "ctr(serpent)",
|
||||
.test = alg_test_skcipher,
|
||||
@@ -2296,6 +2311,21 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "lrw(camellia)",
|
||||
.test = alg_test_skcipher,
|
||||
.suite = {
|
||||
.cipher = {
|
||||
.enc = {
|
||||
.vecs = camellia_lrw_enc_tv_template,
|
||||
.count = CAMELLIA_LRW_ENC_TEST_VECTORS
|
||||
},
|
||||
.dec = {
|
||||
.vecs = camellia_lrw_dec_tv_template,
|
||||
.count = CAMELLIA_LRW_DEC_TEST_VECTORS
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "lrw(serpent)",
|
||||
.test = alg_test_skcipher,
|
||||
@@ -2633,6 +2663,21 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "xts(camellia)",
|
||||
.test = alg_test_skcipher,
|
||||
.suite = {
|
||||
.cipher = {
|
||||
.enc = {
|
||||
.vecs = camellia_xts_enc_tv_template,
|
||||
.count = CAMELLIA_XTS_ENC_TEST_VECTORS
|
||||
},
|
||||
.dec = {
|
||||
.vecs = camellia_xts_dec_tv_template,
|
||||
.count = CAMELLIA_XTS_DEC_TEST_VECTORS
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
.alg = "xts(serpent)",
|
||||
.test = alg_test_skcipher,
|
||||
|
1383
crypto/testmgr.h
1383
crypto/testmgr.h
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user