]> git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/include/internal/blake2_locl.h
ba438f4e3e76b619939aaa55de544040bba0653b
[thirdparty/openssl.git] / crypto / include / internal / blake2_locl.h
1 /*
2 * Copyright 2012, Samuel Neves <sneves@dei.uc.pt>.
3 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 *
5 * Licensed under the OpenSSL licenses, (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 * https://www.openssl.org/source/license.html
9 * or in the file LICENSE in the source distribution.
10 */
11
12 /*
13 * Derived from the BLAKE2 reference implementation written by Samuel Neves.
14 * More information about the BLAKE2 hash function and its implementations
15 * can be found at https://blake2.net.
16 */
17
18 #include <stddef.h>
19 #include "e_os.h"
20
21 # ifdef OPENSSL_NO_BLAKE2
22 # error BLAKE2 is disabled.
23 # endif
24
25 #define BLAKE2S_BLOCKBYTES 64
26 #define BLAKE2S_OUTBYTES 32
27 #define BLAKE2S_KEYBYTES 32
28 #define BLAKE2S_SALTBYTES 8
29 #define BLAKE2S_PERSONALBYTES 8
30
31 #define BLAKE2B_BLOCKBYTES 128
32 #define BLAKE2B_OUTBYTES 64
33 #define BLAKE2B_KEYBYTES 64
34 #define BLAKE2B_SALTBYTES 16
35 #define BLAKE2B_PERSONALBYTES 16
36
37 struct blake2s_param_st {
38 uint8_t digest_length; /* 1 */
39 uint8_t key_length; /* 2 */
40 uint8_t fanout; /* 3 */
41 uint8_t depth; /* 4 */
42 uint8_t leaf_length[4];/* 8 */
43 uint8_t node_offset[6];/* 14 */
44 uint8_t node_depth; /* 15 */
45 uint8_t inner_length; /* 16 */
46 uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
47 uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
48 };
49
50 typedef struct blake2s_param_st BLAKE2S_PARAM;
51
52 struct blake2s_ctx_st {
53 uint32_t h[8];
54 uint32_t t[2];
55 uint32_t f[2];
56 uint8_t buf[BLAKE2S_BLOCKBYTES];
57 size_t buflen;
58 };
59
60 struct blake2b_param_st {
61 uint8_t digest_length; /* 1 */
62 uint8_t key_length; /* 2 */
63 uint8_t fanout; /* 3 */
64 uint8_t depth; /* 4 */
65 uint8_t leaf_length[4];/* 8 */
66 uint8_t node_offset[8];/* 16 */
67 uint8_t node_depth; /* 17 */
68 uint8_t inner_length; /* 18 */
69 uint8_t reserved[14]; /* 32 */
70 uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
71 uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
72 };
73
74 typedef struct blake2b_param_st BLAKE2B_PARAM;
75
76 struct blake2b_ctx_st {
77 uint64_t h[8];
78 uint64_t t[2];
79 uint64_t f[2];
80 uint8_t buf[BLAKE2B_BLOCKBYTES];
81 size_t buflen;
82 };
83
84 #define BLAKE2B_DIGEST_LENGTH 64
85 #define BLAKE2S_DIGEST_LENGTH 32
86
87 typedef struct blake2s_ctx_st BLAKE2S_CTX;
88 typedef struct blake2b_ctx_st BLAKE2B_CTX;
89
90 int BLAKE2b_Init(BLAKE2B_CTX *c);
91 int BLAKE2b_Update(BLAKE2B_CTX *c, const void *data, size_t datalen);
92 int BLAKE2b_Final(unsigned char *md, BLAKE2B_CTX *c);
93
94 int BLAKE2s_Init(BLAKE2S_CTX *c);
95 int BLAKE2s_Update(BLAKE2S_CTX *c, const void *data, size_t datalen);
96 int BLAKE2s_Final(unsigned char *md, BLAKE2S_CTX *c);