diff options
author | Dr. Stephen Henson <steve@openssl.org> | 2012-02-21 14:41:13 +0000 |
---|---|---|
committer | Dr. Stephen Henson <steve@openssl.org> | 2012-02-21 14:41:13 +0000 |
commit | 64095ce9d7c0613b0b45fe8015b4514116afdec0 (patch) | |
tree | f4ca204e5d0192db238ab9e3fb164cd50e72318c /crypto/ec/ec_curve.c | |
parent | 206310c3056847fef7e657879f05a09763c2131e (diff) |
Add new APIs EC_curve_nist2nid and EC_curve_nid2nist which convert
between NIDs and the more common NIST names such as "P-256". Enhance
ecparam utility and ECC method to recognise the NIST names for curves.
Diffstat (limited to 'crypto/ec/ec_curve.c')
-rw-r--r-- | crypto/ec/ec_curve.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c index 31a425cc4a..2ee2f4904f 100644 --- a/crypto/ec/ec_curve.c +++ b/crypto/ec/ec_curve.c @@ -71,6 +71,7 @@ #define OPENSSL_FIPSAPI +#include <string.h> #include "ec_lcl.h" #include <openssl/err.h> #include <openssl/obj_mac.h> @@ -2160,3 +2161,51 @@ size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems) return curve_list_length; } + +/* Functions to translate between common NIST curve names and NIDs */ + +typedef struct { + const char *name; /* NIST Name of curve */ + int nid; /* Curve NID */ +} EC_NIST_NAME; + +static EC_NIST_NAME nist_curves[] = { + {"B-163", NID_sect163r2}, + {"B-233", NID_sect233r1}, + {"B-283", NID_sect283r1}, + {"B-409", NID_sect409r1}, + {"B-571", NID_sect571r1}, + {"K-163", NID_sect163k1}, + {"K-233", NID_sect233k1}, + {"K-283", NID_sect283k1}, + {"K-409", NID_sect409k1}, + {"K-571", NID_sect571k1}, + {"P-192", NID_X9_62_prime192v1}, + {"P-224", NID_secp224r1}, + {"P-256", NID_X9_62_prime256v1}, + {"P-384", NID_secp384r1}, + {"P-521", NID_secp521r1} +}; + +const char *EC_curve_nid2nist(int nid) + { + size_t i; + for (i = 0; i < sizeof(nist_curves)/sizeof(EC_NIST_NAME); i++) + { + if (nist_curves[i].nid == nid) + return nist_curves[i].name; + } + return NULL; + } + +int EC_curve_nist2nid(const char *name) + { + size_t i; + for (i = 0; i < sizeof(nist_curves)/sizeof(EC_NIST_NAME); i++) + { + if (!strcmp(nist_curves[i].name, name)) + return nist_curves[i].nid; + } + return NID_undef; + } + |