blob: 0752e8c83a02925d990a071ab609bd924a361db5 [file] [log] [blame]
<head>
<title>des(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>DES(3)</b><td align=right><b>DES(3)</b>
<tr><td width=20><td colspan=2>
<br>
<p><font size=+1><b>NAME </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
setupDESstate, des_key_setup, block_cipher, desCBCencrypt, desCBCdecrypt,
desECBencrypt, desECBdecrypt, des3CBCencrypt, des3CBCdecrypt,
des3ECBencrypt, des3ECBdecrypt, key_setup, des56to64, des64to56,
setupDES3state, triple_block_cipher, - single and triple digital
encryption standard
</table>
<p><font size=+1><b>SYNOPSIS </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>#include &lt;u.h&gt;<br>
#include &lt;libc.h&gt;<br>
#include &lt;mp.h&gt;<br>
#include &lt;libsec.h&gt;
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des_key_setup(uchar key[8], ulong schedule[32])
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void block_cipher(ulong *schedule, uchar *data, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int decrypting)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void setupDESstate(DESstate *s, uchar key[8], uchar *ivec)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void desCBCencrypt(uchar*, int, DESstate*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void desCBCdecrypt(uchar*, int, DESstate*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void desECBencrypt(uchar*, int, DESstate*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void desECBdecrypt(uchar*, int, DESstate*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void triple_block_cipher(ulong keys[3][32], uchar*, int)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void setupDES3state(DES3state *s, uchar key[3][8], &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uchar *ivec)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des3CBCencrypt(uchar*, int, DES3state*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des3CBCdecrypt(uchar*, int, DES3state*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des3ECBencrypt(uchar*, int, DES3state*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des3ECBdecrypt(uchar*, int, DES3state*)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void key_setup(uchar[7], ulong[32])
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des56to64(uchar *k56, uchar *k64)
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</font></tt>
<tt><font size=+1>void des64to56(uchar *k64, uchar *k56)<br>
</font></tt>
</table>
<p><font size=+1><b>DESCRIPTION </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
The Digital Encryption Standard (DES) is a shared key or symmetric
encryption using either a 56 bit key for single DES or three 56
bit keys for triple des. The keys are encoded into 64 bits where
every eight bit is parity.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
The basic DES function, <i>block_cipher</i>, works on a block of 8 bytes,
converting them in place. It takes a key schedule, a pointer to
the block, and a flag indicating encrypting (0) or decrypting
(1). The key schedule is created from the key using <i>des_key_setup</i>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Since it is a bit awkward, <i>block_cipher</i> is rarely called directly.
Instead, one normally uses routines that encrypt larger buffers
of data and which may chain the encryption state from one buffer
to the next. These routines keep track of the state of the encryption
using a <tt><font size=+1>DESstate</font></tt> structure that contains the key
schedule and any chained state. <i>SetupDESstate</i> sets up the <tt><font size=+1>DESstate</font></tt>
structure using the key and an 8 byte initialization vector.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Electronic code book, using <i>desECBencrypt</i> and <i>desECBdecrypt</i>, is
the less secure mode. The encryption of each 8 bytes does not
depend on the encryption of any other. Hence the encryption is
a substitution cipher using 64 bit characters.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
Cipher block chaining mode, using <i>desCBCencrypt</i> and <i>desCBCdecrypt</i>,
is more secure. Every block encrypted depends on the initialization
vector and all blocks encrypted before it.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
For both CBC and ECB modes, a stream of data can be encrypted
as multiple buffers. However, all buffers except the last must
be a multiple of 8 bytes to ensure successful decryption of the
stream.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
There are equivalent triple DES functions for each of the DES
functions.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
In the past Plan 9 used a 56 bit or 7 byte format for DES keys.
To be compatible with the rest of the world, we&#8217;ve abandoned this
format. There are two functions: <i>des56to64</i> and <i>des64to56</i> to convert
back and forth between the two formats. Also a key schedule can
be set up from the 7 byte format using <i>key_setup</i>.
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
</table>
<p><font size=+1><b>SOURCE </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<tt><font size=+1>/usr/local/plan9/src/libsec<br>
</font></tt>
</table>
<p><font size=+1><b>SEE ALSO </b></font><br>
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
<a href="../man3/mp.html"><i>mp</i>(3)</a>, <a href="../man3/aes.html"><i>aes</i>(3)</a>, <a href="../man3/blowfish.html"><i>blowfish</i>(3)</a>, <a href="../man3/dsa.html"><i>dsa</i>(3)</a>, <a href="../man3/elgamal.html"><i>elgamal</i>(3)</a>, <a href="../man3/rc4.html"><i>rc4</i>(3)</a>, <a href="../man3/rsa.html"><i>rsa</i>(3)</a>,
<a href="../man3/sechash.html"><i>sechash</i>(3)</a>, <a href="../man3/prime.html"><i>prime</i>(3)</a>, <a href="../man3/rand.html"><i>rand</i>(3)</a><br>
</table>
<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>