Blame tests/gc.c

Packit 549fdc
/*
Packit 549fdc
 * Copyright (C) 2004-2012 Free Software Foundation, Inc.
Packit 549fdc
 *
Packit 549fdc
 * This file is part of GnuTLS.
Packit 549fdc
 *
Packit 549fdc
 * GnuTLS is free software; you can redistribute it and/or modify
Packit 549fdc
 * it under the terms of the GNU General Public License as published by
Packit 549fdc
 * the Free Software Foundation; either version 3 of the License, or
Packit 549fdc
 * (at your option) any later version.
Packit 549fdc
 *
Packit 549fdc
 * GnuTLS is distributed in the hope that it will be useful,
Packit 549fdc
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 549fdc
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 549fdc
 * GNU General Public License for more details.
Packit 549fdc
 *
Packit 549fdc
 * You should have received a copy of the GNU General Public License
Packit 549fdc
 * along with this program; if not, write to the Free Software
Packit 549fdc
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Packit 549fdc
 */
Packit 549fdc
Packit 549fdc
#ifdef HAVE_CONFIG_H
Packit 549fdc
#include <config.h>
Packit 549fdc
#endif
Packit 549fdc
Packit 549fdc
#include <stdio.h>
Packit 549fdc
#include <stdlib.h>
Packit 549fdc
#include <gnutls/gnutls.h>
Packit 549fdc
#include <gnutls/crypto.h>
Packit 549fdc
#include "utils.h"
Packit 549fdc
Packit 549fdc
#include "../lib/gnutls_int.h"
Packit 549fdc
#include "../lib/hash_int.h"
Packit 549fdc
#include "../lib/debug.h"
Packit 549fdc
Packit 549fdc
static void tls_log_func(int level, const char *str)
Packit 549fdc
{
Packit 549fdc
	fprintf(stderr, "|<%d>| %s", level, str);
Packit 549fdc
}
Packit 549fdc
Packit 549fdc
void doit(void)
Packit 549fdc
{
Packit 549fdc
	unsigned char digest[20];
Packit 549fdc
	int err;
Packit 549fdc
Packit 549fdc
	/* XXX: We need this to fix secure memory. */
Packit 549fdc
	global_init();
Packit 549fdc
	gnutls_global_set_log_function(tls_log_func);
Packit 549fdc
	if (debug)
Packit 549fdc
		gnutls_global_set_log_level(4711);
Packit 549fdc
Packit 549fdc
	err =
Packit 549fdc
	    gnutls_hmac_fast(GNUTLS_MAC_MD5, "keykeykey", 9, "abcdefgh", 8,
Packit 549fdc
			     digest);
Packit 549fdc
	if (err < 0)
Packit 549fdc
		fail("gnutls_hmac_fast(MD5) failed: %d\n", err);
Packit 549fdc
	else {
Packit 549fdc
		if (memcmp(digest, "\x3c\xb0\x9d\x83\x28\x01\xef\xc0"
Packit 549fdc
			   "\x7b\xb3\xaf\x42\x69\xe5\x93\x9a", 16) == 0) {
Packit 549fdc
			if (debug)
Packit 549fdc
				success("gnutls_hmac_fast(MD5) OK\n");
Packit 549fdc
		} else {
Packit 549fdc
			hexprint(digest, 16);
Packit 549fdc
			fail("gnutls_hmac_fast(MD5) failure\n");
Packit 549fdc
		}
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	err =
Packit 549fdc
	    gnutls_hmac_fast(GNUTLS_MAC_SHA1, "keykeykey", 9, "abcdefgh",
Packit 549fdc
			     8, digest);
Packit 549fdc
	if (err < 0)
Packit 549fdc
		fail("gnutls_hmac_fast(SHA1) failed: %d\n", err);
Packit 549fdc
	else {
Packit 549fdc
		if (memcmp(digest, "\x58\x93\x7a\x58\xfe\xea\x82\xf8"
Packit 549fdc
			   "\x0e\x64\x62\x01\x40\x2b\x2c\xed\x5d\x54\xc1\xfa",
Packit 549fdc
			   20) == 0) {
Packit 549fdc
			if (debug)
Packit 549fdc
				success("gnutls_hmac_fast(SHA1) OK\n");
Packit 549fdc
		} else {
Packit 549fdc
			hexprint(digest, 20);
Packit 549fdc
			fail("gnutls_hmac_fast(SHA1) failure\n");
Packit 549fdc
		}
Packit 549fdc
	}
Packit 549fdc
Packit 549fdc
	gnutls_global_deinit();
Packit 549fdc
}