blob: cdcb0661d91094d330d2222f3b8835252d5bb271 [file] [log] [blame]
xf.libfc6e712025-02-07 01:54:34 -08001/* blake2.h
2 *
3 * Copyright (C) 2006-2021 wolfSSL Inc.
4 *
5 * This file is part of wolfSSL.
6 *
7 * wolfSSL is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * wolfSSL is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20 */
21
22/*!
23 \file wolfssl/wolfcrypt/blake2.h
24*/
25
26#ifndef WOLF_CRYPT_BLAKE2_H
27#define WOLF_CRYPT_BLAKE2_H
28
29#include <wolfssl/wolfcrypt/settings.h>
30
31#if defined(HAVE_BLAKE2) || defined(HAVE_BLAKE2S)
32
33#include <wolfssl/wolfcrypt/blake2-int.h>
34
35/* call old functions if using fips for the sake of hmac @wc_fips */
36#ifdef HAVE_FIPS
37 /* Since hmac can call blake functions provide original calls */
38 #define wc_InitBlake2b InitBlake2b
39 #define wc_Blake2bUpdate Blake2bUpdate
40 #define wc_Blake2bFinal Blake2bFinal
41#endif
42
43#ifdef __cplusplus
44 extern "C" {
45#endif
46
47/* in bytes, variable digest size up to 512 bits (64 bytes) */
48enum {
49#ifdef HAVE_BLAKE2B
50 BLAKE2B_ID = WC_HASH_TYPE_BLAKE2B,
51 BLAKE2B_256 = 32, /* 256 bit type, SSL default */
52#endif
53#ifdef HAVE_BLAKE2S
54 BLAKE2S_ID = WC_HASH_TYPE_BLAKE2S,
55 BLAKE2S_256 = 32 /* 256 bit type */
56#endif
57};
58
59
60#ifdef HAVE_BLAKE2B
61/* BLAKE2b digest */
62typedef struct Blake2b {
63 blake2b_state S[1]; /* our state */
64 word32 digestSz; /* digest size used on init */
65} Blake2b;
66#endif
67
68#ifdef HAVE_BLAKE2S
69/* BLAKE2s digest */
70typedef struct Blake2s {
71 blake2s_state S[1]; /* our state */
72 word32 digestSz; /* digest size used on init */
73} Blake2s;
74#endif
75
76
77#ifdef HAVE_BLAKE2B
78WOLFSSL_API int wc_InitBlake2b(Blake2b*, word32);
79WOLFSSL_API int wc_InitBlake2b_WithKey(Blake2b*, word32, const byte *, word32);
80WOLFSSL_API int wc_Blake2bUpdate(Blake2b*, const byte*, word32);
81WOLFSSL_API int wc_Blake2bFinal(Blake2b*, byte*, word32);
82#endif
83
84#ifdef HAVE_BLAKE2S
85WOLFSSL_API int wc_InitBlake2s(Blake2s*, word32);
86WOLFSSL_API int wc_InitBlake2s_WithKey(Blake2s*, word32, const byte *, word32);
87WOLFSSL_API int wc_Blake2sUpdate(Blake2s*, const byte*, word32);
88WOLFSSL_API int wc_Blake2sFinal(Blake2s*, byte*, word32);
89#endif
90
91
92#ifdef __cplusplus
93 }
94#endif
95
96#endif /* HAVE_BLAKE2 || HAVE_BLAKE2S */
97#endif /* WOLF_CRYPT_BLAKE2_H */
98