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 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <string.h>
00024 #include "gc.h"
00025 
00026 int
00027 main (int argc, char *argv[])
00028 {
00029   Gc_rc rc;
00030 
00031   rc = gc_init ();
00032   if (rc != GC_OK)
00033     {
00034       printf ("gc_init() failed\n");
00035       return 1;
00036     }
00037 
00038     /* Test vectors from RFC 2104. */
00039 
00040   {
00041     char *key =
00042       "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
00043     size_t key_len = 16;
00044     char *data = "Hi There";
00045     size_t data_len = 8;
00046     char *digest =
00047       "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
00048     char out[16];
00049 
00050     /*
00051       key =         0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
00052       key_len =     16 bytes
00053       data =        "Hi There"
00054       data_len =    8  bytes
00055       digest =      0x9294727a3638bb1c13f48ef8158bfc9d
00056     */
00057 
00058     if (gc_hmac_md5 (key, key_len, data, data_len, out) != 0)
00059       {
00060         printf ("call failure\n");
00061         return 1;
00062       }
00063 
00064     if (memcmp (digest, out, 16) != 0)
00065       {
00066         size_t i;
00067         printf ("hash 1 mismatch. expected:\n");
00068         for (i = 0; i < 16; i++)
00069           printf ("%02x ", digest[i] & 0xFF);
00070         printf ("\ncomputed:\n");
00071         for (i = 0; i < 16; i++)
00072           printf ("%02x ", out[i] & 0xFF);
00073         printf ("\n");
00074         return 1;
00075       }
00076   }
00077 
00078   gc_done ();
00079 
00080   return 0;
00081 }

Generated on Tue Oct 21 18:28:19 2008 for gsasl by  doxygen 1.5.6