Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

stSecUtils

Classes, interfaces and records

classeHexConversion

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)

classeSecretKeyError

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)

classeCBCMac

inherits from Exception

(no public members)

interfaceiKey

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;
Getter for Algorithm; internal wiring, not normally called directly.
function Instance: tObject;
Returns the underlying tObject implementing this key, e.g. so code that received only the interface can access class-specific members via a typecast/as-cast; rarely needed by application code.
property Algorithm: ObjectIdentifier read GetAlgorithm;
The object identifier of the algorithm this key belongs to (e.g. an AES or HMAC OID). Useful when application code needs to identify or log which algorithm a passed-around iKey/iSecretKey was created for.

interfaceiSecretKey

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);
Adds (with carry, i.e. big-endian multi-precision addition) aKey's bytes into this key's bytes starting at aPos, with aIncVal as the initial carry-in. Used by KDF/key-derivation code that builds a longer key material buffer from repeated keyed-hash blocks; not typically called directly by application code.
function GetKey: Pointer;
Getter for Key; internal wiring, not normally called directly.
function GetKeyBytes: tBytes;
Getter for KeyBytes; internal wiring, not normally called directly.
function GetKeyLen: Integer;
Getter for KeyLen; internal wiring, not normally called directly.
function GetVectorSize: Integer;
Getter for VectorSize; internal wiring, not normally called directly.
procedure SetKey(aKey: Pointer; aKeyLen: Integer; aVectorSize: Integer); overload;
Replaces the key material from a raw buffer of aKeyLen bytes and records aVectorSize (the IV size the owning cipher/mode expects). Application code normally goes through a higher-level setter (e.g. a component's Key/Password property or SetKeyStr) rather than calling this overload directly.
procedure SetKey(const aKey: tBytes; aKeyOffset, aKeyLen: Integer; aVectorSize: Integer); overload;
Same as the Pointer overload but sources the key bytes from a tBytes buffer at aKeyOffset/aKeyLen; convenient when key material already lives in a managed byte array (e.g. decoded from ASN.1/DER).
procedure SetKeyAt(aKey: ISecretKey; aPos: Integer);
Overwrites aKey.KeyLen bytes of this key's material at aPos with aKey's bytes, without changing this key's own length. Used when assembling a composite key (e.g. concatenated KDF output blocks) in place.
procedure SetKeyStr(const aKeyStr: OctetString; aConvertToBMPStr: Boolean = False);
Sets the key from an OctetString password, optionally converting it to a BMPString (UTF-16BE, PKCS#12-style) first via aConvertToBMPStr; this is the path PFX/PKCS#12 password-based key derivation uses to turn a user-supplied password into key material (see PBES2/PFX handling elsewhere in the DSI units).
procedure SetKeyStrAt(const aKeyStr: OctetString; aPos: Integer);
Like SetKeyAt but takes the replacement bytes directly as an OctetString instead of another iSecretKey; used to splice DER-encoded fragments (e.g. algorithm id, counter, supplemental info) into a KDF output buffer, as done by the TLS 1.2 PRF/key-block code in StreamSec.Mobile.Tls.pas and the ECDH KeyAgreeRecipientInfo code in StreamSec.Mobile.StreamSecII.pas.
procedure SetLength(aKeyLen: Integer);
Resizes the key buffer to aKeyLen bytes, clearing (wiping) any previous key material first. Application code rarely calls this directly; it underlies the higher-level SetKey/SetKeyStr setters.
procedure SetTruncKeyAt(aKey: ISecretKey; aPos: Integer);
Like SetKeyAt but truncates/clips the copy to whatever room remains in this key's buffer from aPos onward, instead of raising when aKey is longer than the remaining space. Used the same way as SetKeyAt when assembling KDF output where the final block may be partial.
procedure SetVectorSize(const aValue: Integer);
Setter for VectorSize; records the IV/vector size the owning cipher/mode expects without touching the key bytes themselves.
procedure TrimLength(aKeyLen: Integer);
Shrinks the key to aKeyLen bytes if it is currently longer, leaving it unchanged otherwise; used after an in-place Encrypt/DecryptIntf call to drop any trailing padding/tag bytes that grew the buffer (see tCipher.DecryptIntf/EncryptIntf).
procedure XORKeyAt(aKey: ISecretKey; aPos: Integer);
XORs aKey's bytes into this key's bytes starting at aPos, in place. Used by KDF/PRF constructions that combine several derived blocks with XOR (e.g. some SSH/TLS key-expansion paths); not typically called directly by application code.
property Key: Pointer read GetKey;
Raw pointer to the key bytes. Use with care: the buffer is only valid for the lifetime of the iSecretKey and is wiped/reallocated on the next SetKey/SetLength call.
property KeyBytes: TBytes read GetKeyBytes;
The key material as a managed tBytes array; the safe way for application code to read out key bytes (e.g. to log a key ID or hand it to another API that wants a byte array) instead of using the raw Key pointer.
property KeyLen: Integer read GetKeyLen;
Current key length in bytes; check this before relying on a fixed key size, since some algorithms/components accept variable-length keys.
property VectorSize: Integer read GetVectorSize write SetVectorSize;
The number of IV/vector blocks the owning cipher/mode expects (a block count, not a byte count; the IV occupies VectorSize * BlockSize bytes), carried alongside the key material. Set from a cipher's BlockVectorSize by the CMS content-encryption-key code (see stMpCms.pas / StreamSec.DSI.PkixCms.pas), which extends the key buffer to hold both key and IV. Note tCipher.SetUpIntf does not read this.

classtSecretKey

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;

interfaceiDualSecretKey

inherits from iUnknown

function GetKey1: iSecretKey; function GetKey2: iSecretKey;

classtDualSecretKey

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);

classtCipher

(no public members)

interfaceiCipher

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;
True if this cipher/mode can decrypt in place (source and destination buffer the same); the base tCipher implementation always returns True, but a mode that needs look-ahead could override it to False. Callers doing bulk in-place decryption (e.g. DecryptToBuf with equal src/dst) can check this first if they need to fall back to a temporary buffer.
function CanEncryptInplace: Boolean;
True if this cipher/mode can encrypt in place; see CanDecryptInplace.
function GetVector: OctetString;
Getter for IVector; internal wiring, not normally called directly.
procedure SetVector(const Value: OctetString);
Setter for IVector; internal wiring, not normally called directly.
function CipherClassType: tCipherClass;
Returns the concrete tCipherClass behind this instance; used by Clone to re-instantiate the same cipher type, and occasionally by application code that received only an iCipher but needs to know/log which cipher class is actually in use.
function GetAlgorithmName: string;
Getter for AlgorithmName; internal wiring, not normally called directly.
function GetBlockSize: Integer;
Getter for BlockSize; internal wiring, not normally called directly.
function GetCipherAlgorithm: tCipherAlg;
Getter for Algorithm; internal wiring, not normally called directly.
function GetCipherAlg: ObjectIdentifier;
Getter for CipherAlg; internal wiring, not normally called directly.
function GetMode: tCipherMode;
Getter for Mode; internal wiring, not normally called directly.
function Decrypt(var Buf; var Count: Integer): Boolean;
Decrypts Count bytes of Buf in place, updating Count if the mode changes the output length (e.g. an AEAD tag being stripped). This is the fundamental decrypt entry point that the other Decrypt* convenience overloads (DecryptBytes/Ptr/Str/ToBuf/ToPtr/Intf) all funnel through.
function DecryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
Decrypts aCount bytes of aBuf starting at aOffset in place, advancing aOffset by aCount on success; convenient when decrypting successive chunks out of one shared buffer (e.g. streaming protocol data).
function DecryptIntf(aBuf: ISecretKey): Boolean;
Decrypts the key material held by an iSecretKey in place and trims it to the resulting length; used where key/PRF material itself must be decrypted (e.g. unwrapping a wrapped content-encryption key).
function DecryptPtr(Buf: Pointer; var Count: Integer): Boolean;
Pointer-based equivalent of Decrypt, for callers holding a raw buffer pointer instead of an untyped var parameter.
function DecryptStr(const Buf: OctetString): OctetString;
Decrypts an OctetString and returns the plaintext as a new OctetString; the simplest entry point for application code that already has ciphertext as a string-like OctetString rather than a raw buffer.
function DecryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean;
Decrypts aSrcCount bytes from aSrc into aDst (which need not be the same buffer), reporting the actual output length via aDstCount; the non-in-place counterpart of Decrypt, useful when the caller wants to preserve the original ciphertext buffer.
function DecryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
Pointer-based equivalent of DecryptToBuf.
function Encrypt(var Buf; var Count: Integer): Boolean;
Encrypts Count bytes of Buf in place, updating Count if the mode changes the output length (e.g. an AEAD tag being appended). This is the fundamental encrypt entry point that the other Encrypt* convenience overloads (EncryptBytes/Ptr/Str/ToBuf/ToPtr/Intf) all funnel through.
function EncryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean;
Encrypts aCount bytes of aBuf starting at aOffset in place, advancing aOffset by aCount on success; see DecryptBytes for the decrypt counterpart and typical streaming-chunk usage.
function EncryptIntf(aBuf: iSecretKey): Boolean;
Encrypts the key material held by an iSecretKey in place, e.g. to wrap a content-encryption or session key before transmitting it (see DecryptIntf for the inverse operation).
function EncryptPtr(Buf: Pointer; var Count: Integer): Boolean;
Pointer-based equivalent of Encrypt.
function EncryptStr(const Buf: OctetString): OctetString;
Encrypts an OctetString and returns the ciphertext as a new OctetString; the simplest entry point for application code that already has plaintext as a string-like OctetString.
function EncryptToBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean;
Encrypts aSrcCount bytes from aSrc into aDst (which need not be the same buffer), reporting the actual output length via aDstCount; the non-in-place counterpart of Encrypt.
function EncryptToPtr(aSrc : Pointer; aSrcCount: Integer; aDst : Pointer; var aDstCount: Integer) : Boolean;
Pointer-based equivalent of EncryptToBuf.
procedure GetVectorBuf(var aIV; aCount: Integer);
Copies up to aCount bytes of the current IVector into aIV and wipes the temporary copy afterwards; used by code that needs the raw IV bytes (e.g. to place them on the wire) without going through the IVector OctetString property.
function Reset(aPosition: Integer = 0; aOverride: Boolean = False) : Boolean;
Rewinds chained modes (CBC/CFB/OFB/etc, see the mode formulas noted above in this unit) back to their initial IVector state; aPosition must be 0 and aOverride False for the reset to actually take effect in the base implementation. Used when the same cipher instance is reused to re-process data from the start, e.g. retrying a record after a failed decrypt.
function SetVectorBuf(const IV; Count: Integer): Boolean;
Sets the IV from a raw buffer of exactly IVLength bytes, returning False if aCount does not match; the raw-pointer counterpart of setting the IVector property directly.
property Algorithm: tCipherAlg read GetCipherAlgorithm;
The high-level cipher algorithm identifier (e.g. caRijndael, caChaCha20) this instance implements; use this to branch on cipher family without needing the class type or OID.
property AlgorithmName: string read GetAlgorithmName;
Human-readable algorithm name (e.g. for logging or display); derived from the concrete cipher class.
property BlockSize: Integer read GetBlockSize;
The cipher's block size in bytes; relevant when padding or chunking plaintext/ciphertext manually instead of using the Encrypt*/Decrypt* convenience methods.
property CipherAlg: ObjectIdentifier read GetCipherAlg;
The ASN.1 object identifier for this cipher/key-size combination, as used e.g. in CMS ContentEncryptionAlgorithmIdentifier or PKCS#8/PFX structures when the algorithm must be recorded on the wire.
property Mode: tCipherMode read GetMode;
The block-cipher mode (ECB/CBC/GCM/etc, see tCipherMode) this instance was constructed with; determines how IVector/State behave and whether CanEncryptInplace/CanDecryptInplace can be relied upon.
property IVector: OctetString read GetVector write SetVector;
The live working chaining register (fIV in tBlockCipher), exposed as an OctetString. Reading it captures the cipher's CURRENT chaining state (not the original seed IV) e.g. to snapshot progress; writing it loads the working register directly and resets the keystream/feedback position (tBlockCiphe... Full description »

interfaceiRC2

function GetEffectiveKeySize: Integer; procedure SetEffectiveKeySize(const Value: Integer); function GetEKBParameter: Integer; procedure SetEKBParameter(const Value: Integer); property EKBParameter: Integer read GetEKBParameter write SetEKBParameter;

classeCipherError

inherits from Exception

(no public members)

classtOptionallyRefCountedObject

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;

classtCipher

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;
Always returns -1.
class function Mode: tCipherMode; virtual;
Returns cmNone, see tCipherMode.
class function Algorithm: tCipherAlg; virtual;
Returns caUnknown, see tCipherAlg.
class function AlgorithmName: string; virtual;
Always returns an empty string.
class function OID(aKeySize: Integer): ObjectIdentifier; virtual;
Always returns an empty string.
class function KeyedIVOID(aKeySize: Integer): ObjectIdentifier; virtual;
Deprecated - names the keyed-IV (KIV) form, which aSetIV = True selects; see id_kivcipher in stOIDs.
class function IVLength: Integer; virtual;
Always returns 0.
class function MaxKeySize: Integer; virtual;
Always returns -1.
class function MinKeySize: Integer; virtual;
Always returns -1.
function Clone: iCipher;
Delegates to CipherClassType.CreateClone, forwarding Self, and returns its result.
function Decrypt(var aBuf; var aCount: Integer): Boolean; virtual;
Delegates to DecryptToBuf, forwarding aBuf, aCount, aBuf and aCount, and returns its result.
function DecryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean; function DecryptIntf(aBuf: ISecretKey): Boolean; function DecryptPtr(aBuf: Pointer; var aCount: Integer): Boolean;
Delegates to Decrypt, passing 2 argument(s), and returns its result.
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;
Delegates to DecryptToBuf, passing 4 argument(s), and returns its result.
function Encrypt(var aBuf; var aCount: Integer): Boolean; virtual;
Delegates to EncryptToBuf, forwarding aBuf, aCount, aBuf and aCount, and returns its result.
function EncryptBytes(const aBuf : tBytes; var aOffset, aCount : Integer) : Boolean; function EncryptIntf(aBuf: iSecretKey): Boolean; function EncryptPtr(aBuf: Pointer; var aCount: Integer): Boolean;
Delegates to Encrypt, passing 2 argument(s), and returns its result.
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;
Delegates to EncryptToBuf, passing 4 argument(s), and returns its result.
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;

interfaceiCipherMAC

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;

classtCipherMAC

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;
Delegates to InternalVerifyFinalBuf, forwarding aSrc, aSrcCount, aDst and aDstCount, and returns its result.
function VerifyFinalBuf(const aSrc; aSrcCount: Integer; var aDst; var aDstCount: Integer) : Boolean; overload;
Delegates to InternalVerifyFinalBuf, forwarding aSrc, aSrcCount, aDst and aDstCount, and returns its result.
property FinalLen: Integer read GetFinalLen;

interfaceiBlockEncryptor

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);

interfaceiKeyWrap

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;

classePaddingError

inherits from Exception

(no public members)

classtBlockPadding

constructor Create(aBlockEncryptor: iBlockEncryptor); overload; virtual; constructor Create(aBlockEncryptor: tCipher); overload; destructor Destroy; override; class function Mode: tBlockPaddingMode; virtual;
Returns bpmNone, see tBlockPaddingMode.
class function ModeName: string; virtual;
Always returns an empty string.
class function SupportsCipherMode(aMode: tCipherMode): Boolean; virtual;
Always returns False.
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;
Whether the padding will have something to finish the input with once aCount more octets are in, i.e. whether FinalLen will then be 0 or more. Full description »
function CanVerifyFinal(aCount: Integer): Boolean; virtual;
Whether VerifyFinalBuf can finish a ciphertext once aCount more octets of it are in, i.e. whether they bring it to a length the padding can have produced. As CanFinish, but for bpmPKCS5, bpmZeroes, bpm10s and bpmSSL3, which finish a plaintext of any length and produce whole blocks, at least one: False for a ciphertext short of that. True while MustInitialize is set: the cipher declines input then.
property FinalLen: Integer read GetFinalLen; property HasCachedInput: Boolean read GetHasCachedInput; property MustInitialize: Boolean read fMustInitialize write SetMustInitialize;

interfaceiSetPadding

procedure RemovePadding(aPadding: tBlockPadding); procedure SetPadding(aPadding: tBlockPadding); function GetPaddingMode: tBlockPaddingMode; procedure SetPaddingMode(const Value: tBlockPaddingMode); property BlockPaddingMode: tBlockPaddingMode read GetPaddingMode write SetPaddingMode;

interfaceiHash

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;

interfaceiKeyedHash

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;

classeHashError

inherits from Exception

(no public members)

classtHash

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;
Always returns nil.
class function DERPrefixLen: Integer; virtual;
Always returns 0.
class function DigestSize: Integer; virtual;
Always returns -1.
class function Rate: Integer; virtual; class function OID: ObjectIdentifier; virtual;
Delegates to HashAlgorithmToOID, forwarding Algorithm, and returns its result.
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;

interfaceiRawRandom

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;

interfaceiRawRandomEx

inherits from iRawRandom

function GetSecurityStrength: Cardinal; procedure SetSeedBuf(const Value; Count: Cardinal); procedure ForceReseed(const Value; Count: Cardinal); property SecurityStrength: Cardinal read GetSecurityStrength;

interfaceiCompoundMode

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;

interfaceiCCMParameters

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;

interfaceiEAXParameters

inherits from iCompoundMode

(no public members)

interfaceiGCMParameters

inherits from iCompoundMode

(no public members)

interfaceiSSHParameters

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;

interfaceiInitialization

function CanInit: Boolean; function Identifier: string; procedure Init;

interfaceiFinalization

function CanFini: Boolean; procedure Fini;

interfaceiProvider

function RegisterCipherClass(aAlg: tCipherAlg; aMode: tCipherMode): Boolean; function RegisterHashClass(aAlg: tHashAlgorithm): Boolean; function RegisterPaddingClass(aMode: tBlockPaddingMode): Boolean; function StartYarrow: Boolean;

classeClassRegistration

inherits from Exception

(no public members)

Types (enumerations, sets, aliases)

enumtCipherAlg

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.

  tCipherAlg = (caUnknown,caRijndael,caDES,caTwoFish,caARC4,caBlowFish,
                caARC2,caHelix,caSEED,caCamellia,caSHACAL2,caChaCha20);

enumtCipherMode

  tCipherMode = (cmNone,cmECB,cmCFB,cmCBC,cmOFB,
                 cmPCFB,      // Deprecated - use cmGCM, cmCCM or cmEAX for new data. A StreamSec mode, kept so that existing data can still be read.
                 cmPipedPCFB, // Deprecated - as cmPCFB.
                 // Accumulated Block Chaining: L. R. Knudsen, "Block chaining
                 // modes of operation", Reports in Informatics 207, Department
                 // of Informatics, University of Bergen, October 2000.
                 cmABC,
                 cmCTR,
                 cmKeyWrap,cmCCM,cmEAX,cmSSH,cmSSHCTR, cmGCM,
                 // SSH AEAD (RFC 5647 aes-gcm): GCM crypto + SSH binary-packet
                 // framing with the 4-byte length in clear (as AAD). Appended at
                 // the end so existing ordinals are unchanged.
                 cmSSHGCM,
                 // SSH chacha20-poly1305@openssh.com (two-key ChaCha20 + Poly1305,
                 // encrypted length field). Appended at the end.
                 cmSSHChaCha);

enumtCBCMACPadding

  tCBCMACPadding = (cmpZeroes,cmp10s,cmpOMAC,cmpXCBCMAC);

typepByte

  pByte = ^Byte;

typeUInt32

  UInt32 = Cardinal;

typepUInt32

  pUInt32 = ^UInt32;

typepByteArray

  pByteArray = ^tByteArray;

arraytByteArray

  tByteArray = packed array [0..MaxInt-3] of Byte;

typetCipherClass

  tCipherClass = class of tCipher;

enumtBlockPaddingMode

  tBlockPaddingMode = (bpmNone,bpmZeroes,bpm10s,bpmOMAC,bpmXCBCMAC,
                       bpmStrSecII,bpmPKCS5,bpmSSL3,bpmCTS,bpmCCM,bpmEAX,
                       bpmSSH,bpmGCM,
                       // SSH AEAD (RFC 5647 aes-gcm) packet framing - appended.
                       bpmSSHGCM,
                       // SSH chacha20-poly1305@openssh.com packet framing.
                       bpmSSHChaCha);

typetBlockPaddingClass

  tBlockPaddingClass = class of tBlockPadding;

enumtHashAlgorithm

  tHashAlgorithm = (haSHA1,                     // unit stSHA1
                    haMD5,                      // unit stMD5
                    haRipeMD160,                // unit stRipeMD160
                    haSHA256,                   // unit stSHA256
                    haSHA384,                   // unit stSHA512
                    haSHA512,                   // unit stSHA512
                    haMD2,                      // unit stMD2
                    haSHA224,                   // unit stSHA256
                    haWhirlpool,                // unit stWhirlpool
                    haHAS160,                   //   reserved
                    haSHA3_224,                 // unit stSHA3
                    haSHA3_256,                 // unit stSHA3
                    haSHA3_384,                 // unit stSHA3
                    haSHA3_512,                 // unit stSHA3
                    haSHA512_224,                   // unit stSHA512
                    haSHA512_256,                   // unit stSHA512
                    haSHAKE128,                 // unit stSHA3 (FIPS 202 XOF, 256-bit output)
                    haSHAKE256,                 // unit stSHA3 (FIPS 202 XOF, 512-bit output)
                    haBlake2b512,               // unit StreamSec.DSI.Blake2 (RFC 7693)
                    haNull,                     {   Identity function.
                                                     haNULL should be used as
                                                     a parameter, when a
                                                     function can be used either
                                                     with or without a hash,
                                                     and the caller opts for the
                                                     alternative without a hash;
                                                     e.g. when calling a KDF
                                                     or Digital Signature that
                                                     includes an optional
                                                     pre-hash. }
                    haDefault,                 {   Use function default.
                                                     haDefault should be used as
                                                     a parameter, when a
                                                     function either has a
                                                     pre-defined default hash
                                                     algorithm, or when the
                                                     function is a method of an
                                                     object that already
                                                     specifies the hash as a
                                                     property of the object, or
                                                     use haDefault as a
                                                     property value when the
                                                     algorithm always should be
                                                     passed as a parameter. }
                    haUndefined);              {   A function might return

settHashAlgorithms

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)

  tHashAlgorithms = set of tHashAlgorithm;

enumtKeyedHashMethod

  tKeyedHashMethod = (khmHMAC,khmSSL3,khmSSL3Finished,khmNull);

typetHashClass

  tHashClass = class of tHash;         

proctRawRandomFactory

  tRawRandomFactory = function(aSecondary: Boolean): iRawRandom;

Routines