internal.h 2.6 KB

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