Skip to content

Commit

Permalink
zero points, allow gt one flexible allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchhill committed Oct 1, 2024
1 parent a63bee8 commit 685aeb2
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/Nethermind.Crypto.Bls/Bls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ public P1Affine()
public P1Affine(scoped ReadOnlySpan<byte> inp) : this()
=> Decode(inp);

public readonly void Zero()
=> _point.Clear();
public void Decode(scoped ReadOnlySpan<byte> inp)
{
int len = inp.Length;
Expand Down Expand Up @@ -644,6 +646,8 @@ public P1(SecretKey sk) : this()
public P1(scoped ReadOnlySpan<byte> inp) : this()
=> Decode(inp);

public readonly void Zero()
=> _point.Clear();
public void Decode(scoped ReadOnlySpan<byte> inp)
{
int len = inp.Length;
Expand Down Expand Up @@ -948,6 +952,8 @@ public P2Affine()
public P2Affine(scoped ReadOnlySpan<byte> inp) : this()
=> Decode(inp);

public readonly void Zero()
=> _point.Clear();
public void Decode(scoped ReadOnlySpan<byte> inp)
{
int len = inp.Length;
Expand Down Expand Up @@ -1136,6 +1142,11 @@ public P2(SecretKey sk) : this()
public P2(scoped ReadOnlySpan<byte> inp) : this()
=> Decode(inp);

public P2(P2Affine affine) : this()
{ blst_p2_from_affine(_point, affine.Point); }

public readonly void Zero()
=> _point.Clear();
public void Decode(scoped ReadOnlySpan<byte> inp)
{
int len = inp.Length;
Expand Down Expand Up @@ -1176,9 +1187,6 @@ public void Decode(ReadOnlySpan<byte> fp1, ReadOnlySpan<byte> fp2, ReadOnlySpan<
blst_p2_from_affine(_point, _point);
}

public P2(P2Affine affine) : this()
{ blst_p2_from_affine(_point, affine.Point); }

public readonly P2 Dup() => new(this);
public readonly P2Affine ToAffine() => new(this);
public readonly byte[] Serialize()
Expand Down Expand Up @@ -1465,8 +1473,17 @@ public static bool FinalVerify(PT gt1, PT gt2)
public static PT One()
{
long[] res = new long[Sz];
Marshal.Copy(blst_fp12_one(), res, 0, Sz);
return new(res);
return One(res);
}

public unsafe static PT One(Span<long> p)
{
int s = (int)blst_fp12_sizeof();
fixed (long* dest = p)
{
Buffer.MemoryCopy((byte*)blst_fp12_one(), dest, s, s);
}
return new(p);
}
}

Expand Down

0 comments on commit 685aeb2

Please sign in to comment.