diff options
| author | tb <> | 2024-10-30 18:21:12 +0000 |
|---|---|---|
| committer | tb <> | 2024-10-30 18:21:12 +0000 |
| commit | eef4d0f03df908d7a28409f0101fbf50da04174f (patch) | |
| tree | b3aa42d47adfb87ed3a6543cdb53ae9f8d73cc14 /src/lib/libcrypto/ec/ec_convert.c | |
| parent | fdf419beaf02f8919505dec685a59f1f38c15eca (diff) | |
| download | openbsd-eef4d0f03df908d7a28409f0101fbf50da04174f.tar.gz openbsd-eef4d0f03df908d7a28409f0101fbf50da04174f.tar.bz2 openbsd-eef4d0f03df908d7a28409f0101fbf50da04174f.zip | |
Move the point2bn and point2hex API to ec_convert.c
discussed with jsing
Diffstat (limited to 'src/lib/libcrypto/ec/ec_convert.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_convert.c | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/src/lib/libcrypto/ec/ec_convert.c b/src/lib/libcrypto/ec/ec_convert.c index f6ee1f9702..e8f8605c10 100644 --- a/src/lib/libcrypto/ec/ec_convert.c +++ b/src/lib/libcrypto/ec/ec_convert.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ec_convert.c,v 1.3 2024/10/30 18:18:35 tb Exp $ */ | 1 | /* $OpenBSD: ec_convert.c,v 1.4 2024/10/30 18:21:12 tb 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 | */ |
| @@ -491,3 +491,85 @@ EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, | |||
| 491 | return ret; | 491 | return ret; |
| 492 | } | 492 | } |
| 493 | LCRYPTO_ALIAS(EC_POINT_oct2point); | 493 | LCRYPTO_ALIAS(EC_POINT_oct2point); |
| 494 | |||
| 495 | BIGNUM * | ||
| 496 | EC_POINT_point2bn(const EC_GROUP *group, const EC_POINT *point, | ||
| 497 | point_conversion_form_t form, BIGNUM *in_bn, BN_CTX *ctx) | ||
| 498 | { | ||
| 499 | BIGNUM *bn = NULL; | ||
| 500 | unsigned char *buf = NULL; | ||
| 501 | size_t buf_len = 0; | ||
| 502 | |||
| 503 | if (!ec_point_to_octets(group, point, form, &buf, &buf_len, ctx)) | ||
| 504 | goto err; | ||
| 505 | if ((bn = BN_bin2bn(buf, buf_len, in_bn)) == NULL) | ||
| 506 | goto err; | ||
| 507 | |||
| 508 | err: | ||
| 509 | freezero(buf, buf_len); | ||
| 510 | |||
| 511 | return bn; | ||
| 512 | } | ||
| 513 | LCRYPTO_ALIAS(EC_POINT_point2bn); | ||
| 514 | |||
| 515 | EC_POINT * | ||
| 516 | EC_POINT_bn2point(const EC_GROUP *group, | ||
| 517 | const BIGNUM *bn, EC_POINT *point, BN_CTX *ctx) | ||
| 518 | { | ||
| 519 | unsigned char *buf = NULL; | ||
| 520 | size_t buf_len = 0; | ||
| 521 | |||
| 522 | /* Of course BN_bn2bin() is in no way symmetric to BN_bin2bn()... */ | ||
| 523 | if ((buf_len = BN_num_bytes(bn)) == 0) | ||
| 524 | goto err; | ||
| 525 | if ((buf = calloc(1, buf_len)) == NULL) | ||
| 526 | goto err; | ||
| 527 | if (!BN_bn2bin(bn, buf)) | ||
| 528 | goto err; | ||
| 529 | if (!ec_point_from_octets(group, buf, buf_len, &point, NULL, ctx)) | ||
| 530 | goto err; | ||
| 531 | |||
| 532 | err: | ||
| 533 | freezero(buf, buf_len); | ||
| 534 | |||
| 535 | return point; | ||
| 536 | } | ||
| 537 | LCRYPTO_ALIAS(EC_POINT_bn2point); | ||
| 538 | |||
| 539 | char * | ||
| 540 | EC_POINT_point2hex(const EC_GROUP *group, const EC_POINT *point, | ||
| 541 | point_conversion_form_t form, BN_CTX *ctx) | ||
| 542 | { | ||
| 543 | BIGNUM *bn; | ||
| 544 | char *hex = NULL; | ||
| 545 | |||
| 546 | if ((bn = EC_POINT_point2bn(group, point, form, NULL, ctx)) == NULL) | ||
| 547 | goto err; | ||
| 548 | if ((hex = BN_bn2hex(bn)) == NULL) | ||
| 549 | goto err; | ||
| 550 | |||
| 551 | err: | ||
| 552 | BN_free(bn); | ||
| 553 | |||
| 554 | return hex; | ||
| 555 | } | ||
| 556 | LCRYPTO_ALIAS(EC_POINT_point2hex); | ||
| 557 | |||
| 558 | EC_POINT * | ||
| 559 | EC_POINT_hex2point(const EC_GROUP *group, const char *hex, | ||
| 560 | EC_POINT *in_point, BN_CTX *ctx) | ||
| 561 | { | ||
| 562 | EC_POINT *point = NULL; | ||
| 563 | BIGNUM *bn = NULL; | ||
| 564 | |||
| 565 | if (BN_hex2bn(&bn, hex) == 0) | ||
| 566 | goto err; | ||
| 567 | if ((point = EC_POINT_bn2point(group, bn, in_point, ctx)) == NULL) | ||
| 568 | goto err; | ||
| 569 | |||
| 570 | err: | ||
| 571 | BN_free(bn); | ||
| 572 | |||
| 573 | return point; | ||
| 574 | } | ||
| 575 | LCRYPTO_ALIAS(EC_POINT_hex2point); | ||
