test-gc-hmac-md5.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Free Software Foundation
00003  * Written by Simon Josefsson
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2, or (at your option)
00008  * any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301, USA.  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023 
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include "gc.h"
00027 
00028 int
00029 main (int argc, char *argv[])
00030 {
00031   Gc_rc rc;
00032 
00033   rc = gc_init ();
00034   if (rc != GC_OK)
00035     {
00036       printf ("gc_init() failed\n");
00037       return 1;
00038     }
00039 
00040     /* Test vectors from RFC 2104. */
00041 
00042   {
00043     char *key =
00044       "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
00045     size_t key_len = 16;
00046     char *data = "Hi There";
00047     size_t data_len = 8;
00048     char *digest =
00049       "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
00050     char out[16];
00051 
00052     /*
00053       key =         0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
00054       key_len =     16 bytes
00055       data =        "Hi There"
00056       data_len =    8  bytes
00057       digest =      0x9294727a3638bb1c13f48ef8158bfc9d
00058     */
00059 
00060     if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0)
00061       {
00062         printf ("call failure\n");
00063         return 1;
00064       }
00065 
00066     if (memcmp (digest, out, 16) != 0)
00067       {
00068         size_t i;
00069         printf ("hash 1 mismatch. expected:\n");
00070         for (i = 0; i < 16; i++)
00071           printf ("%02x ", digest[i] & 0xFF);
00072         printf ("\ncomputed:\n");
00073         for (i = 0; i < 16; i++)
00074           printf ("%02x ", out[i] & 0xFF);
00075         printf ("\n");
00076         return 1;
00077       }
00078   }
00079 
00080   gc_done ();
00081 
00082   return 0;
00083 }

Generated on Tue Aug 22 12:06:07 2006 for gsasl by  doxygen 1.4.7