fips140-defs.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2021 Google LLC
  4. *
  5. * This file is automatically included by all files built into fips140.ko, via
  6. * the "-include" compiler flag.
  7. */
  8. /*
  9. * fips140.ko is built from various unmodified or minimally modified kernel
  10. * source files, many of which are normally meant to be buildable into different
  11. * modules themselves. That results in conflicting instances of module_init()
  12. * and related macros such as MODULE_LICENSE().
  13. *
  14. * To solve that, we undefine MODULE to trick the kernel headers into thinking
  15. * the code is being compiled as built-in. That causes module_init() and
  16. * related macros to be expanded as they would be for built-in code; e.g.,
  17. * module_init() adds the function to the .initcalls section of the binary.
  18. *
  19. * The .c files that contain the real module_init, module license, and module
  20. * parameters for fips140.ko are then responsible for redefining MODULE. The
  21. * real module_init executes all initcalls that were collected into .initcalls.
  22. */
  23. #undef MODULE
  24. /*
  25. * Defining KBUILD_MODFILE is also required, since the kernel headers expect it
  26. * to be defined when code that can be a module is compiled as built-in.
  27. */
  28. #define KBUILD_MODFILE "crypto/fips140"
  29. /*
  30. * Disable symbol exports by default. fips140.ko includes various files that
  31. * use EXPORT_SYMBOL*(), but it's unwanted to export any symbols from fips140.ko
  32. * except where explicitly needed for FIPS certification reasons.
  33. */
  34. #define __DISABLE_EXPORTS
  35. /*
  36. * Redirect all calls to algorithm registration functions to the wrapper
  37. * functions defined within the module.
  38. */
  39. #define aead_register_instance fips140_aead_register_instance
  40. #define ahash_register_instance fips140_ahash_register_instance
  41. #define crypto_register_aead fips140_crypto_register_aead
  42. #define crypto_register_aeads fips140_crypto_register_aeads
  43. #define crypto_register_ahash fips140_crypto_register_ahash
  44. #define crypto_register_ahashes fips140_crypto_register_ahashes
  45. #define crypto_register_alg fips140_crypto_register_alg
  46. #define crypto_register_algs fips140_crypto_register_algs
  47. #define crypto_register_rng fips140_crypto_register_rng
  48. #define crypto_register_rngs fips140_crypto_register_rngs
  49. #define crypto_register_shash fips140_crypto_register_shash
  50. #define crypto_register_shashes fips140_crypto_register_shashes
  51. #define crypto_register_skcipher fips140_crypto_register_skcipher
  52. #define crypto_register_skciphers fips140_crypto_register_skciphers
  53. #define shash_register_instance fips140_shash_register_instance
  54. #define skcipher_register_instance fips140_skcipher_register_instance