Add functions to allow the mocking of AES hw support for testing. Bug: 586 Change-Id: I5bc8e6df3a5a14e6b218f41181d06406e835f9c1 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/58605 Reviewed-by: Adam Langley <agl@google.com> Commit-Queue: Bob Beck <bbe@google.com>
diff --git a/ssl/ssl_lib.cc b/ssl/ssl_lib.cc index 86e8eb3..c035825 100644 --- a/ssl/ssl_lib.cc +++ b/ssl/ssl_lib.cc
@@ -484,6 +484,17 @@ return true; } +void SSL_CTX_set_aes_hw_override_for_testing(SSL_CTX *ctx, + bool override_value) { + ctx->aes_hw_override = true; + ctx->aes_hw_override_value = override_value; +} + +void SSL_set_aes_hw_override_for_testing(SSL *ssl, bool override_value) { + ssl->config->aes_hw_override = true; + ssl->config->aes_hw_override_value = override_value; +} + BSSL_NAMESPACE_END using namespace bssl; @@ -525,7 +536,9 @@ false_start_allowed_without_alpn(false), handoff(false), enable_early_data(false), - only_fips_cipher_suites_in_tls13(false) { + only_fips_cipher_suites_in_tls13(false), + aes_hw_override(false), + aes_hw_override_value(false) { CRYPTO_MUTEX_init(&lock); CRYPTO_new_ex_data(&ex_data); } @@ -647,6 +660,8 @@ ssl->config->permute_extensions = ctx->permute_extensions; ssl->config->only_fips_cipher_suites_in_tls13 = ctx->only_fips_cipher_suites_in_tls13; + ssl->config->aes_hw_override = ctx->aes_hw_override; + ssl->config->aes_hw_override_value = ctx->aes_hw_override_value; if (!ssl->config->supported_group_list.CopyFrom(ctx->supported_group_list) || !ssl->config->alpn_client_proto_list.CopyFrom( @@ -2026,18 +2041,27 @@ } int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) { - return ssl_create_cipher_list(&ctx->cipher_list, str, false /* not strict */); + const bool has_aes_hw = ctx->aes_hw_override ? ctx->aes_hw_override_value + : EVP_has_aes_hardware(); + return ssl_create_cipher_list(&ctx->cipher_list, has_aes_hw, str, + false /* not strict */); } int SSL_CTX_set_strict_cipher_list(SSL_CTX *ctx, const char *str) { - return ssl_create_cipher_list(&ctx->cipher_list, str, true /* strict */); + const bool has_aes_hw = ctx->aes_hw_override ? ctx->aes_hw_override_value + : EVP_has_aes_hardware(); + return ssl_create_cipher_list(&ctx->cipher_list, has_aes_hw, str, + true /* strict */); } int SSL_set_cipher_list(SSL *ssl, const char *str) { if (!ssl->config) { return 0; } - return ssl_create_cipher_list(&ssl->config->cipher_list, str, + const bool has_aes_hw = ssl->config->aes_hw_override + ? ssl->config->aes_hw_override_value + : EVP_has_aes_hardware(); + return ssl_create_cipher_list(&ssl->config->cipher_list, has_aes_hw, str, false /* not strict */); } @@ -2045,7 +2069,10 @@ if (!ssl->config) { return 0; } - return ssl_create_cipher_list(&ssl->config->cipher_list, str, + const bool has_aes_hw = ssl->config->aes_hw_override + ? ssl->config->aes_hw_override_value + : EVP_has_aes_hardware(); + return ssl_create_cipher_list(&ssl->config->cipher_list, has_aes_hw, str, true /* strict */); }