Merge pull request #2891 from julek-wolfssl/refactor-evp-functions

Move EVP functions to evp.c
This commit is contained in:
toddouska
2020-04-14 09:22:51 -07:00
committed by GitHub
11 changed files with 4415 additions and 4447 deletions
+41 -4281
View File
File diff suppressed because it is too large Load Diff
+10 -10
View File
@@ -27460,7 +27460,7 @@ static void test_wolfSSL_EVP_PKEY_set1_get1_DSA(void)
AssertIntNE(wolfSSL_EVP_PKEY_set1_DSA(set1Pkey, dsa), WOLFSSL_SUCCESS);
/* Initialize set1Pkey */
set1Pkey = wolfSSL_PKEY_new();
set1Pkey = wolfSSL_EVP_PKEY_new();
/* Should Fail Verify: setDsa not initialized from set1Pkey */
AssertIntNE(wolfSSL_DSA_do_verify(hash,signature,setDsa,&answer),
@@ -27487,7 +27487,7 @@ static void test_wolfSSL_EVP_PKEY_set1_get1_EC_KEY (void)
printf(testingFmt,
"wolfSSL_EVP_PKEY_set1_EC_KEY and wolfSSL_EVP_PKEY_get1_EC_KEY");
AssertNotNull(ecKey = wolfSSL_EC_KEY_new());
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
/* Test wolfSSL_EVP_PKEY_set1_EC_KEY */
AssertIntEQ(wolfSSL_EVP_PKEY_set1_EC_KEY(NULL, ecKey), WOLFSSL_FAILURE);
@@ -27537,7 +27537,7 @@ static void test_wolfSSL_EVP_PKEY_set1_get1_DH (void)
AssertIntEQ(code, 0);
code = -1;
pkey = wolfSSL_PKEY_new();
pkey = wolfSSL_EVP_PKEY_new();
/* Set DH into PKEY */
AssertIntEQ(wolfSSL_EVP_PKEY_set1_DH(pkey, setDh), WOLFSSL_SUCCESS);
@@ -27789,7 +27789,7 @@ static void test_wolfSSL_EVP_PKEY_assign(void)
printf(testingFmt, "wolfSSL_EVP_PKEY_assign");
#ifndef NO_RSA
type = EVP_PKEY_RSA;
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertNotNull(rsa = wolfSSL_RSA_new());
AssertIntEQ(wolfSSL_EVP_PKEY_assign(NULL,type,rsa), WOLFSSL_FAILURE);
AssertIntEQ(wolfSSL_EVP_PKEY_assign(pkey,type,NULL), WOLFSSL_FAILURE);
@@ -27800,7 +27800,7 @@ static void test_wolfSSL_EVP_PKEY_assign(void)
#ifndef NO_DSA
type = EVP_PKEY_DSA;
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertNotNull(dsa = wolfSSL_DSA_new());
AssertIntEQ(wolfSSL_EVP_PKEY_assign(NULL,type,dsa), WOLFSSL_FAILURE);
AssertIntEQ(wolfSSL_EVP_PKEY_assign(pkey,type,NULL), WOLFSSL_FAILURE);
@@ -27811,7 +27811,7 @@ static void test_wolfSSL_EVP_PKEY_assign(void)
#ifdef HAVE_ECC
type = EVP_PKEY_EC;
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertNotNull(ecKey = wolfSSL_EC_KEY_new());
AssertIntEQ(wolfSSL_EVP_PKEY_assign(NULL,type,ecKey), WOLFSSL_FAILURE);
AssertIntEQ(wolfSSL_EVP_PKEY_assign(pkey,type,NULL), WOLFSSL_FAILURE);
@@ -28963,7 +28963,7 @@ static void test_wolfSSL_EVP_PKEY_encrypt(void)
XMEMSET(outDec, 0, rsaKeySz);
AssertNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
AssertNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
AssertIntEQ(EVP_PKEY_encrypt_init(ctx), WOLFSSL_SUCCESS);
@@ -29046,7 +29046,7 @@ static void test_wolfSSL_EVP_PKEY_sign(void)
SHA256_Final(hash, &c);
AssertNotNull(rsa = RSA_generate_key(2048, 3, NULL, NULL));
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
AssertNotNull(ctx = EVP_PKEY_CTX_new(pkey, NULL));
AssertIntEQ(EVP_PKEY_sign_init(ctx), WOLFSSL_SUCCESS);
@@ -29098,7 +29098,7 @@ static void test_EVP_PKEY_rsa(void)
WOLFSSL_EVP_PKEY* pkey;
AssertNotNull(rsa = wolfSSL_RSA_new());
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertIntEQ(EVP_PKEY_assign_RSA(NULL, rsa), WOLFSSL_FAILURE);
AssertIntEQ(EVP_PKEY_assign_RSA(pkey, NULL), WOLFSSL_FAILURE);
AssertIntEQ(EVP_PKEY_assign_RSA(pkey, rsa), WOLFSSL_SUCCESS);
@@ -29117,7 +29117,7 @@ static void test_EVP_PKEY_ec(void)
WOLFSSL_EVP_PKEY* pkey;
AssertNotNull(ecKey = wolfSSL_EC_KEY_new());
AssertNotNull(pkey = wolfSSL_PKEY_new());
AssertNotNull(pkey = wolfSSL_EVP_PKEY_new());
AssertIntEQ(EVP_PKEY_assign_EC_KEY(NULL, ecKey), WOLFSSL_FAILURE);
AssertIntEQ(EVP_PKEY_assign_EC_KEY(pkey, NULL), WOLFSSL_FAILURE);
AssertIntEQ(EVP_PKEY_assign_EC_KEY(pkey, ecKey), WOLFSSL_SUCCESS);
+4323 -128
View File
File diff suppressed because it is too large Load Diff
+1 -2
View File
@@ -207,8 +207,7 @@ int wolfCrypt_Init(void)
WOLFSSL_MSG("Using AF_ALG for crypto acceleration");
#endif
#if !defined(WOLFCRYPT_ONLY) && \
( defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) )
#if !defined(WOLFCRYPT_ONLY) && defined(OPENSSL_EXTRA)
wolfSSL_EVP_init();
#endif
+4 -4
View File
@@ -16758,8 +16758,8 @@ int openssl_pkey0_test(void)
}
keySz = (size_t)RSA_size(pubRsa);
prvPkey = wolfSSL_PKEY_new();
pubPkey = wolfSSL_PKEY_new();
prvPkey = wolfSSL_EVP_PKEY_new();
pubPkey = wolfSSL_EVP_PKEY_new();
if((prvPkey == NULL) || (pubPkey == NULL)){
printf("error with PKEY_new\n");
ret = ERR_BASE_PKEY-13;
@@ -17140,8 +17140,8 @@ int openssl_evpSig_test(void)
return ERR_BASE_EVPSIG-6;
}
prvPkey = wolfSSL_PKEY_new();
pubPkey = wolfSSL_PKEY_new();
prvPkey = wolfSSL_EVP_PKEY_new();
pubPkey = wolfSSL_EVP_PKEY_new();
if((prvPkey == NULL) || (pubPkey == NULL)){
XFREE(pubTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
XFREE(prvTmp, HEAP_HINT ,DYNAMIC_TYPE_TMP_BUFFER);
+9
View File
@@ -4553,6 +4553,15 @@ enum encrypt_side {
WOLFSSL_LOCAL int SetKeysSide(WOLFSSL*, enum encrypt_side);
/* Set*Internal and Set*External functions */
WOLFSSL_LOCAL int SetDsaInternal(WOLFSSL_DSA* dsa);
WOLFSSL_LOCAL int SetDsaExternal(WOLFSSL_DSA* dsa);
#ifndef HAVE_USER_RSA
WOLFSSL_LOCAL int SetRsaExternal(WOLFSSL_RSA* rsa);
WOLFSSL_LOCAL int SetRsaInternal(WOLFSSL_RSA* rsa);
#endif
WOLFSSL_LOCAL int SetDhInternal(WOLFSSL_DH* dh);
WOLFSSL_LOCAL int SetDhExternal(WOLFSSL_DH *dh);
#ifndef NO_DH
WOLFSSL_LOCAL int DhGenKeyPair(WOLFSSL* ssl, DhKey* dhKey,
-1
View File
@@ -64,7 +64,6 @@ WOLFSSL_API int wolfSSL_DH_size(WOLFSSL_DH*);
WOLFSSL_API int wolfSSL_DH_generate_key(WOLFSSL_DH*);
WOLFSSL_API int wolfSSL_DH_compute_key(unsigned char* key, WOLFSSL_BIGNUM* pub,
WOLFSSL_DH*);
WOLFSSL_API int SetDhExternal(WOLFSSL_DH *dh);
WOLFSSL_API int wolfSSL_DH_LoadDer(WOLFSSL_DH*, const unsigned char*, int sz);
WOLFSSL_API int wolfSSL_DH_set0_pqg(WOLFSSL_DH*, WOLFSSL_BIGNUM*,
WOLFSSL_BIGNUM*, WOLFSSL_BIGNUM*);
+26 -1
View File
@@ -543,6 +543,7 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt(WOLFSSL_EVP_PKEY_CTX *ctx,
const unsigned char *in, size_t inlen);
WOLFSSL_API int wolfSSL_EVP_PKEY_encrypt_init(WOLFSSL_EVP_PKEY_CTX *ctx);
WOLFSSL_API WOLFSSL_EVP_PKEY *wolfSSL_EVP_PKEY_new(void);
WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_EVP_PKEY_new_ex(void* heap);
WOLFSSL_API void wolfSSL_EVP_PKEY_free(WOLFSSL_EVP_PKEY*);
WOLFSSL_API int wolfSSL_EVP_PKEY_size(WOLFSSL_EVP_PKEY *pkey);
WOLFSSL_API int wolfSSL_EVP_PKEY_missing_parameters(WOLFSSL_EVP_PKEY *pkey);
@@ -602,6 +603,10 @@ WOLFSSL_API int wolfSSL_PKCS5_PBKDF2_HMAC(const char *pass, int passlen,
int saltlen, int iter,
const WOLFSSL_EVP_MD *digest,
int keylen, unsigned char *out);
WOLFSSL_LOCAL int wolfSSL_EVP_get_hashinfo(const WOLFSSL_EVP_MD* evp,
int* pHash, int* pHashSz);
#define EVP_CIPH_STREAM_CIPHER WOLFSSL_EVP_CIPH_STREAM_CIPHER
#define EVP_CIPH_ECB_MODE WOLFSSL_EVP_CIPH_ECB_MODE
#define EVP_CIPH_CBC_MODE WOLFSSL_EVP_CIPH_CBC_MODE
@@ -763,6 +768,7 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
#define EVP_PKEY_assign_EC_KEY wolfSSL_EVP_PKEY_assign_EC_KEY
#define EVP_PKEY_get1_DSA wolfSSL_EVP_PKEY_get1_DSA
#define EVP_PKEY_set1_DSA wolfSSL_EVP_PKEY_set1_DSA
#define EVP_PKEY_get0_RSA wolfSSL_EVP_PKEY_get0_RSA
#define EVP_PKEY_get1_RSA wolfSSL_EVP_PKEY_get1_RSA
#define EVP_PKEY_set1_RSA wolfSSL_EVP_PKEY_set1_RSA
#define EVP_PKEY_set1_EC_KEY wolfSSL_EVP_PKEY_set1_EC_KEY
@@ -788,7 +794,7 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
#define EVP_PKEY_decrypt_init wolfSSL_EVP_PKEY_decrypt_init
#define EVP_PKEY_encrypt wolfSSL_EVP_PKEY_encrypt
#define EVP_PKEY_encrypt_init wolfSSL_EVP_PKEY_encrypt_init
#define EVP_PKEY_new wolfSSL_PKEY_new
#define EVP_PKEY_new wolfSSL_EVP_PKEY_new
#define EVP_PKEY_free wolfSSL_EVP_PKEY_free
#define EVP_PKEY_up_ref wolfSSL_EVP_PKEY_up_ref
#define EVP_PKEY_size wolfSSL_EVP_PKEY_size
@@ -875,6 +881,25 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
#define EVP_MAX_IV_LENGTH 16
#endif
#define EVP_R_BAD_DECRYPT (-MIN_CODE_E + 100 + 1)
#define EVP_R_BN_DECODE_ERROR (-MIN_CODE_E + 100 + 2)
#define EVP_R_DECODE_ERROR (-MIN_CODE_E + 100 + 3)
#define EVP_R_PRIVATE_KEY_DECODE_ERROR (-MIN_CODE_E + 100 + 4)
#define EVP_PKEY_NONE NID_undef
#define EVP_PKEY_RSA 6
#define EVP_PKEY_RSA2 19
#define EVP_PKEY_DH 28
#define EVP_CIPHER_mode WOLFSSL_CIPHER_mode
/* WOLFSSL_EVP_CIPHER is just the string name of the cipher */
#define EVP_CIPHER_name(x) x
#define EVP_MD_CTX_reset wolfSSL_EVP_MD_CTX_cleanup
/* WOLFSSL_EVP_MD is just the string name of the digest */
#define EVP_MD_name(x) x
#define EVP_CIPHER_nid wolfSSL_EVP_CIPHER_nid
WOLFSSL_API void printPKEY(WOLFSSL_EVP_PKEY *k);
#ifdef __cplusplus
-1
View File
@@ -157,7 +157,6 @@ WOLFSSL_API int wolfSSL_RSA_set_ex_data(WOLFSSL_RSA *rsa, int idx, void *data);
#define RSA_sign wolfSSL_RSA_sign
#define RSA_verify wolfSSL_RSA_verify
#define RSA_public_decrypt wolfSSL_RSA_public_decrypt
#define EVP_PKEY_get0_RSA wolfSSL_EVP_PKEY_get0_RSA
#define RSA_meth_new wolfSSL_RSA_meth_new
#define RSA_meth_free wolfSSL_RSA_meth_free
-16
View File
@@ -1114,11 +1114,6 @@ enum {
#define PEM_R_BAD_PASSWORD_READ (-MIN_CODE_E + 3)
#define PEM_R_BAD_DECRYPT (-MIN_CODE_E + 4)
#define EVP_R_BAD_DECRYPT (-MIN_CODE_E + 100 + 1)
#define EVP_R_BN_DECODE_ERROR (-MIN_CODE_E + 100 + 2)
#define EVP_R_DECODE_ERROR (-MIN_CODE_E + 100 + 3)
#define EVP_R_PRIVATE_KEY_DECODE_ERROR (-MIN_CODE_E + 100 + 4)
#define ERR_LIB_PEM 9
#define ERR_LIB_X509 10
#define ERR_LIB_EVP 11
@@ -1205,10 +1200,6 @@ enum {
#define SSL_get0_param wolfSSL_get0_param
#define ERR_NUM_ERRORS 16
#define EVP_PKEY_NONE NID_undef
#define EVP_PKEY_RSA 6
#define EVP_PKEY_RSA2 19
#define EVP_PKEY_DH 28
#define SN_pkcs9_emailAddress "Email"
#define LN_pkcs9_emailAddress "emailAddress"
#define NID_pkcs9_emailAddress 48
@@ -1229,19 +1220,12 @@ enum {
#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (0xc02b)
#define TLS1_CK_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (0xcca9)
#define EVP_CIPHER_mode WOLFSSL_CIPHER_mode
/* WOLFSSL_EVP_CIPHER is just the string name of the cipher */
#define EVP_CIPHER_name(x) x
#define EVP_MD_CTX_reset wolfSSL_EVP_MD_CTX_cleanup
/* WOLFSSL_EVP_MD is just the string name of the digest */
#define EVP_MD_name(x) x
#define X509_STORE_get0_objects wolfSSL_X509_STORE_get0_objects
#define sk_X509_OBJECT_num wolfSSL_sk_X509_OBJECT_num
#define sk_X509_OBJECT_value wolfSSL_sk_X509_OBJECT_value
#define sk_X509_OBJECT_delete wolfSSL_sk_X509_OBJECT_delete
#define X509_OBJECT_free wolfSSL_X509_OBJECT_free
#define X509_OBJECT_get_type(x) 0
#define EVP_CIPHER_nid wolfSSL_EVP_CIPHER_nid
#define OpenSSL_version(x) wolfSSL_lib_version()
+1 -3
View File
@@ -1165,7 +1165,7 @@ WOLFSSL_API WOLFSSL_SESSION* wolfSSL_get1_session(WOLFSSL* ssl);
/* what's ref count */
WOLFSSL_API WOLFSSL_X509* wolfSSL_X509_new(void);
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
#if defined(OPENSSL_EXTRA_X509_SMALL) || defined(OPENSSL_ALL)
WOLFSSL_API int wolfSSL_RSA_up_ref(WOLFSSL_RSA* rsa);
WOLFSSL_API int wolfSSL_X509_up_ref(WOLFSSL_X509* x509);
WOLFSSL_API int wolfSSL_EVP_PKEY_up_ref(WOLFSSL_EVP_PKEY* pkey);
@@ -1420,8 +1420,6 @@ WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_d2i_PrivateKey_EVP(WOLFSSL_EVP_PKEY** key,
unsigned char** in, long inSz);
WOLFSSL_API int wolfSSL_i2d_PrivateKey(WOLFSSL_EVP_PKEY* key,
unsigned char** der);
WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_PKEY_new_ex(void* heap);
WOLFSSL_API WOLFSSL_EVP_PKEY* wolfSSL_PKEY_new(void);
WOLFSSL_API int wolfSSL_X509_cmp_current_time(const WOLFSSL_ASN1_TIME*);
#ifdef OPENSSL_EXTRA
WOLFSSL_API int wolfSSL_X509_cmp_time(const WOLFSSL_ASN1_TIME* asnTime,