des.3 (3525B)
1 .TH DES 3 2 .SH NAME 3 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 4 .SH SYNOPSIS 5 .B #include <u.h> 6 .br 7 .B #include <libc.h> 8 .br 9 .B #include <mp.h> 10 .br 11 .B #include <libsec.h> 12 .PP 13 .B 14 void des_key_setup(uchar key[8], ulong schedule[32]) 15 .PP 16 .B 17 void block_cipher(ulong *schedule, uchar *data, 18 .B 19 int decrypting) 20 .PP 21 .B 22 void setupDESstate(DESstate *s, uchar key[8], uchar *ivec) 23 .PP 24 .B 25 void desCBCencrypt(uchar*, int, DESstate*) 26 .PP 27 .B 28 void desCBCdecrypt(uchar*, int, DESstate*) 29 .PP 30 .B 31 void desECBencrypt(uchar*, int, DESstate*) 32 .PP 33 .B 34 void desECBdecrypt(uchar*, int, DESstate*) 35 .PP 36 .B 37 void triple_block_cipher(ulong keys[3][32], uchar*, int) 38 .PP 39 .B 40 void setupDES3state(DES3state *s, uchar key[3][8], 41 .B 42 uchar *ivec) 43 .PP 44 .B 45 void des3CBCencrypt(uchar*, int, DES3state*) 46 .PP 47 .B 48 void des3CBCdecrypt(uchar*, int, DES3state*) 49 .PP 50 .B 51 void des3ECBencrypt(uchar*, int, DES3state*) 52 .PP 53 .B 54 void des3ECBdecrypt(uchar*, int, DES3state*) 55 .PP 56 .B 57 void key_setup(uchar[7], ulong[32]) 58 .PP 59 .B 60 void des56to64(uchar *k56, uchar *k64) 61 .PP 62 .B 63 void des64to56(uchar *k64, uchar *k56) 64 .SH DESCRIPTION 65 .PP 66 The Digital Encryption Standard (DES) 67 is a shared key or symmetric encryption using either 68 a 56 bit key for single DES or three 56 bit keys for triple des. 69 The keys are encoded into 64 bits where every eight bit 70 is parity. 71 .PP 72 The basic DES function, 73 .IR block_cipher , 74 works on a block of 8 bytes, converting them in place. 75 It takes a key schedule, a pointer to the block, and 76 a flag indicating encrypting (0) or decrypting (1). 77 The key schedule is created from the key using 78 .IR des_key_setup . 79 .PP 80 Since it is a bit awkward, 81 .I block_cipher 82 is rarely called directly. Instead, one normally uses 83 routines that encrypt larger buffers of data and 84 which may chain the encryption state from one buffer 85 to the next. 86 These routines keep track of the state of the 87 encryption using a 88 .B DESstate 89 structure that contains the key schedule and any chained 90 state. 91 .I SetupDESstate 92 sets up the 93 .B DESstate 94 structure using the key and an 8 byte initialization vector. 95 .PP 96 Electronic code book, using 97 .I desECBencrypt 98 and 99 .IR desECBdecrypt , 100 is the less secure mode. The encryption of each 8 bytes 101 does not depend on the encryption of any other. 102 Hence the encryption is a substitution 103 cipher using 64 bit characters. 104 .PP 105 Cipher block chaining mode, using 106 .I desCBCencrypt 107 and 108 .IR desCBCdecrypt , 109 is more secure. Every block encrypted depends on the initialization 110 vector and all blocks encrypted before it. 111 .PP 112 For both CBC and ECB modes, a stream of data can be encrypted as 113 multiple buffers. However, all buffers except the last must 114 be a multiple of 8 bytes to ensure successful decryption of 115 the stream. 116 .PP 117 There are equivalent triple DES functions for each of the 118 DES functions. 119 .PP 120 In the past Plan 9 used a 56 bit or 7 byte 121 format for DES keys. To be compatible with the rest 122 of the world, we've abandoned this format. 123 There are two functions: 124 .I des56to64 125 and 126 .I des64to56 127 to convert back and forth between the two formats. 128 Also a key schedule can be set up from the 7 byte format 129 using 130 .IR key_setup . 131 .PP 132 .SH SOURCE 133 .B \*9/src/libsec 134 .SH SEE ALSO 135 .MR mp (3) , 136 .MR aes (3) , 137 .MR blowfish (3) , 138 .MR dsa (3) , 139 .MR elgamal (3) , 140 .MR rc4 (3) , 141 .MR rsa (3) , 142 .MR sechash (3) , 143 .MR prime (3) , 144 .MR rand (3)