The code follows a set of house rules for Delphi. The cryptographic code departs from a few of them on purpose; this file lists those exceptions and the rule each one departs from.
varparameters for state that changes in place. The inner loops of AES (Crypto4D.Aes), GHASH (Crypto4D.Ghash), Argon2, BLAKE2b and bcrypt pass their state, a block or a pair of words as avarparameter and change it where it is. Returning a copy of up to 1 KiB per call costs too much in these loops.Crypto4D.Pbkdf2passes aTHashSHA2record asvarto overwrite it with zeros. TheStoreroutines ofTByteOrderandTArgon2.PutLengthPrefixedwrite into the byte array they are given, so that a buffer that holds a secret is filled in place and not copied. Departs from: never usevarparameters.- Names from the specification. Code that follows a specification or a reference implementation keeps
its names, so that it can be compared with the source line by line: the sixteen words
Aup toPandMix(A, B, C, D)of Argon2 and BLAKE2b, the schedule indexSof BLAKE2b, the names of BearSSL in the AES translation (QandRin MixColumns), andX0,Y14,T27and so on in the S-box circuit of Boyar and Peralta. Departs from: descriptive role names. - Global
externaldeclarations.BCryptGenRandomon Windows andgetrandomon Linux are declared as global functions in the implementation section ofCrypto4D.Random. An external routine cannot be a class method. Departs from: no global functions. - Signatures set by the RTL. The memory manager hooks of the test helper
TFreedMemoryScannertake value parameters, becauseTMemoryManagerExprescribes the signature. Departs from:constfor all parameters. - Documentation comments. Public types and routines have
///XML documentation, which the IDE shows as help, andsrc\Crypto4D.Aes.passtarts with the copyright and permission notice of BearSSL. There are no other comments. Departs from: no comments. - No Spring4D. The library depends on the RTL only. Collections are
TBytesandTArray<T>, and their length is the count. Departs from: use Spring4D collections. - An options record with public fields.
TPasswordHashLimitsis a record whose fields a caller changes after starting fromForStoredHashesorForMessages; it has no rules of its own to protect. A record that does have rules, such asTArgon2ParametersorTRsaPublicKey, keeps its fields private, checks them inCreateand offers them as read-only properties. Departs from: private fields with properties.
The ARX functions of Argon2, BLAKE2b and bcrypt and the masks of TUnpaddedBase64 add and subtract modulo
2^32 or 2^64. These routines sit between {$I Crypto4D.OverflowOff.inc} and
{$I Crypto4D.OverflowRestore.inc}, which switch overflow checking off and back on only when it was on.
So that an inline routine is also compiled without the check where it is expanded, its callers sit
between the same two lines.