conformance fixes
[libc-test.git] / src / functional / crypt.c
blobc23a1f93ccf37349ee94a4b4a06f107d1e918303
1 #include <string.h>
2 #include <crypt.h>
3 #include "test.h"
5 static char *p;
7 #define T(h,s,k) p = crypt(k,s); \
8 if (strcmp(p,h)!=0) t_error("crypt(%s, \"%s\") failed: got \"%s\" want \"%s\"\n", #k, s, p, h);
10 int main()
13 /* md5 */
14 T("$1$abcd0123$9Qcg8DyviekV3tDGMZynJ1", "$1$abcd0123$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !")
15 T("$1$$qRPK7m23GJusamGpoGLby/", "$1$$", "")
16 T("$1$salt$UsdFqFVB.FsuinRDK5eE..", "$1$salt$", "")
17 T("$1$salt1234$.pylIeU8A8nhxsVrZNOP..", "$1$salt1234$", "Aa@\xaa 0123456789")
18 T("$1$aaaaaaaa$zqksdEYCs/p2VrrMTPU0x0", "$1$aaaaaaaaaaaaaaaaaaaa$", "aaaaaaaaaaaaaaaaaaaa")
19 /* blowfish */
20 T("*",
21 "$2a$00$0123456789012345678901", "")
22 T("*",
23 "$2a$08$01234567890123456789", "")
24 T("$2a$04$012345678901234567890u8auMTJmy9uQv1pCMPSGmRjXec5nzCf6",
25 "$2a$04$0123456789012345678901", "")
26 T("$2a$04$abcdefghijklmnopqrstuuEgxSMhZgdHqm5w1Iw6ZfXSn4If4J406",
27 "$2a$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40")
28 T("$2a$04$abcdefghijklmnopqrstuu8J3SjO9LQpndv9O3HW/e0PB1xKk.PJu",
29 "$2a$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789")
30 T("$2x$04$abcdefghijklmnopqrstuubUAnPDiHn0JtKfNM4q6HN1ZsdaC1D8i",
31 "$2x$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40")
32 T("$2x$04$abcdefghijklmnopqrstuuxYRr8W0rYwastFTc35iurVdXD9PtVhq",
33 "$2x$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789")
34 T("$2y$04$abcdefghijklmnopqrstuubUAnPDiHn0JtKfNM4q6HN1ZsdaC1D8i",
35 "$2y$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40")
36 T("$2y$04$abcdefghijklmnopqrstuu8J3SjO9LQpndv9O3HW/e0PB1xKk.PJu",
37 "$2y$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789")
38 /* sha256 */
39 T("$5$$3c2QQ0KjIU1OLtB29cl8Fplc2WN7X89bnoEjaR7tWu.", "$5$$", "")
40 T("$5$rounds=1234$abc0123456789$3VfDjPt05VHFn47C/ojFZ6KRPYrOjj1lLbH.dkF3bZ6", "$5$rounds=1234$abc0123456789$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !")
41 T("$5$salt1234$1145V3OxW91Wl.LSS3pmBHvb2jV3ujiUhD7DgpoJtw9", "$5$salt1234$", "Aa@\xaa 0123456789")
42 T("$5$rounds=1000$$ZIwsx59lFMWVo3Yt6IxpZVn0IhpY8Yg4gxC21zUDBI4", "$5$rounds=1$", "a")
43 T("$5$rounds=1234$$i.IiuqtWmTzupHAZtfV/PB33Usz.MwGHq9BKFAEj.B3", "$5$rounds=00001234$", "a")
44 /* incompatible with glibc crypt (sha crypt design bugs) */
45 //T("*", "$5$rounds=$", "")
46 //T("*", "$5$rounds=1234", "")
47 //T("*", "$5$rounds=123x$", "")
48 //T("*", "$5$rounds=+1234$", "")
49 //T("*", "$5$rounds= 1234$", "")
50 //T("*", "$5$rounds=1234567890123456789012345678901234567890$", "")
51 //T("*", "$5$rounds= +00$", "")
52 //T("*", "$5$rounds=-4294965296$", "")
53 /* official tests */
54 T("$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5",
55 "$5$saltstring", "Hello world!")
56 T("$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5",
57 "$5$rounds=5000$toolongsaltstring", "This is just a test")
58 T("$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1",
59 "$5$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over morethan one line.")
60 T("$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL972bIC",
61 "$5$rounds=10$roundstoolow", "the minimum number is still observed")
62 /* slow tests */
63 //T("$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA",
64 // "$5$rounds=10000$saltstringsaltstring", "Hello world!")
65 //T("$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/",
66 // "$5$rounds=77777$short", "we have a short salt string but not a short password")
67 //T("$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD",
68 // "$5$rounds=123456$asaltof16chars..", "a short string")
69 /* sha512 */
70 T("$6$$/chiBau24cE26QQVW3IfIe68Xu5.JQ4E8Ie7lcRLwqxO5cxGuBhqF2HmTL.zWJ9zjChg3yJYFXeGBQ2y3Ba1d1",
71 "$6$$", "")
72 T("$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1",
73 "$6$rounds=1234$abc0123456789$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !")
74 T("$6$salt1234$44TYByJTJkEpcbmj8XzV6H7ltUN.7FUFFWKGeph85fMuAME8f1yQnXxqPbz6gfMq7tisOjTrxg3S2DDebWewt1",
75 "$6$salt1234$", "Aa@\xaa 0123456789")
76 T("$6$rounds=1000$$hETGMQQ5sXu1md3PrmRCM4AxTgbNpYQaIhk4xQzvCiNfeogfCR9PZGSRXghUOxMAPFU2wuz/ZLafIHrHopO.60",
77 "$6$rounds=1$", "a")
78 T("$6$rounds=1234$$.9spjeVb1fINMikxgAZEpur.ZQ/Gte./HuKWm2sAZ37eK3e1.ZdfRuatKdR/H..lKQfb2AB.RtHh7xKm.FE2J.",
79 "$6$rounds=00001234$", "a")
80 /* incompatible with glibc crypt (sha crypt design bugs) */
81 //T("*", "$6$rounds=$", "")
82 //T("*", "$6$rounds=1234", "")
83 //T("*", "$6$rounds=123x$", "")
84 //T("*", "$6$rounds=+1234$", "")
85 //T("*", "$6$rounds= 1234$", "")
86 //T("*", "$6$rounds=1234567890123456789012345678901234567890$", "")
87 //T("*", "$6$rounds= +00$", "")
88 //T("*", "$6$rounds=-4294965296$", "")
89 /* official tests */
90 T("$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1",
91 "$6$saltstring", "Hello world!")
92 T("$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQzQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0",
93 "$6$rounds=5000$toolongsaltstring", "This is just a test")
94 T("$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1",
95 "$6$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over morethan one line.")
96 T("$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1xhLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX.",
97 "$6$rounds=10$roundstoolow", "the minimum number is still observed")
98 /* slow tests */
99 //T("$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sbHbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v.",
100 // "$6$rounds=10000$saltstringsaltstring", "Hello world!")
101 //T("$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0gge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0",
102 // "$6$rounds=77777$short", "we have a short salt string but not a short password")
103 //T("$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1",
104 // "$6$rounds=123456$asaltof16chars..", "a short string")
106 return t_status;