diff options
Diffstat (limited to 'ssh-rsa.c')
-rw-r--r-- | ssh-rsa.c | 37 |
1 files changed, 36 insertions, 1 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssh-rsa.c,v 1.61 2017/05/07 23:15:59 djm Exp $ */ | 1 | /* $OpenBSD: ssh-rsa.c,v 1.62 2017/07/01 13:50:45 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> | 3 | * Copyright (c) 2000, 2003 Markus Friedl <markus@openbsd.org> |
4 | * | 4 | * |
@@ -78,6 +78,41 @@ rsa_hash_alg_nid(int type) | |||
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | /* calculate p-1 and q-1 */ | ||
82 | int | ||
83 | ssh_rsa_generate_additional_parameters(struct sshkey *key) | ||
84 | { | ||
85 | RSA *rsa; | ||
86 | BIGNUM *aux = NULL; | ||
87 | BN_CTX *ctx = NULL; | ||
88 | int r; | ||
89 | |||
90 | if (key == NULL || key->rsa == NULL || | ||
91 | sshkey_type_plain(key->type) != KEY_RSA) | ||
92 | return SSH_ERR_INVALID_ARGUMENT; | ||
93 | |||
94 | if ((ctx = BN_CTX_new()) == NULL) | ||
95 | return SSH_ERR_ALLOC_FAIL; | ||
96 | if ((aux = BN_new()) == NULL) { | ||
97 | r = SSH_ERR_ALLOC_FAIL; | ||
98 | goto out; | ||
99 | } | ||
100 | rsa = key->rsa; | ||
101 | |||
102 | if ((BN_sub(aux, rsa->q, BN_value_one()) == 0) || | ||
103 | (BN_mod(rsa->dmq1, rsa->d, aux, ctx) == 0) || | ||
104 | (BN_sub(aux, rsa->p, BN_value_one()) == 0) || | ||
105 | (BN_mod(rsa->dmp1, rsa->d, aux, ctx) == 0)) { | ||
106 | r = SSH_ERR_LIBCRYPTO_ERROR; | ||
107 | goto out; | ||
108 | } | ||
109 | r = 0; | ||
110 | out: | ||
111 | BN_clear_free(aux); | ||
112 | BN_CTX_free(ctx); | ||
113 | return r; | ||
114 | } | ||
115 | |||
81 | /* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */ | 116 | /* RSASSA-PKCS1-v1_5 (PKCS #1 v2.0 signature) with SHA1 */ |
82 | int | 117 | int |
83 | ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, | 118 | ssh_rsa_sign(const struct sshkey *key, u_char **sigp, size_t *lenp, |