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