forked from wolfSSL/wolfssl
ECC helper cleanup
This commit is contained in:
@ -2490,6 +2490,34 @@ int wc_ecc_get_curve_size_from_id(int curve_id)
|
|||||||
return ecc_sets[curve_idx].size;
|
return ecc_sets[curve_idx].size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns the curve index that corresponds to a given curve name in
|
||||||
|
* ecc_sets[] of ecc.c
|
||||||
|
*
|
||||||
|
* name curve name, from ecc_sets[].name in ecc.c
|
||||||
|
* return curve index in ecc_sets[] on success, negative on error
|
||||||
|
*/
|
||||||
|
int wc_ecc_get_curve_idx_from_name(const char* curveName)
|
||||||
|
{
|
||||||
|
int curve_idx;
|
||||||
|
word32 len;
|
||||||
|
|
||||||
|
if (curveName == NULL)
|
||||||
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
|
len = XSTRLEN(curveName);
|
||||||
|
|
||||||
|
for (curve_idx = 0; ecc_sets[curve_idx].size != 0; curve_idx++) {
|
||||||
|
if (XSTRNCASECMP(ecc_sets[curve_idx].name, curveName, len) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ecc_sets[curve_idx].size == 0) {
|
||||||
|
WOLFSSL_MSG("ecc_set curve name not found");
|
||||||
|
return ECC_CURVE_INVALID;
|
||||||
|
}
|
||||||
|
return curve_idx;
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the curve size that corresponds to a given curve name,
|
/* Returns the curve size that corresponds to a given curve name,
|
||||||
* as listed in ecc_sets[] of ecc.c.
|
* as listed in ecc_sets[] of ecc.c.
|
||||||
*
|
*
|
||||||
@ -2498,26 +2526,16 @@ int wc_ecc_get_curve_size_from_id(int curve_id)
|
|||||||
*/
|
*/
|
||||||
int wc_ecc_get_curve_size_from_name(const char* curveName)
|
int wc_ecc_get_curve_size_from_name(const char* curveName)
|
||||||
{
|
{
|
||||||
int x;
|
int curve_idx;
|
||||||
|
|
||||||
if (curveName == NULL)
|
if (curveName == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
/* find curve from name */
|
curve_idx = wc_ecc_get_curve_idx_from_name(curveName);
|
||||||
for (x = 0; ecc_sets[x].size != 0; x++) {
|
if (curve_idx < 0)
|
||||||
if (XSTRNCMP(ecc_sets[x].name, curveName,
|
return curve_idx;
|
||||||
XSTRLEN(curveName)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecc_sets[x].size == 0) {
|
return ecc_sets[curve_idx].size;
|
||||||
WOLFSSL_MSG("ecc_set curve name not found");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* will be 0 if not found */
|
|
||||||
return ecc_sets[x].size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the curve id that corresponds to a given curve name,
|
/* Returns the curve id that corresponds to a given curve name,
|
||||||
@ -2528,25 +2546,16 @@ int wc_ecc_get_curve_size_from_name(const char* curveName)
|
|||||||
*/
|
*/
|
||||||
int wc_ecc_get_curve_id_from_name(const char* curveName)
|
int wc_ecc_get_curve_id_from_name(const char* curveName)
|
||||||
{
|
{
|
||||||
int x;
|
int curve_idx;
|
||||||
|
|
||||||
if (curveName == NULL)
|
if (curveName == NULL)
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
|
|
||||||
/* find curve from name */
|
curve_idx = wc_ecc_get_curve_idx_from_name(curveName);
|
||||||
for (x = 0; ecc_sets[x].size != 0; x++) {
|
if (curve_idx < 0)
|
||||||
if (XSTRNCMP(ecc_sets[x].name, curveName,
|
return curve_idx;
|
||||||
XSTRLEN(curveName)) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecc_sets[x].size == 0) {
|
return ecc_sets[curve_idx].id;
|
||||||
WOLFSSL_MSG("ecc_set curve name not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* will be -1 if not found */
|
|
||||||
return ecc_sets[x].id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -369,6 +369,9 @@ int wc_ecc_get_curve_id(int curve_idx);
|
|||||||
#define wc_ecc_get_curve_name_from_id wc_ecc_get_name
|
#define wc_ecc_get_curve_name_from_id wc_ecc_get_name
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_get_curve_size_from_id(int curve_id);
|
int wc_ecc_get_curve_size_from_id(int curve_id);
|
||||||
|
|
||||||
|
WOLFSSL_API
|
||||||
|
int wc_ecc_get_curve_idx_from_name(const char* curveName);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
int wc_ecc_get_curve_size_from_name(const char* curveName);
|
int wc_ecc_get_curve_size_from_name(const char* curveName);
|
||||||
WOLFSSL_API
|
WOLFSSL_API
|
||||||
|
Reference in New Issue
Block a user