skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

index.html (4038B)


      1 <html>
      2   <head>
      3     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      4     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      5     <meta http-equiv="Content-Language" content="en" />
      6     <title>skalibs: the stdcrypto library interface</title>
      7     <meta name="Description" content="skalibs: the stdcrypto library interface" />
      8     <meta name="Keywords" content="skalibs stdcrypto libstdcrypto library interface" />
      9     <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
     10   </head>
     11 <body>
     12 
     13 <p>
     14 <a href="../libskarnet.html">libskarnet</a><br />
     15 <a href="../index.html">skalibs</a><br />
     16 <a href="//skarnet.org/software/">Software</a><br />
     17 <a href="//skarnet.org/">skarnet.org</a>
     18 </p>
     19 
     20 <h1> The <tt>stdcrypto</tt> library interface </h1>
     21 
     22 <p>
     23 <tt>stdcrypto</tt> is a small collection of standard,
     24 public-domain cryptographic primitives. Currently, the following
     25 operations are provided:
     26 </p>
     27 
     28 <ul>
     29   <li> rc4 </li>
     30   <li> md5 </li>
     31   <li> sha1 </li>
     32   <li> sha256 </li>
     33   <li> sha512 </li>
     34 </ul>
     35 
     36 <p>
     37  Please bear in mind that rc4 and md5 are broken, and that sha1 is about to be.
     38 Do not use them in security-critical applications.
     39 </p>
     40 
     41 <h2> Compiling </h2>
     42 
     43 <ul>
     44  <li> Use <tt>#include &lt;skalibs/stdcrypto.h&gt;</tt> </li>
     45 </ul>
     46 
     47 <h2> Programming </h2>
     48 
     49 <p>
     50  You should refer to the <tt>skalibs/stdcrypto.h</tt> header and included headers
     51 for the exact function prototypes.
     52 </p>
     53 
     54 <h3> <a name="rc4" />
     55 RC4 </h3>
     56 
     57 <pre>
     58   RC4Schedule ctx ;
     59   unsigned char const *key ;
     60   size_t keylen ;
     61   unsigned char const *in ;
     62   unsigned char *out ;
     63   size_t len ;
     64 
     65   rc4_init(&amp;ctx, key, keylen) ;
     66   rc4(&amp;ctx, in, out, len) ;
     67 </pre>
     68 
     69 <ul>
     70   <li> <tt>rc4_init()</tt> initializes a RC4Schedule structure with a key <em>key</em>,
     71 of length <em>keylen</em>. It then computes and throws away the first <tt>RC4_THROWAWAY</tt>
     72 bytes, usually 100 </li>
     73   <li> <tt>rc4()</tt> encrypts <em>len</em> bytes of <em>in</em> with the RC4 flow, and
     74 stores the results into <em>out</em> </li>
     75 </ul>
     76 
     77 <h3> <a name="md5" />
     78 MD5 </h3>
     79 
     80 <pre>
     81   MD5Schedule ctx ;
     82   char const *message ;
     83   size_t messagelen ;
     84   char digest[16] ;
     85 
     86   md5_init(&amp;ctx) ;
     87   md5_update(&amp;ctx, message, messagelen) ;
     88   md5_final(&amp;ctx, digest) ;
     89 </pre>    
     90 
     91 <ul>
     92   <li> <tt>md5_init()</tt> prepares a MD5Schedule structure for computation </li>
     93   <li> <tt>md5_update()</tt> adds <em>message</em> to the message to be digested </li>
     94   <li> <tt>md5_final()</tt> computes the digest </li>
     95 </ul>
     96 
     97 <h3> <a name="sha1"></a>
     98 SHA1 </h3>
     99 
    100 <pre>
    101   SHA1Schedule ctx ;
    102   char const *message ;
    103   size_t messagelen ;
    104   unsigned char digest[20] ;
    105 
    106   sha1_init(&amp;ctx) ;
    107   sha1_update(&amp;ctx, message, messagelen) ;
    108   sha1_final(&amp;ctx, digest) ;
    109 </pre>
    110 
    111 <ul>
    112   <li> <tt>sha1_init()</tt> prepares a SHA1Schedule structure for computation </li>
    113   <li> <tt>sha1_update()</tt> adds <em>message</em> to the message to be digested </li>
    114   <li> <tt>sha1_final()</tt> computes the digest </li>
    115 </ul>
    116 
    117 <h3> <a name="sha256"></a>
    118 SHA256 </h3>
    119 
    120 <pre>
    121   SHA256Schedule ctx ;
    122   char const *message ;
    123   size_t messagelen ;
    124   char digest[32] ;
    125 
    126   sha256_init(&amp;ctx) ;
    127   sha256_update(&amp;ctx, message, messagelen) ;
    128   sha256_final(&amp;ctx, digest) ;
    129 </pre>
    130 
    131 <ul>
    132   <li> <tt>sha256_init()</tt> prepares a SHA256Schedule structure for computation </li>
    133   <li> <tt>sha256_update()</tt> adds <em>message</em> to the message to be digested </li>
    134   <li> <tt>sha256_final()</tt> computes the digest </li>
    135 </ul>
    136 
    137 <h3> <a name="sha512"></a>
    138 SHA512 </h3>
    139 
    140 <pre>
    141   SHA512Schedule ctx ;
    142   char const *message ;
    143   size_t messagelen ;
    144   char digest[64] ;
    145 
    146   sha512_init(&amp;ctx) ;
    147   sha512_update(&amp;ctx, message, messagelen) ;
    148   sha512_final(&amp;ctx, digest) ;
    149 </pre>
    150 
    151 <ul>
    152   <li> <tt>sha512_init()</tt> prepares a SHA512Schedule structure for computation </li>
    153   <li> <tt>sha512_update()</tt> adds <em>message</em> to the message to be digested </li>
    154   <li> <tt>sha512_final()</tt> computes the digest </li>
    155 </ul>
    156 
    157 </body>
    158 </html>