use EVP_get_digestbyname

This commit is contained in:
Hideki Miyazaki 2021-07-21 14:24:44 +09:00
parent b4c61b4df9
commit 6a3ff81f2d
No known key found for this signature in database
GPG Key ID: 7EB19ED9B9D5AC28
3 changed files with 50 additions and 21 deletions

View File

@ -45933,19 +45933,23 @@ static void test_wolfSSL_ERR_strings()
static void test_EVP_blake2()
{
#if defined(OPENSSL_EXTRA)
#if defined(OPENSSL_EXTRA) && (defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S))
printf(testingFmt, "test_EVP_blake2");
const EVP_MD* md = NULL;
(void)md;
#if defined(HAVE_BLAKE2)
md = EVP_blake2b512();
AssertTrue(md != NULL);
AssertIntEQ(XSTRNCMP(md, "BLAKE2b512", XSTRLEN("BLAKE2b512")), 0);
AssertIntEQ(XSTRNCMP(md, "BLAKE2B512", XSTRLEN("BLAKE2B512")), 0);
#endif
#if defined(HAVE_BLAKE2S)
md = EVP_blake2s256();
AssertTrue(md != NULL);
AssertIntEQ(XSTRNCMP(md, "BLAKE2s256", XSTRLEN("BLAKE2s256")), 0);
AssertIntEQ(XSTRNCMP(md, "BLAKE2S256", XSTRLEN("BLAKE2S256")), 0);
#endif
printf(resultFmt, passed);
#endif

View File

@ -2336,6 +2336,12 @@ static const struct s_ent {
#endif
#ifndef WOLFSSL_NOSHA3_512
{WC_HASH_TYPE_SHA3_512, NID_sha3_512, "SHA3_512"},
#endif
#ifdef HAVE_BLAKE2
{WC_HASH_TYPE_BLAKE2B, NID_blake2b512, "BLAKE2B512"},
#endif
#ifdef HAVE_BLAKE2S
{WC_HASH_TYPE_BLAKE2S, NID_blake2s256, "BLAKE2S256"},
#endif
{WC_HASH_TYPE_NONE, 0, NULL}
};
@ -3503,6 +3509,12 @@ const WOLFSSL_EVP_MD *wolfSSL_EVP_get_digestbyname(const char *name)
{"MD5", "ssl3-md5"},
{"SHA1", "ssl3-sha1"},
{"SHA1", "SHA"},
#ifdef HAVE_BLAKE2
{"BLAKE2b512", "blake2b512"},
#endif
#ifdef HAVE_BLAKE2S
{"BLAKE2s256", "blake2s256"},
#endif
{ NULL, NULL}
};
char nameUpper[15]; /* 15 bytes should be enough for any name */
@ -3567,6 +3579,32 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
#endif /* !NO_MD5 */
#ifdef HAVE_BLAKE2
/* return EVP_MD
* @param none
* @return "blake2b512"
*/
const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2b512()
{
WOLFSSL_ENTER("EVP_blake2b512");
return EVP_get_digestbyname("BLAKE2b512");
}
#endif
#ifdef HAVE_BLAKE2S
/* return EVP_MD
* @param none
* @return "blake2s256"
*/
const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2s256()
{
WOLFSSL_ENTER("EVP_blake2s256");
return EVP_get_digestbyname("BLAKE2s256");
}
#endif
#ifndef NO_WOLFSSL_STUB
void wolfSSL_EVP_set_pw_prompt(const char *prompt)
@ -7151,22 +7189,7 @@ int wolfSSL_EVP_PKEY_assign_DH(EVP_PKEY* pkey, WOLFSSL_DH* key)
}
#endif /* !NO_DH */
/* return EVP_MD
* @param none
* @return "BLAKE2b512"
*/
const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2b512()
{
return (const WOLFSSL_EVP_MD*)"BLAKE2b512";
}
/* return EVP_MD
* @param none
* @return "BLAKE2s256"
*/
const WOLFSSL_EVP_MD* wolfSSL_EVP_blake2s256()
{
return (const WOLFSSL_EVP_MD*)"BLAKE2s256";
}
#endif /* OPENSSL_EXTRA */

View File

@ -291,6 +291,8 @@ enum {
NID_sha3_256 = 1097,
NID_sha3_384 = 1098,
NID_sha3_512 = 1099,
NID_blake2b512 = 1056,
NID_blake2s256 = 1057,
};
enum {