@@ -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
25702570int
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
26272623int
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 }
0 commit comments