MCPcopy Create free account
hub / github.com/apache/impala / TEST_F

Function TEST_F

be/src/util/openssl-util-test.cc:137–174  ·  view source on GitHub ↗

Test basic encryption functionality.

Source from the content-addressed store, hash-verified

135
136/// Test basic encryption functionality.
137TEST_F(OpenSSLUtilTest, Encryption) {
138 const int buffer_size = 1024 * 1024;
139 vector<uint8_t> original(buffer_size);
140 vector<uint8_t> prev_encrypted(buffer_size);
141 vector<uint8_t> encrypted(buffer_size);
142 vector<uint8_t> decrypted(buffer_size);
143 GenerateRandomData(original.data(), buffer_size);
144
145 // Check GCM, CTR and CFB
146 AES_CIPHER_MODE modes[] = {
147 AES_CIPHER_MODE::AES_256_GCM,
148 AES_CIPHER_MODE::AES_256_CTR,
149 AES_CIPHER_MODE::AES_256_CFB,
150 AES_CIPHER_MODE::AES_128_GCM
151 };
152 for (auto m : modes) {
153 // Iterate multiple times to ensure that key regeneration works correctly.
154 EncryptionKey key;
155 for (int i = 0; i < 2; ++i) {
156 // Generate a new key for each iteration.
157 ASSERT_OK(key.InitializeRandom(AES_BLOCK_SIZE, m));
158
159 // Check that OpenSSL is happy with the amount of entropy we're feeding it.
160 DCHECK_EQ(1, RAND_status());
161
162 ASSERT_OK(key.Encrypt(original.data(), buffer_size, encrypted.data()));
163 if (i > 0) {
164 // Check that we're not somehow reusing the same key.
165 ASSERT_NE(0, memcmp(encrypted.data(), prev_encrypted.data(), buffer_size));
166 }
167 memcpy(prev_encrypted.data(), encrypted.data(), buffer_size);
168
169 // We should get the original data by decrypting it.
170 ASSERT_OK(key.Decrypt(encrypted.data(), buffer_size, decrypted.data()));
171 ASSERT_EQ(0, memcmp(original.data(), decrypted.data(), buffer_size));
172 }
173 }
174}
175
176/// Test to check whether key and mode are validated in InitializeFields().
177TEST_F(OpenSSLUtilTest, ValidateInitialize) {

Callers

nothing calls this directly

Calls 15

ValidatePemBundleFunction · 0.85
SubstituteFunction · 0.85
read_certFunction · 0.85
_msg_timeFunction · 0.85
unlinkFunction · 0.85
InitializeRandomMethod · 0.80
EncryptMethod · 0.80
DecryptMethod · 0.80
InitializeFieldsMethod · 0.80
IsGcmModeMethod · 0.80
GetDetailMethod · 0.80

Tested by

no test coverage detected