Back to index

glibc  2.9
sha512c-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   { "$6$saltstring", "Hello world!",
00013     "$6$saltstring$svn8UoSVapNtMuq1ukKS4tPQd8iKwSMHWjl/O817G3uBnIFNjnQJu"
00014     "esI68u4OTLiBFdcbYEdFCoEOfaS35inz1" },
00015   { "$6$rounds=10000$saltstringsaltstring", "Hello world!",
00016     "$6$rounds=10000$saltstringsaltst$OW1/O6BYHV6BcXZu8QVeXbDWra3Oeqh0sb"
00017     "HbbMCVNSnCM/UrjmM0Dp8vOuZeHBy/YTBmSK6H9qs/y3RnOaw5v." },
00018   { "$6$rounds=5000$toolongsaltstring", "This is just a test",
00019     "$6$rounds=5000$toolongsaltstrin$lQ8jolhgVRVhY4b5pZKaysCLi0QBxGoNeKQ"
00020     "zQ3glMhwllF7oGDZxUhx1yxdYcz/e1JSbq3y6JMxxl8audkUEm0" },
00021   { "$6$rounds=1400$anotherlongsaltstring",
00022     "a very much longer text to encrypt.  This one even stretches over more"
00023     "than one line.",
00024     "$6$rounds=1400$anotherlongsalts$POfYwTEok97VWcjxIiSOjiykti.o/pQs.wP"
00025     "vMxQ6Fm7I6IoYN3CmLs66x9t0oSwbtEW7o7UmJEiDwGqd8p4ur1" },
00026   { "$6$rounds=77777$short",
00027     "we have a short salt string but not a short password",
00028     "$6$rounds=77777$short$WuQyW2YR.hBNpjjRhpYD/ifIw05xdfeEyQoMxIXbkvr0g"
00029     "ge1a1x3yRULJ5CCaUeOxFmtlcGZelFl5CxtgfiAc0" },
00030   { "$6$rounds=123456$asaltof16chars..", "a short string",
00031     "$6$rounds=123456$asaltof16chars..$BtCwjqMJGx5hrJhZywWvt0RLE8uZ4oPwc"
00032     "elCjmw2kSYu.Ec6ycULevoBK25fs2xXgMNrCzIMVcgEJAstJeonj1" },
00033   { "$6$rounds=10$roundstoolow", "the minimum number is still observed",
00034     "$6$rounds=1000$roundstoolow$kUMsbe306n21p9R.FRkW3IGn.S9NPN0x50YhH1x"
00035     "hLsPuWGsUSklZt58jaTfF4ZEQpyUNGc0dqbpBYYBaHHrsX." },
00036 };
00037 #define ntests (sizeof (tests) / sizeof (tests[0]))
00038 
00039 
00040 static int
00041 do_test (void)
00042 {
00043   int result = 0;
00044   int i;
00045 
00046   for (i = 0; i < ntests; ++i)
00047     {
00048       char *cp = crypt (tests[i].input, tests[i].salt);
00049 
00050       if (strcmp (cp, tests[i].expected) != 0)
00051        {
00052          printf ("test %d: expected \"%s\", got \"%s\"\n",
00053                 i, tests[i].expected, cp);
00054          result = 1;
00055        }
00056     }
00057 
00058   return result;
00059 }
00060 
00061 #define TIMEOUT 6
00062 #define TEST_FUNCTION do_test ()
00063 #include "../test-skeleton.c"