?? cast128.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://www.hertreg.ac.uk/ss/
or email davebarton@bigfoot.com
Algorithm Details
-----------------
Name CAST-128 block cipher
Author Carlisle Adams and Stafford Taveres
Patented No
Block size 64bit
Key size 128bit
Modes ECB, CBC, CFB 8bit, OFB, OFB counter 8bit
Procedures
----------
function CAST-128SelfTest: Boolean;
Performs a self test
procedure CAST-128Init;
Initializes a TCAST-128Data record with key information
procedure CAST-128Burn;
Clears a TCAST-128Data record of any key information
procedure CAST-128Reset;
Resets any chaining mode information (needed for CBC, CFB, OFB, OFBC)
procedure CAST-128EncryptECB;
Encrypts the data in a 64bit block using the ECB mode
procedure CAST-128DecryptECB;
Decrypts the data in a 64bit block using the ECB mode
procedure CAST-128EncryptCBC;
Encrypts the data in a 64bit block using the CBC chaining mode
procedure CAST-128DecryptCBC;
Decrypts the data in a 64bit block using the CBC chaining mode
procedure CAST-128EncryptOFB;
Encrypts the data in a 64bit block using the OFB chaining mode
procedure CAST-128DecryptOFB;
Decrypts the data in a 64bit block using the OFB chaining mode
procedure CAST-128EncryptCFB;
Encrypts Len bytes of data using the CFB chaining mode
procedure CAST-128DecryptCFB;
Decrypts Len bytes of data using the CFB chaining mode
procedure CAST-128EncryptOFBC;
Encrypts Len bytes of data using the OFB counter chaining mode
procedure CAST-128DecryptOFBC;
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[0..8191] of byte;
i: integer;
KeyData: TCAST-128Data;
begin
CAST-128Init(KeyData,@Key,Sizeof(Key),@IV);
for i:= 1 to (8192 div 8) do
CAST-128EncryptCBC(KeyData,@Data[(i-1)*8],@Data[(i-1)*8]);
CAST-128Reset(KeyData);
for i:= 1 to (8192 div 8) do
CAST-128DecryptCBC(KeyData,@Data[(i-1)*8],@Data[(i-1)*8]);
CAST-128Reset(KeyData); // not really necessary but just to demonstrate
CAST-128Burn;
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
Copyright (c) 1998 David Barton
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -