mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-26 13:09:26 +02:00
* Blowfish II implementation
This commit is contained in:
parent
1714dbb563
commit
1886fad528
@ -66,7 +66,9 @@ ipcserver Server part of SimpleIPC unit test, console app (MVC)
|
||||
ipcclient Client part of SimpleIPC unit test, console app (MVC)
|
||||
testdebug Client part of dbugintf debugging info test (MVC)
|
||||
testbf.pp Test for BlowFish encryption (MVC)
|
||||
testbf2.pp Test for BlowFish 2 encryption (MVC)
|
||||
testbfs.pp Test for BlowFish encryption/descryption stream (MVC)
|
||||
testbf2s.pp Test for BlowFish 2 encryption/descryption stream (MVC)
|
||||
testzip.pp Test for TZipper class (MVC)
|
||||
poolmm1.pp Test for pooledmm (free) (MG)
|
||||
poolmm2.pp Test for pooledmm (nonfree) (VS)
|
||||
|
130
packages/fcl-base/examples/testbf2.pp
Normal file
130
packages/fcl-base/examples/testbf2.pp
Normal file
@ -0,0 +1,130 @@
|
||||
{
|
||||
This file is part of the Free Component Library (FCL)
|
||||
Copyright (c) 2023 by the Free Pascal development team
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
{
|
||||
Blowfish 2 test.
|
||||
Based on http://pccipher.free.fr/blowfish2/blowfish2.txt
|
||||
}
|
||||
program testbf2;
|
||||
|
||||
uses blowfish2, blowfish, sysutils;
|
||||
|
||||
Procedure Test1;
|
||||
|
||||
var
|
||||
L,R : QWord;
|
||||
ctx : TBlowfish2Context;
|
||||
|
||||
begin
|
||||
(* Plaintext 128-bit block :$00000000000000010000000000000002 *)
|
||||
|
||||
L := QWord($0000000000000001);
|
||||
R := QWord($0000000000000002); // 64 bits L + 64 bits R = 128-bit block
|
||||
|
||||
|
||||
Writeln(format('Plaintext 128-bit block: %x %x',[L, R]));
|
||||
Writeln('Key: TESTKEY');
|
||||
|
||||
Blowfish2_Init (@ctx, 'TESTKEY', 7);
|
||||
Blowfish2_Encrypt(@ctx, L, R);
|
||||
|
||||
Writeln('Ciphertext 128-bit block: ');
|
||||
Writeln(format('%X %X',[L, R]));
|
||||
|
||||
if (L = QWord($7B2B9DE71D1B1C62)) and (R = QWord($91C230351177BEE8)) then
|
||||
Writeln('Test encryption OK.')
|
||||
else
|
||||
Writeln('Test encryption failed');
|
||||
Blowfish2_Decrypt(@ctx, L, R);
|
||||
if (L = 1) and (R = 2) then
|
||||
Writeln('Test decryption OK.')
|
||||
else
|
||||
Writeln('Test decryption failed.');
|
||||
end;
|
||||
|
||||
Procedure Test2;
|
||||
|
||||
var
|
||||
L,R : QWord;
|
||||
ctx : TBlowfish2Context;
|
||||
|
||||
begin
|
||||
|
||||
(* Plaintext 128-bit block :$01020304050607080910111213141516 *)
|
||||
|
||||
L:=QWord($0102030405060708);
|
||||
R:=QWord($0910111213141516);
|
||||
|
||||
|
||||
Writeln(format('Plaintext 128-bit block : %x %x',[L, R]));
|
||||
|
||||
Writeln('Key: A');
|
||||
|
||||
Blowfish2_Init (@ctx, 'A', 1);
|
||||
Blowfish2_Encrypt(@ctx, L, R);
|
||||
|
||||
Writeln('Ciphertext 128-bit block: ');
|
||||
Writeln(Format('%x %x', [L, R]));
|
||||
|
||||
if (L = QWord($CA38165603F9915C)) and (R = QWord($61F0776A0F55E807)) then
|
||||
Writeln('Test encryption OK.')
|
||||
else
|
||||
Writeln('Test encryption failed.');
|
||||
Blowfish2_Decrypt(@ctx, L,R);
|
||||
if (L=QWord($0102030405060708)) and (R = QWord($0910111213141516)) then
|
||||
Writeln('Test decryption OK.')
|
||||
else
|
||||
Writeln('Test decryption failed.');
|
||||
end;
|
||||
|
||||
Procedure Test3;
|
||||
|
||||
var
|
||||
L,R : QWord;
|
||||
ctx : TBlowfish2Context;
|
||||
|
||||
begin
|
||||
|
||||
(* Plaintext 128-bit block :$01020304050607080910111213141516 *)
|
||||
|
||||
L:=QWord($0102030405060708);
|
||||
R:=QWord($0910111213141516);
|
||||
|
||||
|
||||
Writeln(Format('Plaintext 128-bit block: %x %x',[L, R]));
|
||||
|
||||
Writeln('Key: B');
|
||||
|
||||
Blowfish2_Init(@ctx, 'B', 1);
|
||||
Blowfish2_Encrypt(@ctx, L, R);
|
||||
|
||||
Writeln('Ciphertext 128-bit block: ');
|
||||
Writeln(format('%x %x', [L, R]));
|
||||
|
||||
if (L = QWord($D07690A78B109983)) and (R = QWord($8DDF85826F2366C2)) then
|
||||
Writeln('Test encryption OK.')
|
||||
else
|
||||
Writeln('Test encryption failed.');
|
||||
Blowfish2_Decrypt(@ctx, L, R);
|
||||
if (L = QWord($0102030405060708)) and (R = QWord($0910111213141516)) then
|
||||
Writeln('Test decryption OK.')
|
||||
else
|
||||
Writeln('Test decryption failed.');
|
||||
end;
|
||||
|
||||
|
||||
begin
|
||||
Test1;
|
||||
Test2;
|
||||
Test3;
|
||||
end.
|
||||
|
@ -48,6 +48,8 @@ begin
|
||||
T.ResourceStrings:=true;
|
||||
T:=P.Targets.AddUnit('blowfish.pp');
|
||||
T.ResourceStrings:=true;
|
||||
T:=P.Targets.AddUnit('blowfish2.pp');
|
||||
T.ResourceStrings:=true;
|
||||
T:=P.Targets.AddUnit('bufstream.pp');
|
||||
T.ResourceStrings:=true;
|
||||
T:=P.Targets.AddUnit('cachecls.pp');
|
||||
|
3
packages/fcl-base/namespaced/System.Hash.Blowfish2.pp
Normal file
3
packages/fcl-base/namespaced/System.Hash.Blowfish2.pp
Normal file
@ -0,0 +1,3 @@
|
||||
unit System.Hash.Blowfish2;
|
||||
{$DEFINE FPC_DOTTEDUNITS}
|
||||
{$i blowfish2.pp}
|
@ -39,6 +39,7 @@ src/streamcoll.pp=namespaced/Fcl.Streams.Collection.pp
|
||||
src/inifiles.pp=namespaced/System.IniFiles.pp
|
||||
src/custapp.pp=namespaced/Fcl.CustApp.pp
|
||||
src/blowfish.pp=namespaced/System.Hash.Blowfish.pp
|
||||
src/blowfish2.pp=namespaced/System.Hash.Blowfish2.pp
|
||||
src/nullstream.pp=namespaced/Fcl.Streams.Null.pp
|
||||
src/syncobjs.pp=namespaced/System.SyncObjs.pp
|
||||
src/avl_tree.pp=namespaced/Fcl.AVLTree.pp
|
||||
|
1193
packages/fcl-base/src/blowfish2.pp
Normal file
1193
packages/fcl-base/src/blowfish2.pp
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user