Monero
Toggle main menu visibility
Loading...
Searching...
No Matches
external
randomx
src
blake2
blake2.h
Go to the documentation of this file.
1
/*
2
Copyright (c) 2018-2019, tevador <tevador@gmail.com>
3
4
All rights reserved.
5
6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions are met:
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in the
12
documentation and/or other materials provided with the distribution.
13
* Neither the name of the copyright holder nor the
14
names of its contributors may be used to endorse or promote products
15
derived from this software without specific prior written permission.
16
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
*/
28
29
/* Original code from Argon2 reference source code package used under CC0 Licence
30
* https://github.com/P-H-C/phc-winner-argon2
31
* Copyright 2015
32
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
33
*/
34
35
#ifndef PORTABLE_BLAKE2_H
36
#define PORTABLE_BLAKE2_H
37
38
#include <
stdint.h
>
39
#include <limits.h>
40
41
#if defined(__cplusplus)
42
extern
"C"
{
43
#endif
44
45
enum
blake2b_constant
{
46
BLAKE2B_BLOCKBYTES
= 128,
47
BLAKE2B_OUTBYTES
= 64,
48
BLAKE2B_KEYBYTES
= 64,
49
BLAKE2B_SALTBYTES
= 16,
50
BLAKE2B_PERSONALBYTES
= 16
51
};
52
53
#pragma pack(push, 1)
54
typedef
struct
__blake2b_param
{
55
uint8_t
digest_length
;
/* 1 */
56
uint8_t
key_length
;
/* 2 */
57
uint8_t
fanout
;
/* 3 */
58
uint8_t
depth
;
/* 4 */
59
uint32_t
leaf_length
;
/* 8 */
60
uint64_t
node_offset
;
/* 16 */
61
uint8_t
node_depth
;
/* 17 */
62
uint8_t
inner_length
;
/* 18 */
63
uint8_t
reserved
[14];
/* 32 */
64
uint8_t
salt
[
BLAKE2B_SALTBYTES
];
/* 48 */
65
uint8_t
personal
[
BLAKE2B_PERSONALBYTES
];
/* 64 */
66
}
blake2b_param
;
67
#pragma pack(pop)
68
69
typedef
struct
__blake2b_state
{
70
uint64_t
h
[8];
71
uint64_t
t
[2];
72
uint64_t
f
[2];
73
uint8_t
buf
[
BLAKE2B_BLOCKBYTES
];
74
unsigned
buflen
;
75
unsigned
outlen
;
76
uint8_t
last_node
;
77
}
blake2b_state
;
78
79
/* Ensure param structs have not been wrongly padded */
80
/* Poor man's static_assert */
81
enum
{
82
blake2_size_check_0
= 1 / !!(CHAR_BIT == 8),
83
blake2_size_check_2
=
84
1 / !!(
sizeof
(
blake2b_param
) ==
sizeof
(
uint64_t
) * CHAR_BIT)
85
};
86
87
//randomx namespace
88
#define blake2b_init randomx_blake2b_init
89
#define blake2b_init_key randomx_blake2b_init_key
90
#define blake2b_init_param randomx_blake2b_init_param
91
#define blake2b_update randomx_blake2b_update
92
#define blake2b_final randomx_blake2b_final
93
#define blake2b randomx_blake2b
94
#define blake2b_long randomx_blake2b_long
95
96
/* Streaming API */
97
int
blake2b_init
(
blake2b_state
*
S
,
size_t
outlen);
98
int
blake2b_init_key
(
blake2b_state
*
S
,
size_t
outlen,
const
void
*
key
,
99
size_t
keylen);
100
int
blake2b_init_param
(
blake2b_state
*
S
,
const
blake2b_param
*P);
101
int
blake2b_update
(
blake2b_state
*
S
,
const
void
*in,
size_t
inlen);
102
int
blake2b_final
(
blake2b_state
*
S
,
void
*out,
size_t
outlen);
103
104
/* Simple API */
105
int
blake2b
(
void
*out,
size_t
outlen,
const
void
*in,
size_t
inlen,
106
const
void
*
key
,
size_t
keylen);
107
108
/* Argon2 Team - Begin Code */
109
int
blake2b_long
(
void
*out,
size_t
outlen,
const
void
*in,
size_t
inlen);
110
/* Argon2 Team - End Code */
111
112
#if defined(__cplusplus)
113
}
114
#endif
115
116
#endif
blake2b_state
struct __blake2b_state blake2b_state
blake2b_update
#define blake2b_update
Definition
blake2.h:91
blake2b
#define blake2b
Definition
blake2.h:93
blake2b_constant
blake2b_constant
Definition
blake2.h:45
BLAKE2B_PERSONALBYTES
@ BLAKE2B_PERSONALBYTES
Definition
blake2.h:50
BLAKE2B_KEYBYTES
@ BLAKE2B_KEYBYTES
Definition
blake2.h:48
BLAKE2B_OUTBYTES
@ BLAKE2B_OUTBYTES
Definition
blake2.h:47
BLAKE2B_SALTBYTES
@ BLAKE2B_SALTBYTES
Definition
blake2.h:49
BLAKE2B_BLOCKBYTES
@ BLAKE2B_BLOCKBYTES
Definition
blake2.h:46
blake2_size_check_0
@ blake2_size_check_0
Definition
blake2.h:82
blake2_size_check_2
@ blake2_size_check_2
Definition
blake2.h:83
blake2b_final
#define blake2b_final
Definition
blake2.h:92
blake2b_init
#define blake2b_init
Definition
blake2.h:88
blake2b_long
#define blake2b_long
Definition
blake2.h:94
blake2b_init_key
#define blake2b_init_key
Definition
blake2.h:89
blake2b_init_param
#define blake2b_init_param
Definition
blake2.h:90
blake2b_param
struct __blake2b_param blake2b_param
key
const char * key
Definition
hmac_keccak.cpp:40
S
#define S(s)
Definition
mdb_load.c:52
stdint.h
uint32_t
unsigned int uint32_t
Definition
stdint.h:126
uint8_t
unsigned char uint8_t
Definition
stdint.h:124
uint64_t
unsigned __int64 uint64_t
Definition
stdint.h:136
__blake2b_param
Definition
blake2.h:54
__blake2b_param::reserved
uint8_t reserved[14]
Definition
blake2.h:63
__blake2b_param::inner_length
uint8_t inner_length
Definition
blake2.h:62
__blake2b_param::leaf_length
uint32_t leaf_length
Definition
blake2.h:59
__blake2b_param::node_depth
uint8_t node_depth
Definition
blake2.h:61
__blake2b_param::fanout
uint8_t fanout
Definition
blake2.h:57
__blake2b_param::digest_length
uint8_t digest_length
Definition
blake2.h:55
__blake2b_param::salt
uint8_t salt[BLAKE2B_SALTBYTES]
Definition
blake2.h:64
__blake2b_param::depth
uint8_t depth
Definition
blake2.h:58
__blake2b_param::node_offset
uint64_t node_offset
Definition
blake2.h:60
__blake2b_param::key_length
uint8_t key_length
Definition
blake2.h:56
__blake2b_param::personal
uint8_t personal[BLAKE2B_PERSONALBYTES]
Definition
blake2.h:65
__blake2b_state
Definition
blake2.h:69
__blake2b_state::last_node
uint8_t last_node
Definition
blake2.h:76
__blake2b_state::t
uint64_t t[2]
Definition
blake2.h:71
__blake2b_state::f
uint64_t f[2]
Definition
blake2.h:72
__blake2b_state::buflen
unsigned buflen
Definition
blake2.h:74
__blake2b_state::h
uint64_t h[8]
Definition
blake2.h:70
__blake2b_state::outlen
unsigned outlen
Definition
blake2.h:75
__blake2b_state::buf
uint8_t buf[BLAKE2B_BLOCKBYTES]
Definition
blake2.h:73
Generated on
for Monero by
1.17.0