1
/* sapphire.h -- Interface for the Saphire II stream cipher.
3
Dedicated to the Public Domain the author and inventor
4
(Michael Paul Johnson). This code comes with no warranty.
5
Use it at your own risk.
6
Ported from the Pascal implementation of the Sapphire Stream
7
Cipher 9 December 1994.
8
Added hash-specific functions 27 December 1994.
9
Made index variable initialization key-dependent,
10
made the output function more resistant to cryptanalysis,
11
and renamed to Sapphire II Stream Cipher 2 January 1995.
13
unsigned char is assumed to be 8 bits. If it is not, the
14
results of assignments need to be reduced to 8 bits with
15
& 0xFF or % 0x100, whichever is faster.
29
// These variables comprise the state of the state machine.
30
unsigned char cards[256]; // A permutation of 0-255.
31
unsigned char rotor, // Index that rotates smoothly
32
ratchet, // Index that moves erratically
33
avalanche, // Index heavily data dependent
34
last_plain, // Last plain text byte
35
last_cipher; // Last cipher text byte
37
// This function is used by initialize(), which is called by the
39
unsigned char keyrand (int limit, unsigned char *user_key,
40
unsigned char keysize, unsigned char *rsum,
41
unsigned *keypos); public:sapphire (unsigned char
42
*key = NULL, // Calls initialize if a real
43
unsigned char keysize = 0); // key is provided. If none
44
// is provided, call initialize
45
// before encrypt or decrypt.
46
~sapphire (); // Destroy cipher state information.
47
void initialize (unsigned char *key, // User key is used to set
48
unsigned char keysize); // up state information.
49
void hash_init (void); // Set up default hash.
50
unsigned char encrypt (unsigned char b = 0); // Encrypt byte
51
// or get a random byte.
52
unsigned char decrypt (unsigned char b); // Decrypt byte.
53
void hash_final (unsigned char *hash, // Copy hash value to hash
54
unsigned char hashlength = 20); // Hash length (16-32)
55
void burn (void); // Destroy cipher state information.