#1 2024-12-05 23:56:42

Uefi
Member
Registered: 2024-02-14
Posts: 46

BloomFilter and sha256

Hello, I would like to try using sha256 and possibly other hashes in BllomFilter, please see if I added the function correctly ?

  TCrc32Algo = (
    caCrc32c,
    caCrc32,
    caAdler32,
    caxxHash32,
    caFnv32,
    caDefault,
    caMd5,
    caSha1,
    caSha256);

function sha256c(crc: cardinal; buffer: pointer; len: cardinal): cardinal;
var
  sha: TSha256;
  dig: THash256Rec;
begin
  sha.Init;
  sha.Update(@crc, SizeOf(crc));
  sha.Update(buffer, len);
  sha.Final(dig.b);
  result := dig.c[0] xor dig.c[1] xor dig.c[2] xor dig.c[3] xor dig.c[4];
end;

function CryptCrc32(algo: TCrc32Algo): THasher;
begin
  case algo of
    caCrc32c:
      result := crc32c;
    caCrc32:
      result := crc32;
    caAdler32:
      result := adler32; // from mormot.lib.z - nil if unit was not included
    caxxHash32:
      result := @xxHash32;
    caFnv32:
      result := @fnv32;
    caDefault:
      result := DefaultHasher; // may use AES-NI with process-specific seed
    caMd5:
      result := @md5hash32;
    caSha1:
      result := @sha1hash32; // may use Intel SHA HW opcodes
    caSha256:
      result:= @sha256c;
  else
    result := nil;
  end;
end;

Offline

#2 2024-12-06 07:53:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,742
Website

Re: BloomFilter and sha256

You can indeed supply your own THasher function.

I have added caSha256 since it may be needed by someone else.
https://github.com/synopse/mORMot2/commit/bfda46d0

Offline

#3 2024-12-06 14:10:52

Uefi
Member
Registered: 2024-02-14
Posts: 46

Re: BloomFilter and sha256

ab wrote:

You can indeed supply your own THasher function.

I have added caSha256 since it may be needed by someone else.
https://github.com/synopse/mORMot2/commit/bfda46d0

Thank you very much smile

Offline

Board footer

Powered by FluxBB