1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>sapphire.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.17 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>sapphire.h</h1><div class="fragment"><pre>00001 <span class="comment">/* sapphire.h -- Interface for the Saphire II stream cipher.</span>
00002 <span class="comment"></span>
00003 <span class="comment"> Dedicated to the Public Domain the author and inventor</span>
00004 <span class="comment"> (Michael Paul Johnson). This code comes with no warranty.</span>
00005 <span class="comment"> Use it at your own risk.</span>
00006 <span class="comment"> Ported from the Pascal implementation of the Sapphire Stream</span>
00007 <span class="comment"> Cipher 9 December 1994.</span>
00008 <span class="comment"> Added hash-specific functions 27 December 1994.</span>
00009 <span class="comment"> Made index variable initialization key-dependent,</span>
00010 <span class="comment"> made the output function more resistant to cryptanalysis,</span>
00011 <span class="comment"> and renamed to Sapphire II Stream Cipher 2 January 1995.</span>
00012 <span class="comment"></span>
00013 <span class="comment"> unsigned char is assumed to be 8 bits. If it is not, the</span>
00014 <span class="comment"> results of assignments need to be reduced to 8 bits with</span>
00015 <span class="comment"> & 0xFF or % 0x100, whichever is faster.</span>
00016 <span class="comment">*/</span>
00017
00018 <span class="preprocessor">#ifndef NULL</span>
00019 <span class="preprocessor"></span><span class="preprocessor">#define NULL 0</span>
00020 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* */</span>
00021
00022 <span class="preprocessor">#include <defs.h></span>
00023
00024 SWORD_NAMESPACE_START
00025
00026 <span class="keyword">class </span>sapphire
00027 {
00028
00029 <span class="comment">// These variables comprise the state of the state machine.</span>
00030 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> cards[256]; <span class="comment">// A permutation of 0-255.</span>
00031 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> rotor, <span class="comment">// Index that rotates smoothly</span>
00032 ratchet, <span class="comment">// Index that moves erratically</span>
00033 avalanche, <span class="comment">// Index heavily data dependent</span>
00034 last_plain, <span class="comment">// Last plain text byte</span>
00035 last_cipher; <span class="comment">// Last cipher text byte</span>
00036
00037 <span class="comment">// This function is used by initialize(), which is called by the</span>
00038 <span class="comment">// constructor.</span>
00039 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> keyrand (<span class="keywordtype">int</span> limit, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *user_key,
00040 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> keysize, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *rsum,
00041 <span class="keywordtype">unsigned</span> *keypos); <span class="keyword">public</span>:sapphire (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>
00042 *key = NULL, <span class="comment">// Calls initialize if a real</span>
00043 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> keysize = 0); <span class="comment">// key is provided. If none</span>
00044 <span class="comment">// is provided, call initialize</span>
00045 <span class="comment">// before encrypt or decrypt.</span>
00046 ~sapphire (); <span class="comment">// Destroy cipher state information.</span>
00047 <span class="keywordtype">void</span> initialize (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *key, <span class="comment">// User key is used to set</span>
00048 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> keysize); <span class="comment">// up state information.</span>
00049 <span class="keywordtype">void</span> hash_init (<span class="keywordtype">void</span>); <span class="comment">// Set up default hash.</span>
00050 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> encrypt (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b = 0); <span class="comment">// Encrypt byte</span>
00051 <span class="comment">// or get a random byte.</span>
00052 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> decrypt (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b); <span class="comment">// Decrypt byte.</span>
00053 <span class="keywordtype">void</span> hash_final (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *hash, <span class="comment">// Copy hash value to hash</span>
00054 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> hashlength = 20); <span class="comment">// Hash length (16-32)</span>
00055 <span class="keywordtype">void</span> burn (<span class="keywordtype">void</span>); <span class="comment">// Destroy cipher state information.</span>
00056 };
00057
00058
00059 SWORD_NAMESPACE_END
</pre></div><hr><address style="align: right;"><small>Generated on Thu Oct 31 12:11:28 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.17 </small></address>
</body>
</html>
|