inherits from EConvertError
Raised by the hexadecimal <-> binary helpers (HexToBin) for a short output buffer or a non-hexadecimal character. Descends from EConvertError so that an application which already handles conversion failures keeps working.
(no public members)
inherits from Exception
Raised by tSecretKey when a positioned write (SetKeyAt, SetKeyStrAt, AddTruncKeyAt, XORKeyAt) would run past the end of the key buffer. The check is what keeps a bad offset from corrupting the heap, so the message names the offset, the length written and the key length.
(no public members)
inherits from Exception
(no public members)
inherits from iUnknown
iKey is the minimal key abstraction shared by every keyed primitive in the library (ciphers, MACs, KDFs). Application code rarely implements or calls it directly; it is the common base that lets TLS/SSH/CMS code pass around "some key" (see iSecretKey below) without depending on a concrete class.
function GetAlgorithm: ObjectIdentifier;
function Instance: tObject;
property Algorithm: ObjectIdentifier read GetAlgorithm;
inherits from iKey
iSecretKey is the library's general-purpose secret-key container: raw key bytes plus an associated IV/vector size, reference-counted and wiped on destruction (see tSecretKey.ClearKey/Destroy). Application code meets this interface whenever a component API accepts or returns a key as an interface rather than a raw byte buffer, e.g. TstCustomMAC.SetKeyIntf/ HashIntf, TstCustomCipherComponent.EncryptIntf/DecryptIntf, or the content-encryption keys built up during CMS EnvelopedData/TLS key-schedule processing (see StreamSec.DSI.PkixCms.pas and StreamSec.Mobile.Tls.pas). There is no client/server distinction; it is protocol-agnostic key material used identically on both sides of any handshake.
procedure AddTruncKeyAt(aKey: iSecretKey; aPos: Integer; IncVal: Byte = 0);
function GetKey: Pointer;
function GetKeyBytes: tBytes;
function GetKeyLen: Integer;
function GetVectorSize: Integer;
procedure SetKey(aKey: Pointer; aKeyLen: Integer; aVectorSize: Integer); overload;
procedure SetKey(const aKey: tBytes; aKeyOffset, aKeyLen: Integer; aVectorSize: Integer); overload;
procedure SetKeyAt(aKey: ISecretKey; aPos: Integer);
procedure SetKeyStr(const aKeyStr: OctetString; aConvertToBMPStr: Boolean = False);
procedure SetKeyStrAt(const aKeyStr: OctetString; aPos: Integer);
procedure SetLength(aKeyLen: Integer);
procedure SetTruncKeyAt(aKey: ISecretKey; aPos: Integer);
procedure SetVectorSize(const aValue: Integer);
procedure TrimLength(aKeyLen: Integer);
procedure XORKeyAt(aKey: ISecretKey; aPos: Integer);
property Key: Pointer read GetKey;
property KeyBytes: TBytes read GetKeyBytes;
property KeyLen: Integer read GetKeyLen;
property VectorSize: Integer read GetVectorSize write SetVectorSize;
inherits from tInterfacedObject
implements iSecretKey
tSecretKey is the most basic iSecretKey implementer. It is most commonly used for passing or storing password.
constructor Create(aAlgorithm: ObjectIdentifier);
constructor CreateStr(aValue: POctetChar; aLen: Integer = -1);
constructor CreateBMPStr(aValue: PWideChar; aLen: Integer = -1);
constructor CreateBytes(const aValue: TBytes; aOffset, aCount: Integer); overload;
constructor CreateBytes(const aValue: TBytes); overload;
destructor Destroy; override;
procedure AddTruncKeyAt(aKey : iSecretKey; aPos : Integer; aIncVal: Byte = 0);
procedure SetKey(aKey : Pointer; aKeyLen : Integer; aVectorSize: Integer); overload;
procedure SetKey(const aKey : tBytes; aKeyOffset, aKeyLen : Integer; aVectorSize: Integer); overload;
procedure SetKeyAt(aKey: iSecretKey; aPos: Integer);
procedure SetTruncKeyAt(aKey: iSecretKey; aPos: Integer);
procedure SetKeyStr(const aKeyStr: OctetString; aConvertToBMPStr: Boolean);
procedure SetKeyStrAt(const aKeyStr: OctetString; aPos: Integer);
procedure SetLength(aKeyLen: Integer);
procedure TrimLength(aKeyLen: Integer);
procedure XORKeyAt(aKey: iSecretKey; aPos: Integer);
property Algorithm: ObjectIdentifier read GetAlgorithm;
property Key: Pointer read GetKey;
property KeyBytes: tBytes read GetKeyBytes;
property KeyLen: Integer read GetKeyLen;
property VectorSize: Integer read GetVectorSize write SetVectorSize;
inherits from iUnknown
function GetKey1: iSecretKey;
function GetKey2: iSecretKey;
inherits from tInterfacedObject
implements iSecretKey, iDualSecretKey
tDualSecretKey is most commonly used for opening PFX files, in case it is unknown whether it uses the old PKCS#12 password based key derivation, or the new PKCS#8 based key derivation. THE PASSWORD'S ENCODING IN A PFX IS THE CALLER'S CHOICE, made by the key object passed. CreateForPFX makes Key1 the password as a BMPString with a NULL terminator - RFC 7292 appendix B.1, for every password in a PFX - and Key2 its UTF-8 octets. The PKCS#12 schemes and the PFX MAC take Key1; PBES2 takes Key2 (the form OpenSSL writes PBES2 in) and so does PBMAC1 (which RFC 9879 requires to be UTF-8); a reader tries Key1 first and then Key2. Any other iSecretKey is used as the octet string it is, for every scheme, so the caller does the encoding: tSecretKey.CreateBMPStr gives RFC 7292's encoding throughout.
class function CreateForPFX(const aPassword: string): iSecretKey;
constructor Create(aKey1, aKey2: iSecretKey);
(no public members)
iCipher is the common interface implemented by every symmetric cipher in the library (see tCipher below, the base class for all block/stream ciphers). Application code normally reaches it indirectly through a published component (e.g. TstCustomCipherComponent, which implements iCipher and forwards to its internal tCipher) rather than instantiating a tCipher descendant and using this interface by hand; it is documented here because component code and other library units (TLS, SSH, CMS content encryption) pass ciphers around as iCipher. There is no client/server distinction: the same interface encrypts and decrypts on either side of a connection, the only difference being which direction (Encrypt vs Decrypt) each side calls.
function CanDecryptInplace: Boolean;
function CanEncryptInplace: Boolean;
function GetVector: OctetString;
procedure SetVector(const Value: OctetString);
function CipherClassType: tCipherClass;
function GetAlgorithmName: string;
function GetBlockSize: Integer;
function GetCipherAlgorithm: tCipherAlg;
function GetCipherAlg: ObjectIdentifier;
function GetMode: tCipherMode;
function Decrypt(var Buf; var Count: Integer): Boolean;
function DecryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
function DecryptIntf(aBuf: ISecretKey): Boolean;
function DecryptPtr(Buf: Pointer; var Count: Integer): Boolean;
function DecryptStr(const Buf: OctetString): OctetString;
function DecryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean;
function DecryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
function Encrypt(var Buf; var Count: Integer): Boolean;
function EncryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
function EncryptIntf(aBuf: iSecretKey): Boolean;
function EncryptPtr(Buf: Pointer; var Count: Integer): Boolean;
function EncryptStr(const Buf: OctetString): OctetString;
function EncryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean;
function EncryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
procedure GetVectorBuf(var aIV; aCount: Integer);
function Reset(aPosition: Integer = 0; aOverride: Boolean = False) : Boolean;
function SetVectorBuf(const IV; Count: Integer): Boolean;
property Algorithm: tCipherAlg read GetCipherAlgorithm;
property AlgorithmName: string read GetAlgorithmName;
property BlockSize: Integer read GetBlockSize;
property CipherAlg: ObjectIdentifier read GetCipherAlg;
property Mode: tCipherMode read GetMode;
property IVector: OctetString read GetVector write SetVector;
function GetEffectiveKeySize: Integer;
procedure SetEffectiveKeySize(const Value: Integer);
function GetEKBParameter: Integer;
procedure SetEKBParameter(const Value: Integer);
property EKBParameter: Integer read GetEKBParameter write SetEKBParameter;
inherits from Exception
(no public members)
inherits from TObject
procedure AfterConstruction; override;
procedure BeforeDestruction; override;
class function NewInstance: tObject; override;
property RefCount: Integer read fRefCount;
constructor CreateUnkeyed(aRefCounted: Boolean = False); virtual;
inherits from tOptionallyRefCountedObject
implements iCipher
tCipher is the base class for all ciphers
constructor CreateBytes(const aKey : tBytes; aOffset, aCount: Integer; aSetIV : Boolean = False; aRefCounted : Boolean = False); virtual;
constructor CreateClone(aCipher: tCipher); virtual;
constructor CreateIntf(aSecretKey : iSecretKey; aSetIV : Boolean = False; aRefCounted: Boolean = False); virtual;
constructor Create(const aKey; aCount: Integer; aSetIV : Boolean = False; aRefCounted : Boolean = False); virtual;
constructor CreateUnkeyed(aRefCounted: Boolean = False); override;
destructor Destroy; override;
class function ClassIsRegistered: Boolean;
class function BlockSize: Integer; virtual;
class function Mode: tCipherMode; virtual;
class function Algorithm: tCipherAlg; virtual;
class function AlgorithmName: string; virtual;
class function OID(aKeySize: Integer): ObjectIdentifier; virtual;
class function KeyedIVOID(aKeySize: Integer): ObjectIdentifier; virtual;
class function IVLength: Integer; virtual;
class function MaxKeySize: Integer; virtual;
class function MinKeySize: Integer; virtual;
function Clone: iCipher;
function Decrypt(var aBuf; var aCount: Integer): Boolean; virtual;
function DecryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
function DecryptIntf(aBuf: ISecretKey): Boolean;
function DecryptPtr(aBuf: Pointer; var aCount: Integer): Boolean;
function DecryptStr(const aBuf: OctetString): OctetString; virtual;
function DecryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; virtual;
function DecryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
function Encrypt(var aBuf; var aCount: Integer): Boolean; virtual;
function EncryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
function EncryptIntf(aBuf: iSecretKey): Boolean;
function EncryptPtr(aBuf: Pointer; var aCount: Integer): Boolean;
function EncryptStr(const aBuf: OctetString): OctetString; virtual;
function EncryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; virtual;
function EncryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
procedure GetVectorBuf(var aIV; aCount: Integer); virtual;
function Reset(aPosition: Integer = 0; aOverride: Boolean = False) : Boolean; virtual;
procedure SetUp(const aKey; aCount: Integer); virtual; abstract;
procedure SetUpIntf(aSecretKey: ISecretKey);
function SetVectorBuf(const aIV; aCount: Integer): Boolean; virtual;
property State: OctetString read GetVector write SetVector;
property IVector: OctetString read GetIVector write SetIVector;
inherits from iCipher
function GetFinal: OctetString;
function GetFinalLen: Integer;
function EncryptToNil(const aBuf; aCount: Integer): Boolean;
procedure GetFinalBuf(var aMac; aCount: Integer);
function VerifyFinalBuf(const aSrc; aSrcCount: Integer) : Boolean; overload;
function VerifyFinalBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; overload;
property Mac: OctetString read GetFinal;
inherits from tCipher
implements iCipherMAC
function DecryptStr(const aBuf: OctetString): OctetString; override;
function EncryptStr(const aBuf: OctetString): OctetString; override;
function EncryptToNil(const aBuf; aCount: Integer): Boolean; virtual;
procedure GetFinalBuf(var aMac; aCount: Integer); virtual;
function VerifyFinalBuf(const aSrc; aSrcCount: Integer) : Boolean; overload;
function VerifyFinalBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; overload;
property FinalLen: Integer read GetFinalLen;
function CreateAnother(const aKey; aCount: Integer; aSetIV : Boolean = False) : iBlockEncryptor;
function GetBlockSize: Integer;
function GetMode: tCipherMode;
procedure DecryptBlock(var aBuf);
procedure DecryptBlockToDst(var aDst; const aSrc);
procedure EncryptBlock(var aBuf);
procedure EncryptBlockToDst(var aDst; const aSrc);
procedure SetUp(const aKey; aCount: Integer);
function KeyWrapDecrypt(const aInBuf; aInBufLen : Integer; const aKey; aKeyLen : Integer; var aOutBuf; aOutBufLen: Integer) : Integer; overload;
function KeyWrapEncrypt(const aInBuf; aInBufLen : Integer; const aKey; aKeyLen : Integer; var aOutBuf; aOutBufLen: Integer) : Integer; overload;
function KeyWrapDecrypt(aInBuf : iSecretKey; aKey : iSecretKey; var aOutBuf: iSecretKey) : Boolean; overload;
function KeyWrapEncrypt(aInBuf : iSecretKey; aKey : iSecretKey; var aOutBuf: iSecretKey) : Boolean; overload;
inherits from Exception
(no public members)
constructor Create(aBlockEncryptor: iBlockEncryptor); overload; virtual;
constructor Create(aBlockEncryptor: tCipher); overload;
destructor Destroy; override;
class function Mode: tBlockPaddingMode; virtual;
class function ModeName: string; virtual;
class function SupportsCipherMode(aMode: tCipherMode): Boolean; virtual;
procedure ChangeCipher(const aBlockEncryptor: iBlockEncryptor); virtual;
function BeforeDecrypt(var aSrc : pByteArray; var aSrcCount: Integer; var aDst : pByteArray; var aDstCount: Integer) : Boolean; virtual; abstract;
function BeforeEncrypt(var aSrc : pByteArray; var aSrcCount: Integer; var aDst : pByteArray; var aDstCount: Integer) : Boolean; virtual; abstract;
function BeforeEncryptToNil(var aBuf : pByteArray; var aCount: Integer): Boolean; virtual; abstract;
procedure GetFinalBuf(var aMac; aCount: Integer); virtual; abstract;
function VerifyFinalBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; virtual; abstract;
function CanFinish(aCount: Integer): Boolean; virtual;
function CanVerifyFinal(aCount: Integer): Boolean; virtual;
property FinalLen: Integer read GetFinalLen;
property HasCachedInput: Boolean read GetHasCachedInput;
property MustInitialize: Boolean read fMustInitialize write SetMustInitialize;
procedure RemovePadding(aPadding: tBlockPadding);
procedure SetPadding(aPadding: tBlockPadding);
function GetPaddingMode: tBlockPaddingMode;
procedure SetPaddingMode(const Value: tBlockPaddingMode);
property BlockPaddingMode: tBlockPaddingMode read GetPaddingMode write SetPaddingMode;
function GetDigest: OctetString;
function GetAlgorithm: tHashAlgorithm;
function GetCyclesOfCompress: Int64;
function GetDERPrefix: Pointer;
function GetDERPrefixLen: Integer;
function GetDigestSize: Integer;
function GetOID: ObjectIdentifier;
function Clone: iHash;
procedure Done(Digest: Pointer);
procedure DoneBytes(var Digest: tBytes); overload;
procedure DoneBytes(const Buf: tBytes; Offset: Integer); overload;
procedure GetContext(Context: Pointer);
procedure HashData(const Data; Count: Int64);
procedure HashBytes(const Data: tBytes); overload;
procedure HashBytes(const Data: tBytes; Offset, Count: Integer); overload;
procedure SetUp;
procedure SetUpContext(Context: Pointer);
property Digest: OctetString read GetDigest;
inherits from iHash
function GetKey: iSecretKey;
function GetKeyedHashMethod: tKeyedHashMethod;
procedure SetKey(const Value: iSecretKey);
procedure SetKeyedHashMethod(const Value: tKeyedHashMethod);
property Key: iSecretKey read GetKey write SetKey;
property KeyedHashMethod: tKeyedHashMethod read GetKeyedHashMethod write SetKeyedHashMethod;
inherits from Exception
(no public members)
inherits from tOptionallyRefCountedObject
implements iHash, iKeyedHash
THash is the abstract base class for hash algorithms.
constructor Create(const Data; Count: Int64; aRefCounted: Boolean = False); overload; virtual;
constructor CreateBytes(const Data: tBytes; Offset, Count: Integer; aRefCounted: Boolean = False); virtual;
constructor CreateUnkeyed(aRefCounted: Boolean = False); override;
destructor Destroy; override;
class function Algorithm: tHashAlgorithm; virtual;
class function CyclesOfCompress: Int64;
class function DERPrefix: Pointer; virtual;
class function DERPrefixLen: Integer; virtual;
class function DigestSize: Integer; virtual;
class function Rate: Integer; virtual;
class function OID: ObjectIdentifier; virtual;
class function Iterate(const aData: tBytes; aIterations: Cardinal): tBytes;
procedure Done(Digest: Pointer);
procedure DoneReverse(Digest: Pointer);
procedure DoneBytes(var Digest: tBytes); overload; virtual;
procedure DoneBytes(const Buf: tBytes; Offset: Integer); overload; virtual;
procedure GetContext(Context: Pointer); virtual; abstract;
procedure HashData(const Data; Count: Int64); virtual; abstract;
procedure HashBits(const aData; aBitOffset, aBitCount: Int64); overload; virtual;
procedure HashBits(const aData; aBitCount: Int64); overload; virtual;
procedure HashReverseData(const aData; aCount: Int64); virtual;
procedure HashBytes(const Data: tBytes); overload; virtual;
procedure HashBytes(const Data: tBytes; Offset, Count: Integer); overload; virtual;
procedure SetUp; virtual;
procedure SetUpContext(Context: Pointer); virtual; abstract;
property Digest: OctetString read GetDigest;
property Key: iSecretKey read fKey write SetKey;
property KeyedHashMethod: tKeyedHashMethod read fKeyedHashMethod write SetKeyedHashMethod;
inherits from IUnknown
function GetSeed: iSecretKey;
function NewSeed: iSecretKey;
procedure RawRandom(var X; MaxBitSize: Cardinal); overload;
procedure RawRandom(var X: tBytes); overload;
procedure RawRandom(var X: tBytes; ByteOffset, MaxBitSize: Cardinal); overload;
procedure SetSeed(const Value: iSecretKey);
property Seed: iSecretKey read GetSeed write SetSeed;
inherits from iRawRandom
function GetSecurityStrength: Cardinal;
procedure SetSeedBuf(const Value; Count: Cardinal);
procedure ForceReseed(const Value; Count: Cardinal);
property SecurityStrength: Cardinal read GetSecurityStrength;
function GetMACLength: Integer;
function GetMessageCounter: Int64;
function GetMessageCounterLength: Integer;
function GetN: OctetString;
function GetNLength: Integer;
procedure SetMACLength(Value: Integer);
procedure SetMessageCounter(Value: Int64);
procedure SetMessageCounterLength(Value: Integer);
procedure SetN(const Value: OctetString);
procedure SetNLength(Value: Integer);
procedure Initialize;
procedure Finalize;
property MACLength: Integer read GetMACLength write SetMACLength;
property MessageCounter: Int64 read GetMessageCounter write SetMessageCounter;
property MessageCounterLength: Integer read GetMessageCounterLength write SetMessageCounterLength;
property N: OctetString read GetN write SetN;
property NLength: Integer read GetNLength write SetNLength;
inherits from iCompoundMode
function GetAdditionalDataLength: Int64;
function GetLengthLength: Integer;
function GetMessageLength: Int64;
procedure SetAdditionalDataLength(Value: Int64);
procedure SetLengthLength(Value: Integer);
procedure SetMessageLength(Value: Int64);
property AdditionalDataLength: Int64 read GetAdditionalDataLength write SetAdditionalDataLength;
property LengthLength: Integer read GetLengthLength write SetLengthLength;
property MessageLength: Int64 read GetMessageLength write SetMessageLength;
inherits from iCompoundMode
(no public members)
inherits from iCompoundMode
(no public members)
inherits from iCompoundMode
function GetMessageLength: Int64;
function GetHashAlgorithm: tHashAlgorithm;
function GetHashClass: tHashClass;
function GetHMACKey: iSecretKey;
function GetPRNG: iRawRandom;
function GetRemainingCipherTextInputLength: Integer;
procedure SetMessageLength(Value: Int64);
procedure SetHashAlgorithm(Value: tHashAlgorithm);
procedure SetHashClass(Value: tHashClass);
procedure SetHMACKey(const Value: iSecretKey);
procedure SetPRNG(const Value: iRawRandom);
property MessageLength: Int64 read GetMessageLength write SetMessageLength;
property HashAlgorithm: tHashAlgorithm read GetHashAlgorithm write SetHashAlgorithm;
property HashClass: tHashClass read GetHashClass write SetHashClass;
property PRNG: iRawRandom read GetPRNG write SetPRNG;
function CanInit: Boolean;
function Identifier: string;
procedure Init;
function CanFini: Boolean;
procedure Fini;
function RegisterCipherClass(aAlg: tCipherAlg; aMode: tCipherMode): Boolean;
function RegisterHashClass(aAlg: tHashAlgorithm): Boolean;
function RegisterPaddingClass(aMode: tBlockPaddingMode): Boolean;
function StartYarrow: Boolean;
inherits from Exception
(no public members)
Deprecated - caTwoFish (stTwoFish): use caRijndael (AES) for new data. TwoFish works as before on Win32 and Win64; on a compiler without an inline assembler it has no block function and raises eCipherError.
haUndefined to signal an error condition. Do not use this value as a parameter or property value, except to signal that the state is not supposed to include any hash algorithm (e.g. in a S/MIME Capability)