Adding EVP support for SHA3

This commit is contained in:
Eric Blankenhorn
2020-02-19 14:10:28 -06:00
parent 6eda4e7b46
commit a64e1540ba
4 changed files with 634 additions and 0 deletions

383
src/ssl.c
View File

@@ -16249,6 +16249,212 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
int wolfSSL_SHA3_224_Init(WOLFSSL_SHA3_224_CTX* sha)
{
int ret;
typedef char sha_test[sizeof(SHA3_224_CTX) >= sizeof(wc_Sha3) ? 1 : -1];
(void)sizeof(sha_test);
WOLFSSL_ENTER("SHA3_224_Init");
ret = wc_InitSha3_224((wc_Sha3*)sha, NULL, 0);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_224_Update(WOLFSSL_SHA3_224_CTX* sha, const void* input,
unsigned long sz)
{
int ret;
WOLFSSL_ENTER("SHA3_224_Update");
ret = wc_Sha3_224_Update((wc_Sha3*)sha, (const byte*)input, (word32)sz);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_224_Final(byte* input, WOLFSSL_SHA3_224_CTX* sha)
{
int ret;
WOLFSSL_ENTER("SHA3_224_Final");
ret = wc_Sha3_224_Final((wc_Sha3*)sha, input);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
#endif /* WOLFSSL_NOSHA3_224 */
#ifndef WOLFSSL_NOSHA3_256
int wolfSSL_SHA3_256_Init(WOLFSSL_SHA3_256_CTX* sha3_256)
{
int ret;
typedef char sha_test[sizeof(SHA3_256_CTX) >= sizeof(wc_Sha3) ? 1 : -1];
(void)sizeof(sha_test);
WOLFSSL_ENTER("SHA3_256_Init");
ret = wc_InitSha3_256((wc_Sha3*)sha3_256, NULL, 0);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_256_Update(WOLFSSL_SHA3_256_CTX* sha, const void* input,
unsigned long sz)
{
int ret;
WOLFSSL_ENTER("SHA3_256_Update");
ret = wc_Sha3_256_Update((wc_Sha3*)sha, (const byte*)input, (word32)sz);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_256_Final(byte* input, WOLFSSL_SHA3_256_CTX* sha)
{
int ret;
WOLFSSL_ENTER("SHA3_256_Final");
ret = wc_Sha3_256_Final((wc_Sha3*)sha, input);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
#endif /* WOLFSSL_NOSHA3_256 */
int wolfSSL_SHA3_384_Init(WOLFSSL_SHA3_384_CTX* sha)
{
int ret;
typedef char sha_test[sizeof(SHA3_384_CTX) >= sizeof(wc_Sha3) ? 1 : -1];
(void)sizeof(sha_test);
WOLFSSL_ENTER("SHA3_384_Init");
ret = wc_InitSha3_384((wc_Sha3*)sha, NULL, 0);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_384_Update(WOLFSSL_SHA3_384_CTX* sha, const void* input,
unsigned long sz)
{
int ret;
WOLFSSL_ENTER("SHA3_384_Update");
ret = wc_Sha3_384_Update((wc_Sha3*)sha, (const byte*)input, (word32)sz);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_384_Final(byte* input, WOLFSSL_SHA3_384_CTX* sha)
{
int ret;
WOLFSSL_ENTER("SHA3_384_Final");
ret = wc_Sha3_384_Final((wc_Sha3*)sha, input);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
#ifndef WOLFSSL_NOSHA3_512
int wolfSSL_SHA3_512_Init(WOLFSSL_SHA3_512_CTX* sha)
{
int ret;
typedef char sha_test[sizeof(SHA3_512_CTX) >= sizeof(wc_Sha3) ? 1 : -1];
(void)sizeof(sha_test);
WOLFSSL_ENTER("SHA3_512_Init");
ret = wc_InitSha3_512((wc_Sha3*)sha, NULL, 0);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_512_Update(WOLFSSL_SHA3_512_CTX* sha, const void* input,
unsigned long sz)
{
int ret;
WOLFSSL_ENTER("SHA3_512_Update");
ret = wc_Sha3_512_Update((wc_Sha3*)sha, (const byte*)input, (word32)sz);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
int wolfSSL_SHA3_512_Final(byte* input, WOLFSSL_SHA3_512_CTX* sha)
{
int ret;
WOLFSSL_ENTER("SHA3_512_Final");
ret = wc_Sha3_512_Final((wc_Sha3*)sha, input);
/* return 1 on success, 0 otherwise */
if (ret == 0)
return 1;
return 0;
}
#endif /* WOLFSSL_NOSHA3_512 */
static const struct s_ent {
const unsigned char macType;
const char *name;
@@ -16278,6 +16484,16 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
#ifdef WOLFSSL_SHA512
{WC_HASH_TYPE_SHA512, "SHA512"},
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
{WC_HASH_TYPE_SHA3_224, "SHA3_224"},
#endif
#ifndef WOLFSSL_NOSHA3_256
{WC_HASH_TYPE_SHA3_256, "SHA3_256"},
#endif
{WC_HASH_TYPE_SHA3_384, "SHA3_384"},
#ifndef WOLFSSL_NOSHA3_512
{WC_HASH_TYPE_SHA3_512, "SHA3_512"},
#endif
{0, NULL}
};
@@ -16413,6 +16629,37 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_224(void)
{
WOLFSSL_ENTER("EVP_sha3_224");
return EVP_get_digestbyname("SHA3_224");
}
#endif /* WOLFSSL_NOSHA3_224 */
#ifndef WOLFSSL_NOSHA3_256
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_256(void)
{
WOLFSSL_ENTER("EVP_sha3_256");
return EVP_get_digestbyname("SHA3_256");
}
#endif /* WOLFSSL_NOSHA3_256 */
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_384(void)
{
WOLFSSL_ENTER("EVP_sha3_384");
return EVP_get_digestbyname("SHA3_384");
}
#ifndef WOLFSSL_NOSHA3_512
const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_512(void)
{
WOLFSSL_ENTER("EVP_sha3_512");
return EVP_get_digestbyname("SHA3_512");
}
#endif /* WOLFSSL_NOSHA3_512 */
WOLFSSL_EVP_MD_CTX *wolfSSL_EVP_MD_CTX_new(void)
{
@@ -16509,6 +16756,32 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
break;
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
case WC_HASH_TYPE_SHA3_224:
wc_Sha3_224_Copy((wc_Sha3*)&src->hash.digest,
(wc_Sha3*)&des->hash.digest);
break;
#endif
#ifndef WOLFSSL_NOSHA3_256
case WC_HASH_TYPE_SHA3_256:
wc_Sha3_256_Copy((wc_Sha3*)&src->hash.digest,
(wc_Sha3*)&des->hash.digest);
break;
#endif
case WC_HASH_TYPE_SHA3_384:
wc_Sha3_384_Copy((wc_Sha3*)&src->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
default:
return WOLFSSL_FAILURE;
}
@@ -16934,6 +17207,28 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
break;
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
case WC_HASH_TYPE_SHA3_224:
wc_Sha3_224_Free((wc_Sha3*)&ctx->hash.digest);
break;
#endif
#ifndef WOLFSSL_NOSHA3_256
case WC_HASH_TYPE_SHA3_256:
wc_Sha3_256_Free((wc_Sha3*)&ctx->hash.digest);
break;
#endif
case WC_HASH_TYPE_SHA3_384:
wc_Sha3_384_Free((wc_Sha3*)&ctx->hash.digest);
break;
#ifndef WOLFSSL_NOSHA3_512
case WC_HASH_TYPE_SHA3_512:
wc_Sha3_512_Free((wc_Sha3*)&ctx->hash.digest);
break;
#endif
default:
return WOLFSSL_FAILURE;
}
@@ -18491,6 +18786,28 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
ret = wolfSSL_MD5_Init(&(ctx->hash.digest.md5));
}
#endif
#ifndef WOLFSSL_NOSHA3_224
else if (XSTRNCMP(type, "SHA3_224", 8) == 0) {
ctx->macType = WC_HASH_TYPE_SHA3_224;
ret = wolfSSL_SHA3_224_Init(&(ctx->hash.digest.sha3_224));
}
#endif
#ifndef WOLFSSL_NOSHA3_256
else if (XSTRNCMP(type, "SHA3_256", 8) == 0) {
ctx->macType = WC_HASH_TYPE_SHA3_256;
ret = wolfSSL_SHA3_256_Init(&(ctx->hash.digest.sha3_256));
}
#endif
else if (XSTRNCMP(type, "SHA3_384", 8) == 0) {
ctx->macType = WC_HASH_TYPE_SHA3_384;
ret = wolfSSL_SHA3_384_Init(&(ctx->hash.digest.sha3_384));
}
#ifndef WOLFSSL_NOSHA3_512
else if (XSTRNCMP(type, "SHA3_512", 8) == 0) {
ctx->macType = WC_HASH_TYPE_SHA3_512;
ret = wolfSSL_SHA3_512_Init(&(ctx->hash.digest.sha3_512));
}
#endif
#ifndef NO_SHA
/* has to be last since would pick or 224, 256, 384, or 512 too */
else if (XSTRNCMP(type, "SHA", 3) == 0) {
@@ -18556,6 +18873,28 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
(unsigned long)sz);
break;
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
case WC_HASH_TYPE_SHA3_224:
wolfSSL_SHA3_224_Update((SHA3_224_CTX*)&ctx->hash, data,
(unsigned long)sz);
break;
#endif
#ifndef WOLFSSL_NOSHA3_256
case WC_HASH_TYPE_SHA3_256:
wolfSSL_SHA3_256_Update((SHA3_256_CTX*)&ctx->hash, data,
(unsigned long)sz);
break;
#endif
case WC_HASH_TYPE_SHA3_384:
wolfSSL_SHA3_384_Update((SHA3_384_CTX*)&ctx->hash, data,
(unsigned long)sz);
break;
#ifndef WOLFSSL_NOSHA3_512
case WC_HASH_TYPE_SHA3_512:
wolfSSL_SHA3_512_Update((SHA3_512_CTX*)&ctx->hash, data,
(unsigned long)sz);
break;
#endif
default:
return WOLFSSL_FAILURE;
}
@@ -18612,6 +18951,28 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
if (s) *s = WC_SHA512_DIGEST_SIZE;
break;
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
case WC_HASH_TYPE_SHA3_224:
wolfSSL_SHA3_224_Final(md, (SHA3_224_CTX*)&ctx->hash);
if (s) *s = WC_SHA3_224_DIGEST_SIZE;
break;
#endif
#ifndef WOLFSSL_NOSHA3_256
case WC_HASH_TYPE_SHA3_256:
wolfSSL_SHA3_256_Final(md, (SHA3_256_CTX*)&ctx->hash);
if (s) *s = WC_SHA3_256_DIGEST_SIZE;
break;
#endif
case WC_HASH_TYPE_SHA3_384:
wolfSSL_SHA3_384_Final(md, (SHA3_384_CTX*)&ctx->hash);
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
default:
return WOLFSSL_FAILURE;
}
@@ -18679,6 +19040,28 @@ int wolfSSL_EVP_MD_type(const WOLFSSL_EVP_MD *md)
mdlen = WC_SHA512_DIGEST_SIZE;
} else
#endif
#ifndef WOLFSSL_NOSHA3_224
if (XSTRNCMP(evp_md, "SHA3_224", 8) == 0) {
type = WC_SHA3_224;
mdlen = WC_SHA3_224_DIGEST_SIZE;
} else
#endif
#ifndef WOLFSSL_NOSHA3_256
if (XSTRNCMP(evp_md, "SHA3_256", 8) == 0) {
type = WC_SHA3_256;
mdlen = WC_SHA3_256_DIGEST_SIZE;
} else
#endif
if (XSTRNCMP(evp_md, "SHA3_384", 8) == 0) {
type = WC_SHA3_384;
mdlen = WC_SHA3_384_DIGEST_SIZE;
} else
#ifndef WOLFSSL_NOSHA3_512
if (XSTRNCMP(evp_md, "SHA3_512", 8) == 0) {
type = WC_SHA3_512;
mdlen = WC_SHA3_512_DIGEST_SIZE;
} else
#endif
#ifndef NO_SHA
if (XSTRNCMP(evp_md, "SHA", 3) == 0) {
type = WC_SHA;

View File

@@ -15507,6 +15507,82 @@ int openssl_test(void)
#endif /* WOLFSSL_SHA512 */
#ifndef WOLFSSL_NOSHA3_224
e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
e.output = "\x54\x3e\x68\x68\xe1\x66\x6c\x1a\x64\x36\x30\xdf\x77\x36\x7a\xe5\xa6\x2a\x85\x07\x0a\x51\xc1\x4c\xbf\x66\x5c\xbc";
e.inLen = XSTRLEN(e.input);
e.outLen = WC_SHA3_224_DIGEST_SIZE;
EVP_MD_CTX_init(&md_ctx);
EVP_DigestInit(&md_ctx, EVP_sha3_224());
EVP_DigestUpdate(&md_ctx, e.input, (unsigned long)e.inLen);
EVP_DigestFinal(&md_ctx, hash, 0);
if (XMEMCMP(hash, e.output, WC_SHA3_224_DIGEST_SIZE) != 0)
return -7403;
#endif /* WOLFSSL_NOSHA3_224 */
#ifndef WOLFSSL_NOSHA3_256
d.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
d.output = "\x91\x6f\x60\x61\xfe\x87\x97\x41\xca\x64\x69\xb4\x39\x71\xdf"
"\xdb\x28\xb1\xa3\x2d\xc3\x6c\xb3\x25\x4e\x81\x2b\xe2\x7a\xad"
"\x1d\x18";
d.inLen = XSTRLEN(d.input);
d.outLen = WC_SHA3_256_DIGEST_SIZE;
EVP_MD_CTX_init(&md_ctx);
EVP_DigestInit(&md_ctx, EVP_sha3_256());
EVP_DigestUpdate(&md_ctx, d.input, (unsigned long)d.inLen);
EVP_DigestFinal(&md_ctx, hash, 0);
if (XMEMCMP(hash, d.output, WC_SHA3_256_DIGEST_SIZE) != 0)
return -7404;
#endif /* WOLFSSL_NOSHA3_256 */
e.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
e.output = "\x79\x40\x7d\x3b\x59\x16\xb5\x9c\x3e\x30\xb0\x98\x22\x97\x47\x91\xc3\x13\xfb\x9e\xcc\x84\x9e\x40\x6f\x23\x59\x2d\x04\xf6\x25\xdc\x8c\x70\x9b\x98\xb4\x3b\x38\x52\xb3\x37\x21\x61\x79\xaa\x7f\xc7";
e.inLen = XSTRLEN(e.input);
e.outLen = WC_SHA3_384_DIGEST_SIZE;
EVP_MD_CTX_init(&md_ctx);
EVP_DigestInit(&md_ctx, EVP_sha3_384());
EVP_DigestUpdate(&md_ctx, e.input, (unsigned long)e.inLen);
EVP_DigestFinal(&md_ctx, hash, 0);
if (XMEMCMP(hash, e.output, WC_SHA3_384_DIGEST_SIZE) != 0)
return -7405;
#ifndef WOLFSSL_NOSHA3_512
f.input = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhi"
"jklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
f.output = "\xaf\xeb\xb2\xef\x54\x2e\x65\x79\xc5\x0c\xad\x06\xd2\xe5\x78\xf9\xf8\xdd\x68\x81\xd7\xdc\x82\x4d\x26\x36\x0f\xee\xbf\x18\xa4\xfa\x73\xe3\x26\x11\x22\x94\x8e\xfc\xfd\x49\x2e\x74\xe8\x2e\x21\x89\xed\x0f\xb4\x40\xd1\x87\xf3\x82\x27\x0c\xb4\x55\xf2\x1d\xd1\x85";
f.inLen = XSTRLEN(f.input);
f.outLen = WC_SHA3_512_DIGEST_SIZE;
EVP_MD_CTX_init(&md_ctx);
EVP_DigestInit(&md_ctx, EVP_sha3_512());
EVP_DigestUpdate(&md_ctx, f.input, (unsigned long)f.inLen);
EVP_DigestFinal(&md_ctx, hash, 0);
if (XMEMCMP(hash, f.output, WC_SHA3_512_DIGEST_SIZE) != 0)
return -7406;
#endif /* WOLFSSL_NOSHA3_512 */
#ifndef NO_MD5
if (RAND_bytes(hash, sizeof(hash)) != 1)

View File

@@ -43,6 +43,7 @@
#include <wolfssl/openssl/md5.h>
#endif
#include <wolfssl/openssl/sha.h>
#include <wolfssl/openssl/sha3.h>
#include <wolfssl/openssl/ripemd.h>
#include <wolfssl/openssl/rsa.h>
#include <wolfssl/openssl/dsa.h>
@@ -88,6 +89,11 @@ WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha384(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha512(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_ripemd160(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_224(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_256(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_384(void);
WOLFSSL_API const WOLFSSL_EVP_MD* wolfSSL_EVP_sha3_512(void);
WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_128_ecb(void);
WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_192_ecb(void);
WOLFSSL_API const WOLFSSL_EVP_CIPHER* wolfSSL_EVP_aes_256_ecb(void);
@@ -157,6 +163,16 @@ typedef union {
#ifdef WOLFSSL_RIPEMD
WOLFSSL_RIPEMD_CTX ripemd;
#endif
#ifndef WOLFSSL_NOSHA3_224
WOLFSSL_SHA3_224_CTX sha3_224;
#endif
#ifndef WOLFSSL_NOSHA3_256
WOLFSSL_SHA3_256_CTX sha3_256;
#endif
WOLFSSL_SHA3_384_CTX sha3_384;
#ifndef WOLFSSL_NOSHA3_512
WOLFSSL_SHA3_512_CTX sha3_512;
#endif
} WOLFSSL_Hasher;
typedef struct WOLFSSL_EVP_PKEY_CTX WOLFSSL_EVP_PKEY_CTX;
@@ -262,6 +278,10 @@ enum {
NID_ecdsa_with_SHA512 = 796,
NID_dsa_with_SHA224 = 802,
NID_dsa_with_SHA256 = 803,
NID_sha3_224 = 1096,
NID_sha3_256 = 1097,
NID_sha3_384 = 1098,
NID_sha3_512 = 1099,
};
enum {
@@ -628,6 +648,11 @@ typedef WOLFSSL_EVP_CIPHER_CTX EVP_CIPHER_CTX;
#define EVP_sha512 wolfSSL_EVP_sha512
#define EVP_ripemd160 wolfSSL_EVP_ripemd160
#define EVP_sha3_224 wolfSSL_EVP_sha3_224
#define EVP_sha3_256 wolfSSL_EVP_sha3_256
#define EVP_sha3_384 wolfSSL_EVP_sha3_384
#define EVP_sha3_512 wolfSSL_EVP_sha3_512
#define EVP_aes_128_cbc wolfSSL_EVP_aes_128_cbc
#define EVP_aes_192_cbc wolfSSL_EVP_aes_192_cbc
#define EVP_aes_256_cbc wolfSSL_EVP_aes_256_cbc

150
wolfssl/openssl/sha3.h Normal file
View File

@@ -0,0 +1,150 @@
/* sha3.h
*
* Copyright (C) 2006-2020 wolfSSL Inc.
*
* This file is part of wolfSSL.
*
* wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/
/* sha3.h for openssl */
#ifndef WOLFSSL_SHA3_H_
#define WOLFSSL_SHA3_H_
#include <wolfssl/wolfcrypt/settings.h>
#include <wolfssl/wolfcrypt/types.h>
#ifdef WOLFSSL_PREFIX
#include "prefix_sha.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Using ALIGN16 because when AES-NI is enabled digest and buffer in Sha3
* struct are 16 byte aligned. Any dereference to those elements after casting
* to Sha3 is expected to also be 16 byte aligned addresses. */
struct WOLFSSL_SHA3_CTX {
/* big enough to hold wolfcrypt Sha3, but check on init */
ALIGN16 void* holder[(424 + WC_ASYNC_DEV_SIZE) / sizeof(void*)];
};
#ifndef WOLFSSL_NOSHA3_224
typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_224_CTX;
WOLFSSL_API int wolfSSL_SHA3_224_Init(WOLFSSL_SHA3_224_CTX*);
WOLFSSL_API int wolfSSL_SHA3_224_Update(WOLFSSL_SHA3_224_CTX*, const void*,
unsigned long);
WOLFSSL_API int wolfSSL_SHA3_224_Final(unsigned char*, WOLFSSL_SHA3_224_CTX*);
enum {
SHA3_224_DIGEST_LENGTH = 28
};
typedef WOLFSSL_SHA3_224_CTX SHA3_224_CTX;
#define SHA3_224_Init wolfSSL_SHA3_224_Init
#define SHA3_224_Update wolfSSL_SHA3_224_Update
#define SHA3_224_Final wolfSSL_SHA3_224_Final
#if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
#define SHA3_224 wolfSSL_SHA3_224
#endif
#endif /* WOLFSSL_NOSHA3_224 */
#ifndef WOLFSSL_NOSHA3_256
typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_256_CTX;
WOLFSSL_API int wolfSSL_SHA3_256_Init(WOLFSSL_SHA3_256_CTX*);
WOLFSSL_API int wolfSSL_SHA3_256_Update(WOLFSSL_SHA3_256_CTX*, const void*,
unsigned long);
WOLFSSL_API int wolfSSL_SHA3_256_Final(unsigned char*, WOLFSSL_SHA3_256_CTX*);
enum {
SHA3_256_DIGEST_LENGTH = 32
};
typedef WOLFSSL_SHA3_256_CTX SHA3_256_CTX;
#define SHA3_256_Init wolfSSL_SHA3_256_Init
#define SHA3_256_Update wolfSSL_SHA3_256_Update
#define SHA3_256_Final wolfSSL_SHA3_256_Final
#if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
#define SHA3_256 wolfSSL_SHA3_256
#endif
#endif /* WOLFSSL_NOSHA3_256 */
typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_384_CTX;
WOLFSSL_API int wolfSSL_SHA3_384_Init(WOLFSSL_SHA3_384_CTX*);
WOLFSSL_API int wolfSSL_SHA3_384_Update(WOLFSSL_SHA3_384_CTX*, const void*,
unsigned long);
WOLFSSL_API int wolfSSL_SHA3_384_Final(unsigned char*, WOLFSSL_SHA3_384_CTX*);
enum {
SHA3_384_DIGEST_LENGTH = 48
};
typedef WOLFSSL_SHA3_384_CTX SHA3_384_CTX;
#define SHA3_384_Init wolfSSL_SHA3_384_Init
#define SHA3_384_Update wolfSSL_SHA3_384_Update
#define SHA3_384_Final wolfSSL_SHA3_384_Final
#if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
#define SHA3_384 wolfSSL_SHA3_384
#endif
#ifndef WOLFSSL_NOSHA3_512
typedef struct WOLFSSL_SHA3_CTX WOLFSSL_SHA3_512_CTX;
WOLFSSL_API int wolfSSL_SHA3_512_Init(WOLFSSL_SHA3_512_CTX*);
WOLFSSL_API int wolfSSL_SHA3_512_Update(WOLFSSL_SHA3_512_CTX*, const void*,
unsigned long);
WOLFSSL_API int wolfSSL_SHA3_512_Final(unsigned char*, WOLFSSL_SHA3_512_CTX*);
enum {
SHA3_512_DIGEST_LENGTH = 64
};
typedef WOLFSSL_SHA3_512_CTX SHA3_512_CTX;
#define SHA3_512_Init wolfSSL_SHA3_512_Init
#define SHA3_512_Update wolfSSL_SHA3_512_Update
#define SHA3_512_Final wolfSSL_SHA3_512_Final
#if defined(NO_OLD_WC_NAMES) && !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
#define SHA3_512 wolfSSL_SHA3_512
#endif
#endif /* WOLFSSL_NOSHA3_512 */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* WOLFSSL_SHA3_H_ */