Back to index

courier  0.68.2
testsuite.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2001-2005 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "config.h"
00007 #include      "sha1.h"
00008 #include      <stdio.h>
00009 #include      <stdlib.h>
00010 #include      <string.h>
00011 
00012 
00013 static char foo[1000001];
00014 
00015 static void sha1()
00016 {
00017 SHA1_DIGEST   digest;
00018 unsigned i, n;
00019 
00020 static char *testcases[]={"abc",
00021 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", foo};
00022 
00023        for (n=0; n<sizeof(testcases)/sizeof(testcases[0]); n++)
00024        {
00025               i=strlen(testcases[n]);
00026               sha1_digest(testcases[n], i, digest);
00027               printf( (i < 200 ? "SHA1(%s)=":
00028                      "SHA1(%-1.20s...)="), testcases[n]);
00029 
00030               for (i=0; i<20; i++)
00031               {
00032                      if (i && (i & 3) == 0)      putchar(' ');
00033                      printf("%02X", digest[i]);
00034               }
00035               printf("\n");
00036        }
00037 }
00038 
00039 static void sha256()
00040 {
00041        SHA256_DIGEST digest;
00042        unsigned i, n;
00043 
00044        static char *testcases[]={"abc",
00045                               "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
00046                               foo};
00047 
00048        for (n=0; n<sizeof(testcases)/sizeof(testcases[0]); n++)
00049        {
00050               i=strlen(testcases[n]);
00051               sha256_digest(testcases[n], i, digest);
00052               printf( (i < 200 ? "SHA256(%s)=":
00053                       "SHA256(%-1.20s...)="), testcases[n]);
00054 
00055               for (i=0; i<sizeof(digest); i++)
00056               {
00057                      if (i && (i & 3) == 0)      putchar(' ');
00058                      printf("%02X", digest[i]);
00059               }
00060               printf("\n");
00061        }
00062 }
00063 
00064 static void sha512()
00065 {
00066        SHA512_DIGEST digest;
00067        unsigned i, n;
00068 
00069        static char *testcases[]={"abc",
00070                               "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
00071                               foo};
00072 
00073        for (n=0; n<sizeof(testcases)/sizeof(testcases[0]); n++)
00074        {
00075               i=strlen(testcases[n]);
00076               sha512_digest(testcases[n], i, digest);
00077               printf( (i < 200 ? "SHA512(%s)=":
00078                       "SHA512(%-1.20s...)="), testcases[n]);
00079 
00080               for (i=0; i<sizeof(digest); i++)
00081               {
00082                      if (i && (i & 7) == 0)      putchar(' ');
00083                      printf("%02X", digest[i]);
00084               }
00085               printf("\n");
00086        }
00087 }
00088 int main()
00089 {
00090        memset(foo, 'a', 1000000);
00091        sha1();
00092        sha256();
00093        sha512();
00094        exit (0);
00095        return (0);
00096 }