Forum > Unix

Calling the same sha1 functions, on linux 32bits different than 64bit (SOLVED)

(1/2) > >>

esvignolo:
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:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

john horst:
Must be a bug in whatever version of the compiler you are using.

Linux 32 (Ubuntu 16.04) / Free Pascal Compiler version 3.3.1-r20:41871M [2019/04/15] for i386 and Free Pascal Compiler version 3.0.4 [2017/10/02] for i386

Linux 64 (UBUNTU 19.04) / Free Pascal Compiler version 3.2.0-beta-r44874 [2020/04/19] for x86_64

I get the expected result of tNpbgC8ZQDOcSkHAWopKzQjJ1hI= everytime

Thaddy:
I also can not replicate it on linux-armhf (which is 32 bit) Raspbian.

esvignolo:

--- Quote from: john horst on April 20, 2020, 08:13:58 am ---Must be a bug in whatever version of the compiler you are using.

Linux 32 (Ubuntu 16.04) / Free Pascal Compiler version 3.3.1-r20:41871M [2019/04/15] for i386 and Free Pascal Compiler version 3.0.4 [2017/10/02] for i386

Linux 64 (UBUNTU 19.04) / Free Pascal Compiler version 3.2.0-beta-r44874 [2020/04/19] for x86_64

I get the expected result of tNpbgC8ZQDOcSkHAWopKzQjJ1hI= everytime

--- End quote ---

Hi, thanks for testing. I use the trunk FPC SVN Revision 62571M and now update today, and the bug still there.

ASBzone:

--- Quote from: esvignolo on April 20, 2020, 12:56:32 am ---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.


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  %)

Thanks!!!

--- End quote ---


What version of Linux, FPC and Lazarus?


Also, are using the 32-bit version of FPC or the 64-bit version and cross-compiling?

Navigation

[0] Message Index

[#] Next page

Go to full version