diff options
author | tb <> | 2024-10-18 17:56:45 +0000 |
---|---|---|
committer | tb <> | 2024-10-18 17:56:45 +0000 |
commit | 9f898f3c2396c52080e2bf9000f513e152deb708 (patch) | |
tree | 645fe8d8f868ef53d5564522aa5cc812363174fa /src | |
parent | 2df019274e47fee92f671fabf664648e1d0f3e42 (diff) | |
download | openbsd-9f898f3c2396c52080e2bf9000f513e152deb708.tar.gz openbsd-9f898f3c2396c52080e2bf9000f513e152deb708.tar.bz2 openbsd-9f898f3c2396c52080e2bf9000f513e152deb708.zip |
Use better naming in ec_curve.c
Rename struct ec_list_element into struct ec_curve. Accordingly, curve_list
becomes struct ec_curve ec_curve_list[]. Adjust internal API to match.
suggested by jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec_curve.c | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/src/lib/libcrypto/ec/ec_curve.c b/src/lib/libcrypto/ec/ec_curve.c index 2529229ba5..4c1611f1af 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.44 2024/10/18 17:27:07 tb Exp $ */ | 1 | /* $OpenBSD: ec_curve.c,v 1.45 2024/10/18 17:56:45 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -1791,7 +1791,7 @@ static const struct { | |||
1791 | }, | 1791 | }, |
1792 | }; | 1792 | }; |
1793 | 1793 | ||
1794 | static const struct ec_list_element { | 1794 | static const struct ec_curve { |
1795 | const char *comment; | 1795 | const char *comment; |
1796 | int nid; | 1796 | int nid; |
1797 | int seed_len; | 1797 | int seed_len; |
@@ -1804,7 +1804,7 @@ static const struct ec_list_element { | |||
1804 | const uint8_t *x; | 1804 | const uint8_t *x; |
1805 | const uint8_t *y; | 1805 | const uint8_t *y; |
1806 | const uint8_t *order; | 1806 | const uint8_t *order; |
1807 | } curve_list[] = { | 1807 | } ec_curve_list[] = { |
1808 | /* secg curves */ | 1808 | /* secg curves */ |
1809 | { | 1809 | { |
1810 | .comment = "SECG/WTLS curve over a 112 bit prime field", | 1810 | .comment = "SECG/WTLS curve over a 112 bit prime field", |
@@ -2329,10 +2329,10 @@ static const struct ec_list_element { | |||
2329 | }, | 2329 | }, |
2330 | }; | 2330 | }; |
2331 | 2331 | ||
2332 | #define CURVE_LIST_LENGTH (sizeof(curve_list) / sizeof(curve_list[0])) | 2332 | #define EC_CURVE_LIST_LENGTH (sizeof(ec_curve_list) / sizeof(ec_curve_list[0])) |
2333 | 2333 | ||
2334 | static EC_GROUP * | 2334 | static EC_GROUP * |
2335 | ec_group_new_from_data(const struct ec_list_element *curve) | 2335 | ec_group_new_from_data(const struct ec_curve *curve) |
2336 | { | 2336 | { |
2337 | EC_GROUP *group = NULL, *ret = NULL; | 2337 | EC_GROUP *group = NULL, *ret = NULL; |
2338 | EC_POINT *generator = NULL; | 2338 | EC_POINT *generator = NULL; |
@@ -2448,9 +2448,9 @@ EC_GROUP_new_by_curve_name(int nid) | |||
2448 | if (nid <= 0) | 2448 | if (nid <= 0) |
2449 | return NULL; | 2449 | return NULL; |
2450 | 2450 | ||
2451 | for (i = 0; i < CURVE_LIST_LENGTH; i++) { | 2451 | for (i = 0; i < EC_CURVE_LIST_LENGTH; i++) { |
2452 | if (curve_list[i].nid == nid) | 2452 | if (ec_curve_list[i].nid == nid) |
2453 | return ec_group_new_from_data(&curve_list[i]); | 2453 | return ec_group_new_from_data(&ec_curve_list[i]); |
2454 | } | 2454 | } |
2455 | 2455 | ||
2456 | ECerror(EC_R_UNKNOWN_GROUP); | 2456 | ECerror(EC_R_UNKNOWN_GROUP); |
@@ -2459,7 +2459,7 @@ EC_GROUP_new_by_curve_name(int nid) | |||
2459 | LCRYPTO_ALIAS(EC_GROUP_new_by_curve_name); | 2459 | LCRYPTO_ALIAS(EC_GROUP_new_by_curve_name); |
2460 | 2460 | ||
2461 | static void | 2461 | static void |
2462 | ec_list_element_free(struct ec_list_element *curve) | 2462 | ec_curve_free(struct ec_curve *curve) |
2463 | { | 2463 | { |
2464 | if (curve == NULL) | 2464 | if (curve == NULL) |
2465 | return; | 2465 | return; |
@@ -2477,7 +2477,7 @@ ec_list_element_free(struct ec_list_element *curve) | |||
2477 | } | 2477 | } |
2478 | 2478 | ||
2479 | static int | 2479 | static int |
2480 | ec_list_element_encode_parameter(const BIGNUM *bn, int param_len, | 2480 | ec_curve_encode_parameter(const BIGNUM *bn, int param_len, |
2481 | const uint8_t **out_param) | 2481 | const uint8_t **out_param) |
2482 | { | 2482 | { |
2483 | uint8_t *buf = NULL; | 2483 | uint8_t *buf = NULL; |
@@ -2502,10 +2502,10 @@ ec_list_element_encode_parameter(const BIGNUM *bn, int param_len, | |||
2502 | return ret; | 2502 | return ret; |
2503 | } | 2503 | } |
2504 | 2504 | ||
2505 | static struct ec_list_element * | 2505 | static struct ec_curve * |
2506 | ec_list_element_from_group(const EC_GROUP *group) | 2506 | ec_curve_from_group(const EC_GROUP *group) |
2507 | { | 2507 | { |
2508 | struct ec_list_element *curve = NULL; | 2508 | struct ec_curve *curve = NULL; |
2509 | BN_CTX *ctx; | 2509 | BN_CTX *ctx; |
2510 | BIGNUM *p, *a, *b, *x, *y; | 2510 | BIGNUM *p, *a, *b, *x, *y; |
2511 | const EC_POINT *generator = NULL; | 2511 | const EC_POINT *generator = NULL; |
@@ -2543,17 +2543,17 @@ ec_list_element_from_group(const EC_GROUP *group) | |||
2543 | if (BN_num_bytes(order) > curve->param_len) | 2543 | if (BN_num_bytes(order) > curve->param_len) |
2544 | curve->param_len = BN_num_bytes(order); | 2544 | curve->param_len = BN_num_bytes(order); |
2545 | 2545 | ||
2546 | if (!ec_list_element_encode_parameter(p, curve->param_len, &curve->p)) | 2546 | if (!ec_curve_encode_parameter(p, curve->param_len, &curve->p)) |
2547 | goto err; | 2547 | goto err; |
2548 | if (!ec_list_element_encode_parameter(a, curve->param_len, &curve->a)) | 2548 | if (!ec_curve_encode_parameter(a, curve->param_len, &curve->a)) |
2549 | goto err; | 2549 | goto err; |
2550 | if (!ec_list_element_encode_parameter(b, curve->param_len, &curve->b)) | 2550 | if (!ec_curve_encode_parameter(b, curve->param_len, &curve->b)) |
2551 | goto err; | 2551 | goto err; |
2552 | if (!ec_list_element_encode_parameter(x, curve->param_len, &curve->x)) | 2552 | if (!ec_curve_encode_parameter(x, curve->param_len, &curve->x)) |
2553 | goto err; | 2553 | goto err; |
2554 | if (!ec_list_element_encode_parameter(y, curve->param_len, &curve->y)) | 2554 | if (!ec_curve_encode_parameter(y, curve->param_len, &curve->y)) |
2555 | goto err; | 2555 | goto err; |
2556 | if (!ec_list_element_encode_parameter(order, curve->param_len, &curve->order)) | 2556 | if (!ec_curve_encode_parameter(order, curve->param_len, &curve->order)) |
2557 | goto err; | 2557 | goto err; |
2558 | 2558 | ||
2559 | if ((cofactor = EC_GROUP_get0_cofactor(group)) != NULL) { | 2559 | if ((cofactor = EC_GROUP_get0_cofactor(group)) != NULL) { |
@@ -2589,13 +2589,13 @@ ec_list_element_from_group(const EC_GROUP *group) | |||
2589 | BN_CTX_end(ctx); | 2589 | BN_CTX_end(ctx); |
2590 | BN_CTX_free(ctx); | 2590 | BN_CTX_free(ctx); |
2591 | 2591 | ||
2592 | ec_list_element_free(curve); | 2592 | ec_curve_free(curve); |
2593 | 2593 | ||
2594 | return NULL; | 2594 | return NULL; |
2595 | } | 2595 | } |
2596 | 2596 | ||
2597 | static int | 2597 | static int |
2598 | ec_list_element_cmp(const struct ec_list_element *a, const struct ec_list_element *b) | 2598 | ec_curve_cmp(const struct ec_curve *a, const struct ec_curve *b) |
2599 | { | 2599 | { |
2600 | int cmp; | 2600 | int cmp; |
2601 | 2601 | ||
@@ -2645,13 +2645,13 @@ ec_list_element_cmp(const struct ec_list_element *a, const struct ec_list_elemen | |||
2645 | } | 2645 | } |
2646 | 2646 | ||
2647 | static int | 2647 | static int |
2648 | ec_group_nid_from_curve(const struct ec_list_element *curve) | 2648 | ec_group_nid_from_curve(const struct ec_curve *curve) |
2649 | { | 2649 | { |
2650 | size_t i; | 2650 | size_t i; |
2651 | 2651 | ||
2652 | for (i = 0; i < CURVE_LIST_LENGTH; i++) { | 2652 | for (i = 0; i < EC_CURVE_LIST_LENGTH; i++) { |
2653 | if (ec_list_element_cmp(curve, &curve_list[i]) == 0) | 2653 | if (ec_curve_cmp(curve, &ec_curve_list[i]) == 0) |
2654 | return curve_list[i].nid; | 2654 | return ec_curve_list[i].nid; |
2655 | } | 2655 | } |
2656 | 2656 | ||
2657 | return NID_undef; | 2657 | return NID_undef; |
@@ -2660,10 +2660,10 @@ ec_group_nid_from_curve(const struct ec_list_element *curve) | |||
2660 | int | 2660 | int |
2661 | ec_group_is_builtin_curve(const EC_GROUP *group) | 2661 | ec_group_is_builtin_curve(const EC_GROUP *group) |
2662 | { | 2662 | { |
2663 | struct ec_list_element *curve; | 2663 | struct ec_curve *curve; |
2664 | int ret = 0; | 2664 | int ret = 0; |
2665 | 2665 | ||
2666 | if ((curve = ec_list_element_from_group(group)) == NULL) | 2666 | if ((curve = ec_curve_from_group(group)) == NULL) |
2667 | goto err; | 2667 | goto err; |
2668 | 2668 | ||
2669 | if (ec_group_nid_from_curve(curve) == NID_undef) | 2669 | if (ec_group_nid_from_curve(curve) == NID_undef) |
@@ -2672,7 +2672,7 @@ ec_group_is_builtin_curve(const EC_GROUP *group) | |||
2672 | ret = 1; | 2672 | ret = 1; |
2673 | 2673 | ||
2674 | err: | 2674 | err: |
2675 | ec_list_element_free(curve); | 2675 | ec_curve_free(curve); |
2676 | 2676 | ||
2677 | return ret; | 2677 | return ret; |
2678 | } | 2678 | } |
@@ -2683,16 +2683,16 @@ EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems) | |||
2683 | size_t i, min; | 2683 | size_t i, min; |
2684 | 2684 | ||
2685 | if (r == NULL || nitems == 0) | 2685 | if (r == NULL || nitems == 0) |
2686 | return CURVE_LIST_LENGTH; | 2686 | return EC_CURVE_LIST_LENGTH; |
2687 | 2687 | ||
2688 | min = nitems < CURVE_LIST_LENGTH ? nitems : CURVE_LIST_LENGTH; | 2688 | min = nitems < EC_CURVE_LIST_LENGTH ? nitems : EC_CURVE_LIST_LENGTH; |
2689 | 2689 | ||
2690 | for (i = 0; i < min; i++) { | 2690 | for (i = 0; i < min; i++) { |
2691 | r[i].nid = curve_list[i].nid; | 2691 | r[i].nid = ec_curve_list[i].nid; |
2692 | r[i].comment = curve_list[i].comment; | 2692 | r[i].comment = ec_curve_list[i].comment; |
2693 | } | 2693 | } |
2694 | 2694 | ||
2695 | return CURVE_LIST_LENGTH; | 2695 | return EC_CURVE_LIST_LENGTH; |
2696 | } | 2696 | } |
2697 | LCRYPTO_ALIAS(EC_get_builtin_curves); | 2697 | LCRYPTO_ALIAS(EC_get_builtin_curves); |
2698 | 2698 | ||