?? rc2.txt
字號:
Encryption Algorithm Implementations
====================================
DISCLAIMER:
This implementation was developed totally outside of the USA and so it is free
from export restrictions. However if you have laws in your country which prevent
the use of strong cryptographical products then please remove this archive from
your computer. I retain no responsibly for this implementation.
This implementation is FREEWARE, you may use this implementation freely. You
have permission to modify any of the files included in this archive provided you
do not redistribute these files. If you wish to redistribute these
implementations you may do so provided all the files in this archive are kept
intact and unmodified. If you do redistribute these files please email me and
tell me (if you upload to a BBS/web site/ftp site etc), this is not a requirement
but it is nice to know who is using these implementations.
For the lastest updates/information try
http://web.ukonline.co.uk/david.w32/delphi.html
or email davebarton@bigfoot.com
Algorithm Details
-----------------
Name RC2 block cipher
Author Ron Rivest
Patented No (the name is copyright)
Block size 64bit
Key size Variable - upto 1024bit
Modes ECB, CBC, CFB 8bit, OFB, OFB counter 8bit
Procedures
----------
function RC2SelfTest: Boolean;
Performs a self test
procedure RC2Init;
Initializes a TRC2Data record with key information
procedure RC2Burn;
Clears a TRC2Data record of any key information
procedure RC2Reset;
Resets any chaining mode information (needed for CBC, CFB, OFB, OFBC)
procedure RC2EncryptECB;
Encrypts the data in a 64bit block using the ECB mode
procedure RC2DecryptECB;
Decrypts the data in a 64bit block using the ECB mode
procedure RC2EncryptCBC;
Encrypts the data in a 64bit block using the CBC chaining mode
procedure RC2DecryptCBC;
Decrypts the data in a 64bit block using the CBC chaining mode
procedure RC2EncryptOFB;
Encrypts the data in a 64bit block using the OFB chaining mode
procedure RC2DecryptOFB;
Decrypts the data in a 64bit block using the OFB chaining mode
procedure RC2EncryptCFB;
Encrypts Len bytes of data using the CFB chaining mode
procedure RC2DecryptCFB;
Decrypts Len bytes of data using the CFB chaining mode
procedure RC2EncryptOFBC;
Encrypts Len bytes of data using the OFB counter chaining mode
procedure RC2DecryptOFBC;
Decrypts Len bytes of data using the OFB counter chaining mode
Usage
-----
Before usage I recommend that you call the SelfTest function to test that the
implementation is performing correctly.
Before you can use the encryption routines you must call Init to perform the
keysetup routines, if you are planning on using any of the chaining modes
(CBC, CFB, OFB, OFBC) then you need to supply an initialization vector (IV) which
is the same size as the block size (64bit). The IV is just a block of data used
to initialize the chaining modes - it doesn't have to be kept secret.
If you only want to use the ECB encryption mode you can then just call the
encryption and decryption routines as you want, to encrypt data in blocks.
If you want to use the chaining modes (which hides patterns in the data) you must
call the Reset procedure after a series of encryptions/decryptions.
eg.
procedure EncryptAndDecrypt;
const
Key: array[0..7] of byte= ($11, $22, $33, $44, $55, $66, $77, $88);
IV: array[0..7] of byte= ($11, $22, $33, $44, $55, $66, $77, $88);
var
Data: array[1..8192] of byte;
i: integer;
KeyData: TRC2Data;
begin
RC2Init(KeyData,@Key,Sizeof(Key),@IV);
for i:= 1 to (8192 div 8) do
RC2EncryptCBC(KeyData,@Data[(i-1)*8],@Data[(i-1)*8]);
RC2Reset(KeyData);
for i:= 1 to (8192 div 8) do
RC2DecryptCBC(KeyData,@Data[(i-1)*8],@Data[(i-1)*8]);
RC2Reset(KeyData); // not really necessary but just to demonstrate
RC2Burn;
end;
Finally you should always call Burn.
Notes On Encryption Modes
-------------------------
ECB, CBC, OFB: These modes encrypt data in blocks of 64bits (8bytes)
CFB, OFBC: These modes encrypt data in blocks of 8bits (1byte)
I hope you find this implementation useful!
Dave
davebarton@bigfoot.com
http://web.ukonline.co.uk/david.w32/delphi.html
Copyright (c) 1998 David Barton
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -