diff options
Diffstat (limited to 'api/2.5/Crypto.Signature.PKCS1_PSS-module.html')
-rw-r--r-- | api/2.5/Crypto.Signature.PKCS1_PSS-module.html | 413 |
1 files changed, 413 insertions, 0 deletions
diff --git a/api/2.5/Crypto.Signature.PKCS1_PSS-module.html b/api/2.5/Crypto.Signature.PKCS1_PSS-module.html new file mode 100644 index 0000000..11c1a40 --- /dev/null +++ b/api/2.5/Crypto.Signature.PKCS1_PSS-module.html @@ -0,0 +1,413 @@ +<?xml version="1.0" encoding="ascii"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> + <title>Crypto.Signature.PKCS1_PSS</title> + <link rel="stylesheet" href="epydoc.css" type="text/css" /> + <script type="text/javascript" src="epydoc.js"></script> +</head> + +<body bgcolor="white" text="black" link="blue" vlink="#204080" + alink="#204080"> +<!-- ==================== NAVIGATION BAR ==================== --> +<table class="navbar" border="0" width="100%" cellpadding="0" + bgcolor="#a0c0ff" cellspacing="0"> + <tr valign="middle"> + <!-- Home link --> + <th> <a + href="Crypto-module.html">Home</a> </th> + + <!-- Tree link --> + <th> <a + href="module-tree.html">Trees</a> </th> + + <!-- Index link --> + <th> <a + href="identifier-index.html">Indices</a> </th> + + <!-- Help link --> + <th> <a + href="help.html">Help</a> </th> + + <!-- Project homepage --> + <th class="navbar" align="right" width="100%"> + <table border="0" cellpadding="0" cellspacing="0"> + <tr><th class="navbar" align="center" + ><a href="http://www.pycrypto.org/">PyCrypto.org</a></th> + </tr></table></th> + </tr> +</table> +<table width="100%" cellpadding="0" cellspacing="0"> + <tr valign="top"> + <td width="100%"> + <span class="breadcrumbs"> + <a href="Crypto-module.html">Package Crypto</a> :: + <a href="Crypto.Signature-module.html">Package Signature</a> :: + Module PKCS1_PSS + </span> + </td> + <td> + <table cellpadding="0" cellspacing="0"> + <!-- hide/show private --> + <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" + onclick="toggle_private();">hide private</a>]</span></td></tr> + <tr><td align="right"><span class="options" + >[<a href="frames.html" target="_top">frames</a + >] | <a href="Crypto.Signature.PKCS1_PSS-module.html" + target="_top">no frames</a>]</span></td></tr> + </table> + </td> + </tr> +</table> +<!-- ==================== MODULE DESCRIPTION ==================== --> +<h1 class="epydoc">Module PKCS1_PSS</h1><p class="nomargin-top"></p> +<p>RSA digital signature protocol with appendix according to PKCS#1 PSS.</p> +<p>See <a class="rst-reference external" href="http://www.ietf.org/rfc/rfc3447.txt" target="_top">RFC3447</a> or the <a class="rst-reference external" href="http://www.rsa.com/rsalabs/node.asp?id=2125" target="_top">original RSA Labs specification</a>.</p> +<p>This scheme is more properly called <tt class="rst-docutils literal"><span class="pre">RSASSA-PSS</span></tt>.</p> +<p>For example, a sender may authenticate a message using SHA-1 and PSS like +this:</p> +<blockquote> +<pre class="py-doctest"> +<span class="py-prompt">>>> </span><span class="py-keyword">from</span> Crypto.Signature <span class="py-keyword">import</span> PKCS1_PSS +<span class="py-prompt">>>> </span><span class="py-keyword">from</span> Crypto.Hash <span class="py-keyword">import</span> SHA +<span class="py-prompt">>>> </span><span class="py-keyword">from</span> Crypto.PublicKey <span class="py-keyword">import</span> RSA +<span class="py-prompt">>>> </span><span class="py-keyword">from</span> Crypto <span class="py-keyword">import</span> Random +<span class="py-prompt">>>></span> +<span class="py-prompt">>>> </span>message = <span class="py-string">'To be signed'</span> +<span class="py-prompt">>>> </span>key = RSA.importKey(open(<span class="py-string">'privkey.der'</span>).read()) +<span class="py-prompt">>>> </span>h = SHA.new() +<span class="py-prompt">>>> </span>h.update(message) +<span class="py-prompt">>>> </span>signer = PKCS1_PSS.new(key) +<span class="py-prompt">>>> </span>signature = PKCS1_PSS.sign(key)</pre> +</blockquote> +<p>At the receiver side, verification can be done like using the public part of +the RSA key:</p> +<blockquote> +<pre class="py-doctest"> +<span class="py-prompt">>>> </span>key = RSA.importKey(open(<span class="py-string">'pubkey.der'</span>).read()) +<span class="py-prompt">>>> </span>h = SHA.new() +<span class="py-prompt">>>> </span>h.update(message) +<span class="py-prompt">>>> </span>verifier = PKCS1_PSS.new(key) +<span class="py-prompt">>>> </span><span class="py-keyword">if</span> verifier.verify(h, signature): +<span class="py-prompt">>>> </span> <span class="py-keyword">print</span> <span class="py-string">"The signature is authentic."</span> +<span class="py-prompt">>>> </span><span class="py-keyword">else</span>: +<span class="py-prompt">>>> </span> <span class="py-keyword">print</span> <span class="py-string">"The signature is not authentic."</span></pre> +</blockquote> + +<!-- ==================== CLASSES ==================== --> +<a name="section-Classes"></a> +<table class="summary" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr bgcolor="#70b0f0" class="table-header"> + <td colspan="2" class="table-header"> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr valign="top"> + <td align="left"><span class="table-header">Classes</span></td> + <td align="right" valign="top" + ><span class="options">[<a href="#section-Classes" + class="privatelink" onclick="toggle_private();" + >hide private</a>]</span></td> + </tr> + </table> + </td> +</tr> +<tr class="private"> + <td width="15%" align="right" valign="top" class="summary"> + <span class="summary-type"> </span> + </td><td class="summary"> + <a href="Crypto.Signature.PKCS1_PSS.PSS_SigScheme-class.html" class="summary-name" onclick="show_private();">PSS_SigScheme</a><br /> + This signature scheme can perform PKCS#1 PSS RSA signature or verification. + </td> + </tr> +</table> +<!-- ==================== FUNCTIONS ==================== --> +<a name="section-Functions"></a> +<table class="summary" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr bgcolor="#70b0f0" class="table-header"> + <td colspan="2" class="table-header"> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr valign="top"> + <td align="left"><span class="table-header">Functions</span></td> + <td align="right" valign="top" + ><span class="options">[<a href="#section-Functions" + class="privatelink" onclick="toggle_private();" + >hide private</a>]</span></td> + </tr> + </table> + </td> +</tr> +<tr class="private"> + <td width="15%" align="right" valign="top" class="summary"> + <span class="summary-type"> </span> + </td><td class="summary"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td><span class="summary-sig"><a name="MGF1"></a><span class="summary-sig-name">MGF1</span>(<span class="summary-sig-arg">mgfSeed</span>, + <span class="summary-sig-arg">maskLen</span>, + <span class="summary-sig-arg">hash</span>)</span><br /> + Mask Generation Function, described in B.2.1</td> + <td align="right" valign="top"> + + + </td> + </tr> + </table> + + </td> + </tr> +<tr class="private"> + <td width="15%" align="right" valign="top" class="summary"> + <span class="summary-type"> </span> + </td><td class="summary"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td><span class="summary-sig"><a href="Crypto.Signature.PKCS1_PSS-module.html#EMSA_PSS_ENCODE" class="summary-sig-name" onclick="show_private();">EMSA_PSS_ENCODE</a>(<span class="summary-sig-arg">mhash</span>, + <span class="summary-sig-arg">emBits</span>, + <span class="summary-sig-arg">randFunc</span>, + <span class="summary-sig-arg">mgf</span>, + <span class="summary-sig-arg">sLen</span>)</span><br /> + Implement the <tt class="rst-docutils literal"><span class="pre">EMSA-PSS-ENCODE</span></tt> function, as defined +in PKCS#1 v2.1 (RFC3447, 9.1.1).</td> + <td align="right" valign="top"> + + + </td> + </tr> + </table> + + </td> + </tr> +<tr class="private"> + <td width="15%" align="right" valign="top" class="summary"> + <span class="summary-type"> </span> + </td><td class="summary"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td><span class="summary-sig"><a href="Crypto.Signature.PKCS1_PSS-module.html#EMSA_PSS_VERIFY" class="summary-sig-name" onclick="show_private();">EMSA_PSS_VERIFY</a>(<span class="summary-sig-arg">mhash</span>, + <span class="summary-sig-arg">em</span>, + <span class="summary-sig-arg">emBits</span>, + <span class="summary-sig-arg">mgf</span>, + <span class="summary-sig-arg">sLen</span>)</span><br /> + Implement the <tt class="rst-docutils literal"><span class="pre">EMSA-PSS-VERIFY</span></tt> function, as defined +in PKCS#1 v2.1 (RFC3447, 9.1.2).</td> + <td align="right" valign="top"> + + + </td> + </tr> + </table> + + </td> + </tr> +<tr> + <td width="15%" align="right" valign="top" class="summary"> + <span class="summary-type"> </span> + </td><td class="summary"> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr> + <td><span class="summary-sig"><a href="Crypto.Signature.PKCS1_PSS-module.html#new" class="summary-sig-name">new</a>(<span class="summary-sig-arg">key</span>, + <span class="summary-sig-arg">mgfunc</span>=<span class="summary-sig-default">None</span>, + <span class="summary-sig-arg">saltLen</span>=<span class="summary-sig-default">None</span>)</span><br /> + Return a signature scheme object <a href="Crypto.Signature.PKCS1_PSS.PSS_SigScheme-class.html" class="link" onclick="show_private();">PSS_SigScheme</a> that +can be used to perform PKCS#1 PSS signature or verification.</td> + <td align="right" valign="top"> + + + </td> + </tr> + </table> + + </td> + </tr> +</table> +<!-- ==================== FUNCTION DETAILS ==================== --> +<a name="section-FunctionDetails"></a> +<table class="details" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr bgcolor="#70b0f0" class="table-header"> + <td colspan="2" class="table-header"> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr valign="top"> + <td align="left"><span class="table-header">Function Details</span></td> + <td align="right" valign="top" + ><span class="options">[<a href="#section-FunctionDetails" + class="privatelink" onclick="toggle_private();" + >hide private</a>]</span></td> + </tr> + </table> + </td> +</tr> +</table> +<a name="EMSA_PSS_ENCODE"></a> +<div class="private"> +<table class="details" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr><td> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr valign="top"><td> + <h3 class="epydoc"><span class="sig"><span class="sig-name">EMSA_PSS_ENCODE</span>(<span class="sig-arg">mhash</span>, + <span class="sig-arg">emBits</span>, + <span class="sig-arg">randFunc</span>, + <span class="sig-arg">mgf</span>, + <span class="sig-arg">sLen</span>)</span> + </h3> + </td><td align="right" valign="top" + > + </td> + </tr></table> + + <p>Implement the <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">EMSA-PSS-ENCODE</span></tt> function, as defined +in PKCS#1 v2.1 (RFC3447, 9.1.1).</p> +<p>The original <tt class="rst-docutils literal"><span class="pre">EMSA-PSS-ENCODE</span></tt> actually accepts the message <tt class="rst-docutils literal">M</tt> as input, +and hash it internally. Here, we expect that the message has already +been hashed instead.</p> + <dl class="fields"> + <dt>Parameters:</dt> + <dd><ul class="nomargin-top"> + <li><strong class="pname"><code>mhash</code></strong> (hash object) - The hash object that holds the digest of the message being signed.</li> + <li><strong class="pname"><code>emBits</code></strong> (int) - Maximum length of the final encoding, in bits.</li> + <li><strong class="pname"><code>randFunc</code></strong> (callable) - An RNG function that accepts as only parameter an int, and returns +a string of random bytes, to be used as salt.</li> + <li><strong class="pname"><code>mgf</code></strong> (callable) - A mask generation function that accepts two parameters: a string to +use as seed, and the lenth of the mask to generate, in bytes.</li> + <li><strong class="pname"><code>sLen</code></strong> (int) - Length of the salt, in bytes.</li> + </ul></dd> + <dt>Returns:</dt> + <dd>An <tt class="rst-docutils literal">emLen</tt> byte long string that encodes the hash +(with <tt class="rst-docutils literal">emLen = \ceil(emBits/8)</tt>).</dd> + <dt>Raises:</dt> + <dd><ul class="nomargin-top"> + <li><code><strong class='fraise'>ValueError</strong></code> - When digest or salt length are too big.</li> + </ul></dd> + </dl> +</td></tr></table> +</div> +<a name="EMSA_PSS_VERIFY"></a> +<div class="private"> +<table class="details" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr><td> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr valign="top"><td> + <h3 class="epydoc"><span class="sig"><span class="sig-name">EMSA_PSS_VERIFY</span>(<span class="sig-arg">mhash</span>, + <span class="sig-arg">em</span>, + <span class="sig-arg">emBits</span>, + <span class="sig-arg">mgf</span>, + <span class="sig-arg">sLen</span>)</span> + </h3> + </td><td align="right" valign="top" + > + </td> + </tr></table> + + <p>Implement the <tt class="rst-rst-docutils literal rst-docutils literal"><span class="pre">EMSA-PSS-VERIFY</span></tt> function, as defined +in PKCS#1 v2.1 (RFC3447, 9.1.2).</p> +<p><tt class="rst-docutils literal"><span class="pre">EMSA-PSS-VERIFY</span></tt> actually accepts the message <tt class="rst-docutils literal">M</tt> as input, +and hash it internally. Here, we expect that the message has already +been hashed instead.</p> + <dl class="fields"> + <dt>Parameters:</dt> + <dd><ul class="nomargin-top"> + <li><strong class="pname"><code>mhash</code></strong> (hash object) - The hash object that holds the digest of the message to be verified.</li> + <li><strong class="pname"><code>em</code></strong> (string) - The signature to verify, therefore proving that the sender really signed +the message that was received.</li> + <li><strong class="pname"><code>emBits</code></strong> (int) - Length of the final encoding (em), in bits.</li> + <li><strong class="pname"><code>mgf</code></strong> (callable) - A mask generation function that accepts two parameters: a string to +use as seed, and the lenth of the mask to generate, in bytes.</li> + <li><strong class="pname"><code>sLen</code></strong> (int) - Length of the salt, in bytes.</li> + </ul></dd> + <dt>Returns:</dt> + <dd>0 if the encoding is consistent, 1 if it is inconsistent.</dd> + <dt>Raises:</dt> + <dd><ul class="nomargin-top"> + <li><code><strong class='fraise'>ValueError</strong></code> - When digest or salt length are too big.</li> + </ul></dd> + </dl> +</td></tr></table> +</div> +<a name="new"></a> +<div> +<table class="details" border="1" cellpadding="3" + cellspacing="0" width="100%" bgcolor="white"> +<tr><td> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tr valign="top"><td> + <h3 class="epydoc"><span class="sig"><span class="sig-name">new</span>(<span class="sig-arg">key</span>, + <span class="sig-arg">mgfunc</span>=<span class="sig-default">None</span>, + <span class="sig-arg">saltLen</span>=<span class="sig-default">None</span>)</span> + </h3> + </td><td align="right" valign="top" + > + </td> + </tr></table> + + Return a signature scheme object <a href="Crypto.Signature.PKCS1_PSS.PSS_SigScheme-class.html" class="link" onclick="show_private();">PSS_SigScheme</a> that +can be used to perform PKCS#1 PSS signature or verification. + <dl class="fields"> + <dt>Parameters:</dt> + <dd><ul class="nomargin-top"> + <li><strong class="pname"><code>key</code></strong> (RSA key object) - The key to use to sign or verify the message. This is a <a href="Crypto.PublicKey.RSA-module.html" class="link">Crypto.PublicKey.RSA</a> object. +Signing is only possible if <em>key</em> is a private RSA key.</li> + <li><strong class="pname"><code>mgfunc</code></strong> (callable) - A mask generation function that accepts two parameters: a string to +use as seed, and the lenth of the mask to generate, in bytes. +If not specified, the standard MGF1 is used.</li> + <li><strong class="pname"><code>saltLen</code></strong> (int) - Length of the salt, in bytes. If not specified, it matches the output +size of the hash function.</li> + </ul></dd> + </dl> +</td></tr></table> +</div> +<br /> +<!-- ==================== NAVIGATION BAR ==================== --> +<table class="navbar" border="0" width="100%" cellpadding="0" + bgcolor="#a0c0ff" cellspacing="0"> + <tr valign="middle"> + <!-- Home link --> + <th> <a + href="Crypto-module.html">Home</a> </th> + + <!-- Tree link --> + <th> <a + href="module-tree.html">Trees</a> </th> + + <!-- Index link --> + <th> <a + href="identifier-index.html">Indices</a> </th> + + <!-- Help link --> + <th> <a + href="help.html">Help</a> </th> + + <!-- Project homepage --> + <th class="navbar" align="right" width="100%"> + <table border="0" cellpadding="0" cellspacing="0"> + <tr><th class="navbar" align="center" + ><a href="http://www.pycrypto.org/">PyCrypto.org</a></th> + </tr></table></th> + </tr> +</table> +<table border="0" cellpadding="0" cellspacing="0" width="100%%"> + <tr> + <td align="left" class="footer"> + Generated by Epydoc 3.0.1 on Fri Jan 13 12:36:11 2012 + </td> + <td align="right" class="footer"> + <a target="mainFrame" href="http://epydoc.sourceforge.net" + >http://epydoc.sourceforge.net</a> + </td> + </tr> +</table> + +<script type="text/javascript"> + <!-- + // Private objects are initially displayed (because if + // javascript is turned off then we want them to be + // visible); but by default, we want to hide them. So hide + // them unless we have a cookie that says to show them. + checkCookie(); + // --> +</script> +</body> +</html> |