summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjsing <>2015-06-20 13:26:08 +0000
committerjsing <>2015-06-20 13:26:08 +0000
commitecdf858d16bcab60c535bd54df320b055de8e85e (patch)
tree084b2eb66357efe77748467dcb0b1ebc4303b10b
parentc20a320b71eec149be5b817565a280f26954a04b (diff)
downloadopenbsd-ecdf858d16bcab60c535bd54df320b055de8e85e.tar.gz
openbsd-ecdf858d16bcab60c535bd54df320b055de8e85e.tar.bz2
openbsd-ecdf858d16bcab60c535bd54df320b055de8e85e.zip
Provide EC_curve_nid2nist() and EC_curve_nist2nid().
From OpenSSL. Rides libcrypto bump. ok miod@ (a while ago)
-rw-r--r--src/lib/libcrypto/ec/ec.h4
-rw-r--r--src/lib/libcrypto/ec/ec_curve.c55
-rw-r--r--src/lib/libssl/src/crypto/ec/ec.h4
-rw-r--r--src/lib/libssl/src/crypto/ec/ec_curve.c55
4 files changed, 114 insertions, 4 deletions
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
index db0b99a8e9..3b409ff92d 100644
--- a/src/lib/libcrypto/ec/ec.h
+++ b/src/lib/libcrypto/ec/ec.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec.h,v 1.9 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ec.h,v 1.10 2015/06/20 13:26:08 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -395,6 +395,8 @@ typedef struct {
395 * are filled with the data of the first nitems internal groups */ 395 * are filled with the data of the first nitems internal groups */
396size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 396size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
397 397
398const char *EC_curve_nid2nist(int nid);
399int EC_curve_nist2nid(const char *name);
398 400
399/********************************************************************/ 401/********************************************************************/
400/* EC_POINT functions */ 402/* EC_POINT functions */
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c
index d913867b76..9278e5593b 100644
--- a/src/lib/libcrypto/ec/ec_curve.c
+++ b/src/lib/libcrypto/ec/ec_curve.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_curve.c,v 1.11 2015/02/09 01:12:03 doug Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.12 2015/06/20 13:26:08 jsing Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -69,6 +69,8 @@
69 * 69 *
70 */ 70 */
71 71
72#include <string.h>
73
72#include <openssl/opensslconf.h> 74#include <openssl/opensslconf.h>
73 75
74#include "ec_lcl.h" 76#include "ec_lcl.h"
@@ -3285,3 +3287,54 @@ EC_get_builtin_curves(EC_builtin_curve * r, size_t nitems)
3285 3287
3286 return curve_list_length; 3288 return curve_list_length;
3287} 3289}
3290
3291/*
3292 * Functions to translate between common NIST curve names and NIDs.
3293 */
3294
3295typedef struct {
3296 const char *name; /* NIST Name of curve */
3297 int nid; /* Curve NID */
3298} EC_NIST_NAME;
3299
3300static EC_NIST_NAME nist_curves[] = {
3301 { "B-163", NID_sect163r2 },
3302 { "B-233", NID_sect233r1 },
3303 { "B-283", NID_sect283r1 },
3304 { "B-409", NID_sect409r1 },
3305 { "B-571", NID_sect571r1 },
3306 { "K-163", NID_sect163k1 },
3307 { "K-233", NID_sect233k1 },
3308 { "K-283", NID_sect283k1 },
3309 { "K-409", NID_sect409k1 },
3310 { "K-571", NID_sect571k1 },
3311 { "P-192", NID_X9_62_prime192v1 },
3312 { "P-224", NID_secp224r1 },
3313 { "P-256", NID_X9_62_prime256v1 },
3314 { "P-384", NID_secp384r1 },
3315 { "P-521", NID_secp521r1 }
3316};
3317
3318const char *
3319EC_curve_nid2nist(int nid)
3320{
3321 size_t i;
3322
3323 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
3324 if (nist_curves[i].nid == nid)
3325 return (nist_curves[i].name);
3326 }
3327 return (NULL);
3328}
3329
3330int
3331EC_curve_nist2nid(const char *name)
3332{
3333 size_t i;
3334
3335 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
3336 if (!strcmp(nist_curves[i].name, name))
3337 return (nist_curves[i].nid);
3338 }
3339 return (NID_undef);
3340}
diff --git a/src/lib/libssl/src/crypto/ec/ec.h b/src/lib/libssl/src/crypto/ec/ec.h
index db0b99a8e9..3b409ff92d 100644
--- a/src/lib/libssl/src/crypto/ec/ec.h
+++ b/src/lib/libssl/src/crypto/ec/ec.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec.h,v 1.9 2014/06/12 15:49:29 deraadt Exp $ */ 1/* $OpenBSD: ec.h,v 1.10 2015/06/20 13:26:08 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -395,6 +395,8 @@ typedef struct {
395 * are filled with the data of the first nitems internal groups */ 395 * are filled with the data of the first nitems internal groups */
396size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems); 396size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
397 397
398const char *EC_curve_nid2nist(int nid);
399int EC_curve_nist2nid(const char *name);
398 400
399/********************************************************************/ 401/********************************************************************/
400/* EC_POINT functions */ 402/* EC_POINT functions */
diff --git a/src/lib/libssl/src/crypto/ec/ec_curve.c b/src/lib/libssl/src/crypto/ec/ec_curve.c
index d913867b76..9278e5593b 100644
--- a/src/lib/libssl/src/crypto/ec/ec_curve.c
+++ b/src/lib/libssl/src/crypto/ec/ec_curve.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_curve.c,v 1.11 2015/02/09 01:12:03 doug Exp $ */ 1/* $OpenBSD: ec_curve.c,v 1.12 2015/06/20 13:26:08 jsing Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -69,6 +69,8 @@
69 * 69 *
70 */ 70 */
71 71
72#include <string.h>
73
72#include <openssl/opensslconf.h> 74#include <openssl/opensslconf.h>
73 75
74#include "ec_lcl.h" 76#include "ec_lcl.h"
@@ -3285,3 +3287,54 @@ EC_get_builtin_curves(EC_builtin_curve * r, size_t nitems)
3285 3287
3286 return curve_list_length; 3288 return curve_list_length;
3287} 3289}
3290
3291/*
3292 * Functions to translate between common NIST curve names and NIDs.
3293 */
3294
3295typedef struct {
3296 const char *name; /* NIST Name of curve */
3297 int nid; /* Curve NID */
3298} EC_NIST_NAME;
3299
3300static EC_NIST_NAME nist_curves[] = {
3301 { "B-163", NID_sect163r2 },
3302 { "B-233", NID_sect233r1 },
3303 { "B-283", NID_sect283r1 },
3304 { "B-409", NID_sect409r1 },
3305 { "B-571", NID_sect571r1 },
3306 { "K-163", NID_sect163k1 },
3307 { "K-233", NID_sect233k1 },
3308 { "K-283", NID_sect283k1 },
3309 { "K-409", NID_sect409k1 },
3310 { "K-571", NID_sect571k1 },
3311 { "P-192", NID_X9_62_prime192v1 },
3312 { "P-224", NID_secp224r1 },
3313 { "P-256", NID_X9_62_prime256v1 },
3314 { "P-384", NID_secp384r1 },
3315 { "P-521", NID_secp521r1 }
3316};
3317
3318const char *
3319EC_curve_nid2nist(int nid)
3320{
3321 size_t i;
3322
3323 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
3324 if (nist_curves[i].nid == nid)
3325 return (nist_curves[i].name);
3326 }
3327 return (NULL);
3328}
3329
3330int
3331EC_curve_nist2nid(const char *name)
3332{
3333 size_t i;
3334
3335 for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
3336 if (!strcmp(nist_curves[i].name, name))
3337 return (nist_curves[i].nid);
3338 }
3339 return (NID_undef);
3340}