16 #ifndef _LINUX_CRYPTO_H
17 #define _LINUX_CRYPTO_H
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include <linux/types.h>
22 #include <linux/list.h>
23 #include <linux/string.h>
25 #include <linux/errno.h>
27 #define crypto_register_alg crypto_register_alg_rsl
28 #define crypto_unregister_alg crypto_unregister_alg_rsl
29 #define crypto_alloc_tfm crypto_alloc_tfm_rsl
30 #define crypto_free_tfm crypto_free_tfm_rsl
31 #define crypto_alg_available crypto_alg_available_rsl
36 #define CRYPTO_ALG_TYPE_MASK 0x000000ff
37 #define CRYPTO_ALG_TYPE_CIPHER 0x00000001
38 #define CRYPTO_ALG_TYPE_DIGEST 0x00000002
39 #define CRYPTO_ALG_TYPE_COMPRESS 0x00000004
44 #define CRYPTO_TFM_MODE_MASK 0x000000ff
45 #define CRYPTO_TFM_REQ_MASK 0x000fff00
46 #define CRYPTO_TFM_RES_MASK 0xfff00000
48 #define CRYPTO_TFM_MODE_ECB 0x00000001
49 #define CRYPTO_TFM_MODE_CBC 0x00000002
50 #define CRYPTO_TFM_MODE_CFB 0x00000004
51 #define CRYPTO_TFM_MODE_CTR 0x00000008
53 #define CRYPTO_TFM_REQ_WEAK_KEY 0x00000100
54 #define CRYPTO_TFM_RES_WEAK_KEY 0x00100000
55 #define CRYPTO_TFM_RES_BAD_KEY_LEN 0x00200000
56 #define CRYPTO_TFM_RES_BAD_KEY_SCHED 0x00400000
57 #define CRYPTO_TFM_RES_BAD_BLOCK_LEN 0x00800000
58 #define CRYPTO_TFM_RES_BAD_FLAGS 0x01000000
63 #define CRYPTO_UNSPEC 0
64 #define CRYPTO_MAX_ALG_NAME 64
99 #define cra_cipher cra_u.cipher
100 #define cra_digest cra_u.digest
101 #define cra_compress cra_u.compress
142 const u8 *
key,
unsigned int keylen);
168 unsigned int nsg,
u8 *
out);
170 const u8 *
key,
unsigned int keylen);
175 const u8 *
src,
unsigned int slen,
178 const u8 *
src,
unsigned int slen,
182 #define crt_cipher crt_u.cipher
183 #define crt_digest crt_u.digest
184 #define crt_compress crt_u.compress
218 static inline const char *crypto_tfm_alg_name(
struct crypto_tfm *tfm)
223 static inline const char *crypto_tfm_alg_modname(
struct crypto_tfm *tfm)
233 static inline u32 crypto_tfm_alg_type(
struct crypto_tfm *tfm)
238 static inline unsigned int crypto_tfm_alg_min_keysize(
struct crypto_tfm *tfm)
241 return tfm->
__crt_alg->cra_cipher.cia_min_keysize;
244 static inline unsigned int crypto_tfm_alg_max_keysize(
struct crypto_tfm *tfm)
247 return tfm->
__crt_alg->cra_cipher.cia_max_keysize;
250 static inline unsigned int crypto_tfm_alg_ivsize(
struct crypto_tfm *tfm)
253 return tfm->crt_cipher.cit_ivsize;
256 static inline unsigned int crypto_tfm_alg_blocksize(
struct crypto_tfm *tfm)
261 static inline unsigned int crypto_tfm_alg_digestsize(
struct crypto_tfm *tfm)
264 return tfm->
__crt_alg->cra_digest.dia_digestsize;
270 static inline void crypto_digest_init(
struct crypto_tfm *tfm)
273 tfm->crt_digest.dit_init(tfm);
276 static inline void crypto_digest_update(
struct crypto_tfm *tfm,
281 tfm->crt_digest.dit_update(tfm, sg, nsg);
284 static inline void crypto_digest_final(
struct crypto_tfm *tfm,
u8 *
out)
287 tfm->crt_digest.dit_final(tfm, out);
290 static inline void crypto_digest_digest(
struct crypto_tfm *tfm,
292 unsigned int nsg,
u8 *out)
295 tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
298 static inline int crypto_digest_setkey(
struct crypto_tfm *tfm,
299 const u8 *
key,
unsigned int keylen)
302 if (tfm->crt_digest.dit_setkey ==
NULL)
304 return tfm->crt_digest.dit_setkey(tfm, key, keylen);
307 static inline int crypto_cipher_setkey(
struct crypto_tfm *tfm,
308 const u8 *key,
unsigned int keylen)
311 return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
314 static inline int crypto_cipher_encrypt(
struct crypto_tfm *tfm,
320 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
323 static inline int crypto_cipher_encrypt_iv(
struct crypto_tfm *tfm,
326 unsigned int nbytes,
u8 *
iv)
330 return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
333 static inline int crypto_cipher_decrypt(
struct crypto_tfm *tfm,
339 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
342 static inline int crypto_cipher_decrypt_iv(
struct crypto_tfm *tfm,
345 unsigned int nbytes,
u8 *iv)
349 return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
352 static inline void crypto_cipher_set_iv(
struct crypto_tfm *tfm,
353 const u8 *src,
unsigned int len)
356 memcpy(tfm->crt_cipher.cit_iv, src, len);
359 static inline void crypto_cipher_get_iv(
struct crypto_tfm *tfm,
360 u8 *dst,
unsigned int len)
363 memcpy(dst, tfm->crt_cipher.cit_iv, len);
366 static inline int crypto_comp_compress(
struct crypto_tfm *tfm,
367 const u8 *src,
unsigned int slen,
368 u8 *dst,
unsigned int *
dlen)
371 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
374 static inline int crypto_comp_decompress(
struct crypto_tfm *tfm,
375 const u8 *src,
unsigned int slen,
376 u8 *dst,
unsigned int *dlen)
379 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);