summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2010-12-02 16:05:58 +0100
committerMiloslav Trmač <mitr@redhat.com>2010-12-02 16:05:58 +0100
commit73f2df61b947fc2a4352ec305e3783b5071078c5 (patch)
treefa50f33194e58c6610136e330af801fa6d9d78fa
parent24c1c8a9e044cc7fe1c5c9343c0cdaaf57da9aa6 (diff)
parent5e1bd25811ad476fee2cba5ec3ce83d20c74baf6 (diff)
downloadncrypto-73f2df61b947fc2a4352ec305e3783b5071078c5.tar.gz
ncrypto-73f2df61b947fc2a4352ec305e3783b5071078c5.tar.xz
ncrypto-73f2df61b947fc2a4352ec305e3783b5071078c5.zip
Merge branch 'local', drop openssl helper
Conflicts: lib/ncrypto_local.c
-rw-r--r--lib/ncrypto_local.c21
-rw-r--r--lib/ncrypto_nss.c19
-rw-r--r--tests/symm_ciphers.c4
-rw-r--r--tests/symm_keys.c5
-rw-r--r--tests/symm_signatures.c4
5 files changed, 33 insertions, 20 deletions
diff --git a/lib/ncrypto_local.c b/lib/ncrypto_local.c
index 5a138fc..1d761cd 100644
--- a/lib/ncrypto_local.c
+++ b/lib/ncrypto_local.c
@@ -28,34 +28,15 @@ Red Hat author: Miloslav Trmač <mitr@redhat.com> */
#include <stdbool.h>
#include <stdint.h>
+#include <stdlib.h>
#include <string.h>
#include <glib.h>
-#include <openssl/rand.h>
#include <ncrypto/ncrypto.h>
#include "internal.h"
- /* Helpers */
-
-static CK_RV
-ckr_openssl (void)
-{
- /* FIXME: better error handling? This will be replaced anyway. */
- 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 */
CK_RV
diff --git a/lib/ncrypto_nss.c b/lib/ncrypto_nss.c
index a430c3f..46716ea 100644
--- a/lib/ncrypto_nss.c
+++ b/lib/ncrypto_nss.c
@@ -114,6 +114,25 @@ ncr_close (void)
return res;
}
+ /* Random numbers */
+
+CK_RV
+ncr_get_random_bytes (void *dest, size_t size)
+{
+ CK_RV res;
+
+ g_return_val_if_fail (dest != NULL, CKR_ARGUMENTS_BAD);
+ g_return_val_if_fail (size <= INT_MAX, CKR_ARGUMENTS_BAD);
+
+ res = ensure_ncr_is_open ();
+ if (res != CKR_OK)
+ return res;
+
+ if (PK11_GenerateRandom (dest, size) != SECSuccess)
+ return CKR_GENERAL_ERROR;
+ return CKR_OK;
+}
+
/* Asymmetric keys */
struct ncr_public_key
diff --git a/tests/symm_ciphers.c b/tests/symm_ciphers.c
index 892cfed..bdc29d3 100644
--- a/tests/symm_ciphers.c
+++ b/tests/symm_ciphers.c
@@ -403,5 +403,9 @@ main (void)
res = ncr_symm_cipher_free (sess);
assert (res == CKR_OK);
+ /* Close the implicit reference, primarily to shut up valgrind. */
+ res = ncr_close ();
+ assert (res == CKR_OK);
+
return EXIT_SUCCESS;
}
diff --git a/tests/symm_keys.c b/tests/symm_keys.c
index 3f5aed0..5c64070 100644
--- a/tests/symm_keys.c
+++ b/tests/symm_keys.c
@@ -135,5 +135,10 @@ main (void)
res = ncr_symm_key_destroy (key);
assert (res == CKR_OK);
+
+ /* Close the implicit reference, primarily to shut up valgrind. */
+ res = ncr_close ();
+ assert (res == CKR_OK);
+
return EXIT_SUCCESS;
}
diff --git a/tests/symm_signatures.c b/tests/symm_signatures.c
index fa672fd..69eb8eb 100644
--- a/tests/symm_signatures.c
+++ b/tests/symm_signatures.c
@@ -361,5 +361,9 @@ main (void)
assert (res == CKR_OK);
}
+ /* Close the implicit reference, primarily to shut up valgrind. */
+ res = ncr_close ();
+ assert (res == CKR_OK);
+
return EXIT_SUCCESS;
}