All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: ell@lists.01.org
Subject: [PATCH 2/4] pkcs5: Memzero copies of secrets
Date: Tue, 19 Mar 2019 01:48:41 +0100	[thread overview]
Message-ID: <20190319004843.13451-2-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <20190319004843.13451-1-andrew.zaborowski@intel.com>

[-- Attachment #1: Type: text/plain, Size: 1849 bytes --]

Those functions are used, among others, for decrypting private keys and
are passed the private key passphrases so make sure those are being
cleared.
---
 ell/pkcs5.c | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/ell/pkcs5.c b/ell/pkcs5.c
index 9fac479..bd7db90 100644
--- a/ell/pkcs5.c
+++ b/ell/pkcs5.c
@@ -89,11 +89,11 @@ LIB_EXPORT bool l_pkcs5_pbkdf1(enum l_checksum_type type, const char *password,
 
 	l_checksum_free(checksum);
 
-	if (iter_count)
-		return false;
+	if (!iter_count)
+		memcpy(out_dk, t, dk_len);
 
-	memcpy(out_dk, t, dk_len);
-	return true;
+	explicit_bzero(t, sizeof(t));
+	return !iter_count;
 }
 
 /* RFC8018 section 5.2 */
@@ -399,14 +399,13 @@ static struct l_cipher *pkcs5_cipher_from_pbes2_params(
 		return NULL;
 
 	cipher = l_cipher_new(enc_scheme->cipher_type, derived_key, key_len);
-	if (!cipher)
-		return NULL;
-
-	if (l_cipher_set_iv(cipher, params, enc_scheme->iv_size))
-		return cipher;
+	if (cipher && !l_cipher_set_iv(cipher, params, enc_scheme->iv_size)) {
+		l_cipher_free(cipher);
+		cipher = NULL;
+	}
 
-	l_cipher_free(cipher);
-	return NULL;
+	explicit_bzero(derived_key, 16);
+	return cipher;
 }
 
 struct l_cipher *pkcs5_cipher_from_alg_id(const uint8_t *id_asn1,
@@ -474,12 +473,11 @@ struct l_cipher *pkcs5_cipher_from_alg_id(const uint8_t *id_asn1,
 		return NULL;
 
 	cipher = l_cipher_new(pbes1_scheme->cipher_type, derived_key + 0, 8);
-	if (!cipher)
-		return NULL;
-
-	if (l_cipher_set_iv(cipher, derived_key + 8, 8))
-		return cipher;
+	if (cipher && !l_cipher_set_iv(cipher, derived_key + 8, 8)) {
+		l_cipher_free(cipher);
+		cipher = NULL;
+	}
 
-	l_cipher_free(cipher);
-	return NULL;
+	explicit_bzero(derived_key, 16);
+	return cipher;
 }
-- 
2.19.1


  reply	other threads:[~2019-03-19  0:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-19  0:48 [PATCH 1/4] ecc: Clear point coordinates, use explicit_bzero Andrew Zaborowski
2019-03-19  0:48 ` Andrew Zaborowski [this message]
2019-03-19  0:48 ` [PATCH 3/4] settings: Clear values in unescape_value on error Andrew Zaborowski
2019-03-19  0:48 ` [PATCH 4/4] all: Replace uses of memset with explicit_bzero Andrew Zaborowski
2019-03-19 19:19 ` [PATCH 1/4] ecc: Clear point coordinates, use explicit_bzero Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190319004843.13451-2-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.