summaryrefslogtreecommitdiff
path: root/source3/tests/crypttest.c
blob: c9133f40bee9650f0cd2cc041f73beba4c94cfd3 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif

#include <sys/types.h>

#ifdef HAVE_STRING_H
#include <string.h>
#endif

#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif

main()
{
	char passwd[9];
	char salt[9];
	char c_out1[256];
	char c_out2[256];

	char expected_out[14];

	strcpy(expected_out, "12yJ.Of/NQ.Pk");
	strcpy(passwd, "12345678");
	strcpy(salt, "12345678");
	
	strcpy(c_out1, crypt(passwd, salt));
	salt[2] = '\0';
	strcpy(c_out2, crypt(passwd, salt));

	/*
	 * If the non-trucated salt fails but the
	 * truncated salt succeeds then exit 1.
	 */

	if((strcmp(c_out1, expected_out) != 0) && 
		(strcmp(c_out2, expected_out) == 0))
		exit(1);

#ifdef HAVE_BIGCRYPT
	/*
	 * Try the same with bigcrypt...
	 */

	{
		char big_passwd[17];
		char big_salt[17];
		char big_c_out1[256];
		char big_c_out2[256];
		char big_expected_out[27];

		strcpy(big_passwd, "1234567812345678");
		strcpy(big_salt, "1234567812345678");
		strcpy(big_expected_out, "12yJ.Of/NQ.PklfyCuHi/rwM");

		strcpy(big_c_out1, bigcrypt(big_passwd, big_salt));
		big_salt[2] = '\0';
		strcpy(big_c_out2, bigcrypt(big_passwd, big_salt));

		/*
		 * If the non-trucated salt fails but the
		 * truncated salt succeeds then exit 1.
		 */

		if((strcmp(big_c_out1, big_expected_out) != 0) && 
			(strcmp(big_c_out2, big_expected_out) == 0))
			exit(1);

	}
#endif

	exit(0);
}