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;
     Exit;
   end;
   end;
   {$IFDEF Use_OpenSSL}
   {$IFDEF Use_OpenSSL}
-  end;
   SetLength(Result,BN_num_bytes(EC_KEY_get0_private_key(FPrivateKeyInfo.EC_KEY_Ptr)));
   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)]);
   BN_bn2bin(EC_KEY_get0_private_key(FPrivateKeyInfo.EC_KEY_Ptr),@Result[Low(Result)]);
   {$ELSE}
   {$ELSE}

+ 4 - 0
src/core/UPCEncryption.pas

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

+ 5 - 0
src/core/UPCOpenSSLSignature.pas

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

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

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

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

@@ -106,7 +106,7 @@ implementation
   {$R *.lfm}
   {$R *.lfm}
 {$ENDIF}
 {$ENDIF}
 
 
-Uses UNode, UTime, UECIES, UAES, UAccounts, UFRMMemoText, UBaseTypes;
+Uses UNode, UTime, UPCEncryption, UAccounts, UFRMMemoText, UBaseTypes;
 
 
 { TFRMPayloadDecoder }
 { TFRMPayloadDecoder }
 
 
@@ -369,7 +369,7 @@ procedure TFRMPayloadDecoder.TryToDecode;
     for i := 0 to FWalletKeys.Count - 1 do begin
     for i := 0 to FWalletKeys.Count - 1 do begin
       WalletKey := FWalletKeys.Key[i];
       WalletKey := FWalletKeys.Key[i];
       If Assigned(WalletKey.PrivateKey) then begin
       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;
           Result := true;
           exit;
           exit;
         end;
         end;
@@ -383,7 +383,7 @@ procedure TFRMPayloadDecoder.TryToDecode;
   Begin
   Begin
     Result := false;
     Result := false;
     for i := 0 to memoPasswords.Lines.Count - 1 do begin
     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
         if (TCrypto.IsHumanReadable(Decrypted)) then begin
           Result := true;
           Result := true;
           PasswordUsed := memoPasswords.Lines[i];
           PasswordUsed := memoPasswords.Lines[i];

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

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

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

@@ -352,7 +352,7 @@ begin
       i := WalletKeys.IndexOfAccountKey(EC.PublicKey);
       i := WalletKeys.IndexOfAccountKey(EC.PublicKey);
       if (i>=0) then begin
       if (i>=0) then begin
         wk := WalletKeys.Key[i];
         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;
       end;
       s := 'Imported '+DateTimeToStr(now);
       s := 'Imported '+DateTimeToStr(now);
       s := InputBox('Set a name','Name for this private key:',s);
       s := InputBox('Set a name','Name for this private key:',s);

+ 12 - 24
src/pascalcoin_wallet_classic.lpi

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