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 <asm/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);
171 #ifdef CONFIG_CRYPTO_HMAC
172 void *dit_hmac_block;
178 const u8 *
src,
unsigned int slen,
181 const u8 *
src,
unsigned int slen,
185 #define crt_cipher crt_u.cipher
186 #define crt_digest crt_u.digest
187 #define crt_compress crt_u.compress
221 static inline const char *crypto_tfm_alg_name(
struct crypto_tfm *tfm)
226 static inline const char *crypto_tfm_alg_modname(
struct crypto_tfm *tfm)
236 static inline u32 crypto_tfm_alg_type(
struct crypto_tfm *tfm)
241 static inline unsigned int crypto_tfm_alg_min_keysize(
struct crypto_tfm *tfm)
244 return tfm->
__crt_alg->cra_cipher.cia_min_keysize;
247 static inline unsigned int crypto_tfm_alg_max_keysize(
struct crypto_tfm *tfm)
250 return tfm->
__crt_alg->cra_cipher.cia_max_keysize;
253 static inline unsigned int crypto_tfm_alg_ivsize(
struct crypto_tfm *tfm)
256 return tfm->crt_cipher.cit_ivsize;
259 static inline unsigned int crypto_tfm_alg_blocksize(
struct crypto_tfm *tfm)
264 static inline unsigned int crypto_tfm_alg_digestsize(
struct crypto_tfm *tfm)
267 return tfm->
__crt_alg->cra_digest.dia_digestsize;
273 static inline void crypto_digest_init(
struct crypto_tfm *tfm)
276 tfm->crt_digest.dit_init(tfm);
279 static inline void crypto_digest_update(
struct crypto_tfm *tfm,
284 tfm->crt_digest.dit_update(tfm, sg, nsg);
287 static inline void crypto_digest_final(
struct crypto_tfm *tfm,
u8 *
out)
290 tfm->crt_digest.dit_final(tfm, out);
293 static inline void crypto_digest_digest(
struct crypto_tfm *tfm,
295 unsigned int nsg,
u8 *out)
298 tfm->crt_digest.dit_digest(tfm, sg, nsg, out);
301 static inline int crypto_digest_setkey(
struct crypto_tfm *tfm,
302 const u8 *
key,
unsigned int keylen)
305 if (tfm->crt_digest.dit_setkey ==
NULL)
307 return tfm->crt_digest.dit_setkey(tfm, key, keylen);
310 static inline int crypto_cipher_setkey(
struct crypto_tfm *tfm,
311 const u8 *key,
unsigned int keylen)
314 return tfm->crt_cipher.cit_setkey(tfm, key, keylen);
317 static inline int crypto_cipher_encrypt(
struct crypto_tfm *tfm,
323 return tfm->crt_cipher.cit_encrypt(tfm, dst, src, nbytes);
326 static inline int crypto_cipher_encrypt_iv(
struct crypto_tfm *tfm,
329 unsigned int nbytes,
u8 *
iv)
333 return tfm->crt_cipher.cit_encrypt_iv(tfm, dst, src, nbytes, iv);
336 static inline int crypto_cipher_decrypt(
struct crypto_tfm *tfm,
342 return tfm->crt_cipher.cit_decrypt(tfm, dst, src, nbytes);
345 static inline int crypto_cipher_decrypt_iv(
struct crypto_tfm *tfm,
348 unsigned int nbytes,
u8 *iv)
352 return tfm->crt_cipher.cit_decrypt_iv(tfm, dst, src, nbytes, iv);
355 static inline void crypto_cipher_set_iv(
struct crypto_tfm *tfm,
356 const u8 *src,
unsigned int len)
359 memcpy(tfm->crt_cipher.cit_iv, src, len);
362 static inline void crypto_cipher_get_iv(
struct crypto_tfm *tfm,
363 u8 *dst,
unsigned int len)
366 memcpy(dst, tfm->crt_cipher.cit_iv, len);
369 static inline int crypto_comp_compress(
struct crypto_tfm *tfm,
370 const u8 *src,
unsigned int slen,
371 u8 *dst,
unsigned int *
dlen)
374 return tfm->crt_compress.cot_compress(tfm, src, slen, dst, dlen);
377 static inline int crypto_comp_decompress(
struct crypto_tfm *tfm,
378 const u8 *src,
unsigned int slen,
379 u8 *dst,
unsigned int *dlen)
382 return tfm->crt_compress.cot_decompress(tfm, src, slen, dst, dlen);
388 #ifdef CONFIG_CRYPTO_HMAC
389 void crypto_hmac_init(
struct crypto_tfm *tfm,
u8 *key,
unsigned int *keylen);
390 void crypto_hmac_update(
struct crypto_tfm *tfm,
393 unsigned int *keylen,
u8 *out);
394 void crypto_hmac(
struct crypto_tfm *tfm,
u8 *key,
unsigned int *keylen,