From 8ff8c33d1d720a227db193c2105cbdcf119e5746 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Sun, 4 Dec 2005 01:30:35 +0000 Subject: - implemented RSA, only signing and verifying esma_pkcs1 padded - removed gmp-helper: chunk_to_mpz is now done with gmp functions, prime generation in prime-pool - added prime-pool (needs priority fix) - proof of concept RSA authentication - mpz uses LEAK_DETECTIVE - configuration-manager supports rsa keys --- Source/charon/testcases/rsa_test.c | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Source/charon/testcases/rsa_test.c (limited to 'Source/charon/testcases/rsa_test.c') diff --git a/Source/charon/testcases/rsa_test.c b/Source/charon/testcases/rsa_test.c new file mode 100644 index 000000000..37f349558 --- /dev/null +++ b/Source/charon/testcases/rsa_test.c @@ -0,0 +1,85 @@ +/** + * @file rsa_test.h + * + * @brief Tests for the hasher_t classes. + * + */ + +/* + * 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 . + * + * 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 + +#include "rsa_test.h" + +#include +#include +#include + + +/* + * described in Header-File + */ +void test_rsa(tester_t *tester) +{ + rsa_private_key_t *private_key; + rsa_public_key_t *public_key; + chunk_t data, signature, private_key_chunk, public_key_chunk; + logger_t *logger; + status_t status; + u_int8_t test_data[] = { + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + 0x01,0x02,0x03,0x04, + }; + data.ptr = test_data; + data.len = sizeof(test_data); + + logger = charon->logger_manager->create_logger(charon->logger_manager, TESTER, NULL); + logger->enable_level(logger, FULL); + + private_key = rsa_private_key_create(); + + private_key->generate_key(private_key, 1024); + + status = private_key->build_emsa_pkcs1_signature(private_key, HASH_MD5, data, &signature); + tester->assert_true(tester, status == SUCCESS, "build emsa_pkcs1_signature"); + + public_key = private_key->get_public_key(private_key); + + status = public_key->verify_emsa_pkcs1_signature(public_key, data, signature); + tester->assert_true(tester, status == SUCCESS, "verify emsa_pkcs1_signature"); + + public_key->get_key(public_key, &public_key_chunk); + private_key->get_key(private_key, &private_key_chunk); + + logger->log_chunk(logger, RAW, "Public Key", &public_key_chunk); + logger->log_chunk(logger, RAW, "Private Key", &private_key_chunk); + + + allocator_free(public_key_chunk.ptr); + allocator_free(private_key_chunk.ptr); + allocator_free(signature.ptr); + + private_key->destroy(private_key); + public_key->destroy(public_key); + +} -- cgit v1.2.3