blob: 9ec1e6c6f242b25e6deda3b333b8e7e6a50a27b6 [file] [log] [blame]
Adam Langleye1333452021-01-21 11:56:52 -08001/* Copyright (c) 2021, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15#ifndef OPENSSL_HEADER_BLAKE2_H
16#define OPENSSL_HEADER_BLAKE2_H
17
18#include <openssl/base.h>
19
20#if defined(__cplusplus)
21extern "C" {
22#endif
23
24
25#define BLAKE2B256_DIGEST_LENGTH (256 / 8)
26#define BLAKE2B_CBLOCK 128
27
28struct blake2b_state_st {
29 uint64_t h[8];
30 uint64_t t_low, t_high;
31 union {
32 uint8_t bytes[BLAKE2B_CBLOCK];
33 uint64_t words[16];
34 } block;
35 size_t block_used;
36};
37
38// BLAKE2B256_Init initialises |b2b| to perform a BLAKE2b-256 hash. There are no
39// pointers inside |b2b| thus release of |b2b| is purely managed by the caller.
40OPENSSL_EXPORT void BLAKE2B256_Init(BLAKE2B_CTX *b2b);
41
42// BLAKE2B256_Update appends |len| bytes from |data| to the digest being
43// calculated by |b2b|.
44OPENSSL_EXPORT void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *data,
45 size_t len);
46
47// BLAKE2B256_Final completes the digest calculated by |b2b| and writes
48// |BLAKE2B256_DIGEST_LENGTH| bytes to |out|.
49OPENSSL_EXPORT void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH],
50 BLAKE2B_CTX *b2b);
51
52// BLAKE2B256 writes the BLAKE2b-256 digset of |len| bytes from |data| to
53// |out|.
54OPENSSL_EXPORT void BLAKE2B256(const uint8_t *data, size_t len,
55 uint8_t out[BLAKE2B256_DIGEST_LENGTH]);
56
57
58#if defined(__cplusplus)
59} // extern C
60#endif
61
62#endif // OPENSSL_HEADER_BLAKE2_H