diff options
author | Kenny Root <kroot@google.com> | 2015-09-25 02:46:08 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-09-25 02:46:08 +0000 |
commit | 217603a4384148cd37c60a42f945449641617d27 (patch) | |
tree | dd743d9d64af3145fe96b8d5fc2f3427544794bd /src/crypto/cipher/aead_test.cc | |
parent | e246de8f184e644debf965ecdca552f006b56881 (diff) | |
parent | d947d006e7a7ebcfdfe642e686250caf2028c2c1 (diff) | |
download | external_boringssl-217603a4384148cd37c60a42f945449641617d27.zip external_boringssl-217603a4384148cd37c60a42f945449641617d27.tar.gz external_boringssl-217603a4384148cd37c60a42f945449641617d27.tar.bz2 |
am d947d006: am b8494591: Revert "Revert "external/boringssl: sync with upstream.""
* commit 'd947d006e7a7ebcfdfe642e686250caf2028c2c1':
Revert "Revert "external/boringssl: sync with upstream.""
Diffstat (limited to 'src/crypto/cipher/aead_test.cc')
-rw-r--r-- | src/crypto/cipher/aead_test.cc | 62 |
1 files changed, 26 insertions, 36 deletions
diff --git a/src/crypto/cipher/aead_test.cc b/src/crypto/cipher/aead_test.cc index e4b75d6..baaee9e 100644 --- a/src/crypto/cipher/aead_test.cc +++ b/src/crypto/cipher/aead_test.cc @@ -22,6 +22,7 @@ #include <openssl/err.h> #include "../test/file_test.h" +#include "../test/scoped_types.h" #include "../test/stl_compat.h" @@ -35,18 +36,6 @@ // CT: 5294265a60 // TAG: 1d45758621762e061368e68868e2f929 -// EVP_AEAD_CTX lacks a zero state, so it doesn't fit easily into -// ScopedOpenSSLContext. -class EVP_AEAD_CTXScoper { - public: - EVP_AEAD_CTXScoper(EVP_AEAD_CTX *ctx) : ctx_(ctx) {} - ~EVP_AEAD_CTXScoper() { - EVP_AEAD_CTX_cleanup(ctx_); - } - private: - EVP_AEAD_CTX *ctx_; -}; - static bool TestAEAD(FileTest *t, void *arg) { const EVP_AEAD *aead = reinterpret_cast<const EVP_AEAD*>(arg); @@ -60,20 +49,19 @@ static bool TestAEAD(FileTest *t, void *arg) { return false; } - EVP_AEAD_CTX ctx; - if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bssl::vector_data(&key), - key.size(), tag.size(), - evp_aead_seal)) { + ScopedEVP_AEAD_CTX ctx; + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, + bssl::vector_data(&key), key.size(), + tag.size(), evp_aead_seal)) { t->PrintLine("Failed to init AEAD."); return false; } - EVP_AEAD_CTXScoper cleanup(&ctx); std::vector<uint8_t> out(in.size() + EVP_AEAD_max_overhead(aead)); if (!t->HasAttribute("NO_SEAL")) { size_t out_len; - if (!EVP_AEAD_CTX_seal(&ctx, bssl::vector_data(&out), &out_len, out.size(), - bssl::vector_data(&nonce), nonce.size(), + if (!EVP_AEAD_CTX_seal(ctx.get(), bssl::vector_data(&out), &out_len, + out.size(), bssl::vector_data(&nonce), nonce.size(), bssl::vector_data(&in), in.size(), bssl::vector_data(&ad), ad.size())) { t->PrintLine("Failed to run AEAD."); @@ -101,17 +89,17 @@ static bool TestAEAD(FileTest *t, void *arg) { // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. - EVP_AEAD_CTX_cleanup(&ctx); - if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bssl::vector_data(&key), - key.size(), tag.size(), - evp_aead_open)) { + ctx.Reset(); + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, + bssl::vector_data(&key), key.size(), + tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; } std::vector<uint8_t> out2(out.size()); size_t out2_len; - int ret = EVP_AEAD_CTX_open(&ctx, + int ret = EVP_AEAD_CTX_open(ctx.get(), bssl::vector_data(&out2), &out2_len, out2.size(), bssl::vector_data(&nonce), nonce.size(), bssl::vector_data(&out), out.size(), @@ -137,10 +125,10 @@ static bool TestAEAD(FileTest *t, void *arg) { // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. - EVP_AEAD_CTX_cleanup(&ctx); - if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bssl::vector_data(&key), - key.size(), tag.size(), - evp_aead_open)) { + ctx.Reset(); + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, + bssl::vector_data(&key), key.size(), + tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; } @@ -148,8 +136,8 @@ static bool TestAEAD(FileTest *t, void *arg) { // Garbage at the end isn't ignored. out.push_back(0); out2.resize(out.size()); - if (EVP_AEAD_CTX_open(&ctx, bssl::vector_data(&out2), &out2_len, out2.size(), - bssl::vector_data(&nonce), nonce.size(), + if (EVP_AEAD_CTX_open(ctx.get(), bssl::vector_data(&out2), &out2_len, + out2.size(), bssl::vector_data(&nonce), nonce.size(), bssl::vector_data(&out), out.size(), bssl::vector_data(&ad), ad.size())) { t->PrintLine("Decrypted bad data with trailing garbage."); @@ -159,10 +147,10 @@ static bool TestAEAD(FileTest *t, void *arg) { // The "stateful" AEADs for implementing pre-AEAD cipher suites need to be // reset after each operation. - EVP_AEAD_CTX_cleanup(&ctx); - if (!EVP_AEAD_CTX_init_with_direction(&ctx, aead, bssl::vector_data(&key), - key.size(), tag.size(), - evp_aead_open)) { + ctx.Reset(); + if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, + bssl::vector_data(&key), key.size(), + tag.size(), evp_aead_open)) { t->PrintLine("Failed to init AEAD."); return false; } @@ -171,8 +159,8 @@ static bool TestAEAD(FileTest *t, void *arg) { out[0] ^= 0x80; out.resize(out.size() - 1); out2.resize(out.size()); - if (EVP_AEAD_CTX_open(&ctx, bssl::vector_data(&out2), &out2_len, out2.size(), - bssl::vector_data(&nonce), nonce.size(), + if (EVP_AEAD_CTX_open(ctx.get(), bssl::vector_data(&out2), &out2_len, + out2.size(), bssl::vector_data(&nonce), nonce.size(), bssl::vector_data(&out), out.size(), bssl::vector_data(&ad), ad.size())) { t->PrintLine("Decrypted bad data with corrupted byte."); @@ -200,6 +188,7 @@ static int TestCleanupAfterInitFailure(const EVP_AEAD *aead) { fprintf(stderr, "A silly tag length didn't trigger an error!\n"); return 0; } + ERR_clear_error(); /* Running a second, failed _init should not cause a memory leak. */ if (EVP_AEAD_CTX_init(&ctx, aead, key, key_len, @@ -208,6 +197,7 @@ static int TestCleanupAfterInitFailure(const EVP_AEAD *aead) { fprintf(stderr, "A silly tag length didn't trigger an error!\n"); return 0; } + ERR_clear_error(); /* Calling _cleanup on an |EVP_AEAD_CTX| after a failed _init should be a * no-op. */ |