mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 12:14:38 +02:00
Change the following functions to behave the same as opeSSL:
- EVP_CIPHER_CTX_cleanup - BIO_free - EVP_PKEY_cmp
This commit is contained in:
@@ -16286,8 +16286,9 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
XFREE(bio, 0, DYNAMIC_TYPE_OPENSSL);
|
XFREE(bio, 0, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
return WOLFSSL_SUCCESS;
|
||||||
}
|
}
|
||||||
return 1;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* like BIO_free, but no return value */
|
/* like BIO_free, but no return value */
|
||||||
|
21
tests/api.c
21
tests/api.c
@@ -37690,6 +37690,7 @@ static void test_EVP_PKEY_cmp(void)
|
|||||||
EVP_PKEY *a, *b;
|
EVP_PKEY *a, *b;
|
||||||
const unsigned char *in;
|
const unsigned char *in;
|
||||||
|
|
||||||
|
printf(testingFmt, "wolfSSL_EVP_PKEY_cmp()");
|
||||||
#if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
|
#if !defined(NO_RSA) && defined(USE_CERT_BUFFERS_2048)
|
||||||
in = client_key_der_2048;
|
in = client_key_der_2048;
|
||||||
AssertNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
|
AssertNotNull(a = wolfSSL_d2i_PrivateKey(EVP_PKEY_RSA, NULL,
|
||||||
@@ -37699,7 +37700,11 @@ static void test_EVP_PKEY_cmp(void)
|
|||||||
&in, (long)sizeof_client_key_der_2048));
|
&in, (long)sizeof_client_key_der_2048));
|
||||||
|
|
||||||
/* Test success case RSA */
|
/* Test success case RSA */
|
||||||
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(a, b), 1);
|
||||||
|
#else
|
||||||
AssertIntEQ(EVP_PKEY_cmp(a, b), 0);
|
AssertIntEQ(EVP_PKEY_cmp(a, b), 0);
|
||||||
|
#endif /* WOLFSSL_ERROR_CODE_OPENSSL */
|
||||||
|
|
||||||
EVP_PKEY_free(b);
|
EVP_PKEY_free(b);
|
||||||
EVP_PKEY_free(a);
|
EVP_PKEY_free(a);
|
||||||
@@ -37714,7 +37719,11 @@ static void test_EVP_PKEY_cmp(void)
|
|||||||
&in, (long)sizeof_ecc_clikey_der_256));
|
&in, (long)sizeof_ecc_clikey_der_256));
|
||||||
|
|
||||||
/* Test success case ECC */
|
/* Test success case ECC */
|
||||||
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(a, b), 1);
|
||||||
|
#else
|
||||||
AssertIntEQ(EVP_PKEY_cmp(a, b), 0);
|
AssertIntEQ(EVP_PKEY_cmp(a, b), 0);
|
||||||
|
#endif /* WOLFSSL_ERROR_CODE_OPENSSL */
|
||||||
|
|
||||||
EVP_PKEY_free(b);
|
EVP_PKEY_free(b);
|
||||||
EVP_PKEY_free(a);
|
EVP_PKEY_free(a);
|
||||||
@@ -37731,8 +37740,11 @@ static void test_EVP_PKEY_cmp(void)
|
|||||||
AssertNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
|
AssertNotNull(b = wolfSSL_d2i_PrivateKey(EVP_PKEY_EC, NULL,
|
||||||
&in, (long)sizeof_ecc_clikey_der_256));
|
&in, (long)sizeof_ecc_clikey_der_256));
|
||||||
|
|
||||||
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(a, b), -1);
|
||||||
|
#else
|
||||||
AssertIntNE(EVP_PKEY_cmp(a, b), 0);
|
AssertIntNE(EVP_PKEY_cmp(a, b), 0);
|
||||||
|
#endif /* WOLFSSL_ERROR_CODE_OPENSSL */
|
||||||
EVP_PKEY_free(b);
|
EVP_PKEY_free(b);
|
||||||
EVP_PKEY_free(a);
|
EVP_PKEY_free(a);
|
||||||
#endif
|
#endif
|
||||||
@@ -37740,10 +37752,17 @@ static void test_EVP_PKEY_cmp(void)
|
|||||||
/* invalid or empty failure cases */
|
/* invalid or empty failure cases */
|
||||||
a = EVP_PKEY_new();
|
a = EVP_PKEY_new();
|
||||||
b = EVP_PKEY_new();
|
b = EVP_PKEY_new();
|
||||||
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(NULL, NULL), 0);
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(a, NULL), 0);
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(NULL, b), 0);
|
||||||
|
AssertIntEQ(EVP_PKEY_cmp(a, b), 0);
|
||||||
|
#else
|
||||||
AssertIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
|
AssertIntNE(EVP_PKEY_cmp(NULL, NULL), 0);
|
||||||
AssertIntNE(EVP_PKEY_cmp(a, NULL), 0);
|
AssertIntNE(EVP_PKEY_cmp(a, NULL), 0);
|
||||||
AssertIntNE(EVP_PKEY_cmp(NULL, b), 0);
|
AssertIntNE(EVP_PKEY_cmp(NULL, b), 0);
|
||||||
AssertIntNE(EVP_PKEY_cmp(a, b), 0);
|
AssertIntNE(EVP_PKEY_cmp(a, b), 0);
|
||||||
|
#endif
|
||||||
EVP_PKEY_free(b);
|
EVP_PKEY_free(b);
|
||||||
EVP_PKEY_free(a);
|
EVP_PKEY_free(a);
|
||||||
|
|
||||||
|
@@ -1975,17 +1975,29 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_missing_parameters(WOLFSSL_EVP_PKEY *pkey)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* wolfSSL_EVP_PKEY_cmp
|
||||||
|
* returns 0 on success, -1 on failure.
|
||||||
|
*
|
||||||
|
* This behavior is different from openssl.
|
||||||
|
* EVP_PKEY_cmp returns:
|
||||||
|
* 1 : two keys match
|
||||||
|
* 0 : do not match
|
||||||
|
* -1: key types are different
|
||||||
|
* -2: the operation is not supported
|
||||||
|
* If you mant this function behave the same as openSSL,
|
||||||
|
* define WOLFSSL_ERROR_CODE_OPENSSL so that WS_RETURN_CODE fills the gap.
|
||||||
|
*/
|
||||||
WOLFSSL_API int wolfSSL_EVP_PKEY_cmp(const WOLFSSL_EVP_PKEY *a, const WOLFSSL_EVP_PKEY *b)
|
WOLFSSL_API int wolfSSL_EVP_PKEY_cmp(const WOLFSSL_EVP_PKEY *a, const WOLFSSL_EVP_PKEY *b)
|
||||||
{
|
{
|
||||||
int ret = -1; /* failure */
|
int ret = -1; /* failure */
|
||||||
int a_sz = 0, b_sz = 0;
|
int a_sz = 0, b_sz = 0;
|
||||||
|
|
||||||
if (a == NULL || b == NULL)
|
if (a == NULL || b == NULL)
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, WOLFSSL_FAILURE);
|
||||||
|
|
||||||
/* check its the same type of key */
|
/* check its the same type of key */
|
||||||
if (a->type != b->type)
|
if (a->type != b->type)
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, -1);
|
||||||
|
|
||||||
/* get size based on key type */
|
/* get size based on key type */
|
||||||
switch (a->type) {
|
switch (a->type) {
|
||||||
@@ -2006,27 +2018,30 @@ WOLFSSL_API int wolfSSL_EVP_PKEY_cmp(const WOLFSSL_EVP_PKEY *a, const WOLFSSL_EV
|
|||||||
break;
|
break;
|
||||||
#endif /* HAVE_ECC */
|
#endif /* HAVE_ECC */
|
||||||
default:
|
default:
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, -2);
|
||||||
} /* switch (a->type) */
|
} /* switch (a->type) */
|
||||||
|
|
||||||
/* check size */
|
/* check size */
|
||||||
if (a_sz <= 0 || b_sz <= 0 || a_sz != b_sz) {
|
if (a_sz <= 0 || b_sz <= 0 || a_sz != b_sz) {
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, WOLFSSL_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check public key size */
|
/* check public key size */
|
||||||
if (a->pkey_sz > 0 && b->pkey_sz > 0 && a->pkey_sz != b->pkey_sz) {
|
if (a->pkey_sz > 0 && b->pkey_sz > 0 && a->pkey_sz != b->pkey_sz) {
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, WOLFSSL_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check public key */
|
/* check public key */
|
||||||
if (a->pkey.ptr && b->pkey.ptr) {
|
if (a->pkey.ptr && b->pkey.ptr) {
|
||||||
if (XMEMCMP(a->pkey.ptr, b->pkey.ptr, a->pkey_sz) != 0) {
|
if (XMEMCMP(a->pkey.ptr, b->pkey.ptr, a->pkey_sz) != 0) {
|
||||||
return ret;
|
return WS_RETURN_CODE(ret, WOLFSSL_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
|
ret = 1; /* the keys match */
|
||||||
|
#else
|
||||||
ret = 0; /* success */
|
ret = 0; /* success */
|
||||||
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4124,9 +4139,10 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
}
|
}
|
||||||
ctx->gcmAuthInSz = 0;
|
ctx->gcmAuthInSz = 0;
|
||||||
#endif
|
#endif
|
||||||
|
return WOLFSSL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return WOLFSSL_SUCCESS;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Permanent stub for Qt compilation. */
|
/* Permanent stub for Qt compilation. */
|
||||||
|
@@ -696,6 +696,7 @@ enum AlertLevel {
|
|||||||
* Since wolfSSL 4.7.0, the following functions use this macro:
|
* Since wolfSSL 4.7.0, the following functions use this macro:
|
||||||
* - wolfSSL_CTX_load_verify_locations
|
* - wolfSSL_CTX_load_verify_locations
|
||||||
* - wolfSSL_X509_LOOKUP_load_file
|
* - wolfSSL_X509_LOOKUP_load_file
|
||||||
|
* - wolfSSL_EVP_PKEY_cmp
|
||||||
*/
|
*/
|
||||||
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
#if defined(WOLFSSL_ERROR_CODE_OPENSSL)
|
||||||
#define WS_RETURN_CODE(item1,item2) \
|
#define WS_RETURN_CODE(item1,item2) \
|
||||||
|
Reference in New Issue
Block a user