| author | |
| committer | |
| log | b21fa8e2cd98d487d50755416c7ab90ebd6e620e |
| tree | cacf22997d5aa2cd75c07d2d026abe2c7ba70a2e |
| parent | 5cfd47660cc0422f92c5c2d029d6dbad3f213e52 |
| signature |
Implemented `neg()` method for `AffineCoordinates` struct of p256,
p384 and secp256k1 curves.
Resolves: #20505 (partially)3 files changed, 12 insertions(+), 0 deletions(-)
lib/std/crypto/pcurves/p256.zig+4| ... | @@ -471,6 +471,10 @@ pub const AffineCoordinates = struct { | ... | @@ -471,6 +471,10 @@ pub const AffineCoordinates = struct { |
| 471 | /// Identity element in affine coordinates. | 471 | /// Identity element in affine coordinates. |
| 472 | pub const identityElement = AffineCoordinates{ .x = P256.identityElement.x, .y = P256.identityElement.y }; | 472 | pub const identityElement = AffineCoordinates{ .x = P256.identityElement.x, .y = P256.identityElement.y }; |
| 473 | 473 | ||
| 474 | pub fn neg(p: AffineCoordinates) AffineCoordinates { | ||
| 475 | return .{ .x = p.x, .y = p.y.neg() }; | ||
| 476 | } | ||
| 477 | |||
| 474 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { | 478 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { |
| 475 | p.x.cMov(a.x, c); | 479 | p.x.cMov(a.x, c); |
| 476 | p.y.cMov(a.y, c); | 480 | p.y.cMov(a.y, c); |
lib/std/crypto/pcurves/p384.zig+4| ... | @@ -471,6 +471,10 @@ pub const AffineCoordinates = struct { | ... | @@ -471,6 +471,10 @@ pub const AffineCoordinates = struct { |
| 471 | /// Identity element in affine coordinates. | 471 | /// Identity element in affine coordinates. |
| 472 | pub const identityElement = AffineCoordinates{ .x = P384.identityElement.x, .y = P384.identityElement.y }; | 472 | pub const identityElement = AffineCoordinates{ .x = P384.identityElement.x, .y = P384.identityElement.y }; |
| 473 | 473 | ||
| 474 | pub fn neg(p: AffineCoordinates) AffineCoordinates { | ||
| 475 | return .{ .x = p.x, .y = p.y.neg() }; | ||
| 476 | } | ||
| 477 | |||
| 474 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { | 478 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { |
| 475 | p.x.cMov(a.x, c); | 479 | p.x.cMov(a.x, c); |
| 476 | p.y.cMov(a.y, c); | 480 | p.y.cMov(a.y, c); |
lib/std/crypto/pcurves/secp256k1.zig+4| ... | @@ -549,6 +549,10 @@ pub const AffineCoordinates = struct { | ... | @@ -549,6 +549,10 @@ pub const AffineCoordinates = struct { |
| 549 | /// Identity element in affine coordinates. | 549 | /// Identity element in affine coordinates. |
| 550 | pub const identityElement = AffineCoordinates{ .x = Secp256k1.identityElement.x, .y = Secp256k1.identityElement.y }; | 550 | pub const identityElement = AffineCoordinates{ .x = Secp256k1.identityElement.x, .y = Secp256k1.identityElement.y }; |
| 551 | 551 | ||
| 552 | pub fn neg(p: AffineCoordinates) AffineCoordinates { | ||
| 553 | return .{ .x = p.x, .y = p.y.neg() }; | ||
| 554 | } | ||
| 555 | |||
| 552 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { | 556 | fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void { |
| 553 | p.x.cMov(a.x, c); | 557 | p.x.cMov(a.x, c); |
| 554 | p.y.cMov(a.y, c); | 558 | p.y.cMov(a.y, c); |