|
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.fasteasytrade.JRandTest.Algo.Cipher com.fasteasytrade.JRandTest.Algo.ZAC3
ZAC3 encryption algorithm Copyright (c) 2005 Zur Aougav
Symetric algorithm.
Use 3 ARC4 keys:
Hence, ciphered text length is double input's length.
Before encryption starts, each key is skipped a random number of times (with 4096 <= skip <= 69631). SHA1 digest message (20 bytes) is calculated from the invisible key output. The 20 bytes should be written at the header of the ciphered message/file. Of course, decryption does the reverse, read the hash 20 bytes, and step each key with a check if digest message arrived at is the correct one. Hence, the random number of steps is never exposed directly, but the hash contains implicitly the correct position.
Field Summary | |
(package private) byte[] |
controlBuf
Original key bytes buffer for controlKey |
(package private) RC4Key |
controlKey
controlKey gives one byte to enable swap of encrypt data and fill data (from fillKey) |
(package private) byte[] |
controlShaDigest
controlKey is processed controlSkip times, and prng data is hashed using sha1. |
(package private) int |
controlSkip
random number we skip controlKey before start using it. |
(package private) byte[] |
cryptBuf
Original key bytes buffer for cryptKey |
(package private) RC4Key |
cryptKey
encrypt and decrypt data using cryptKey |
(package private) byte[] |
cryptShaDigest
cryptKey is processed cryptSkip times, and prng data is hashed using sha1. |
(package private) int |
cryptSkip
random number we skip cryptKey before start using it. |
(package private) byte[] |
fillBuf
Original key bytes buffer for fillKey |
(package private) RC4Key |
fillKey
add one byte for each encrypt data byte |
(package private) byte[] |
fillShaDigest
fillKey is processed fillSkip times, and prng data is hashed using sha1. |
(package private) int |
fillSkip
random number we skip fillKey before start using it. |
(package private) boolean |
garbage
Boolean flag if we ever find an incorrect fill byte in data. |
(package private) Random |
rnd
Use java random class to fill new keys put some garbage bytes in output buffer (if decryption fails). |
Constructor Summary | |
ZAC3()
default constructor - does nothing. |
|
ZAC3(byte[] cryptBuf,
byte[] fillBuf,
byte[] controlBuf)
constructor with 3 keys to setup. |
Method Summary | |
boolean |
decrypt(byte[] inputBuf,
byte[] outputBuf,
int len)
decrypt buffer. |
boolean |
encrypt(byte[] inputBuf,
byte[] outputBuf)
encrypt buffer. each input byte becomes two bytes, by adding one byte from fillKey. |
protected void |
finalize()
carefull clear of buffers in ZAC3 object |
byte[] |
getControlBuf()
|
byte[] |
getControlShaDigest()
|
byte[] |
getCryptBuf()
|
byte[] |
getCryptShaDigest()
|
byte[] |
getFillBuf()
|
byte[] |
getFillShaDigest()
|
boolean |
initDecrypt(byte[] cryptShaDigest,
byte[] fillShaDigest,
byte[] controlShaDigest)
init keys, using hash on prng of each key. |
void |
initEncrypt()
init keys, using hash on prng of each key. |
static void |
main(String[] args)
Run ZAC3 Algorithm. |
void |
reset()
Reset "state" of prng by setting keys to bufkeys and skip each key. |
void |
setup(byte[] cryptBuf,
byte[] fillBuf,
byte[] controlBuf)
setup 3 keys to ZAC3 algorithm. |
Methods inherited from class com.fasteasytrade.JRandTest.Algo.Cipher |
compareBytes |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
RC4Key cryptKey
RC4Key fillKey
RC4Key controlKey
byte[] cryptShaDigest
byte[] fillShaDigest
byte[] controlShaDigest
byte[] cryptBuf
byte[] fillBuf
byte[] controlBuf
int cryptSkip
int fillSkip
int controlSkip
boolean garbage
Only used while decryption.
If true, we fill (silently) all output data with random data from rnd variable.
Random rnd
Constructor Detail |
public ZAC3()
public ZAC3(byte[] cryptBuf, byte[] fillBuf, byte[] controlBuf)
cryptBuf
- kept in obejct cryptBuf and init cryptKeyfillBuf
- kept in obejct fillBuf and init fillKeycontrolBuf
- kept in obejct controlBuf and init controlKeyMethod Detail |
public void setup(byte[] cryptBuf, byte[] fillBuf, byte[] controlBuf)
keep keys and skip data in object so initEncrypt() and reset() can run properly.
cryptBuf
- 256 bytes to cryptKeyfillBuf
- 256 bytes to fillKeycontrolBuf
- 256 bytes to controlKeypublic void initEncrypt()
initEncrypt method is run before encryption starts.
public boolean encrypt(byte[] inputBuf, byte[] outputBuf)
if control_byte is even
then output order is concat(encrypted_data_byte, fill_byte),
else output order is concat(fill_byte, encrypted_data_byte)
caller gets back a clear input buffer (full of 0x00).
inputBuf
- input bytes buffer, length noutputBuf
- output encrypted bytes buffer, must be length 2n
public boolean initDecrypt(byte[] cryptShaDigest, byte[] fillShaDigest, byte[] controlShaDigest)
initDecrypt method is run before decryption starts.
public boolean decrypt(byte[] inputBuf, byte[] outputBuf, int len)
if control_byte is even
then input order is concat(encrypted_data_byte, fill_byte),
else input order is concat(fill_byte, encrypted_data_byte)
If filler byte is not in a correct place, we flag garbage
boolean value, and hence forth, fill *any* output buffer with random data
without decryption. Note taht no alert is given.
inputBuf
- input ciphered bytes buffer, length 2noutputBuf
- output data bytes buffer, must be length nlen
- intput buffer length
public void reset()
public byte[] getControlShaDigest()
public byte[] getCryptShaDigest()
public byte[] getFillShaDigest()
public byte[] getControlBuf()
public byte[] getCryptBuf()
public byte[] getFillBuf()
protected void finalize() throws Throwable
Throwable
public static void main(String[] args) throws Exception
Command line syntax:
java ZAC3 [options] [ops] [inputfilename outputfilename]
options:
-crf <cryptKeyFile.key>
default: cryptKeyFile.key
-fif <fillKeyFile.key>
default: fillKeyFile.key
-cof <controlKeyFile.key> default:
controlKeyFile.key
ops:
-h print this help message
-e encrypt inputfilename into
outputfilename
-enc encrypt inputfilename into outputfilename
-d decrypt inputfilename into
outputfilename
-dec decrypt inputfilename into outputfilename
-compare compare two files - inputfilename and
outputfilename
-gen generate random keys and write them to key
files
args
- keys, operations, input and output filenames
Exception
- missing operands or IOExceptions
|
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |