]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
added gnutls_key_generate() to API.
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 13 Mar 2011 17:07:52 +0000 (18:07 +0100)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sun, 13 Mar 2011 17:07:52 +0000 (18:07 +0100)
lib/crypto-api.c
lib/ext_session_ticket.c
lib/includes/gnutls/gnutls.h.in

index b5f6cc52bbc90b8508dfb4d585e5d993f5e7240d..f7f200c2f8aaea56623304932db4826683d721b0 100644 (file)
@@ -28,6 +28,7 @@
 #include <gnutls_cipher_int.h>
 #include <gnutls_datum.h>
 #include <gnutls/crypto.h>
+#include <random.h>
 #include <crypto.h>
 
 /**
@@ -457,3 +458,40 @@ gnutls_hash_fast (gnutls_digest_algorithm_t algorithm,
 {
   return _gnutls_hash_fast (algorithm, text, textlen, digest);
 }
+
+/**
+ * gnutls_key_generate:
+ * @key: is a pointer to a #gnutls_datum_t which will contain a newly
+ * created key.
+ * @key_size: The number of bytes of the key.
+ *
+ * Generates a random key of @key_bytes size.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, or an
+ * error code.
+ *
+ * Since: 3.0.0
+ **/
+int
+gnutls_key_generate (gnutls_datum_t * key, unsigned int key_size)
+{
+  int ret;
+
+  key->size = key_size;
+  key->data = gnutls_malloc (key->size);
+  if (!key->data)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ret = _gnutls_rnd (GNUTLS_RND_RANDOM, key->data, key->size);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      _gnutls_free_datum (key);
+      return ret;
+    }
+
+  return 0;
+}
index f2c36ade768e80304db65b322cc428cbaa4acbf4..92a2c9380889e29b3d4df983754ed9cd9e665cfb 100644 (file)
@@ -480,25 +480,7 @@ error:
 int
 gnutls_session_ticket_key_generate (gnutls_datum_t * key)
 {
-  int ret;
-
-  key->size = SESSION_KEY_SIZE;
-  key->data = gnutls_malloc (key->size);
-  if (!key->data)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  ret = _gnutls_rnd (GNUTLS_RND_RANDOM, key->data, key->size);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      _gnutls_free_datum (key);
-      return ret;
-    }
-
-  return 0;
+  return gnutls_key_generate(key, SESSION_KEY_SIZE);
 }
 
 /**
index 7e70a33fe0d5b867c64ef988d2bbf8bd6a70d2b7..5933f4d4c7be9d537e7d1a24f9179cf5b35107a1 100644 (file)
@@ -847,6 +847,8 @@ extern "C"
   int gnutls_session_ticket_enable_server (gnutls_session_t session,
                                            const gnutls_datum_t * key);
 
+  int gnutls_key_generate (gnutls_datum_t * key, unsigned int key_size);
+
 /* if you just want some defaults, use the following.
  */
   int gnutls_priority_init (gnutls_priority_t * priority_cache,
@@ -1711,6 +1713,7 @@ extern "C"
 #define GNUTLS_E_CRYPTODEV_DEVICE_ERROR -212
 
 #define GNUTLS_E_CHANNEL_BINDING_NOT_AVAILABLE -213
+#define GNUTLS_E_BAD_COOKIE -214
 
 /* PKCS11 related */
 #define GNUTLS_E_PKCS11_ERROR -300