4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
22 * Use is subject to license terms.
25 #pragma ident "%Z%%M% %I% %E% SMI"
37 { "$5$saltstring", "Hello world!",
38 "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
39 { "$5$rounds=10000$saltstringsaltstring", "Hello world!",
40 "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBA"
42 { "$5$rounds=5000$toolongsaltstring", "This is just a test",
43 "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07g"
45 { "$5$rounds=1400$anotherlongsaltstring",
46 "a very much longer text to encrypt. This one even stretches"
47 " over morethan one line.",
48 "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIU"
50 { "$5$rounds=77777$short",
51 "we have a short salt string but not a short password",
52 "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0"
54 { "$5$rounds=123456$asaltof16chars..", "a short string",
55 "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2"
56 "jxPyzV/cZKmF/wJvD" },
57 { "$5$rounds=10$roundstoolow", "the minimum number is still observed",
58 "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY"
68 { "$6$saltstring", "Hello world!",
69 "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnI"
70 "FNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1" },
71 { "$6$rounds=10000$saltstringsaltstring", "Hello world!",
72 "$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3"
73 "Oeqh0sbHbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." },
74 { "$6$rounds=5000$toolongsaltstring", "This is just a test",
75 "$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxG"
76 "oNeKQzQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" },
77 { "$6$rounds=1400$anotherlongsaltstring",
78 "a very much longer text to encrypt. This one even stretches "
79 "over morethan one line.",
80 "$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/p"
81 "Qs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" },
82 { "$6$rounds=77777$short",
83 "we have a short salt string but not a short password",
84 "$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXb"
85 "kvr0gge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" },
86 { "$6$rounds=123456$asaltof16chars..", "a short string",
87 "$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ"
88 "4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" },
89 { "$6$rounds=10$roundstoolow", "the minimum number is still observed",
90 "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50Y"
91 "hH1xhLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
95 #error "One of CRYPT_SHA256 or CRYPT_SHA512 must be defined"
98 #define ntests2 (sizeof (tests2) / sizeof (tests2[0]))
101 main(int argc
, char *argv
[])
105 char ctbuffer
[CRYPT_MAXCIPHERTEXTLEN
];
106 size_t ctbufflen
= sizeof (ctbuffer
);
109 fprintf(stderr
, "CRYPT_SHA256 ");
111 fprintf(stderr
, "CRYPT_SHA512 ");
113 fprintf(stderr
, "CRYPT_MAXCIPHERTEXTLEN = %d\n",
114 CRYPT_MAXCIPHERTEXTLEN
);
115 for (cnt
= 0; cnt
< ntests2
; ++cnt
) {
117 fprintf(stderr
, "test %d (outlen=%d): ", cnt
,
118 strlen(tests2
[cnt
].expected
));
119 cp
= crypt_genhash_impl(ctbuffer
, ctbufflen
,
120 tests2
[cnt
].input
, tests2
[cnt
].salt
, NULL
);
122 if (cp
== NULL
|| (strcmp(cp
, tests2
[cnt
].expected
) != 0)) {
124 "FAILED\nE(%d): \"%s\"\nG(%d): \"%s\"\n",
125 strlen(tests2
[cnt
].expected
), tests2
[cnt
].expected
,
126 (cp
? strlen(cp
) : 0), (cp
? cp
: "NULL"));
129 fprintf(stderr
, "OK\n");
134 fprintf(stderr
, "all tests OK\n");
136 fprintf(stderr
, "%d tests failed\n", failures
);