URI:
       tdes3ECB.c - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tdes3ECB.c (927B)
       ---
            1 #include "os.h"
            2 #include <mp.h>
            3 #include <libsec.h>
            4 
            5 /* I wasn't sure what to do when the buffer was not */
            6 /* a multiple of 8.  I did what lacy's cryptolib did */
            7 /* to be compatible, but it looks dangerous to me */
            8 /* since its encrypting plain text with the key. -- presotto */
            9 
           10 void
           11 des3ECBencrypt(uchar *p, int len, DES3state *s)
           12 {
           13         int i;
           14         uchar tmp[8];
           15 
           16         for(; len >= 8; len -= 8){
           17                 triple_block_cipher(s->expanded, p, DES3EDE);
           18                 p += 8;
           19         }
           20 
           21         if(len > 0){
           22                 for (i=0; i<8; i++)
           23                         tmp[i] = i;
           24                 triple_block_cipher(s->expanded, tmp, DES3EDE);
           25                 for (i = 0; i < len; i++)
           26                         p[i] ^= tmp[i];
           27         }
           28 }
           29 
           30 void
           31 des3ECBdecrypt(uchar *p, int len, DES3state *s)
           32 {
           33         int i;
           34         uchar tmp[8];
           35 
           36         for(; len >= 8; len -= 8){
           37                 triple_block_cipher(s->expanded, p, DES3DED);
           38                 p += 8;
           39         }
           40 
           41         if(len > 0){
           42                 for (i=0; i<8; i++)
           43                         tmp[i] = i;
           44                 triple_block_cipher(s->expanded, tmp, DES3EDE);
           45                 for (i = 0; i < len; i++)
           46                         p[i] ^= tmp[i];
           47         }
           48 }