diff --git a/src/Neo.Cryptography.BLS12_381/Fp.cs b/src/Neo.Cryptography.BLS12_381/Fp.cs index d724ef5..d0024c2 100644 --- a/src/Neo.Cryptography.BLS12_381/Fp.cs +++ b/src/Neo.Cryptography.BLS12_381/Fp.cs @@ -26,7 +26,7 @@ namespace Neo.Cryptography.BLS12_381; public static Fp FromBytes(ReadOnlySpan data) { if (data.Length != Size) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size} bytes."); Span tmp = stackalloc ulong[SizeL]; BinaryPrimitives.TryReadUInt64BigEndian(data[0..8], out tmp[5]); @@ -63,6 +63,9 @@ public static Fp FromBytes(ReadOnlySpan data) internal static Fp FromRawUnchecked(ulong[] values) { + if (values.Length != SizeL) + throw new FormatException($"The argument `{nameof(values)}` must contain {SizeL} entries."); + return MemoryMarshal.Cast(values)[0]; } diff --git a/src/Neo.Cryptography.BLS12_381/Fp12.cs b/src/Neo.Cryptography.BLS12_381/Fp12.cs index 60ad044..cad6303 100644 --- a/src/Neo.Cryptography.BLS12_381/Fp12.cs +++ b/src/Neo.Cryptography.BLS12_381/Fp12.cs @@ -47,7 +47,7 @@ public Fp12(in Fp6 c0, in Fp6 c1) public static Fp12 FromBytes(ReadOnlySpan data) { if (data.Length != Size) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size} bytes."); Fp6 c0 = Fp6.FromBytes(data[Fp6.Size..]); Fp6 c1 = Fp6.FromBytes(data[..Fp6.Size]); return new(in c0, in c1); diff --git a/src/Neo.Cryptography.BLS12_381/Fp2.cs b/src/Neo.Cryptography.BLS12_381/Fp2.cs index 8c318a5..ae053ca 100644 --- a/src/Neo.Cryptography.BLS12_381/Fp2.cs +++ b/src/Neo.Cryptography.BLS12_381/Fp2.cs @@ -38,7 +38,7 @@ public Fp2(in Fp c0, in Fp c1) public static Fp2 FromBytes(ReadOnlySpan data) { if (data.Length != Size) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size} bytes."); Fp c0 = Fp.FromBytes(data[Fp.Size..]); Fp c1 = Fp.FromBytes(data[..Fp.Size]); return new(in c0, in c1); diff --git a/src/Neo.Cryptography.BLS12_381/Fp6.cs b/src/Neo.Cryptography.BLS12_381/Fp6.cs index 3261e30..18c4418 100644 --- a/src/Neo.Cryptography.BLS12_381/Fp6.cs +++ b/src/Neo.Cryptography.BLS12_381/Fp6.cs @@ -45,7 +45,7 @@ public Fp6(in Fp2 c0, in Fp2 c1, in Fp2 c2) public static Fp6 FromBytes(ReadOnlySpan data) { if (data.Length != Size) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size} bytes."); Fp2 c0 = Fp2.FromBytes(data[(Fp2.Size * 2)..]); Fp2 c1 = Fp2.FromBytes(data[Fp2.Size..(Fp2.Size * 2)]); Fp2 c2 = Fp2.FromBytes(data[..Fp2.Size]); diff --git a/src/Neo.Cryptography.BLS12_381/G1Projective.cs b/src/Neo.Cryptography.BLS12_381/G1Projective.cs index 0d9eba0..93bfb95 100644 --- a/src/Neo.Cryptography.BLS12_381/G1Projective.cs +++ b/src/Neo.Cryptography.BLS12_381/G1Projective.cs @@ -205,7 +205,7 @@ public G1Projective Double() { int length = b.Length; if (length != 32) - throw new ArgumentException($"The argument {nameof(b)} should be 32 bytes."); + throw new ArgumentException($"The argument {nameof(b)} must be 32 bytes."); G1Projective acc = Identity; diff --git a/src/Neo.Cryptography.BLS12_381/Scalar.cs b/src/Neo.Cryptography.BLS12_381/Scalar.cs index 5a3ea10..922f5bc 100644 --- a/src/Neo.Cryptography.BLS12_381/Scalar.cs +++ b/src/Neo.Cryptography.BLS12_381/Scalar.cs @@ -24,9 +24,12 @@ namespace Neo.Cryptography.BLS12_381; internal Scalar(ulong[] values) { + if (values.Length != SizeL) + throw new FormatException($"The argument `{nameof(values)}` must contain {SizeL} entries."); + // This internal method is only used by the constants classes. // The data must be in the correct format. - // So, there is no need to do any checks. + // So, there is no need to do any additional checks. this = MemoryMarshal.AsRef(MemoryMarshal.Cast(values)); } @@ -47,7 +50,7 @@ public Scalar(RandomNumberGenerator rng) public static Scalar FromBytes(ReadOnlySpan data) { if (data.Length != Size) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size} bytes."); ref readonly Scalar ref_ = ref MemoryMarshal.AsRef(data); @@ -77,7 +80,7 @@ public static Scalar FromBytes(ReadOnlySpan data) public static Scalar FromBytesWide(ReadOnlySpan data) { if (data.Length != Size * 2) - throw new FormatException($"The argument `{nameof(data)}` should contain {Size * 2} bytes."); + throw new FormatException($"The argument `{nameof(data)}` must contain {Size * 2} bytes."); ReadOnlySpan d = MemoryMarshal.Cast(data); return d[0] * R2 + d[1] * R3; @@ -85,6 +88,9 @@ public static Scalar FromBytesWide(ReadOnlySpan data) public static Scalar FromRaw(ReadOnlySpan data) { + if (data.Length != SizeL) + throw new FormatException($"The argument `{nameof(data)}` must contain {SizeL} entries."); + ReadOnlySpan span = MemoryMarshal.Cast(data); return span[0] * R2; }