<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>Crypto++: rabin.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.4 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">Crypto++</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">rabin.h</div> </div> </div> <div class="contents"> <a href="rabin_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#ifndef CRYPTOPP_RABIN_H</span> <a name="l00002"></a>00002 <span class="preprocessor"></span><span class="preprocessor">#define CRYPTOPP_RABIN_H</span> <a name="l00003"></a>00003 <span class="preprocessor"></span><span class="comment"></span> <a name="l00004"></a>00004 <span class="comment">/** \file</span> <a name="l00005"></a>00005 <span class="comment">*/</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="preprocessor">#include "oaep.h"</span> <a name="l00008"></a>00008 <span class="preprocessor">#include "pssr.h"</span> <a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="integer_8h.html">integer.h</a>"</span> <a name="l00010"></a>00010 <a name="l00011"></a>00011 NAMESPACE_BEGIN(CryptoPP) <a name="l00012"></a>00012 <a name="l00013"></a>00013 <span class="comment">//! _</span> <a name="l00014"></a><a class="code" href="class_rabin_function.html">00014</a> <span class="comment"></span>class <a class="code" href="class_rabin_function.html" title="_">RabinFunction</a> : public <a class="code" href="class_trapdoor_function.html" title="_">TrapdoorFunction</a>, public <a class="code" href="class_public_key.html" title="interface for public keys">PublicKey</a> <a name="l00015"></a>00015 { <a name="l00016"></a>00016 <span class="keyword">typedef</span> <a class="code" href="class_rabin_function.html" title="_">RabinFunction</a> <a class="code" href="class_rabin_function.html" title="_">ThisClass</a>; <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="keyword">public</span>: <a name="l00019"></a>00019 <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &n, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &r, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &s) <a name="l00020"></a>00020 {m_n = n; m_r = r; m_s = s;} <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="keywordtype">void</span> BERDecode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt); <a name="l00023"></a>00023 <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt) <span class="keyword">const</span>; <a name="l00024"></a>00024 <a name="l00025"></a>00025 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> ApplyFunction(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x) <span class="keyword">const</span>; <a name="l00026"></a>00026 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> PreimageBound()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_n;} <a name="l00027"></a>00027 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> ImageBound()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_n;} <a name="l00028"></a>00028 <a name="l00029"></a>00029 <span class="keywordtype">bool</span> Validate(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level) <span class="keyword">const</span>; <a name="l00030"></a>00030 <span class="keywordtype">bool</span> GetVoidValue(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> std::type_info &valueType, <span class="keywordtype">void</span> *pValue) <span class="keyword">const</span>; <a name="l00031"></a>00031 <span class="keywordtype">void</span> AssignFrom(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &source); <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetModulus()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_n;} <a name="l00034"></a>00034 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetQuadraticResidueModPrime1()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_r;} <a name="l00035"></a>00035 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetQuadraticResidueModPrime2()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_s;} <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="keywordtype">void</span> SetModulus(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &n) {m_n = n;} <a name="l00038"></a>00038 <span class="keywordtype">void</span> SetQuadraticResidueModPrime1(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &r) {m_r = r;} <a name="l00039"></a>00039 <span class="keywordtype">void</span> SetQuadraticResidueModPrime2(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &s) {m_s = s;} <a name="l00040"></a>00040 <a name="l00041"></a>00041 <span class="keyword">protected</span>: <a name="l00042"></a>00042 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> m_n, m_r, m_s; <a name="l00043"></a>00043 }; <a name="l00044"></a>00044 <span class="comment"></span> <a name="l00045"></a>00045 <span class="comment">//! _</span> <a name="l00046"></a><a class="code" href="class_invertible_rabin_function.html">00046</a> <span class="comment"></span><span class="keyword">class </span><a class="code" href="class_invertible_rabin_function.html" title="_">InvertibleRabinFunction</a> : <span class="keyword">public</span> <a class="code" href="class_rabin_function.html" title="_">RabinFunction</a>, <span class="keyword">public</span> <a class="code" href="class_trapdoor_function_inverse.html" title="_">TrapdoorFunctionInverse</a>, <span class="keyword">public</span> <a class="code" href="class_private_key.html" title="interface for private keys">PrivateKey</a> <a name="l00047"></a>00047 { <a name="l00048"></a>00048 <span class="keyword">typedef</span> <a class="code" href="class_invertible_rabin_function.html" title="_">InvertibleRabinFunction</a> <a class="code" href="class_rabin_function.html" title="_">ThisClass</a>; <a name="l00049"></a>00049 <a name="l00050"></a>00050 <span class="keyword">public</span>: <a name="l00051"></a>00051 <span class="keywordtype">void</span> Initialize(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &n, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &r, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &s, <a name="l00052"></a>00052 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &u) <a name="l00053"></a>00053 {m_n = n; m_r = r; m_s = s; m_p = p; m_q = q; m_u = u;} <a name="l00054"></a>00054 <span class="keywordtype">void</span> Initialize(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> keybits) <a name="l00055"></a>00055 {<a class="code" href="class_generatable_crypto_material.html#a38d492343c32e530a5c2781b5797f755" title="calls the above function with a NameValuePairs object that just specifies "KeySize"">GenerateRandomWithKeySize</a>(rng, keybits);} <a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="keywordtype">void</span> BERDecode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt); <a name="l00058"></a>00058 <span class="keywordtype">void</span> DEREncode(<a class="code" href="class_buffered_transformation.html" title="interface for buffered transformations">BufferedTransformation</a> &bt) <span class="keyword">const</span>; <a name="l00059"></a>00059 <a name="l00060"></a>00060 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> CalculateInverse(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &x) <span class="keyword">const</span>; <a name="l00061"></a>00061 <a name="l00062"></a>00062 <span class="keywordtype">bool</span> <a class="code" href="class_invertible_rabin_function.html#ab943e623f7f1ffb3d890c1ab9e4e3474" title="check this object for errors">Validate</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> level) <span class="keyword">const</span>; <a name="l00063"></a>00063 <span class="keywordtype">bool</span> <a class="code" href="class_invertible_rabin_function.html#a52931eba7e69b47a1b9307dc92721e0f" title="to be implemented by derived classes, users should use one of the above functions instead...">GetVoidValue</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *name, <span class="keyword">const</span> std::type_info &valueType, <span class="keywordtype">void</span> *pValue) <span class="keyword">const</span>; <a name="l00064"></a>00064 <span class="keywordtype">void</span> <a class="code" href="class_invertible_rabin_function.html#a66594bb7f369e4ecc30bbe6ae62527ea" title="assign values from source to this object">AssignFrom</a>(<span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &source);<span class="comment"></span> <a name="l00065"></a>00065 <span class="comment"> /*! parameters: (ModulusSize) */</span> <a name="l00066"></a>00066 <span class="keywordtype">void</span> <a class="code" href="class_invertible_rabin_function.html#a571737380b956b4add10c855484af670">GenerateRandom</a>(<a class="code" href="class_random_number_generator.html" title="interface for random number generators">RandomNumberGenerator</a> &rng, <span class="keyword">const</span> <a class="code" href="class_name_value_pairs.html" title="interface for retrieving values given their names">NameValuePairs</a> &alg); <a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetPrime1()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_p;} <a name="l00069"></a>00069 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetPrime2()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_q;} <a name="l00070"></a>00070 <span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a>& GetMultiplicativeInverseOfPrime2ModPrime1()<span class="keyword"> const </span>{<span class="keywordflow">return</span> m_u;} <a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="keywordtype">void</span> SetPrime1(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &p) {m_p = p;} <a name="l00073"></a>00073 <span class="keywordtype">void</span> SetPrime2(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &q) {m_q = q;} <a name="l00074"></a>00074 <span class="keywordtype">void</span> SetMultiplicativeInverseOfPrime2ModPrime1(<span class="keyword">const</span> <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> &u) {m_u = u;} <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="keyword">protected</span>: <a name="l00077"></a>00077 <a class="code" href="class_integer.html" title="multiple precision integer and basic arithmetics">Integer</a> m_p, m_q, m_u; <a name="l00078"></a>00078 }; <a name="l00079"></a>00079 <span class="comment"></span> <a name="l00080"></a>00080 <span class="comment">//! Rabin</span> <a name="l00081"></a><a class="code" href="struct_rabin.html">00081</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="struct_rabin.html" title="Rabin.">Rabin</a> <a name="l00082"></a>00082 { <a name="l00083"></a>00083 <span class="keyword">static</span> std::string StaticAlgorithmName() {<span class="keywordflow">return</span> <span class="stringliteral">"Rabin-Crypto++Variant"</span>;} <a name="l00084"></a>00084 <span class="keyword">typedef</span> <a class="code" href="class_rabin_function.html" title="_">RabinFunction</a> <a class="code" href="class_rabin_function.html" title="_">PublicKey</a>; <a name="l00085"></a>00085 <span class="keyword">typedef</span> <a class="code" href="class_invertible_rabin_function.html" title="_">InvertibleRabinFunction</a> <a class="code" href="class_invertible_rabin_function.html" title="_">PrivateKey</a>; <a name="l00086"></a>00086 }; <a name="l00087"></a>00087 <span class="comment"></span> <a name="l00088"></a>00088 <span class="comment">//! Rabin encryption</span> <a name="l00089"></a>00089 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> STANDARD> <a name="l00090"></a><a class="code" href="struct_rabin_e_s.html">00090</a> <span class="keyword">struct </span><a class="code" href="struct_rabin_e_s.html" title="Rabin encryption.">RabinES</a> : <span class="keyword">public</span> <a class="code" href="class_t_f___e_s.html" title="Trapdoor Function Based Encryption Scheme.">TF_ES</a><STANDARD, Rabin> <a name="l00091"></a>00091 { <a name="l00092"></a>00092 }; <a name="l00093"></a>00093 <span class="comment"></span> <a name="l00094"></a>00094 <span class="comment">//! Rabin signature</span> <a name="l00095"></a>00095 <span class="comment"></span><span class="keyword">template</span> <<span class="keyword">class</span> STANDARD, <span class="keyword">class</span> H> <a name="l00096"></a><a class="code" href="struct_rabin_s_s.html">00096</a> <span class="keyword">struct </span><a class="code" href="struct_rabin_s_s.html" title="Rabin signature.">RabinSS</a> : <span class="keyword">public</span> <a class="code" href="class_t_f___s_s.html" title="Trapdoor Function Based Signature Scheme.">TF_SS</a><STANDARD, H, Rabin> <a name="l00097"></a>00097 { <a name="l00098"></a>00098 }; <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">// More typedefs for backwards compatibility</span> <a name="l00101"></a>00101 <span class="keyword">class </span><a class="code" href="class_s_h_a1.html" title="SHA-1">SHA1</a>; <a name="l00102"></a>00102 <span class="keyword">typedef</span> <a class="code" href="struct_rabin_e_s.html" title="Rabin encryption.">RabinES<OAEP<SHA1></a> >::Decryptor <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">RabinDecryptor</a>; <a name="l00103"></a>00103 <span class="keyword">typedef</span> <a class="code" href="struct_rabin_e_s.html" title="Rabin encryption.">RabinES<OAEP<SHA1></a> >::Encryptor <a class="code" href="class_p_k___final_template.html" title="A template implementing constructors for public key algorithm classes.">RabinEncryptor</a>; <a name="l00104"></a>00104 <a name="l00105"></a>00105 NAMESPACE_END <a name="l00106"></a>00106 <a name="l00107"></a>00107 <span class="preprocessor">#endif</span> </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Sun Oct 16 2011 for Crypto++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>