Back to index

glibc  2.9
sha256c-test.c
Go to the documentation of this file.
00001 #include <crypt.h>
00002 #include <stdio.h>
00003 #include <string.h>
00004 
00005 static const struct
00006 {
00007   const char *salt;
00008   const char *input;
00009   const char *expected;
00010 } tests[] =
00011 {
00012   { "$5$saltstring", "Hello world!",
00013     "$5$saltstring$5B8vYYiY.CVt1RlTTf8KbXBH3hsxY/GNooZaBBGWEc5" },
00014   { "$5$rounds=10000$saltstringsaltstring", "Hello world!",
00015     "$5$rounds=10000$saltstringsaltst$3xv.VbSHBb41AL9AvLeujZkZRBAwqFMz2."
00016     "opqey6IcA" },
00017   { "$5$rounds=5000$toolongsaltstring", "This is just a test",
00018     "$5$rounds=5000$toolongsaltstrin$Un/5jzAHMgOGZ5.mWJpuVolil07guHPvOW8"
00019     "mGRcvxa5" },
00020   { "$5$rounds=1400$anotherlongsaltstring",
00021     "a very much longer text to encrypt.  This one even stretches over more"
00022     "than one line.",
00023     "$5$rounds=1400$anotherlongsalts$Rx.j8H.h8HjEDGomFU8bDkXm3XIUnzyxf12"
00024     "oP84Bnq1" },
00025   { "$5$rounds=77777$short",
00026     "we have a short salt string but not a short password",
00027     "$5$rounds=77777$short$JiO1O3ZpDAxGJeaDIuqCoEFysAe1mZNJRs3pw0KQRd/" },
00028   { "$5$rounds=123456$asaltof16chars..", "a short string",
00029     "$5$rounds=123456$asaltof16chars..$gP3VQ/6X7UUEW3HkBn2w1/Ptq2jxPyzV/"
00030     "cZKmF/wJvD" },
00031   { "$5$rounds=10$roundstoolow", "the minimum number is still observed",
00032     "$5$rounds=1000$roundstoolow$yfvwcWrQ8l/K0DAWyuPMDNHpIVlTQebY9l/gL97"
00033     "2bIC" },
00034 };
00035 #define ntests (sizeof (tests) / sizeof (tests[0]))
00036 
00037 
00038 
00039 static int
00040 do_test (void)
00041 {
00042   int result = 0;
00043   int i;
00044 
00045   for (i = 0; i < ntests; ++i)
00046     {
00047       char *cp = crypt (tests[i].input, tests[i].salt);
00048 
00049       if (strcmp (cp, tests[i].expected) != 0)
00050        {
00051          printf ("test %d: expected \"%s\", got \"%s\"\n",
00052                 i, tests[i].expected, cp);
00053          result = 1;
00054        }
00055     }
00056 
00057   return result;
00058 }
00059 
00060 #define TIMEOUT 6
00061 #define TEST_FUNCTION do_test ()
00062 #include "../test-skeleton.c"