/* * Written by Dr Stephen N Henson ([email protected]) for the OpenSSL * project. */ /* ==================================================================== * Copyright (c) 2015 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [email protected]. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ #include <openssl/evp.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> OPENSSL_MSVC_PRAGMA(…) OPENSSL_MSVC_PRAGMA(…) #include <map> #include <string> #include <utility> #include <vector> OPENSSL_MSVC_PRAGMA(…) #include <gtest/gtest.h> #include <openssl/bn.h> #include <openssl/bytestring.h> #include <openssl/crypto.h> #include <openssl/digest.h> #include <openssl/dh.h> #include <openssl/dsa.h> #include <openssl/err.h> #include <openssl/rsa.h> #include "../test/file_test.h" #include "../test/test_util.h" #include "../test/wycheproof_util.h" // evp_test dispatches between multiple test types. PrivateKey tests take a key // name parameter and single block, decode it as a PEM private key, and save it // under that key name. Decrypt, Sign, and Verify tests take a previously // imported key name as parameter and test their respective operations. static const EVP_MD *GetDigest(FileTest *t, const std::string &name) { … } static int GetKeyType(FileTest *t, const std::string &name) { … } static bool GetRSAPadding(FileTest *t, int *out, const std::string &name) { … } KeyMap; static bool ImportKey(FileTest *t, KeyMap *key_map, EVP_PKEY *(*parse_func)(CBS *cbs), int (*marshal_func)(CBB *cbb, const EVP_PKEY *key)) { … } static bool GetOptionalBignum(FileTest *t, bssl::UniquePtr<BIGNUM> *out, const std::string &key) { … } static bool ImportDHKey(FileTest *t, KeyMap *key_map) { … } // SetupContext configures |ctx| based on attributes in |t|, with the exception // of the signing digest which must be configured externally. static bool SetupContext(FileTest *t, KeyMap *key_map, EVP_PKEY_CTX *ctx) { … } static bool TestDerive(FileTest *t, KeyMap *key_map, EVP_PKEY *key) { … } static bool TestEVP(FileTest *t, KeyMap *key_map) { … } TEST(EVPTest, TestVectors) { … } static void RunWycheproofVerifyTest(const char *path) { … } TEST(EVPTest, WycheproofDSA) { … } TEST(EVPTest, WycheproofECDSAP224) { … } TEST(EVPTest, WycheproofECDSAP256) { … } TEST(EVPTest, WycheproofECDSAP384) { … } TEST(EVPTest, WycheproofECDSAP521) { … } TEST(EVPTest, WycheproofEdDSA) { … } TEST(EVPTest, WycheproofRSAPKCS1) { … } TEST(EVPTest, WycheproofRSAPKCS1Sign) { … } TEST(EVPTest, WycheproofRSAPSS) { … } static void RunWycheproofDecryptTest( const char *path, std::function<void(FileTest *, EVP_PKEY_CTX *)> setup_cb) { … } static void RunWycheproofOAEPTest(const char *path) { … } TEST(EVPTest, WycheproofRSAOAEP2048) { … } TEST(EVPTest, WycheproofRSAOAEP3072) { … } TEST(EVPTest, WycheproofRSAOAEP4096) { … } TEST(EVPTest, WycheproofRSAOAEPMisc) { … } static void RunWycheproofPKCS1DecryptTest(const char *path) { … } TEST(EVPTest, WycheproofRSAPKCS1Decrypt) { … }