|
@@ -23,7 +23,7 @@ interface
|
|
|
|
|
|
|
|
uses
|
|
uses
|
|
|
SysUtils,
|
|
SysUtils,
|
|
|
- Generics.Collections,
|
|
|
|
|
|
|
+ Classes,
|
|
|
HlpIHash,
|
|
HlpIHash,
|
|
|
ClpISigner,
|
|
ClpISigner,
|
|
|
ClpSecureRandom,
|
|
ClpSecureRandom,
|
|
@@ -65,7 +65,7 @@ type
|
|
|
FVariant: String;
|
|
FVariant: String;
|
|
|
FforSigning: Boolean;
|
|
FforSigning: Boolean;
|
|
|
Fkey: IECKeyParameters;
|
|
Fkey: IECKeyParameters;
|
|
|
- Fm_list: TList<TCryptoLibByteArray>;
|
|
|
|
|
|
|
+ FBuffer: TMemoryStream;
|
|
|
|
|
|
|
|
function Aggregate: TCryptoLibByteArray;
|
|
function Aggregate: TCryptoLibByteArray;
|
|
|
|
|
|
|
@@ -248,33 +248,16 @@ begin
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TECSchnorrSigner.Aggregate: TCryptoLibByteArray;
|
|
function TECSchnorrSigner.Aggregate: TCryptoLibByteArray;
|
|
|
-var
|
|
|
|
|
- sum, index: Int32;
|
|
|
|
|
- arr: TCryptoLibByteArray;
|
|
|
|
|
begin
|
|
begin
|
|
|
- sum := 0;
|
|
|
|
|
- for arr in Fm_list do
|
|
|
|
|
- begin
|
|
|
|
|
- sum := sum + System.length(arr);
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
- System.SetLength(Result, sum);
|
|
|
|
|
- index := 0;
|
|
|
|
|
-
|
|
|
|
|
- for arr in Fm_list do
|
|
|
|
|
-
|
|
|
|
|
- begin
|
|
|
|
|
- System.Move(arr[0], Result[index], System.length(arr) *
|
|
|
|
|
- System.SizeOf(Byte));
|
|
|
|
|
- index := index + System.length(arr);
|
|
|
|
|
- end;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ FBuffer.Position := 0;
|
|
|
|
|
+ System.SetLength(Result, FBuffer.Size);
|
|
|
|
|
+ FBuffer.Read(Result[0], FBuffer.Size);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
procedure TECSchnorrSigner.BlockUpdate(input: TCryptoLibByteArray;
|
|
procedure TECSchnorrSigner.BlockUpdate(input: TCryptoLibByteArray;
|
|
|
inOff, length: Int32);
|
|
inOff, length: Int32);
|
|
|
begin
|
|
begin
|
|
|
- Fm_list.Add(System.Copy(input, inOff, length));
|
|
|
|
|
|
|
+ FBuffer.Write(input[inOff], length);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
constructor TECSchnorrSigner.Create(const digest: IHash;
|
|
constructor TECSchnorrSigner.Create(const digest: IHash;
|
|
@@ -283,12 +266,12 @@ begin
|
|
|
inherited Create();
|
|
inherited Create();
|
|
|
FDigest := digest;
|
|
FDigest := digest;
|
|
|
FVariant := schnorr_variant;
|
|
FVariant := schnorr_variant;
|
|
|
- Fm_list := TList<TCryptoLibByteArray>.Create();
|
|
|
|
|
|
|
+ FBuffer := TMemoryStream.Create();
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
destructor TECSchnorrSigner.Destroy;
|
|
destructor TECSchnorrSigner.Destroy;
|
|
|
begin
|
|
begin
|
|
|
- Fm_list.Free;
|
|
|
|
|
|
|
+ FBuffer.Free;
|
|
|
inherited Destroy;
|
|
inherited Destroy;
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
@@ -418,7 +401,7 @@ function TECSchnorrSigner.Do_Verify(const pu_key: IECPublicKeyParameters;
|
|
|
var
|
|
var
|
|
|
curve: IECCurve;
|
|
curve: IECCurve;
|
|
|
n, r, s, h, v: TBigInteger;
|
|
n, r, s, h, v: TBigInteger;
|
|
|
- size: Int32;
|
|
|
|
|
|
|
+ Size: Int32;
|
|
|
G, q, sG, rW, hW, LR: IECPoint;
|
|
G, q, sG, rW, hW, LR: IECPoint;
|
|
|
xQ, yQ, tempV, tempH, rb: TCryptoLibByteArray;
|
|
xQ, yQ, tempV, tempH, rb: TCryptoLibByteArray;
|
|
|
R_and_S: TCryptoLibGenericArray<TBigInteger>;
|
|
R_and_S: TCryptoLibGenericArray<TBigInteger>;
|
|
@@ -431,14 +414,14 @@ begin
|
|
|
curve := pu_key.parameters.curve;
|
|
curve := pu_key.parameters.curve;
|
|
|
n := curve.order;
|
|
n := curve.order;
|
|
|
G := pu_key.parameters.G;
|
|
G := pu_key.parameters.G;
|
|
|
- size := TBits.Asr32(curve.FieldSize, 3);
|
|
|
|
|
|
|
+ Size := TBits.Asr32(curve.FieldSize, 3);
|
|
|
|
|
|
|
|
R_and_S := Decode_Sig(sig);
|
|
R_and_S := Decode_Sig(sig);
|
|
|
|
|
|
|
|
r := R_and_S[0];
|
|
r := R_and_S[0];
|
|
|
s := R_and_S[1];
|
|
s := R_and_S[1];
|
|
|
|
|
|
|
|
- if (not(r.IsInitialized) or (r.CompareTo(TBigInteger.Two.Pow(size * 8)
|
|
|
|
|
|
|
+ if (not(r.IsInitialized) or (r.CompareTo(TBigInteger.Two.Pow(Size * 8)
|
|
|
.Subtract(TBigInteger.One)) = 1) or (s.CompareTo(TBigInteger.Zero) = 0) or
|
|
.Subtract(TBigInteger.One)) = 1) or (s.CompareTo(TBigInteger.Zero) = 0) or
|
|
|
(s.CompareTo(n.Subtract(TBigInteger.One)) = 1)) then
|
|
(s.CompareTo(n.Subtract(TBigInteger.One)) = 1)) then
|
|
|
begin
|
|
begin
|
|
@@ -591,7 +574,8 @@ end;
|
|
|
procedure TECSchnorrSigner.Reset;
|
|
procedure TECSchnorrSigner.Reset;
|
|
|
begin
|
|
begin
|
|
|
FDigest.Initialize;
|
|
FDigest.Initialize;
|
|
|
- Fm_list.Clear;
|
|
|
|
|
|
|
+ FBuffer.Clear;
|
|
|
|
|
+ FBuffer.SetSize(0);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TECSchnorrSigner.Sign_K(const pv_key: IECPrivateKeyParameters;
|
|
function TECSchnorrSigner.Sign_K(const pv_key: IECPrivateKeyParameters;
|
|
@@ -602,7 +586,7 @@ end;
|
|
|
|
|
|
|
|
procedure TECSchnorrSigner.Update(input: Byte);
|
|
procedure TECSchnorrSigner.Update(input: Byte);
|
|
|
begin
|
|
begin
|
|
|
- Fm_list.Add(TCryptoLibByteArray.Create(input));
|
|
|
|
|
|
|
+ FBuffer.Write(TCryptoLibByteArray.Create(input)[0], 1);
|
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
function TECSchnorrSigner.VerifySignature
|
|
function TECSchnorrSigner.VerifySignature
|