summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-10-21 19:21:56 +0200
committerMiloslav Trmač <mitr@redhat.com>2010-10-21 19:21:56 +0200
commiteeee1d64aebbf2d29b322730d1bc4bee0661a07f (patch)
tree65d80c6801f6e5d37961664a0c5a18bdc40b0c39
parent9a27ed0fb407c404938dadd7d3a347515729f0bb (diff)
downloadncrypto-eeee1d64aebbf2d29b322730d1bc4bee0661a07f.tar.gz
ncrypto-eeee1d64aebbf2d29b322730d1bc4bee0661a07f.tar.xz
ncrypto-eeee1d64aebbf2d29b322730d1bc4bee0661a07f.zip
Add random data generation
-rw-r--r--include/ncrypto/ncrypto.h4
-rw-r--r--lib/ncrypto_local.c11
2 files changed, 15 insertions, 0 deletions
diff --git a/include/ncrypto/ncrypto.h b/include/ncrypto/ncrypto.h
index ada244b..b23a8c4 100644
--- a/include/ncrypto/ncrypto.h
+++ b/include/ncrypto/ncrypto.h
@@ -47,6 +47,10 @@ Red Hat author: Miloslav Trmač <mitr@redhat.com> */
CK_RV ncr_open (void);
CK_RV ncr_close (void);
+ /* Random numbers */
+
+CK_RV ncr_get_random_bytes (void *dest, size_t size);
+
/* Symmetric keys */
struct ncr_symm_key;
diff --git a/lib/ncrypto_local.c b/lib/ncrypto_local.c
index 8c65789..366963a 100644
--- a/lib/ncrypto_local.c
+++ b/lib/ncrypto_local.c
@@ -32,6 +32,7 @@ Red Hat author: Miloslav Trmač <mitr@redhat.com> */
#include <glib.h>
#include <openssl/evp.h>
+#include <openssl/rand.h>
#include <ncrypto/ncrypto.h>
@@ -44,6 +45,16 @@ ckr_openssl (void)
return CKR_GENERAL_ERROR;
}
+ /* Random numbers */
+
+CK_RV
+ncr_get_random_bytes (void *dest, size_t size)
+{
+ /* This is not strong enough, we need cryptographically strong random
+ numbers! */
+ return RAND_pseudo_bytes (dest, size) != 0 ? CKR_OK : ckr_openssl ();
+}
+
/* Symmetric keys */
struct ncr_symm_key