From 1e4884f615b20946411a74e41eb9c6aa65e2d5f3 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Thu, 24 Sep 2015 10:57:52 -0700 Subject: external/boringssl: sync with upstream. This change imports the current version of BoringSSL. The only local change now is that |BORINGSSL_201509| is defined in base.h. This allows this change to be made without (hopefully) breaking the build. This change will need https://android-review.googlesource.com/172744 to be landed afterwards to update a test. Change-Id: I6d1f463f7785a2423bd846305af91c973c326104 --- src/crypto/cipher/cipher_test.cc | 57 +++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 13 deletions(-) (limited to 'src/crypto/cipher/cipher_test.cc') diff --git a/src/crypto/cipher/cipher_test.cc b/src/crypto/cipher/cipher_test.cc index 97a84e0..5f04178 100644 --- a/src/crypto/cipher/cipher_test.cc +++ b/src/crypto/cipher/cipher_test.cc @@ -69,6 +69,12 @@ static const EVP_CIPHER *GetCipher(const std::string &name) { if (name == "DES-CBC") { return EVP_des_cbc(); + } else if (name == "DES-ECB") { + return EVP_des_ecb(); + } else if (name == "DES-EDE") { + return EVP_des_ede(); + } else if (name == "DES-EDE-CBC") { + return EVP_des_ede_cbc(); } else if (name == "DES-EDE3-CBC") { return EVP_des_ede3_cbc(); } else if (name == "RC4") { @@ -104,6 +110,7 @@ static const EVP_CIPHER *GetCipher(const std::string &name) { static bool TestOperation(FileTest *t, const EVP_CIPHER *cipher, bool encrypt, + bool streaming, const std::vector &key, const std::vector &iv, const std::vector &plaintext, @@ -160,11 +167,29 @@ static bool TestOperation(FileTest *t, (!aad.empty() && !EVP_CipherUpdate(ctx.get(), nullptr, &unused, bssl::vector_data(&aad), aad.size())) || - !EVP_CIPHER_CTX_set_padding(ctx.get(), 0) || - (!in->empty() && - !EVP_CipherUpdate(ctx.get(), bssl::vector_data(&result), &result_len1, - bssl::vector_data(in), in->size())) || - !EVP_CipherFinal_ex(ctx.get(), bssl::vector_data(&result) + result_len1, + !EVP_CIPHER_CTX_set_padding(ctx.get(), 0)) { + t->PrintLine("Operation failed."); + return false; + } + if (streaming) { + for (size_t i = 0; i < in->size(); i++) { + uint8_t c = (*in)[i]; + int len; + if (!EVP_CipherUpdate(ctx.get(), bssl::vector_data(&result) + result_len1, + &len, &c, 1)) { + t->PrintLine("Operation failed."); + return false; + } + result_len1 += len; + } + } else if (!in->empty() && + !EVP_CipherUpdate(ctx.get(), bssl::vector_data(&result), + &result_len1, bssl::vector_data(in), + in->size())) { + t->PrintLine("Operation failed."); + return false; + } + if (!EVP_CipherFinal_ex(ctx.get(), bssl::vector_data(&result) + result_len1, &result_len2)) { t->PrintLine("Operation failed."); return false; @@ -236,15 +261,21 @@ static bool TestCipher(FileTest *t, void *arg) { } // By default, both directions are run, unless overridden by the operation. - if (operation != kDecrypt && - !TestOperation(t, cipher, true /* encrypt */, key, iv, plaintext, - ciphertext, aad, tag)) { - return false; + if (operation != kDecrypt) { + if (!TestOperation(t, cipher, true /* encrypt */, false /* single-shot */, + key, iv, plaintext, ciphertext, aad, tag) || + !TestOperation(t, cipher, true /* encrypt */, true /* streaming */, key, + iv, plaintext, ciphertext, aad, tag)) { + return false; + } } - if (operation != kEncrypt && - !TestOperation(t, cipher, false /* decrypt */, key, iv, plaintext, - ciphertext, aad, tag)) { - return false; + if (operation != kEncrypt) { + if (!TestOperation(t, cipher, false /* decrypt */, false /* single-shot */, + key, iv, plaintext, ciphertext, aad, tag) || + !TestOperation(t, cipher, false /* decrypt */, true /* streaming */, + key, iv, plaintext, ciphertext, aad, tag)) { + return false; + } } return true; -- cgit v1.1