#include #include #include char *__crypt_sha256(const char *pw, const char *salt, char *output); static const struct { char *h; char *s; char *k; } t[] = { {"$5$rounds=1234$abc0123456789$3VfDjPt05VHFn47C/ojFZ6KRPYrOjj1lLbH.dkF3bZ6", "$5$rounds=1234$abc0123456789$", "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"}, {"*", "$55$", ""}, {"$5$$3c2QQ0KjIU1OLtB29cl8Fplc2WN7X89bnoEjaR7tWu.", "$5$$", ""}, {"$5$salt$HrcUzzoef72uxM/YhTU5BAi419Fblqlq//zyM.rIOG0", "$5$salt$", ""}, {"$5$salt1234$BvcCH7hKo17/ntDgDlEwYxXx8mpvE8S57LUDZTL7XQC", "$5$salt1234$", ""}, {"$5$salt1234$R0UaMrtBbZLZnp/gkgrFvfvgaP9ttQfKe8s6270zumD", "$5$salt1234$", "a"}, {"$5$salt1234$yIGonLACDTBOAHFFhBoa70V4StnUS2PdbWDzNZrS8UC", "$5$salt1234$", "abc"}, {"$5$salt1234$1145V3OxW91Wl.LSS3pmBHvb2jV3ujiUhD7DgpoJtw9", "$5$salt1234$", "Aa@\xaa 0123456789"}, {"$5$aaaaaaaaaaaaaaaa$q.VQjybA0pKixryyW2EZyePZ/VjbS6iTBEwbRHQxpIA", "$5$aaaaaaaaaaaaaaaaaaaa$", "aaaaaaaaaaaaaaaaaaaa"}, {"$5$rounds=1000$$ZIwsx59lFMWVo3Yt6IxpZVn0IhpY8Yg4gxC21zUDBI4", "$5$rounds=1$", "a"}, {"$5$rounds=1000$$ZIwsx59lFMWVo3Yt6IxpZVn0IhpY8Yg4gxC21zUDBI4", "$5$rounds=1000$", "a"}, {"$5$rounds=1234$$i.IiuqtWmTzupHAZtfV/PB33Usz.MwGHq9BKFAEj.B3", "$5$rounds=1234$", "a"}, {"$5$rounds=1234$$i.IiuqtWmTzupHAZtfV/PB33Usz.MwGHq9BKFAEj.B3", "$5$rounds=00001234$", "a"}, /* incompatible with glibc crypt (sha crypt design bugs) */ {"*", "$5$rounds=$", ""}, {"*", "$5$rounds=1234", ""}, {"*", "$5$rounds=123x$", ""}, {"*", "$5$rounds=+1234$", ""}, {"*", "$5$rounds= 1234$", ""}, {"*", "$5$rounds=1234567890123456789012345678901234567890$", ""}, {"*", "$5$rounds= +00$", ""}, {"*", "$5$rounds=-4294965296$", ""}, /* official tests: */ {"$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5", "$5$saltstring", "Hello world!"}, {"$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2.opqey6IcA", "$5$rounds=10000$saltstringsaltstring", "Hello world!"}, {"$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8mGRcvxa5", "$5$rounds=5000$toolongsaltstring", "This is just a test"}, {"$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12oP84Bnq1", "$5$rounds=1400$anotherlongsaltstring", "a very much longer text to encrypt. This one even stretches over morethan one line."}, {"$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/", "$5$rounds=77777$short", "we have a short salt string but not a short password"}, {"$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/cZKmF/wJvD", "$5$rounds=123456$asaltof16chars..", "a short string"}, {"$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL972bIC", "$5$rounds=10$roundstoolow", "the minimum number is still observed"}, }; int main() { char a[128]; char *p; int i, err = 0; for (i = 0; i < sizeof t/sizeof *t; i++) { p = __crypt_sha256(t[i].k, t[i].s, a); if (strcmp(p, t[i].h) != 0) { printf("crypt(%s, %s) got %s want %s crypt: %s\n", t[i].k, t[i].s, p, t[i].h, crypt(t[i].k, t[i].s)); err = 1; } } return err; }