• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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 
15 #ifndef OPENSSL_HEADER_SERVICE_INDICATOR_INTERNAL_H
16 #define OPENSSL_HEADER_SERVICE_INDICATOR_INTERNAL_H
17 
18 #include <openssl/base.h>
19 #include <openssl/service_indicator.h>
20 
21 #if defined(BORINGSSL_FIPS)
22 
23 // FIPS_service_indicator_update_state records that an approved service has been
24 // invoked.
25 void FIPS_service_indicator_update_state(void);
26 
27 // FIPS_service_indicator_lock_state and |FIPS_service_indicator_unlock_state|
28 // stop |FIPS_service_indicator_update_state| from actually updating the service
29 // indicator. This is used when a primitive calls a potentially approved
30 // primitive to avoid false positives. For example, just because a key
31 // generation calls |BCM_rand_bytes| (and thus the approved DRBG) doesn't mean
32 // that the key generation operation itself is approved.
33 //
34 // This lock nests: i.e. locking twice is fine so long as each lock is paired
35 // with an unlock. If the (64-bit) counter overflows, the process aborts.
36 void FIPS_service_indicator_lock_state(void);
37 void FIPS_service_indicator_unlock_state(void);
38 
39 // The following functions may call |FIPS_service_indicator_update_state| if
40 // their parameter specifies an approved operation.
41 
42 void AEAD_GCM_verify_service_indicator(const EVP_AEAD_CTX *ctx);
43 void AEAD_CCM_verify_service_indicator(const EVP_AEAD_CTX *ctx);
44 void EC_KEY_keygen_verify_service_indicator(const EC_KEY *eckey);
45 void ECDH_verify_service_indicator(const EC_KEY *ec_key);
46 void EVP_Cipher_verify_service_indicator(const EVP_CIPHER_CTX *ctx);
47 void EVP_DigestSign_verify_service_indicator(const EVP_MD_CTX *ctx);
48 void EVP_DigestVerify_verify_service_indicator(const EVP_MD_CTX *ctx);
49 void HMAC_verify_service_indicator(const EVP_MD *evp_md);
50 void TLSKDF_verify_service_indicator(const EVP_MD *dgst);
51 
52 #else
53 
54 // Service indicator functions are no-ops in non-FIPS builds.
55 
FIPS_service_indicator_update_state(void)56 inline void FIPS_service_indicator_update_state(void) {}
FIPS_service_indicator_lock_state(void)57 inline void FIPS_service_indicator_lock_state(void) {}
FIPS_service_indicator_unlock_state(void)58 inline void FIPS_service_indicator_unlock_state(void) {}
59 
AEAD_GCM_verify_service_indicator(const EVP_AEAD_CTX * ctx)60 inline void AEAD_GCM_verify_service_indicator(
61     [[maybe_unused]] const EVP_AEAD_CTX *ctx) {}
62 
AEAD_CCM_verify_service_indicator(const EVP_AEAD_CTX * ctx)63 inline void AEAD_CCM_verify_service_indicator(
64     [[maybe_unused]] const EVP_AEAD_CTX *ctx) {}
65 
EC_KEY_keygen_verify_service_indicator(const EC_KEY * eckey)66 inline void EC_KEY_keygen_verify_service_indicator(
67     [[maybe_unused]] const EC_KEY *eckey) {}
68 
ECDH_verify_service_indicator(const EC_KEY * ec_key)69 inline void ECDH_verify_service_indicator(
70     [[maybe_unused]] const EC_KEY *ec_key) {}
71 
EVP_Cipher_verify_service_indicator(const EVP_CIPHER_CTX * ctx)72 inline void EVP_Cipher_verify_service_indicator(
73     [[maybe_unused]] const EVP_CIPHER_CTX *ctx) {}
74 
EVP_DigestSign_verify_service_indicator(const EVP_MD_CTX * ctx)75 inline void EVP_DigestSign_verify_service_indicator(
76     [[maybe_unused]] const EVP_MD_CTX *ctx) {}
77 
EVP_DigestVerify_verify_service_indicator(const EVP_MD_CTX * ctx)78 inline void EVP_DigestVerify_verify_service_indicator(
79     [[maybe_unused]] const EVP_MD_CTX *ctx) {}
80 
HMAC_verify_service_indicator(const EVP_MD * evp_md)81 inline void HMAC_verify_service_indicator(
82     [[maybe_unused]] const EVP_MD *evp_md) {}
83 
TLSKDF_verify_service_indicator(const EVP_MD * dgst)84 inline void TLSKDF_verify_service_indicator(
85     [[maybe_unused]] const EVP_MD *dgst) {}
86 
87 #endif  // BORINGSSL_FIPS
88 
89 #endif  // OPENSSL_HEADER_SERVICE_INDICATOR_INTERNAL_H
90