internal.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Cryptographic API.
  3. *
  4. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  5. * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. */
  13. #ifndef _CRYPTO_INTERNAL_H
  14. #define _CRYPTO_INTERNAL_H
  15. #include <crypto/algapi.h>
  16. #include <linux/mm.h>
  17. #include <linux/highmem.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/init.h>
  20. #include <linux/list.h>
  21. #include <linux/kernel.h>
  22. #include <linux/rwsem.h>
  23. #include <linux/slab.h>
  24. #include <asm/kmap_types.h>
  25. extern struct list_head crypto_alg_list;
  26. extern struct rw_semaphore crypto_alg_sem;
  27. extern enum km_type crypto_km_types[];
  28. static inline enum km_type crypto_kmap_type(int out)
  29. {
  30. return crypto_km_types[(in_softirq() ? 2 : 0) + out];
  31. }
  32. static inline void *crypto_kmap(struct page *page, int out)
  33. {
  34. return kmap_atomic(page, crypto_kmap_type(out));
  35. }
  36. static inline void crypto_kunmap(void *vaddr, int out)
  37. {
  38. kunmap_atomic(vaddr, crypto_kmap_type(out));
  39. }
  40. static inline void crypto_yield(struct crypto_tfm *tfm)
  41. {
  42. if (tfm->crt_flags & CRYPTO_TFM_REQ_MAY_SLEEP)
  43. cond_resched();
  44. }
  45. #ifdef CONFIG_CRYPTO_HMAC
  46. int crypto_alloc_hmac_block(struct crypto_tfm *tfm);
  47. void crypto_free_hmac_block(struct crypto_tfm *tfm);
  48. #else
  49. static inline int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
  50. {
  51. return 0;
  52. }
  53. static inline void crypto_free_hmac_block(struct crypto_tfm *tfm)
  54. { }
  55. #endif
  56. #ifdef CONFIG_PROC_FS
  57. void __init crypto_init_proc(void);
  58. void __exit crypto_exit_proc(void);
  59. #else
  60. static inline void crypto_init_proc(void)
  61. { }
  62. static inline void crypto_exit_proc(void)
  63. { }
  64. #endif
  65. static inline unsigned int crypto_digest_ctxsize(struct crypto_alg *alg,
  66. int flags)
  67. {
  68. return alg->cra_ctxsize;
  69. }
  70. static inline unsigned int crypto_cipher_ctxsize(struct crypto_alg *alg,
  71. int flags)
  72. {
  73. unsigned int len = alg->cra_ctxsize;
  74. switch (flags & CRYPTO_TFM_MODE_MASK) {
  75. case CRYPTO_TFM_MODE_CBC:
  76. len = ALIGN(len, (unsigned long)alg->cra_alignmask + 1);
  77. len += alg->cra_blocksize;
  78. break;
  79. }
  80. return len;
  81. }
  82. static inline unsigned int crypto_compress_ctxsize(struct crypto_alg *alg,
  83. int flags)
  84. {
  85. return alg->cra_ctxsize;
  86. }
  87. int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
  88. int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags);
  89. int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags);
  90. int crypto_init_digest_ops(struct crypto_tfm *tfm);
  91. int crypto_init_cipher_ops(struct crypto_tfm *tfm);
  92. int crypto_init_compress_ops(struct crypto_tfm *tfm);
  93. void crypto_exit_digest_ops(struct crypto_tfm *tfm);
  94. void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
  95. void crypto_exit_compress_ops(struct crypto_tfm *tfm);
  96. #endif /* _CRYPTO_INTERNAL_H */