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