CryptoLib4Pascal icon indicating copy to clipboard operation
CryptoLib4Pascal copied to clipboard

Several compilation errors

Open Uefi1 opened this issue 3 years ago • 5 comments

Hello, I can't compile the package again because there are several errors:

const
  EmptyBytesNil: TCryptoLibCustomByteArrayBuffer = (FData: Nil; FLength: 0;
    FIsNil: True);
[DCC Error] ClpCryptoLibTypes.pas(226): E2071 This type cannot be initialized

whether to replace :
var
  EmptyBytesNil: TCryptoLibCustomByteArrayBuffer = (FData: Nil; FLength: 0;
    FIsNil: True); 
???


Create(Int32(TThread.GetTickCount)); // Can be replaced by windows.GetTickCount ?
[DCC Error] ClpRandom.pas(108): E2003 Undeclared identifier: 'GetTickCount'
  if Supports(FHash, IXOF) then // What the  IXOF ???

  begin
    LXOFSizeInBits := (System.Length(output) - outOff) * 8;
    (FHash as IXOF).XOFSizeInBits := LXOFSizeInBits;
    Limit := LXOFSizeInBits shr 3;
  end
  else
  begin
    Limit := GetDigestSize;
  end;
[DCC Error] ClpDigest.pas(178): E2003 Undeclared identifier: 'IXOF'

Uefi1 avatar Aug 12 '22 23:08 Uefi1

You did not tell your Delphi version. Library supports Delphi Tokyo and newer versions. Library also needs HashLib4Pascal and SimpleBaseLib4Pascal.

I have no problem compiling the library and the ClpDigest.pas unit using Delphi 10.4.2 and I have identical code in my system. I also checked and made sure that I have the latest code from GitHub and they were actually the latest.

I have following library units in my test project they also need ClpDigest.pas to be compiled.

uses
  ClpIBufferedCipher,
  ClpCipherUtilities,
  ClpIParametersWithIV,
  ClpParametersWithIV,
  ClpParameterUtilities;

You probably need to give more information about your problem.

BTW, IXOF is an interface which is defined in HlpIHashInfo.pas in HaslLib4Pascal codes.

My wild guess, your search path is not complete. Search path for this library should have about 68 paths in it including CryptoLib4Pascal, SimpleBaseLib4Pascal, HashLib4Pascal.

ertankucukoglu avatar Aug 13 '22 00:08 ertankucukoglu

You did not tell your Delphi version. Library supports Delphi Tokyo and newer versions. Library also needs HashLib4Pascal and SimpleBaseLib4Pascal.

In any case, you can change the code so that it fits all versions of Delphi, my Version is Delphi XE2 UPD: really took the latest HashLib and already passed on now the actual errors are:

const
  EmptyBytesNil: TCryptoLibCustomByteArrayBuffer = (FData: Nil; FLength: 0;
    FIsNil: True);

[DCC Error] ClpCryptoLibTypes.pas(226): E2071 This type cannot be initialized
constructor TRandom.Create;
begin
{$IFDEF FPC}
  Create(Int32(TThread.GetTickCount64));
{$ELSE}
  Create(Int32(TThread.GetTickCount)); // replaced by Create(Int32(Windows.GetTickCount)); ??????
 
{$ENDIF FPC}
end;

[DCC Error] ClpRandom.pas(108): E2003 Undeclared identifier: 'GetTickCount'
  const
    ZeroBytes: TCryptoLibByteArray = Nil;

[DCC Error] ClpAsn1Objects.pas(985): E2071 This type cannot be initialized
  const
    ZeroBytes: TCryptoLibByteArray = Nil;
[DCC Error] ClpAsn1Objects.pas(985): E2071 This type cannot be initialized

Uefi1 avatar Aug 13 '22 01:08 Uefi1

Hello @Uefi1 as @ertankucukoglu has pointed out CryptoLib4Pascal has never supported XE2 from it's inception. the minimum supported version is Delphi Tokyo. you can try to modify the code for XE2 support but that would be a humongous task as even I was not able to achieve that when building out the library in the first place since the code uses a couple of modern Delphi features not available in XE2. Making HashLib4Pascal and SimpleBaseLib4Pascal compatible with XE2 was quite easy because it was initially built with Delphi 2010 support in mind. if this is a task you wish to undertake then that is fine but I am not willing to go through that process for this Library.

One last thing, if you can't afford to upgrade to the latest version of Delphi, you can consider using Lazarus/FPC as that is free and supported by this library.

Xor-el avatar Aug 13 '22 07:08 Xor-el

if this is a task you wish to undertake then that is fine but I am not willing to go through that process for this Library.

I still don't understand if I need this library or not, does it allow me to work with bip39 mnemonic phrases or not?

Uefi1 avatar Aug 13 '22 08:08 Uefi1

if this is a task you wish to undertake then that is fine but I am not willing to go through that process for this Library.

I still don't understand if I need this library or not, does it allow me to work with bip39 mnemonic phrases or not?

out of the box, no. however, this library provides Cryptographic primitives which you can build on top to achieve your goals if you know how to use it.

Xor-el avatar Aug 13 '22 10:08 Xor-el

out of the box, no. however, this library provides Cryptographic primitives which you can build on top to achieve your goals if you know how to use it. Is there anything I can use out of the box to work with bip39 bip44 from Delphi ?

Uefi1 avatar Aug 13 '22 12:08 Uefi1

out of the box, no. however, this library provides Cryptographic primitives which you can build on top to achieve your goals if you know how to use it. Is there anything I can use out of the box to work with bip39 bip44 from Delphi ?

Unfortunately, not sure of any.

Xor-el avatar Aug 13 '22 23:08 Xor-el

Unfortunately, not sure of any. Please make such a library for delphi =)

Uefi1 avatar Aug 14 '22 03:08 Uefi1

You can use PBKDF2 to implement BIP39 easily ... PBKDF2 is contained for example in the TMS Crypt Lib. https://learnmeabitcoin.com/technical/mnemonic shows how to do it. Alternatively you could create a C DLL based on some code here and use that wihtin your Delphi project.

ctriroli avatar Aug 15 '22 13:08 ctriroli

You can use PBKDF2 to implement BIP39 easily ... PBKDF2 is contained for example in the TMS Crypt Lib. https://learnmeabitcoin.com/technical/mnemonic shows how to do it. Alternatively you could create a C DLL based on some code here and use that wihtin your Delphi project.

I think this is the best approach for him as he is not able to upgrade his Delphi version at this moment. That been said, if he only needs PBKDF2 to implement BIP39 (no idea about this) , then HashLib4Pascal is sufficient too.

Xor-el avatar Aug 15 '22 13:08 Xor-el

You can use PBKDF2 to implement BIP39 easily ... PBKDF2 is contained for example in the TMS Crypt Lib.

I think this is the best approach for him as he is not able to upgrade his Delphi version at this moment. That been said, if he only needs PBKDF2 to implement BIP39 (no idea about this) , then HashLib4Pascal is sufficient too.

Yes, I tried to run javascripts bip39 https://github.com/iancoleman/bip39 from under delphi, there are several libraries for this: ChakraCore, v8delphiwrapper, but since I know very little javascript, my attempts were unsuccessful, there you need to somehow correct the javascript codes in order to successfully launch =(

Uefi1 avatar Aug 16 '22 06:08 Uefi1

Even better might be to use a Python implementation https://pypi.org/project/bip39/ Delphi and Python in combination rocks as we all hopefully know ;-) https://pythongui.org/python4delphi/

ctriroli avatar Aug 16 '22 10:08 ctriroli

Delphi and Python in combination rocks as we all hopefully know ;-)

Such an implementation python4delphi is not suitable since it requires the python itself installed in the system !

Uefi1 avatar Aug 16 '22 10:08 Uefi1

@Uefi1 , maybe you can try porting the Python or Javascript implementation to Delphi. It would be a great way to contribute to the Delphi open source ecosystem.

Xor-el avatar Aug 16 '22 10:08 Xor-el

maybe you can try porting the Python or Javascript implementation to Delphi. It would be a great way to contribute to the Delphi open source ecosystem.

I don't have enough knowledge for this, I'm still just a beginner programmer =)

Uefi1 avatar Aug 16 '22 11:08 Uefi1

Delphi and Python in combination rocks as we all hopefully know ;-)

Such an implementation python4delphi is not suitable since it requires the python itself installed in the system !

That is like saying any application with a required dll for deployment would not be suitable. You install Python4Delphi in your IDE and need to distribute the Python DLL with your application (I guess). Why is that not suitable in your situation?

ctriroli avatar Aug 16 '22 21:08 ctriroli

That is like saying any application with a required dll for deployment would not be suitable. You install Python4Delphi in your IDE and need to distribute the Python DLL with your application (I guess). Why is that not suitable in your situation?

For python4delphi, python must be installed on the system, this is inconvenient !!!

Uefi1 avatar Aug 17 '22 05:08 Uefi1

For python4delphi, python must be installed on the system, this is inconvenient !!!

No, you only need to distribute the python dll with your application. Distribution of dlls is a common thing.

ctriroli avatar Aug 17 '22 06:08 ctriroli

For python4delphi, python must be installed on the system, this is inconvenient !!!

No, you only need to distribute the python dll with your application. Distribution of dlls is a common thing.

See: https://en.delphipraxis.net/topic/6686-python-dll-init-question/

ctriroli avatar Aug 17 '22 06:08 ctriroli

See: https://en.delphipraxis.net/topic/6686-python-dll-init-question/

Hail, it turns out the bip39 library appeared on chilkat: )) https://www.example-code.com/delphiDll/bip39_computation_of_binary_seed.asp I have only one question left, how can I now use this library to convert the mnemonic phrase to the address of the ETHERIUM wallet, if you can figure it out please write me Please =)

Uefi1 avatar Aug 18 '22 07:08 Uefi1