summaryrefslogtreecommitdiff
path: root/ssh-rsa.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2017-07-01 13:50:45 +0000
committerDamien Miller <djm@mindrot.org>2017-07-21 14:17:32 +1000
commit83fa3a044891887369ce8b487ce88d713a04df48 (patch)
treef5d227629414d0a30ef14141a5613ed31fd1985c /ssh-rsa.c
parent738c73dca2c99ee78c531b4cbeefc2008fe438f0 (diff)
downloadopenssh-git-83fa3a044891887369ce8b487ce88d713a04df48.tar.gz
upstream commit
remove post-SSHv1 removal dead code from rsa.c and merge the remaining bit that it still used into ssh-rsa.c; ok markus Upstream-ID: ac8a048d24dcd89594b0052ea5e3404b473bfa2f
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r--ssh-rsa.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/ssh-rsa.c b/ssh-rsa.c
index e8acc01f..f570ae6d 100644
--- a/ssh-rsa.c
+++ b/ssh-rsa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-rsa.c,v 1.61 2017/05/07 23:15:59 djm Exp $ */
+/* $OpenBSD: ssh-rsa.c,v 1.62 2017/07/01 13:50:45 djm Exp $ */
/*
* Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org>
*
@@ -78,6 +78,41 @@ 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;
+ int r;
+
+ if (key == NULL || key->rsa == NULL ||
+ sshkey_type_plain(key->type) != KEY_RSA)
+ return SSH_ERR_INVALID_ARGUMENT;
+
+ if ((ctx = BN_CTX_new()) == NULL)
+ return SSH_ERR_ALLOC_FAIL;
+ if ((aux = BN_new()) == NULL) {
+ r = SSH_ERR_ALLOC_FAIL;
+ goto out;
+ }
+ rsa = key->rsa;
+
+ 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)) {
+ r = SSH_ERR_LIBCRYPTO_ERROR;
+ goto out;
+ }
+ r = 0;
+ out:
+ BN_clear_free(aux);
+ BN_CTX_free(ctx);
+ return r;
+}
+
/* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */
int
ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp,