| author | |
| committer | |
| log | eaca8626b270b5c17d686c77220e2aacb5fd908f |
| tree | 11195fb7cb36c4bf648eff2737a42aad4161118d |
| parent | 40e64245fc5555f29bbb5bb37e3b78d64f9b3c9b |
| signature |
Fixes compilation errors in functions that are syntaxic sugar
to operate on serialized scalars.
Also make it explicit that square roots in fields whose size is
not congruent to 3 modulo 4 are not an error, they are just
not implemented yet.
Reported by @vitalonodo - Thanks!5 files changed, 8 insertions(+), 8 deletions(-)
lib/std/crypto/pcurves/common.zig+1-1| ... | ... | @@ -277,7 +277,7 @@ pub fn Field(comptime params: FieldParams) type { |
| 277 | 277 | |
| 278 | 278 | // x=x2^((field_order+1)/4) w/ field order=3 (mod 4). |
| 279 | 279 | fn uncheckedSqrt(x2: Fe) Fe { |
| 280 | comptime debug.assert(field_order % 4 == 3); | |
| 280 | if (field_order % 4 != 3) @compileError("unimplemented"); | |
| 281 | 281 | if (field_order == 115792089210356248762697446949407573530086143415290314195533631308867097853951) { |
| 282 | 282 | const t11 = x2.mul(x2.sq()); |
| 283 | 283 | const t1111 = t11.mul(t11.sqn(2)); |
lib/std/crypto/pcurves/p256/scalar.zig+2-2| ... | ... | @@ -39,7 +39,7 @@ pub fn reduce48(s: [48]u8, endian: std.builtin.Endian) CompressedScalar { |
| 39 | 39 | |
| 40 | 40 | /// Reduce a 64-bytes scalar to the field size. |
| 41 | 41 | pub fn reduce64(s: [64]u8, endian: std.builtin.Endian) CompressedScalar { |
| 42 | return ScalarDouble.fromBytes64(s, endian).toBytes(endian); | |
| 42 | return Scalar.fromBytes64(s, endian).toBytes(endian); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /// Return a*b (mod L) |
| ... | ... | @@ -160,7 +160,7 @@ pub const Scalar = struct { |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /// Return true if n is a quadratic residue mod L. |
| 163 | pub fn isSquare(n: Scalar) Scalar { | |
| 163 | pub fn isSquare(n: Scalar) bool { | |
| 164 | 164 | return n.fe.isSquare(); |
| 165 | 165 | } |
| 166 | 166 |
lib/std/crypto/pcurves/p384/scalar.zig+2-2| ... | ... | @@ -34,7 +34,7 @@ pub fn rejectNonCanonical(s: CompressedScalar, endian: std.builtin.Endian) NonCa |
| 34 | 34 | |
| 35 | 35 | /// Reduce a 64-bytes scalar to the field size. |
| 36 | 36 | pub fn reduce64(s: [64]u8, endian: std.builtin.Endian) CompressedScalar { |
| 37 | return ScalarDouble.fromBytes64(s, endian).toBytes(endian); | |
| 37 | return Scalar.fromBytes64(s, endian).toBytes(endian); | |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /// Return a*b (mod L) |
| ... | ... | @@ -149,7 +149,7 @@ pub const Scalar = struct { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /// Return true if n is a quadratic residue mod L. |
| 152 | pub fn isSquare(n: Scalar) Scalar { | |
| 152 | pub fn isSquare(n: Scalar) bool { | |
| 153 | 153 | return n.fe.isSquare(); |
| 154 | 154 | } |
| 155 | 155 |
lib/std/crypto/pcurves/secp256k1.zig+1-1| ... | ... | @@ -221,7 +221,7 @@ pub const Secp256k1 = struct { |
| 221 | 221 | var t0 = p.x.mul(q.x); |
| 222 | 222 | var t1 = p.y.mul(q.y); |
| 223 | 223 | var t3 = q.x.add(q.y); |
| 224 | var t4 = p.x.add(p.y1); | |
| 224 | var t4 = p.x.add(p.y); | |
| 225 | 225 | t3 = t3.mul(t4); |
| 226 | 226 | t4 = t0.add(t1); |
| 227 | 227 | t3 = t3.sub(t4); |
lib/std/crypto/pcurves/secp256k1/scalar.zig+2-2| ... | ... | @@ -39,7 +39,7 @@ pub fn reduce48(s: [48]u8, endian: std.builtin.Endian) CompressedScalar { |
| 39 | 39 | |
| 40 | 40 | /// Reduce a 64-bytes scalar to the field size. |
| 41 | 41 | pub fn reduce64(s: [64]u8, endian: std.builtin.Endian) CompressedScalar { |
| 42 | return ScalarDouble.fromBytes64(s, endian).toBytes(endian); | |
| 42 | return Scalar.fromBytes64(s, endian).toBytes(endian); | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /// Return a*b (mod L) |
| ... | ... | @@ -160,7 +160,7 @@ pub const Scalar = struct { |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /// Return true if n is a quadratic residue mod L. |
| 163 | pub fn isSquare(n: Scalar) Scalar { | |
| 163 | pub fn isSquare(n: Scalar) bool { | |
| 164 | 164 | return n.fe.isSquare(); |
| 165 | 165 | } |
| 166 | 166 |