Monero
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 
51  };
52 
53 #pragma pack(push, 1)
54  typedef struct __blake2b_param {
57  uint8_t fanout; /* 3 */
58  uint8_t depth; /* 4 */
61  uint8_t node_depth; /* 17 */
63  uint8_t reserved[14]; /* 32 */
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];
74  unsigned buflen;
75  unsigned outlen;
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),
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);
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
uint8_t inner_length
Definition: blake2.h:62
struct __blake2b_param blake2b_param
blake2b_constant
Definition: blake2.h:45
unsigned buflen
Definition: blake2.h:74
#define blake2b_init
Definition: blake2.h:88
#define blake2b_final
Definition: blake2.h:92
const char * key
Definition: hmac_keccak.cpp:40
#define blake2b
Definition: blake2.h:93
unsigned char uint8_t
Definition: stdint.h:124
uint64_t f[2]
Definition: blake2.h:72
uint8_t depth
Definition: blake2.h:58
#define blake2b_init_key
Definition: blake2.h:89
Definition: blake2.h:47
Definition: blake2.h:54
uint8_t salt[BLAKE2B_SALTBYTES]
Definition: blake2.h:64
uint8_t personal[BLAKE2B_PERSONALBYTES]
Definition: blake2.h:65
struct __blake2b_state blake2b_state
Definition: blake2.h:46
Definition: blake2.h:49
uint64_t h[8]
Definition: blake2.h:70
#define blake2b_init_param
Definition: blake2.h:90
unsigned int uint32_t
Definition: stdint.h:126
#define blake2b_long
Definition: blake2.h:94
Definition: blake2.h:69
unsigned __int64 uint64_t
Definition: stdint.h:136
uint8_t buf[BLAKE2B_BLOCKBYTES]
Definition: blake2.h:73
Definition: blake2.h:83
uint8_t fanout
Definition: blake2.h:57
#define blake2b_update
Definition: blake2.h:91
Definition: blake2.h:50
Definition: blake2.h:48
uint64_t node_offset
Definition: blake2.h:60
Definition: blake2.h:82
#define S(s)
Definition: mdb_load.c:52
uint8_t key_length
Definition: blake2.h:56
uint64_t t[2]
Definition: blake2.h:71
unsigned outlen
Definition: blake2.h:75
uint32_t leaf_length
Definition: blake2.h:59
uint8_t node_depth
Definition: blake2.h:61
uint8_t last_node
Definition: blake2.h:76
uint8_t reserved[14]
Definition: blake2.h:63
uint8_t digest_length
Definition: blake2.h:55