bcrypt-for-delphi icon indicating copy to clipboard operation
bcrypt-for-delphi copied to clipboard

Compatibility with Platforms other than Windows

Open GabryJ84 opened this issue 4 years ago • 3 comments

Latest Delphi versions added the possibility to compile also for other platforms, including Android, iOS/OSX and Linux64.

The code is not compatible because of the following issues:

  • It uses Windows, ComObj and ActiveX which are Windows exclusives.

I am not a Crypto expert but as far as I have been able to investigate, the incompatibilities are relative to some Memory Management, the Hash Generation and the Password robustness check and, in particular:

CryptAcquireContextW CryptReleaseContext CryptGenRandom CryptAcquireContext CryptCreateHash CryptHashData CryptGetHashParam CryptDestroyHash

who use advapi32 which is not present in other platforms.

OleCheck/CoCreateGUID

which doesn't work outside Windows

ZeroMemory HResultFromWin32

which doesn't work outside Windows too

AnsiString PAnsiChar FoldStringW WideCharToMultiByte

which is not present in Linux64, Android and iOS

QueryPerformanceFrequency QueryPerformanceCounter

which works only with Windows

I have investigated a bit and discovered that the 2 point is easily solvable since Delphi provides a CreateGuid function which is platform independent.

As for point 5, there should be TStopWatch (which, on Windows, queries QueryPerformanceCounter), but I don't know if it works also for QueryPerformanceFrequency.

As for point 4, the matter is tricky since strings are all UTF-16 encoded and the type AnsiString is not present.

As for point 3, Zeromemory seems to be replaceable with FillByte but don't know if you achieve the same results, while HResultFromWin32 maybe is useless and GetLastError is sufficient enough?

Point 1 could be solved using System.Hash functions, although I don't know when this was added (no more than 10 years ago) so there should be some conditionals telling the code to use System.Hash on non windows systems.

I believe that since this unit is gold for developers, since it allows to write cross platform apache modules and CGIs, it would be a good thing to add the compatibility to all of the platforms delphi supports.

Thankyou

GabryJ84 avatar Mar 15 '20 13:03 GabryJ84

I'm also interested in using this library on Android platform.

dominikkv avatar Apr 27 '20 09:04 dominikkv

At the very least the code in BCrypt.pas has to run on Delphi 5. So if you want to take advantage of anything only available in newer versions of Delphi, you have to re-implement those features.

JackTrapper avatar Apr 01 '21 14:04 JackTrapper

@GabryJ84 try this: https://github.com/viniciussanchez/bcrypt

kazuser avatar Jul 22 '24 05:07 kazuser