Add RAND_DRBG_bytes
[openssl.git] / crypto / rand / drbg_lib.c
index 5d3d0f2..5e6bdce 100644 (file)
@@ -534,6 +534,28 @@ int RAND_DRBG_generate(RAND_DRBG *drbg, unsigned char *out, size_t outlen,
     return 1;
 }
 
+/*
+ * Generates |outlen| random bytes and stores them in |out|. It will
+ * using the given |drbg| to generate the bytes.
+ *
+ * Requires that drbg->lock is already locked for write, if non-null.
+ *
+ * Returns 1 on success 0 on failure.
+ */
+int RAND_DRBG_bytes(RAND_DRBG *drbg, unsigned char *out, size_t outlen)
+{
+    unsigned char *additional = NULL;
+    size_t additional_len;
+    size_t ret;
+
+    additional_len = rand_drbg_get_additional_data(&additional, drbg->max_adinlen);
+    ret = RAND_DRBG_generate(drbg, out, outlen, 0, additional, additional_len);
+    if (additional_len != 0)
+        OPENSSL_secure_clear_free(additional, additional_len);
+
+    return ret;
+}
+
 /*
  * Set the RAND_DRBG callbacks for obtaining entropy and nonce.
  *