home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1997 December / Internet_Info_CD-ROM_Walnut_Creek_December_1997.iso / drafts / draft_n_r / draft-rivest-rc2desc-00.txt < prev    next >
Text File  |  1997-06-24  |  9KB  |  269 lines

  1.  
  2. Internet Draft                      Ron Rivest
  3. draft-rivest-rc2desc-00.txt         RSA Data Security, Inc.
  4. Created 1987
  5. Revised March 12, 1992
  6. Revised June 23, 1997               Expires December 22, 1997
  7.  
  8.            A Description of the RC2(r) Encryption Algorithm
  9.  
  10. Status of this memo
  11.  
  12. This document is an Internet-Draft. Internet-Drafts are working
  13. documents of the Internet Engineering Task Force (IETF), its areas,
  14. and its working groups. Note that other groups may also distribute
  15. working documents as Internet-Drafts.
  16.  
  17. Internet-Drafts are draft documents valid for a maximum of six months
  18. and may be updated, replaced, or obsoleted by other documents at any
  19. time. It is inappropriate to use Internet-Drafts as reference material
  20. or to cite them other than as "work in progress."
  21.  
  22. To learn the current status of any Internet-Draft, please check the
  23. "1id-abstracts.txt" listing contained in the Internet-Drafts Shadow
  24. Directories on ftp.is.co.za (Africa), nic.nordu.net (Europe),
  25. munnari.oz.au (Pacific Rim), ds.internic.net (US East Coast), or
  26. ftp.isi.edu (US West Coast).
  27.  
  28.  
  29. 1. Introduction
  30.  
  31. This draft is an RSA Laboratories Technical Note. It is meant for
  32. informational use by the Internet community.
  33.  
  34. This memo describes a conventional (secret-key) block encryption
  35. algorithm, called RC2, which may be considered as a proposal for a DES
  36. replacement. The input and output block sizes are 64 bits each. The
  37. key size is variable, from one byte up to 128 bytes, although the
  38. current implementation uses eight bytes.
  39.  
  40. The algorithm is designed to be easy to implement on 16-bit
  41. microprocessors. On an IBM AT, the encryption runs about twice as fast
  42. as DES (assuming that key expansion has been done).
  43.  
  44. 1.1 Algorithm description
  45.  
  46. We use the term "word" to denote a 16-bit quantity. The symbol + will
  47. denote twos-complement addition. The symbol & will denote the bitwise
  48. "and" operation. The term XOR will denote the bitwise "exclusive-or"
  49. operation. The symbol ~ will denote bitwise complement.  The symbol ^
  50. will denote the exponentiation operation.  The term MOD will denote
  51. the modulo operation.
  52.  
  53. There are three separate algorithms involved:
  54.  
  55.    Key expansion. This takes a (variable-length) input key and
  56.    produces an expanded key consisting of 64 words K[0], ..., K[63].
  57.  
  58.    Encryption. This takes a 64-bit input quantity stored in words
  59.    R[0], ..., R[3] and encrypts it "in place" (the result is left in
  60.    R[0], ..., R[3]).
  61.  
  62.    Decryption. The inverse operation to encryption. (This will not be
  63.    described, since it is merely the inverse operation.)
  64.  
  65.  
  66. 2. Key expansion
  67.  
  68. Since we will be dealing with eight-bit byte operations as well
  69. as 16-bit word operations, we will use two alternative notations
  70. for referring to the key buffer:
  71.  
  72.      For word operations, we will refer to the positions of the
  73.           buffer as K[0], ..., K[63]; each K[i] is a 16-bit word.
  74.           
  75.      For byte operations,  we will refer to the key buffer as
  76.           L[0], ..., L[127]; each L[i] is an eight-bit byte.
  77.           
  78. These are alternative views of the same data buffer. At all times
  79. it will be true that
  80.  
  81.               K[i] = L[2*i] + 256*L[2*i+1].
  82.  
  83. (Note that the low-order byte of each K word is given before the
  84. high-order byte.)
  85.  
  86. We will assume that exactly T bytes of key are supplied, for some
  87. T in the range 1 <= T <= 128. (Our current implementation uses T
  88. = 8.) However, regardless of T, the algorithm has a maximum
  89. effective key length in bits, denoted T1. That is, the search
  90. space is 2^(8*T), or 2^T1, whichever is smaller.
  91.  
  92. The purpose of the key-expansion algorithm is to modify the key
  93. buffer so that each bit of the expanded key depends in a
  94. complicated way on every bit of the supplied input key.
  95.  
  96. The key expansion algorithm begins by placing the supplied T-byte
  97. key into bytes L[0], ..., L[T-1] of the key buffer.
  98.  
  99. The key expansion algorithm then computes the effective key
  100. length in bytes T8 and a mask TM based on the effective key
  101. length in bits T1. It uses the following operations:
  102.  
  103. T8 = (T1+7)/8;
  104. TM = 255 MOD 2^(8 + T1 - 8*T8);
  105.  
  106. Thus TM has its 8 - (8*T8 - T1) least significant bits set.
  107.  
  108. For example, with an effective key length of 64 bits, T1 = 64,
  109. T8 = 8 and TM = 0xff.  With an effective key length of 63 bits,
  110. T1 = 63, T8 = 8 and TM = 0x7f.
  111.  
  112. Here PITABLE[0], ..., PITABLE[255] is an array of "random" bytes
  113. based on the digits of PI = 3.14159... . More precisely, the array
  114. PITABLE is a random permutation of the values 0, ..., 255. Here is
  115. the PITABLE in hexadecimal notation:
  116.  
  117.      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
  118. 00: d9 78 f9 c4 19 dd b5 ed 28 e9 fd 79 4a a0 d8 9d
  119. 10: c6 7e 37 83 2b 76 53 8e 62 4c 64 88 44 8b fb a2
  120. 20: 17 9a 59 f5 87 b3 4f 13 61 45 6d 8d 09 81 7d 32
  121. 30: bd 8f 40 eb 86 b7 7b 0b f0 95 21 22 5c 6b 4e 82
  122. 40: 54 d6 65 93 ce 60 b2 1c 73 56 c0 14 a7 8c f1 dc
  123. 50: 12 75 ca 1f 3b be e4 d1 42 3d d4 30 a3 3c b6 26
  124. 60: 6f bf 0e da 46 69 07 57 27 f2 1d 9b bc 94 43 03
  125. 70: f8 11 c7 f6 90 ef 3e e7 06 c3 d5 2f c8 66 1e d7
  126. 80: 08 e8 ea de 80 52 ee f7 84 aa 72 ac 35 4d 6a 2a
  127. 90: 96 1a d2 71 5a 15 49 74 4b 9f d0 5e 04 18 a4 ec
  128. a0: c2 e0 41 6e 0f 51 cb cc 24 91 af 50 a1 f4 70 39
  129. b0: 99 7c 3a 85 23 b8 b4 7a fc 02 36 5b 25 55 97 31
  130. c0: 2d 5d fa 98 e3 8a 92 ae 05 df 29 10 67 6c ba c9
  131. d0: d3 00 e6 cf e1 9e a8 2c 63 16 01 3f 58 e2 89 a9
  132. e0: 0d 38 34 1b ab 33 ff b0 bb 48 0c 5f b9 b1 cd 2e
  133. f0: c5 f3 db 47 e5 a5 9c 77 0a a6 20 68 fe 7f c1 ad
  134.  
  135. The key expansion operation consists of the following two loops
  136. and intermediate step:
  137.  
  138. for i = T, T+1, ..., 127 do
  139.   L[i] = PITABLE[L[i-1] + L[i-T]];
  140.  
  141. L[128-T8] = PITABLE[L[128-T8] & TM];
  142.  
  143. for i = 127-T8, ..., 0 do
  144.   L[i] = PITABLE[L[i+1] XOR L[i+T8]];
  145.  
  146. (In the first loop, the addition of L[i-1] and L[i-T] is
  147. performed modulo 256.)
  148.  
  149. The "effective key" consists of the values L[128-T8], ..., L[127].
  150. The intermediate step's bitwise "and" operation reduces the
  151. search space for L[128-T8] so that the effective number of key
  152. bits is T1. The expanded key depends only on the effective key
  153. bits, regardless of the supplied key K. Since the expanded key is
  154. not itself modified during encryption or decryption, as a
  155. pragmatic matter one can expand the key just once when encrypting
  156. or decrypting a large block of data.
  157.  
  158.  
  159. 3. Encryption algorithm
  160.  
  161. The encryption operation is defined in terms of primitive "mix"
  162. and "mash" operations.
  163.  
  164. Here the expression "x rol k" denotes the 16-bit word x rotated
  165. left by k bits, with the bits shifted out the top end entering
  166. the bottom end.
  167.  
  168. 3.1 Mix up R[i]
  169.  
  170. The primitive "Mix up R[i]" operation is defined as follows,
  171. where s[0] is 1, s[1] is 2, s[2] is 3, and s[3] is 5, and where
  172. the indices of the array R are always to be considered "modulo
  173. 4," so that R[i-1] refers to R[3] if i is 0 (these values a
  174. "wrapped around" so that R always has a subscript in the range 0
  175. to 3 inclusive):
  176.  
  177. R[i] = R[i] + K[j] + (R[i-1] & R[i-2]) + ((~R[i-1]) & R[i-3]);
  178. j = j + 1;
  179. R[i] = R[i] rol s[i];
  180.  
  181. In words: The next key word K[j] is added to R[i], and j is
  182. advanced. Then R[i-1] is used to create a "composite" word which
  183. is added to R[i]. The composite word is identical with R[i-2] in
  184. those positions where R[i-1] is one, and identical to R[i-3] in
  185. those positions where R[i-1] is zero. Then R[i] is rotated left
  186. by s[i] bits (bits rotated out the left end of R[i] are brought
  187. back in at the right). Here j is a "global" variable so that K[j]
  188. is always the first key word in the expanded key which has not
  189. yet been used in a "mix" operation.
  190.  
  191. 3.2 Mixing round
  192.  
  193. A "mixing round" consists of the following operations:
  194.  
  195. Mix up R[0]
  196. Mix up R[1]
  197. Mix up R[2]
  198. Mix up R[3]
  199.  
  200. 3.3 Mash R[i]
  201.  
  202. The primitive "Mash R[i]" operation is defined as follows (using
  203. the previous conventions regarding subscripts for R):
  204.  
  205. R[i] = R[i] + K[R[i-1] & 63];
  206.  
  207. In words: R[i] is "mashed" by adding to it one of the words of
  208. the expanded key. The key word to be used is determined by
  209. looking at the low-order six bits of R[i-1], and using that as an
  210. index into the key array K.
  211.  
  212. 3.4 Mashing round
  213.  
  214. A "mashing round" consists of:
  215.  
  216. Mash R[0]
  217. Mash R[1]
  218. Mash R[2]
  219. Mash R[3]
  220.  
  221. 3.5 Encryption operation
  222.  
  223. The entire encryption operation can now be described as follows.
  224. Here j is a global integer variable which is affected by the
  225. mixing operations.
  226.  
  227.      1. Initialize words R[0], ..., R[3] to contain the 64-bit input
  228.         value.
  229.  
  230.      2. Expand the key, so that words K[0], ..., K[63] become
  231.         defined.
  232.  
  233.      3. Initialize j to zero.
  234.  
  235.      4. Perform five mixing rounds.
  236.  
  237.      5. Perform one mashing round.
  238.  
  239.      6. Perform six mixing rounds.
  240.  
  241.      7. Perform one mashing round.
  242.  
  243.      8. Perform five mixing rounds.
  244.  
  245. Note that each mixing round uses four key words, and that there
  246. are 16 mixing rounds altogether, so that each key word is used
  247. exactly once in a mixing round. The mashing rounds will refer to
  248. up to eight of the key words in a data-dependent manner. (There
  249. may be repetitions, and the actual set of words referred to will
  250. vary from encryption to encryption.)
  251.  
  252.  
  253. A. Intellectual Property Notice
  254.  
  255. RC2 is a registered trademark of RSA Data Security, Inc. RSA's
  256. copyrighted RC2 software is available under license from RSA
  257. Data Security, Inc.
  258.  
  259.  
  260. B. Author's Address
  261.  
  262. Ron Rivest
  263. RSA Laboratories
  264. 100 Marine Parkway, #500      
  265. Redwood City, CA  94065  USA  
  266. (415) 595-8782
  267. rsa-labs@rsa.com
  268.  
  269.