⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sapphire_8h-source.html

📁 Crypto++是一个非常强大的密码学库,主要是功能全
💻 HTML
字号:
<!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>Crypto++: sapphire.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Compound&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Compound&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div><h1>sapphire.h</h1><div class="fragment"><pre>00001 <span class="preprocessor">#ifndef CRYPTOPP_SAPPHIRE_H</span>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_SAPPHIRE_H</span>00003 <span class="preprocessor"></span>00004 <span class="preprocessor">#include "seckey.h"</span>00005 <span class="preprocessor">#include "secblock.h"</span>00006 00007 NAMESPACE_BEGIN(CryptoPP)00008 00009 <span class="comment">/// base class, do not use directly</span><a name="l00010"></a><a class="code" href="class_sapphire_base.html">00010</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_sapphire_base.html">SapphireBase</a> : <span class="keyword">public</span> <a class="code" href="class_variable_key_length.html">VariableKeyLength</a>&lt;16, 1, 255&gt;00011 {00012 <span class="keyword">protected</span>:00013         <a class="code" href="class_sapphire_base.html">SapphireBase</a>();00014         <a class="code" href="class_sapphire_base.html">SapphireBase</a>(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keyLength);00015         ~<a class="code" href="class_sapphire_base.html">SapphireBase</a>();00016 00017         <span class="keyword">inline</span> <span class="keywordtype">void</span> ShuffleCards()00018         {00019                 ratchet += cards[rotor++];00020                 byte swaptemp = cards[last_cipher];00021                 cards[last_cipher] = cards[ratchet];00022                 cards[ratchet] = cards[last_plain];00023                 cards[last_plain] = cards[rotor];00024                 cards[rotor] = swaptemp;00025                 avalanche += cards[swaptemp];00026         }00027 00028         <span class="comment">// These variables comprise the state of the state machine.</span>00029 00030         <a class="code" href="class_sec_block.html">SecByteBlock</a> cards;             <span class="comment">// A permutation of 0-255.</span>00031         byte 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="keyword">private</span>:00038         byte keyrand(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> limit, <span class="keyword">const</span> byte *user_key, byte keysize, byte *rsum, <span class="keywordtype">unsigned</span> *keypos);00039 };00040 <span class="comment"></span>00041 <span class="comment">/// &lt;a href="http://www.weidai.com/scan-mirror/cs.html#Sapphire-II"&gt;Sapphire-II Cipher&lt;/a&gt;</span><a name="l00042"></a><a class="code" href="class_sapphire_encryption.html">00042</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a> : <span class="keyword">public</span> <a class="code" href="class_stream_transformation.html">StreamTransformation</a>, <span class="keyword">public</span> <a class="code" href="class_sapphire_base.html">SapphireBase</a>00043 {00044 <span class="keyword">public</span>:00045         <a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a>(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keyLength=DEFAULT_KEYLENGTH)00046                 : <a class="code" href="class_sapphire_base.html">SapphireBase</a>(userKey, keyLength) {}00047 <a name="l00048"></a><a class="code" href="class_sapphire_encryption.html#_sapphire_r_n_gd0">00048</a>         <span class="keyword">inline</span> byte <a class="code" href="class_sapphire_encryption.html#_sapphire_r_n_gd0">ProcessByte</a>(byte b)00049         {00050                 ShuffleCards();00051                 last_cipher = b^cards[(cards[ratchet] + cards[rotor]) &amp; 0xFF] ^00052                                           cards[cards[(cards[last_plain] +00053                                                                    cards[last_cipher] +00054                                                                    cards[avalanche])&amp;0xFF]];00055                 last_plain = b;00056                 <span class="keywordflow">return</span> last_cipher;00057         }00058 00059         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_encryption.html#_sapphire_r_n_gd1">ProcessString</a>(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00060         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_encryption.html#_sapphire_r_n_gd1">ProcessString</a>(byte *inoutString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00061 00062 <span class="keyword">protected</span>:00063         <a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a>() {}     <span class="comment">// for SapphireHash</span>00064 };00065 <span class="comment"></span>00066 <span class="comment">/// &lt;a href="http://www.weidai.com/scan-mirror/cs.html#Sapphire-II"&gt;Sapphire-II cipher&lt;/a&gt;</span><a name="l00067"></a><a class="code" href="class_sapphire_decryption.html">00067</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_sapphire_decryption.html">SapphireDecryption</a> : <span class="keyword">public</span> <a class="code" href="class_stream_transformation.html">StreamTransformation</a>, <span class="keyword">public</span> <a class="code" href="class_sapphire_base.html">SapphireBase</a>00068 {00069 <span class="keyword">public</span>:00070         <a class="code" href="class_sapphire_decryption.html">SapphireDecryption</a>(<span class="keyword">const</span> byte *userKey, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keyLength=DEFAULT_KEYLENGTH)00071                 : <a class="code" href="class_sapphire_base.html">SapphireBase</a>(userKey, keyLength) {}00072 <a name="l00073"></a><a class="code" href="class_sapphire_decryption.html#_sapphire_decryptiona1">00073</a>         <span class="keyword">inline</span> byte <a class="code" href="class_sapphire_decryption.html#_sapphire_decryptiona1">ProcessByte</a>(byte b)00074         {00075                 ShuffleCards();00076                 last_plain = b^cards[(cards[ratchet] + cards[rotor]) &amp; 0xFF] ^00077                                            cards[cards[(cards[last_plain] +00078                                                                         cards[last_cipher] +00079                                                                         cards[avalanche])&amp;0xFF]];00080                 last_cipher = b;00081                 <span class="keywordflow">return</span> last_plain;00082         }00083 00084         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_decryption.html#_sapphire_decryptiona2">ProcessString</a>(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00085         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_decryption.html#_sapphire_decryptiona2">ProcessString</a>(byte *inoutString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00086 };00087 <span class="comment"></span>00088 <span class="comment">/// Sapphire Random Number Generator</span><a name="l00089"></a><a class="code" href="class_sapphire_r_n_g.html">00089</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_sapphire_r_n_g.html">SapphireRNG</a> : <span class="keyword">public</span> <a class="code" href="class_random_number_generator.html">RandomNumberGenerator</a>, <span class="keyword">private</span> <a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a>00090 {00091 <span class="keyword">public</span>:00092         <a class="code" href="class_sapphire_r_n_g.html">SapphireRNG</a>(<span class="keyword">const</span> byte *seed, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> seedLength)00093                 : <a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a>(seed, seedLength) {}00094 00095         <span class="keyword">inline</span> byte GetByte() {<span class="keywordflow">return</span> <a class="code" href="class_sapphire_encryption.html#_sapphire_r_n_gd0">SapphireEncryption::ProcessByte</a>(0);}00096 };00097 <span class="comment"></span>00098 <span class="comment">//! Sapphire Hash</span>00099 <span class="comment"></span><span class="comment">/*! Digest Length = 160 bits */</span><a name="l00100"></a><a class="code" href="class_sapphire_hash.html">00100</a> <span class="keyword">class </span><a class="code" href="class_sapphire_hash.html">SapphireHash</a> : <span class="keyword">public</span> <a class="code" href="class_hash_transformation.html">HashTransformation</a>, <span class="keyword">private</span> <a class="code" href="class_sapphire_encryption.html">SapphireEncryption</a>00101 {00102 <span class="keyword">public</span>:00103         <a class="code" href="class_sapphire_hash.html">SapphireHash</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hashLength=20);00104         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_hash.html#_sapphire_hasha1">Update</a>(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);00105         <span class="keywordtype">void</span> <a class="code" href="class_sapphire_hash.html#_sapphire_hasha2">TruncatedFinal</a>(byte *hash, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> size);<a name="l00106"></a><a class="code" href="class_sapphire_hash.html#_sapphire_hasha3">00106</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="class_sapphire_hash.html#_sapphire_hasha3">DigestSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> hashLength;}00107 00108 <span class="keyword">private</span>:00109         <span class="keywordtype">void</span> Init();00110         <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> hashLength;00111 };00112 00113 NAMESPACE_END00114 00115 <span class="preprocessor">#endif</span></pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Jul 8 23:34:24 2003 for Crypto++ by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 > </a>1.3.2 </small></address></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -