~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to include/sapphire.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* sapphire.h -- Interface for the Saphire II stream cipher.
 
2
 
 
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.
 
12
 
 
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.
 
16
*/  
 
17
  
 
18
#ifndef NULL
 
19
#define NULL 0
 
20
#endif  /*  */
 
21
 
 
22
#include <defs.h>
 
23
 
 
24
SWORD_NAMESPACE_START
 
25
 
 
26
  class sapphire 
 
27
{
 
28
  
 
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
 
36
  
 
37
    // This function is used by initialize(), which is called by the
 
38
    // constructor.
 
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.
 
56
};
 
57
 
 
58
 
 
59
SWORD_NAMESPACE_END