aboutsummaryrefslogtreecommitdiffstats
path: root/Source/charon/testcases/rsa_test.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2005-12-04 01:30:35 +0000
committerMartin Willi <martin@strongswan.org>2005-12-04 01:30:35 +0000
commit8ff8c33d1d720a227db193c2105cbdcf119e5746 (patch)
tree7de51ee9de420cf13eca9c91f4dfb70901d41e10 /Source/charon/testcases/rsa_test.c
parenta374d1ee669a6b7674f242119369770cb9e5705c (diff)
downloadstrongswan-8ff8c33d1d720a227db193c2105cbdcf119e5746.tar.bz2
strongswan-8ff8c33d1d720a227db193c2105cbdcf119e5746.tar.xz
- 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
Diffstat (limited to 'Source/charon/testcases/rsa_test.c')
-rw-r--r--Source/charon/testcases/rsa_test.c85
1 files changed, 85 insertions, 0 deletions
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 <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 "rsa_test.h"
+
+#include <daemon.h>
+#include <utils/allocator.h>
+#include <utils/logger.h>
+
+
+/*
+ * 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);
+
+}