Skip to content

Commit

Permalink
changed caAesNi32 into caDefault
Browse files Browse the repository at this point in the history
- map DefaultHasher() depending on the system it runs on
  • Loading branch information
Arnaud Bouchez committed Aug 23, 2023
1 parent 9c11859 commit b3e3c5b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/crypt/mormot.crypt.secure.pas
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ TStreamRedirectSha3_512 = class(TStreamRedirectSynHasher)

/// the known 32-bit crc algorithms as returned by CryptCrc32()
// - ccaCrc32 and ccaAdler32 require mormot.lib.z.pas to be included
// - AesNiHash() is part of it, but is NOT cross-platform, and not persistable
// between executions, since is randomly seeded at process startup
// - caDefault may be AesNiHash32(), therefore not persistable between
// executions, since is randomly seeded at process startup
// - some cryptographic-level hashes are truncated to 32-bit - caSha1 could
// leverage Intel SHA HW opcodes to achieve pretty good performance
TCrc32Algo = (
Expand All @@ -736,13 +736,12 @@ TStreamRedirectSha3_512 = class(TStreamRedirectSynHasher)
caAdler32,
caxxHash32,
caFnv32,
caAesNi32,
caDefault,
caMd5,
caSha1);

/// returns the 32-bit crc function for a given algorithm
// - may return nil, e.g. for caCrc32/caAdler32 when mormot.lib.z is not loaded
// or for caAesNi32 when AES-NI and SSE 4.1 are not available
function CryptCrc32(algo: TCrc32Algo): THasher;

function ToText(algo: TSignAlgo): PShortString; overload;
Expand Down Expand Up @@ -1306,7 +1305,7 @@ TBinaryCookieGenerator = record
Crypt: array[byte] of byte;
/// initialize ephemeral temporary cookie generation
// - default crc32c is fast and secure enough on most platforms, but you
// may consider caAesNi32 or caSha1 on recent Intel/AMD servers
// may consider caDefault or caSha1 on recent Intel/AMD servers
procedure Init(const Name: RawUtf8 = 'mORMot';
DefaultSessionTimeOutMinutes: cardinal = 0;
SignAlgo: TCrc32Algo = caCrc32c);
Expand All @@ -1325,7 +1324,7 @@ TBinaryCookieGenerator = record
PRecordTypeInfo: PRttiInfo = nil; PExpires: PUnixTime = nil;
PIssued: PUnixTime = nil): TBinaryCookieGeneratorSessionID;
/// allow the very same cookie to be recognized after server restart
// - note that the seeded caAesNi32 won't be persistable by definition
// - note that caDefault won't be persistable, because may map AesNiHash32
function Save: RawUtf8;
/// unserialize the cookie generation context as serialized by Save
function Load(const Saved: RawUtf8): boolean;
Expand Down Expand Up @@ -2905,8 +2904,8 @@ function CryptCrc32(algo: TCrc32Algo): THasher;
result := @xxHash32;
caFnv32:
result := @fnv32;
caAesNi32:
result := AesNiHash32; // may return nil on non-Intel or oldest CPUs
caDefault:
result := DefaultHasher; // may use AES-NI with process-specific seed
caMd5:
result := @md5hash32;
caSha1:
Expand Down Expand Up @@ -5468,7 +5467,7 @@ TCryptCrcInternal = class(TCryptHash)
const
/// CSV text of TCrc32Algo items
CrcAlgosText: PUtf8Char =
'crc32,crc32c,xxhash32,adler32,fnv32,aesni32,md5-32,sha1-32';
'crc32,crc32c,xxhash32,adler32,fnv32,default32,md5-32,sha1-32';

constructor TCryptCrc32Internal.Create(const name: RawUtf8);
begin
Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'2.1.5791'
'2.1.5792'

0 comments on commit b3e3c5b

Please sign in to comment.