Browse Source

some code refactoring.

Ugochukwu Mmaduekwe 6 years ago
parent
commit
b66fb947b3

+ 3 - 0
CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr

@@ -284,6 +284,9 @@ uses
   ClpChaChaEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpChaChaEngine.pas',
   ClpRijndaelEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRijndaelEngine.pas',
   ClpIRijndaelEngine in '..\..\CryptoLib\src\Interfaces\ClpIRijndaelEngine.pas',
+  ClpIAlgorithmParameterSpec in '..\..\CryptoLib\src\Interfaces\ClpIAlgorithmParameterSpec.pas',
+  ClpIIESParameterSpec in '..\..\CryptoLib\src\Interfaces\ClpIIESParameterSpec.pas',
+  ClpIESParameterSpec in '..\..\CryptoLib\src\Crypto\Parameters\ClpIESParameterSpec.pas',
   UsageExamples in '..\src\UsageExamples.pas';
 
 begin

+ 9 - 9
CryptoLib.Samples/src/UsageExamples.pas

@@ -60,8 +60,8 @@ uses
   // ClpIESEngine,
   ClpPascalCoinIESEngine,
   ClpIPascalCoinIESEngine,
-  ClpIIESWithCipherParameters,
-  ClpIESWithCipherParameters,
+  ClpIIESParameterSpec,
+  ClpIESParameterSpec,
   ClpIAesEngine,
   ClpAesEngine,
   ClpIBlockCipherModes,
@@ -138,7 +138,7 @@ type
     class function GetECIESPascalCoinCompatibilityEngine
       : IPascalCoinIESEngine; static;
     class function GetECKeyPair: IAsymmetricCipherKeyPair; static;
-    class function GetIESCipherParameters: IIESWithCipherParameters; static;
+    class function GetIESParameterSpec: IIESParameterSpec; static;
 
     class function ECIESPascalCoinEncrypt(const PublicKey
       : IAsymmetricKeyParameter; PlainText: TBytes): TBytes; static;
@@ -184,7 +184,7 @@ var
 begin
   // Decryption
   CipherDecrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine);
-  CipherDecrypt.Init(False, PrivateKey, GetIESCipherParameters, FRandom);
+  CipherDecrypt.Init(False, PrivateKey, GetIESParameterSpec, FRandom);
   PlainText := CipherDecrypt.DoFinal(CipherText);
   result := True;
 end;
@@ -196,7 +196,7 @@ var
 begin
   // Encryption
   CipherEncrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine);
-  CipherEncrypt.Init(True, PublicKey, GetIESCipherParameters, FRandom);
+  CipherEncrypt.Init(True, PublicKey, GetIESParameterSpec, FRandom);
   result := CipherEncrypt.DoFinal(PlainText);
 end;
 
@@ -714,13 +714,13 @@ begin
 
 end;
 
-class function TUsageExamples.GetIESCipherParameters: IIESWithCipherParameters;
+class function TUsageExamples.GetIESParameterSpec: IIESParameterSpec;
 var
   Derivation, Encoding, IVBytes: TBytes;
   MacKeySizeInBits, CipherKeySizeInBits: Int32;
   UsePointCompression: Boolean;
 begin
-  // Set up  IES Cipher Parameters For Compatibility With PascalCoin Current Implementation
+  // Set up  IES Parameter Spec For Compatibility With PascalCoin Current Implementation
 
   // The derivation and encoding vectors are used when initialising the KDF and MAC.
   // They're optional but if used then they need to be known by the other user so that
@@ -741,8 +741,8 @@ begin
   // from a point or not in the EphemeralKeyPairGenerator
   UsePointCompression := True; // for compatibility
 
-  result := TIESWithCipherParameters.Create(Derivation, Encoding,
-    MacKeySizeInBits, CipherKeySizeInBits, IVBytes, UsePointCompression);
+  result := TIESParameterSpec.Create(Derivation, Encoding, MacKeySizeInBits,
+    CipherKeySizeInBits, IVBytes, UsePointCompression);
 end;
 
 class procedure TUsageExamples.GetPublicKeyFromPrivateKey();

+ 3 - 0
CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.TestInsight.dpr

@@ -294,6 +294,9 @@ uses
   ClpChaChaEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpChaChaEngine.pas',
   ClpRijndaelEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRijndaelEngine.pas',
   ClpIRijndaelEngine in '..\..\CryptoLib\src\Interfaces\ClpIRijndaelEngine.pas',
+  ClpIAlgorithmParameterSpec in '..\..\CryptoLib\src\Interfaces\ClpIAlgorithmParameterSpec.pas',
+  ClpIIESParameterSpec in '..\..\CryptoLib\src\Interfaces\ClpIIESParameterSpec.pas',
+  ClpIESParameterSpec in '..\..\CryptoLib\src\Crypto\Parameters\ClpIESParameterSpec.pas',
   ClpFixedSecureRandom in '..\src\Utils\ClpFixedSecureRandom.pas',
   ClpIFixedSecureRandom in '..\src\Utils\ClpIFixedSecureRandom.pas',
   BlowfishTestVectors in '..\src\Crypto\BlowfishTestVectors.pas',

+ 13 - 12
CryptoLib.Tests/src/Math/IESCipherTests.pas

@@ -36,8 +36,9 @@ uses
   ClpIAesEngine,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpGeneratorUtilities,
-  ClpIESWithCipherParameters,
-  ClpIIESWithCipherParameters,
+  ClpIESParameterSpec,
+  ClpIIESParameterSpec,
+  ClpIAlgorithmParameterSpec,
   // ClpKeyParameter,
   // ClpIKeyParameter,
   // ClpParametersWithIV,
@@ -87,11 +88,11 @@ type
 
     function GetECIESAES256CBCEngine: IIESEngine;
     function GetECKeyPair: IAsymmetricCipherKeyPair;
-    function GetIESWithCipherParameters: IIESWithCipherParameters;
+    function GetIESParameterSpec: IAlgorithmParameterSpec;
 
-    procedure doIESCipher_Encryption_Decryption_TestWithIV
+    procedure DoIESCipher_Encryption_Decryption_TestWithIV
       (const KeyPair: IAsymmetricCipherKeyPair;
-      const param: IIESWithCipherParameters; const Random: ISecureRandom;
+      const param: IAlgorithmParameterSpec; const Random: ISecureRandom;
       const PlainText: String);
 
   protected
@@ -107,9 +108,9 @@ implementation
 
 { TTestIESCipher }
 
-procedure TTestIESCipher.doIESCipher_Encryption_Decryption_TestWithIV
+procedure TTestIESCipher.DoIESCipher_Encryption_Decryption_TestWithIV
   (const KeyPair: IAsymmetricCipherKeyPair;
-  const param: IIESWithCipherParameters; const Random: ISecureRandom;
+  const param: IAlgorithmParameterSpec; const Random: ISecureRandom;
   const PlainText: String);
 var
   PlainTextBytes, CipherTextBytes, DecryptionResultBytes: TBytes;
@@ -193,7 +194,7 @@ begin
   result := KeyPairGeneratorInstance.GenerateKeyPair();
 end;
 
-function TTestIESCipher.GetIESWithCipherParameters: IIESWithCipherParameters;
+function TTestIESCipher.GetIESParameterSpec: IAlgorithmParameterSpec;
 var
   Derivation, Encoding, IVBytes: TBytes;
   MacKeySizeInBits, CipherKeySizeInBits: Int32;
@@ -219,8 +220,8 @@ begin
   // from a point or not in the EphemeralKeyPairGenerator
   UsePointCompression := False;
 
-  result := TIESWithCipherParameters.Create(Derivation, Encoding,
-    MacKeySizeInBits, CipherKeySizeInBits, IVBytes, UsePointCompression);
+  result := TIESParameterSpec.Create(Derivation, Encoding, MacKeySizeInBits,
+    CipherKeySizeInBits, IVBytes, UsePointCompression);
 
 end;
 
@@ -253,8 +254,8 @@ begin
 
     // Call IESCipher Encryption and Decryption Method
 
-    doIESCipher_Encryption_Decryption_TestWithIV(GetECKeyPair,
-      GetIESWithCipherParameters, RandomInstance, PlainText);
+    DoIESCipher_Encryption_Decryption_TestWithIV(GetECKeyPair,
+      GetIESParameterSpec, RandomInstance, PlainText);
 
     System.Inc(I);
   end;

+ 21 - 21
CryptoLib/src/Crypto/ClpIESCipher.pas

@@ -28,7 +28,8 @@ uses
   ClpIECIESPublicKeyParser,
   ClpECIESPublicKeyParser,
   ClpIAsymmetricKeyParameter,
-  ClpIIESWithCipherParameters,
+  ClpIAlgorithmParameterSpec,
+  ClpIIESParameterSpec,
   ClpICipherParameters,
   ClpIParametersWithRandom,
   ClpIECKeyParameters,
@@ -53,10 +54,10 @@ resourcestring
     'Must be Passed Recipient''s Public EC Key for Encryption';
   SInvalidPrivateKey =
     'Must be Passed Recipient''s Private EC Key for Decryption';
-  SIESCipherParameterNil = 'IES Cipher Parameters Cannot Be Nil';
+  SIAlgorithmParameterSpecNil = 'Parameter Spec Cannot Be Nil';
   SUnableToProcessBlock = 'Unable to Process Block. "%s"';
-  SIESCipherParameterError = 'IES Cipher Parameter Error';
-  SNonceInvalidLength = 'NONCE in IES Parameters Needs to be "%s" Bytes Long';
+  SIESParameterSpecError = 'Must be Passed IES Parameter Spec';
+  SNonceInvalidLength = 'Nonce in IES Parameters Needs to be "%s" Bytes Long';
 
 type
   TIESCipher = class sealed(TInterfacedObject, IIESCipher)
@@ -67,7 +68,7 @@ type
     FEngine: IIESEngine;
     FForEncryption: Boolean;
     FBuffer: TMemoryStream;
-    FIESCipherParameters: IIESWithCipherParameters;
+    FEngineSpec: IIESParameterSpec;
     Fkey: IAsymmetricKeyParameter;
     FRandom: ISecureRandom;
 
@@ -75,8 +76,7 @@ type
 
   public
     procedure Init(ForEncryption: Boolean; const Key: ICipherParameters;
-      const IESCipherParameters: IIESWithCipherParameters;
-      const Random: ISecureRandom);
+      const EngineSpec: IAlgorithmParameterSpec; const Random: ISecureRandom);
 
     procedure ProcessBytes(const input: TCryptoLibByteArray); overload;
     procedure ProcessBytes(const input: TCryptoLibByteArray;
@@ -142,13 +142,13 @@ begin
   FBuffer.SetSize(Int64(0));
 
   // Convert parameters for use in IESEngine
-  params := TIESWithCipherParameters.Create(FIESCipherParameters.GetDerivationV,
-    FIESCipherParameters.GetEncodingV, FIESCipherParameters.MacKeySize,
-    FIESCipherParameters.CipherKeySize);
+  params := TIESWithCipherParameters.Create(FEngineSpec.GetDerivationV,
+    FEngineSpec.GetEncodingV, FEngineSpec.MacKeySize,
+    FEngineSpec.CipherKeySize);
 
-  if (FIESCipherParameters.Nonce <> Nil) then
+  if (FEngineSpec.Nonce <> Nil) then
   begin
-    params := TParametersWithIV.Create(params, FIESCipherParameters.Nonce);
+    params := TParametersWithIV.Create(params, FEngineSpec.Nonce);
   end;
   ecParams := (Fkey as IECKeyParameters).Parameters;
 
@@ -159,7 +159,7 @@ begin
     gen.Init(TECKeyGenerationParameters.Create(ecParams, FRandom)
       as IECKeyGenerationParameters);
 
-    UsePointCompression := FIESCipherParameters.PointCompression;
+    UsePointCompression := FEngineSpec.PointCompression;
 
     kGen := TEphemeralKeyPairGenerator.Create(gen,
       TKeyEncoder.Create(UsePointCompression) as IKeyEncoder);
@@ -225,8 +225,7 @@ begin
 end;
 
 procedure TIESCipher.Init(ForEncryption: Boolean; const Key: ICipherParameters;
-  const IESCipherParameters: IIESWithCipherParameters;
-  const Random: ISecureRandom);
+  const EngineSpec: IAlgorithmParameterSpec; const Random: ISecureRandom);
 var
   LKey: ICipherParameters;
   Nonce: TCryptoLibByteArray;
@@ -234,21 +233,22 @@ begin
 
   FForEncryption := ForEncryption;
 
-  if (IESCipherParameters = Nil) then
+  if (EngineSpec = Nil) then
   begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SIESCipherParameterNil);
+    raise EArgumentNilCryptoLibException.CreateRes
+      (@SIAlgorithmParameterSpecNil);
   end
-  else if (Supports(IESCipherParameters, IIESWithCipherParameters)) then
+  else if (Supports(EngineSpec, IIESParameterSpec)) then
   begin
-    FIESCipherParameters := IESCipherParameters as IIESWithCipherParameters;
+    FEngineSpec := EngineSpec as IIESParameterSpec;
   end
   else
   begin
     raise EInvalidParameterCryptoLibException.CreateRes
-      (@SIESCipherParameterError);
+      (@SIESParameterSpecError);
   end;
 
-  Nonce := FIESCipherParameters.Nonce;
+  Nonce := FEngineSpec.Nonce;
 
   if ((FivLength <> 0) and ((Nonce = Nil) or (System.length(Nonce) <>
     FivLength))) then

+ 0 - 1
CryptoLib/src/Crypto/Engines/ClpPascalCoinIESEngine.pas

@@ -34,7 +34,6 @@ uses
   ClpIEphemeralKeyPair,
   ClpKdfParameters,
   ClpIKdfParameters,
-  ClpIIESWithCipherParameters,
   ClpIESEngine,
   ClpArrayUtils,
   ClpBigInteger,

+ 225 - 0
CryptoLib/src/Crypto/Parameters/ClpIESParameterSpec.pas

@@ -0,0 +1,225 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIESParameterSpec;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIIESParameterSpec,
+  ClpIAlgorithmParameterSpec,
+  ClpCryptoLibTypes;
+
+type
+
+  /// <summary>
+  /// Parameter spec for an integrated encryptor, as in IEEE P1363a
+  /// </summary>
+  TIESParameterSpec = class sealed(TInterfacedObject, IAlgorithmParameterSpec,
+    IIESParameterSpec)
+
+  strict private
+  var
+    Fderivation, Fencoding, FNonce: TCryptoLibByteArray;
+    FmacKeySize, FcipherKeySize: Int32;
+    FusePointCompression: Boolean;
+
+  strict private
+    function GetDerivationV: TCryptoLibByteArray; inline;
+    function GetEncodingV: TCryptoLibByteArray; inline;
+    function GetMacKeySize: Int32; inline;
+    function GetCipherKeySize: Int32; inline;
+    function GetNonce: TCryptoLibByteArray; inline;
+    function GetPointCompression: Boolean; inline;
+
+  public
+
+    /// <summary>
+    /// Set the IES engine parameters.
+    /// </summary>
+    /// <param name="derivation">
+    /// the optional derivation vector for the KDF.
+    /// </param>
+    /// <param name="encoding">
+    /// the optional encoding vector for the KDF.
+    /// </param>
+    /// <param name="macKeySize">
+    /// the key size (in bits) for the MAC.
+    /// </param>
+    constructor Create(const derivation, encoding: TCryptoLibByteArray;
+      MacKeySize: Int32); overload;
+
+    /// <summary>
+    /// Set the IES engine parameters.
+    /// </summary>
+    /// <param name="derivation">
+    /// the optional derivation vector for the KDF.
+    /// </param>
+    /// <param name="encoding">
+    /// the optional encoding vector for the KDF.
+    /// </param>
+    /// <param name="macKeySize">
+    /// the key size (in bits) for the MAC.
+    /// </param>
+    /// <param name="CipherKeySize">
+    /// the key size (in bits) for the block cipher.
+    /// </param>
+    /// <param name="Nonce">
+    /// an IV to use initialising the block cipher.
+    /// </param>
+    constructor Create(const derivation, encoding: TCryptoLibByteArray;
+      MacKeySize, CipherKeySize: Int32;
+      const Nonce: TCryptoLibByteArray = Nil); overload;
+
+    /// <summary>
+    /// Set the IES engine parameters.
+    /// </summary>
+    /// <param name="derivation">
+    /// the optional derivation vector for the KDF.
+    /// </param>
+    /// <param name="encoding">
+    /// the optional encoding vector for the KDF.
+    /// </param>
+    /// <param name="macKeySize">
+    /// the key size (in bits) for the MAC.
+    /// </param>
+    /// <param name="CipherKeySize">
+    /// the key size (in bits) for the block cipher.
+    /// </param>
+    /// <param name="Nonce">
+    /// an IV to use initialising the block cipher.
+    /// </param>
+    /// <param name="UsePointCompression">
+    /// whether to use EC point compression or not (false by default)
+    /// </param>
+    constructor Create(const derivation, encoding: TCryptoLibByteArray;
+      MacKeySize, CipherKeySize: Int32; const Nonce: TCryptoLibByteArray;
+      UsePointCompression: Boolean); overload;
+
+    /// <summary>
+    /// Returns the derivation vector.
+    /// </summary>
+    /// <value>
+    /// the derivation vector.
+    /// </value>
+    property DerivationV: TCryptoLibByteArray read GetDerivationV;
+
+    /// <summary>
+    /// Returns the encoding vector.
+    /// </summary>
+    /// <value>
+    /// the encoding vector.
+    /// </value>
+    property EncodingV: TCryptoLibByteArray read GetEncodingV;
+
+    /// <summary>
+    /// Return the key size in bits for the MAC used with the message
+    /// </summary>
+    /// <value>
+    /// the key size in bits for the MAC used with the message
+    /// </value>
+    property MacKeySize: Int32 read GetMacKeySize;
+
+    /// <summary>
+    /// Return the key size in bits for the block cipher used with the message
+    /// </summary>
+    /// <value>
+    /// the key size in bits for the block cipher used with the message
+    /// </value>
+    property CipherKeySize: Int32 read GetCipherKeySize;
+
+    /// <summary>
+    /// Return the Nonce (IV) value to be associated with message.
+    /// </summary>
+    /// <value>
+    /// block cipher IV for message.
+    /// </value>
+    property Nonce: TCryptoLibByteArray read GetNonce;
+
+    /// <summary>
+    /// Return the 'point compression' flag.
+    /// </summary>
+    /// <value>
+    /// the point compression flag
+    /// </value>
+    property PointCompression: Boolean read GetPointCompression;
+
+  end;
+
+implementation
+
+{ TIESParameterSpec }
+
+constructor TIESParameterSpec.Create(const derivation,
+  encoding: TCryptoLibByteArray; MacKeySize: Int32);
+begin
+  Create(derivation, encoding, MacKeySize, -1, Nil, false);
+end;
+
+constructor TIESParameterSpec.Create(const derivation,
+  encoding: TCryptoLibByteArray; MacKeySize, CipherKeySize: Int32;
+  const Nonce: TCryptoLibByteArray);
+begin
+  Create(derivation, encoding, MacKeySize, CipherKeySize, Nonce, false);
+end;
+
+constructor TIESParameterSpec.Create(const derivation,
+  encoding: TCryptoLibByteArray; MacKeySize, CipherKeySize: Int32;
+  const Nonce: TCryptoLibByteArray; UsePointCompression: Boolean);
+begin
+  Inherited Create();
+  Fderivation := derivation;
+  Fencoding := encoding;
+  FmacKeySize := MacKeySize;
+  FcipherKeySize := CipherKeySize;
+  FNonce := System.Copy(Nonce);
+  FusePointCompression := UsePointCompression;
+end;
+
+function TIESParameterSpec.GetCipherKeySize: Int32;
+begin
+  result := FcipherKeySize;
+end;
+
+function TIESParameterSpec.GetDerivationV: TCryptoLibByteArray;
+begin
+  result := System.Copy(Fderivation);
+end;
+
+function TIESParameterSpec.GetEncodingV: TCryptoLibByteArray;
+begin
+  result := System.Copy(Fencoding);
+end;
+
+function TIESParameterSpec.GetMacKeySize: Int32;
+begin
+  result := FmacKeySize;
+end;
+
+function TIESParameterSpec.GetNonce: TCryptoLibByteArray;
+begin
+  result := System.Copy(FNonce);
+end;
+
+function TIESParameterSpec.GetPointCompression: Boolean;
+begin
+  result := FusePointCompression;
+end;
+
+end.

+ 2 - 71
CryptoLib/src/Crypto/Parameters/ClpIESWithCipherParameters.pas

@@ -34,13 +34,9 @@ type
 
   strict private
   var
-    Fnonce: TCryptoLibByteArray;
     FcipherKeySize: Int32;
-    FusePointCompression: Boolean;
 
     function GetCipherKeySize: Int32; inline;
-    function GetNonce: TCryptoLibByteArray; inline;
-    function GetPointCompression: Boolean; inline;
   public
 
     /// <summary>
@@ -58,37 +54,8 @@ type
     /// <param name="CipherKeySize">
     /// the key size (in bits) for the block cipher.
     /// </param>
-    /// <param name="nonce">
-    /// an IV to use initialising the block cipher.
-    /// </param>
-    constructor Create(const derivation, encoding: TCryptoLibByteArray;
-      macKeySize, CipherKeySize: Int32;
-      const nonce: TCryptoLibByteArray = Nil); overload;
-
-    /// <summary>
-    /// Set the IES engine parameters.
-    /// </summary>
-    /// <param name="derivation">
-    /// the optional derivation vector for the KDF.
-    /// </param>
-    /// <param name="encoding">
-    /// the optional encoding vector for the KDF.
-    /// </param>
-    /// <param name="macKeySize">
-    /// the key size (in bits) for the MAC.
-    /// </param>
-    /// <param name="CipherKeySize">
-    /// the key size (in bits) for the block cipher.
-    /// </param>
-    /// <param name="nonce">
-    /// an IV to use initialising the block cipher.
-    /// </param>
-    /// <param name="UsePointCompression">
-    /// whether to use EC point compression or not (false by default)
-    /// </param>
     constructor Create(const derivation, encoding: TCryptoLibByteArray;
-      macKeySize, CipherKeySize: Int32; const nonce: TCryptoLibByteArray;
-      UsePointCompression: Boolean); overload;
+      macKeySize, CipherKeySize: Int32);
 
     /// <summary>
     /// Return the key size in bits for the block cipher used with the message
@@ -98,21 +65,6 @@ type
     /// </value>
     property CipherKeySize: Int32 read GetCipherKeySize;
 
-    /// <summary>
-    /// Return the nonce (IV) value to be associated with message.
-    /// </summary>
-    /// <value>
-    /// block cipher IV for message.
-    /// </value>
-    property nonce: TCryptoLibByteArray read GetNonce;
-
-    /// <summary>
-    /// Return the 'point compression' flag.
-    /// </summary>
-    /// <value>
-    /// the point compression flag
-    /// </value>
-    property PointCompression: Boolean read GetPointCompression;
   end;
 
 implementation
@@ -124,32 +76,11 @@ begin
   Result := FcipherKeySize;
 end;
 
-function TIESWithCipherParameters.GetNonce: TCryptoLibByteArray;
-begin
-  Result := System.Copy(Fnonce);
-end;
-
-function TIESWithCipherParameters.GetPointCompression: Boolean;
-begin
-  Result := FusePointCompression;
-end;
-
 constructor TIESWithCipherParameters.Create(const derivation,
-  encoding: TCryptoLibByteArray; macKeySize, CipherKeySize: Int32;
-  const nonce: TCryptoLibByteArray);
-begin
-  Create(derivation, encoding, macKeySize, CipherKeySize, nonce, false);
-end;
-
-constructor TIESWithCipherParameters.Create(const derivation,
-  encoding: TCryptoLibByteArray; macKeySize, CipherKeySize: Int32;
-  const nonce: TCryptoLibByteArray; UsePointCompression: Boolean);
+  encoding: TCryptoLibByteArray; macKeySize, CipherKeySize: Int32);
 begin
   Inherited Create(derivation, encoding, macKeySize);
-
   FcipherKeySize := CipherKeySize;
-  Fnonce := System.Copy(nonce);
-  FusePointCompression := UsePointCompression;
 end;
 
 end.

+ 31 - 0
CryptoLib/src/Interfaces/ClpIAlgorithmParameterSpec.pas

@@ -0,0 +1,31 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIAlgorithmParameterSpec;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+type
+  IAlgorithmParameterSpec = interface(IInterface)
+    ['{FBA69725-AEFF-4B99-92C0-1819E5DE2DA1}']
+  end;
+
+implementation
+
+end.

+ 2 - 2
CryptoLib/src/Interfaces/ClpIIESCipher.pas

@@ -24,7 +24,7 @@ interface
 uses
   ClpICipherParameters,
   ClpISecureRandom,
-  ClpIIESWithCipherParameters,
+  ClpIAlgorithmParameterSpec,
   ClpCryptoLibTypes;
 
 type
@@ -32,7 +32,7 @@ type
     ['{DD112FD3-844A-4EF0-B9B8-22AFAEFB0881}']
 
     procedure Init(ForEncryption: Boolean; const Key: ICipherParameters;
-      const engineSpec: IIESWithCipherParameters; const Random: ISecureRandom);
+      const engineSpec: IAlgorithmParameterSpec; const Random: ISecureRandom);
 
     procedure ProcessBytes(const input: TCryptoLibByteArray); overload;
     procedure ProcessBytes(const input: TCryptoLibByteArray;

+ 90 - 0
CryptoLib/src/Interfaces/ClpIIESParameterSpec.pas

@@ -0,0 +1,90 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIIESParameterSpec;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIAlgorithmParameterSpec,
+  ClpCryptoLibTypes;
+
+type
+  IIESParameterSpec = interface(IAlgorithmParameterSpec)
+    ['{F83CD14B-C049-4878-8D78-0214FD9D2B8A}']
+
+    /// <summary>
+    /// Returns the derivation vector.
+    /// </summary>
+    /// <value>
+    /// the derivation vector.
+    /// </value>
+    function GetDerivationV: TCryptoLibByteArray;
+    property DerivationV: TCryptoLibByteArray read GetDerivationV;
+
+    /// <summary>
+    /// Returns the encoding vector.
+    /// </summary>
+    /// <value>
+    /// the encoding vector.
+    /// </value>
+    function GetEncodingV: TCryptoLibByteArray;
+    property EncodingV: TCryptoLibByteArray read GetEncodingV;
+
+    /// <summary>
+    /// Return the key size in bits for the MAC used with the message
+    /// </summary>
+    /// <value>
+    /// the key size in bits for the MAC used with the message
+    /// </value>
+    function GetMacKeySize: Int32;
+    property MacKeySize: Int32 read GetMacKeySize;
+
+    /// <summary>
+    /// Return the key size in bits for the block cipher used with the message
+    /// </summary>
+    /// <value>
+    /// the key size in bits for the block cipher used with the message
+    /// </value>
+    function GetCipherKeySize: Int32;
+    property CipherKeySize: Int32 read GetCipherKeySize;
+
+    /// <summary>
+    /// Return the Nonce (IV) value to be associated with message.
+    /// </summary>
+    /// <value>
+    /// block cipher IV for message.
+    /// </value>
+    function GetNonce: TCryptoLibByteArray;
+    property Nonce: TCryptoLibByteArray read GetNonce;
+
+    /// <summary>
+    /// Return the 'point compression' flag.
+    /// </summary>
+    /// <value>
+    /// the point compression flag
+    /// </value>
+    function GetPointCompression: Boolean;
+    property PointCompression: Boolean read GetPointCompression;
+
+  end;
+
+implementation
+
+end.

+ 0 - 20
CryptoLib/src/Interfaces/ClpIIESWithCipherParameters.pas

@@ -40,26 +40,6 @@ type
     /// </value>
     property CipherKeySize: Int32 read GetCipherKeySize;
 
-    function GetNonce: TCryptoLibByteArray;
-
-    /// <summary>
-    /// Return the nonce (IV) value to be associated with message.
-    /// </summary>
-    /// <value>
-    /// block cipher IV for message.
-    /// </value>
-    property Nonce: TCryptoLibByteArray read GetNonce;
-
-    function GetPointCompression: Boolean;
-
-    /// <summary>
-    /// Return the 'point compression' flag.
-    /// </summary>
-    /// <value>
-    /// the point compression flag
-    /// </value>
-    property PointCompression: Boolean read GetPointCompression;
-
   end;
 
 implementation

+ 13 - 1
CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk

@@ -25,7 +25,7 @@
  Acknowledgements: 
 Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the development of this library "/>
     <Version Major="3" Minor="1"/>
-    <Files Count="281">
+    <Files Count="284">
       <Item1>
         <Filename Value="..\..\Asn1\ClpOidTokenizer.pas"/>
         <UnitName Value="ClpOidTokenizer"/>
@@ -1152,6 +1152,18 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel
         <Filename Value="..\..\Crypto\Engines\ClpRijndaelEngine.pas"/>
         <UnitName Value="ClpRijndaelEngine"/>
       </Item281>
+      <Item282>
+        <Filename Value="..\..\Interfaces\ClpIIESParameterSpec.pas"/>
+        <UnitName Value="ClpIIESParameterSpec"/>
+      </Item282>
+      <Item283>
+        <Filename Value="..\..\Interfaces\ClpIAlgorithmParameterSpec.pas"/>
+        <UnitName Value="ClpIAlgorithmParameterSpec"/>
+      </Item283>
+      <Item284>
+        <Filename Value="..\..\Crypto\Parameters\ClpIESParameterSpec.pas"/>
+        <UnitName Value="ClpIESParameterSpec"/>
+      </Item284>
     </Files>
     <RequiredPkgs Count="3">
       <Item1>

+ 2 - 1
CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas

@@ -98,7 +98,8 @@ uses
   ClpSpeckEngine, ClpIBufferedStreamCipher, ClpIChaChaEngine, 
   ClpIXSalsa20Engine, ClpISalsa20Engine, ClpBufferedStreamCipher, 
   ClpSalsa20Engine, ClpXSalsa20Engine, ClpChaChaEngine, ClpIRijndaelEngine, 
-  ClpRijndaelEngine;
+  ClpRijndaelEngine, ClpIIESParameterSpec, ClpIAlgorithmParameterSpec, 
+  ClpIESParameterSpec;
 
 implementation