Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

89 rindas
4.3 KiB

  1. /* Copyright (c) 2017, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_FIPSMODULE_DELOCATE_H
  15. #define OPENSSL_HEADER_FIPSMODULE_DELOCATE_H
  16. #include <openssl/base.h>
  17. #include "../internal.h"
  18. #if defined(BORINGSSL_FIPS) && !defined(OPENSSL_ASAN) && !defined(OPENSSL_MSAN)
  19. #define DEFINE_BSS_GET(type, name) \
  20. static type name __attribute__((used)); \
  21. type *name##_bss_get(void) __attribute__((const));
  22. // For FIPS builds we require that CRYPTO_ONCE_INIT be zero.
  23. #define DEFINE_STATIC_ONCE(name) DEFINE_BSS_GET(CRYPTO_once_t, name)
  24. // For FIPS builds we require that CRYPTO_STATIC_MUTEX_INIT be zero.
  25. #define DEFINE_STATIC_MUTEX(name) \
  26. DEFINE_BSS_GET(struct CRYPTO_STATIC_MUTEX, name)
  27. // For FIPS builds we require that CRYPTO_EX_DATA_CLASS_INIT be zero.
  28. #define DEFINE_STATIC_EX_DATA_CLASS(name) \
  29. DEFINE_BSS_GET(CRYPTO_EX_DATA_CLASS, name)
  30. #else
  31. #define DEFINE_BSS_GET(type, name) \
  32. static type name; \
  33. static type *name##_bss_get(void) { return &name; }
  34. #define DEFINE_STATIC_ONCE(name) \
  35. static CRYPTO_once_t name = CRYPTO_ONCE_INIT; \
  36. static CRYPTO_once_t *name##_bss_get(void) { return &name; }
  37. #define DEFINE_STATIC_MUTEX(name) \
  38. static struct CRYPTO_STATIC_MUTEX name = CRYPTO_STATIC_MUTEX_INIT; \
  39. static struct CRYPTO_STATIC_MUTEX *name##_bss_get(void) { return &name; }
  40. #define DEFINE_STATIC_EX_DATA_CLASS(name) \
  41. static CRYPTO_EX_DATA_CLASS name = CRYPTO_EX_DATA_CLASS_INIT; \
  42. static CRYPTO_EX_DATA_CLASS *name##_bss_get(void) { return &name; }
  43. #endif
  44. #define DEFINE_DATA(type, name, accessor_decorations) \
  45. DEFINE_BSS_GET(type, name##_storage) \
  46. DEFINE_STATIC_ONCE(name##_once) \
  47. static void name##_do_init(type *out); \
  48. static void name##_init(void) { name##_do_init(name##_storage_bss_get()); } \
  49. accessor_decorations type *name(void) { \
  50. CRYPTO_once(name##_once_bss_get(), name##_init); \
  51. /* See http://c-faq.com/ansi/constmismatch.html for why the following \
  52. * cast is needed. */ \
  53. return (const type *)name##_storage_bss_get(); \
  54. } \
  55. static void name##_do_init(type *out)
  56. // DEFINE_METHOD_FUNCTION defines a function named |name| which returns a
  57. // method table of type const |type|*. In FIPS mode, to avoid rel.ro data, it
  58. // is split into a CRYPTO_once_t-guarded initializer in the module and
  59. // unhashed, non-module accessor functions to space reserved in the BSS. The
  60. // method table is initialized by a caller-supplied function which takes a
  61. // parameter named |out| of type |type|*. The caller should follow the macro
  62. // invocation with the body of this function:
  63. //
  64. // DEFINE_METHOD_FUNCTION(EVP_MD, EVP_md4) {
  65. // out->type = NID_md4;
  66. // out->md_size = MD4_DIGEST_LENGTH;
  67. // out->flags = 0;
  68. // out->init = md4_init;
  69. // out->update = md4_update;
  70. // out->final = md4_final;
  71. // out->block_size = 64;
  72. // out->ctx_size = sizeof(MD4_CTX);
  73. // }
  74. //
  75. // This mechanism does not use a static initializer because their execution
  76. // order is undefined. See FIPS.md for more details.
  77. #define DEFINE_METHOD_FUNCTION(type, name) DEFINE_DATA(type, name, const)
  78. #define DEFINE_LOCAL_DATA(type, name) DEFINE_DATA(type, name, static const)
  79. #endif // OPENSSL_HEADER_FIPSMODULE_DELOCATE_H