Skip to content

Commit a14352b

Browse files
authored
std: fix compile errors in std.crypto.ecc (#23797)
Implemented `neg()` method for `AffineCoordinates` struct of p256, p384 and secp256k1 curves. Resolves: #20505 (partially)
1 parent 369177f commit a14352b

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/std/crypto/pcurves/p256.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ pub const AffineCoordinates = struct {
471471
/// Identity element in affine coordinates.
472472
pub const identityElement = AffineCoordinates{ .x = P256.identityElement.x, .y = P256.identityElement.y };
473473

474+
pub fn neg(p: AffineCoordinates) AffineCoordinates {
475+
return .{ .x = p.x, .y = p.y.neg() };
476+
}
477+
474478
fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void {
475479
p.x.cMov(a.x, c);
476480
p.y.cMov(a.y, c);

lib/std/crypto/pcurves/p384.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ pub const AffineCoordinates = struct {
471471
/// Identity element in affine coordinates.
472472
pub const identityElement = AffineCoordinates{ .x = P384.identityElement.x, .y = P384.identityElement.y };
473473

474+
pub fn neg(p: AffineCoordinates) AffineCoordinates {
475+
return .{ .x = p.x, .y = p.y.neg() };
476+
}
477+
474478
fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void {
475479
p.x.cMov(a.x, c);
476480
p.y.cMov(a.y, c);

lib/std/crypto/pcurves/secp256k1.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ pub const AffineCoordinates = struct {
549549
/// Identity element in affine coordinates.
550550
pub const identityElement = AffineCoordinates{ .x = Secp256k1.identityElement.x, .y = Secp256k1.identityElement.y };
551551

552+
pub fn neg(p: AffineCoordinates) AffineCoordinates {
553+
return .{ .x = p.x, .y = p.y.neg() };
554+
}
555+
552556
fn cMov(p: *AffineCoordinates, a: AffineCoordinates, c: u1) void {
553557
p.x.cMov(a.x, c);
554558
p.y.cMov(a.y, c);

0 commit comments

Comments
 (0)