Add `.gitignore'.
[gnutls.git] / tests / gc.c
blob0f23dfbb4b8f21091fc0770bde40cd465e74f0b8
1 /*
2 * Copyright (C) 2004, 2005 Free Software Foundation
4 * This file is part of GNUTLS.
6 * GNUTLS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
25 #include <stdio.h>
26 #include <stdlib.h>
28 #include "utils.h"
30 #include "gc.h"
32 int
33 is_secure_mem (const void *ign)
35 return 0;
38 void
39 doit (void)
41 char digest[20];
42 int err;
44 /* XXX: We need this to fix secure memory. */
45 gnutls_global_init();
47 err = gc_init ();
48 if (err)
49 fail ("gc_init() failed: %d\n", err);
51 gc_set_allocators (malloc, malloc, is_secure_mem, realloc, free);
53 err = gc_md5 ("abcdefgh", 8, digest);
54 if (err)
55 fail ("gc_md5() failed: %d\n", err);
56 else
58 if (memcmp (digest, "\xe8\xdc\x40\x81\xb1\x34\x34\xb4"
59 "\x51\x89\xa7\x20\xb7\x7b\x68\x18", 16) == 0)
60 success ("gc_md5() OK\n");
61 else
63 hexprint (digest, 16);
64 fail ("gc_md5() failure\n");
68 err = gc_hash_buffer (GC_MD5, "abcdefgh", 8, digest);
69 if (err)
70 fail ("gc_hash_buffer(GC_MD5) failed: %d\n", err);
71 else
73 if (memcmp (digest, "\xe8\xdc\x40\x81\xb1\x34\x34\xb4"
74 "\x51\x89\xa7\x20\xb7\x7b\x68\x18", 16) == 0)
75 success ("gc_hash_buffer(GC_MD5) OK\n");
76 else
78 hexprint (digest, 16);
79 fail ("gc_hash_buffer(GC_MD5) failure\n");
83 err = gc_hash_buffer (GC_SHA1, "abcdefgh", 8, digest);
84 if (err)
85 fail ("gc_hash_buffer(GC_SHA1) failed: %d\n", err);
86 else
88 if (memcmp (digest, "\x42\x5a\xf1\x2a\x07\x43\x50\x2b"
89 "\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a",
90 20) == 0)
91 success ("gc_hash_buffer(GC_SHA1) OK\n");
92 else
94 hexprint (digest, 20);
95 fail ("gc_hash_buffer(GC_SHA1) failure\n");
99 err = gc_hmac_md5 ("keykeykey", 9, "abcdefgh", 8, digest);
100 if (err)
101 fail ("gc_hmac_md5() failed: %d\n", err);
102 else
104 if (memcmp (digest, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0"
105 "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0)
106 success ("gc_hmac_md5() OK\n");
107 else
109 hexprint (digest, 16);
110 fail ("gc_hmac_md5() failure\n");
114 err = gc_hmac_sha1 ("keykeykey", 9, "abcdefgh", 8, digest);
115 if (err)
116 fail ("gc_hmac_sha1() failed: %d\n", err);
117 else
119 if (memcmp (digest, "\x58\x93\x7a\x58\xfe\xea\x82\xf8"
120 "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa",
121 20) == 0)
122 success ("gc_hmac_sha1() OK\n");
123 else
125 hexprint (digest, 20);
126 fail ("gc_hmac_sha1() failure\n");
130 err = gc_pbkdf2_sha1 ("password", 8, "salt", 4, 4711, digest, 16);
131 if (err)
132 fail ("gc_pkcs5_pbkdf2_sha1() failed: %d\n", err);
133 else
135 if (memcmp (digest, "\x09\xb7\x85\x57\xdd\xf6\x07\x15"
136 "\x1c\x52\x34\xde\xba\x5c\xdc\x59", 16) == 0)
137 success ("gc_pkcs5_pbkdf2_sha1() OK\n");
138 else
140 hexprint (digest, 16);
141 fail ("gc_pkcs5_pbkdf2_sha1() failure\n");
145 gc_done ();