/usr/share/doc/libghc-crypto-doc/html/src/Codec-Encryption-RSA-EMEOAEP.html is in libghc-crypto-doc 4.2.5.1-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>Codec/Encryption/RSA/EMEOAEP.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-2"></a><span class='hs-comment'>-- |</span>
<a name="line-3"></a><span class='hs-comment'>-- Module : Coded.Encryption.RSA.EMEOAEP</span>
<a name="line-4"></a><span class='hs-comment'>-- Copyright : (c) David J. Sankel 2003, Dominic Steinitz 2003</span>
<a name="line-5"></a><span class='hs-comment'>-- License : GPL (see the file ReadMe.tex)</span>
<a name="line-6"></a><span class='hs-comment'>--</span>
<a name="line-7"></a><span class='hs-comment'>-- Maintainer : dominic.steinitz@blueyonder.co.uk</span>
<a name="line-8"></a><span class='hs-comment'>-- Stability : experimental</span>
<a name="line-9"></a><span class='hs-comment'>-- Portability : non-portable</span>
<a name="line-10"></a><span class='hs-comment'>--</span>
<a name="line-11"></a><span class='hs-comment'>-- A modified version of the EMEOAEP module supplied by David J. Sankel</span>
<a name="line-12"></a><span class='hs-comment'>-- (<<a href="http://www.electronconsulting.com/rsa-haskell">http://www.electronconsulting.com/rsa-haskell</a>>).</span>
<a name="line-13"></a><span class='hs-comment'>--</span>
<a name="line-14"></a><span class='hs-comment'>-- As the original code is GPL, this has to be.</span>
<a name="line-15"></a><span class='hs-comment'>-- This code is free software; you can redistribute it and\/or modify</span>
<a name="line-16"></a><span class='hs-comment'>-- it under the terms of the GNU General Public License as published by</span>
<a name="line-17"></a><span class='hs-comment'>-- the Free Software Foundation; either version 2 of the License, or</span>
<a name="line-18"></a><span class='hs-comment'>-- (at your option) any later version.</span>
<a name="line-19"></a><span class='hs-comment'>--</span>
<a name="line-20"></a><span class='hs-comment'>-- This code is distributed in the hope that it will be useful,</span>
<a name="line-21"></a><span class='hs-comment'>-- but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="line-22"></a><span class='hs-comment'>-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="line-23"></a><span class='hs-comment'>-- GNU General Public License for more details.</span>
<a name="line-24"></a><span class='hs-comment'>--</span>
<a name="line-25"></a><span class='hs-comment'>-- You should have received a copy of the GNU General Public License</span>
<a name="line-26"></a><span class='hs-comment'>-- along with this code; if not, write to the Free Software</span>
<a name="line-27"></a><span class='hs-comment'>-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111\-1307 USA</span>
<a name="line-28"></a><span class='hs-comment'>-----------------------------------------------------------------------------</span>
<a name="line-29"></a>
<a name="line-30"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Codec</span><span class='hs-varop'>.</span><span class='hs-conid'>Encryption</span><span class='hs-varop'>.</span><span class='hs-conid'>RSA</span><span class='hs-varop'>.</span><span class='hs-conid'>EMEOAEP</span><span class='hs-layout'>(</span>
<a name="line-31"></a> <span class='hs-comment'>-- * Function Types</span>
<a name="line-32"></a> <span class='hs-varid'>encode</span><span class='hs-layout'>,</span>
<a name="line-33"></a> <span class='hs-varid'>decode</span>
<a name="line-34"></a> <span class='hs-layout'>)</span><span class='hs-keyword'>where</span>
<a name="line-35"></a>
<a name="line-36"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Codec</span><span class='hs-varop'>.</span><span class='hs-conid'>Utils</span> <span class='hs-layout'>(</span><span class='hs-conid'>Octet</span><span class='hs-layout'>)</span>
<a name="line-37"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Bits</span>
<a name="line-38"></a>
<a name="line-39"></a><a name="xorOctets"></a><span class='hs-definition'>xorOctets</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Bits</span> <span class='hs-varid'>a</span> <span class='hs-keyglyph'>=></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>a</span><span class='hs-keyglyph'>]</span>
<a name="line-40"></a><span class='hs-definition'>xorOctets</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>zipWith</span> <span class='hs-varid'>xor</span>
<a name="line-41"></a>
<a name="line-42"></a><span class='hs-comment'>-- | Take a mask generating function, a hash function, a label (which may be</span>
<a name="line-43"></a><span class='hs-comment'>-- null), a random seed, the modulus of the key and the message and returns</span>
<a name="line-44"></a><span class='hs-comment'>-- an encoded message. NB you could pass in the length of the modulus</span>
<a name="line-45"></a><span class='hs-comment'>-- but it seems safer to pass in the modulus itself and calculate the</span>
<a name="line-46"></a><span class='hs-comment'>-- length when required. See </span>
<a name="line-47"></a><span class='hs-comment'>-- <ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/pkcs-1v2-1.pdf> for more</span>
<a name="line-48"></a><span class='hs-comment'>-- details.</span>
<a name="line-49"></a>
<a name="line-50"></a><a name="encode"></a><span class='hs-definition'>encode</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span>
<a name="line-51"></a> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span>
<a name="line-52"></a> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span>
<a name="line-53"></a>
<a name="line-54"></a><span class='hs-definition'>encode</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>p</span> <span class='hs-varid'>seed</span> <span class='hs-varid'>n</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span>
<a name="line-55"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>length</span> <span class='hs-varid'>m</span> <span class='hs-varop'>></span> <span class='hs-varid'>emLen</span> <span class='hs-comment'>-</span> <span class='hs-num'>2</span><span class='hs-varop'>*</span><span class='hs-varid'>hLen</span> <span class='hs-comment'>-</span> <span class='hs-num'>2</span>
<a name="line-56"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>error</span> <span class='hs-str'>"Codec.Encryption.EMEOAEP.encode: message too long"</span>
<a name="line-57"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>em</span>
<a name="line-58"></a> <span class='hs-keyword'>where</span>
<a name="line-59"></a> <span class='hs-varid'>emLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>n</span>
<a name="line-60"></a> <span class='hs-varid'>mLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>m</span>
<a name="line-61"></a> <span class='hs-varid'>ps</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>take</span> <span class='hs-layout'>(</span><span class='hs-varid'>emLen</span><span class='hs-comment'>-</span><span class='hs-varid'>mLen</span><span class='hs-comment'>-</span><span class='hs-num'>2</span><span class='hs-varop'>*</span><span class='hs-varid'>hLen</span><span class='hs-comment'>-</span><span class='hs-num'>2</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>repeat</span> <span class='hs-varop'>$</span> <span class='hs-num'>0x00</span>
<a name="line-62"></a> <span class='hs-varid'>pHash</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>p</span>
<a name="line-63"></a> <span class='hs-varid'>hLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>pHash</span>
<a name="line-64"></a> <span class='hs-varid'>db</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>pHash</span> <span class='hs-varop'>++</span> <span class='hs-varid'>ps</span> <span class='hs-varop'>++</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0x01</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>++</span> <span class='hs-varid'>m</span>
<a name="line-65"></a> <span class='hs-varid'>dbMask</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>seed</span> <span class='hs-layout'>(</span><span class='hs-varid'>length</span> <span class='hs-varid'>db</span><span class='hs-layout'>)</span>
<a name="line-66"></a> <span class='hs-varid'>maskedDB</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>db</span> <span class='hs-varop'>`xorOctets`</span> <span class='hs-varid'>dbMask</span>
<a name="line-67"></a> <span class='hs-varid'>seedMask</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>maskedDB</span> <span class='hs-varid'>hLen</span>
<a name="line-68"></a> <span class='hs-varid'>maskedSeed</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>seed</span> <span class='hs-varop'>`xorOctets`</span> <span class='hs-varid'>seedMask</span>
<a name="line-69"></a> <span class='hs-varid'>em</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0x00</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>++</span> <span class='hs-varid'>maskedSeed</span> <span class='hs-varop'>++</span> <span class='hs-varid'>maskedDB</span>
<a name="line-70"></a>
<a name="line-71"></a><span class='hs-comment'>-- | Take a mask generating function, a hash function, a label (which may be</span>
<a name="line-72"></a><span class='hs-comment'>-- null) and the message and returns the decoded.</span>
<a name="line-73"></a>
<a name="line-74"></a><a name="decode"></a><span class='hs-definition'>decode</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span>
<a name="line-75"></a> <span class='hs-layout'>(</span><span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Octet</span><span class='hs-keyglyph'>]</span>
<a name="line-76"></a>
<a name="line-77"></a><span class='hs-definition'>decode</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>p</span> <span class='hs-varid'>em</span> <span class='hs-keyglyph'>=</span>
<a name="line-78"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>length</span> <span class='hs-varid'>em</span> <span class='hs-varop'><</span> <span class='hs-num'>2</span><span class='hs-varop'>*</span><span class='hs-varid'>hLen</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span> <span class='hs-varop'>||</span>
<a name="line-79"></a> <span class='hs-varid'>one</span> <span class='hs-varop'>/=</span> <span class='hs-num'>0x01</span> <span class='hs-varop'>||</span>
<a name="line-80"></a> <span class='hs-varid'>pHash'</span> <span class='hs-varop'>/=</span> <span class='hs-varid'>pHash</span> <span class='hs-varop'>||</span>
<a name="line-81"></a> <span class='hs-varid'>y</span> <span class='hs-varop'>/=</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0x00</span><span class='hs-keyglyph'>]</span>
<a name="line-82"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>error</span> <span class='hs-str'>"Codec.Encryption.EMEOAEP.decode: decryption error"</span>
<a name="line-83"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>m</span>
<a name="line-84"></a> <span class='hs-keyword'>where</span>
<a name="line-85"></a> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span><span class='hs-varid'>rest</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitAt</span> <span class='hs-num'>1</span> <span class='hs-varid'>em</span>
<a name="line-86"></a> <span class='hs-varid'>pHash</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>p</span>
<a name="line-87"></a> <span class='hs-varid'>hLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>pHash</span>
<a name="line-88"></a> <span class='hs-layout'>(</span><span class='hs-varid'>maskedSeed</span><span class='hs-layout'>,</span><span class='hs-varid'>maskedDB</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitAt</span> <span class='hs-varid'>hLen</span> <span class='hs-varid'>rest</span>
<a name="line-89"></a> <span class='hs-varid'>seedMask</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>maskedDB</span> <span class='hs-varid'>hLen</span>
<a name="line-90"></a> <span class='hs-varid'>seed</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>maskedSeed</span> <span class='hs-varop'>`xorOctets`</span> <span class='hs-varid'>seedMask</span>
<a name="line-91"></a> <span class='hs-varid'>emLen</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>length</span> <span class='hs-varid'>em</span>
<a name="line-92"></a> <span class='hs-varid'>dbMask</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mgf</span> <span class='hs-varid'>hash</span> <span class='hs-varid'>seed</span> <span class='hs-layout'>(</span><span class='hs-varid'>emLen</span> <span class='hs-comment'>-</span> <span class='hs-varid'>hLen</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span>
<a name="line-93"></a> <span class='hs-varid'>db</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>maskedDB</span> <span class='hs-varop'>`xorOctets`</span> <span class='hs-varid'>dbMask</span>
<a name="line-94"></a> <span class='hs-layout'>(</span><span class='hs-varid'>pHash'</span><span class='hs-layout'>,</span><span class='hs-varid'>rest'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>splitAt</span> <span class='hs-varid'>hLen</span> <span class='hs-varid'>db</span>
<a name="line-95"></a> <span class='hs-layout'>(</span><span class='hs-varid'>one</span><span class='hs-conop'>:</span><span class='hs-varid'>m</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>dropWhile</span> <span class='hs-layout'>(</span><span class='hs-varop'>==</span> <span class='hs-num'>0x00</span><span class='hs-layout'>)</span> <span class='hs-varid'>rest'</span>
</pre></body>
</html>
|