]>
Commit | Line | Data |
---|---|---|
2d0b4412 | 1 | /* |
8020d79b | 2 | * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. |
2d0b4412 | 3 | * |
04e388ce | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
b1322259 RS |
5 | * this file except in compliance with the License. You can obtain a copy |
6 | * in the file LICENSE in the source distribution or at | |
208527a7 | 7 | * https://www.openssl.org/source/license.html |
2d0b4412 BC |
8 | */ |
9 | ||
fffb6734 TM |
10 | #ifndef OSSL_PROV_BLAKE2_H |
11 | # define OSSL_PROV_BLAKE2_H | |
d5e5e2ff SL |
12 | |
13 | # include <openssl/opensslconf.h> | |
2d0b4412 | 14 | |
d5e5e2ff SL |
15 | # include <openssl/e_os2.h> |
16 | # include <stddef.h> | |
786b9a8d | 17 | # include <crypto/evp.h> |
2d0b4412 | 18 | |
d5e5e2ff SL |
19 | # define BLAKE2S_BLOCKBYTES 64 |
20 | # define BLAKE2S_OUTBYTES 32 | |
21 | # define BLAKE2S_KEYBYTES 32 | |
22 | # define BLAKE2S_SALTBYTES 8 | |
23 | # define BLAKE2S_PERSONALBYTES 8 | |
2d0b4412 | 24 | |
d5e5e2ff SL |
25 | # define BLAKE2B_BLOCKBYTES 128 |
26 | # define BLAKE2B_OUTBYTES 64 | |
27 | # define BLAKE2B_KEYBYTES 64 | |
28 | # define BLAKE2B_SALTBYTES 16 | |
29 | # define BLAKE2B_PERSONALBYTES 16 | |
2d0b4412 BC |
30 | |
31 | struct blake2s_param_st { | |
32 | uint8_t digest_length; /* 1 */ | |
33 | uint8_t key_length; /* 2 */ | |
34 | uint8_t fanout; /* 3 */ | |
35 | uint8_t depth; /* 4 */ | |
a5741089 | 36 | uint8_t leaf_length[4];/* 8 */ |
2d0b4412 BC |
37 | uint8_t node_offset[6];/* 14 */ |
38 | uint8_t node_depth; /* 15 */ | |
39 | uint8_t inner_length; /* 16 */ | |
2d0b4412 BC |
40 | uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */ |
41 | uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */ | |
42 | }; | |
43 | ||
44 | typedef struct blake2s_param_st BLAKE2S_PARAM; | |
45 | ||
46 | struct blake2s_ctx_st { | |
47 | uint32_t h[8]; | |
48 | uint32_t t[2]; | |
49 | uint32_t f[2]; | |
50 | uint8_t buf[BLAKE2S_BLOCKBYTES]; | |
51 | size_t buflen; | |
18568864 | 52 | size_t outlen; |
2d0b4412 BC |
53 | }; |
54 | ||
55 | struct blake2b_param_st { | |
56 | uint8_t digest_length; /* 1 */ | |
57 | uint8_t key_length; /* 2 */ | |
58 | uint8_t fanout; /* 3 */ | |
59 | uint8_t depth; /* 4 */ | |
a5741089 KR |
60 | uint8_t leaf_length[4];/* 8 */ |
61 | uint8_t node_offset[8];/* 16 */ | |
2d0b4412 BC |
62 | uint8_t node_depth; /* 17 */ |
63 | uint8_t inner_length; /* 18 */ | |
64 | uint8_t reserved[14]; /* 32 */ | |
65 | uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */ | |
66 | uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */ | |
67 | }; | |
68 | ||
69 | typedef struct blake2b_param_st BLAKE2B_PARAM; | |
70 | ||
71 | struct blake2b_ctx_st { | |
72 | uint64_t h[8]; | |
73 | uint64_t t[2]; | |
74 | uint64_t f[2]; | |
75 | uint8_t buf[BLAKE2B_BLOCKBYTES]; | |
76 | size_t buflen; | |
18568864 | 77 | size_t outlen; |
2d0b4412 BC |
78 | }; |
79 | ||
80 | #define BLAKE2B_DIGEST_LENGTH 64 | |
81 | #define BLAKE2S_DIGEST_LENGTH 32 | |
82 | ||
83 | typedef struct blake2s_ctx_st BLAKE2S_CTX; | |
84 | typedef struct blake2b_ctx_st BLAKE2B_CTX; | |
85 | ||
786b9a8d ČK |
86 | struct blake2b_md_data_st { |
87 | BLAKE2B_CTX ctx; | |
88 | BLAKE2B_PARAM params; | |
89 | }; | |
90 | ||
47c076ac SL |
91 | int ossl_blake2s256_init(void *ctx); |
92 | int ossl_blake2b512_init(void *ctx); | |
d5e5e2ff | 93 | |
47c076ac SL |
94 | int ossl_blake2b_init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P); |
95 | int ossl_blake2b_init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, | |
96 | const void *key); | |
97 | int ossl_blake2b_update(BLAKE2B_CTX *c, const void *data, size_t datalen); | |
98 | int ossl_blake2b_final(unsigned char *md, BLAKE2B_CTX *c); | |
2d0b4412 | 99 | |
786b9a8d ČK |
100 | OSSL_FUNC_digest_set_ctx_params_fn ossl_blake2b_set_ctx_params; |
101 | OSSL_FUNC_digest_settable_ctx_params_fn ossl_blake2b_settable_ctx_params; | |
102 | ||
fc3c0223 AS |
103 | /* |
104 | * These setters are internal and do not check the validity of their parameters. | |
105 | * See blake2b_mac_ctrl for validation logic. | |
106 | */ | |
107 | ||
47c076ac SL |
108 | void ossl_blake2b_param_init(BLAKE2B_PARAM *P); |
109 | void ossl_blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen); | |
110 | void ossl_blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen); | |
111 | void ossl_blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, | |
112 | size_t length); | |
113 | void ossl_blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, | |
114 | size_t length); | |
115 | int ossl_blake2s_init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P); | |
116 | int ossl_blake2s_init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, | |
117 | const void *key); | |
118 | int ossl_blake2s_update(BLAKE2S_CTX *c, const void *data, size_t datalen); | |
119 | int ossl_blake2s_final(unsigned char *md, BLAKE2S_CTX *c); | |
120 | ||
121 | void ossl_blake2s_param_init(BLAKE2S_PARAM *P); | |
122 | void ossl_blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen); | |
123 | void ossl_blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen); | |
124 | void ossl_blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, | |
125 | size_t length); | |
126 | void ossl_blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, | |
127 | size_t length); | |
d5e5e2ff | 128 | |
fffb6734 | 129 | #endif /* OSSL_PROV_BLAKE2_H */ |