2005-11-17 17:22:08 +00:00
|
|
|
/**
|
|
|
|
* @file diffie_hellman_test.c
|
|
|
|
*
|
2005-11-29 07:32:33 +00:00
|
|
|
* @brief Tests for the diffie_hellman_t class.
|
2005-11-17 17:22:08 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "diffie_hellman_test.h"
|
|
|
|
|
|
|
|
#include "../transforms/diffie_hellman.h"
|
|
|
|
|
2005-11-23 09:22:25 +00:00
|
|
|
#include <globals.h>
|
|
|
|
#include <utils/logger_manager.h>
|
|
|
|
#include <utils/allocator.h>
|
2005-11-23 09:57:18 +00:00
|
|
|
#include <encoding/payloads/transform_substructure.h>
|
2005-11-17 17:22:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* described in Header-File
|
|
|
|
*/
|
|
|
|
void test_diffie_hellman(tester_t *tester)
|
|
|
|
{
|
2005-11-18 10:18:45 +00:00
|
|
|
diffie_hellman_t *my_diffie_hellman, *other_diffie_hellman;
|
2005-11-17 17:22:08 +00:00
|
|
|
logger_t *logger;
|
2005-11-18 10:18:45 +00:00
|
|
|
chunk_t my_public_value, other_public_value;
|
|
|
|
chunk_t my_secret, other_secret;
|
2005-11-17 17:22:08 +00:00
|
|
|
|
|
|
|
logger = global_logger_manager->create_logger(global_logger_manager,TESTER,"Diffie Hellman");
|
|
|
|
|
|
|
|
|
2005-11-18 10:18:45 +00:00
|
|
|
my_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
|
|
|
|
tester->assert_true(tester,(my_diffie_hellman != NULL), "create call check");
|
2005-11-17 17:22:08 +00:00
|
|
|
|
2005-11-18 10:18:45 +00:00
|
|
|
other_diffie_hellman = diffie_hellman_create(MODP_1024_BIT);
|
|
|
|
tester->assert_true(tester,(other_diffie_hellman != NULL), "create call check");
|
2005-11-17 17:22:08 +00:00
|
|
|
|
2005-11-29 07:15:52 +00:00
|
|
|
my_diffie_hellman->get_my_public_value(my_diffie_hellman,&my_public_value);
|
2005-11-18 10:18:45 +00:00
|
|
|
logger->log_chunk(logger,RAW,"My public value",&my_public_value);
|
|
|
|
|
2005-11-29 07:15:52 +00:00
|
|
|
other_diffie_hellman->get_my_public_value(other_diffie_hellman,&other_public_value);
|
2005-11-18 10:18:45 +00:00
|
|
|
logger->log_chunk(logger,RAW,"Other public value",&other_public_value);
|
|
|
|
|
2005-11-28 20:29:47 +00:00
|
|
|
my_diffie_hellman->set_other_public_value(my_diffie_hellman,other_public_value);
|
|
|
|
other_diffie_hellman->set_other_public_value(other_diffie_hellman,my_public_value);
|
2005-11-17 17:22:08 +00:00
|
|
|
|
2005-11-18 10:18:45 +00:00
|
|
|
allocator_free(my_public_value.ptr);
|
|
|
|
allocator_free(other_public_value.ptr);
|
|
|
|
|
|
|
|
tester->assert_true(tester,( my_diffie_hellman->get_shared_secret(my_diffie_hellman,&my_secret) == SUCCESS), "get_shared_secret call check");
|
|
|
|
logger->log_chunk(logger,RAW,"My shared secret",&my_secret);
|
2005-11-17 17:22:08 +00:00
|
|
|
|
2005-11-18 10:18:45 +00:00
|
|
|
tester->assert_true(tester,( other_diffie_hellman->get_shared_secret(other_diffie_hellman,&other_secret) == SUCCESS), "get_shared_secret call check");
|
|
|
|
logger->log_chunk(logger,RAW,"Other shared secret",&other_secret);
|
|
|
|
|
|
|
|
tester->assert_true(tester,( memcmp(my_secret.ptr,other_secret.ptr,other_secret.len) == 0), "shared secret same value check");
|
|
|
|
|
|
|
|
allocator_free(my_secret.ptr);
|
|
|
|
allocator_free(other_secret.ptr);
|
2005-11-17 17:22:08 +00:00
|
|
|
|
2005-11-28 20:29:47 +00:00
|
|
|
my_diffie_hellman->destroy(my_diffie_hellman);
|
|
|
|
other_diffie_hellman->destroy(other_diffie_hellman);
|
2005-11-17 17:22:08 +00:00
|
|
|
global_logger_manager->destroy_logger(global_logger_manager,logger);
|
|
|
|
}
|