if (parg) {
size_t i;
int *cptr = parg;
+
for (i = 0; i < clistlen; i++) {
- /* TODO(TLS1.3): Handle DH groups here */
- int nid = tls1_ec_curve_id2nid(clist[i], NULL);
- if (nid != 0)
- cptr[i] = nid;
+ const TLS_GROUP_INFO *cinf = tls1_group_id_lookup(clist[i]);
+
+ if (cinf != NULL)
+ cptr[i] = cinf->nid;
else
cptr[i] = TLSEXT_nid_unknown | clist[i];
}
&s->ext.supportedgroups_len, parg);
case SSL_CTRL_GET_SHARED_GROUP:
- return tls1_ec_curve_id2nid(tls1_shared_group(s, larg), NULL);
+ {
+ uint16_t id = tls1_shared_group(s, larg);
+ if (larg != -1) {
+ const TLS_GROUP_INFO *ginf = tls1_group_id_lookup(id);
+
+ return ginf == NULL ? 0 : ginf->nid;
+ }
+ return id;
+ }
#endif
case SSL_CTRL_SET_SIGALGS:
return tls1_set_sigalgs(s->cert, parg, larg, 0);
return pkey;
}
#ifndef OPENSSL_NO_EC
-/* Generate a private key a curve ID */
-EVP_PKEY *ssl_generate_pkey_curve(int id)
+/* Generate a private key from a group ID */
+EVP_PKEY *ssl_generate_pkey_group(uint16_t id)
{
EVP_PKEY_CTX *pctx = NULL;
EVP_PKEY *pkey = NULL;
- unsigned int curve_flags;
- int nid = tls1_ec_curve_id2nid(id, &curve_flags);
+ const TLS_GROUP_INFO *ginf = tls1_group_id_lookup(id);
+ uint16_t gtype;
- if (nid == 0)
+ if (ginf == NULL)
goto err;
- if ((curve_flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
- pctx = EVP_PKEY_CTX_new_id(nid, NULL);
- nid = 0;
- } else {
+ gtype = ginf->flags & TLS_CURVE_TYPE;
+ if (gtype == TLS_CURVE_CUSTOM)
+ pctx = EVP_PKEY_CTX_new_id(ginf->nid, NULL);
+ else
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
- }
if (pctx == NULL)
goto err;
if (EVP_PKEY_keygen_init(pctx) <= 0)
goto err;
- if (nid != 0 && EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, nid) <= 0)
+ if (gtype != TLS_CURVE_CUSTOM
+ && EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, ginf->nid) <= 0)
goto err;
if (EVP_PKEY_keygen(pctx, &pkey) <= 0) {
EVP_PKEY_free(pkey);
# ifndef OPENSSL_NO_EC
-__owur int tls1_ec_curve_id2nid(uint16_t curve_id, unsigned int *pflags);
+__owur const TLS_GROUP_INFO *tls1_group_id_lookup(uint16_t curve_id);
__owur uint16_t tls1_ec_nid2curve_id(int nid);
__owur int tls1_check_curve(SSL *s, const unsigned char *p, size_t len);
__owur uint16_t tls1_shared_group(SSL *s, int nmatch);
void tls1_get_formatlist(SSL *s, const unsigned char **pformats,
size_t *num_formats);
__owur int tls1_check_ec_tmp_key(SSL *s, unsigned long id);
-__owur EVP_PKEY *ssl_generate_pkey_curve(int id);
+__owur EVP_PKEY *ssl_generate_pkey_group(uint16_t id);
# endif /* OPENSSL_NO_EC */
__owur int tls_curve_allowed(SSL *s, uint16_t curve, int op);
*/
key_share_key = s->s3->tmp.pkey;
} else {
- key_share_key = ssl_generate_pkey_curve(curve_id);
+ key_share_key = ssl_generate_pkey_group(curve_id);
if (key_share_key == NULL) {
SSLerr(SSL_F_ADD_KEY_SHARE, ERR_R_EVP_LIB);
return 0;
PACKET key_share_list, encoded_pt;
const uint16_t *clntcurves, *srvrcurves;
size_t clnt_num_curves, srvr_num_curves;
- int group_nid, found = 0;
- unsigned int curve_flags;
+ int found = 0;
+ const TLS_GROUP_INFO *ginf;
if (s->hit && (s->ext.psk_kex_mode & TLSEXT_KEX_MODE_FLAG_KE_DHE) == 0)
return 1;
continue;
}
- group_nid = tls1_ec_curve_id2nid(group_id, &curve_flags);
+ ginf = tls1_group_id_lookup(group_id);
- if (group_nid == 0) {
+ if (ginf == NULL) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PARSE_CTOS_KEY_SHARE,
SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
return 0;
}
- if ((curve_flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
+ if ((ginf->flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
/* Can happen for some curves, e.g. X25519 */
EVP_PKEY *key = EVP_PKEY_new();
- if (key == NULL || !EVP_PKEY_set_type(key, group_nid)) {
+ if (key == NULL || !EVP_PKEY_set_type(key, ginf->nid)) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PARSE_CTOS_KEY_SHARE, ERR_R_EVP_LIB);
EVP_PKEY_free(key);
if (pctx == NULL
|| EVP_PKEY_paramgen_init(pctx) <= 0
|| EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx,
- group_nid) <= 0
+ ginf->nid) <= 0
|| EVP_PKEY_paramgen(pctx, &s->s3->peer_tmp) <= 0) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PARSE_CTOS_KEY_SHARE, ERR_R_EVP_LIB);
#ifndef OPENSSL_NO_EC
PACKET encoded_pt;
const unsigned char *ecparams;
- int curve_nid;
- unsigned int curve_flags;
+ const TLS_GROUP_INFO *ginf;
EVP_PKEY_CTX *pctx = NULL;
/*
return 0;
}
- curve_nid = tls1_ec_curve_id2nid(*(ecparams + 2), &curve_flags);
+ ginf = tls1_group_id_lookup(ecparams[2]);
- if (curve_nid == 0) {
+ if (ginf == NULL) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE,
SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
return 0;
}
- if ((curve_flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
+ if ((ginf->flags & TLS_CURVE_TYPE) == TLS_CURVE_CUSTOM) {
EVP_PKEY *key = EVP_PKEY_new();
- if (key == NULL || !EVP_PKEY_set_type(key, curve_nid)) {
+ if (key == NULL || !EVP_PKEY_set_type(key, ginf->nid)) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE, ERR_R_EVP_LIB);
EVP_PKEY_free(key);
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if (pctx == NULL
|| EVP_PKEY_paramgen_init(pctx) <= 0
- || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, curve_nid) <= 0
+ || EVP_PKEY_CTX_set_ec_paramgen_curve_nid(pctx, ginf->nid) <= 0
|| EVP_PKEY_paramgen(pctx, &s->s3->peer_tmp) <= 0) {
*al = SSL_AD_INTERNAL_ERROR;
SSLerr(SSL_F_TLS_PROCESS_SKE_ECDHE, ERR_R_EVP_LIB);
SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
goto err;
}
- s->s3->tmp.pkey = ssl_generate_pkey_curve(curve_id);
+ s->s3->tmp.pkey = ssl_generate_pkey_group(curve_id);
/* Generate a new key for this curve */
if (s->s3->tmp.pkey == NULL) {
SSLerr(SSL_F_TLS_CONSTRUCT_SERVER_KEY_EXCHANGE, ERR_R_EVP_LIB);
TLSEXT_curve_P_384
};
-int tls1_ec_curve_id2nid(uint16_t curve_id, unsigned int *pflags)
+const TLS_GROUP_INFO *tls1_group_id_lookup(uint16_t curve_id)
{
- const TLS_GROUP_INFO *cinfo;
/* ECC curves from RFC 4492 and RFC 7027 */
if (curve_id < 1 || curve_id > OSSL_NELEM(nid_list))
- return NID_undef;
- cinfo = nid_list + curve_id - 1;
- if (pflags)
- *pflags = cinfo->flags;
- return cinfo->nid;
+ return NULL;
+ return &nid_list[curve_id - 1];
}
uint16_t tls1_ec_nid2curve_id(int nid)