📄 cryptlib_8h-source.html
字号:
00450 <span class="comment">//! interface for the data processing part of stream ciphers</span>00451 <span class="comment"></span><a name="l00452"></a><a class="code" href="class_stream_transformation.html">00452</a> <span class="keyword">class </span>CRYPTOPP_DLL StreamTransformation : <span class="keyword">public</span> Algorithm00453 {00454 <span class="keyword">public</span>:<span class="comment"></span>00455 <span class="comment"> //! return a reference to this object, </span>00456 <span class="comment"></span><span class="comment"> /*! This function is useful for passing a temporary StreamTransformation object to a </span>00457 <span class="comment"> function that takes a non-const reference. */</span><a name="l00458"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera0">00458</a> StreamTransformation& Ref() {<span class="keywordflow">return</span> *<span class="keyword">this</span>;}00459 <span class="comment"></span>00460 <span class="comment"> //! returns block size, if input must be processed in blocks, otherwise 1</span><a name="l00461"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera1">00461</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MandatoryBlockSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1;}00462 <span class="comment"></span>00463 <span class="comment"> //! returns the input block size that is most efficient for this cipher</span>00464 <span class="comment"></span><span class="comment"> /*! \note optimal input length is n * OptimalBlockSize() - GetOptimalBlockSizeUsed() for any n > 0 */</span><a name="l00465"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera2">00465</a> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OptimalBlockSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> MandatoryBlockSize();}<span class="comment"></span>00466 <span class="comment"> //! returns how much of the current block is used up</span><a name="l00467"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera3">00467</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> GetOptimalBlockSizeUsed()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 0;}00468 <span class="comment"></span>00469 <span class="comment"> //! returns how input should be aligned for optimal performance</span><a name="l00470"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera4">00470</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OptimalDataAlignment()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1;}00471 <span class="comment"></span>00472 <span class="comment"> //! encrypt or decrypt an array of bytes of specified length</span>00473 <span class="comment"></span><span class="comment"> /*! \note either inString == outString, or they don't overlap */</span>00474 <span class="keyword">virtual</span> <span class="keywordtype">void</span> ProcessData(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) =0;00475 <span class="comment"></span>00476 <span class="comment"> //! for ciphers where the last block of data is special, encrypt or decrypt the last block of data</span>00477 <span class="comment"></span><span class="comment"> /*! For now the only use of this function is for CBC-CTS mode. */</span>00478 <span class="keyword">virtual</span> <span class="keywordtype">void</span> ProcessLastBlock(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length);<span class="comment"></span>00479 <span class="comment"> //! returns the minimum size of the last block, 0 indicating the last block is not special</span><a name="l00480"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera7">00480</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MinLastBlockSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 0;}00481 <span class="comment"></span>00482 <span class="comment"> //! same as ProcessData(inoutString, inoutString, length)</span><a name="l00483"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera8">00483</a> <span class="comment"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> ProcessString(byte *inoutString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00484 {ProcessData(inoutString, inoutString, length);}<span class="comment"></span>00485 <span class="comment"> //! same as ProcessData(outString, inString, length)</span><a name="l00486"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera9">00486</a> <span class="comment"></span> <span class="keyword">inline</span> <span class="keywordtype">void</span> ProcessString(byte *outString, <span class="keyword">const</span> byte *inString, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00487 {ProcessData(outString, inString, length);}<span class="comment"></span>00488 <span class="comment"> //! implemented as {ProcessData(&input, &input, 1); return input;}</span><a name="l00489"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera10">00489</a> <span class="comment"></span> <span class="keyword">inline</span> byte ProcessByte(byte input)00490 {ProcessData(&input, &input, 1); <span class="keywordflow">return</span> input;}00491 <span class="comment"></span>00492 <span class="comment"> //! returns whether this cipher supports random access</span>00493 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsRandomAccess() <span class="keyword">const</span> =0;<span class="comment"></span>00494 <span class="comment"> //! for random access ciphers, seek to an absolute position</span><a name="l00495"></a><a class="code" href="class_stream_transformation.html#_symmetric_ciphera12">00495</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> Seek(dword n)00496 {00497 assert(!IsRandomAccess());00498 <span class="keywordflow">throw</span> NotImplemented(<span class="stringliteral">"StreamTransformation: this object doesn't support random access"</span>);00499 }00500 <span class="comment"></span>00501 <span class="comment"> //! returns whether this transformation is self-inverting (e.g. xor with a keystream)</span>00502 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsSelfInverting() <span class="keyword">const</span> =0;<span class="comment"></span>00503 <span class="comment"> //! returns whether this is an encryption object</span>00504 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> IsForwardTransformation() <span class="keyword">const</span> =0;00505 };00506 <span class="comment"></span>00507 <span class="comment">//! interface for hash functions and data processing part of MACs</span>00508 <span class="comment"></span><span class="comment"></span>00509 <span class="comment">/*! HashTransformation objects are stateful. They are created in an initial state,</span>00510 <span class="comment"> change state as Update() is called, and return to the initial</span>00511 <span class="comment"> state when Final() is called. This interface allows a large message to</span>00512 <span class="comment"> be hashed in pieces by calling Update() on each piece followed by</span>00513 <span class="comment"> calling Final().</span>00514 <span class="comment">*/</span><a name="l00515"></a><a class="code" href="class_hash_transformation.html">00515</a> <span class="keyword">class </span>CRYPTOPP_DLL HashTransformation : <span class="keyword">public</span> Algorithm00516 {00517 <span class="keyword">public</span>:<span class="comment"></span>00518 <span class="comment"> //! process more input</span>00519 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> Update(<span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length) =0;00520 <span class="comment"></span>00521 <span class="comment"> //! request space to write input into</span><a name="l00522"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_ca6">00522</a> <span class="comment"></span> <span class="keyword">virtual</span> byte * CreateUpdateSpace(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> &size) {size=0; <span class="keywordflow">return</span> NULL;}00523 <span class="comment"></span>00524 <span class="comment"> //! compute hash for current message, then restart for a new message</span>00525 <span class="comment"></span><span class="comment"> /*! \pre size of digest == DigestSize(). */</span><a name="l00526"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea13">00526</a> <span class="keyword">virtual</span> <span class="keywordtype">void</span> Final(byte *digest)00527 {TruncatedFinal(digest, DigestSize());}00528 <span class="comment"></span>00529 <span class="comment"> //! discard the current state, and restart with a new message</span><a name="l00530"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_ca8">00530</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> Restart()00531 {TruncatedFinal(NULL, 0);}00532 <span class="comment"></span>00533 <span class="comment"> //! size of the hash returned by Final()</span>00534 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> DigestSize() <span class="keyword">const</span> =0;00535 <span class="comment"></span>00536 <span class="comment"> //! block size of underlying compression function, or 0 if not block based</span><a name="l00537"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_ca10">00537</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="namespace_name.html#a9">BlockSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 0;}00538 <span class="comment"></span>00539 <span class="comment"> //! input to Update() should have length a multiple of this for optimal speed</span><a name="l00540"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_ca11">00540</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OptimalBlockSize()<span class="keyword"> const </span>{<span class="keywordflow">return</span> 1;}00541 <span class="comment"></span>00542 <span class="comment"> //! use this if your input is in one piece and you don't want to call Update() and Final() separately</span><a name="l00543"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea14">00543</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> CalculateDigest(byte *digest, <span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00544 {Update(input, length); Final(digest);}00545 <span class="comment"></span>00546 <span class="comment"> //! verify that digest is a valid digest for the current message, then reinitialize the object</span>00547 <span class="comment"></span><span class="comment"> /*! Default implementation is to call Final() and do a bitwise comparison</span>00548 <span class="comment"> between its output and digest. */</span><a name="l00549"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea15">00549</a> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> Verify(<span class="keyword">const</span> byte *digest)00550 {<span class="keywordflow">return</span> TruncatedVerify(digest, DigestSize());}00551 <span class="comment"></span>00552 <span class="comment"> //! use this if your input is in one piece and you don't want to call Update() and Verify() separately</span><a name="l00553"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea16">00553</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> VerifyDigest(<span class="keyword">const</span> byte *digest, <span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00554 {Update(input, length); <span class="keywordflow">return</span> Verify(digest);}00555 <span class="comment"></span>00556 <span class="comment"> //! truncated version of Final()</span>00557 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> TruncatedFinal(byte *digest, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digestSize) =0;00558 <span class="comment"></span>00559 <span class="comment"> //! truncated version of CalculateDigest()</span><a name="l00560"></a><a class="code" href="class_hash_transformation.html#_x_m_a_c_c___basea17">00560</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> CalculateTruncatedDigest(byte *digest, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> digestSize, <span class="keyword">const</span> byte *input, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> length)00561 {Update(input, length); Tru
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -