Monero
argon2_core.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 ARGON2_CORE_H
36 #define ARGON2_CORE_H
37 
38 #include <stdint.h>
39 #include "argon2.h"
40 
41 #if defined(__cplusplus)
42 extern "C" {
43 #endif
44 
45 #define CONST_CAST(x) (x)(uintptr_t)
46 
47  /**********************Argon2 internal constants*******************************/
48 
50  /* Memory block size in bytes */
56 
57  /* Number of pseudo-random values generated by one call to Blake in Argon2i
58  to
59  generate reference block positions */
61 
62  /* Pre-hashing digest length and its extension*/
65 };
66 
67 /*************************Argon2 internal data types***********************/
68 
69 /*
70  * Structure for the (1KB) memory block implemented as 128 64-bit words.
71  * Memory blocks can be copied, XORed. Internal words can be accessed by [] (no
72  * bounds checking).
73  */
75 
76 /*
77  * Argon2 instance: memory pointer, number of passes, amount of memory, type,
78  * and derived values.
79  * Used to evaluate the number and location of blocks to construct in each
80  * thread
81  */
82 typedef struct Argon2_instance_t {
83  block *memory; /* Memory pointer */
85  uint32_t passes; /* Number of passes */
86  uint32_t memory_blocks; /* Number of blocks in memory */
92  int print_internals; /* whether to print the memory blocks */
93  argon2_context *context_ptr; /* points back to original context */
96 
97 /*
98  * Argon2 position: where we construct the block right now. Used to distribute
99  * work between threads.
100  */
101 typedef struct Argon2_position_t {
107 
108 /*Struct that holds the inputs for thread handling FillSegment*/
109 typedef struct Argon2_thread_data {
113 
114 /*************************Argon2 core functions********************************/
115 
116 /*
117  * Computes absolute position of reference block in the lane following a skewed
118  * distribution and using a pseudo-random value as input
119  * @param instance Pointer to the current instance
120  * @param position Pointer to the current position
121  * @param pseudo_rand 32-bit pseudo-random value used to determine the position
122  * @param same_lane Indicates if the block will be taken from the current lane.
123  * If so we can reference the current segment
124  * @pre All pointers must be valid
125  */
127  const argon2_position_t *position, uint32_t pseudo_rand,
128  int same_lane);
129 
130 /*
131  * Function that validates all inputs against predefined restrictions and return
132  * an error code
133  * @param context Pointer to current Argon2 context
134  * @return ARGON2_OK if everything is all right, otherwise one of error codes
135  * (all defined in <argon2.h>
136  */
138 
139 /*
140  * Function allocates memory, hashes the inputs with Blake, and creates first
141  * two blocks. Returns the pointer to the main memory with 2 blocks per lane
142  * initialized
143  * @param context Pointer to the Argon2 internal structure containing memory
144  * pointer, and parameters for time and space requirements.
145  * @param instance Current Argon2 instance
146  * @return Zero if successful, -1 if memory failed to allocate. @context->state
147  * will be modified if successful.
148  */
150 
151 /*
152  * Function that fills the entire memory t_cost times based on the first two
153  * blocks in each lane
154  * @param instance Pointer to the current instance
155  * @return ARGON2_OK if successful, @context->state
156  */
158 
159 #if defined(__cplusplus)
160 }
161 #endif
162 
163 #endif
uint32_t segment_length
Definition: argon2_core.h:87
int randomx_argon2_initialize(argon2_instance_t *instance, argon2_context *context)
Definition: argon2_core.c:385
Definition: argon2_core.h:109
enum Argon2_type argon2_type
struct Argon2_position_t argon2_position_t
argon2_type type
Definition: argon2_core.h:91
Definition: argon2_core.h:101
Definition: argon2_core.h:54
randomx_argon2_impl * impl
Definition: argon2_core.h:94
Definition: argon2_core.h:82
unsigned char uint8_t
Definition: stdint.h:124
struct block_ block
struct Argon2_instance_t argon2_instance_t
argon2_position_t pos
Definition: argon2_core.h:111
uint32_t randomx_argon2_index_alpha(const argon2_instance_t *instance, const argon2_position_t *position, uint32_t pseudo_rand, int same_lane)
Definition: argon2_core.c:88
void randomx_argon2_impl(const argon2_instance_t *instance, argon2_position_t position)
Definition: argon2.h:238
Definition: argon2_core.h:64
Definition: argon2_core.h:63
uint32_t threads
Definition: argon2_core.h:90
argon2_context * context_ptr
Definition: argon2_core.h:93
unsigned int uint32_t
Definition: stdint.h:126
uint32_t passes
Definition: argon2_core.h:85
uint32_t lanes
Definition: argon2_core.h:89
uint32_t lane_length
Definition: argon2_core.h:88
Definition: argon2_core.h:74
Definition: argon2_core.h:55
Definition: argon2.h:188
Definition: argon2_core.h:51
unsigned __int64 uint64_t
Definition: stdint.h:136
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:105
argon2_core_constants
Definition: argon2_core.h:49
static reverse_alphabet instance
Definition: base58.cpp:73
Definition: argon2_core.h:60
int randomx_argon2_validate_inputs(const argon2_context *context)
Definition: argon2_core.c:185
uint32_t lane
Definition: argon2_core.h:103
struct Argon2_thread_data argon2_thread_data
uint32_t memory_blocks
Definition: argon2_core.h:86
int print_internals
Definition: argon2_core.h:92
Definition: argon2_core.h:53
uint32_t index
Definition: argon2_core.h:105
uint64_t v[ARGON2_QWORDS_IN_BLOCK]
Definition: argon2_core.h:74
Definition: argon2_core.h:52
block * memory
Definition: argon2_core.h:83
int randomx_argon2_fill_memory_blocks(argon2_instance_t *instance)
Definition: argon2_core.c:178
uint32_t pass
Definition: argon2_core.h:102
uint32_t version
Definition: argon2_core.h:84
argon2_instance_t * instance_ptr
Definition: argon2_core.h:110
uint8_t slice
Definition: argon2_core.h:104