Author Topic: LibRHash4P - LibRHash for Free Pascal and Delphi  (Read 1050 times)


  • New Member
  • *
  • Posts: 10
    • Pazera-Software
LibRHash4P - LibRHash for Free Pascal and Delphi
« on: January 15, 2020, 01:25:55 pm »
RHash / LibRHash

RHash is a console application for calculating various check- and hashsums, including CRC32, CRC32C, MD4, MD5, SHA1, SHA256, SHA512, SHA3, AICH, ED2K, DC++ TTH, BitTorrent BTIH, Tiger, GOST R 34.11-94, GOST R 34.11-2012, RIPEMD-160, HAS-160, EDON-R, and Whirlpool.
RHash is written in C and is really very fast.

RHash author: Aleksey Kravchenko
RHash repository:

LibRHash is a library that "drives" the RHash and can be compiled into a separate DLL or SO library file.


LibRHash4P - LibRHash for Pascal

LibRHash4P repository:

LibRHash4P consists of two main files:
1. librhash.pas - pascal unit that imports all functions from the LibRHash library.
2. rhash4p.pas - unit with the TRHashFile class for hashing files, and several helpful functions.

In the repository you can also find a demonstration program and compiled libraries for Windows and Linux (32 and 64-bit).
Most libraries are compiled in two versions: with -O2 and -O3 optimization enabled. Libraries compiled with "-O3" optimization should generally be slightly faster, but in some special situations they may be slower. In general, you should test the "O2" and "O3" libraries and choose the best one for your needs.

When calculating the EDONR512 hashsum with a hash buffer larger than 8KiB, incorrect results are sometimes returned. That is why in the TRhashFile class I introduced buffer size control if the hash EDONR512 was selected.

If you need a very fast hash library, you should definitely pay attention to the LibRHash library.


  • Sr. Member
  • ****
  • Posts: 408
Re: LibRHash4P - LibRHash for Free Pascal and Delphi
« Reply #1 on: January 15, 2020, 04:01:38 pm »
Nice work I must say, well done.
also, I like how well you structured rhash4p.pas.
although RHash is fast, HashLib4Pascal when compiled with FPC did not perform badly when compared side by side with RHash.
Infact, HashLib outperformed RHash in some Hashes and I must say I am impressed. O:-)
« Last Edit: January 15, 2020, 04:10:40 pm by Xor-el »


  • New Member
  • *
  • Posts: 10
    • Pazera-Software
Re: LibRHash4P - LibRHash for Free Pascal and Delphi
« Reply #2 on: January 16, 2020, 07:25:23 pm »

I did a series of speed tests on several pascal libraries/projects: Wolfgang Ehrhardt's hashing units, DCPCrypt, LockBox3, HashLib4Pascal, ZlibEx (, LibRHash4P.

Best results:

1. CRC32
  32-bit: ZlibEx 495 MB/s, Wolfgang E. 315 MB/s
  64-bit: ZlibEx 335 MB/s, LibRHash 314 MB/s

2. Adler32
  32-bit: ZlibEx 761 MB/s, Wolfgang E. 605 MB/s
  64-bit: Wolfgang E. 614 MB/s, ZlibEx 257 MB/s

3. MD5
  32-bit: LibRHash 368 MB/s, Wolfgang E. 251 MB/s, HashLib4Pascal 233 MB/s
  64-bit: LibRHash 343 MB/s, Wolfgang E. 226 MB/s

4. SHA-1
  32-bit: LibRHash 428 MB/s, Wolfgang E. 170 MB/s
  64-bit: LibRHash 186 MB/s, Wolfgang E. 154 MB/s

5. SHA2-256
  32-bit: LibRHash 223 MB/s, Wolfgang E. 104 MB/s
  64-bit: LibRHash 142 MB/s, HashLib4Pascal 93 MB/s

6. SHA2-512
  32-bit: LibRHash 235 MB/s, Wolfgang E. 50 MB/s
  64-bit: LibRHash 207 MB/s, HashLib4Pascal 131 MB/s

7. SHA3-256
  32-bit: LibRHash 59 MB/s, Wolfgang E. 52 MB/s
  64-bit: Wolfgang E. 129 MB/s, LibRHash 115 MB/s

8. SHA3-512
  32-bit: LibRHash 32 MB/s, Wolfgang E. 29 MB/s
  64-bit: Wolfgang E. 75 MB/s, LibRHash 65 MB/s

All the above results were obtained by the application compiled using Delphi XE7.


In most cases, LibRHash proved to be the fastest, but an external DLL/SO library file is required.
From the Pascal-world, Wolfgang units and the HashLib4Pascal deserve special mention. DCPCrypt is medium and LockBox is very, very slow.
HashLib4Pascal is currently the most complete hashing library and is still being developed. Wolfgang, unfortunately, will not make any updates anymore, but he left us a lot of great mathematical, hashing and cryptographic pascal units.

Some time ago I did a series of tests with a program compiled using Free Pascal, and I noticed that some hashing algorithms work faster than in Delphi, some much faster! But I have no results. When I find some time, I will do speed tests with the latest Free Pascal and Delphi Rio.

You did a really good job with HashLib4Pascal and several other projects. Thanks.


  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8783
  • FPC developer.
Re: LibRHash4P - LibRHash for Free Pascal and Delphi
« Reply #3 on: January 16, 2020, 08:53:00 pm »
Note that FPC has rotate intrinsics that can speed up pure pascal versions of MD5.

FPC has own md5 and some other hashes in package hash. Afaik only the 32-bit version is assembler though and 64-bit is pure pascal (there is an 64-bit asm version in the track though)
« Last Edit: January 16, 2020, 10:02:00 pm by marcov »


  • Sr. Member
  • ****
  • Posts: 408
Re: LibRHash4P - LibRHash for Free Pascal and Delphi
« Reply #4 on: January 16, 2020, 09:56:12 pm »
@jacekpazera, thanks for the benchmark.
I am awaiting the benchmark involving FPC.
Thanks once again.


TinyPortal © 2005-2018