[openssh-commits] [openssh] 02/03: upstream: Ensure that D mod (P-1) and D mod (Q-1) are calculated in

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Feb 16 13:35:38 AEDT 2018


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit d2b3db2860c962927def39a52f67f1c23f7b201a
Author: jsing at openbsd.org <jsing at openbsd.org>
Date:   Wed Feb 14 16:27:24 2018 +0000

    upstream: Ensure that D mod (P-1) and D mod (Q-1) are calculated in
    
    constant time.
    
    This avoids a potential side channel timing leak.
    
    ok djm@ markus@
    
    OpenBSD-Commit-ID: 71ff3c16be03290e63d8edab8fac053d8a82968c
---
 ssh-rsa.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/ssh-rsa.c b/ssh-rsa.c
index 89e3c8c7..49e71c87 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-rsa.c,v 1.65 2018/02/07 05:17:56 jsing Exp $ */
+/* $OpenBSD: ssh-rsa.c,v 1.66 2018/02/14 16:27:24 jsing Exp $ */
 /*
  * Copyright (c) 2000, 2003 Markus Friedl <markus at openbsd.org>
  *
@@ -79,13 +79,12 @@ rsa_hash_alg_nid(int type)
 	}
 }
 
-/* calculate p-1 and q-1 */
 int
 ssh_rsa_generate_additional_parameters(struct sshkey *key)
 {
-	RSA *rsa;
 	BIGNUM *aux = NULL;
 	BN_CTX *ctx = NULL;
+	BIGNUM d;
 	int r;
 
 	if (key == NULL || key->rsa == NULL ||
@@ -98,12 +97,15 @@ ssh_rsa_generate_additional_parameters(struct sshkey *key)
 		r = SSH_ERR_ALLOC_FAIL;
 		goto out;
 	}
-	rsa = key->rsa;
+	BN_set_flags(aux, BN_FLG_CONSTTIME);
 
-	if ((BN_sub(aux, rsa->q, BN_value_one()) == 0) ||
-	    (BN_mod(rsa->dmq1, rsa->d, aux, ctx) == 0) ||
-	    (BN_sub(aux, rsa->p, BN_value_one()) == 0) ||
-	    (BN_mod(rsa->dmp1, rsa->d, aux, ctx) == 0)) {
+	BN_init(&d);
+	BN_with_flags(&d, key->rsa->d, BN_FLG_CONSTTIME);
+
+	if ((BN_sub(aux, key->rsa->q, BN_value_one()) == 0) ||
+	    (BN_mod(key->rsa->dmq1, &d, aux, ctx) == 0) ||
+	    (BN_sub(aux, key->rsa->p, BN_value_one()) == 0) ||
+	    (BN_mod(key->rsa->dmp1, &d, aux, ctx) == 0)) {
 		r = SSH_ERR_LIBCRYPTO_ERROR;
 		goto out;
 	}

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list