home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / CRYP60.ZIP / CRYP.DOC < prev    next >
Encoding:
Text File  |  1992-11-20  |  15.8 KB  |  366 lines

  1.  
  2.  
  3.                           Data Encryption
  4.                            Fast & Secure
  5.  
  6.                       ──────────────────────
  7.                The algorithm for the Data Encryption
  8.             Standard runs too slow on most micros, but
  9.              simpler methods have not provided secure
  10.                encryption. This program solves this
  11.               problem by being both fast and secure.
  12.                       ──────────────────────
  13.  
  14.                          by Harry J. Smith
  15.  
  16. The Data Encryption Standard, DES (1), though normally considered
  17. a very secure form of encryption, has a very complicated algorithm
  18. (2) and runs very slow when implemented on a micro computer. The
  19. program CRYPT (3) as implemented on most systems that use the UNIX
  20. operating system is quite fast, but is not a very secure form of
  21. data encryption. The data encryption program CRYP presented here
  22. attempts to be even more secure than DES by using a larger and
  23. more random key, and at the same time is reasonably fast.
  24.  
  25. The program TNT (4) is a good example of a data encryption method
  26. that has attempted to be both fast and secure but it too is about
  27. 10 to 20 times more complicated, as measured by program execution
  28. time, than the method presented here. This forces TNT to be
  29. written in assembly language to be practical. CRYP was written in
  30. a high order language and is about 4.5 times faster, exclusive of
  31. I/O time, than TNT written in assembly language.
  32.  
  33. Another article (5) contained encryption programs that were fast
  34. and were written in a high order language, but they used the same
  35. encryption key over and over again for the same input key. If one
  36. enciphered message were ever compromised then any other message
  37. which used the same input key would no longer be secure with this
  38. method.
  39.  
  40. Basic Method Used
  41. An alphanumeric key, input by the operator of the program, is
  42. converted into nine 16-bit seeds for nine different random number
  43. generators. The output of the nine generators are combined to
  44. generate a random sequence of bits of about 3.55 * 10**44 bits
  45. long (approximately 2**148 bits). This sequence of bits is then
  46. used as a pseudo infinite key and is exclusive-ORed with the bits
  47. of the data file to produce the data for the enciphered file.
  48.  
  49. Processing the Key
  50. The characters of the key input by the operator are converted to
  51. a standard form containing only 63 different characters. Lower
  52. case letters are converted to upper case and control characters
  53. are converted to the special characters and the numbers. The space
  54. character is changed to a '/' so the standard form will never
  55. contain a space. This is done because it may be difficult on some
  56. systems to input a space character in an argument on the command
  57. line.
  58.  
  59. A key of 24 characters is needed. If the input key is longer than
  60. 24 characters, it is hashed into a 24 character key. For the first
  61. 24 characters, each character is increased by the sum of all
  62. characters that precede it. For the 25 character on, each charac-
  63. ter is increased by the sum of all characters that follow it. Then
  64. characters in the same position modulo 24 are then added together
  65. to make the key 24 characters long. The summing of characters is
  66. done arithmetically modulo 256.
  67.  
  68. If the key is shorter than 24 characters, trailing '/' are
  69. appended to make it 24 characters. The 24-character key is also
  70. converted to the standard form. Only the 6 least significant bits
  71. of each of the 24 key characters are used to generate the seeds
  72. for the random number generators.
  73.  
  74. Continuation File
  75. In order to make this method an infinite key encryption system (4)
  76. a continuation file, CRY.CON, is maintained by the program. This
  77. file contains one record of 18 bytes from the random number
  78. generators. Each time a file is enciphered, the continuation file
  79. is read, its 18 bytes are exclusive-ORed with the 18 bytes of the
  80. bits from the encryption key to produce the starting seeds for the
  81. 9 random number generators. The continuation file is also output
  82. as the first 18 bytes of the enciphered file. After the input file
  83. is enciphered the continuation file is updated by reseeding the
  84. random number generators with the 18 bytes of the continuation
  85. file and the next 4096 bytes from the generators are stored in a
  86. pool of random numbers in reverse order. Each 16 bits stored is
  87. the sum of 9 random integers, one from each generator, truncated
  88. to the lower 16 bits. The first 18 bytes of this pool is then
  89. written to the continuation file.
  90.  
  91. There is an option in CRYP to initialize the continuation file.
  92. When this option is selected the encryption key is used directly
  93. to seed the random number generators and 18 bytes output from the
  94. generators, as described above, are stored in the continuation
  95. file. The key used to initialize the continuation file should not
  96. be the same key used to encrypt data files.
  97.  
  98. The use of the continuation file does not cause each file enci-
  99. phering to start up with the pseudo infinite key exactly where it
  100. left off, but causes it to start up at a random point in its
  101. extremely long periodic cycle. It is impractical to try to start
  102. up where the previous file left off because the pool of 2048
  103. random integers, described shortly, would have to be save and
  104. protected between runs. Starting up at a random point and reiniti-
  105. alizing the pool for each file is a better method.
  106.  
  107. The Random Number Generators
  108. The nine random number generators were chosen very carefully and
  109. have been tested to ensure they each produce the proper number of
  110. random integers before they cycle and start reproducing the same
  111. sequence all over again. Four of the generators are Congruential
  112. generators (6) and five of them are Shift-register generators (7).
  113. This was done to prevent the problems that can arise when only one
  114. type of generator is used (7). The generators were chosen so their
  115. periods would be relatively prime to each other (65536, 65535,
  116. 65537, 65521, 65519, 65497, 65479, 65449 and 65447 respectively).
  117. This was done to produce a very long resulting period in the
  118. pseudo infinite key. The pseudo infinite key is generated in
  119. 16-bit increments by a combination of exclusive-ORing and arithme-
  120. tic addition of the output of the nine random number generators.
  121.  
  122. The Pseudo Infinite Key
  123. After the seeds of the 9 generators are established, each genera-
  124. tor is called once and the sum of the 9 integers generated,
  125. truncated to 16 bits, is used to initialize rr, the running random
  126. integer. This rr is normally updated by adding, and truncating to
  127. 16 bits, the next output of the next generator, cycling the
  128. generators 0 through 8 and repeating. Thus, only one call to one
  129. generator is needed to get 16 more bits for the basic random bit
  130. sequence.
  131.  
  132. Next the pool of 2048 random integers is initialized. This is done
  133. by storing consecutive values of rr generated as just described.
  134. After this rr is recomputed by calling each generator once and
  135. summing the 9 integers generated as before. This makes rr indepen-
  136. dent from any integer in the pool.
  137.  
  138. Now we are ready to start generating bits of the pseudo infinite
  139. key. The next 16 bits of this key is always generated by:
  140.  
  141. 1) Use the lower 11 bits of rr as a relative index into the pool.
  142.  
  143. 2) Use the integer at this position in the pool as the next 16
  144. bits of the pseudo infinite key.
  145.  
  146. 3) Update rr by adding the output of the next generator to rr and
  147. keep the lower 16 bits.
  148.  
  149. 4) Replace the integer just used in the pool with the exclusive-OR
  150. of itself and rr (do not change rr).
  151.  
  152. This process causes the pseudo infinite key to be a very compli-
  153. cated function of the output of the 9 random number generators,
  154. but is a simple process to program and execute.
  155.  
  156. One criticism of this method might be that it is a substitution
  157. cipher only and that a combination of a transposition and substi-
  158. tution produces the strongest cipher schemes. The normal transpo-
  159. sition process is what makes the TNT program run so slow. In a
  160. sense CRYP does have a transposition process but it is a transpo-
  161. sition in the pseudo infinite key instead of in the text.
  162.  
  163. Process Overview
  164. In order to understand the method better, outlines of the three
  165. options of the program are given:
  166.  
  167. Encipher Process-
  168.  
  169. 1) Process key from operator.
  170. 2) Read continuation file.
  171. 3) Copy continuation file to output file.
  172. 4) Initialize random number seeds.
  173. 5) Fill random number pool.
  174. 6) Read, encrypt, write input file to output file.
  175. 7) Restore random number seeds from continuation file.
  176. 8) Build and write random record to continuation file.
  177.  
  178. Decipher Process-
  179.  
  180. 1) Process key from operator.
  181. 2) Read first 18 bytes of input file.
  182. 3) Initialize random number seeds.
  183. 4) Fill random number pool.
  184. 5) Read, encrypt, write input file to output file.
  185.  
  186. Initialize Continuation file-
  187.  
  188. 1) Process key from operator.
  189. 2) Initialize random number seeds.
  190. 3) Build and write random record to continuation file.
  191.  
  192. Timing Data
  193. A file of 128K bytes of all zeros was generated using DEBUG, and
  194. COPY in the following way:
  195.  
  196.    A:\>DEBUG
  197.    -FCS:100,L,8000,0
  198.    -RCX
  199.    CX xxxx
  200.    :8000
  201.    -RBX
  202.    BX xxxx
  203.    :0
  204.    -NA:Z
  205.    -W
  206.    Writing 08000 bytes
  207.    -Q
  208.  
  209.    A:\>COPY /B Z+Z+Z+Z Z128K
  210.    Z
  211.    Z
  212.    Z
  213.    Z
  214.    1 File(s) copied
  215.  
  216. This file was then enciphered on a hard disk drive in 6.2 seconds
  217. and then deciphered in 9.4 seconds. The system used was a 386 AT
  218. clone running MS DOS 3.3 at a clock rate of 8 MHz.
  219.  
  220. Randomness Testing
  221. The 128k file of all zero described above was enciphered four
  222. different times and a Chi-square test applied to each enciphered
  223. file. The Chi-squared statistic generated was 232.8, 294.8, 304.5
  224. and 225.9. For a Chi-square test with 255 degrees of freedom as
  225. this test is, the Chi-square statistic has a median value of 254.3
  226. and should be between 200.6 and 316.9, 99% of the time and between
  227. 219.0 and 293.2, 90% of the time.
  228.  
  229. Twenty-four Chi-square tests were run on other encipherings of the
  230. all zero file, taking 5120 byte blocks of data per test. The
  231. maximum Chi-square was 291.3, the minimum Chi-square was 198.8 and
  232. the average was 254.7. On these 24 runs the mean, second, third,
  233. and fourth moments of the distribution of the value of the bytes
  234. were also calculated with no significant deviation from their
  235. theoretical values.
  236.  
  237. Operating the program
  238. This program is written in C and all operator input comes from the
  239. DOS command line. The format of the command to execute CRYP can be
  240. found by executing CRYP with no parameters. The output to the
  241. screen in this case is:
  242.  
  243.    CRYP - A data encryption system written in C, with pipes
  244.    Version 6.00, 1992-11-15, 1400 hours
  245.    Copyright (c) 1987-1992 by author: Harry J. Smith
  246.  
  247.      usage: CRYP key [D/I] [<infile] [>outfile]
  248.        D = Decipher
  249.        I = Init CRY.CON file using key and exit
  250.        default = Encipher and update CRY.CON file
  251.  
  252. The key parameter is a string of any length the system supports,
  253. but probably not more than 72 characters. If the key is the only
  254. parameter given, then the standard input is encrypted and output
  255. to the standard output. The [D/I] parameter is an optional field.
  256. When it is present and is the single character D or d the input is
  257. deciphered instead of enciphered. When the [D/I] parameter is the
  258. single character I or i the continuation file is initialized. The
  259. same key that is used to encipher a file must be used to decipher
  260. it, but should not be used to initialize the continuation file.
  261.  
  262. A file can be enciphered twice with the same or different keys and
  263. then deciphered by deciphering twice using the keys in the reverse
  264. order. This double encryption is not recommended since CRYP is
  265. very secure with only one encryption.
  266.  
  267. Choosing a key
  268. If you are serious about protecting the information contained in
  269. your file, the encryption key should be chosen carefully, and of
  270. course it also needs to be protected. A key of FEBRUARY is a poor
  271. choice because if a few characters can be determined the rest can
  272. be guessed. A short key such as ASDF is bad because if the key
  273. space is searched in lexicographic order the key will be found in
  274. less than 2**24 tries.
  275.  
  276. A good scheme for choosing a key is to make up a phrase that makes
  277. no special sense but is at least 48 characters long. When this key
  278. is converted to the 24-character key the characters will look
  279. random. For example, the eight input keys:
  280.  
  281.    1) YOU/SHOULD/MAKE/YOUR/KEYS/AT/LEAST/48/CHARACTERS
  282.    2) TRY/TO/MAKE/YOUR/KEYS/EASY/TO/REMEMBER/BUT/HARD/TO/BREAK
  283.    3) THE/WIND/BLOWS/THE/SNOW/FALLS/IT/WILL/NOT/BE/HOT
  284.    4) A/NEST/IS/A/HOME/IF/YOU/ARE/A/BIRD/BUT/I/LIKE/MINE
  285.    5) ROSE/HAS/HAD/TOO/MUCH/SAID/I/HAVE/NOTHING/TO/ADD
  286.    6) ROPE/IT/CAN/BE/LONG/IT/CAN/BE/SHORT/BUT/NOT/FOR/ME
  287.    7) EAGLE/WHAT/A/BIRD/IF/I/COULD/FLY/WOULD/BE/ONE/TOO
  288.    8) BOOK/READ/ONE/TO/ME/READ/ONE/MYSELF/BUT/NOT/TO/YOU
  289.  
  290. produce the following eight 24-character keys:
  291.  
  292.    1) B>DRQJM](YTR_2(4%36G3**1
  293.    2) U/1"@N)C422T+58;(>/9D2%"
  294.    3) IKOR]SRMH[PVAHHNGXXIR2!!
  295.    4) *J!!%88?I&##)#<282,2/*P2
  296.    5) :@OEKD]OHK]S33:@!'M<55GD
  297.    6) Y:W-Z^#_ZLHCVY3+KKC>8F&7
  298.    7) $'99::+'/4,^XNSVXB\STXXG
  299.    8) ._*'14,4%ORZ0]\WWVLGJ[MB
  300.  
  301. respectively. The long form of the key is easier to remember and
  302. easier to type, the short form is more random and harder to crack.
  303.  
  304. How Secure is the Method?
  305. The search space is about 2**144 keys. An extremely powerful
  306. computer would be needed to search and find the key in a timely
  307. manner. If 10**14 processors could each test 10**14 different keys
  308. per second it would take about 10**7 years to find a randomly
  309. selected key.
  310.  
  311. If there is a flaw in this method it would be that a chunk of the
  312. pseudo key, if it were exposed, could be used to determine the
  313. value of the seeds used to produce it. This seams totally impossi-
  314. ble because the process of generating the pseudo infinite key
  315. appears to be quite irreversible, but this is not proven. Thus, it
  316. is still necessary to change the input key periodically.
  317.  
  318. Pascal version
  319. An interactive user interface version of this program, CRYU, was
  320. developed using TURBO Pascal. Tests were performed to insure that
  321. a file can be enciphered with one of the programs and then
  322. deciphered with the other program. The running time of the two
  323. programs are essentially the same.
  324.  
  325. C Named files version
  326. A C version CRYN that uses files names on the command line instead
  327. of pipes was also developed. The format of the command to execute
  328. CRYN can be found by executing CRYN with no parameters. The output
  329. to the screen in this case is:
  330.  
  331.    CRYN - A data encryption system written in C, named files
  332.    Version 6.00, 1992-11-15, 1400 hours
  333.    Copyright (c) 1987-1992 by author: Harry J. Smith
  334.  
  335.    usage: CRYN key [infile outfile [D]]
  336.      key only => Init CRY.CON file using key and exit
  337.          no D => Encipher and update CRY.CON file
  338.             D => Decipher
  339.  
  340. In all versions of the of the program, if a key is given which is
  341. a file name, then the first line of the file is used as the key.
  342.  
  343. Notes
  344. 1. Data Encryption Standard, U. S. Department of Commerce,
  345. National Bureau of standards, FIPS Publication 46, 1977 January
  346. 15.
  347. 2. Katzan, H. The Standard Data Encryption Algorithm. New York:
  348. Petrocelli Books, 1977.
  349. 3. Kernighan, B., and Plauger, P. Software Tools. Reading, Mass.:
  350. Addison-Wesley, 1976.
  351. 4. Thomas, J., and Thersites, J. "Designing a File Encryption
  352. System", Dr.Dobb's Journal (August 1984): 44-53.
  353. 5.Scacchitti, F. E., "The Cryptographer's Toolbox", Dr. Dobb's
  354. Journal (May 1986): 58-64.
  355. 6. Knuth, D. E. The Art of Computer Programming, vol. 2, Seminu-
  356. merical Algorithms. Reading, Mass.: Addison-Wesley, 1968.
  357. 7. Ralston, A. Encyclopedia of Computer Science, First Edition,
  358. "Random Number Generation", New York: Van Nostrand Reinhold, 1976.
  359. 8. Stout, R. B., "S-CODER for Data Encryption" Dr. Dobb's Journal
  360. (Jan 1990): 52-58.
  361.  
  362.                           Harry J. Smith
  363.                         19628 Via Monte Dr.
  364.                         Saratoga, CA 95070
  365.                           (408) 741-0406
  366.