Browse Source

Allow CryptoLib4Pascal - gui-classic

Pascal Coin 6 years ago
parent
commit
42043b4b7a

+ 0 - 1
src/core/UCrypto.pas

@@ -233,7 +233,6 @@ begin
     Exit;
   end;
   {$IFDEF Use_OpenSSL}
-  end;
   SetLength(Result,BN_num_bytes(EC_KEY_get0_private_key(FPrivateKeyInfo.EC_KEY_Ptr)));
   BN_bn2bin(EC_KEY_get0_private_key(FPrivateKeyInfo.EC_KEY_Ptr),@Result[Low(Result)]);
   {$ELSE}

+ 4 - 0
src/core/UPCEncryption.pas

@@ -30,6 +30,10 @@ unit UPCEncryption;
 
 interface
 
+{$IFDEF FPC}
+  {$MODE Delphi}
+{$ENDIF}
+
 {$I config.inc}
 
 {$IF (not Defined(Use_OpenSSL)) and (not Defined(Use_CryptoLib4Pascal))}

+ 5 - 0
src/core/UPCOpenSSLSignature.pas

@@ -26,6 +26,11 @@ unit UPCOpenSSLSignature;
 
 interface
 
+{$IFDEF FPC}
+  {$MODE Delphi}
+{$ENDIF}
+
+
 {$I config.inc}
 
 {$IF (not Defined(Use_OpenSSL))}

+ 6 - 5
src/gui-classic/UFRMOperation.pas

@@ -32,6 +32,7 @@ uses
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls, UNode, UWallet, UCrypto, Buttons, UBlockChain,
   UAccounts, UFRMAccountSelect, ActnList, ComCtrls, Types, UFRMMemoText,
+  UPCEncryption,
   UBaseTypes, UPCOrderedLists;
 
 Const
@@ -182,7 +183,7 @@ type
 implementation
 
 uses
-  UECIES, UConst, UOpTransaction, UFRMNewPrivateKeyType, UAES, UFRMWalletKeys,
+  UConst, UOpTransaction, UFRMNewPrivateKeyType, UFRMWalletKeys,
   UCommon, UGUIUtils, UPCDataTypes, ULog;
 
 {$IFnDEF FPC}
@@ -1322,7 +1323,7 @@ begin
       // Use sender
       errors := 'Error encrypting';
       account := FNode.Operations.SafeBoxTransaction.Account(SenderAccount.account);
-      payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u));
+      TPCEncryption.DoPascalCoinECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u),payload_encrypted);
       valid := Length(payload_encrypted)>0;
     end else if (rbEncryptedWithEC.Checked) then begin
       errors := 'Error encrypting';
@@ -1358,7 +1359,7 @@ begin
           exit;
         end;
         account := FNode.Operations.SafeBoxTransaction.Account(dest_account_number);
-        payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u));
+        TPCEncryption.DoPascalCoinECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u),payload_encrypted);
         valid := Length(payload_encrypted)>0;
       end else if (PageControlOpType.ActivePage=tsChangePrivateKey) then begin
         if (rbChangeKeyWithAnother.Checked) then begin
@@ -1380,7 +1381,7 @@ begin
           exit;
         end;
         if public_key.EC_OpenSSL_NID<>CT_Account_NUL.accountInfo.accountKey.EC_OpenSSL_NID then begin
-          payload_encrypted := ECIESEncrypt(public_key,TEncoding.ANSI.GetBytes(payload_u));
+          TPCEncryption.DoPascalCoinECIESEncrypt(public_key,TEncoding.ANSI.GetBytes(payload_u),payload_encrypted);
           valid := Length(payload_encrypted)>0;
         end else begin
           valid := false;
@@ -1391,7 +1392,7 @@ begin
         errors := 'This operation does not allow this kind of payload';
       end;
     end else if (rbEncrptedWithPassword.Checked) then begin
-      payload_encrypted := TAESComp.EVP_Encrypt_AES256(TEncoding.ANSI.GetBytes(payload_u),TEncoding.ANSI.GetBytes(ebEncryptPassword.Text));
+      payload_encrypted := TPCEncryption.DoPascalCoinAESEncrypt(TEncoding.ANSI.GetBytes(payload_u),TEncoding.ANSI.GetBytes(ebEncryptPassword.Text));
       valid := Length(payload_encrypted)>0;
     end else if (rbNotEncrypted.Checked) then begin
       payload_encrypted := TEncoding.ANSI.GetBytes(payload_u);

+ 3 - 3
src/gui-classic/UFRMPayloadDecoder.pas

@@ -106,7 +106,7 @@ implementation
   {$R *.lfm}
 {$ENDIF}
 
-Uses UNode, UTime, UECIES, UAES, UAccounts, UFRMMemoText, UBaseTypes;
+Uses UNode, UTime, UPCEncryption, UAccounts, UFRMMemoText, UBaseTypes;
 
 { TFRMPayloadDecoder }
 
@@ -369,7 +369,7 @@ procedure TFRMPayloadDecoder.TryToDecode;
     for i := 0 to FWalletKeys.Count - 1 do begin
       WalletKey := FWalletKeys.Key[i];
       If Assigned(WalletKey.PrivateKey) then begin
-        If ECIESDecrypt(WalletKey.PrivateKey.EC_OpenSSL_NID,WalletKey.PrivateKey.PrivateKey,false,raw,Decrypted) then begin
+        if TPCEncryption.DoPascalCoinECIESDecrypt(WalletKey.PrivateKey.PrivateKey,raw,Decrypted) then begin
           Result := true;
           exit;
         end;
@@ -383,7 +383,7 @@ procedure TFRMPayloadDecoder.TryToDecode;
   Begin
     Result := false;
     for i := 0 to memoPasswords.Lines.Count - 1 do begin
-      if (TAESComp.EVP_Decrypt_AES256(raw,memoPasswords.Lines[i],Decrypted)) then begin
+      if TPCEncryption.DoPascalCoinAESDecrypt(raw,TEncoding.ANSI.GetBytes(memoPasswords.Lines[i]),Decrypted) then begin
         if (TCrypto.IsHumanReadable(Decrypted)) then begin
           Result := true;
           PasswordUsed := memoPasswords.Lines[i];

+ 1 - 1
src/gui-classic/UFRMWallet.pas

@@ -317,7 +317,7 @@ implementation
 {$ENDIF}
 
 Uses UFolderHelper, UOpenSSL, UTime, UFileStorage,
-  UThread, UOpTransaction, UECIES, UFRMPascalCoinWalletConfig,
+  UThread, UOpTransaction, UFRMPascalCoinWalletConfig,
   UFRMOperationsExplorer,
   {$IFDEF TESTNET}
   UFRMRandomOperations,

+ 1 - 1
src/gui-classic/UFRMWalletKeys.pas

@@ -352,7 +352,7 @@ begin
       i := WalletKeys.IndexOfAccountKey(EC.PublicKey);
       if (i>=0) then begin
         wk := WalletKeys.Key[i];
-        if Assigned(wk.PrivateKey) And (Assigned(wk.PrivateKey.PrivateKey)) then raise Exception.Create('This key is already in your wallet!');
+        if Assigned(wk.PrivateKey) And (wk.PrivateKey.HasPrivateKey) then raise Exception.Create('This key is already in your wallet!');
       end;
       s := 'Imported '+DateTimeToStr(now);
       s := InputBox('Set a name','Name for this private key:',s);

+ 12 - 24
src/pascalcoin_wallet_classic.lpi

@@ -21,7 +21,7 @@
     <VersionInfo>
       <UseVersionInfo Value="True"/>
       <MajorVersionNr Value="4"/>
-      <RevisionNr Value="2"/>
+      <RevisionNr Value="3"/>
       <StringTable ProductVersion="0.0.0.0"/>
     </VersionInfo>
     <BuildModes Count="1">
@@ -40,7 +40,7 @@
         <PackageName Value="LCL"/>
       </Item1>
     </RequiredPackages>
-    <Units Count="33">
+    <Units Count="32">
       <Unit0>
         <Filename Value="pascalcoin_wallet_classic.dpr"/>
         <IsPartOfProject Value="True"/>
@@ -167,40 +167,36 @@
         <IsPartOfProject Value="True"/>
       </Unit24>
       <Unit25>
-        <Filename Value="core\UOpenSSLdef.pas"/>
+        <Filename Value="core\UFileStorage.pas"/>
         <IsPartOfProject Value="True"/>
       </Unit25>
       <Unit26>
-        <Filename Value="core\UFileStorage.pas"/>
+        <Filename Value="core\UAES.pas"/>
         <IsPartOfProject Value="True"/>
       </Unit26>
       <Unit27>
-        <Filename Value="core\UAES.pas"/>
+        <Filename Value="core\UChunk.pas"/>
         <IsPartOfProject Value="True"/>
       </Unit27>
       <Unit28>
-        <Filename Value="core\UChunk.pas"/>
-        <IsPartOfProject Value="True"/>
-      </Unit28>
-      <Unit29>
         <Filename Value="gui-classic\UFRMAccountSelect.pas"/>
         <IsPartOfProject Value="True"/>
         <ComponentName Value="FRMAccountSelect"/>
         <HasResources Value="True"/>
         <ResourceBaseClass Value="Form"/>
+      </Unit28>
+      <Unit29>
+        <Filename Value="core\UBaseTypes.pas"/>
+        <IsPartOfProject Value="True"/>
       </Unit29>
       <Unit30>
-        <Filename Value="core\UBaseTypes.pas"/>
+        <Filename Value="config.inc"/>
         <IsPartOfProject Value="True"/>
       </Unit30>
       <Unit31>
-        <Filename Value="config.inc"/>
-        <IsPartOfProject Value="True"/>
-      </Unit31>
-      <Unit32>
         <Filename Value="core\UTxMultiOperation.pas"/>
         <IsPartOfProject Value="True"/>
-      </Unit32>
+      </Unit31>
     </Units>
   </ProjectOptions>
   <CompilerOptions>
@@ -211,7 +207,7 @@
     </Target>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
-      <OtherUnitFiles Value="core;gui-classic;libraries\synapse;libraries\sphere10;libraries\hashlib4pascal;libraries\generics.collections;libraries\pascalcoin;libraries\paszlib"/>
+      <OtherUnitFiles Value="core;gui-classic;libraries\synapse;libraries\sphere10;libraries\cryptolib4pascal;libraries\simplebaselib4pascal;libraries\hashlib4pascal;libraries\generics.collections;libraries\pascalcoin;libraries\paszlib"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     <Parsing>
@@ -219,15 +215,7 @@
         <SyntaxMode Value="Delphi"/>
       </SyntaxOptions>
     </Parsing>
-    <CodeGeneration>
-      <Optimizations>
-        <OptimizationLevel Value="4"/>
-      </Optimizations>
-    </CodeGeneration>
     <Linking>
-      <Debugging>
-        <GenerateDebugInfo Value="False"/>
-      </Debugging>
       <Options>
         <Win32>
           <GraphicApplication Value="True"/>