internal.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/kmod.h>
  20. #include <asm/kmap_types.h>
  21. extern enum km_type crypto_km_types[];
  22. static inline enum km_type crypto_kmap_type(int out)
  23. {
  24. return crypto_km_types[(in_softirq() ? 2 : 0) + out];
  25. }
  26. static inline void *crypto_kmap(struct page *page, int out)
  27. {
  28. return kmap_atomic(page, crypto_kmap_type(out));
  29. }
  30. static inline void crypto_kunmap(void *vaddr, int out)
  31. {
  32. kunmap_atomic(vaddr, crypto_kmap_type(out));
  33. }
  34. static inline void crypto_yield(struct crypto_tfm *tfm)
  35. {
  36. if (!in_atomic())
  37. cond_resched();
  38. }
  39. static inline void *crypto_tfm_ctx(struct crypto_tfm *tfm)
  40. {
  41. return (void *)&tfm[1];
  42. }
  43. struct crypto_alg *crypto_alg_lookup(const char *name);
  44. /* A far more intelligent version of this is planned. For now, just
  45. * try an exact match on the name of the algorithm. */
  46. static inline struct crypto_alg *crypto_alg_mod_lookup(const char *name)
  47. {
  48. return try_then_request_module(crypto_alg_lookup(name), name);
  49. }
  50. #ifdef CONFIG_CRYPTO_HMAC
  51. int crypto_alloc_hmac_block(struct crypto_tfm *tfm);
  52. void crypto_free_hmac_block(struct crypto_tfm *tfm);
  53. #else
  54. static inline int crypto_alloc_hmac_block(struct crypto_tfm *tfm)
  55. {
  56. return 0;
  57. }
  58. static inline void crypto_free_hmac_block(struct crypto_tfm *tfm)
  59. { }
  60. #endif
  61. #ifdef CONFIG_PROC_FS
  62. void __init crypto_init_proc(void);
  63. #else
  64. static inline void crypto_init_proc(void)
  65. { }
  66. #endif
  67. int crypto_init_digest_flags(struct crypto_tfm *tfm, u32 flags);
  68. int crypto_init_cipher_flags(struct crypto_tfm *tfm, u32 flags);
  69. int crypto_init_compress_flags(struct crypto_tfm *tfm, u32 flags);
  70. int crypto_init_digest_ops(struct crypto_tfm *tfm);
  71. int crypto_init_cipher_ops(struct crypto_tfm *tfm);
  72. int crypto_init_compress_ops(struct crypto_tfm *tfm);
  73. void crypto_exit_digest_ops(struct crypto_tfm *tfm);
  74. void crypto_exit_cipher_ops(struct crypto_tfm *tfm);
  75. void crypto_exit_compress_ops(struct crypto_tfm *tfm);
  76. #endif /* _CRYPTO_INTERNAL_H */