Xor-el / CryptoLib4Pascal

Crypto for Modern Object Pascal
MIT License
209 stars 63 forks source link

Several compilation errors #33

Closed Uefi1 closed 1 year ago

Uefi1 commented 2 years ago

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'
ertankucukoglu commented 2 years ago

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.

Uefi1 commented 2 years ago

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
Xor-el commented 2 years ago

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.

Uefi1 commented 2 years ago

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?

Xor-el commented 2 years ago

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.

Uefi1 commented 2 years ago

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 ?

Xor-el commented 2 years ago

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.

Uefi1 commented 2 years ago

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

ctriroli commented 2 years ago

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.

Xor-el commented 2 years ago

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.

Uefi1 commented 2 years ago

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 =(

ctriroli commented 2 years ago

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/

Uefi1 commented 2 years ago

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 !

Xor-el commented 2 years ago

@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.

Uefi1 commented 2 years ago

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

ctriroli commented 2 years ago

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?

Uefi1 commented 2 years ago

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 !!!

ctriroli commented 2 years ago

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 commented 2 years ago

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/

Uefi1 commented 2 years ago

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