[gnome-keyring/gnome-3-2] pkcs11: Use g_random_int_range() for pseudo-random hash iteration count



commit 71bdb5dc967ec99b3b2fe9d5994de7996b4142c5
Author: Stef Walter <stefw collabora co uk>
Date:   Mon Oct 24 11:18:41 2011 +0200

    pkcs11: Use g_random_int_range() for pseudo-random hash iteration count
    
     * Used when hashing passwords into symmetric keys
     * Previous solution was overflowing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662025

 pkcs11/gkm/gkm-data-der.c               |    2 +-
 pkcs11/secret-store/gkm-secret-binary.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
---
diff --git a/pkcs11/gkm/gkm-data-der.c b/pkcs11/gkm/gkm-data-der.c
index 8e60651..79bde94 100644
--- a/pkcs11/gkm/gkm-data-der.c
+++ b/pkcs11/gkm/gkm-data-der.c
@@ -966,7 +966,7 @@ prepare_and_encode_pkcs8_cipher (GNode *asn, const gchar *password,
 		g_return_val_if_reached (NULL);
 
 	/* Randomize some input for the password based secret */
-	iterations = 1000 + (int) (1000.0 * rand () / (RAND_MAX + 1.0));
+	iterations = g_random_int_range (1000, 4096);
 	gcry_create_nonce (salt, sizeof (salt));
 
 	/* Allocate space for the key and iv */
diff --git a/pkcs11/secret-store/gkm-secret-binary.c b/pkcs11/secret-store/gkm-secret-binary.c
index 29cd9cd..9f6569e 100644
--- a/pkcs11/secret-store/gkm-secret-binary.c
+++ b/pkcs11/secret-store/gkm-secret-binary.c
@@ -584,7 +584,7 @@ gkm_secret_binary_write (GkmSecretCollection *collection, GkmSecretData *sdata,
 	egg_buffer_init_full (&buffer, 256, g_realloc);
 
 	/* Prepare the keyring for encryption */
-	hash_iterations = 1000 + (int) (1000.0 * rand() / (RAND_MAX + 1.0));
+	hash_iterations = g_random_int_range (1000, 4096);
 	gcry_create_nonce (salt, sizeof (salt));
 
 	egg_buffer_append (&buffer, (guchar*)KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]