Skip to content

Commit 560aa14

Browse files
committed
Revert "Pass key structure to sshkey_ec_validate_*"
This reverts commit dca62f3. kex_ecdh_dec_key_group uses it without a sshkey_ecdsa_pk structure.
1 parent 88d850e commit 560aa14

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

ssh-ecdsa.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ ssh_ecdsa_deserialize_public(const char *ktype, struct sshbuf *b,
198198
ecdsa_pk->key.q = ecdsa_pk->data;
199199
ecdsa_pk->key.qlen = ecdsa_qlen;
200200
memcpy(ecdsa_pk->key.q, ecdsa_q, ecdsa_qlen);
201-
if (sshkey_ec_validate_public(ecdsa_pk) != 0) {
201+
if (sshkey_ec_validate_public(key->ecdsa_nid, ecdsa_q,
202+
ecdsa_qlen) != 0) {
202203
r = SSH_ERR_KEY_INVALID_EC_VALUE;
203204
goto out;
204205
}
@@ -244,7 +245,8 @@ ssh_ecdsa_deserialize_private(const char *ktype, struct sshbuf *b,
244245
ecdsa_sk->key.x = ecdsa_sk->data;
245246
ecdsa_sk->key.xlen = ecdsa_xlen;
246247
memcpy(ecdsa_sk->key.x, ecdsa_x, ecdsa_xlen);
247-
if ((r = sshkey_ec_validate_private(ecdsa_sk)) != 0)
248+
if ((r = sshkey_ec_validate_private(ecdsa_sk->key.curve,
249+
ecdsa_sk->key.x, ecdsa_sk->key.xlen)) != 0)
248250
goto out;
249251
/* success */
250252
key->ecdsa_sk = ecdsa_sk;

sshkey.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,33 +2568,29 @@ bn_less(const u_char *a, size_t alen, const u_char *b, size_t blen, u_int carry)
25682568
}
25692569

25702570
int
2571-
sshkey_ec_validate_public(struct sshkey_ecdsa_pk *ecdsa_pk)
2571+
sshkey_ec_validate_public(int nid, const u_char *q, size_t qlen)
25722572
{
25732573
const br_ec_impl *ec;
2574-
int curve;
2575-
const u_char *q, *n;
2576-
size_t qlen, nlen, glen;
2574+
const u_char *n;
2575+
size_t nlen, glen;
25772576
size_t xoff, xlen, yoff, ylen;
25782577
u_char one[] = {1}, tmp[BR_EC_KBUF_PUB_MAX_SIZE];
25792578

2580-
curve = ecdsa_pk->key.curve;
2581-
q = ecdsa_pk->key.q;
2582-
qlen = ecdsa_pk->key.qlen;
25832579
ec = br_ec_get_default();
2584-
if ((ec->supported_curves & 1 << curve) == 0)
2580+
if ((ec->supported_curves & 1 << nid) == 0)
25852581
return SSH_ERR_LIBCRYPTO_ERROR;
25862582

2587-
if (curve == BR_EC_curve25519)
2583+
if (nid == BR_EC_curve25519)
25882584
return qlen == 32 ? 0 : SSH_ERR_KEY_INVALID_EC_VALUE;
25892585

2590-
ec->generator(curve, &glen);
2591-
n = ec->order(curve, &nlen);
2586+
ec->generator(nid, &glen);
2587+
n = ec->order(nid, &nlen);
25922588

25932589
/* We must check that the public key has the same size as
25942590
* the generator, otherwise behavior of mul() below is
25952591
* undefined. */
25962592
if (qlen > sizeof(tmp) || qlen != glen ||
2597-
(xoff = ec->xoff(curve, &xlen)) != 1 ||
2593+
(xoff = ec->xoff(nid, &xlen)) != 1 ||
25982594
qlen != 1 + 2 * xlen || q[0] != 4)
25992595
return SSH_ERR_KEY_INVALID_EC_VALUE;
26002596
yoff = xoff + xlen;
@@ -2618,26 +2614,24 @@ sshkey_ec_validate_public(struct sshkey_ecdsa_pk *ecdsa_pk)
26182614
/* Attempt a multiplication to verify that the point is
26192615
* actually on the curve. */
26202616
memcpy(tmp, q, qlen);
2621-
if (ec->mul(tmp, qlen, one, sizeof(one), curve) != 1)
2617+
if (ec->mul(tmp, qlen, one, sizeof(one), nid) != 1)
26222618
return SSH_ERR_KEY_INVALID_EC_VALUE;
26232619

26242620
return 0;
26252621
}
26262622

26272623
int
2628-
sshkey_ec_validate_private(struct sshkey_ecdsa_sk *ecdsa_sk)
2624+
sshkey_ec_validate_private(int nid, const u_char *x, size_t xlen)
26292625
{
26302626
const br_ec_impl *ec;
2631-
const u_char *x, *n;
2632-
size_t xlen, nlen;
2627+
const u_char *n;
2628+
size_t nlen;
26332629

2634-
x = ecdsa_sk->key.x;
2635-
xlen = ecdsa_sk->key.xlen;
26362630
ec = br_ec_get_default();
2637-
if ((ec->supported_curves & 1 << ecdsa_sk->key.curve) == 0)
2631+
if ((ec->supported_curves & 1 << nid) == 0)
26382632
return SSH_ERR_LIBCRYPTO_ERROR;
26392633

2640-
n = ec->order(ecdsa_sk->key.curve, &nlen);
2634+
n = ec->order(nid, &nlen);
26412635

26422636
/* log2(private) > log2(order)/2 */
26432637
if (xlen <= nlen / 2 || xlen > nlen)
@@ -3410,8 +3404,10 @@ sshkey_parse_private_pem_fileblob(struct sshbuf *blob, int type,
34103404
memcpy(ecdsa_sk->key.x, ec->x, ec->xlen);
34113405

34123406
if (sshkey_curve_nid_to_name(ec->curve) == NULL ||
3413-
sshkey_ec_validate_public(ecdsa_pk) != 0 ||
3414-
sshkey_ec_validate_private(ecdsa_sk) != 0) {
3407+
sshkey_ec_validate_public(ec->curve,
3408+
ecdsa_pk->key.q, ecdsa_pk->key.qlen) != 0 ||
3409+
sshkey_ec_validate_private(ec->curve,
3410+
ecdsa_sk->key.x, ecdsa_sk->key.xlen) != 0) {
34153411
r = SSH_ERR_INVALID_FORMAT;
34163412
goto out;
34173413
}

sshkey.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,10 @@ const char * sshkey_curve_nid_to_name(int);
275275
u_int sshkey_curve_nid_to_bits(int);
276276
int sshkey_ecdsa_bits_to_nid(int);
277277
int sshkey_ec_nid_to_hash_alg(int nid);
278-
int sshkey_ec_validate_public(struct sshkey_ecdsa_pk *);
279-
int sshkey_ec_validate_private(struct sshkey_ecdsa_sk *);
278+
int sshkey_ec_validate_public(int nid, const u_char *q,
279+
size_t qlen);
280+
int sshkey_ec_validate_private(int nid, const u_char *x,
281+
size_t xlen);
280282
const char *sshkey_ssh_name(const struct sshkey *);
281283
const char *sshkey_ssh_name_plain(const struct sshkey *);
282284
int sshkey_names_valid2(const char *, int, int);

0 commit comments

Comments
 (0)