xref: /aosp_15_r20/external/boringssl/include/openssl/blake2.h (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1 /* 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)
21 extern "C" {
22 #endif
23 
24 
25 #define BLAKE2B256_DIGEST_LENGTH (256 / 8)
26 #define BLAKE2B_CBLOCK 128
27 
28 struct blake2b_state_st {
29   uint64_t h[8];
30   uint64_t t_low, t_high;
31   uint8_t block[BLAKE2B_CBLOCK];
32   size_t block_used;
33 };
34 
35 // BLAKE2B256_Init initialises |b2b| to perform a BLAKE2b-256 hash. There are no
36 // pointers inside |b2b| thus release of |b2b| is purely managed by the caller.
37 OPENSSL_EXPORT void BLAKE2B256_Init(BLAKE2B_CTX *b2b);
38 
39 // BLAKE2B256_Update appends |len| bytes from |data| to the digest being
40 // calculated by |b2b|.
41 OPENSSL_EXPORT void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *data,
42                                       size_t len);
43 
44 // BLAKE2B256_Final completes the digest calculated by |b2b| and writes
45 // |BLAKE2B256_DIGEST_LENGTH| bytes to |out|.
46 OPENSSL_EXPORT void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH],
47                                      BLAKE2B_CTX *b2b);
48 
49 // BLAKE2B256 writes the BLAKE2b-256 digset of |len| bytes from |data| to
50 // |out|.
51 OPENSSL_EXPORT void BLAKE2B256(const uint8_t *data, size_t len,
52                                uint8_t out[BLAKE2B256_DIGEST_LENGTH]);
53 
54 
55 #if defined(__cplusplus)
56 }  // extern C
57 #endif
58 
59 #endif  // OPENSSL_HEADER_BLAKE2_H
60