dualcone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+
5
+ cflags = %w[
6
+ -march=native -fno-exceptions -pipe
7
+ -fstack-protector-strong -fPIC -Wall -Werror
8
+ -Wno-missing-braces
9
+ ]
10
+
11
+ if ENV['DEBUG']
12
+ cflags.unshift('-O0', '-g')
13
+ else
14
+ cflags.unshift('-Os')
15
+ end
16
+
17
+ LIBHYDROGEN_DIR = File.join(__dir__, '..', '..', 'vendor', 'libhydrogen')
18
+
19
+ abort 'ERROR: make is required to build libhydrogen.' unless find_executable('make')
20
+
21
+ append_cflags(cflags)
22
+
23
+ # Build the bundled version of libhydrogen in vendor
24
+ Dir.chdir(LIBHYDROGEN_DIR) do
25
+ system('make clean')
26
+ system("export CFLAGS='#{cflags.join(' ')}'; make")
27
+ system('PREFIX=. make install')
28
+
29
+ # Ensure that our bundled version of libhydrogen is always used
30
+ $DEFLIBPATH.unshift("#{LIBHYDROGEN_DIR}/lib")
31
+ dir_config('hydrogen', "#{LIBHYDROGEN_DIR}/include", "#{LIBHYDROGEN_DIR}/lib")
32
+ end
33
+
34
+ abort 'ERROR: Failed to build libhydrogen.' unless have_library('hydrogen') && have_header('hydrogen.h')
35
+
36
+ create_makefile('dualcone/dualcone')
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'dualcone/version'
4
+ require 'dualcone/dualcone'
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dualcone
4
+ VERSION = '0.0.1'
5
+ end
@@ -0,0 +1,18 @@
1
+ /*
2
+ * ISC License
3
+ *
4
+ * Copyright (c) 2017-2019
5
+ * Frank Denis <j at pureftpd dot org>
6
+ *
7
+ * Permission to use, copy, modify, and/or distribute this software for any
8
+ * purpose with or without fee is hereby granted, provided that the above
9
+ * copyright notice and this permission notice appear in all copies.
10
+ *
11
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
+ */
@@ -0,0 +1,61 @@
1
+ PREFIX ?= /usr/local
2
+ WFLAGS ?= -Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wno-type-limits
3
+ CFLAGS ?= -Os -march=native -fno-exceptions $(WFLAGS)
4
+ CFLAGS += -I.
5
+ OBJ = hydrogen.o
6
+ AR ?= ar
7
+ RANLIB ?= ranlib
8
+
9
+ SRC = \
10
+ hydrogen.c \
11
+ hydrogen.h \
12
+ impl/common.h \
13
+ impl/core.h \
14
+ impl/gimli-core.h \
15
+ impl/hash.h \
16
+ impl/hydrogen_p.h \
17
+ impl/kdf.h \
18
+ impl/kx.h \
19
+ impl/pwhash.h \
20
+ impl/random.h \
21
+ impl/secretbox.h \
22
+ impl/sign.h \
23
+ impl/x25519.h
24
+
25
+ all: lib test
26
+
27
+ lib: libhydrogen.a
28
+
29
+ install: lib
30
+ mkdir -p $(PREFIX)/lib
31
+ install -o 0 -g 0 -m 0755 libhydrogen.a $(PREFIX)/lib 2> /dev/null || install -m 0755 libhydrogen.a $(PREFIX)/lib
32
+ mkdir -p $(PREFIX)/include
33
+ install -o 0 -g 0 -m 0644 hydrogen.h $(PREFIX)/include 2> /dev/null || install -m 0644 hydrogen.h $(PREFIX)/include
34
+ ldconfig 2> /dev/null || true
35
+
36
+ uninstall:
37
+ rm -f $(PREFIX)/lib/libhydrogen.a
38
+ rm -f $(PREFIX)/include/hydrogen.h
39
+
40
+ test: tests/tests
41
+ rm -f tests/tests.done
42
+ tests/tests && touch tests/tests.done
43
+
44
+ tests/tests: $(SRC) tests/tests.c
45
+ $(CC) $(CFLAGS) -O3 -o tests/tests hydrogen.c tests/tests.c
46
+
47
+ $(OBJ): $(SRC)
48
+
49
+ libhydrogen.a: $(OBJ)
50
+ $(AR) -r $@ $^
51
+ $(RANLIB) $@
52
+
53
+ .PHONY: clean
54
+
55
+ clean:
56
+ rm -f libhydrogen.a $(OBJ)
57
+ rm -f tests/tests tests/*.done
58
+
59
+ check: test
60
+
61
+ distclean: clean
@@ -0,0 +1,36 @@
1
+ [![Build Status](https://travis-ci.org/jedisct1/libhydrogen.svg?branch=master)](https://travis-ci.org/jedisct1/libhydrogen?branch=master)
2
+ [![Financial Contributors on Open Collective](https://opencollective.com/libhydrogen/all/badge.svg?label=financial+contributors)](https://opencollective.com/libhydrogen) [![Coverity Scan Build Status](https://scan.coverity.com/projects/13315/badge.svg)](https://scan.coverity.com/projects/13315)
3
+
4
+ ![libhydrogen](https://raw.github.com/jedisct1/libhydrogen/master/logo.png)
5
+ ==============
6
+
7
+ The Hydrogen library is a small, easy-to-use, hard-to-misuse cryptographic library.
8
+
9
+ Features:
10
+ - Consistent high-level API, inspired by libsodium. Instead of low-level primitives, it exposes simple functions to solve common problems that cryptography can solve.
11
+ - 100% built using just two cryptographic building blocks: the [Curve25519](https://cr.yp.to/ecdh.html) elliptic curve, and the [Gimli](https://csrc.nist.gov/CSRC/media/Projects/Lightweight-Cryptography/documents/round-1/spec-doc/gimli-spec.pdf) permutation.
12
+ - Small and easy to audit. Implemented as one tiny file for every set of operation, and adding a single `.c` file to your project is all it takes to use libhydrogen in your project.
13
+ - The whole code is released under a single, very liberal license (ISC).
14
+ - Zero dynamic memory allocations and low stack requirements (median: 32 bytes, max: 128 bytes). This makes it usable in constrained environments such as microcontrollers.
15
+ - Portable: written in standard C99. Supports Linux, *BSD, MacOS, Windows, and the Arduino IDE out of the box.
16
+ - Can generate cryptographically-secure random numbers, even on Arduino boards.
17
+ - Attempts to mitigate the implications of accidental misuse, even on systems with an unreliable PRG and/or no clock.
18
+
19
+ Non-goals:
20
+ - Having multiple primitives serving the same purpose, even to provide compatibility with other libraries.
21
+ - Networking -- but a simple key exchange API based on the Noise protocol is available, and a STROBE-based transport API will be implemented.
22
+ - Interoperability with other libraries.
23
+ - Replacing libsodium. Libhydrogen tries to keep the number of APIs and the code size down to a minimum.
24
+
25
+ # [Libhydrogen documentation](https://github.com/jedisct1/libhydrogen/wiki)
26
+
27
+ The documentation is maintained in the [libhydrogen wiki](https://github.com/jedisct1/libhydrogen/wiki).
28
+
29
+ The legacy libhydrogen code (leveraging XChaCha20, SipHashX, BLAKE2SX, Curve25519) remains available in the [v0 branch](https://github.com/jedisct1/libhydrogen/tree/v0).
30
+
31
+ ## Contributors
32
+
33
+ ### Code Contributors
34
+
35
+ This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
36
+ <a href="https://github.com/jedisct1/libhydrogen/graphs/contributors"><img src="https://opencollective.com/libhydrogen/contributors.svg?width=890&button=false" /></a>
@@ -0,0 +1,18 @@
1
+ #include "hydrogen.h"
2
+
3
+ #include "impl/common.h"
4
+ #include "impl/hydrogen_p.h"
5
+
6
+ #include "impl/core.h"
7
+ #include "impl/gimli-core.h"
8
+ #include "impl/random.h"
9
+
10
+ #include "impl/hash.h"
11
+ #include "impl/kdf.h"
12
+ #include "impl/secretbox.h"
13
+
14
+ #include "impl/x25519.h"
15
+
16
+ #include "impl/kx.h"
17
+ #include "impl/pwhash.h"
18
+ #include "impl/sign.h"
@@ -0,0 +1,331 @@
1
+ #ifndef hydrogen_H
2
+ #define hydrogen_H
3
+
4
+ #include <stdbool.h>
5
+ #include <stdint.h>
6
+ #include <stdlib.h>
7
+
8
+ #ifdef __cplusplus
9
+ #ifdef __GNUC__
10
+ #pragma GCC diagnostic ignored "-Wlong-long"
11
+ #endif
12
+ extern "C" {
13
+ #endif
14
+
15
+ #if defined(__clang__) || defined(__GNUC__)
16
+ #define _hydro_attr_(X) __attribute__(X)
17
+ #else
18
+ #define _hydro_attr_(X)
19
+ #endif
20
+ #define _hydro_attr_deprecated_ _hydro_attr_((deprecated))
21
+ #define _hydro_attr_malloc_ _hydro_attr_((malloc))
22
+ #define _hydro_attr_noinline_ _hydro_attr_((noinline))
23
+ #define _hydro_attr_noreturn_ _hydro_attr_((noreturn))
24
+ #define _hydro_attr_warn_unused_result_ _hydro_attr_((warn_unused_result))
25
+ #define _hydro_attr_weak_ _hydro_attr_((weak))
26
+
27
+ #if defined(__INTEL_COMPILER) || defined(_MSC_VER)
28
+ #define _hydro_attr_aligned_(X) __declspec(align(X))
29
+ #elif defined(__clang__) || defined(__GNUC__)
30
+ #define _hydro_attr_aligned_(X) _hydro_attr_((aligned(X)))
31
+ #else
32
+ #define _hydro_attr_aligned_(X)
33
+ #endif
34
+
35
+ #define HYDRO_VERSION_MAJOR 1
36
+ #define HYDRO_VERSION_MINOR 0
37
+
38
+ int hydro_init(void);
39
+
40
+ /* ---------------- */
41
+
42
+ #define hydro_random_SEEDBYTES 32
43
+
44
+ uint32_t hydro_random_u32(void);
45
+
46
+ uint32_t hydro_random_uniform(const uint32_t upper_bound);
47
+
48
+ void hydro_random_buf(void *out, size_t out_len);
49
+
50
+ void hydro_random_buf_deterministic(void *out, size_t out_len,
51
+ const uint8_t seed[hydro_random_SEEDBYTES]);
52
+
53
+ void hydro_random_ratchet(void);
54
+
55
+ void hydro_random_reseed(void);
56
+
57
+ /* ---------------- */
58
+
59
+ #define hydro_hash_BYTES 32
60
+ #define hydro_hash_BYTES_MAX 65535
61
+ #define hydro_hash_BYTES_MIN 16
62
+ #define hydro_hash_CONTEXTBYTES 8
63
+ #define hydro_hash_KEYBYTES 32
64
+
65
+ typedef struct hydro_hash_state {
66
+ uint32_t state[12];
67
+ uint8_t buf_off;
68
+ uint8_t align[3];
69
+ } hydro_hash_state;
70
+
71
+ void hydro_hash_keygen(uint8_t key[hydro_hash_KEYBYTES]);
72
+
73
+ int hydro_hash_init(hydro_hash_state *state, const char ctx[hydro_hash_CONTEXTBYTES],
74
+ const uint8_t key[hydro_hash_KEYBYTES]);
75
+
76
+ int hydro_hash_update(hydro_hash_state *state, const void *in_, size_t in_len);
77
+
78
+ int hydro_hash_final(hydro_hash_state *state, uint8_t *out, size_t out_len);
79
+
80
+ int hydro_hash_hash(uint8_t *out, size_t out_len, const void *in_, size_t in_len,
81
+ const char ctx[hydro_hash_CONTEXTBYTES],
82
+ const uint8_t key[hydro_hash_KEYBYTES]);
83
+
84
+ /* ---------------- */
85
+
86
+ #define hydro_secretbox_CONTEXTBYTES 8
87
+ #define hydro_secretbox_HEADERBYTES (20 + 16)
88
+ #define hydro_secretbox_KEYBYTES 32
89
+ #define hydro_secretbox_PROBEBYTES 16
90
+
91
+ void hydro_secretbox_keygen(uint8_t key[hydro_secretbox_KEYBYTES]);
92
+
93
+ int hydro_secretbox_encrypt(uint8_t *c, const void *m_, size_t mlen, uint64_t msg_id,
94
+ const char ctx[hydro_secretbox_CONTEXTBYTES],
95
+ const uint8_t key[hydro_secretbox_KEYBYTES]);
96
+
97
+ int hydro_secretbox_decrypt(void *m_, const uint8_t *c, size_t clen, uint64_t msg_id,
98
+ const char ctx[hydro_secretbox_CONTEXTBYTES],
99
+ const uint8_t key[hydro_secretbox_KEYBYTES])
100
+ _hydro_attr_warn_unused_result_;
101
+
102
+ void hydro_secretbox_probe_create(uint8_t probe[hydro_secretbox_PROBEBYTES], const uint8_t *c,
103
+ size_t c_len, const char ctx[hydro_secretbox_CONTEXTBYTES],
104
+ const uint8_t key[hydro_secretbox_KEYBYTES]);
105
+
106
+ int hydro_secretbox_probe_verify(const uint8_t probe[hydro_secretbox_PROBEBYTES], const uint8_t *c,
107
+ size_t c_len, const char ctx[hydro_secretbox_CONTEXTBYTES],
108
+ const uint8_t key[hydro_secretbox_KEYBYTES])
109
+ _hydro_attr_warn_unused_result_;
110
+
111
+ /* ---------------- */
112
+
113
+ #define hydro_kdf_CONTEXTBYTES 8
114
+ #define hydro_kdf_KEYBYTES 32
115
+ #define hydro_kdf_BYTES_MAX 65535
116
+ #define hydro_kdf_BYTES_MIN 16
117
+
118
+ void hydro_kdf_keygen(uint8_t key[hydro_kdf_KEYBYTES]);
119
+
120
+ int hydro_kdf_derive_from_key(uint8_t *subkey, size_t subkey_len, uint64_t subkey_id,
121
+ const char ctx[hydro_kdf_CONTEXTBYTES],
122
+ const uint8_t key[hydro_kdf_KEYBYTES]);
123
+
124
+ /* ---------------- */
125
+
126
+ #define hydro_sign_BYTES 64
127
+ #define hydro_sign_CONTEXTBYTES 8
128
+ #define hydro_sign_PUBLICKEYBYTES 32
129
+ #define hydro_sign_SECRETKEYBYTES 64
130
+ #define hydro_sign_SEEDBYTES 32
131
+
132
+ typedef struct hydro_sign_state {
133
+ hydro_hash_state hash_st;
134
+ } hydro_sign_state;
135
+
136
+ typedef struct hydro_sign_keypair {
137
+ uint8_t pk[hydro_sign_PUBLICKEYBYTES];
138
+ uint8_t sk[hydro_sign_SECRETKEYBYTES];
139
+ } hydro_sign_keypair;
140
+
141
+ void hydro_sign_keygen(hydro_sign_keypair *kp);
142
+
143
+ void hydro_sign_keygen_deterministic(hydro_sign_keypair *kp,
144
+ const uint8_t seed[hydro_sign_SEEDBYTES]);
145
+
146
+ int hydro_sign_init(hydro_sign_state *state, const char ctx[hydro_sign_CONTEXTBYTES]);
147
+
148
+ int hydro_sign_update(hydro_sign_state *state, const void *m_, size_t mlen);
149
+
150
+ int hydro_sign_final_create(hydro_sign_state *state, uint8_t csig[hydro_sign_BYTES],
151
+ const uint8_t sk[hydro_sign_SECRETKEYBYTES]);
152
+
153
+ int hydro_sign_final_verify(hydro_sign_state *state, const uint8_t csig[hydro_sign_BYTES],
154
+ const uint8_t pk[hydro_sign_PUBLICKEYBYTES])
155
+ _hydro_attr_warn_unused_result_;
156
+
157
+ int hydro_sign_create(uint8_t csig[hydro_sign_BYTES], const void *m_, size_t mlen,
158
+ const char ctx[hydro_sign_CONTEXTBYTES],
159
+ const uint8_t sk[hydro_sign_SECRETKEYBYTES]);
160
+
161
+ int hydro_sign_verify(const uint8_t csig[hydro_sign_BYTES], const void *m_, size_t mlen,
162
+ const char ctx[hydro_sign_CONTEXTBYTES],
163
+ const uint8_t pk[hydro_sign_PUBLICKEYBYTES]) _hydro_attr_warn_unused_result_;
164
+
165
+ /* ---------------- */
166
+
167
+ #define hydro_kx_SESSIONKEYBYTES 32
168
+ #define hydro_kx_PUBLICKEYBYTES 32
169
+ #define hydro_kx_SECRETKEYBYTES 32
170
+ #define hydro_kx_PSKBYTES 32
171
+ #define hydro_kx_SEEDBYTES 32
172
+
173
+ typedef struct hydro_kx_keypair {
174
+ uint8_t pk[hydro_kx_PUBLICKEYBYTES];
175
+ uint8_t sk[hydro_kx_SECRETKEYBYTES];
176
+ } hydro_kx_keypair;
177
+
178
+ typedef struct hydro_kx_session_keypair {
179
+ uint8_t rx[hydro_kx_SESSIONKEYBYTES];
180
+ uint8_t tx[hydro_kx_SESSIONKEYBYTES];
181
+ } hydro_kx_session_keypair;
182
+
183
+ typedef struct hydro_kx_state {
184
+ hydro_kx_keypair eph_kp;
185
+ hydro_hash_state h_st;
186
+ } hydro_kx_state;
187
+
188
+ void hydro_kx_keygen(hydro_kx_keypair *static_kp);
189
+
190
+ void hydro_kx_keygen_deterministic(hydro_kx_keypair *static_kp,
191
+ const uint8_t seed[hydro_kx_SEEDBYTES]);
192
+
193
+ /* NOISE_N */
194
+
195
+ #define hydro_kx_N_PACKET1BYTES (32 + 16)
196
+
197
+ int hydro_kx_n_1(hydro_kx_session_keypair *kp, uint8_t packet1[hydro_kx_N_PACKET1BYTES],
198
+ const uint8_t psk[hydro_kx_PSKBYTES],
199
+ const uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES]);
200
+
201
+ int hydro_kx_n_2(hydro_kx_session_keypair *kp, const uint8_t packet1[hydro_kx_N_PACKET1BYTES],
202
+ const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
203
+
204
+ /* NOISE_KK */
205
+
206
+ #define hydro_kx_KK_PACKET1BYTES (32 + 16)
207
+ #define hydro_kx_KK_PACKET2BYTES (32 + 16)
208
+
209
+ int hydro_kx_kk_1(hydro_kx_state *state, uint8_t packet1[hydro_kx_KK_PACKET1BYTES],
210
+ const uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
211
+ const hydro_kx_keypair *static_kp);
212
+
213
+ int hydro_kx_kk_2(hydro_kx_session_keypair *kp, uint8_t packet2[hydro_kx_KK_PACKET2BYTES],
214
+ const uint8_t packet1[hydro_kx_KK_PACKET1BYTES],
215
+ const uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
216
+ const hydro_kx_keypair *static_kp);
217
+
218
+ int hydro_kx_kk_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
219
+ const uint8_t packet2[hydro_kx_KK_PACKET2BYTES],
220
+ const hydro_kx_keypair *static_kp);
221
+
222
+ /* NOISE_XX */
223
+
224
+ #define hydro_kx_XX_PACKET1BYTES (32 + 16)
225
+ #define hydro_kx_XX_PACKET2BYTES (32 + 32 + 16 + 16)
226
+ #define hydro_kx_XX_PACKET3BYTES (32 + 16 + 16)
227
+
228
+ int hydro_kx_xx_1(hydro_kx_state *state, uint8_t packet1[hydro_kx_XX_PACKET1BYTES],
229
+ const uint8_t psk[hydro_kx_PSKBYTES]);
230
+
231
+ int hydro_kx_xx_2(hydro_kx_state *state, uint8_t packet2[hydro_kx_XX_PACKET2BYTES],
232
+ const uint8_t packet1[hydro_kx_XX_PACKET1BYTES],
233
+ const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
234
+
235
+ int hydro_kx_xx_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
236
+ uint8_t packet3[hydro_kx_XX_PACKET3BYTES],
237
+ uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
238
+ const uint8_t packet2[hydro_kx_XX_PACKET2BYTES],
239
+ const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
240
+
241
+ int hydro_kx_xx_4(hydro_kx_state *state, hydro_kx_session_keypair *kp,
242
+ uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES],
243
+ const uint8_t packet3[hydro_kx_XX_PACKET3BYTES],
244
+ const uint8_t psk[hydro_kx_PSKBYTES]);
245
+
246
+ /* NOISE_NK */
247
+
248
+ #define hydro_kx_NK_PACKET1BYTES (32 + 16)
249
+ #define hydro_kx_NK_PACKET2BYTES (32 + 16)
250
+
251
+ int hydro_kx_nk_1(hydro_kx_state *state, uint8_t packet1[hydro_kx_NK_PACKET1BYTES],
252
+ const uint8_t psk[hydro_kx_PSKBYTES],
253
+ const uint8_t peer_static_pk[hydro_kx_PUBLICKEYBYTES]);
254
+
255
+ int hydro_kx_nk_2(hydro_kx_session_keypair *kp, uint8_t packet2[hydro_kx_NK_PACKET2BYTES],
256
+ const uint8_t packet1[hydro_kx_NK_PACKET1BYTES],
257
+ const uint8_t psk[hydro_kx_PSKBYTES], const hydro_kx_keypair *static_kp);
258
+
259
+ int hydro_kx_nk_3(hydro_kx_state *state, hydro_kx_session_keypair *kp,
260
+ const uint8_t packet2[hydro_kx_NK_PACKET2BYTES]);
261
+
262
+ /* ---------------- */
263
+
264
+ #define hydro_pwhash_CONTEXTBYTES 8
265
+ #define hydro_pwhash_MASTERKEYBYTES 32
266
+ #define hydro_pwhash_STOREDBYTES 128
267
+
268
+ void hydro_pwhash_keygen(uint8_t master_key[hydro_pwhash_MASTERKEYBYTES]);
269
+
270
+ int hydro_pwhash_deterministic(uint8_t *h, size_t h_len, const char *passwd, size_t passwd_len,
271
+ const char ctx[hydro_pwhash_CONTEXTBYTES],
272
+ const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
273
+ uint64_t opslimit, size_t memlimit, uint8_t threads);
274
+
275
+ int hydro_pwhash_create(uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd,
276
+ size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
277
+ uint64_t opslimit, size_t memlimit, uint8_t threads);
278
+
279
+ int hydro_pwhash_verify(const uint8_t stored[hydro_pwhash_STOREDBYTES], const char *passwd,
280
+ size_t passwd_len, const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
281
+ uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
282
+
283
+ int hydro_pwhash_derive_static_key(uint8_t *static_key, size_t static_key_len,
284
+ const uint8_t stored[hydro_pwhash_STOREDBYTES],
285
+ const char *passwd, size_t passwd_len,
286
+ const char ctx[hydro_pwhash_CONTEXTBYTES],
287
+ const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
288
+ uint64_t opslimit_max, size_t memlimit_max, uint8_t threads_max);
289
+
290
+ int hydro_pwhash_reencrypt(uint8_t stored[hydro_pwhash_STOREDBYTES],
291
+ const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES],
292
+ const uint8_t new_master_key[hydro_pwhash_MASTERKEYBYTES]);
293
+
294
+ int hydro_pwhash_upgrade(uint8_t stored[hydro_pwhash_STOREDBYTES],
295
+ const uint8_t master_key[hydro_pwhash_MASTERKEYBYTES], uint64_t opslimit,
296
+ size_t memlimit, uint8_t threads);
297
+
298
+ /* ---------------- */
299
+
300
+ void hydro_memzero(void *pnt, size_t len);
301
+
302
+ void hydro_increment(uint8_t *n, size_t len);
303
+
304
+ bool hydro_equal(const void *b1_, const void *b2_, size_t len);
305
+
306
+ int hydro_compare(const uint8_t *b1_, const uint8_t *b2_, size_t len);
307
+
308
+ char *hydro_bin2hex(char *hex, size_t hex_maxlen, const uint8_t *bin, size_t bin_len);
309
+
310
+ int hydro_hex2bin(uint8_t *bin, size_t bin_maxlen, const char *hex, size_t hex_len,
311
+ const char *ignore, const char **hex_end_p);
312
+
313
+ int hydro_pad(unsigned char *buf, size_t unpadded_buflen, size_t blocksize, size_t max_buflen);
314
+
315
+ int hydro_unpad(const unsigned char *buf, size_t padded_buflen, size_t blocksize);
316
+
317
+ /* ---------------- */
318
+
319
+ #define HYDRO_HWTYPE_ATMEGA328 1
320
+
321
+ #ifndef HYDRO_HWTYPE
322
+ #ifdef __AVR__
323
+ #define HYDRO_HWTYPE HYDRO_HWTYPE_ATMEGA328
324
+ #endif
325
+ #endif
326
+
327
+ #ifdef __cplusplus
328
+ }
329
+ #endif
330
+
331
+ #endif