Recent

Author Topic: HashLib4Pascal  (Read 24267 times)

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #60 on: January 20, 2020, 08:23:55 am »
BTW I need a
Quote
"{SHA}" + Base64-encoded SHA-1 digest of the password
only (-nbs).
HashLib4Pascal has support for SHA-1 including a host of other algorithms.
for Base64, you can use https://github.com/Xor-el/SimpleBaseLib4Pascal

trevor

  • New Member
  • *
  • Posts: 10
Re: HashLib4Pascal
« Reply #61 on: January 20, 2020, 10:07:32 am »
BTW I need a
Quote
"{SHA}" + Base64-encoded SHA-1 digest of the password
only (-nbs).
HashLib4Pascal has support for SHA-1 including a host of other algorithms.
for Base64, you can use https://github.com/Xor-el/SimpleBaseLib4Pascal

Thanks! I'm trying to figure out but so far unsuccessfully:

Code: Pascal  [Select][+][-]
  1. var
  2.   shah: IHash;
  3. begin
  4.   shah := TSHA1.Create();
  5.   Memo1.Text := shah.ComputeString(Edit1.Text, TEncoding.UTF8);
  6. end;

Now I need to wrap 'shah' into base64 right? Something like 'TBase64(shah.ComputeString(Edit1.Text, TEncoding.UTF8))'?

Code: Pascal  [Select][+][-]
  1.     class property Default: IBase64 read GetDefault;
  2.     class property DefaultNoPadding: IBase64 read GetDefaultNoPadding;
  3.     class property UrlEncoding: IBase64 read GetUrlEncoding;
  4.     class property XmlEncoding: IBase64 read GetXmlEncoding;
  5.     class property RegExEncoding: IBase64 read GetRegExEncoding;
  6.     class property FileEncoding: IBase64 read GetFileEncoding;

So what should I use?

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #62 on: January 20, 2020, 10:28:38 am »
@trevor, below is a Demo that computes the output using the SHA-1 algorithm and compares the result to the one found at https://httpd.apache.org/docs/2.4/misc/password_encryptions.html.
You will need the HashLib4Pascal and SimpleBaseLib4Pascal packages as they are dependencies.

Code: Pascal  [Select][+][-]
  1. program PassDemo;
  2.  
  3. uses
  4.   SysUtils,
  5.   SbpBase64,
  6.   HlpHashFactory;
  7.  
  8. var
  9.   Password, Result: string;
  10. begin
  11.   Password := 'myPassword';
  12.   Result := '{SHA}' + TBase64.Default.Encode(
  13.     THashFactory.TCrypto.CreateSHA1().ComputeString(
  14.     Password, TEncoding.UTF8).GetBytes());
  15.   WriteLn(Result);
  16.   Assert(Result = '{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=');
  17.   ReadLn;
  18. end.
  19.  

trevor

  • New Member
  • *
  • Posts: 10
Re: HashLib4Pascal
« Reply #63 on: January 20, 2020, 10:42:52 am »
@trevor, below is a Demo that computes the output using the SHA-1 algorithm and compares the result to the one found at https://httpd.apache.org/docs/2.4/misc/password_encryptions.html.
You will need the HashLib4Pascal and SimpleBaseLib4Pascal packages as they are dependencies.

Code: Pascal  [Select][+][-]
  1. program PassDemo;
  2.  
  3. uses
  4.   SysUtils,
  5.   SbpBase64,
  6.   HlpHashFactory;
  7.  
  8. var
  9.   Password, Result: string;
  10. begin
  11.   Password := 'myPassword';
  12.   Result := '{SHA}' + TBase64.Default.Encode(
  13.     THashFactory.TCrypto.CreateSHA1().ComputeString(
  14.     Password, TEncoding.UTF8).GetBytes());
  15.   WriteLn(Result);
  16.   Assert(Result = '{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=');
  17.   ReadLn;
  18. end.
  19.  

Thanks a lot! You're the best! Exactly what I need!  ;D

Xor-el

  • Sr. Member
  • ****
  • Posts: 408
Re: HashLib4Pascal
« Reply #64 on: February 18, 2020, 09:11:58 am »
updated to version 4.1

- changelog from 4.0 to 4.1

* add Blake3 and Blake3XOF support
* performance improvements especially XOF Related.

** Now updated in OPM

lvincent7

  • Newbie
  • Posts: 1
Re: HashLib4Pascal
« Reply #65 on: April 27, 2020, 05:21:15 am »
@trevor, below is a Demo that computes the output using the SHA-1 algorithm and compares the result to the one found at https://httpd.apache.org/docs/2.4/misc/password_encryptions.html.
You will need the HashLib4Pascal and SimpleBaseLib4Pascal packages as they are dependencies.

Code: Pascal  [Select][+][-]
  1. program PassDemo;
  2.  
  3. uses
  4.   SysUtils,
  5.   SbpBase64,
  6.   HlpHashFactory;
  7.  
  8. var
  9.   Password, Result: string;
  10. begin
  11.   Password := 'myPassword';
  12.   Result := '{SHA}' + TBase64.Default.Encode(
  13.     THashFactory.TCrypto.CreateSHA1().ComputeString(
  14.     Password, TEncoding.UTF8).GetBytes());
  15.   WriteLn(Result);
  16.   Assert(Result = '{SHA}VBPuJHI7uixaa6LQGWx4s+5GKNE=');
  17.   ReadLn;
  18. end.
  19.  

Thanks a lot! You're the best! Exactly what I need!  ;D

Hi Xor-el,

I really appreciate this Hash library. Thank you. Although I'm still new with hashing and cryptos, I would like to ask if the example above can be fitted similar to the freeformatter website?: https://www.freeformatter.com/hmac-generator.html#ad-output

I'm a little bit confused what corresponds to the string and which correspond to the secret key in the example.

Thanks again!


ASBzone

  • Sr. Member
  • ****
  • Posts: 364
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: HashLib4Pascal
« Reply #66 on: April 27, 2020, 03:03:15 pm »
updated to version 4.1

- changelog from 4.0 to 4.1

* add Blake3 and Blake3XOF support
* performance improvements especially XOF Related.

** Now updated in OPM




Thanks for your work on this encryption library, Xor-el.

Question for you:  Based on the following URL, I had expected Blake3 to perform faster than it does.

https://www.infoq.com/news/2020/01/blake3-fast-crypto-hash/

Here's the result I receive from compiling the performance benchmark project:


Adler32 Throughput: 1008.67 MB/s with Blocks of 64 KB
CRC-32_PKZIP_Generic Throughput: 272.60 MB/s with Blocks of 64 KB
CRC32_PKZIP_Fast Throughput: 1362.69 MB/s with Blocks of 64 KB
MurmurHash3_x86_32 Throughput: 1059.08 MB/s with Blocks of 64 KB
XXHash32 Throughput: 2872.15 MB/s with Blocks of 64 KB
SipHash2_4 Throughput: 490.02 MB/s with Blocks of 64 KB
XXHash64 Throughput: 5555.96 MB/s with Blocks of 64 KB
MurmurHash3_x86_128 Throughput: 1161.00 MB/s with Blocks of 64 KB
MurmurHash3_x64_128 Throughput: 2166.02 MB/s with Blocks of 64 KB
MD5 Throughput: 406.56 MB/s with Blocks of 64 KB
SHA1 Throughput: 203.96 MB/s with Blocks of 64 KB
SHA2_256 Throughput: 105.44 MB/s with Blocks of 64 KB
SHA2_512 Throughput: 166.15 MB/s with Blocks of 64 KB
SHA3_256 Throughput: 114.94 MB/s with Blocks of 64 KB
SHA3_512 Throughput: 62.42 MB/s with Blocks of 64 KB
Blake2B_256 Throughput: 253.35 MB/s with Blocks of 64 KB
Blake2B_512 Throughput: 250.90 MB/s with Blocks of 64 KB
Blake2S_128 Throughput: 135.23 MB/s with Blocks of 64 KB
Blake2S_256 Throughput: 134.46 MB/s with Blocks of 64 KB
Blake2BP_512 Throughput: 229.02 MB/s with Blocks of 64 KB
Blake2SP_256 Throughput: 122.54 MB/s with Blocks of 64 KB
Blake3_256 Throughput: 171.33 MB/s with Blocks of 64 KB

The results are for the 64-bit version running on an older i5 system.

On my Ryzen 2700X, I get the following (higher scores, but relatively similar ratios):


Adler32 Throughput: 1640.79 MB/s with Blocks of 64 KB
CRC-32_PKZIP_Generic Throughput: 473.77 MB/s with Blocks of 64 KB
CRC32_PKZIP_Fast Throughput: 2661.13 MB/s with Blocks of 64 KB
MurmurHash3_x86_32 Throughput: 2870.29 MB/s with Blocks of 64 KB
XXHash32 Throughput: 6589.35 MB/s with Blocks of 64 KB
SipHash2_4 Throughput: 875.60 MB/s with Blocks of 64 KB
XXHash64 Throughput: 11974.94 MB/s with Blocks of 64 KB
MurmurHash3_x86_128 Throughput: 3170.98 MB/s with Blocks of 64 KB
MurmurHash3_x64_128 Throughput: 5952.44 MB/s with Blocks of 64 KB
MD5 Throughput: 645.21 MB/s with Blocks of 64 KB
SHA1 Throughput: 362.31 MB/s with Blocks of 64 KB
SHA2_256 Throughput: 206.44 MB/s with Blocks of 64 KB
SHA2_512 Throughput: 331.27 MB/s with Blocks of 64 KB
SHA3_256 Throughput: 216.15 MB/s with Blocks of 64 KB
SHA3_512 Throughput: 117.08 MB/s with Blocks of 64 KB
Blake2B_256 Throughput: 622.10 MB/s with Blocks of 64 KB
Blake2B_512 Throughput: 609.48 MB/s with Blocks of 64 KB
Blake2S_128 Throughput: 262.54 MB/s with Blocks of 64 KB
Blake2S_256 Throughput: 264.10 MB/s with Blocks of 64 KB
Blake2BP_512 Throughput: 542.54 MB/s with Blocks of 64 KB
Blake2SP_256 Throughput: 237.92 MB/s with Blocks of 64 KB
Blake3_256 Throughput: 347.90 MB/s with Blocks of 64 KB

I skipped implementing Blake2 altogether, since it seems to be a little bit more involved to use than the other hash functions, and I expected Blake3 to be faster anyway.   (It would have helped if I had run the benchmark first.)

Any thoughts on the above?   Is there something that I am overlooking?

I compiled the benchmark as is.

Regards,
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.9 r63452 / FPC v3.2.1-beta-r45705 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 2004 (Build 19041.264)
Other Systems: Windows 10 Pro x64, Version 1909 or greater

 

TinyPortal © 2005-2018