forked from wolfSSL/wolfssl
Refactor of the EVP macType
to use enum wc_HashType
to resolve issues with invalid casting.
This commit is contained in:
@@ -34996,7 +34996,7 @@ int wolfSSL_RSA_padding_add_PKCS1_PSS(WOLFSSL_RSA *rsa, unsigned char *EM,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashType = (enum wc_HashType)wolfSSL_EVP_md2macType(hashAlg);
|
hashType = wolfSSL_EVP_md2macType(hashAlg);
|
||||||
if (hashType < WC_HASH_TYPE_NONE || hashType > WC_HASH_TYPE_MAX) {
|
if (hashType < WC_HASH_TYPE_NONE || hashType > WC_HASH_TYPE_MAX) {
|
||||||
WOLFSSL_MSG("wolfSSL_EVP_md2macType error");
|
WOLFSSL_MSG("wolfSSL_EVP_md2macType error");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -35103,7 +35103,7 @@ int wolfSSL_RSA_verify_PKCS1_PSS(WOLFSSL_RSA *rsa, const unsigned char *mHash,
|
|||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashType = (enum wc_HashType)wolfSSL_EVP_md2macType(hashAlg);
|
hashType = wolfSSL_EVP_md2macType(hashAlg);
|
||||||
if (hashType < WC_HASH_TYPE_NONE || hashType > WC_HASH_TYPE_MAX) {
|
if (hashType < WC_HASH_TYPE_NONE || hashType > WC_HASH_TYPE_MAX) {
|
||||||
WOLFSSL_MSG("wolfSSL_EVP_md2macType error");
|
WOLFSSL_MSG("wolfSSL_EVP_md2macType error");
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
@@ -31014,7 +31014,7 @@ static void test_wolfSSL_ASN1_INTEGER_set()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Testing code used in dpp.c in hostap */
|
/* Testing code used in dpp.c in hostap */
|
||||||
#ifdef OPENSSL_ALL
|
#if defined(OPENSSL_ALL) && defined(HAVE_ECC) && defined(USE_CERT_BUFFERS_256)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* AlgorithmIdentifier ecPublicKey with optional parameters present
|
/* AlgorithmIdentifier ecPublicKey with optional parameters present
|
||||||
* as an OID identifying the curve */
|
* as an OID identifying the curve */
|
||||||
@@ -31029,7 +31029,7 @@ ASN1_SEQUENCE(DPP_BOOTSTRAPPING_KEY) = {
|
|||||||
} ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY);
|
} ASN1_SEQUENCE_END(DPP_BOOTSTRAPPING_KEY);
|
||||||
|
|
||||||
IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY);
|
IMPLEMENT_ASN1_FUNCTIONS(DPP_BOOTSTRAPPING_KEY);
|
||||||
#endif /* WOLFSSL_WPAS */
|
#endif
|
||||||
|
|
||||||
static void test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS()
|
static void test_wolfSSL_IMPLEMENT_ASN1_FUNCTIONS()
|
||||||
{
|
{
|
||||||
|
@@ -1823,7 +1823,7 @@ int wolfSSL_EVP_SignUpdate(WOLFSSL_EVP_MD_CTX *ctx, const void *data, size_t len
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const struct s_ent {
|
static const struct s_ent {
|
||||||
const int macType;
|
const enum wc_HashType macType;
|
||||||
const int nid;
|
const int nid;
|
||||||
const char *name;
|
const char *name;
|
||||||
} md_tbl[] = {
|
} md_tbl[] = {
|
||||||
@@ -1862,10 +1862,10 @@ static const struct s_ent {
|
|||||||
#ifndef WOLFSSL_NOSHA3_512
|
#ifndef WOLFSSL_NOSHA3_512
|
||||||
{WC_HASH_TYPE_SHA3_512, NID_sha3_512, "SHA3_512"},
|
{WC_HASH_TYPE_SHA3_512, NID_sha3_512, "SHA3_512"},
|
||||||
#endif
|
#endif
|
||||||
{0, 0, NULL}
|
{WC_HASH_TYPE_NONE, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int wolfSSL_EVP_md2macType(const WOLFSSL_EVP_MD *md)
|
static enum wc_HashType wolfSSL_EVP_md2macType(const WOLFSSL_EVP_MD *md)
|
||||||
{
|
{
|
||||||
const struct s_ent *ent ;
|
const struct s_ent *ent ;
|
||||||
|
|
||||||
@@ -2101,7 +2101,7 @@ static int wolfSSL_evp_digest_pk_init(WOLFSSL_EVP_MD_CTX *ctx,
|
|||||||
if (wc_HmacSetKey(&ctx->hash.hmac, hashType, key, (word32)keySz) != 0)
|
if (wc_HmacSetKey(&ctx->hash.hmac, hashType, key, (word32)keySz) != 0)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
ctx->macType = NID_hmac;
|
ctx->isHMAC = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int ret;
|
int ret;
|
||||||
@@ -2128,7 +2128,7 @@ static int wolfssl_evp_digest_pk_update(WOLFSSL_EVP_MD_CTX *ctx,
|
|||||||
const void *d, unsigned int cnt)
|
const void *d, unsigned int cnt)
|
||||||
{
|
{
|
||||||
if (ctx->pctx == NULL) {
|
if (ctx->pctx == NULL) {
|
||||||
if (ctx->macType != NID_hmac)
|
if (!ctx->isHMAC)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
if (wc_HmacUpdate(&ctx->hash.hmac, (const byte *)d, cnt) != 0)
|
if (wc_HmacUpdate(&ctx->hash.hmac, (const byte *)d, cnt) != 0)
|
||||||
@@ -2152,7 +2152,7 @@ static int wolfssl_evp_digest_pk_final(WOLFSSL_EVP_MD_CTX *ctx,
|
|||||||
if (ctx->pctx == NULL) {
|
if (ctx->pctx == NULL) {
|
||||||
Hmac hmacCopy;
|
Hmac hmacCopy;
|
||||||
|
|
||||||
if (ctx->macType != NID_hmac)
|
if (!ctx->isHMAC)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
if (wolfSSL_HmacCopy(&hmacCopy, &ctx->hash.hmac) != WOLFSSL_SUCCESS)
|
if (wolfSSL_HmacCopy(&hmacCopy, &ctx->hash.hmac) != WOLFSSL_SUCCESS)
|
||||||
@@ -2267,7 +2267,7 @@ int wolfSSL_EVP_DigestSignFinal(WOLFSSL_EVP_MD_CTX *ctx, unsigned char *sig,
|
|||||||
|
|
||||||
/* Return the maximum size of the signaure when sig is NULL. */
|
/* Return the maximum size of the signaure when sig is NULL. */
|
||||||
if (ctx->pctx == NULL) {
|
if (ctx->pctx == NULL) {
|
||||||
if (ctx->macType != NID_hmac)
|
if (!ctx->isHMAC)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
hashLen = wolfssl_mac_len(ctx->hash.hmac.macType);
|
hashLen = wolfssl_mac_len(ctx->hash.hmac.macType);
|
||||||
@@ -2385,7 +2385,7 @@ int wolfSSL_EVP_DigestVerifyFinal(WOLFSSL_EVP_MD_CTX *ctx,
|
|||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
if (ctx->pctx == NULL) {
|
if (ctx->pctx == NULL) {
|
||||||
if (ctx->macType != NID_hmac)
|
if (!ctx->isHMAC)
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
|
|
||||||
hashLen = wolfssl_mac_len(ctx->hash.hmac.macType);
|
hashLen = wolfssl_mac_len(ctx->hash.hmac.macType);
|
||||||
@@ -3338,83 +3338,85 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
static int wolfSSL_EVP_MD_Copy_Hasher(WOLFSSL_EVP_MD_CTX* des,
|
static int wolfSSL_EVP_MD_Copy_Hasher(WOLFSSL_EVP_MD_CTX* des,
|
||||||
const WOLFSSL_EVP_MD_CTX* src)
|
const WOLFSSL_EVP_MD_CTX* src)
|
||||||
{
|
{
|
||||||
if (src->macType == NID_hmac) {
|
int ret;
|
||||||
wolfSSL_HmacCopy(&des->hash.hmac, (Hmac*)&src->hash.hmac);
|
if (src->isHMAC) {
|
||||||
|
ret = wolfSSL_HmacCopy(&des->hash.hmac, (Hmac*)&src->hash.hmac);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ret = NOT_COMPILED_IN;
|
||||||
switch (src->macType) {
|
switch (src->macType) {
|
||||||
#ifndef NO_MD5
|
|
||||||
case WC_HASH_TYPE_MD5:
|
case WC_HASH_TYPE_MD5:
|
||||||
wc_Md5Copy((wc_Md5*)&src->hash.digest,
|
#ifndef NO_MD5
|
||||||
|
ret = wc_Md5Copy((wc_Md5*)&src->hash.digest,
|
||||||
(wc_Md5*)&des->hash.digest);
|
(wc_Md5*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* !NO_MD5 */
|
#endif /* !NO_MD5 */
|
||||||
|
break;
|
||||||
#ifndef NO_SHA
|
|
||||||
case WC_HASH_TYPE_SHA:
|
case WC_HASH_TYPE_SHA:
|
||||||
wc_ShaCopy((wc_Sha*)&src->hash.digest,
|
#ifndef NO_SHA
|
||||||
|
ret = wc_ShaCopy((wc_Sha*)&src->hash.digest,
|
||||||
(wc_Sha*)&des->hash.digest);
|
(wc_Sha*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* !NO_SHA */
|
#endif /* !NO_SHA */
|
||||||
|
break;
|
||||||
#ifdef WOLFSSL_SHA224
|
|
||||||
case WC_HASH_TYPE_SHA224:
|
case WC_HASH_TYPE_SHA224:
|
||||||
wc_Sha224Copy((wc_Sha224*)&src->hash.digest,
|
#ifdef WOLFSSL_SHA224
|
||||||
|
ret = wc_Sha224Copy((wc_Sha224*)&src->hash.digest,
|
||||||
(wc_Sha224*)&des->hash.digest);
|
(wc_Sha224*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* WOLFSSL_SHA224 */
|
#endif /* WOLFSSL_SHA224 */
|
||||||
|
break;
|
||||||
#ifndef NO_SHA256
|
|
||||||
case WC_HASH_TYPE_SHA256:
|
case WC_HASH_TYPE_SHA256:
|
||||||
wc_Sha256Copy((wc_Sha256*)&src->hash.digest,
|
#ifndef NO_SHA256
|
||||||
|
ret = wc_Sha256Copy((wc_Sha256*)&src->hash.digest,
|
||||||
(wc_Sha256*)&des->hash.digest);
|
(wc_Sha256*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* !NO_SHA256 */
|
#endif /* !NO_SHA256 */
|
||||||
|
break;
|
||||||
#ifdef WOLFSSL_SHA384
|
|
||||||
case WC_HASH_TYPE_SHA384:
|
case WC_HASH_TYPE_SHA384:
|
||||||
wc_Sha384Copy((wc_Sha384*)&src->hash.digest,
|
#ifdef WOLFSSL_SHA384
|
||||||
|
ret = wc_Sha384Copy((wc_Sha384*)&src->hash.digest,
|
||||||
(wc_Sha384*)&des->hash.digest);
|
(wc_Sha384*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* WOLFSSL_SHA384 */
|
#endif /* WOLFSSL_SHA384 */
|
||||||
#ifdef WOLFSSL_SHA512
|
break;
|
||||||
case WC_HASH_TYPE_SHA512:
|
case WC_HASH_TYPE_SHA512:
|
||||||
wc_Sha512Copy((wc_Sha512*)&src->hash.digest,
|
#ifdef WOLFSSL_SHA512
|
||||||
|
ret = wc_Sha512Copy((wc_Sha512*)&src->hash.digest,
|
||||||
(wc_Sha512*)&des->hash.digest);
|
(wc_Sha512*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif /* WOLFSSL_SHA512 */
|
#endif /* WOLFSSL_SHA512 */
|
||||||
#ifdef WOLFSSL_SHA3
|
break;
|
||||||
#ifndef WOLFSSL_NOSHA3_224
|
|
||||||
case WC_HASH_TYPE_SHA3_224:
|
case WC_HASH_TYPE_SHA3_224:
|
||||||
wc_Sha3_224_Copy((wc_Sha3*)&src->hash.digest,
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
|
||||||
|
ret = wc_Sha3_224_Copy((wc_Sha3*)&src->hash.digest,
|
||||||
(wc_Sha3*)&des->hash.digest);
|
(wc_Sha3*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
#ifndef WOLFSSL_NOSHA3_256
|
|
||||||
case WC_HASH_TYPE_SHA3_256:
|
case WC_HASH_TYPE_SHA3_256:
|
||||||
wc_Sha3_256_Copy((wc_Sha3*)&src->hash.digest,
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
|
||||||
|
ret = wc_Sha3_256_Copy((wc_Sha3*)&src->hash.digest,
|
||||||
(wc_Sha3*)&des->hash.digest);
|
(wc_Sha3*)&des->hash.digest);
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
case WC_HASH_TYPE_SHA3_384:
|
case WC_HASH_TYPE_SHA3_384:
|
||||||
wc_Sha3_384_Copy((wc_Sha3*)&src->hash.digest,
|
#if defined(WOLFSSL_SHA3)
|
||||||
|
ret = wc_Sha3_384_Copy((wc_Sha3*)&src->hash.digest,
|
||||||
(wc_Sha3*)&des->hash.digest);
|
(wc_Sha3*)&des->hash.digest);
|
||||||
break;
|
|
||||||
|
|
||||||
#ifndef WOLFSSL_NOSHA3_512
|
|
||||||
case WC_HASH_TYPE_SHA3_512:
|
|
||||||
wc_Sha3_512_Copy((wc_Sha3*)&src->hash.digest,
|
|
||||||
(wc_Sha3*)&des->hash.digest);
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
break;
|
||||||
|
case WC_HASH_TYPE_SHA3_512:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
|
||||||
|
ret = wc_Sha3_512_Copy((wc_Sha3*)&src->hash.digest,
|
||||||
|
(wc_Sha3*)&des->hash.digest);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case WC_HASH_TYPE_NONE:
|
||||||
|
case WC_HASH_TYPE_MD2:
|
||||||
|
case WC_HASH_TYPE_MD4:
|
||||||
|
case WC_HASH_TYPE_MD5_SHA:
|
||||||
|
case WC_HASH_TYPE_BLAKE2B:
|
||||||
|
case WC_HASH_TYPE_BLAKE2S:
|
||||||
default:
|
default:
|
||||||
return WOLFSSL_FAILURE;
|
ret = BAD_FUNC_ARG;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return WOLFSSL_SUCCESS;
|
return ret == 0 ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copies structure in to the structure out
|
/* copies structure in to the structure out
|
||||||
@@ -3796,79 +3798,92 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
|
|
||||||
int wolfSSL_EVP_MD_CTX_cleanup(WOLFSSL_EVP_MD_CTX* ctx)
|
int wolfSSL_EVP_MD_CTX_cleanup(WOLFSSL_EVP_MD_CTX* ctx)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
WOLFSSL_ENTER("EVP_MD_CTX_cleanup");
|
WOLFSSL_ENTER("EVP_MD_CTX_cleanup");
|
||||||
if (ctx->pctx != NULL)
|
if (ctx->pctx != NULL)
|
||||||
wolfSSL_EVP_PKEY_CTX_free(ctx->pctx);
|
wolfSSL_EVP_PKEY_CTX_free(ctx->pctx);
|
||||||
|
|
||||||
if (ctx->macType == NID_hmac) {
|
if (ctx->isHMAC == NID_hmac) {
|
||||||
wc_HmacFree(&ctx->hash.hmac);
|
wc_HmacFree(&ctx->hash.hmac);
|
||||||
|
ret = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
ret = NOT_COMPILED_IN;
|
||||||
switch (ctx->macType) {
|
switch (ctx->macType) {
|
||||||
#ifndef NO_MD5
|
|
||||||
case WC_HASH_TYPE_MD5:
|
case WC_HASH_TYPE_MD5:
|
||||||
|
#ifndef NO_MD5
|
||||||
wc_Md5Free((wc_Md5*)&ctx->hash.digest);
|
wc_Md5Free((wc_Md5*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* !NO_MD5 */
|
#endif /* !NO_MD5 */
|
||||||
|
break;
|
||||||
#ifndef NO_SHA
|
|
||||||
case WC_HASH_TYPE_SHA:
|
case WC_HASH_TYPE_SHA:
|
||||||
|
#ifndef NO_SHA
|
||||||
wc_ShaFree((wc_Sha*)&ctx->hash.digest);
|
wc_ShaFree((wc_Sha*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* !NO_SHA */
|
#endif /* !NO_SHA */
|
||||||
|
break;
|
||||||
#ifdef WOLFSSL_SHA224
|
|
||||||
case WC_HASH_TYPE_SHA224:
|
case WC_HASH_TYPE_SHA224:
|
||||||
|
#ifdef WOLFSSL_SHA224
|
||||||
wc_Sha224Free((wc_Sha224*)&ctx->hash.digest);
|
wc_Sha224Free((wc_Sha224*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* WOLFSSL_SHA224 */
|
#endif /* WOLFSSL_SHA224 */
|
||||||
|
break;
|
||||||
#ifndef NO_SHA256
|
|
||||||
case WC_HASH_TYPE_SHA256:
|
case WC_HASH_TYPE_SHA256:
|
||||||
|
#ifndef NO_SHA256
|
||||||
wc_Sha256Free((wc_Sha256*)&ctx->hash.digest);
|
wc_Sha256Free((wc_Sha256*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* !NO_SHA256 */
|
#endif /* !NO_SHA256 */
|
||||||
|
break;
|
||||||
#ifdef WOLFSSL_SHA384
|
|
||||||
case WC_HASH_TYPE_SHA384:
|
case WC_HASH_TYPE_SHA384:
|
||||||
|
#ifdef WOLFSSL_SHA384
|
||||||
wc_Sha384Free((wc_Sha384*)&ctx->hash.digest);
|
wc_Sha384Free((wc_Sha384*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* WOLFSSL_SHA384 */
|
#endif /* WOLFSSL_SHA384 */
|
||||||
#ifdef WOLFSSL_SHA512
|
break;
|
||||||
case WC_HASH_TYPE_SHA512:
|
case WC_HASH_TYPE_SHA512:
|
||||||
|
#ifdef WOLFSSL_SHA512
|
||||||
wc_Sha512Free((wc_Sha512*)&ctx->hash.digest);
|
wc_Sha512Free((wc_Sha512*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif /* WOLFSSL_SHA512 */
|
#endif /* WOLFSSL_SHA512 */
|
||||||
#ifdef WOLFSSL_SHA3
|
break;
|
||||||
#ifndef WOLFSSL_NOSHA3_224
|
|
||||||
case WC_HASH_TYPE_SHA3_224:
|
case WC_HASH_TYPE_SHA3_224:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
|
||||||
wc_Sha3_224_Free((wc_Sha3*)&ctx->hash.digest);
|
wc_Sha3_224_Free((wc_Sha3*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
#ifndef WOLFSSL_NOSHA3_256
|
|
||||||
case WC_HASH_TYPE_SHA3_256:
|
case WC_HASH_TYPE_SHA3_256:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
|
||||||
wc_Sha3_256_Free((wc_Sha3*)&ctx->hash.digest);
|
wc_Sha3_256_Free((wc_Sha3*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
case WC_HASH_TYPE_SHA3_384:
|
case WC_HASH_TYPE_SHA3_384:
|
||||||
|
#if defined(WOLFSSL_SHA3)
|
||||||
wc_Sha3_384_Free((wc_Sha3*)&ctx->hash.digest);
|
wc_Sha3_384_Free((wc_Sha3*)&ctx->hash.digest);
|
||||||
break;
|
ret = 0;
|
||||||
|
|
||||||
#ifndef WOLFSSL_NOSHA3_512
|
|
||||||
case WC_HASH_TYPE_SHA3_512:
|
|
||||||
wc_Sha3_512_Free((wc_Sha3*)&ctx->hash.digest);
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
break;
|
||||||
|
case WC_HASH_TYPE_SHA3_512:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
|
||||||
|
wc_Sha3_512_Free((wc_Sha3*)&ctx->hash.digest);
|
||||||
|
ret = 0;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case WC_HASH_TYPE_NONE:
|
||||||
|
case WC_HASH_TYPE_MD2:
|
||||||
|
case WC_HASH_TYPE_MD4:
|
||||||
|
case WC_HASH_TYPE_MD5_SHA:
|
||||||
|
case WC_HASH_TYPE_BLAKE2B:
|
||||||
|
case WC_HASH_TYPE_BLAKE2S:
|
||||||
default:
|
default:
|
||||||
return WOLFSSL_FAILURE;
|
ret = BAD_FUNC_ARG;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ForceZero(ctx, sizeof(*ctx));
|
ForceZero(ctx, sizeof(*ctx));
|
||||||
ctx->macType = WC_HASH_TYPE_NONE;
|
ctx->macType = WC_HASH_TYPE_NONE;
|
||||||
return 1;
|
return ret == 0 ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wolfSSL_EVP_CIPHER_CTX_init(WOLFSSL_EVP_CIPHER_CTX* ctx)
|
void wolfSSL_EVP_CIPHER_CTX_init(WOLFSSL_EVP_CIPHER_CTX* ctx)
|
||||||
@@ -5325,165 +5340,179 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
|
|||||||
int wolfSSL_EVP_DigestUpdate(WOLFSSL_EVP_MD_CTX* ctx, const void* data,
|
int wolfSSL_EVP_DigestUpdate(WOLFSSL_EVP_MD_CTX* ctx, const void* data,
|
||||||
size_t sz)
|
size_t sz)
|
||||||
{
|
{
|
||||||
int macType;
|
int ret = WOLFSSL_FAILURE;
|
||||||
|
enum wc_HashType macType;
|
||||||
|
|
||||||
WOLFSSL_ENTER("EVP_DigestUpdate");
|
WOLFSSL_ENTER("EVP_DigestUpdate");
|
||||||
|
|
||||||
macType = wolfSSL_EVP_md2macType(EVP_MD_CTX_md(ctx));
|
macType = wolfSSL_EVP_md2macType(EVP_MD_CTX_md(ctx));
|
||||||
switch (macType) {
|
switch (macType) {
|
||||||
#ifndef NO_MD4
|
|
||||||
case WC_HASH_TYPE_MD4:
|
case WC_HASH_TYPE_MD4:
|
||||||
|
#ifndef NO_MD4
|
||||||
wolfSSL_MD4_Update((MD4_CTX*)&ctx->hash, data,
|
wolfSSL_MD4_Update((MD4_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
ret = WOLFSSL_SUCCESS;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_MD5
|
|
||||||
case WC_HASH_TYPE_MD5:
|
case WC_HASH_TYPE_MD5:
|
||||||
wolfSSL_MD5_Update((MD5_CTX*)&ctx->hash, data,
|
#ifndef NO_MD5
|
||||||
|
ret = wolfSSL_MD5_Update((MD5_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_SHA
|
|
||||||
case WC_HASH_TYPE_SHA:
|
case WC_HASH_TYPE_SHA:
|
||||||
wolfSSL_SHA_Update((SHA_CTX*)&ctx->hash, data,
|
#ifndef NO_SHA
|
||||||
|
ret = wolfSSL_SHA_Update((SHA_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifdef WOLFSSL_SHA224
|
|
||||||
case WC_HASH_TYPE_SHA224:
|
case WC_HASH_TYPE_SHA224:
|
||||||
wolfSSL_SHA224_Update((SHA224_CTX*)&ctx->hash, data,
|
#ifdef WOLFSSL_SHA224
|
||||||
|
ret = wolfSSL_SHA224_Update((SHA224_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_SHA256
|
|
||||||
case WC_HASH_TYPE_SHA256:
|
case WC_HASH_TYPE_SHA256:
|
||||||
wolfSSL_SHA256_Update((SHA256_CTX*)&ctx->hash, data,
|
#ifndef NO_SHA256
|
||||||
|
ret = wolfSSL_SHA256_Update((SHA256_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif /* !NO_SHA256 */
|
||||||
break;
|
break;
|
||||||
#endif /* !NO_SHA256 */
|
|
||||||
#ifdef WOLFSSL_SHA384
|
|
||||||
case WC_HASH_TYPE_SHA384:
|
case WC_HASH_TYPE_SHA384:
|
||||||
wolfSSL_SHA384_Update((SHA384_CTX*)&ctx->hash, data,
|
#ifdef WOLFSSL_SHA384
|
||||||
|
ret = wolfSSL_SHA384_Update((SHA384_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifdef WOLFSSL_SHA512
|
|
||||||
case WC_HASH_TYPE_SHA512:
|
case WC_HASH_TYPE_SHA512:
|
||||||
wolfSSL_SHA512_Update((SHA512_CTX*)&ctx->hash, data,
|
#ifdef WOLFSSL_SHA512
|
||||||
|
ret = wolfSSL_SHA512_Update((SHA512_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
|
#endif /* WOLFSSL_SHA512 */
|
||||||
break;
|
break;
|
||||||
#endif /* WOLFSSL_SHA512 */
|
|
||||||
#ifdef WOLFSSL_SHA3
|
|
||||||
#ifndef WOLFSSL_NOSHA3_224
|
|
||||||
case WC_HASH_TYPE_SHA3_224:
|
case WC_HASH_TYPE_SHA3_224:
|
||||||
wolfSSL_SHA3_224_Update((SHA3_224_CTX*)&ctx->hash, data,
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
|
||||||
|
ret = wolfSSL_SHA3_224_Update((SHA3_224_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WOLFSSL_NOSHA3_256
|
break;
|
||||||
case WC_HASH_TYPE_SHA3_256:
|
case WC_HASH_TYPE_SHA3_256:
|
||||||
wolfSSL_SHA3_256_Update((SHA3_256_CTX*)&ctx->hash, data,
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
|
||||||
|
ret = wolfSSL_SHA3_256_Update((SHA3_256_CTX*)&ctx->hash, data,
|
||||||
|
(unsigned long)sz);
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case WC_HASH_TYPE_SHA3_384:
|
||||||
|
#if defined(WOLFSSL_SHA3)
|
||||||
|
ret = wolfSSL_SHA3_384_Update((SHA3_384_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
case WC_HASH_TYPE_SHA3_384:
|
|
||||||
wolfSSL_SHA3_384_Update((SHA3_384_CTX*)&ctx->hash, data,
|
|
||||||
(unsigned long)sz);
|
|
||||||
break;
|
break;
|
||||||
#ifndef WOLFSSL_NOSHA3_512
|
|
||||||
case WC_HASH_TYPE_SHA3_512:
|
case WC_HASH_TYPE_SHA3_512:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
|
||||||
wolfSSL_SHA3_512_Update((SHA3_512_CTX*)&ctx->hash, data,
|
wolfSSL_SHA3_512_Update((SHA3_512_CTX*)&ctx->hash, data,
|
||||||
(unsigned long)sz);
|
(unsigned long)sz);
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
break;
|
||||||
|
case WC_HASH_TYPE_NONE:
|
||||||
|
case WC_HASH_TYPE_MD2:
|
||||||
|
case WC_HASH_TYPE_MD5_SHA:
|
||||||
|
case WC_HASH_TYPE_BLAKE2B:
|
||||||
|
case WC_HASH_TYPE_BLAKE2S:
|
||||||
default:
|
default:
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return WOLFSSL_SUCCESS;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WOLFSSL_SUCCESS on ok */
|
/* WOLFSSL_SUCCESS on ok */
|
||||||
int wolfSSL_EVP_DigestFinal(WOLFSSL_EVP_MD_CTX* ctx, unsigned char* md,
|
int wolfSSL_EVP_DigestFinal(WOLFSSL_EVP_MD_CTX* ctx, unsigned char* md,
|
||||||
unsigned int* s)
|
unsigned int* s)
|
||||||
{
|
{
|
||||||
int macType;
|
int ret = WOLFSSL_FAILURE;
|
||||||
|
enum wc_HashType macType;
|
||||||
|
|
||||||
WOLFSSL_ENTER("EVP_DigestFinal");
|
WOLFSSL_ENTER("EVP_DigestFinal");
|
||||||
macType = wolfSSL_EVP_md2macType(EVP_MD_CTX_md(ctx));
|
macType = wolfSSL_EVP_md2macType(EVP_MD_CTX_md(ctx));
|
||||||
switch (macType) {
|
switch (macType) {
|
||||||
#ifndef NO_MD4
|
|
||||||
case WC_HASH_TYPE_MD4:
|
case WC_HASH_TYPE_MD4:
|
||||||
|
#ifndef NO_MD4
|
||||||
wolfSSL_MD4_Final(md, (MD4_CTX*)&ctx->hash);
|
wolfSSL_MD4_Final(md, (MD4_CTX*)&ctx->hash);
|
||||||
if (s) *s = MD4_DIGEST_SIZE;
|
if (s) *s = MD4_DIGEST_SIZE;
|
||||||
|
ret = WOLFSSL_SUCCESS;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_MD5
|
|
||||||
case WC_HASH_TYPE_MD5:
|
case WC_HASH_TYPE_MD5:
|
||||||
wolfSSL_MD5_Final(md, (MD5_CTX*)&ctx->hash);
|
#ifndef NO_MD5
|
||||||
|
ret = wolfSSL_MD5_Final(md, (MD5_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_MD5_DIGEST_SIZE;
|
if (s) *s = WC_MD5_DIGEST_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_SHA
|
|
||||||
case WC_HASH_TYPE_SHA:
|
case WC_HASH_TYPE_SHA:
|
||||||
wolfSSL_SHA_Final(md, (SHA_CTX*)&ctx->hash);
|
#ifndef NO_SHA
|
||||||
|
ret = wolfSSL_SHA_Final(md, (SHA_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA_DIGEST_SIZE;
|
if (s) *s = WC_SHA_DIGEST_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifdef WOLFSSL_SHA224
|
|
||||||
case WC_HASH_TYPE_SHA224:
|
case WC_HASH_TYPE_SHA224:
|
||||||
wolfSSL_SHA224_Final(md, (SHA224_CTX*)&ctx->hash);
|
#ifdef WOLFSSL_SHA224
|
||||||
|
ret = wolfSSL_SHA224_Final(md, (SHA224_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA224_DIGEST_SIZE;
|
if (s) *s = WC_SHA224_DIGEST_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifndef NO_SHA256
|
|
||||||
case WC_HASH_TYPE_SHA256:
|
case WC_HASH_TYPE_SHA256:
|
||||||
wolfSSL_SHA256_Final(md, (SHA256_CTX*)&ctx->hash);
|
#ifndef NO_SHA256
|
||||||
|
ret = wolfSSL_SHA256_Final(md, (SHA256_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA256_DIGEST_SIZE;
|
if (s) *s = WC_SHA256_DIGEST_SIZE;
|
||||||
|
#endif /* !NO_SHA256 */
|
||||||
break;
|
break;
|
||||||
#endif /* !NO_SHA256 */
|
|
||||||
#ifdef WOLFSSL_SHA384
|
|
||||||
case WC_HASH_TYPE_SHA384:
|
case WC_HASH_TYPE_SHA384:
|
||||||
wolfSSL_SHA384_Final(md, (SHA384_CTX*)&ctx->hash);
|
#ifdef WOLFSSL_SHA384
|
||||||
|
ret = wolfSSL_SHA384_Final(md, (SHA384_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA384_DIGEST_SIZE;
|
if (s) *s = WC_SHA384_DIGEST_SIZE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#ifdef WOLFSSL_SHA512
|
|
||||||
case WC_HASH_TYPE_SHA512:
|
case WC_HASH_TYPE_SHA512:
|
||||||
wolfSSL_SHA512_Final(md, (SHA512_CTX*)&ctx->hash);
|
#ifdef WOLFSSL_SHA512
|
||||||
|
ret = wolfSSL_SHA512_Final(md, (SHA512_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA512_DIGEST_SIZE;
|
if (s) *s = WC_SHA512_DIGEST_SIZE;
|
||||||
|
#endif /* WOLFSSL_SHA512 */
|
||||||
break;
|
break;
|
||||||
#endif /* WOLFSSL_SHA512 */
|
|
||||||
#ifdef WOLFSSL_SHA3
|
|
||||||
#ifndef WOLFSSL_NOSHA3_224
|
|
||||||
case WC_HASH_TYPE_SHA3_224:
|
case WC_HASH_TYPE_SHA3_224:
|
||||||
wolfSSL_SHA3_224_Final(md, (SHA3_224_CTX*)&ctx->hash);
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_224)
|
||||||
|
ret = wolfSSL_SHA3_224_Final(md, (SHA3_224_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA3_224_DIGEST_SIZE;
|
if (s) *s = WC_SHA3_224_DIGEST_SIZE;
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#ifndef WOLFSSL_NOSHA3_256
|
break;
|
||||||
case WC_HASH_TYPE_SHA3_256:
|
case WC_HASH_TYPE_SHA3_256:
|
||||||
wolfSSL_SHA3_256_Final(md, (SHA3_256_CTX*)&ctx->hash);
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_256)
|
||||||
|
ret = wolfSSL_SHA3_256_Final(md, (SHA3_256_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA3_256_DIGEST_SIZE;
|
if (s) *s = WC_SHA3_256_DIGEST_SIZE;
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
|
break;
|
||||||
case WC_HASH_TYPE_SHA3_384:
|
case WC_HASH_TYPE_SHA3_384:
|
||||||
wolfSSL_SHA3_384_Final(md, (SHA3_384_CTX*)&ctx->hash);
|
#if defined(WOLFSSL_SHA3)
|
||||||
|
ret = wolfSSL_SHA3_384_Final(md, (SHA3_384_CTX*)&ctx->hash);
|
||||||
if (s) *s = WC_SHA3_384_DIGEST_SIZE;
|
if (s) *s = WC_SHA3_384_DIGEST_SIZE;
|
||||||
break;
|
|
||||||
#ifndef WOLFSSL_NOSHA3_512
|
|
||||||
case WC_HASH_TYPE_SHA3_512:
|
|
||||||
wolfSSL_SHA3_512_Final(md, (SHA3_512_CTX*)&ctx->hash);
|
|
||||||
if (s) *s = WC_SHA3_512_DIGEST_SIZE;
|
|
||||||
break;
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
break;
|
||||||
|
case WC_HASH_TYPE_SHA3_512:
|
||||||
|
#if defined(WOLFSSL_SHA3) && !defined(WOLFSSL_NOSHA3_512)
|
||||||
|
ret = wolfSSL_SHA3_512_Final(md, (SHA3_512_CTX*)&ctx->hash);
|
||||||
|
if (s) *s = WC_SHA3_512_DIGEST_SIZE;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case WC_HASH_TYPE_NONE:
|
||||||
|
case WC_HASH_TYPE_MD2:
|
||||||
|
case WC_HASH_TYPE_MD5_SHA:
|
||||||
|
case WC_HASH_TYPE_BLAKE2B:
|
||||||
|
case WC_HASH_TYPE_BLAKE2S:
|
||||||
default:
|
default:
|
||||||
return WOLFSSL_FAILURE;
|
return WOLFSSL_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return WOLFSSL_SUCCESS;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* WOLFSSL_SUCCESS on ok */
|
/* WOLFSSL_SUCCESS on ok */
|
||||||
|
@@ -185,8 +185,11 @@ struct WOLFSSL_EVP_MD_CTX {
|
|||||||
Hmac hmac;
|
Hmac hmac;
|
||||||
#endif
|
#endif
|
||||||
} hash;
|
} hash;
|
||||||
int macType;
|
enum wc_HashType macType;
|
||||||
WOLFSSL_EVP_PKEY_CTX *pctx;
|
WOLFSSL_EVP_PKEY_CTX *pctx;
|
||||||
|
#ifndef NO_HMAC
|
||||||
|
unsigned int isHMAC;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user