| 604 | } |
| 605 | |
| 606 | bool EncryptionKey::IsModeSupported(AES_CIPHER_MODE m, bool allow_non_accelerated) { |
| 607 | bool use_gcm_on_cpu = allow_non_accelerated || CpuInfo::IsSupported(CpuInfo::PCLMULQDQ); |
| 608 | switch (m) { |
| 609 | // It becomes a bit tricky for GCM mode, because GCM mode is enabled since |
| 610 | // OpenSSL 1.0.1, but the tag validation only works since 1.0.1d. We have |
| 611 | // to make sure that OpenSSL version >= 1.0.1d for GCM. So we need |
| 612 | // SSLeay(). Note that SSLeay() may return the compiling version on |
| 613 | // certain platforms if it was built against an older version(see: |
| 614 | // IMPALA-6418). In this case, it will return false, and EncryptionKey |
| 615 | // will try to fall back to CTR mode, so it is not ideal but is OK to use |
| 616 | // SSLeay() for GCM mode here since in the worst case, we will be using |
| 617 | // AES_256_CTR in a system that supports AES_256_GCM. |
| 618 | case AES_CIPHER_MODE::AES_256_GCM: |
| 619 | return (use_gcm_on_cpu |
| 620 | && SSLeay() >= OPENSSL_VERSION_1_0_1D && EVP_aes_256_gcm); |
| 621 | |
| 622 | case AES_CIPHER_MODE::AES_128_GCM: |
| 623 | return (use_gcm_on_cpu |
| 624 | && SSLeay() >= OPENSSL_VERSION_1_0_1D && EVP_aes_128_gcm); |
| 625 | |
| 626 | case AES_CIPHER_MODE::AES_256_CTR: |
| 627 | // If TLS1.2 is supported, then we're on a verison of OpenSSL that |
| 628 | // supports AES-256-CTR. |
| 629 | return (MaxSupportedTlsVersion() >= TLS1_2_VERSION && EVP_aes_256_ctr); |
| 630 | |
| 631 | case AES_CIPHER_MODE::AES_256_CFB: |
| 632 | case AES_CIPHER_MODE::AES_256_ECB: |
| 633 | case AES_CIPHER_MODE::AES_128_ECB: |
| 634 | return true; |
| 635 | case AES_CIPHER_MODE::INVALID: |
| 636 | return false; |
| 637 | default: |
| 638 | return false; |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | AES_CIPHER_MODE EncryptionKey::GetSupportedDefaultMode() { |
| 643 | if (IsModeSupported(AES_CIPHER_MODE::AES_256_GCM)) { |
nothing calls this directly
no test coverage detected