t_crypt.c revision 1.1 1 /* $NetBSD: t_crypt.c,v 1.1 2011/12/27 00:47:23 christos Exp $ */
2
3 /*
4 * Copyright (C) 1995-1998 Eric Young (eay (at) cryptsoft.com) All rights
5 * reserved.
6 *
7 * This package is an SSL implementation written by Eric Young
8 * (eay (at) cryptsoft.com). The implementation was written so as to conform with
9 * Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as the
12 * following conditions are aheared to. The following conditions apply to
13 * all code found in this distribution, be it the RC4, RSA, lhash, DES, etc.,
14 * code; not just the SSL code. The SSL documentation included with this
15 * distribution is covered by the same copyright terms except that the holder
16 * is Tim Hudson (tjh (at) cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in the code
19 * are not to be removed. If this package is used in a product, Eric Young
20 * should be given attribution as the author of the parts of the library
21 * used. This can be in the form of a textual message at program startup or
22 * in documentation (online or textual) provided with the package.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions are
26 * met: 1. Redistributions of source code must retain the copyright notice,
27 * this list of conditions and the following disclaimer. 2. Redistributions
28 * in binary form must reproduce the above copyright notice, this list of
29 * conditions and the following disclaimer in the documentation and/or other
30 * materials provided with the distribution. 3. All advertising materials
31 * mentioning features or use of this software must display the following
32 * acknowledgement: "This product includes cryptographic software written by
33 * Eric Young (eay (at) cryptsoft.com)" The word 'cryptographic' can be left out
34 * if the rouines from the library being used are not cryptographic related
35 * :-). 4. If you include any Windows specific code (or a derivative thereof)
36 * from the apps directory (application code) you must include an
37 * acknowledgement: "This product includes software written by Tim Hudson
38 * (tjh (at) cryptsoft.com)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
43 * NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
44 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
47 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50 * SUCH DAMAGE.
51 *
52 * The licence and distribution terms for any publically available version or
53 * derivative of this code cannot be changed. i.e. this code cannot simply
54 * be copied and put under another distribution licence [including the GNU
55 * Public Licence.]
56 */
57
58 #include <atf-c.h>
59 #include <stdio.h>
60 #include <string.h>
61 #include <stdlib.h>
62 #include <unistd.h>
63
64 static const struct {
65 const char *hash;
66 const char *pw;
67 } tests[] = {
68 /* "new"-style */
69 /* 0 */ { "_J9..CCCCXBrJUJV154M", "U*U*U*U*" },
70 /* 1 */ { "_J9..CCCCXUhOBTXzaiE", "U*U***U" },
71 /* 2 */ { "_J9..CCCC4gQ.mB/PffM", "U*U***U*" },
72 /* 3 */ { "_J9..XXXXvlzQGqpPPdk", "*U*U*U*U" },
73 /* 4 */ { "_J9..XXXXsqM/YSSP..Y", "*U*U*U*U*" },
74 /* 5 */ { "_J9..XXXXVL7qJCnku0I", "*U*U*U*U*U*U*U*U" },
75 /* 6 */ { "_J9..XXXXAj8cFbP5scI", "*U*U*U*U*U*U*U*U*" },
76 /* 7 */ { "_J9..SDizh.vll5VED9g", "ab1234567" },
77 /* 8 */ { "_J9..SDizRjWQ/zePPHc", "cr1234567" },
78 /* 9 */ { "_J9..SDizxmRI1GjnQuE", "zxyDPWgydbQjgq" },
79 /* 10 */ { "_K9..SaltNrQgIYUAeoY", "726 even" },
80 /* 11 */ { "_J9..SDSD5YGyRCr4W4c", "" },
81 /* "old"-style, valid salts */
82 /* 12 */ { "CCNf8Sbh3HDfQ", "U*U*U*U*" },
83 /* 13 */ { "CCX.K.MFy4Ois", "U*U***U" },
84 /* 14 */ { "CC4rMpbg9AMZ.", "U*U***U*" },
85 /* 15 */ { "XXxzOu6maQKqQ", "*U*U*U*U" },
86 /* 16 */ { "SDbsugeBiC58A", "" },
87 /* 17 */ { "./xZjzHv5vzVE", "password" },
88 /* 18 */ { "0A2hXM1rXbYgo", "password" },
89 /* 19 */ { "A9RXdR23Y.cY6", "password" },
90 /* 20 */ { "ZziFATVXHo2.6", "password" },
91 /* 21 */ { "zZDDIZ0NOlPzw", "password" },
92 /* "old"-style, "reasonable" invalid salts, UFC-crypt behavior expected */
93 /* 22 */ { "\001\002wyd0KZo65Jo", "password" },
94 /* 23 */ { "a_C10Dk/ExaG.", "password" },
95 /* 24 */ { "~\377.5OTsRVjwLo", "password" },
96 /* The below are erroneous inputs, so NULL return is expected/required */
97 /* 25 */ { "", "" }, /* no salt */
98 /* 26 */ { " ", "" }, /* setting string is too short */
99 /* 27 */ { "a:", "" }, /* unsafe character */
100 /* 28 */ { "\na", "" }, /* unsafe character */
101 /* 29 */ { "_/......", "" }, /* setting string is too short for its type */
102 /* 30 */ { "_........", "" }, /* zero iteration count */
103 /* 31 */ { "_/!......", "" }, /* invalid character in count */
104 /* 32 */ { "_/......!", "" }, /* invalid character in salt */
105 /* 33 */ { NULL, NULL }
106 };
107
108 ATF_TC(crypt_salts);
109
110 ATF_TC_HEAD(crypt_salts, tc)
111 {
112
113 atf_tc_set_md_var(tc, "descr", "crypt(3) salt consistency checks");
114 }
115
116 ATF_TC_BODY(crypt_salts, tc)
117 {
118 for (size_t i = 0; tests[i].hash; i++) {
119 char *hash = crypt(tests[i].pw, tests[i].hash);
120 if (!hash && strlen(tests[i].hash) < 13)
121 continue; /* expected failure */
122 if (!hash || strcmp(hash, tests[i].hash))
123 ATF_CHECK_MSG(0, "Test %zu %s != %s\n",
124 i, hash, tests[i].hash);
125 }
126 }
127
128 ATF_TP_ADD_TCS(tp)
129 {
130
131 ATF_TP_ADD_TC(tp, crypt_salts);
132 return atf_no_error();
133 }
134