-peer review
[oweals/gnunet.git] / src / include / gnunet_crypto_lib.h
index 33842fc2734f28fba032adf0c9253dacbf68bfcc..710ef31790a29a576aaef029a9df99324e3eb1b2 100644 (file)
@@ -859,15 +859,6 @@ GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
                    size_t xts_len, const void *skm, size_t skm_len, ...);
 
 
-/**
- * Create a new private key. Caller must free return value.
- *
- * @return fresh private key
- */
-struct GNUNET_CRYPTO_RsaPrivateKey *
-GNUNET_CRYPTO_rsa_key_create (void);
-
-
 /**
  * Convert a public key to a string.
  *
@@ -925,11 +916,56 @@ GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
  * @param filename name of file to use for storage
  * @return new private key, NULL on error (for example,
  *   permission denied)
+ * @deprecated use 'GNUNET_CRYPTO_rsa_key_create_start' instead
  */
 struct GNUNET_CRYPTO_RsaPrivateKey *
 GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
 
 
+/**
+ * Handle to cancel private key generation.
+ */
+struct GNUNET_CRYPTO_RsaKeyGenerationContext;
+
+
+/**
+ * Function called upon completion of 'GNUNET_CRYPTO_rsa_key_create_async'.
+ *
+ * @param cls closure
+ * @param pk NULL on error, otherwise the private key (which must be free'd by the callee)
+ * @param emsg NULL on success, otherwise an error message
+ */
+typedef void (*GNUNET_CRYPTO_RsaKeyCallback)(void *cls,
+                                            struct GNUNET_CRYPTO_RsaPrivateKey *pk,
+                                            const char *emsg);
+
+
+/**
+ * Create a new private key by reading it from a file.  If the files
+ * does not exist, create a new key and write it to the file.  If the
+ * contents of the file are invalid the old file is deleted and a
+ * fresh key is created.
+ *
+ * @param filename name of file to use for storage
+ * @param cont function to call when done (or on errors)
+ * @param cont_cls closure for 'cont'
+ * @return handle to abort operation, NULL on fatal errors (cont will not be called if NULL is returned)
+ */
+struct GNUNET_CRYPTO_RsaKeyGenerationContext *
+GNUNET_CRYPTO_rsa_key_create_start (const char *filename,
+                                   GNUNET_CRYPTO_RsaKeyCallback cont,
+                                   void *cont_cls);
+
+
+/**
+ * Abort RSA key generation.
+ *
+ * @param gc key generation context to abort
+ */
+void
+GNUNET_CRYPTO_rsa_key_create_stop (struct GNUNET_CRYPTO_RsaKeyGenerationContext *gc);
+
+
 /**
  * Setup a hostkey file for a peer given the name of the
  * configuration file (!).  This function is used so that
@@ -1049,6 +1085,17 @@ void
 GNUNET_CRYPTO_random_disable_entropy_gathering (void);
 
 
+/**
+ * Check if we are using weak random number generation.
+ *
+ * @return GNUNET_YES if weak number generation is on
+ *         (thus will return YES if 'GNUNET_CRYPTO_random_disable_entropy_gathering'
+ *          was called previously).
+ */
+int
+GNUNET_CRYPTO_random_is_weak (void);
+
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif