gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, master, updated. gnutls_2_11_6-24-gd8e2f83


From: Nikos Mavrogiannopoulos
Subject: [SCM] GNU gnutls branch, master, updated. gnutls_2_11_6-24-gd8e2f83
Date: Thu, 16 Dec 2010 16:12:58 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=d8e2f838bfb81141e7f44cbd2f7adcc756f26044

The branch, master has been updated
       via  d8e2f838bfb81141e7f44cbd2f7adcc756f26044 (commit)
       via  e0e3e4324d753041aba8dfe70fc7b755cba2616d (commit)
      from  9cad5d0a442bedaec3ffd672a5f304de80797605 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d8e2f838bfb81141e7f44cbd2f7adcc756f26044
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Thu Dec 16 17:06:45 2010 +0100

    Added gnutls_pubkey_import_privkey(), that will copy the public key from a 
gnutls_privkey_t structure.

commit e0e3e4324d753041aba8dfe70fc7b755cba2616d
Author: Nikos Mavrogiannopoulos <address@hidden>
Date:   Wed Dec 15 14:19:14 2010 +0100

    Do not export the non-existant symbols gnutls_pkcs11_privkey_sign_hash and 
gnutls_privkey_sign_hash.

-----------------------------------------------------------------------

Summary of changes:
 NEWS                           |    2 +
 lib/abstract_int.h             |    9 ++++
 lib/gnutls_privkey.c           |   90 ++++++++++++++++++++++++++++++++++++++++
 lib/gnutls_pubkey.c            |   28 ++++++++++++
 lib/includes/gnutls/abstract.h |   10 +++-
 lib/libgnutls.map              |    3 +-
 6 files changed, 137 insertions(+), 5 deletions(-)
 create mode 100644 lib/abstract_int.h

diff --git a/NEWS b/NEWS
index 29c7ecf..c3ee12d 100644
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,8 @@ gnutls_openpgp_privkey_sign_data2: ADDED
 gnutls_x509_privkey_sign_data2: ADDED
 gnutls_openpgp_crt_verify_hash: ADDED
 gnutls_openpgp_privkey_sign_hash: REMOVED
+gnutls_pkcs11_privkey_sign_hash: REMOVED
+gnutls_privkey_sign_hash: REMOVED
 gnutls_x509_privkey_sign_hash: DEPRECATED
 gnutls_psk_netconf_derive_key: DEPRECATED
 gnutls_session_set_finished_function: DEPRECATED
diff --git a/lib/abstract_int.h b/lib/abstract_int.h
new file mode 100644
index 0000000..70fc880
--- /dev/null
+++ b/lib/abstract_int.h
@@ -0,0 +1,9 @@
+#ifndef _ABSTRACT_INT_H
+# define _ABSTRACT_INT_H
+
+#include <gnutls/abstract.h>
+
+int _gnutls_privkey_get_public_mpis (gnutls_privkey_t key, 
+  bigint_t * params, int *params_size);
+  
+#endif
diff --git a/lib/gnutls_privkey.c b/lib/gnutls_privkey.c
index 86e45ed..4dbd85f 100644
--- a/lib/gnutls_privkey.c
+++ b/lib/gnutls_privkey.c
@@ -35,6 +35,7 @@
 #include <openpgp/openpgp_int.h>
 #include <openpgp/gnutls_openpgp.h>
 #include <gnutls_sig.h>
+#include <abstract_int.h>
 
 struct gnutls_privkey_st
 {
@@ -103,6 +104,95 @@ gnutls_privkey_get_pk_algorithm (gnutls_privkey_t key, 
unsigned int *bits)
 
 }
 
+static int privkey_to_pubkey(gnutls_pk_algorithm_t pk, 
+  const bigint_t * params, int params_size,
+  bigint_t *new_params, int* new_params_size)
+{
+  int ret, i;
+
+  switch(pk) {
+    case GNUTLS_PK_RSA:
+      if (*new_params_size < RSA_PUBLIC_PARAMS || params_size < 
RSA_PRIVATE_PARAMS)
+        {
+          gnutls_assert ();
+          return GNUTLS_E_INVALID_REQUEST;
+        }
+ 
+      new_params[0] = _gnutls_mpi_copy(params[0]);
+      new_params[1] = _gnutls_mpi_copy(params[1]);
+      
+      *new_params_size = RSA_PUBLIC_PARAMS;
+      
+      if (new_params[0] == NULL || new_params[1] == NULL)
+        {
+          gnutls_assert();
+          ret = GNUTLS_E_MEMORY_ERROR;
+          goto cleanup;
+        }
+        
+      break;
+    case GNUTLS_PK_DSA:
+      if (*new_params_size < DSA_PUBLIC_PARAMS || params_size < 
DSA_PRIVATE_PARAMS)
+        {
+          gnutls_assert ();
+          return GNUTLS_E_INVALID_REQUEST;
+        }
+ 
+      new_params[0] = _gnutls_mpi_copy(params[0]);
+      new_params[1] = _gnutls_mpi_copy(params[1]);
+      new_params[2] = _gnutls_mpi_copy(params[2]);
+      new_params[3] = _gnutls_mpi_copy(params[3]);
+
+      *new_params_size = DSA_PUBLIC_PARAMS;
+      
+      if (new_params[0] == NULL || new_params[1] == NULL || 
+        new_params[2] == NULL || new_params[3] == NULL)
+        {
+          gnutls_assert();
+          ret = GNUTLS_E_MEMORY_ERROR;
+          goto cleanup;
+        }
+        
+      break;
+    default:
+      gnutls_assert();
+      return GNUTLS_E_INVALID_REQUEST;
+  }
+  
+  return 0;
+cleanup:
+  for (i=0;i<*new_params_size;i++)
+    _gnutls_mpi_release(new_params[i]);
+  return ret;
+}
+  
+
+/* Returns the public key of the private key (if possible)
+ */
+int _gnutls_privkey_get_public_mpis (gnutls_privkey_t key, 
+  bigint_t * params, int *params_size)
+{
+  int ret;
+  
+  switch (key->type)
+    {
+    case GNUTLS_PRIVKEY_X509:
+      ret = privkey_to_pubkey( gnutls_privkey_get_pk_algorithm(key, NULL),
+        key->key.x509->params, key->key.x509->params_size, 
+        params, params_size);
+      if (ret < 0)
+        {
+          gnutls_assert();
+          return ret;
+        }
+    default:
+      gnutls_assert ();
+      return GNUTLS_E_INVALID_REQUEST;
+    }
+  
+  return 0;
+}
+
 /**
  * gnutls_privkey_init:
  * @key: The structure to be initialized
diff --git a/lib/gnutls_pubkey.c b/lib/gnutls_pubkey.c
index 7169aec..113d5a0 100644
--- a/lib/gnutls_pubkey.c
+++ b/lib/gnutls_pubkey.c
@@ -37,6 +37,7 @@
 #include <gnutls_num.h>
 #include <x509/common.h>
 #include <x509_b64.h>
+#include <abstract_int.h>
 
 #define PK_PEM_HEADER "PUBLIC KEY"
 
@@ -188,6 +189,33 @@ gnutls_pubkey_import_x509 (gnutls_pubkey_t key, 
gnutls_x509_crt_t crt,
 }
 
 /**
+ * gnutls_pubkey_import_privkey:
+ * @key: The public key
+ * @pkey: The private key
+ * @usage: GNUTLS_KEY_* key usage flags.
+ * @flags: should be zero
+ *
+ * This function will import the given public key to the abstract
+ * #gnutls_pubkey_t structure.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS is returned, otherwise a
+ *   negative error value.
+ **/
+int
+gnutls_pubkey_import_privkey (gnutls_pubkey_t key, gnutls_privkey_t pkey,
+                          unsigned int usage, unsigned int flags)
+{
+  key->pk_algorithm = gnutls_privkey_get_pk_algorithm (pkey, &key->bits);
+
+  key->key_usage = usage;
+
+  key->params_size = sizeof (key->params) / sizeof (key->params[0]);
+
+  return _gnutls_privkey_get_public_mpis (pkey, key->params,
+    &key->params_size);
+}
+
+/**
  * gnutls_pubkey_get_preferred_hash_algorithm:
  * @key: Holds the certificate
  * @hash: The result of the call with the hash algorithm used for signature
diff --git a/lib/includes/gnutls/abstract.h b/lib/includes/gnutls/abstract.h
index 2e68632..5fcbc3c 100644
--- a/lib/includes/gnutls/abstract.h
+++ b/lib/includes/gnutls/abstract.h
@@ -12,6 +12,9 @@
 struct gnutls_pubkey_st;
 typedef struct gnutls_pubkey_st *gnutls_pubkey_t;
 
+struct gnutls_privkey_st;
+typedef struct gnutls_privkey_st *gnutls_privkey_t;
+
 int gnutls_pubkey_init (gnutls_pubkey_t * key);
 void gnutls_pubkey_deinit (gnutls_pubkey_t key);
 int gnutls_pubkey_get_pk_algorithm (gnutls_pubkey_t key, unsigned int *bits);
@@ -24,6 +27,10 @@ int gnutls_pubkey_import_openpgp (gnutls_pubkey_t pkey,
                                  gnutls_openpgp_crt_t crt,
                                  gnutls_openpgp_keyid_t keyid,
                                  unsigned int flags);
+int
+gnutls_pubkey_import_privkey (gnutls_pubkey_t key, gnutls_privkey_t pkey,
+                          unsigned int usage, unsigned int flags);
+
 
 int gnutls_pubkey_get_preferred_hash_algorithm (gnutls_pubkey_t key,
                                                gnutls_digest_algorithm_t *
@@ -78,9 +85,6 @@ gnutls_pubkey_get_verify_algorithm (gnutls_pubkey_t key,
 
 /* Private key operations */
 
-struct gnutls_privkey_st;
-typedef struct gnutls_privkey_st *gnutls_privkey_t;
-
 int gnutls_privkey_init (gnutls_privkey_t * key);
 void gnutls_privkey_deinit (gnutls_privkey_t key);
 int gnutls_privkey_get_pk_algorithm (gnutls_privkey_t key,
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 2a1b869..4ad0ab3 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -630,7 +630,6 @@ GNUTLS_2_12
        gnutls_pkcs11_privkey_get_info;
        gnutls_pkcs11_privkey_import_url;
        gnutls_pkcs11_privkey_sign_data;
-       gnutls_pkcs11_privkey_sign_hash;
        gnutls_pkcs11_privkey_decrypt_data;
        gnutls_pkcs11_obj_export;
        gnutls_pkcs11_type_get_name;
@@ -643,7 +642,6 @@ GNUTLS_2_12
        gnutls_privkey_import_x509;
        gnutls_privkey_import_openpgp;
        gnutls_privkey_sign_data;
-       gnutls_privkey_sign_hash;
        gnutls_privkey_decrypt_data;
        gnutls_pkcs11_privkey_export_url;
        gnutls_x509_crq_privkey_sign;
@@ -700,6 +698,7 @@ GNUTLS_2_12
        gnutls_openpgp_crt_verify_hash;
        gnutls_x509_privkey_sign_data2;
        gnutls_pkcs11_privkey_sign_hash2;
+       gnutls_pubkey_import_privkey;
 } GNUTLS_2_10;
 
 GNUTLS_PRIVATE {


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]