aboutsummaryrefslogtreecommitdiffstats
path: root/argon2/test_supported.c
blob: 4c40ee656fde0aa2e34657cb17438f2441973694 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* See LICENSE file for copyright and license details. */
#include "../common.h"
#ifndef TEST

#include <libar2.h>


int
librecrypt__argon2__test_supported(const char *phrase, size_t len, int text, const char *settings, size_t prefix, size_t *len_out)
{
	uintmax_t hashsize;
	int r;

	/* We don't care about password content, arbitrary binary is supported */
	(void) phrase;
	(void) text;

#define RANGE(MIN, MAX) (uintmax_t)(MIN), (uintmax_t)(MAX)
#define BASE64 librecrypt_common_rfc4848s4_decoding_lut_, argon2__PAD, argon2__STRICT_PAD

	/* Validate string format and parameters */
	r = librecrypt_check_settings_(settings, prefix,
		"$%*$%sm=%p,t=%p,p=%p$%b$%^h",
		"v=16$", "v=19$", "", NULL,
		RANGE(LIBAR2_MIN_M_COST, LIBAR2_MAX_M_COST),
		RANGE(LIBAR2_MIN_T_COST, LIBAR2_MAX_T_COST),
		RANGE(LIBAR2_MIN_LANES, LIBAR2_MAX_LANES),
		RANGE(LIBAR2_MIN_SALTLEN, LIBAR2_MAX_SALTLEN), BASE64,
		&hashsize, RANGE(LIBAR2_MIN_HASHLEN, LIBAR2_MAX_HASHLEN), BASE64);
	if (!r)
		return 0;

	/* Return hash size */
	if (!hashsize)
		hashsize = argon2__HASH_SIZE;
	*len_out = (size_t)hashsize;

	/* Check password size */
#if SIZE_MAX > UINT32_MAX
	return len <= UINT32_MAX;
#else
	(void) len;
	return 1;
#endif
}


#else


CONST int
main(void)
{
	SET_UP_ALARM();

	return 0;
}


#endif
/* TODO test */