14 #include <linux/kernel.h>
17 #include <linux/errno.h>
19 #include <linux/slab.h>
20 #include <asm/scatterlist.h>
28 static inline void xor_64(u8 *
a,
const u8 *
b)
30 ((
u32 *)a)[0] ^= ((
u32 *)b)[0];
31 ((
u32 *)a)[1] ^= ((
u32 *)b)[1];
34 static inline void xor_128(u8 *
a,
const u8 *
b)
36 ((
u32 *)a)[0] ^= ((
u32 *)b)[0];
37 ((
u32 *)a)[1] ^= ((
u32 *)b)[1];
38 ((
u32 *)a)[2] ^= ((
u32 *)b)[2];
39 ((
u32 *)a)[3] ^= ((
u32 *)b)[3];
51 unsigned int nbytes, cryptfn_t crfn,
55 const unsigned int bsize = crypto_tfm_alg_blocksize(tfm);
78 in_place = scatterwalk_samebuf(&walk_in, &walk_out,
85 prfn(tfm, dst_p, src_p, crfn, enc, info, in_place);
99 static void cbc_process(
struct crypto_tfm *tfm, u8 *dst, u8 *src,
100 cryptfn_t
fn,
int enc,
void *info,
int in_place)
110 fn(crypto_tfm_ctx(tfm), dst, iv);
111 memcpy(iv, dst, crypto_tfm_alg_blocksize(tfm));
113 u8
stack[in_place ? crypto_tfm_alg_blocksize(tfm) : 0];
116 fn(crypto_tfm_ctx(tfm), buf, src);
118 memcpy(iv, src, crypto_tfm_alg_blocksize(tfm));
120 memcpy(dst, buf, crypto_tfm_alg_blocksize(tfm));
124 static void ecb_process(
struct crypto_tfm *tfm, u8 *dst, u8 *src,
125 cryptfn_t fn,
int enc,
void *info,
int in_place)
127 fn(crypto_tfm_ctx(tfm), dst, src);
138 return cia->
cia_setkey(crypto_tfm_ctx(tfm), key, keylen,
142 static int ecb_encrypt(
struct crypto_tfm *tfm,
146 return crypt(tfm, dst, src, nbytes,
148 ecb_process, 1,
NULL);
151 static int ecb_decrypt(
struct crypto_tfm *tfm,
156 return crypt(tfm, dst, src, nbytes,
158 ecb_process, 1,
NULL);
161 static int cbc_encrypt(
struct crypto_tfm *tfm,
166 return crypt(tfm, dst, src, nbytes,
168 cbc_process, 1, tfm->crt_cipher.cit_iv);
171 static int cbc_encrypt_iv(
struct crypto_tfm *tfm,
174 unsigned int nbytes, u8 *iv)
176 return crypt(tfm, dst, src, nbytes,
181 static int cbc_decrypt(
struct crypto_tfm *tfm,
186 return crypt(tfm, dst, src, nbytes,
188 cbc_process, 0, tfm->crt_cipher.cit_iv);
191 static int cbc_decrypt_iv(
struct crypto_tfm *tfm,
194 unsigned int nbytes, u8 *iv)
196 return crypt(tfm, dst, src, nbytes,
212 unsigned int nbytes, u8 *iv)
235 switch (tfm->crt_cipher.cit_mode) {
268 switch (crypto_tfm_alg_blocksize(tfm)) {
279 crypto_tfm_alg_name(tfm),
280 crypto_tfm_alg_blocksize(tfm));
285 ops->
cit_ivsize = crypto_tfm_alg_blocksize(tfm);
297 kfree(tfm->crt_cipher.cit_iv);