s2n_openssl.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #pragma once
  16. #include <stdbool.h>
  17. /**
  18. * openssl with OPENSSL_VERSION_NUMBER < 0x10100003L made data type details unavailable
  19. * libressl use openssl with data type details available, but mandatorily set
  20. * OPENSSL_VERSION_NUMBER = 0x20000000L, insane!
  21. * https://github.com/aws/aws-sdk-cpp/pull/507/commits/2c99f1fe0c4b4683280caeb161538d4724d6a179
  22. */
  23. #if defined(LIBRESSL_VERSION_NUMBER) && (OPENSSL_VERSION_NUMBER == 0x20000000L)
  24. #undef OPENSSL_VERSION_NUMBER
  25. #if LIBRESSL_VERSION_NUMBER < 0x3050000fL
  26. #define OPENSSL_VERSION_NUMBER 0x1000107fL
  27. #else
  28. #define OPENSSL_VERSION_NUMBER 0x1010000fL
  29. #endif
  30. #endif
  31. /* Per https://wiki.openssl.org/index.php/Manual:OPENSSL_VERSION_NUMBER(3)
  32. * OPENSSL_VERSION_NUMBER in hex is: MNNFFRBB major minor fix final beta/patch.
  33. * bitwise: MMMMNNNNNNNNFFFFFFFFRRRRBBBBBBBB
  34. * For our purposes we're only concerned about major/minor/fix. Patch versions don't usually introduce
  35. * features.
  36. */
  37. #define S2N_OPENSSL_VERSION_AT_LEAST(major, minor, fix) \
  38. (OPENSSL_VERSION_NUMBER >= ((major << 28) + (minor << 20) + (fix << 12)))
  39. #if (S2N_OPENSSL_VERSION_AT_LEAST(1, 1, 0)) && (!defined(OPENSSL_IS_BORINGSSL)) && (!defined(OPENSSL_IS_AWSLC)) && (!defined(LIBRESSL_VERSION_NUMBER))
  40. #define s2n_evp_ctx_init(ctx) POSIX_GUARD_OSSL(EVP_CIPHER_CTX_init(ctx), S2N_ERR_DRBG)
  41. #define RESULT_EVP_CTX_INIT(ctx) RESULT_GUARD_OSSL(EVP_CIPHER_CTX_init(ctx), S2N_ERR_DRBG)
  42. #else
  43. #define s2n_evp_ctx_init(ctx) EVP_CIPHER_CTX_init(ctx)
  44. #define RESULT_EVP_CTX_INIT(ctx) EVP_CIPHER_CTX_init(ctx)
  45. #endif
  46. #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_FIPS) && !defined(LIBRESSL_VERSION_NUMBER) && !defined(OPENSSL_IS_AWSLC) && !defined(OPENSSL_NO_ENGINE)
  47. #define S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND 1
  48. #else
  49. #define S2N_LIBCRYPTO_SUPPORTS_CUSTOM_RAND 0
  50. #endif
  51. bool s2n_libcrypto_is_awslc();
  52. bool s2n_libcrypto_is_boringssl();
  53. bool s2n_libcrypto_is_libressl();