My testing system is Ubuntu 18.04 (32-bit). However, the same problem occurs in the latest 32-bit Debian 12 (bookworm).
The test program given in
https://wiki.freepascal.org/HMAC-SHA1 returns random and incorrect strings.
Example 1 gives
always the same incorrect value:
Example 1: dfaf125adbe5cf8c8fbc156a0b6e7ccdceb25db8
While Example 2 gives
random values in each program invocation.
I am testing the following program:
// See some samples in: http://en.wikipedia.org/wiki/Hash-based_message_authentication_code
program hsha1;
{$mode objfpc}{$H+}
uses
HMAC;
begin
// for HMAC_SHA1("", "") = 0xfbdb1d1b18aa6c08324b7d64b71fb76370690e1d
WriteLn('Example 1: ', HMACSHA1Print(HMACSHA1Digest('', '')));
// for HMAC_SHA1("key", "The quick brown fox jumps over the lazy dog") = 0xde7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9
WriteLn('Example 2: ', HMACSHA1('key', 'The quick brown fox jumps over the lazy dog'));
WriteLn('Example 2: ', HMACSHA1Print(HMACSHA1Digest('key', 'The quick brown fox jumps over the lazy dog')));
end.
Version of FPC is:
Free Pascal Compiler version 3.2.2 [2021/07/09] for i386 # On Ubuntu 18.04 32-bit
Free Pascal Compiler version 3.2.2+dfsg-20 [2023/03/30] for i386 # On Debian 12 32-bit
No problem on Windows (32-bit and 64-bit) version and Ubuntu 64-bit.