- implemented md5 hasher
- tested
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @file hasher_md5_test.h
|
||||
*
|
||||
* @brief Tests the md5 hasher
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <string.h>
|
||||
|
||||
#include "hasher_md5_test.h"
|
||||
|
||||
#include "../utils/allocator.h"
|
||||
|
||||
|
||||
/*
|
||||
* described in Header-File
|
||||
*/
|
||||
void test_hasher_md5(tester_t *tester)
|
||||
{
|
||||
/*
|
||||
* Test vectors from RFC1321:
|
||||
* MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
|
||||
* MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
|
||||
* MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
|
||||
* MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
|
||||
* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
|
||||
*
|
||||
* currently testing "", "abc", "abcdefghijklmnopqrstuvwxyz"
|
||||
*/
|
||||
hasher_t *hasher = hasher_create(HASH_MD5);
|
||||
u_int8_t hash_buffer[16];
|
||||
chunk_t empty, abc, abcd, hash_chunk;
|
||||
|
||||
u_int8_t hash_empty[] = {
|
||||
0xd4,0x1d,0x8c,0xd9,
|
||||
0x8f,0x00,0xb2,0x04,
|
||||
0xe9,0x80,0x09,0x98,
|
||||
0xec,0xf8,0x42,0x7e
|
||||
};
|
||||
|
||||
u_int8_t hash_abc[] = {
|
||||
0x90,0x01,0x50,0x98,
|
||||
0x3c,0xd2,0x4f,0xb0,
|
||||
0xd6,0x96,0x3f,0x7d,
|
||||
0x28,0xe1,0x7f,0x72
|
||||
};
|
||||
|
||||
u_int8_t hash_abcd[] = {
|
||||
0xc3,0xfc,0xd3,0xd7,
|
||||
0x61,0x92,0xe4,0x00,
|
||||
0x7d,0xfb,0x49,0x6c,
|
||||
0xca,0x67,0xe1,0x3b
|
||||
};
|
||||
|
||||
empty.ptr = "";
|
||||
empty.len = 0;
|
||||
abc.ptr = "abc";
|
||||
abc.len = 3;
|
||||
abcd.ptr = "abcdefghijklmnopqrstuvwxyz";
|
||||
abcd.len = strlen(abcd.ptr);
|
||||
|
||||
tester->assert_true(tester, hasher->get_block_size(hasher) == 16, "block size");
|
||||
|
||||
/* simple hashing, using empty */
|
||||
hasher->get_hash(hasher, empty, hash_buffer);
|
||||
tester->assert_false(tester, memcmp(hash_buffer, hash_empty, 16), "hash for empty");
|
||||
|
||||
/* simple hashing, using "abc" */
|
||||
hasher->get_hash(hasher, abc, hash_buffer);
|
||||
tester->assert_false(tester, memcmp(hash_buffer, hash_abc, 16), "hash for abc");
|
||||
|
||||
/* with allocation, using "abcdb..." */
|
||||
hasher->reset(hasher);
|
||||
hasher->allocate_hash(hasher, abcd, &hash_chunk);
|
||||
tester->assert_true(tester, hash_chunk.len == 16, "hash len");
|
||||
tester->assert_false(tester, memcmp(hash_chunk.ptr, hash_abcd, hash_chunk.len), "hash for abcd...");
|
||||
allocator_free(hash_chunk.ptr);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* @file hasher_md5_test.h
|
||||
*
|
||||
* @brief Tests the md5 hasher
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef HASHER_MD5_TEST_H_
|
||||
#define HASHER_MD5_TEST_H_
|
||||
|
||||
#include "../transforms/hashers/hasher.h"
|
||||
#include "../transforms/hashers/hasher_md5.h"
|
||||
#include "../utils/tester.h"
|
||||
|
||||
/**
|
||||
* @brief Test function used to test the md5-hasher functionality
|
||||
*
|
||||
* @param tester associated tester object
|
||||
*/
|
||||
void test_hasher_md5(tester_t *tester);
|
||||
|
||||
#endif /*HASHER_MD5_TEST_H_*/
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "packet_test.h"
|
||||
#include "diffie_hellman_test.h"
|
||||
#include "hasher_sha1_test.h"
|
||||
#include "hasher_md5_test.h"
|
||||
#include "hmac_test.h"
|
||||
#include "prf_plus_test.h"
|
||||
|
||||
@@ -180,10 +181,15 @@ test_t diffie_hellman_test = {test_diffie_hellman,"Diffie Hellman"};
|
||||
*/
|
||||
test_t hasher_sha1_test = {test_hasher_sha1,"SHA1 hasher"};
|
||||
|
||||
/**
|
||||
* Test for md5 hasher
|
||||
*/
|
||||
test_t hasher_md5_test = {test_hasher_md5,"MD5 hasher"};
|
||||
|
||||
/**
|
||||
* Test for hmac
|
||||
*/
|
||||
test_t hmac_test1 = {test_hmac_sha1, "HMAC-SHA1"};
|
||||
test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"};
|
||||
|
||||
/**
|
||||
* Test for prf_plus
|
||||
@@ -235,37 +241,40 @@ logger_manager_t *global_logger_manager;
|
||||
FILE * test_output = stderr;
|
||||
|
||||
test_t *all_tests[] ={
|
||||
&linked_list_test,
|
||||
&linked_list_iterator_test,
|
||||
&linked_list_insert_and_remove_test,
|
||||
&thread_pool_test,
|
||||
&job_queue_test1,
|
||||
&event_queue_test,
|
||||
&send_queue_test,
|
||||
&scheduler_test,
|
||||
&socket_test,
|
||||
&sender_test,
|
||||
&receiver_test,
|
||||
&ike_sa_id_test,
|
||||
&ike_sa_test,
|
||||
&generator_test1,
|
||||
&generator_test2,
|
||||
&parser_test1,
|
||||
&parser_test2,
|
||||
&parser_test3,
|
||||
&parser_test4,
|
||||
&parser_test5,
|
||||
&generator_test3,
|
||||
&generator_test4,
|
||||
&generator_test5,
|
||||
&generator_test6,
|
||||
&generator_test7,
|
||||
&generator_test8,
|
||||
&ike_sa_manager_test,
|
||||
&packet_test,
|
||||
&diffie_hellman_test,
|
||||
&hasher_sha1_test,
|
||||
NULL
|
||||
&linked_list_test,
|
||||
&linked_list_iterator_test,
|
||||
&linked_list_insert_and_remove_test,
|
||||
&thread_pool_test,
|
||||
&job_queue_test1,
|
||||
&event_queue_test,
|
||||
&send_queue_test,
|
||||
&scheduler_test,
|
||||
&socket_test,
|
||||
&sender_test,
|
||||
&receiver_test,
|
||||
&ike_sa_id_test,
|
||||
//&ike_sa_test,
|
||||
&generator_test1,
|
||||
&generator_test2,
|
||||
&parser_test1,
|
||||
&parser_test2,
|
||||
&parser_test3,
|
||||
&parser_test4,
|
||||
&parser_test5,
|
||||
&generator_test3,
|
||||
&generator_test4,
|
||||
&generator_test5,
|
||||
&generator_test6,
|
||||
&generator_test7,
|
||||
&generator_test8,
|
||||
//&ike_sa_manager_test,
|
||||
&packet_test,
|
||||
&diffie_hellman_test,
|
||||
&hasher_sha1_test,
|
||||
&hasher_md5_test,
|
||||
&hmac_test1,
|
||||
&prf_plus_test,
|
||||
NULL
|
||||
};
|
||||
global_logger_manager = logger_manager_create(FULL);
|
||||
|
||||
@@ -282,8 +291,8 @@ logger_manager_t *global_logger_manager;
|
||||
tester_t *tester = tester_create(test_output, FALSE);
|
||||
|
||||
|
||||
//tester->perform_tests(tester,all_tests);
|
||||
tester->perform_test(tester,&prf_plus_test);
|
||||
tester->perform_tests(tester,all_tests);
|
||||
//tester->perform_test(tester,&hasher_md5_test);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user