diff --git a/CryptoLib/src/Crypto/Engines/ClpChaCha7539Engine.pas b/CryptoLib/src/Crypto/Engines/ClpChaCha7539Engine.pas index 31bb7091..76620834 100644 --- a/CryptoLib/src/Crypto/Engines/ClpChaCha7539Engine.pas +++ b/CryptoLib/src/Crypto/Engines/ClpChaCha7539Engine.pas @@ -164,7 +164,7 @@ procedure TChaCha7539Engine.SetKey(const AKeyBytes, [AlgorithmName]); end; - PackTauOrSigma(System.Length(AKeyBytes), FEngineState, 0); + PackTauOrSigma(32, FEngineState); // Key TPack.LE_To_UInt32(AKeyBytes, 0, FEngineState, 4, 8); diff --git a/CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas b/CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas index 08558b89..ccca9d0f 100644 --- a/CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas +++ b/CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas @@ -296,7 +296,7 @@ procedure TChaChaEngine.SetKey(const AKeyBytes, AIvBytes: TCryptoLibByteArray); [AlgorithmName]); end; - PackTauOrSigma(System.Length(AKeyBytes), FEngineState, 0); + PackTauOrSigma(System.Length(AKeyBytes), FEngineState); // Key TPack.LE_To_UInt32(AKeyBytes, 0, FEngineState, 4, 4); @@ -339,7 +339,7 @@ class procedure TChaChaEngine.HChaCha20(const AKey256, ANonce128: TCryptoLibByte end; System.SetLength(LState, 16); - PackTauOrSigma(32, LState, 0); + PackTauOrSigma(32, LState); TPack.LE_To_UInt32(AKey256, 0, LState, 4, 8); TPack.LE_To_UInt32(ANonce128, 0, LState, 12, 4); diff --git a/CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas b/CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas index aef6a7ff..88732091 100644 --- a/CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas +++ b/CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas @@ -113,7 +113,7 @@ TSalsa20Engine = class(TInterfacedObject, ISalsa20Engine, IStreamCipher) /// class function R(AX: UInt32; AY: Int32): UInt32; static; inline; class procedure PackTauOrSigma(AKeyLength: Int32; - const AState: TCryptoLibUInt32Array; AStateOffset: Int32); static; + const AState: TCryptoLibUInt32Array); static; class procedure SalsaCore(ARounds: Int32; const AInput, AX: TCryptoLibUInt32Array); static; @@ -364,15 +364,15 @@ procedure TSalsa20Engine.ProcessBlocks2( end; class procedure TSalsa20Engine.PackTauOrSigma(AKeyLength: Int32; - const AState: TCryptoLibUInt32Array; AStateOffset: Int32); + const AState: TCryptoLibUInt32Array); var LTsOff: Int32; begin - LTsOff := (AKeyLength - 16) div 4; - AState[AStateOffset] := TAU_SIGMA[LTsOff]; - AState[AStateOffset + 1] := TAU_SIGMA[LTsOff + 1]; - AState[AStateOffset + 2] := TAU_SIGMA[LTsOff + 2]; - AState[AStateOffset + 3] := TAU_SIGMA[LTsOff + 3]; + LTsOff := (AKeyLength div 4) - 4; + AState[0] := TAU_SIGMA[LTsOff]; + AState[1] := TAU_SIGMA[LTsOff + 1]; + AState[2] := TAU_SIGMA[LTsOff + 2]; + AState[3] := TAU_SIGMA[LTsOff + 3]; end; procedure TSalsa20Engine.ProcessBytes(const AInBytes: TCryptoLibByteArray;