Hello, I wanted to consult you. If you know why this can happen.
The same functions in 64bits return different result in Linux 32bits, than in 64bits. Also try on windows32 and macos64, they return the same value as linux64.
But linux32 returns different values.
Here is an example:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, sha1, base64;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
function GenerateKey(const StrToHash: string): string;
var
Outstream: TStringStream;
Encoder: TBase64EncodingStream;
SHA1Digest: TSHA1Digest;
begin
Outstream := TStringStream.Create('');
try
Encoder := TBase64EncodingStream.Create(outstream);
try
SHA1Digest := SHA1String(StrToHash+'258EAFA5-E914-47DA-95CA-C5AB0DC85B11');
Encoder.Flush;
Encoder.Write(SHA1Digest, Length(SHA1Digest));
finally
Encoder.Free;
end;
Result:=Outstream.DataString;
finally
Outstream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
edit2.Text:=GenerateKey('test');
end;
end.
The result must be: tNpbgC8ZQDOcSkHAWopKzQjJ1hI=
But in linux32 is not (the value return is: AoVU8zR2n+1MVbedLj2kKV4v5aQ=).
UPDATE: The result in Linux32, changes in every run
SOLUTION: isn't the best but, i copy sha1.pp into application's directory and add:
// Normally, if an optimized version is available for OS/CPU, that will be used
// Define to use existing unoptimized implementation
{ the assembler implementation does not work on darwin }
{$ifdef darwin}
{$DEFINE SHA1PASCAL}
{$endif darwin}
{$IFDEF LINUX}
{$IFDEF CPU32}
{$DEFINE SHA1PASCAL}
{$ENDIF}
{$ENDIF}
Now works fine