📄 strciphr_8h-source.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>Crypto++: strciphr.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="classes.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul></div><div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul></div><h1>strciphr.h</h1><a href="strciphr_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*! \file</span><a name="l00002"></a>00002 <span class="comment"> This file contains helper classes for implementing stream ciphers.</span><a name="l00003"></a>00003 <span class="comment"></span><a name="l00004"></a>00004 <span class="comment"> All this infrastructure may look very complex compared to what's in Crypto++ 4.x,</span><a name="l00005"></a>00005 <span class="comment"> but stream ciphers implementations now support a lot of new functionality,</span><a name="l00006"></a>00006 <span class="comment"> including better performance (minimizing copying), resetting of keys and IVs, and methods to</span><a name="l00007"></a>00007 <span class="comment"> query which features are supported by a cipher.</span><a name="l00008"></a>00008 <span class="comment"></span><a name="l00009"></a>00009 <span class="comment"> Here's an explanation of these classes. The word "policy" is used here to mean a class with a</span><a name="l00010"></a>00010 <span class="comment"> set of methods that must be implemented by individual stream cipher implementations.</span><a name="l00011"></a>00011 <span class="comment"> This is usually much simpler than the full stream cipher API, which is implemented by</span><a name="l00012"></a>00012 <span class="comment"> either AdditiveCipherTemplate or CFB_CipherTemplate using the policy. So for example, an</span><a name="l00013"></a>00013 <span class="comment"> implementation of SEAL only needs to implement the AdditiveCipherAbstractPolicy interface</span><a name="l00014"></a>00014 <span class="comment"> (since it's an additive cipher, i.e., it xors a keystream into the plaintext).</span><a name="l00015"></a>00015 <span class="comment"> See this line in seal.h:</span><a name="l00016"></a>00016 <span class="comment"></span><a name="l00017"></a>00017 <span class="comment"> typedef SymmetricCipherFinal<ConcretePolicyHolder<SEAL_Policy<B>, AdditiveCipherTemplate<> > > Encryption;</span><a name="l00018"></a>00018 <span class="comment"></span><a name="l00019"></a>00019 <span class="comment"> AdditiveCipherTemplate and CFB_CipherTemplate are designed so that they don't need</span><a name="l00020"></a>00020 <span class="comment"> to take a policy class as a template parameter (although this is allowed), so that</span><a name="l00021"></a>00021 <span class="comment"> their code is not duplicated for each new cipher. Instead they each</span><a name="l00022"></a>00022 <span class="comment"> get a reference to an abstract policy interface by calling AccessPolicy() on itself, so</span><a name="l00023"></a>00023 <span class="comment"> AccessPolicy() must be overriden to return the actual policy reference. This is done</span><a name="l00024"></a>00024 <span class="comment"> by the ConceretePolicyHolder class. Finally, SymmetricCipherFinal implements the constructors and</span><a name="l00025"></a>00025 <span class="comment"> other functions that must be implemented by the most derived class.</span><a name="l00026"></a>00026 <span class="comment">*/</span><a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef CRYPTOPP_STRCIPHR_H</span><a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_STRCIPHR_H</span><a name="l00030"></a>00030 <span class="preprocessor"></span><a name="l00031"></a>00031 <span class="preprocessor">#include "seckey.h"</span><a name="l00032"></a>00032 <span class="preprocessor">#include "secblock.h"</span><a name="l00033"></a>00033 <span class="preprocessor">#include "argnames.h"</span><a name="l00034"></a>00034 <a name="l00035"></a>00035 NAMESPACE_BEGIN(CryptoPP)<a name="l00036"></a>00036 <a name="l00037"></a>00037 template <class POLICY_INTERFACE, class BASE = <a class="code" href="class_empty.html">Empty</a>><a name="l00038"></a><a class="code" href="class_abstract_policy_holder.html">00038</a> class CRYPTOPP_NO_VTABLE <a class="code" href="class_abstract_policy_holder.html">AbstractPolicyHolder</a> : public BASE<a name="l00039"></a>00039 {<a name="l00040"></a>00040 <span class="keyword">public</span>:<a name="l00041"></a><a class="code" href="class_abstract_policy_holder.html#febbd551c30ef32e3bbcbdf5bfecd303">00041</a> <span class="keyword">typedef</span> POLICY_INTERFACE PolicyInterface;<a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="keyword">protected</span>:<a name="l00044"></a>00044 <span class="keyword">virtual</span> <span class="keyword">const</span> POLICY_INTERFACE & GetPolicy() <span class="keyword">const</span> =0;<a name="l00045"></a>00045 <span class="keyword">virtual</span> POLICY_INTERFACE & AccessPolicy() =0;<a name="l00046"></a>00046 };<a name="l00047"></a>00047 <a name="l00048"></a>00048 <span class="keyword">template</span> <<span class="keyword">class</span> POLICY, <span class="keyword">class</span> BASE, <span class="keyword">class</span> POLICY_INTERFACE = CPP_TYPENAME BASE::PolicyInterface><a name="l00049"></a><a class="code" href="class_concrete_policy_holder.html">00049</a> <span class="keyword">class </span><a class="code" href="class_concrete_policy_holder.html">ConcretePolicyHolder</a> : <span class="keyword">public</span> BASE, <span class="keyword">protected</span> POLICY<a name="l00050"></a>00050 {<a name="l00051"></a>00051 <span class="keyword">protected</span>:<a name="l00052"></a><a class="code" href="class_concrete_policy_holder.html#05f67da8cb933d8696c0fa41dd8abf40">00052</a> <span class="keyword">const</span> POLICY_INTERFACE & <a class="code" href="class_concrete_policy_holder.html#05f67da8cb933d8696c0fa41dd8abf40">GetPolicy</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> *<span class="keyword">this</span>;}<a name="l00053"></a><a class="code" href="class_concrete_policy_holder.html#1d90cb30eace971937cf02c0abafe6ea">00053</a> POLICY_INTERFACE & <a class="code" href="class_concrete_policy_holder.html#1d90cb30eace971937cf02c0abafe6ea">AccessPolicy</a>() {<span class="keywordflow">return</span> *<span class="keyword">this</span>;}<a name="l00054"></a>00054 };<a name="l00055"></a>00055 <a name="l00056"></a><a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93fc940e3e878ef290eed45beb9875a04ea">00056</a> <span class="keyword">enum</span> <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f">KeystreamOperationFlags</a> {<a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93fc940e3e878ef290eed45beb9875a04ea">OUTPUT_ALIGNED</a>=1, <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f930b8199ed034e6d749cb403e1678cb1">INPUT_ALIGNED</a>=2, <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f0fc3580c2832e59fe9e21673160e6042">INPUT_NULL</a> = 4};<a name="l00057"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227">00057</a> <span class="keyword">enum</span> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227">KeystreamOperation</a> {<a name="l00058"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742276ab40a8f816d015407f61839c60b9a4e">00058</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742276ab40a8f816d015407f61839c60b9a4e">WRITE_KEYSTREAM</a> = <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f0fc3580c2832e59fe9e21673160e6042">INPUT_NULL</a>, <a name="l00059"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227cdc514c6fefe9937a84c0394bf4d7dbb">00059</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227cdc514c6fefe9937a84c0394bf4d7dbb">WRITE_KEYSTREAM_ALIGNED</a> = <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f0fc3580c2832e59fe9e21673160e6042">INPUT_NULL</a> | <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93fc940e3e878ef290eed45beb9875a04ea">OUTPUT_ALIGNED</a>, <a name="l00060"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742273862fdc8a3c07e925d4a37ea9ee307d3">00060</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742273862fdc8a3c07e925d4a37ea9ee307d3">XOR_KEYSTREAM</a> = 0, <a name="l00061"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227ad43a73f1f4e27c051c0eb38ab63fb8f">00061</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227ad43a73f1f4e27c051c0eb38ab63fb8f">XOR_KEYSTREAM_INPUT_ALIGNED</a> = <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f930b8199ed034e6d749cb403e1678cb1">INPUT_ALIGNED</a>, <a name="l00062"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227c98e33dfc8a7eb9fb546d2d6dc1dce8d">00062</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d0974227c98e33dfc8a7eb9fb546d2d6dc1dce8d">XOR_KEYSTREAM_OUTPUT_ALIGNED</a>= <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93fc940e3e878ef290eed45beb9875a04ea">OUTPUT_ALIGNED</a>, <a name="l00063"></a><a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742278619a63402bbed5800381dc04dcbc4e8">00063</a> <a class="code" href="strciphr_8h.html#b4a226527d2bd01ff19bfa14d09742278619a63402bbed5800381dc04dcbc4e8">XOR_KEYSTREAM_BOTH_ALIGNED</a> = <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93fc940e3e878ef290eed45beb9875a04ea">OUTPUT_ALIGNED</a> | <a class="code" href="strciphr_8h.html#cd7ca957d2fd1c24ecc2a4db7145d93f930b8199ed034e6d749cb403e1678cb1">INPUT_ALIGNED</a>};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -