1570af302Sopenharmony_ci#include <string.h> 2570af302Sopenharmony_ci#include <crypt.h> 3570af302Sopenharmony_ci#include "test.h" 4570af302Sopenharmony_ci 5570af302Sopenharmony_cistatic char *p; 6570af302Sopenharmony_ci 7570af302Sopenharmony_ci#define T(h,s,k) p = crypt(k,s); \ 8570af302Sopenharmony_ci if (!p) p ="*"; \ 9570af302Sopenharmony_ci if (strcmp(p,h)!=0) t_error("crypt(%s, \"%s\") failed: got \"%s\" want \"%s\"\n", #k, s, p, h); 10570af302Sopenharmony_ci 11570af302Sopenharmony_ciint main() 12570af302Sopenharmony_ci{ 13570af302Sopenharmony_ci 14570af302Sopenharmony_ci/* md5 */ 15570af302Sopenharmony_ciT("$1$abcd0123$9Qcg8DyviekV3tDGMZynJ1", "$1$abcd0123$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !") 16570af302Sopenharmony_ciT("$1$$qRPK7m23GJusamGpoGLby/", "$1$$", "") 17570af302Sopenharmony_ciT("$1$salt$UsdFqFVB.FsuinRDK5eE..", "$1$salt$", "") 18570af302Sopenharmony_ciT("$1$salt1234$.pylIeU8A8nhxsVrZNOP..", "$1$salt1234$", "Aa@\xaa 0123456789") 19570af302Sopenharmony_ciT("$1$aaaaaaaa$zqksdEYCs/p2VrrMTPU0x0", "$1$aaaaaaaaaaaaaaaaaaaa$", "aaaaaaaaaaaaaaaaaaaa") 20570af302Sopenharmony_ci/* blowfish */ 21570af302Sopenharmony_ciT("*", 22570af302Sopenharmony_ci "$2a$00$0123456789012345678901", "") 23570af302Sopenharmony_ciT("*", 24570af302Sopenharmony_ci "$2a$08$01234567890123456789", "") 25570af302Sopenharmony_ciT("$2a$04$012345678901234567890u8auMTJmy9uQv1pCMPSGmRjXec5nzCf6", 26570af302Sopenharmony_ci "$2a$04$0123456789012345678901", "") 27570af302Sopenharmony_ciT("$2a$04$abcdefghijklmnopqrstuuEgxSMhZgdHqm5w1Iw6ZfXSn4If4J406", 28570af302Sopenharmony_ci "$2a$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40") 29570af302Sopenharmony_ciT("$2a$04$abcdefghijklmnopqrstuu8J3SjO9LQpndv9O3HW/e0PB1xKk.PJu", 30570af302Sopenharmony_ci "$2a$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789") 31570af302Sopenharmony_ciT("$2x$04$abcdefghijklmnopqrstuubUAnPDiHn0JtKfNM4q6HN1ZsdaC1D8i", 32570af302Sopenharmony_ci "$2x$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40") 33570af302Sopenharmony_ciT("$2x$04$abcdefghijklmnopqrstuuxYRr8W0rYwastFTc35iurVdXD9PtVhq", 34570af302Sopenharmony_ci "$2x$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789") 35570af302Sopenharmony_ciT("$2y$04$abcdefghijklmnopqrstuubUAnPDiHn0JtKfNM4q6HN1ZsdaC1D8i", 36570af302Sopenharmony_ci "$2y$04$abcdefghijklmnopqrstuv", "\xff\xff\xff\xa3\x33\x01\x40") 37570af302Sopenharmony_ciT("$2y$04$abcdefghijklmnopqrstuu8J3SjO9LQpndv9O3HW/e0PB1xKk.PJu", 38570af302Sopenharmony_ci "$2y$04$abcdefghijklmnopqrstuv", "Aa@\xaa 0123456789") 39570af302Sopenharmony_ci/* sha256 */ 40570af302Sopenharmony_ciT("$5$$3c2QQ0KjIU1OLtB29cl8Fplc2WN7X89bnoEjaR7tWu.", "$5$$", "") 41570af302Sopenharmony_ciT("$5$rounds=1234$abc0123456789$3VfDjPt05VHFn47C/ojFZ6KRPYrOjj1lLbH.dkF3bZ6", "$5$rounds=1234$abc0123456789$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !") 42570af302Sopenharmony_ciT("$5$salt1234$1145V3OxW91Wl.LSS3pmBHvb2jV3ujiUhD7DgpoJtw9", "$5$salt1234$", "Aa@\xaa 0123456789") 43570af302Sopenharmony_ciT("$5$rounds=1000$$ZIwsx59lFMWVo3Yt6IxpZVn0IhpY8Yg4gxC21zUDBI4", "$5$rounds=1$", "a") 44570af302Sopenharmony_ciT("$5$rounds=1234$$i.IiuqtWmTzupHAZtfV/PB33Usz.MwGHq9BKFAEj.B3", "$5$rounds=00001234$", "a") 45570af302Sopenharmony_ci/* incompatible with glibc crypt (sha crypt design bugs) */ 46570af302Sopenharmony_ci//T("*", "$5$rounds=$", "") 47570af302Sopenharmony_ci//T("*", "$5$rounds=1234", "") 48570af302Sopenharmony_ci//T("*", "$5$rounds=123x$", "") 49570af302Sopenharmony_ci//T("*", "$5$rounds=+1234$", "") 50570af302Sopenharmony_ci//T("*", "$5$rounds= 1234$", "") 51570af302Sopenharmony_ci//T("*", "$5$rounds=1234567890123456789012345678901234567890$", "") 52570af302Sopenharmony_ci//T("*", "$5$rounds= +00$", "") 53570af302Sopenharmony_ci//T("*", "$5$rounds=-4294965296$", "") 54570af302Sopenharmony_ci/* official tests */ 55570af302Sopenharmony_ciT("$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5", 56570af302Sopenharmony_ci "$5$saltstring", "Hello world!") 57570af302Sopenharmony_ciT("$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5", 58570af302Sopenharmony_ci "$5$rounds=5000$toolongsaltstring", "This is just a test") 59570af302Sopenharmony_ciT("$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1", 60570af302Sopenharmony_ci "$5$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over morethan one line.") 61570af302Sopenharmony_ciT("$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL972bIC", 62570af302Sopenharmony_ci "$5$rounds=10$roundstoolow", "the minimum number is still observed") 63570af302Sopenharmony_ci/* slow tests */ 64570af302Sopenharmony_ci//T("$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA", 65570af302Sopenharmony_ci// "$5$rounds=10000$saltstringsaltstring", "Hello world!") 66570af302Sopenharmony_ci//T("$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/", 67570af302Sopenharmony_ci// "$5$rounds=77777$short", "we have a short salt string but not a short password") 68570af302Sopenharmony_ci//T("$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD", 69570af302Sopenharmony_ci// "$5$rounds=123456$asaltof16chars..", "a short string") 70570af302Sopenharmony_ci/* sha512 */ 71570af302Sopenharmony_ciT("$6$$/chiBau24cE26QQVW3IfIe68Xu5.JQ4E8Ie7lcRLwqxO5cxGuBhqF2HmTL.zWJ9zjChg3yJYFXeGBQ2y3Ba1d1", 72570af302Sopenharmony_ci "$6$$", "") 73570af302Sopenharmony_ciT("$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1", 74570af302Sopenharmony_ci "$6$rounds=1234$abc0123456789$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !") 75570af302Sopenharmony_ciT("$6$salt1234$44TYByJTJkEpcbmj8XzV6H7ltUN.7FUFFWKGeph85fMuAME8f1yQnXxqPbz6gfMq7tisOjTrxg3S2DDebWewt1", 76570af302Sopenharmony_ci "$6$salt1234$", "Aa@\xaa 0123456789") 77570af302Sopenharmony_ciT("$6$rounds=1000$$hETGMQQ5sXu1md3PrmRCM4AxTgbNpYQaIhk4xQzvCiNfeogfCR9PZGSRXghUOxMAPFU2wuz/ZLafIHrHopO.60", 78570af302Sopenharmony_ci "$6$rounds=1$", "a") 79570af302Sopenharmony_ciT("$6$rounds=1234$$.9spjeVb1fINMikxgAZEpur.ZQ/Gte./HuKWm2sAZ37eK3e1.ZdfRuatKdR/H..lKQfb2AB.RtHh7xKm.FE2J.", 80570af302Sopenharmony_ci "$6$rounds=00001234$", "a") 81570af302Sopenharmony_ci/* incompatible with glibc crypt (sha crypt design bugs) */ 82570af302Sopenharmony_ci//T("*", "$6$rounds=$", "") 83570af302Sopenharmony_ci//T("*", "$6$rounds=1234", "") 84570af302Sopenharmony_ci//T("*", "$6$rounds=123x$", "") 85570af302Sopenharmony_ci//T("*", "$6$rounds=+1234$", "") 86570af302Sopenharmony_ci//T("*", "$6$rounds= 1234$", "") 87570af302Sopenharmony_ci//T("*", "$6$rounds=1234567890123456789012345678901234567890$", "") 88570af302Sopenharmony_ci//T("*", "$6$rounds= +00$", "") 89570af302Sopenharmony_ci//T("*", "$6$rounds=-4294965296$", "") 90570af302Sopenharmony_ci/* official tests */ 91570af302Sopenharmony_ciT("$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJuesI68u4OTLiBFdcbYEdFCoEOfaS35inz1", 92570af302Sopenharmony_ci "$6$saltstring", "Hello world!") 93570af302Sopenharmony_ciT("$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQzQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0", 94570af302Sopenharmony_ci "$6$rounds=5000$toolongsaltstring", "This is just a test") 95570af302Sopenharmony_ciT("$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wPvMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1", 96570af302Sopenharmony_ci "$6$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over morethan one line.") 97570af302Sopenharmony_ciT("$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1xhLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX.", 98570af302Sopenharmony_ci "$6$rounds=10$roundstoolow", "the minimum number is still observed") 99570af302Sopenharmony_ci/* slow tests */ 100570af302Sopenharmony_ci//T("$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sbHbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v.", 101570af302Sopenharmony_ci// "$6$rounds=10000$saltstringsaltstring", "Hello world!") 102570af302Sopenharmony_ci//T("$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0gge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0", 103570af302Sopenharmony_ci// "$6$rounds=77777$short", "we have a short salt string but not a short password") 104570af302Sopenharmony_ci//T("$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwcelCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1", 105570af302Sopenharmony_ci// "$6$rounds=123456$asaltof16chars..", "a short string") 106570af302Sopenharmony_ci 107570af302Sopenharmony_cireturn t_status; 108570af302Sopenharmony_ci} 109570af302Sopenharmony_ci 110