From 012b4861d820dfd954dcd3563b6366812a30205f Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Thu, 25 Nov 2010 18:07:25 +0100 Subject: Add ncr_public_key_export --- include/ncrypto/ncrypto.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index a09d451..c4de81e 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -73,6 +73,8 @@ struct ncr_private_key; CK_RV ncr_public_key_create (struct ncr_public_key **key, CK_KEY_TYPE type, const void *der, size_t der_size); +CK_RV ncr_public_key_export (struct ncr_public_key *key, void *dest, + size_t *dest_size_ptr); CK_RV ncr_public_key_destroy (struct ncr_public_key *key); CK_RV ncr_private_key_create (struct ncr_private_key **key, CK_KEY_TYPE type, const void *der, size_t der_size, -- cgit From 4c7d02965c0ad914068eb9edd65b5d918ffbf7be Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Thu, 25 Nov 2010 18:43:58 +0100 Subject: Add ncr_public_key_export_rsa(). --- include/ncrypto/ncrypto.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index c4de81e..9f5a3f4 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -82,10 +82,16 @@ CK_RV ncr_private_key_create (struct ncr_private_key **key, CK_KEY_TYPE type, size_t public_value_size); CK_RV ncr_private_key_destroy (struct ncr_private_key *key); + /* RSA keys */ + CK_RV ncr_public_key_create_rsa (struct ncr_public_key **key, const void *modulus, size_t modulus_size, const void *public_exponent, size_t public_exponent_size); +CK_RV ncr_public_key_export_rsa (struct ncr_public_key *key, + void *modulus, size_t *modulus_size_ptr, + void *public_exponent, + size_t *public_exponent_size_ptr); CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, const void *modulus, size_t modulus_size, const void *public_exponent, -- cgit From 6e919f9347656ba0ae390038679ac942ad6a9964 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Thu, 25 Nov 2010 23:11:03 +0100 Subject: Add private key extraction support --- include/ncrypto/ncrypto.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index 9f5a3f4..47ca5df 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -76,10 +76,14 @@ CK_RV ncr_public_key_create (struct ncr_public_key **key, CK_KEY_TYPE type, CK_RV ncr_public_key_export (struct ncr_public_key *key, void *dest, size_t *dest_size_ptr); CK_RV ncr_public_key_destroy (struct ncr_public_key *key); +/* "Sensitive" corresponds to CKA_SENSITIVE. */ CK_RV ncr_private_key_create (struct ncr_private_key **key, CK_KEY_TYPE type, - const void *der, size_t der_size, + _Bool sensitive, const void *der, size_t der_size, const void *public_value, size_t public_value_size); +CK_RV ncr_private_key_set_sensitive (struct ncr_private_key *key); +CK_RV ncr_private_key_export (struct ncr_private_key *key, void *dest, + size_t *dest_size_ptr); CK_RV ncr_private_key_destroy (struct ncr_private_key *key); /* RSA keys */ @@ -92,7 +96,7 @@ CK_RV ncr_public_key_export_rsa (struct ncr_public_key *key, void *modulus, size_t *modulus_size_ptr, void *public_exponent, size_t *public_exponent_size_ptr); -CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, +CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, _Bool sensitive, const void *modulus, size_t modulus_size, const void *public_exponent, size_t public_exponent_size, -- cgit From 6185079fd24c308530a4cebc66acc86dd7b40375 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 26 Nov 2010 00:37:52 +0100 Subject: Add ncr_private_key_export_rsa () --- include/ncrypto/ncrypto.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index 47ca5df..fe10d9f 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -110,6 +110,18 @@ CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, _Bool sensitive, size_t exponent_2_size, const void *coefficient, size_t coefficient_size); +CK_RV ncr_private_key_export_rsa (struct ncr_private_key *key, void *modulus, + size_t *modulus_size_ptr, + void *public_exponent, + size_t *public_exponent_size_ptr, + void *private_exponent, + size_t *private_exponent_size_ptr, + void *prime_1, size_t *prime_1_size_ptr, + void *prime_2, size_t *prime_2_size_ptr, + void *exponent_1, size_t *exponent_1_size_ptr, + void *exponent_2, size_t *exponent_2_size_ptr, + void *coefficient, + size_t *coefficient_size_ptr); /* Asymmetric operations */ -- cgit From e7fa04556e265d65232d6ef2afc6c0c472198011 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Fri, 26 Nov 2010 02:00:31 +0100 Subject: Pass MPIs around in arrays, not named parameters --- include/ncrypto/ncrypto.h | 70 ++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 31 deletions(-) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index fe10d9f..16d8258 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -86,42 +86,50 @@ CK_RV ncr_private_key_export (struct ncr_private_key *key, void *dest, size_t *dest_size_ptr); CK_RV ncr_private_key_destroy (struct ncr_private_key *key); + /* Multi-precision integers */ + +/* This is used to avoid e.g. 8 separate parameters for RSA private key + passing. */ +struct ncr_mpi +{ + void *data; + size_t size; +}; + /* RSA keys */ +enum + { + NCR_RSA_PUBLIC_MPI_MODULUS, + NCR_RSA_PUBLIC_MPI_PUBLIC_EXPONENT, + NCR_RSA_PUBLIC_NUM_MPIS + }; + +enum + { + NCR_RSA_PRIVATE_MPI_MODULUS, + NCR_RSA_PRIVATE_MPI_PUBLIC_EXPONENT, + NCR_RSA_PRIVATE_MPI_PRIVATE_EXPONENT, + NCR_RSA_PRIVATE_MPI_PRIME_1, + NCR_RSA_PRIVATE_MPI_PRIME_2, + NCR_RSA_PRIVATE_MPI_EXPONENT_1, + NCR_RSA_PRIVATE_MPI_EXPONENT_2, + NCR_RSA_PRIVATE_MPI_COEFFICIENT, + NCR_RSA_PRIVATE_NUM_MPIS + }; + CK_RV ncr_public_key_create_rsa (struct ncr_public_key **key, - const void *modulus, size_t modulus_size, - const void *public_exponent, - size_t public_exponent_size); + const struct ncr_mpi + mpis[static NCR_RSA_PUBLIC_NUM_MPIS]); CK_RV ncr_public_key_export_rsa (struct ncr_public_key *key, - void *modulus, size_t *modulus_size_ptr, - void *public_exponent, - size_t *public_exponent_size_ptr); + struct ncr_mpi + mpis [static NCR_RSA_PUBLIC_NUM_MPIS]); CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, _Bool sensitive, - const void *modulus, size_t modulus_size, - const void *public_exponent, - size_t public_exponent_size, - const void *private_exponent, - size_t private_exponent_size, - const void *prime_1, size_t prime_1_size, - const void *prime_2, size_t prime_2_size, - const void *exponent_1, - size_t exponent_1_size, - const void *exponent_2, - size_t exponent_2_size, - const void *coefficient, - size_t coefficient_size); -CK_RV ncr_private_key_export_rsa (struct ncr_private_key *key, void *modulus, - size_t *modulus_size_ptr, - void *public_exponent, - size_t *public_exponent_size_ptr, - void *private_exponent, - size_t *private_exponent_size_ptr, - void *prime_1, size_t *prime_1_size_ptr, - void *prime_2, size_t *prime_2_size_ptr, - void *exponent_1, size_t *exponent_1_size_ptr, - void *exponent_2, size_t *exponent_2_size_ptr, - void *coefficient, - size_t *coefficient_size_ptr); + const struct ncr_mpi + mpis[static NCR_RSA_PRIVATE_NUM_MPIS]); +CK_RV ncr_private_key_export_rsa (struct ncr_private_key *key, + struct ncr_mpi + mpis[static NCR_RSA_PRIVATE_NUM_MPIS]); /* Asymmetric operations */ -- cgit From cb0170516856f563e12d9ff79ad3333f641a2850 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Mon, 29 Nov 2010 16:38:22 +0100 Subject: Add RSA key generation --- include/ncrypto/ncrypto.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h index 16d8258..d9508bf 100644 --- a/include/ncrypto/ncrypto.h +++ b/include/ncrypto/ncrypto.h @@ -130,6 +130,11 @@ CK_RV ncr_private_key_create_rsa (struct ncr_private_key **key, _Bool sensitive, CK_RV ncr_private_key_export_rsa (struct ncr_private_key *key, struct ncr_mpi mpis[static NCR_RSA_PRIVATE_NUM_MPIS]); +CK_RV ncr_key_pair_generate_rsa (struct ncr_public_key **public_key, + struct ncr_private_key **private_key, + CK_MECHANISM_TYPE mech, _Bool sensitive, + CK_ULONG modulus_bits, + const struct ncr_mpi *public_exponent); /* Asymmetric operations */ -- cgit