[gnome-keyring] egg: Fix issue generating PKCS#12 symkey from password
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring] egg: Fix issue generating PKCS#12 symkey from password
- Date: Mon, 12 Sep 2011 08:15:00 +0000 (UTC)
commit dc959e935eb8e25b123d58bfec8ac0ab87dc4a2f
Author: Stef Walter <stefw collabora co uk>
Date: Mon Sep 12 10:13:20 2011 +0200
egg: Fix issue generating PKCS#12 symkey from password
* If the key needed was longer than the hash size we would
generate the incorrect key.
* Right align the calculated number correctly in the buffer
egg/egg-symkey.c | 9 +++++++--
1 files changed, 7 insertions(+), 2 deletions(-)
---
diff --git a/egg/egg-symkey.c b/egg/egg-symkey.c
index a69100f..45b0fe6 100644
--- a/egg/egg-symkey.c
+++ b/egg/egg-symkey.c
@@ -305,7 +305,8 @@ generate_pkcs12 (int hash_algo, int type, const gchar *utf8_password,
gsize n_hash, i;
gunichar unich;
gcry_error_t gcry;
-
+ gsize length;
+
num_b1 = num_ij = NULL;
n_hash = gcry_md_get_algo_dlen (hash_algo);
@@ -405,7 +406,11 @@ generate_pkcs12 (int hash_algo, int type, const gchar *utf8_password,
g_return_val_if_fail (gcry == 0, FALSE);
gcry_mpi_add (num_ij, num_ij, num_b1);
gcry_mpi_clear_highbit (num_ij, 64 * 8);
- gcry = gcry_mpi_print (GCRYMPI_FMT_USG, buf_i + i, 64, NULL, num_ij);
+ /* We take special care to right align the number in the buffer */
+ gcry = gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &length, num_ij);
+ g_return_val_if_fail (gcry == 0 && length <= 64, FALSE);
+ memset (buf_i + i, 0, 64 - length);
+ gcry = gcry_mpi_print (GCRYMPI_FMT_USG, buf_i + i + (64 - length), 64, NULL, num_ij);
g_return_val_if_fail (gcry == 0, FALSE);
gcry_mpi_release (num_ij);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]