1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3
4pub const ARGON2_MIN_LANES: u64 = 1;
6pub const ARGON2_MAX_LANES: u64 = 0xFFFFFF;
8
9pub const ARGON2_MIN_THREADS: u64 = 1;
11pub const ARGON2_MAX_THREADS: u64 = 0xFFFFFF;
13
14pub const ARGON2_SYNC_POINTS: u64 = 4;
16
17pub const ARGON2_MIN_OUTLEN: u64 = 4;
19pub const ARGON2_MAX_OUTLEN: u64 = 0xFFFFFF;
21
22pub const ARGON2_MIN_MEMORY: u64 = 2 * ARGON2_SYNC_POINTS;
24
25const ADDRESSING_SPACE: u64 = (std::mem::size_of::<usize>() * 8) as u64;
26
27const fn min(a: u64, b: u64) -> u64 {
28 if a < b {
29 a
30 } else {
31 b
32 }
33}
34
35const ARGON2_MAX_MEMORY_BITS: u64 = min(32, ADDRESSING_SPACE - 10 - 1);
36
37pub const ARGON2_MAX_MEMORY: u64 = min(0xFFFFFFFF, 1 << ARGON2_MAX_MEMORY_BITS);
39
40pub const ARGON2_MIN_TIME: u64 = 1;
42pub const ARGON2_MAX_TIME: u64 = 0xFFFFFFFF;
44
45pub const ARGON2_MIN_PWD_LENGTH: u64 = 0;
47pub const ARGON2_MAX_PWD_LENGTH: u64 = 0xFFFFFFFF;
49
50pub const ARGON2_MIN_AD_LENGTH: u64 = 0;
52pub const ARGON2_MAX_AD_LENGTH: u64 = 0xFFFFFFFF;
54
55pub const ARGON2_MIN_SALT_LENGTH: u64 = 8;
57pub const ARGON2_MAX_SALT_LENGTH: u64 = 0xFFFFFFFF;
59
60pub const ARGON2_MIN_SECRET: u64 = 0;
62pub const ARGON2_MAX_SECRET: u64 = 0xFFFFFFFF;
64
65pub const ARGON2_DEFAULT_FLAGS: u32 = 0;
67pub const ARGON2_FLAG_CLEAR_PASSWORD: u32 = 1 << 0;
68pub const ARGON2_FLAG_CLEAR_SECRET: u32 = 1 << 1;
69
70pub type Argon2_ErrorCodes = libc::c_int;
71
72pub const ARGON2_OK: Argon2_ErrorCodes = 0;
73pub const ARGON2_OUTPUT_PTR_NULL: Argon2_ErrorCodes = -1;
74pub const ARGON2_OUTPUT_TOO_SHORT: Argon2_ErrorCodes = -2;
75pub const ARGON2_OUTPUT_TOO_LONG: Argon2_ErrorCodes = -3;
76pub const ARGON2_PWD_TOO_SHORT: Argon2_ErrorCodes = -4;
77pub const ARGON2_PWD_TOO_LONG: Argon2_ErrorCodes = -5;
78pub const ARGON2_SALT_TOO_SHORT: Argon2_ErrorCodes = -6;
79pub const ARGON2_SALT_TOO_LONG: Argon2_ErrorCodes = -7;
80pub const ARGON2_AD_TOO_SHORT: Argon2_ErrorCodes = -8;
81pub const ARGON2_AD_TOO_LONG: Argon2_ErrorCodes = -9;
82pub const ARGON2_SECRET_TOO_SHORT: Argon2_ErrorCodes = -10;
83pub const ARGON2_SECRET_TOO_LONG: Argon2_ErrorCodes = -11;
84pub const ARGON2_TIME_TOO_SMALL: Argon2_ErrorCodes = -12;
85pub const ARGON2_TIME_TOO_LARGE: Argon2_ErrorCodes = -13;
86pub const ARGON2_MEMORY_TOO_LITTLE: Argon2_ErrorCodes = -14;
87pub const ARGON2_MEMORY_TOO_MUCH: Argon2_ErrorCodes = -15;
88pub const ARGON2_LANES_TOO_FEW: Argon2_ErrorCodes = -16;
89pub const ARGON2_LANES_TOO_MANY: Argon2_ErrorCodes = -17;
90pub const ARGON2_PWD_PTR_MISMATCH: Argon2_ErrorCodes = -18;
91pub const ARGON2_SALT_PTR_MISMATCH: Argon2_ErrorCodes = -19;
92pub const ARGON2_SECRET_PTR_MISMATCH: Argon2_ErrorCodes = -20;
93pub const ARGON2_AD_PTR_MISMATCH: Argon2_ErrorCodes = -21;
94pub const ARGON2_MEMORY_ALLOCATION_ERROR: Argon2_ErrorCodes = -22;
95pub const ARGON2_FREE_MEMORY_CBK_NULL: Argon2_ErrorCodes = -23;
96pub const ARGON2_ALLOCATE_MEMORY_CBK_NULL: Argon2_ErrorCodes = -24;
97pub const ARGON2_INCORRECT_PARAMETER: Argon2_ErrorCodes = -25;
98pub const ARGON2_INCORRECT_TYPE: Argon2_ErrorCodes = -26;
99pub const ARGON2_OUT_PTR_MISMATCH: Argon2_ErrorCodes = -27;
100pub const ARGON2_THREADS_TOO_FEW: Argon2_ErrorCodes = -28;
101pub const ARGON2_THREADS_TOO_MANY: Argon2_ErrorCodes = -29;
102pub const ARGON2_MISSING_ARGS: Argon2_ErrorCodes = -30;
103pub const ARGON2_ENCODING_FAIL: Argon2_ErrorCodes = -31;
104pub const ARGON2_DECODING_FAIL: Argon2_ErrorCodes = -32;
105pub const ARGON2_THREAD_FAIL: Argon2_ErrorCodes = -33;
106pub const ARGON2_DECODING_LENGTH_FAIL: Argon2_ErrorCodes = -34;
107pub const ARGON2_VERIFY_MISMATCH: Argon2_ErrorCodes = -35;
108
109pub type allocate_fptr = ::std::option::Option<
110 unsafe extern "C" fn(memory: *mut *mut u8, bytes_to_allocate: libc::size_t) -> libc::c_int,
111>;
112
113pub type deallocate_fptr =
114 ::std::option::Option<unsafe extern "C" fn(memory: *mut u8, bytes_to_allocate: libc::size_t)>;
115
116
117 #[repr(C)]
145#[derive(Debug, Copy, Clone)]
146pub struct Argon2_Context {
147 pub out: *mut u8,
148 pub outlen: u32,
149 pub pwd: *mut u8,
150 pub pwdlen: u32,
151 pub salt: *mut u8,
152 pub saltlen: u32,
153 pub secret: *mut u8,
154 pub secretlen: u32,
155 pub ad: *mut u8,
156 pub adlen: u32,
157 pub t_cost: u32,
158 pub m_cost: u32,
159 pub lanes: u32,
160 pub threads: u32,
161 pub version: u32,
162 pub allocate_cbk: allocate_fptr,
163 pub free_cbk: deallocate_fptr,
164 pub flags: u32,
165}
166
167pub type argon2_context = Argon2_Context;
168
169pub type Argon2_type = libc::c_uint;
170pub use Argon2_type as argon2_type;
171
172pub const Argon2_d: Argon2_type = 0;
173pub const Argon2_i: Argon2_type = 1;
174pub const Argon2_id: Argon2_type = 2;
175
176pub type Argon2_version = libc::c_uint;
177pub use Argon2_version as argon2_version;
178
179pub const ARGON2_VERSION_10: Argon2_version = 0x10;
180pub const ARGON2_VERSION_13: Argon2_version = 0x13;
181pub const ARGON2_VERSION_NUMBER: Argon2_version = ARGON2_VERSION_13;
182
183extern "C" {
184 pub fn argon2_type2string(ty: argon2_type, uppercase: libc::c_int) -> *const libc::c_char;
192
193 pub fn argon2_ctx(context: *mut argon2_context, ty: argon2_type) -> libc::c_int;
199
200 pub fn argon2i_hash_encoded(
226 t_cost: u32,
227 m_cost: u32,
228 parallelism: u32,
229 pwd: *const libc::c_void,
230 pwdlen: libc::size_t,
231 salt: *const libc::c_void,
232 saltlen: libc::size_t,
233 hashlen: libc::size_t,
234 encoded: *mut libc::c_char,
235 encodedlen: libc::size_t,
236 ) -> libc::c_int;
237
238 pub fn argon2i_hash_raw(
262 t_cost: u32,
263 m_cost: u32,
264 parallelism: u32,
265 pwd: *const libc::c_void,
266 pwdlen: libc::size_t,
267 salt: *const libc::c_void,
268 saltlen: libc::size_t,
269 hash: *mut libc::c_void,
270 hashlen: libc::size_t,
271 ) -> libc::c_int;
272
273 pub fn argon2d_hash_encoded(
274 t_cost: u32,
275 m_cost: u32,
276 parallelism: u32,
277 pwd: *const libc::c_void,
278 pwdlen: libc::size_t,
279 salt: *const libc::c_void,
280 saltlen: libc::size_t,
281 hashlen: libc::size_t,
282 encoded: *mut libc::c_char,
283 encodedlen: libc::size_t,
284 ) -> libc::c_int;
285
286 pub fn argon2d_hash_raw(
287 t_cost: u32,
288 m_cost: u32,
289 parallelism: u32,
290 pwd: *const libc::c_void,
291 pwdlen: libc::size_t,
292 salt: *const libc::c_void,
293 saltlen: libc::size_t,
294 hash: *mut libc::c_void,
295 hashlen: libc::size_t,
296 ) -> libc::c_int;
297
298 pub fn argon2id_hash_encoded(
299 t_cost: u32,
300 m_cost: u32,
301 parallelism: u32,
302 pwd: *const libc::c_void,
303 pwdlen: libc::size_t,
304 salt: *const libc::c_void,
305 saltlen: libc::size_t,
306 hashlen: libc::size_t,
307 encoded: *mut libc::c_char,
308 encodedlen: libc::size_t,
309 ) -> libc::c_int;
310
311 pub fn argon2id_hash_raw(
312 t_cost: u32,
313 m_cost: u32,
314 parallelism: u32,
315 pwd: *const libc::c_void,
316 pwdlen: libc::size_t,
317 salt: *const libc::c_void,
318 saltlen: libc::size_t,
319 hash: *mut libc::c_void,
320 hashlen: libc::size_t,
321 ) -> libc::c_int;
322
323 pub fn argon2_hash(
324 t_cost: u32,
325 m_cost: u32,
326 parallelism: u32,
327 pwd: *const libc::c_void,
328 pwdlen: libc::size_t,
329 salt: *const libc::c_void,
330 saltlen: libc::size_t,
331 hash: *mut libc::c_void,
332 hashlen: libc::size_t,
333 encoded: *mut libc::c_char,
334 encodedlen: libc::size_t,
335 ty: argon2_type,
336 version: u32,
337 ) -> libc::c_int;
338
339 pub fn argon2i_verify(
349 encoded: *const libc::c_char,
350 pwd: *const libc::c_void,
351 pwdlen: libc::size_t,
352 ) -> libc::c_int;
353
354 pub fn argon2d_verify(
355 encoded: *const libc::c_char,
356 pwd: *const libc::c_void,
357 pwdlen: libc::size_t,
358 ) -> libc::c_int;
359
360 pub fn argon2id_verify(
361 encoded: *const libc::c_char,
362 pwd: *const libc::c_void,
363 pwdlen: libc::size_t,
364 ) -> libc::c_int;
365
366 pub fn argon2_verify(
367 encoded: *const libc::c_char,
368 pwd: *const libc::c_void,
369 pwdlen: libc::size_t,
370 ty: argon2_type,
371 ) -> libc::c_int;
372
373 pub fn argon2d_ctx(context: *mut argon2_context) -> libc::c_int;
381
382 pub fn argon2i_ctx(context: *mut argon2_context) -> libc::c_int;
390
391 pub fn argon2id_ctx(context: *mut argon2_context) -> libc::c_int;
400
401 pub fn argon2d_verify_ctx(
410 context: *mut argon2_context,
411 hash: *const libc::c_char,
412 ) -> libc::c_int;
413
414 pub fn argon2i_verify_ctx(
422 context: *mut argon2_context,
423 hash: *const libc::c_char,
424 ) -> libc::c_int;
425
426 pub fn argon2id_verify_ctx(
435 context: *mut argon2_context,
436 hash: *const libc::c_char,
437 ) -> libc::c_int;
438
439 pub fn argon2_verify_ctx(
440 context: *mut argon2_context,
441 hash: *const libc::c_char,
442 ty: argon2_type,
443 ) -> libc::c_int;
444
445 pub fn argon2_error_message(error_code: libc::c_int) -> *const libc::c_char;
449
450 pub fn argon2_encodedlen(
466 t_cost: u32,
467 m_cost: u32,
468 parallelism: u32,
469 saltlen: u32,
470 hashlen: u32,
471 ty: argon2_type,
472 ) -> libc::size_t;
473}