]> git.ipfire.org Git - thirdparty/openssl.git/blobdiff - crypto/rand/drbg_lib.c
Add RAND_DRBG_bytes
[thirdparty/openssl.git] / crypto / rand / drbg_lib.c
index 5d3d0f2fd718fe92ae6e7ae9a8f8afd43ae1ea27..5e6bdceb1ed77c45fad3f7c6e4171c74650655aa 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.
  *