1#if defined(HAVE_UNISTD_H)
2#include <unistd.h>
3#endif
4
5#include <sys/types.h>
6
7#ifdef HAVE_STRING_H
8#include <string.h>
9#endif
10
11#ifdef HAVE_STRINGS_H
12#include <strings.h>
13#endif
14
15main()
16{
17	char passwd[9];
18	char salt[9];
19	char c_out1[256];
20	char c_out2[256];
21
22	char expected_out[14];
23
24	strcpy(expected_out, "12yJ.Of/NQ.Pk");
25	strcpy(passwd, "12345678");
26	strcpy(salt, "12345678");
27
28	strcpy(c_out1, crypt(passwd, salt));
29	salt[2] = '\0';
30	strcpy(c_out2, crypt(passwd, salt));
31
32	/*
33	 * If the non-trucated salt fails but the
34	 * truncated salt succeeds then exit 1.
35	 */
36
37	if((strcmp(c_out1, expected_out) != 0) &&
38		(strcmp(c_out2, expected_out) == 0))
39		exit(1);
40
41#ifdef HAVE_BIGCRYPT
42	/*
43	 * Try the same with bigcrypt...
44	 */
45
46	{
47		char big_passwd[17];
48		char big_salt[17];
49		char big_c_out1[256];
50		char big_c_out2[256];
51		char big_expected_out[27];
52
53		strcpy(big_passwd, "1234567812345678");
54		strcpy(big_salt, "1234567812345678");
55		strcpy(big_expected_out, "12yJ.Of/NQ.PklfyCuHi/rwM");
56
57		strcpy(big_c_out1, bigcrypt(big_passwd, big_salt));
58		big_salt[2] = '\0';
59		strcpy(big_c_out2, bigcrypt(big_passwd, big_salt));
60
61		/*
62		 * If the non-trucated salt fails but the
63		 * truncated salt succeeds then exit 1.
64		 */
65
66		if((strcmp(big_c_out1, big_expected_out) != 0) &&
67			(strcmp(big_c_out2, big_expected_out) == 0))
68			exit(1);
69
70	}
71#endif
72
73	exit(0);
74}
75