24 #include <linux/kernel.h>
25 #include <linux/module.h>
27 static u_int32_t ks[12] = {0x01010101, 0x01010101, 0x01010101, 0x01010101,
28 0x02020202, 0x02020202, 0x02020202, 0x02020202,
29 0x03030303, 0x03030303, 0x03030303, 0x03030303};
61 static int crypto_xcbc_digest_setkey(
struct crypto_shash *parent,
62 const u8 *inkey,
unsigned int keylen)
64 unsigned long alignmask = crypto_shash_alignmask(parent);
66 int bs = crypto_shash_blocksize(parent);
71 if ((err = crypto_cipher_setkey(ctx->
child, inkey, keylen)))
74 crypto_cipher_encrypt_one(ctx->
child, consts, (
u8 *)
ks + bs);
75 crypto_cipher_encrypt_one(ctx->
child, consts + bs, (
u8 *)
ks + bs * 2);
76 crypto_cipher_encrypt_one(ctx->
child, key1, (
u8 *)
ks);
78 return crypto_cipher_setkey(ctx->
child, key1, bs);
84 unsigned long alignmask = crypto_shash_alignmask(pdesc->
tfm);
86 int bs = crypto_shash_blocksize(pdesc->
tfm);
99 unsigned long alignmask = crypto_shash_alignmask(parent);
103 int bs = crypto_shash_blocksize(parent);
108 if ((ctx->
len + len) <= bs) {
116 len -= bs - ctx->
len;
120 crypto_cipher_encrypt_one(tfm, prev, prev);
128 crypto_cipher_encrypt_one(tfm, prev, prev);
145 unsigned long alignmask = crypto_shash_alignmask(parent);
149 int bs = crypto_shash_blocksize(parent);
152 u8 *prev = odds + bs;
155 if (ctx->
len != bs) {
157 u8 *p = odds + ctx->
len;
162 rlen = bs - ctx->
len -1;
172 crypto_cipher_encrypt_one(tfm, out, prev);
177 static int xcbc_init_tfm(
struct crypto_tfm *tfm)
184 cipher = crypto_spawn_cipher(spawn);
186 return PTR_ERR(cipher);
193 static void xcbc_exit_tfm(
struct crypto_tfm *tfm)
196 crypto_free_cipher(ctx->
child);
203 unsigned long alignmask;
222 inst = shash_alloc_instance(
"xcbc", alg);
228 shash_crypto_instance(inst),
234 inst->
alg.base.cra_alignmask = alignmask;
240 crypto_tfm_ctx_alignment()) +
242 ~(crypto_tfm_ctx_alignment() - 1)) +
248 inst->
alg.base.cra_init = xcbc_init_tfm;
249 inst->
alg.base.cra_exit = xcbc_exit_tfm;
251 inst->
alg.init = crypto_xcbc_digest_init;
252 inst->
alg.update = crypto_xcbc_digest_update;
253 inst->
alg.final = crypto_xcbc_digest_final;
254 inst->
alg.setkey = crypto_xcbc_digest_setkey;
269 .create = xcbc_create,
274 static int __init crypto_xcbc_module_init(
void)
279 static void __exit crypto_xcbc_module_exit(
void)