Skip to content

Commit

Permalink
fix for SN (short name) of digests to match expected values
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jan 9, 2025
1 parent 908a163 commit 18d49eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
24 changes: 12 additions & 12 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -59072,21 +59072,21 @@ static int test_wolfSSL_EVP_Digest_all(void)
"SHA512",
#endif
#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_224)
"SHA512_224",
"SHA512-224",
#endif
#if defined(WOLFSSL_SHA512) && !defined(WOLFSSL_NOSHA512_256)
"SHA512_256",
"SHA512-256",
#endif
#ifdef WOLFSSL_SHA3
#ifndef WOLFSSL_NOSHA3_224
"SHA3_224",
"SHA3-224",
#endif
#ifndef WOLFSSL_NOSHA3_256
"SHA3_256",
"SHA3-256",
#endif
"SHA3_384",
"SHA3-384",
#ifndef WOLFSSL_NOSHA3_512
"SHA3_512",
"SHA3-512",
#endif
#endif /* WOLFSSL_SHA3 */
NULL
Expand Down Expand Up @@ -59116,29 +59116,29 @@ static int test_wolfSSL_EVP_MD_size(void)
#ifndef WOLFSSL_NOSHA3_224
wolfSSL_EVP_MD_CTX_init(&mdCtx);

ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_224"), 1);
ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3-224"), 1);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_224_DIGEST_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_224_BLOCK_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
#endif
#ifndef WOLFSSL_NOSHA3_256
wolfSSL_EVP_MD_CTX_init(&mdCtx);

ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_256"), 1);
ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3-256"), 1);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_256_DIGEST_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_256_BLOCK_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
#endif
wolfSSL_EVP_MD_CTX_init(&mdCtx);

ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_384"), 1);
ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3-384"), 1);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_384_DIGEST_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_384_BLOCK_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
#ifndef WOLFSSL_NOSHA3_512
wolfSSL_EVP_MD_CTX_init(&mdCtx);

ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3_512"), 1);
ExpectIntEQ(wolfSSL_EVP_DigestInit(&mdCtx, "SHA3-512"), 1);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_size(&mdCtx), WC_SHA3_512_DIGEST_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_block_size(&mdCtx), WC_SHA3_512_BLOCK_SIZE);
ExpectIntEQ(wolfSSL_EVP_MD_CTX_cleanup(&mdCtx), 1);
Expand Down Expand Up @@ -93447,12 +93447,12 @@ static int test_EVP_blake2(void)

#if defined(HAVE_BLAKE2)
ExpectNotNull(md = EVP_blake2b512());
ExpectIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
ExpectIntEQ(XSTRNCMP(md, "BLAKE2b512", XSTRLEN("BLAKE2b512")), 0);
#endif

#if defined(HAVE_BLAKE2S)
ExpectNotNull(md = EVP_blake2s256());
ExpectIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
ExpectIntEQ(XSTRNCMP(md, "BLAKE2s256", XSTRLEN("BLAKE2s256")), 0);
#endif
#endif

Expand Down
32 changes: 11 additions & 21 deletions wolfcrypt/src/evp.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static const struct s_ent {
{WC_HASH_TYPE_SM3, WC_NID_sm3, WC_SN_sm3},
#endif /* WOLFSSL_SHA512 */
#ifdef HAVE_BLAKE2
{WC_HASH_TYPE_BLAKE2B, WC_NID_blake2b512, WC_SN_blakeb512},
{WC_HASH_TYPE_BLAKE2B, WC_NID_blake2b512, WC_SN_blake2b512},
#endif
#ifdef HAVE_BLAKE2S
{WC_HASH_TYPE_BLAKE2S, WC_NID_blake2s256, WC_SN_blake2s256},
Expand Down Expand Up @@ -9950,40 +9950,30 @@ static const struct alias {
{WC_SN_sha3_384, "sha3_384"},
{WC_SN_sha3_512, "sha3_512"},
{WC_SN_sm3, "sm3"},
{"BLAKE2B512", "blake2b512"},
{"BLAKE2S256", "blake2s256"},
{"SHAKE128", "shake128"},
{"SHAKE256", "shake256"},
{WC_SN_blake2b512, "blake2b512"},
{WC_SN_blake2s256, "blake2s256"},
{WC_SN_shake128, "shake128"},
{WC_SN_shake256, "shake256"},
{ NULL, NULL}
};

const WOLFSSL_EVP_MD *wolfSSL_EVP_get_digestbyname(const char *name)
{
char nameUpper[15]; /* 15 bytes should be enough for any name */
size_t i;

const struct alias *al;
const struct s_ent *ent;

for (i = 0; i < sizeof(nameUpper) && name[i] != '\0'; i++) {
nameUpper[i] = (char)XTOUPPER((unsigned char) name[i]);
}
if (i < sizeof(nameUpper))
nameUpper[i] = '\0';
else
return NULL;

name = nameUpper;
for (al = digest_alias_tbl; al->name != NULL; al++)
for (al = digest_alias_tbl; al->name != NULL; al++) {
if(XSTRCMP(name, al->alias) == 0) {
name = al->name;
break;
}
}

for (ent = md_tbl; ent->name != NULL; ent++)
for (ent = md_tbl; ent->name != NULL; ent++) {
if(XSTRCMP(name, ent->name) == 0) {
return (WOLFSSL_EVP_MD *)ent->name;
}
}
return NULL;
}

Expand Down Expand Up @@ -10040,8 +10030,8 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD* type)
*/
const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2b512(void)
{
WOLFSSL_ENTER("EVP_blake2b512");
return wolfSSL_EVP_get_digestbyname("BLAKE2b512");
WOLFSSL_ENTER("wolfSSL_EVP_blake2b512");
return wolfSSL_EVP_get_digestbyname(WC_SN_blake2b512);
}

#endif
Expand Down

0 comments on commit 18d49eb

Please sign in to comment.