home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume40 / libdes / part04 < prev    next >
Internet Message Format  |  1993-10-14  |  55KB

  1. From: eay@psych.psy.uq.oz.au (Eric Young)
  2. Newsgroups: comp.sources.misc
  3. Subject: v40i011: libdes - DES encryption library, Part04/05
  4. Date: 14 Oct 1993 18:02:03 +0100
  5. Sender: aem@aber.ac.uk
  6. Approved: aem@aber.ac.uk
  7. Message-ID: <29k0mb$1mf@uk-usenet.uk.sun.com>
  8. X-Md4-Signature: 8bef35f5ae2281ee43bbbbc760c475f4
  9.  
  10. Submitted-by: eay@psych.psy.uq.oz.au (Eric Young)
  11. Posting-number: Volume 40, Issue 11
  12. Archive-name: libdes/part04
  13. Environment: C
  14. Supersedes: libdes: Volume 29, Issue 43-46
  15.  
  16. #! /bin/sh
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  ARTISTIC FILES MODES.DES des.h des.man ecb_enc.c
  22. #   enc_read.c makefile pcbc_enc.c set_key.c speed.c str2key.c times
  23. #   vms.com
  24. # Wrapped by alecm@uk-usenet on Wed Oct 13 10:33:50 1993
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. echo If this archive is complete, you will see the following message:
  27. echo '          "shar: End of archive 4 (of 5)."'
  28. if test -f 'ARTISTIC' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'ARTISTIC'\"
  30. else
  31.   echo shar: Extracting \"'ARTISTIC'\" \(4642 characters\)
  32.   sed "s/^X//" >'ARTISTIC' <<'END_OF_FILE'
  33. X
  34. X             The "Artistic License"
  35. X
  36. X                Preamble
  37. X
  38. XThe intent of this document is to state the conditions under which a
  39. XPackage may be copied, such that the Copyright Holder maintains some
  40. Xsemblance of artistic control over the development of the package,
  41. Xwhile giving the users of the package the right to use and distribute
  42. Xthe Package in a more-or-less customary fashion, plus the right to make
  43. Xreasonable modifications.
  44. X
  45. XDefinitions:
  46. X
  47. X    "Package" refers to the collection of files distributed by the
  48. X    Copyright Holder, and derivatives of that collection of files
  49. X    created through textual modification.
  50. X
  51. X    "Standard Version" refers to such a Package if it has not been
  52. X    modified, or has been modified in accordance with the wishes
  53. X    of the Copyright Holder as specified below.
  54. X
  55. X    "Copyright Holder" is whoever is named in the copyright or
  56. X    copyrights for the package.
  57. X
  58. X    "You" is you, if you're thinking about copying or distributing
  59. X    this Package.
  60. X
  61. X    "Reasonable copying fee" is whatever you can justify on the
  62. X    basis of media cost, duplication charges, time of people involved,
  63. X    and so on.  (You will not be required to justify it to the
  64. X    Copyright Holder, but only to the computing community at large
  65. X    as a market that must bear the fee.)
  66. X
  67. X    "Freely Available" means that no fee is charged for the item
  68. X    itself, though there may be fees involved in handling the item.
  69. X    It also means that recipients of the item may redistribute it
  70. X    under the same conditions they received it.
  71. X
  72. X1. You may make and give away verbatim copies of the source form of the
  73. XStandard Version of this Package without restriction, provided that you
  74. Xduplicate all of the original copyright notices and associated disclaimers.
  75. X
  76. X2. You may apply bug fixes, portability fixes and other modifications
  77. Xderived from the Public Domain or from the Copyright Holder.  A Package
  78. Xmodified in such a way shall still be considered the Standard Version.
  79. X
  80. X3. You may otherwise modify your copy of this Package in any way, provided
  81. Xthat you insert a prominent notice in each changed file stating how and
  82. Xwhen you changed that file, and provided that you do at least ONE of the
  83. Xfollowing:
  84. X
  85. X    a) place your modifications in the Public Domain or otherwise make them
  86. X    Freely Available, such as by posting said modifications to Usenet or
  87. X    an equivalent medium, or placing the modifications on a major archive
  88. X    site such as uunet.uu.net, or by allowing the Copyright Holder to include
  89. X    your modifications in the Standard Version of the Package.
  90. X
  91. X    b) use the modified Package only within your corporation or organization.
  92. X
  93. X    c) rename any non-standard executables so the names do not conflict
  94. X    with standard executables, which must also be provided, and provide
  95. X    a separate manual page for each non-standard executable that clearly
  96. X    documents how it differs from the Standard Version.
  97. X
  98. X    d) make other distribution arrangements with the Copyright Holder.
  99. X
  100. X4. You may distribute the programs of this Package in object code or
  101. Xexecutable form, provided that you do at least ONE of the following:
  102. X
  103. X    a) distribute a Standard Version of the executables and library files,
  104. X    together with instructions (in the manual page or equivalent) on where
  105. X    to get the Standard Version.
  106. X
  107. X    b) accompany the distribution with the machine-readable source of
  108. X    the Package with your modifications.
  109. X
  110. X    c) give non-standard executables non-standard names, and clearly
  111. X    document the differences in manual pages (or equivalent), together
  112. X    with instructions on where to get the Standard Version.
  113. X
  114. X    d) make other distribution arrangements with the Copyright Holder.
  115. X
  116. X5. You may charge a reasonable copying fee for any distribution of this
  117. XPackage.  You may charge any fee you choose for support of this
  118. XPackage.  You may not charge a fee for this Package itself.  However,
  119. Xyou may distribute this Package in aggregate with other (possibly
  120. Xcommercial) programs as part of a larger (possibly commercial) software
  121. Xdistribution provided that you do not advertise this Package as a
  122. Xproduct of your own.
  123. X
  124. X6. Any programs linked with this library do not automatically fall
  125. Xunder the copyright of this Package, but belong to whomever generated
  126. Xthem, and may be sold commercially, and may be aggregated with this
  127. XPackage.
  128. X
  129. X7. The name of the Copyright Holder may not be used to endorse or promote
  130. Xproducts derived from this software without specific prior written permission.
  131. X
  132. X8. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  133. XIMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  134. XWARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  135. X
  136. X                The End
  137. X
  138. END_OF_FILE
  139.   if test 4642 -ne `wc -c <'ARTISTIC'`; then
  140.     echo shar: \"'ARTISTIC'\" unpacked with wrong size!
  141.   fi
  142.   # end of 'ARTISTIC'
  143. fi
  144. if test -f 'FILES' -a "${1}" != "-c" ; then 
  145.   echo shar: Will not clobber existing file \"'FILES'\"
  146. else
  147.   echo shar: Extracting \"'FILES'\" \(2333 characters\)
  148.   sed "s/^X//" >'FILES' <<'END_OF_FILE'
  149. X/* General stuff */
  150. XCHANGES        - Changes since the last posting to comp.sources.misc.
  151. XARTISTIC    - Copying info.
  152. XCOPYING        - Copying info.
  153. XMODES.DES    - A description of the features of the different modes of DES.
  154. XFILES        - This file.
  155. XINSTALL        - How to make things compile.
  156. XImakefile    - For use with kerberos.
  157. XREADME        - What this package is.
  158. XVERSION        - Which version this is.
  159. XKERBEROS    - Kerberos version 4 notes.
  160. Xmakefile    - The make file.
  161. Xtimes        - Some outputs from 'speed' on my local machines.
  162. Xvms.com        - For use when compiling under VMS
  163. X
  164. X/* My sunOS des(1) replacement */
  165. Xdes.c        - des(1) source code.
  166. Xdes.man        - des(1) manual.
  167. X
  168. X/* Testing and timing programs. */
  169. Xdestest.c    - Source for libdes.a test program.
  170. Xspeed.c        - Source for libdes.a timing program.
  171. Xrpw.c        - Source for libdes.a testing password reading routines.
  172. X
  173. X/* libdes.a source code */
  174. Xdes_crypt.man    - libdes.a manual page.
  175. Xdes.h        - Public libdes.a header file.
  176. Xecb_enc.c    - des_ecb_encrypt() source, this contains the basic DES code.
  177. X3ecb_enc.c    - des_3ecb_encrypt() source.
  178. Xcbc_ckm.c    - des_cbc_cksum() source.
  179. Xcbc_enc.c    - des_cbc_encrypt() source.
  180. X3cbc_enc.c    - des_3cbc_encrypt() source.
  181. Xcfb_enc.c    - des_cfb_encrypt() source.
  182. Xofb_enc.c    - des_cfb_encrypt() source.
  183. Xenc_read.c    - des_enc_read() source.
  184. Xenc_writ.c    - des_enc_write() source.
  185. Xpcbc_enc.c    - des_pcbc_encrypt() source.
  186. Xqud_cksm.c    - quad_cksum() source.
  187. Xrand_key.c    - des_random_key() source.
  188. Xread_pwd.c    - Source for des_read_password() plus related functions.
  189. Xset_key.c    - Source for des_set_key().
  190. Xstr2key.c    - Covert a string of any length into a key.
  191. Xfcrypt.c    - A small, fast version of crypt(3).
  192. Xdes_locl.h    - Internal libdes.a header file.
  193. Xpodd.h        - Odd parity tables - used in des_set_key().
  194. Xsk.h        - Lookup tables used in des_set_key().
  195. Xspr.h        - What is left of the S tables - used in ecb_encrypt().
  196. X
  197. X/* The perl scripts - you can ignore these files they are only
  198. X * included for the curious */
  199. Xdes.pl        - des in perl anyone? des_set_key and des_ecb_encrypt
  200. X          both done in a perl library.
  201. Xtestdes.pl    - Testing program for des.pl
  202. XdoIP        - Perl script used to develop IP xor/shift code.
  203. XdoPC1        - Perl script used to develop PC1 xor/shift code.
  204. XdoPC2        - Generates sk.h.
  205. XPC1        - Output of doPC1 should be the same as output from PC1.
  206. XPC2        - used in development of doPC2.
  207. Xshifts.pl    - Perl library used by my perl scripts.
  208. X
  209. END_OF_FILE
  210.   if test 2333 -ne `wc -c <'FILES'`; then
  211.     echo shar: \"'FILES'\" unpacked with wrong size!
  212.   fi
  213.   # end of 'FILES'
  214. fi
  215. if test -f 'MODES.DES' -a "${1}" != "-c" ; then 
  216.   echo shar: Will not clobber existing file \"'MODES.DES'\"
  217. else
  218.   echo shar: Extracting \"'MODES.DES'\" \(4262 characters\)
  219.   sed "s/^X//" >'MODES.DES' <<'END_OF_FILE'
  220. XModes of DES
  221. XQuite a bit of the following information has been taken from
  222. X    AS 2805.5.2
  223. X    Australian Standard
  224. X    Electronic funds transfer - Requirements for interfaces,
  225. X    Part 5.2: Modes of operation for an n-bit block cipher algorithm
  226. X    Appendix A
  227. X
  228. XThere are several different modes in which DES can be used, they are
  229. Xas follows.
  230. X
  231. XElectronic Codebook Mode (ECB) (des_ecb_encrypt())
  232. X- 64 bits are enciphered at a time.
  233. X- The order of the blocks can be rearranged without detection.
  234. X- The same plaintext block always produces the same ciphertext block
  235. X  (for the same key) making it vulnerable to a 'dictionary attack'.
  236. X- An error will only affect one ciphertext block.
  237. X
  238. XCipher Block Chaining Mode (CBC) (des_cbc_encrypt())
  239. X- a multiple of 64 bits are enciphered at a time.
  240. X- The CBC mode produces the same ciphertext whenever the same
  241. X  plaintext is encrypted using the same key and starting variable.
  242. X- The chaining operation makes the ciphertext blocks dependent on the
  243. X  current and all preceding plaintext blocks and therefore blocks can not
  244. X  be rearranged.
  245. X- The use of different starting variables prevents the same plaintext
  246. X  enciphering to the same ciphertext.
  247. X- An error will affect the current and the following ciphertext blocks.
  248. X
  249. XCipher Feedback Mode (CFB) (des_cfb_encrypt())
  250. X- a number of bits (j) <= 64 are enciphered at a time.
  251. X- The CFB mode produces the same ciphertext whenever the same
  252. X  plaintext is encrypted using the same key and starting variable.
  253. X- The chaining operation makes the ciphertext variables dependent on the
  254. X  current and all preceding variables and therefore j-bit variables are
  255. X  chained together and con not be rearranged.
  256. X- The use of different starting variables prevents the same plaintext
  257. X  enciphering to the same ciphertext.
  258. X- The strength of the CFB mode depends on the size of k (maximal if
  259. X  j == k).  In my implementation this is always the case.
  260. X- Selection of a small value for j will require more cycles through
  261. X  the encipherment algorithm per unit of plaintext and thus cause
  262. X  greater processing overheads.
  263. X- Only multiples of j bits can be enciphered.
  264. X- An error will affect the current and the following ciphertext variables.
  265. X
  266. XOutput Feedback Mode (OFB) (des_ofb_encrypt())
  267. X- a number of bits (j) <= 64 are enciphered at a time.
  268. X- The OFB mode produces the same ciphertext whenever the same
  269. X  plaintext enciphered using the same key and starting variable.  More
  270. X  over, in the OFB mode the same key stream is produced when the same
  271. X  key and start variable are used.  Consequently, for security reasons
  272. X  a specific start variable should be used only once for a given key.
  273. X- The absence of chaining makes the OFB more vulnerable to specific attacks.
  274. X- The use of different start variables values prevents the same
  275. X  plaintext enciphering to the same ciphertext, by producing different
  276. X  key streams.
  277. X- Selection of a small value for j will require more cycles through
  278. X  the encipherment algorithm per unit of plaintext and thus cause
  279. X  greater processing overheads.
  280. X- Only multiples of j bits can be enciphered.
  281. X- OFB mode of operation does not extend ciphertext errors in the
  282. X  resultant plaintext output.  Every bit error in the ciphertext causes
  283. X  only one bit to be in error in the deciphered plaintext.
  284. X- OFB mode is not self-synchronising.  If the two operation of
  285. X  encipherment and decipherment get out of synchronism, the system needs
  286. X  to be re-initialised.
  287. X- Each re-initialisation should use a value of the start variable
  288. Xdifferent from the start variable values used before with the same
  289. Xkey.  The reason for this is that an identical bit stream would be
  290. Xproduced each time from the same parameters.  This would be
  291. Xsusceptible to a ' known plaintext' attack.
  292. X
  293. XTriple ECB Mode (des_3ecb_encrypt())
  294. X- Encrypt with key1, decrypt with key2 and encrypt with key1 again.
  295. X- As for ECB encryption but increases the effective key length to 112 bits.
  296. X- If both keys are the same it is equivalent to encrypting once with
  297. X  just one key.
  298. X
  299. XTriple CBC Mode (des_3cbc_encrypt())
  300. X- Encrypt with key1, decrypt with key2 and encrypt with key1 again.
  301. X- As for CBC encryption but increases the effective key length to 112 bits.
  302. X- If both keys are the same it is equivalent to encrypting once with
  303. X  just one key.
  304. END_OF_FILE
  305.   if test 4262 -ne `wc -c <'MODES.DES'`; then
  306.     echo shar: \"'MODES.DES'\" unpacked with wrong size!
  307.   fi
  308.   # end of 'MODES.DES'
  309. fi
  310. if test -f 'des.h' -a "${1}" != "-c" ; then 
  311.   echo shar: Will not clobber existing file \"'des.h'\"
  312. else
  313.   echo shar: Extracting \"'des.h'\" \(4062 characters\)
  314.   sed "s/^X//" >'des.h' <<'END_OF_FILE'
  315. X/* des.h */
  316. X/* Copyright (C) 1993 Eric Young - see README for more details */
  317. X#ifndef DES_DEFS
  318. X#define DES_DEFS
  319. X
  320. Xtypedef unsigned char des_cblock[8];
  321. Xtypedef struct des_ks_struct
  322. X    {
  323. X    union    {
  324. X        des_cblock _;
  325. X        /* make sure things are correct size on machines with
  326. X         * 8 byte longs */
  327. X        unsigned long pad[2];
  328. X        } ks;
  329. X#define _    ks._
  330. X    } des_key_schedule[16];
  331. X
  332. X#define DES_KEY_SZ     (sizeof(des_cblock))
  333. X#define DES_ENCRYPT    1
  334. X#define DES_DECRYPT    0
  335. X
  336. X#define DES_CBC_MODE    0
  337. X#define DES_PCBC_MODE    1
  338. X
  339. X#define C_Block des_cblock
  340. X#define Key_schedule des_key_schedule
  341. X#define ENCRYPT DES_ENCRYPT
  342. X#define DECRYPT DES_DECRYPT
  343. X#define KEY_SZ DES_KEY_SZ
  344. X#define string_to_key des_string_to_key
  345. X#define read_pw_string des_read_pw_string
  346. X#define random_key des_random_key
  347. X#define pcbc_encrypt des_pcbc_encrypt
  348. X#define set_key des_set_key
  349. X#define key_sched des_key_sched
  350. X#define ecb_encrypt des_ecb_encrypt
  351. X#define cbc_encrypt des_cbc_encrypt
  352. X#define cbc_cksum des_cbc_cksum
  353. X#define quad_cksum des_quad_cksum
  354. X
  355. X/* For compatibility with the MIT lib - eay 20/05/92 */
  356. Xtypedef struct des_ks_struct bit_64;
  357. X
  358. Xextern int des_check_key;    /* defaults to false */
  359. Xextern int des_rw_mode;        /* defaults to DES_PCBC_MODE */
  360. X
  361. X/* The next line is used to disable full ANSI prototypes, if your
  362. X * compiler has problems with the prototypes, make sure this line always
  363. X * evaluates to true :-) */
  364. X#if !defined(MSDOS) && !defined(__STDC__)
  365. X#ifndef KERBEROS
  366. Xint des_3ecb_encrypt();
  367. Xint des_cbc_encrypt();
  368. Xint des_3cbc_encrypt();
  369. Xint des_cfb_encrypt();
  370. Xint des_ecb_encrypt();
  371. Xint des_encrypt();
  372. Xint des_enc_read();
  373. Xint des_enc_write();
  374. Xint des_ofb_encrypt();
  375. Xint des_pcbc_encrypt();
  376. Xint des_random_key();
  377. Xint des_read_password();
  378. Xint des_read_2passwords();
  379. Xint des_read_pw_string();
  380. Xint des_is_weak_key();
  381. Xint des_set_key();
  382. Xint des_key_sched();
  383. Xint des_string_to_key();
  384. Xint des_string_to_2keys();
  385. X#endif
  386. Xchar *crypt();
  387. Xunsigned long des_cbc_cksum();
  388. Xunsigned long des_quad_cksum();
  389. Xunsigned long des_cbc_cksum();
  390. Xvoid des_set_odd_parity();
  391. X#else /* PROTO */
  392. Xint des_3ecb_encrypt(des_cblock *input,des_cblock *output,\
  393. X    des_key_schedule ks1,des_key_schedule ks2,int encrypt);
  394. Xunsigned long des_cbc_cksum(des_cblock *input,des_cblock *output,\
  395. X    long length,des_key_schedule schedule,des_cblock *ivec);
  396. Xint des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,\
  397. X    des_key_schedule schedule,des_cblock *ivec,int encrypt);
  398. Xint des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,\
  399. X    des_key_schedule sk1,des_key_schedule sk2,\
  400. X    des_cblock *ivec1,des_cblock *ivec2,int encrypt);
  401. Xint des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,\
  402. X    long length,des_key_schedule schedule,des_cblock *ivec,int encrypt);
  403. Xint des_ecb_encrypt(des_cblock *input,des_cblock *output,\
  404. X    des_key_schedule ks,int encrypt);
  405. Xint des_encrypt(unsigned long *input,unsigned long *output,
  406. X    des_key_schedule ks, int encrypt);
  407. Xint des_enc_read(int fd,char *buf,int len,des_key_schedule sched,\
  408. X    des_cblock *iv);
  409. Xint des_enc_write(int fd,char *buf,int len,des_key_schedule sched,\
  410. X    des_cblock *iv);
  411. Xchar *crypt(char *buf,char *salt);
  412. Xint des_ofb_encrypt(unsigned char *in,unsigned char *out,\
  413. X    int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
  414. Xint des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,\
  415. X    des_key_schedule schedule,des_cblock *ivec,int encrypt);
  416. Xunsigned long des_quad_cksum(des_cblock *input,des_cblock *output,\
  417. X    long length,int out_count,des_cblock *seed);
  418. Xint des_random_key(des_cblock ret);
  419. Xint des_read_password(des_cblock *key,char *prompt,int verify);
  420. Xint des_read_2passwords(des_cblock *key1,des_cblock *key2, \
  421. X    char *prompt,int verify);
  422. Xint des_read_pw_string(char *buf,int length,char *prompt,int verify);
  423. Xvoid des_set_odd_parity(des_cblock *key);
  424. Xint des_is_weak_key(des_cblock *key);
  425. Xint des_set_key(des_cblock *key,des_key_schedule schedule);
  426. Xint des_key_sched(des_cblock *key,des_key_schedule schedule);
  427. Xint des_string_to_key(char *str,des_cblock *key);
  428. Xint des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
  429. X#endif
  430. X#endif
  431. END_OF_FILE
  432.   if test 4062 -ne `wc -c <'des.h'`; then
  433.     echo shar: \"'des.h'\" unpacked with wrong size!
  434.   fi
  435.   # end of 'des.h'
  436. fi
  437. if test -f 'des.man' -a "${1}" != "-c" ; then 
  438.   echo shar: Will not clobber existing file \"'des.man'\"
  439. else
  440.   echo shar: Extracting \"'des.man'\" \(4709 characters\)
  441.   sed "s/^X//" >'des.man' <<'END_OF_FILE'
  442. X.TH DES 1 
  443. X.SH NAME
  444. Xdes - encrypt or decrypt data using Data Encryption Standard
  445. X.SH SYNOPSIS
  446. X.B des
  447. X(
  448. X.B \-e
  449. X|
  450. X.B \-E
  451. X) | (
  452. X.B \-d
  453. X|
  454. X.B \-D
  455. X) | (
  456. X.B \-\fR[\fPcC\fR][\fPckname\fR]\fP
  457. X) |
  458. X[
  459. X.B \-b3hfs
  460. X] [
  461. X.B \-k
  462. X.I key
  463. X]
  464. X] [
  465. X.B \-u\fR[\fIuuname\fR]
  466. X[
  467. X.I input-file
  468. X[
  469. X.I output-file
  470. X] ]
  471. X.SH DESCRIPTION
  472. X.B des
  473. Xencrypts and decrypts data using the
  474. XData Encryption Standard algorithm.
  475. XOne of
  476. X.B \-e, \-E
  477. X(for encrypt) or
  478. X.B \-d, \-D
  479. X(for decrypt) must be specified.
  480. XIt is also possible to use
  481. X.B \-c
  482. Xor
  483. X.B \-C
  484. Xin conjunction or instead of the a encrypt/decrypt option to generate
  485. Xa 16 character hexadecimal checksum, generated via the
  486. X.I des_cbc_cksum.
  487. X.LP
  488. XTwo standard encryption modes are supported by the
  489. X.B des
  490. Xprogram, Cipher Block Chaining (the default) and Electronic Code Book
  491. X(specified with
  492. X.B \-b
  493. X).
  494. X.LP
  495. XThe key used for the DES
  496. Xalgorithm is obtained by prompting the user unless the
  497. X.B `\-k
  498. X.I key'
  499. Xoption is given.
  500. XIf the key is an argument to the
  501. X.B des
  502. Xcommand, it is potentially visible to users executing
  503. X.BR ps (1)
  504. Xor a derivative.  To minimise this possibility,
  505. X.B des
  506. Xtakes care to destroy the key argument immediately upon entry.
  507. XIf your shell keeps a history file be careful to make sure it is not
  508. Xworld readable.
  509. X.LP
  510. XSince this program attempts to maintain compatability with sunOS's
  511. Xdes(1) command, there are 2 different methods used to convert the user
  512. Xsupplied key to a des key.
  513. XWhenever and one or more of
  514. X.B \-E, \-D, \-C
  515. Xor
  516. X.B \-3
  517. Xoptions are used, the key conversion procedure will not be compatible
  518. Xwith the sunOS des(1) version but will use all the user supplied
  519. Xcharacter to generate the des key.
  520. X.B des
  521. Xcommand reads from standard input unless
  522. X.I input-file
  523. Xis specified and writes to standard output unless
  524. X.I output-file
  525. Xis given.
  526. X.SH OPTIONS
  527. X.TP
  528. X.B \-b
  529. XSelect ECB
  530. X(eight bytes at a time) encryption mode.
  531. X.TP
  532. X.B \-3
  533. XEncrypt using triple encryption.
  534. XBy default triple cbc encryption is used but if the
  535. X.B \-b
  536. Xoption is used then triple ecb encryption is performed.
  537. XIf the key is less than 8 characters long, the flag has no effect.
  538. X.TP
  539. X.B \-e
  540. XEncrypt data using an 8 byte key in a manner compatible with sunOS
  541. Xdes(1).
  542. X.TP
  543. X.B \-E
  544. XEncrypt data using a key of nearly unlimited length (1024 bytes).
  545. XThis will product a more secure encryption.
  546. X.TP
  547. X.B \-d
  548. XDecrypt data that was encrypted with the \-e option.
  549. X.TP
  550. X.B \-D
  551. XDecrypt data that was encrypted with the \-E option.
  552. X.TP
  553. X.B \-c
  554. XGenerate a 16 character hexadecimal cbc checksum and output this to
  555. Xstderr.
  556. XIf a filename was specified after the
  557. X.B \-c
  558. Xoption, the checksum is output to that file.
  559. XThe checksum is generated using a key generated in a sunOS compatible
  560. Xmanner.
  561. X.TP
  562. X.B \-C
  563. XA cbc checksum is generated in the same manner as described for the
  564. X.B \-c
  565. Xoption but the DES key is generated in the same manner as used for the
  566. X.B \-E
  567. Xand
  568. X.B \-D
  569. Xoptions
  570. X.TP
  571. X.B \-f
  572. XDoes nothing - allowed for compatibility with sunOS des(1) command.
  573. X.TP
  574. X.B \-s
  575. XDoes nothing - allowed for compatibility with sunOS des(1) command.
  576. X.TP
  577. X.B "\-k \fIkey\fP"
  578. XUse the encryption 
  579. X.I key
  580. Xspecified.
  581. X.TP
  582. X.B "\-h"
  583. XThe
  584. X.I key
  585. Xis assumed to be a 16 character hexadecimal number.
  586. XIf the
  587. X.B "\-3"
  588. Xoption is used the key is assumed to be a 32 character hexadecimal
  589. Xnumber.
  590. X.TP
  591. X.B \-u
  592. XThis flag is used to read and write uuencoded files.  If decrypting,
  593. Xthe input file is assumed to contain uuencoded, DES encrypted data.
  594. XIf encrypting, the characters following the -u are used as the name of
  595. Xthe uuencoded file to embed in the begin line of the uuencoded
  596. Xoutput.  If there is no name specified after the -u, the name text.des
  597. Xwill be embedded in the header.
  598. X.SH SEE ALSO
  599. X.B ps (1)
  600. X.B des_crypt(3)
  601. X.SH BUGS
  602. X.LP
  603. XThe problem with using the
  604. X.B -e
  605. Xoption is the short key length.
  606. XIt would be better to use a real 56-bit key rather than an
  607. XASCII-based 56-bit pattern.  Knowing that the key was derived from ASCII
  608. Xradically reduces the time necessary for a brute-force cryptographic attack.
  609. XMy attempt to remove this problem is to add an alternative text-key to
  610. XDES-key function.  This alternative function (accessed via
  611. X.B -E, -D, -S
  612. Xand
  613. X.B -3
  614. X)
  615. Xuses DES to help generate the key.
  616. X.LP
  617. XBe carefully when using the -u option.  Doing des -ud <filename> will
  618. Xnot decrypt filename (the -u option will gobble the d option).
  619. X.LP
  620. XThe VMS operating system operates in a world where files are always a
  621. Xmultiple of 512 bytes.  This causes problems when encrypted data is
  622. Xsend from unix to VMS since a 88 byte file will suddenly be padded
  623. Xwith 424 null bytes.  To get around this problem, use the -u option
  624. Xto uuencode the data before it is send to the VMS system.
  625. X.SH AUTHOR
  626. X.LP
  627. XEric Young (eay@psych.psy.uq.oz.au), Psychology Department,
  628. XUniversity of Queensland, Australia.
  629. END_OF_FILE
  630.   if test 4709 -ne `wc -c <'des.man'`; then
  631.     echo shar: \"'des.man'\" unpacked with wrong size!
  632.   fi
  633.   # end of 'des.man'
  634. fi
  635. if test -f 'ecb_enc.c' -a "${1}" != "-c" ; then 
  636.   echo shar: Will not clobber existing file \"'ecb_enc.c'\"
  637. else
  638.   echo shar: Extracting \"'ecb_enc.c'\" \(2525 characters\)
  639.   sed "s/^X//" >'ecb_enc.c' <<'END_OF_FILE'
  640. X/* ecb_enc.c */
  641. X/* Copyright (C) 1993 Eric Young - see README for more details */
  642. X#include "des_locl.h"
  643. X#include "spr.h"
  644. X
  645. Xint des_ecb_encrypt(input,output,ks,encrypt)
  646. Xdes_cblock *input;
  647. Xdes_cblock *output;
  648. Xdes_key_schedule ks;
  649. Xint encrypt;
  650. X    {
  651. X    register unsigned long l0,l1;
  652. X    register unsigned char *in,*out;
  653. X    unsigned long ll[2];
  654. X
  655. X    in=(unsigned char *)input;
  656. X    out=(unsigned char *)output;
  657. X    c2l(in,l0);
  658. X    c2l(in,l1);
  659. X    ll[0]=l0;
  660. X    ll[1]=l1;
  661. X    des_encrypt(ll,ll,ks,encrypt);
  662. X    l0=ll[0];
  663. X    l1=ll[1];
  664. X    l2c(l0,out);
  665. X    l2c(l1,out);
  666. X    l0=l1=ll[0]=ll[1]=0;
  667. X    return(0);
  668. X    }
  669. X
  670. Xint des_encrypt(input,output,ks,encrypt)
  671. Xunsigned long *input;
  672. Xunsigned long *output;
  673. Xdes_key_schedule ks;
  674. Xint encrypt;
  675. X    {
  676. X    register unsigned long l,r,t,u;
  677. X#ifdef ALT_ECB
  678. X    register unsigned char *des_SP=(unsigned char *)des_SPtrans;
  679. X#endif
  680. X#ifdef MSDOS
  681. X    union fudge {
  682. X        unsigned long  l;
  683. X        unsigned short s[2];
  684. X        unsigned char  c[4];
  685. X        } U,T;
  686. X#endif
  687. X    register int i;
  688. X    register unsigned long *s;
  689. X
  690. X    l=input[0];
  691. X    r=input[1];
  692. X
  693. X    /* do IP */
  694. X    PERM_OP(r,l,t, 4,0x0f0f0f0f);
  695. X    PERM_OP(l,r,t,16,0x0000ffff);
  696. X    PERM_OP(r,l,t, 2,0x33333333);
  697. X    PERM_OP(l,r,t, 8,0x00ff00ff);
  698. X    PERM_OP(r,l,t, 1,0x55555555);
  699. X    /* r and l are reversed - remember that :-) - fix
  700. X     * it in the next step */
  701. X
  702. X    /* Things have been modified so that the initial rotate is
  703. X     * done outside the loop.  This required the
  704. X     * des_SPtrans values in sp.h to be rotated 1 bit to the right.
  705. X     * One perl script later and things have a 5% speed up on a sparc2.
  706. X     * Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
  707. X     * for pointing this out. */
  708. X    t=(r<<1)|(r>>31);
  709. X    r=(l<<1)|(l>>31);
  710. X    l=t;
  711. X
  712. X    /* clear the top bits on machines with 8byte longs */
  713. X    l&=0xffffffff;
  714. X    r&=0xffffffff;
  715. X
  716. X    s=(unsigned long *)ks;
  717. X    /* I don't know if it is worth the effort of loop unrolling the
  718. X     * inner loop */
  719. X    if (encrypt)
  720. X        {
  721. X        for (i=0; i<32; i+=4)
  722. X            {
  723. X            D_ENCRYPT(l,r,i+0); /*  1 */
  724. X            D_ENCRYPT(r,l,i+2); /*  2 */
  725. X            }
  726. X        }
  727. X    else
  728. X        {
  729. X        for (i=30; i>0; i-=4)
  730. X            {
  731. X            D_ENCRYPT(l,r,i-0); /* 16 */
  732. X            D_ENCRYPT(r,l,i-2); /* 15 */
  733. X            }
  734. X        }
  735. X    l=(l>>1)|(l<<31);
  736. X    r=(r>>1)|(r<<31);
  737. X    /* clear the top bits on machines with 8byte longs */
  738. X    l&=0xffffffff;
  739. X    r&=0xffffffff;
  740. X
  741. X    /* swap l and r
  742. X     * we will not do the swap so just remember they are
  743. X     * reversed for the rest of the subroutine
  744. X     * luckily FP fixes this problem :-) */
  745. X
  746. X    PERM_OP(r,l,t, 1,0x55555555);
  747. X    PERM_OP(l,r,t, 8,0x00ff00ff);
  748. X    PERM_OP(r,l,t, 2,0x33333333);
  749. X    PERM_OP(l,r,t,16,0x0000ffff);
  750. X    PERM_OP(r,l,t, 4,0x0f0f0f0f);
  751. X
  752. X    output[0]=l;
  753. X    output[1]=r;
  754. X    l=r=t=u=0;
  755. X    return(0);
  756. X    }
  757. X
  758. END_OF_FILE
  759.   if test 2525 -ne `wc -c <'ecb_enc.c'`; then
  760.     echo shar: \"'ecb_enc.c'\" unpacked with wrong size!
  761.   fi
  762.   # end of 'ecb_enc.c'
  763. fi
  764. if test -f 'enc_read.c' -a "${1}" != "-c" ; then 
  765.   echo shar: Will not clobber existing file \"'enc_read.c'\"
  766. else
  767.   echo shar: Extracting \"'enc_read.c'\" \(3343 characters\)
  768.   sed "s/^X//" >'enc_read.c' <<'END_OF_FILE'
  769. X/* enc_read.c */
  770. X/* Copyright (C) 1993 Eric Young - see README for more details */
  771. X#include <errno.h>
  772. X#include "des_locl.h"
  773. X
  774. X/* This has some uglies in it but it works - even over sockets. */
  775. Xextern int errno;
  776. Xint des_rw_mode=DES_PCBC_MODE;
  777. X
  778. Xint des_enc_read(fd,buf,len,sched,iv)
  779. Xint fd;
  780. Xchar *buf;
  781. Xint len;
  782. Xdes_key_schedule sched;
  783. Xdes_cblock *iv;
  784. X    {
  785. X    /* data to be unencrypted */
  786. X    int net_num=0;
  787. X    unsigned char net[BSIZE];
  788. X    /* extra unencrypted data 
  789. X     * for when a block of 100 comes in but is des_read one byte at
  790. X     * a time. */
  791. X    static char unnet[BSIZE];
  792. X    static int unnet_start=0;
  793. X    static int unnet_left=0;
  794. X    int i;
  795. X    long num=0,rnum;
  796. X    unsigned char *p;
  797. X
  798. X    /* left over data from last decrypt */
  799. X    if (unnet_left != 0)
  800. X        {
  801. X        if (unnet_left < len)
  802. X            {
  803. X            /* we still still need more data but will return
  804. X             * with the number of bytes we have - should always
  805. X             * check the return value */
  806. X            bcopy(&(unnet[unnet_start]),buf,unnet_left);
  807. X            /* eay 26/08/92 I had the next 2 lines
  808. X             * reversed :-( */
  809. X            i=unnet_left;
  810. X            unnet_start=unnet_left=0;
  811. X            }
  812. X        else
  813. X            {
  814. X            bcopy(&(unnet[unnet_start]),buf,len);
  815. X            unnet_start+=len;
  816. X            unnet_left-=len;
  817. X            i=len;
  818. X            }
  819. X        return(i);
  820. X        }
  821. X
  822. X    /* We need to get more data. */
  823. X    if (len > MAXWRITE) len=MAXWRITE;
  824. X
  825. X    /* first - get the length */
  826. X    net_num=0;
  827. X    while (net_num < HDRSIZE) 
  828. X        {
  829. X        i=read(fd,&(net[net_num]),HDRSIZE-net_num);
  830. X        if ((i == -1) && (errno == EINTR)) continue;
  831. X        if (i <= 0) return(0);
  832. X        net_num+=i;
  833. X        }
  834. X
  835. X    /* we now have at net_num bytes in net */
  836. X    p=net;
  837. X    num=0;
  838. X    n2l(p,num);
  839. X    /* num should be rounded up to the next group of eight
  840. X     * we make sure that we have read a multiple of 8 bytes from the net.
  841. X     */
  842. X    if ((num > MAXWRITE) || (num < 0)) /* error */
  843. X        return(-1);
  844. X    rnum=(num < 8)?8:((num+7)/8*8);
  845. X
  846. X    net_num=0;
  847. X    while (net_num < rnum)
  848. X        {
  849. X        i=read(fd,&(net[net_num]),rnum-net_num);
  850. X        if ((i == -1) && (errno == EINTR)) continue;
  851. X        if (i <= 0) return(0);
  852. X        net_num+=i;
  853. X        }
  854. X
  855. X    /* Check if there will be data left over. */
  856. X    if (len < num)
  857. X        {
  858. X        if (des_rw_mode & DES_PCBC_MODE)
  859. X            pcbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
  860. X                num,sched,iv,DES_DECRYPT);
  861. X        else
  862. X            cbc_encrypt((des_cblock *)net,(des_cblock *)unnet,
  863. X                num,sched,iv,DES_DECRYPT);
  864. X        bcopy(unnet,buf,len);
  865. X        unnet_start=len;
  866. X        unnet_left=num-len;
  867. X
  868. X        /* The following line is done because we return num
  869. X         * as the number of bytes read. */
  870. X        num=len;
  871. X        }
  872. X    else
  873. X        {
  874. X        /* >output is a multiple of 8 byes, if len < rnum
  875. X         * >we must be careful.  The user must be aware that this
  876. X         * >routine will write more bytes than he asked for.
  877. X         * >The length of the buffer must be correct.
  878. X         * FIXED - Should be ok now 18-9-90 - eay */
  879. X        if (len < rnum)
  880. X            {
  881. X            char tmpbuf[BSIZE];
  882. X
  883. X            if (des_rw_mode & DES_PCBC_MODE)
  884. X                pcbc_encrypt((des_cblock *)net,
  885. X                    (des_cblock *)tmpbuf,
  886. X                    num,sched,iv,DES_DECRYPT);
  887. X            else
  888. X                cbc_encrypt((des_cblock *)net,
  889. X                    (des_cblock *)tmpbuf,
  890. X                    num,sched,iv,DES_DECRYPT);
  891. X
  892. X            /* eay 26/08/92 fix a bug that returned more
  893. X             * bytes than you asked for (returned len bytes :-( */
  894. X            bcopy(tmpbuf,buf,num);
  895. X            }
  896. X        else
  897. X            {
  898. X            if (des_rw_mode & DES_PCBC_MODE)
  899. X                pcbc_encrypt((des_cblock *)net,
  900. X                    (des_cblock *)buf,num,sched,iv,
  901. X                    DES_DECRYPT);
  902. X            else
  903. X                cbc_encrypt((des_cblock *)net,
  904. X                    (des_cblock *)buf,num,sched,iv,
  905. X                    DES_DECRYPT);
  906. X            }
  907. X        }
  908. X    return(num);
  909. X    }
  910. X
  911. END_OF_FILE
  912.   if test 3343 -ne `wc -c <'enc_read.c'`; then
  913.     echo shar: \"'enc_read.c'\" unpacked with wrong size!
  914.   fi
  915.   # end of 'enc_read.c'
  916. fi
  917. if test -f 'makefile' -a "${1}" != "-c" ; then 
  918.   echo shar: Will not clobber existing file \"'makefile'\"
  919. else
  920.   echo shar: Extracting \"'makefile'\" \(3215 characters\)
  921.   sed "s/^X//" >'makefile' <<'END_OF_FILE'
  922. X# Turn this option on if using a SGI Iris running IRIX.
  923. X# IRIX does not appear to define sgttyb anywhere :-(
  924. X#OPTS0= -D_IRIX 
  925. X
  926. X# Version 1.94 has changed the strings_to_key function so that it is
  927. X# now compatible with MITs when the string is longer than 8 characters.
  928. X# If you wish to keep the old version, uncomment the following line.
  929. X# This will affect the -E/-D options on des(1).
  930. X#OPTS1= -DOLD_STR_TO_KEY
  931. X
  932. X# This #define specifies the use of an alternative D_ENCRYPT macro in
  933. X# ecb_encrypt.  The choice of macro can make a %20 difference in the
  934. X# speed.  Unfortunatly the choise of the best macro appears to be very
  935. X# dependant on the compiler and the machine in question.
  936. X# For the following combinations use the ALT_ECB option.
  937. X# Sparc 2 (cc -O4), sun 3/260 (cc -O4)
  938. X# For the following combinations do not use the ALT_ECB option.
  939. X# Sparc 2 (gcc2 -O2), sun 3/260 (cc -O2), mvax2 (cc -O), MSDOS (Turbo Cv2)
  940. X# For other machines, experiment with changing the option and run
  941. X# ./speed to see which is faster.
  942. X# DO NOT TURN THIS OPTION ON WHEN COMPILING THIS CODE ON A 64 BIT MACHINE
  943. X#OPTS2= -DALT_ECB
  944. X
  945. XOPTS= $(OPTS0) $(OPTS1) $(OPTS2)
  946. X#CC=cc
  947. X#CFLAGS= -g $(OPTS)
  948. XCC=gcc
  949. XCFLAGS= -O2 $(OPTS)
  950. X
  951. XLIBDIR=/usr/local/lib
  952. XBINDIR=/usr/local/bin
  953. XINCDIR=/usr/include
  954. XMANDIR=/usr/local/man
  955. XMAN1=1
  956. XMAN3=3
  957. XSHELL=/bin/sh
  958. X
  959. XOBJS=    cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
  960. X    qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
  961. X    enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
  962. X    3ecb_enc.o ofb_enc.o 3cbc_enc.o
  963. X
  964. XGENERAL=ARTISTIC COPYING FILES INSTALL Imakefile README VERSION makefile times \
  965. X    vms.com KERBEROS MODES.DES CHANGES
  966. XDES=    des.c des.man
  967. XTESTING=destest.c speed.c rpw.c
  968. XLIBDES=    des_crypt.man des.h cbc_cksm.c cbc_enc.c ecb_enc.c \
  969. X    enc_read.c enc_writ.c pcbc_enc.c qud_cksm.c rand_key.c \
  970. X    read_pwd.c set_key.c str2key.c fcrypt.c des_locl.h \
  971. X    podd.h sk.h spr.h cfb_enc.c 3ecb_enc.c \
  972. X    ofb_enc.c 3cbc_enc.c
  973. X
  974. XPERL=    des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
  975. X
  976. XALL=    $(GENERAL) $(DES) $(TESTING) $(LIBDES) $(PERL)
  977. X
  978. XLIB=    libdes.a
  979. X
  980. Xall: $(LIB) destest rpw des speed
  981. X
  982. X$(LIB):    $(OBJS)
  983. X    /bin/rm -f $(LIB)
  984. X    ar cr $(LIB) $(OBJS)
  985. X    -if test -s /bin/ranlib; then /bin/ranlib $(LIB); \
  986. X    else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(LIB); \
  987. X    else exit 0; fi; fi
  988. X
  989. Xdestest: destest.o libdes.a
  990. X    $(CC) $(CFLAGS) -o destest destest.o libdes.a
  991. X
  992. Xrpw: rpw.o libdes.a
  993. X    $(CC) $(CFLAGS) -o rpw rpw.o libdes.a
  994. X
  995. Xspeed: speed.o libdes.a
  996. X    $(CC) $(CFLAGS) -o speed speed.o libdes.a
  997. X
  998. Xdes: des.o libdes.a
  999. X    $(CC) $(CFLAGS) -o des des.o libdes.a
  1000. X
  1001. Xtar:
  1002. X    tar cf libdes.tar $(ALL)
  1003. X
  1004. Xshar:
  1005. X    shar $(ALL) >libdes.shar
  1006. X
  1007. Xclean:
  1008. X    /bin/rm -f *.o rpw destest des speed $(LIB)
  1009. X
  1010. Xinstall: $(LIB) des
  1011. X    cp $(LIB) $(LIBDIR)/$(LIB)
  1012. X    -if test -s /bin/ranlib; then /bin/ranlib $(LIBDIR)/$(LIB); \
  1013. X    else if test -s /usr/bin/ranlib; then /usr/bin/ranlib $(LIBDIR)/$(LIB); \
  1014. X    fi; fi
  1015. X    chmod 644 $(LIBDIR)/$(LIB)
  1016. X    cp des $(BINDIR)/des
  1017. X    chmod 711 $(BINDIR)/des
  1018. X    cp des_crypt.man $(MANDIR)/man$(MAN3)/des_crypt.$(MAN3)
  1019. X    chmod 644 $(MANDIR)/man$(MAN3)/des_crypt.$(MAN3)
  1020. X    cp des.man $(MANDIR)/man$(MAN1)/des.$(MAN1)
  1021. X    chmod 644 $(MANDIR)/man$(MAN1)/des.$(MAN1)
  1022. X    cp des.h $(INCDIR)/des.h
  1023. X    chmod 644 $(INCDIR)/des.h
  1024. X# DO NOT DELETE THIS LINE -- make depend depends on it.
  1025. END_OF_FILE
  1026.   if test 3215 -ne `wc -c <'makefile'`; then
  1027.     echo shar: \"'makefile'\" unpacked with wrong size!
  1028.   fi
  1029.   # end of 'makefile'
  1030. fi
  1031. if test -f 'pcbc_enc.c' -a "${1}" != "-c" ; then 
  1032.   echo shar: Will not clobber existing file \"'pcbc_enc.c'\"
  1033. else
  1034.   echo shar: Extracting \"'pcbc_enc.c'\" \(1447 characters\)
  1035.   sed "s/^X//" >'pcbc_enc.c' <<'END_OF_FILE'
  1036. X/* pcbc_enc.c */
  1037. X/* Copyright (C) 1993 Eric Young - see README for more details */
  1038. X#include "des_locl.h"
  1039. X
  1040. Xint des_pcbc_encrypt(input,output,length,schedule,ivec,encrypt)
  1041. Xdes_cblock *input;
  1042. Xdes_cblock *output;
  1043. Xlong length;
  1044. Xdes_key_schedule schedule;
  1045. Xdes_cblock *ivec;
  1046. Xint encrypt;
  1047. X    {
  1048. X    register unsigned long sin0,sin1,xor0,xor1,tout0,tout1;
  1049. X    unsigned long tin[2],tout[2];
  1050. X    unsigned char *in,*out,*iv;
  1051. X
  1052. X    in=(unsigned char *)input;
  1053. X    out=(unsigned char *)output;
  1054. X    iv=(unsigned char *)ivec;
  1055. X
  1056. X    if (encrypt)
  1057. X        {
  1058. X        c2l(iv,xor0);
  1059. X        c2l(iv,xor1);
  1060. X        for (; length>0; length-=8)
  1061. X            {
  1062. X            if (length >= 8)
  1063. X                {
  1064. X                c2l(in,sin0);
  1065. X                c2l(in,sin1);
  1066. X                }
  1067. X            else
  1068. X                c2ln(in,sin0,sin1,length);
  1069. X            tin[0]=sin0^xor0;
  1070. X            tin[1]=sin1^xor1;
  1071. X            des_encrypt((unsigned long *)tin,(unsigned long *)tout,
  1072. X                schedule,encrypt);
  1073. X            tout0=tout[0];
  1074. X            tout1=tout[1];
  1075. X            xor0=sin0^tout[0];
  1076. X            xor1=sin1^tout[1];
  1077. X            l2c(tout0,out);
  1078. X            l2c(tout1,out);
  1079. X            }
  1080. X        }
  1081. X    else
  1082. X        {
  1083. X        c2l(iv,xor0); c2l(iv,xor1);
  1084. X        for (; length>0; length-=8)
  1085. X            {
  1086. X            c2l(in,sin0);
  1087. X            c2l(in,sin1);
  1088. X            tin[0]=sin0;
  1089. X            tin[1]=sin1;
  1090. X            des_encrypt((unsigned long *)tin,(unsigned long *)tout,
  1091. X                schedule,encrypt);
  1092. X            tout0=tout[0]^xor0;
  1093. X            tout1=tout[1]^xor1;
  1094. X            if (length >= 8)
  1095. X                {
  1096. X                l2c(tout0,out);
  1097. X                l2c(tout1,out);
  1098. X                }
  1099. X            else
  1100. X                l2cn(tout0,tout1,out,length);
  1101. X            xor0=tout0^sin0;
  1102. X            xor1=tout1^sin1;
  1103. X            }
  1104. X        }
  1105. X    tin[0]=tin[1]=tout[0]=tout[1]=0;
  1106. X    sin0=sin1=xor0=xor1=tout0=tout1=0;
  1107. X    return(0);
  1108. X    }
  1109. END_OF_FILE
  1110.   if test 1447 -ne `wc -c <'pcbc_enc.c'`; then
  1111.     echo shar: \"'pcbc_enc.c'\" unpacked with wrong size!
  1112.   fi
  1113.   # end of 'pcbc_enc.c'
  1114. fi
  1115. if test -f 'set_key.c' -a "${1}" != "-c" ; then 
  1116.   echo shar: Will not clobber existing file \"'set_key.c'\"
  1117. else
  1118.   echo shar: Extracting \"'set_key.c'\" \(4706 characters\)
  1119.   sed "s/^X//" >'set_key.c' <<'END_OF_FILE'
  1120. X/* set_key.c */
  1121. X/* Copyright (C) 1993 Eric Young - see README for more details */
  1122. X/* set_key.c v 1.4 eay 24/9/91
  1123. X * 1.4 Speed up by 400% :-)
  1124. X * 1.3 added register declarations.
  1125. X * 1.2 unrolled make_key_sched a bit more
  1126. X * 1.1 added norm_expand_bits
  1127. X * 1.0 First working version
  1128. X */
  1129. X#include "des_locl.h"
  1130. X#include "podd.h"
  1131. X#include "sk.h"
  1132. X
  1133. Xstatic int check_parity();
  1134. X
  1135. Xint des_check_key=0;
  1136. X
  1137. Xvoid des_set_odd_parity(key)
  1138. Xdes_cblock *key;
  1139. X    {
  1140. X    int i;
  1141. X
  1142. X    for (i=0; i<DES_KEY_SZ; i++)
  1143. X        (*key)[i]=odd_parity[(*key)[i]];
  1144. X    }
  1145. X
  1146. Xstatic int check_parity(key)
  1147. Xdes_cblock *key;
  1148. X    {
  1149. X    int i;
  1150. X
  1151. X    for (i=0; i<DES_KEY_SZ; i++)
  1152. X        {
  1153. X        if ((*key)[i] != odd_parity[(*key)[i]])
  1154. X            return(0);
  1155. X        }
  1156. X    return(1);
  1157. X    }
  1158. X
  1159. X/* Weak and semi week keys as take from
  1160. X * %A D.W. Davies
  1161. X * %A W.L. Price
  1162. X * %T Security for Computer Networks
  1163. X * %I John Wiley & Sons
  1164. X * %D 1984
  1165. X * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
  1166. X * (and actual cblock values).
  1167. X */
  1168. X#define NUM_WEAK_KEY    16
  1169. Xstatic des_cblock weak_keys[NUM_WEAK_KEY]={
  1170. X    /* weak keys */
  1171. X    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1172. X    0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
  1173. X    0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
  1174. X    0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
  1175. X    /* semi-weak keys */
  1176. X    0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,
  1177. X    0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,
  1178. X    0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1,
  1179. X    0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E,
  1180. X    0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,
  1181. X    0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01,
  1182. X    0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE,
  1183. X    0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,
  1184. X    0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,
  1185. X    0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01,
  1186. X    0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE,
  1187. X    0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1};
  1188. X
  1189. Xint des_is_weak_key(key)
  1190. Xdes_cblock *key;
  1191. X    {
  1192. X    int i;
  1193. X
  1194. X    for (i=0; i<NUM_WEAK_KEY; i++)
  1195. X        /* Added == 0 to comparision, I obviously don't run
  1196. X         * this section very often :-(, thanks to
  1197. X         * engineering@MorningStar.Com for the fix
  1198. X         * eay 93/06/29 */
  1199. X        if (memcmp(weak_keys[i],key,sizeof(key)) == 0) return(1);
  1200. X    return(0);
  1201. X    }
  1202. X
  1203. X/* NOW DEFINED IN des_local.h
  1204. X * See ecb_encrypt.c for a pseudo description of these macros. 
  1205. X * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
  1206. X *     (b)^=(t),\
  1207. X *     (a)=((a)^((t)<<(n))))
  1208. X */
  1209. X
  1210. X#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
  1211. X    (a)=(a)^(t)^(t>>(16-(n))))
  1212. X
  1213. Xstatic char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
  1214. X
  1215. X/* return 0 if key parity is odd (correct),
  1216. X * return -1 if key parity error,
  1217. X * return -2 if illegal weak key.
  1218. X */
  1219. Xint des_set_key(key,schedule)
  1220. Xdes_cblock *key;
  1221. Xdes_key_schedule schedule;
  1222. X    {
  1223. X    register unsigned long c,d,t,s;
  1224. X    register unsigned char *in;
  1225. X    register unsigned long *k;
  1226. X    register int i;
  1227. X
  1228. X    if (des_check_key)
  1229. X        {
  1230. X        if (!check_parity(key))
  1231. X            return(-1);
  1232. X
  1233. X        if (des_is_weak_key(key))
  1234. X            return(-2);
  1235. X        }
  1236. X
  1237. X    k=(unsigned long *)schedule;
  1238. X    in=(unsigned char *)key;
  1239. X
  1240. X    c2l(in,c);
  1241. X    c2l(in,d);
  1242. X
  1243. X    /* do PC1 in 60 simple operations */ 
  1244. X/*    PERM_OP(d,c,t,4,0x0f0f0f0f);
  1245. X    HPERM_OP(c,t,-2, 0xcccc0000);
  1246. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  1247. X    HPERM_OP(c,t, 8, 0x00ff0000);
  1248. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  1249. X    HPERM_OP(d,t,-8, 0xff000000);
  1250. X    HPERM_OP(d,t, 8, 0x00ff0000);
  1251. X    HPERM_OP(d,t, 2, 0x33330000);
  1252. X    d=((d&0x00aa00aa)<<7)|((d&0x55005500)>>7)|(d&0xaa55aa55);
  1253. X    d=(d>>8)|((c&0xf0000000)>>4);
  1254. X    c&=0x0fffffff; */
  1255. X
  1256. X    /* I now do it in 47 simple operations :-)
  1257. X     * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
  1258. X     * for the inspiration. :-) */
  1259. X    PERM_OP (d,c,t,4,0x0f0f0f0f);
  1260. X    HPERM_OP(c,t,-2,0xcccc0000);
  1261. X    HPERM_OP(d,t,-2,0xcccc0000);
  1262. X    PERM_OP (d,c,t,1,0x55555555);
  1263. X    PERM_OP (c,d,t,8,0x00ff00ff);
  1264. X    PERM_OP (d,c,t,1,0x55555555);
  1265. X    d=    (((d&0x000000ff)<<16)| (d&0x0000ff00)     |
  1266. X         ((d&0x00ff0000)>>16)|((c&0xf0000000)>>4));
  1267. X    c&=0x0fffffff;
  1268. X
  1269. X    for (i=0; i<ITERATIONS; i++)
  1270. X        {
  1271. X        if (shifts2[i])
  1272. X            { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
  1273. X        else
  1274. X            { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
  1275. X        c&=0x0fffffff;
  1276. X        d&=0x0fffffff;
  1277. X        /* could be a few less shifts but I am to lazy at this
  1278. X         * point in time to investigate */
  1279. X        s=    des_skb[0][ (c    )&0x3f                ]|
  1280. X            des_skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
  1281. X            des_skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
  1282. X            des_skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
  1283. X                          ((c>>22)&0x38)];
  1284. X        t=    des_skb[4][ (d    )&0x3f                ]|
  1285. X            des_skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
  1286. X            des_skb[6][ (d>>15)&0x3f                ]|
  1287. X            des_skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
  1288. X
  1289. X        /* table contained 0213 4657 */
  1290. X        *(k++)=((t<<16)|(s&0x0000ffff))&0xffffffff;
  1291. X        s=     ((s>>16)|(t&0xffff0000));
  1292. X        
  1293. X        s=(s<<4)|(s>>28);
  1294. X        *(k++)=s&0xffffffff;
  1295. X        }
  1296. X    return(0);
  1297. X    }
  1298. X
  1299. Xint des_key_sched(key,schedule)
  1300. Xdes_cblock *key;
  1301. Xdes_key_schedule schedule;
  1302. X    {
  1303. X    return(des_set_key(key,schedule));
  1304. X    }
  1305. END_OF_FILE
  1306.   if test 4706 -ne `wc -c <'set_key.c'`; then
  1307.     echo shar: \"'set_key.c'\" unpacked with wrong size!
  1308.   fi
  1309.   # end of 'set_key.c'
  1310. fi
  1311. if test -f 'speed.c' -a "${1}" != "-c" ; then 
  1312.   echo shar: Will not clobber existing file \"'speed.c'\"
  1313. else
  1314.   echo shar: Extracting \"'speed.c'\" \(4296 characters\)
  1315.   sed "s/^X//" >'speed.c' <<'END_OF_FILE'
  1316. X/* speed.c */
  1317. X/* Copyright (C) 1993 Eric Young - see README for more details */
  1318. X/* 11-Sep-92 Andrew Daviel   Support for Silicon Graphics IRIX added */
  1319. X/* 06-Apr-92 Luke Brennan    Support for VMS and add extra signal calls */
  1320. X
  1321. X#ifndef MSDOS
  1322. X#define TIMES
  1323. X#endif
  1324. X
  1325. X#include <stdio.h>
  1326. X#include <signal.h>
  1327. X#ifndef VMS
  1328. X#ifndef _IRIX
  1329. X#include <time.h>
  1330. X#endif
  1331. X#ifdef TIMES
  1332. X#include <sys/types.h>
  1333. X#include <sys/times.h>
  1334. X#endif /* TIMES */
  1335. X#else /* VMS */
  1336. X#include <types.h>
  1337. Xstruct tms {
  1338. X    time_t tms_utime;
  1339. X    time_t tms_stime;
  1340. X    time_t tms_uchild;    /* I dunno...  */
  1341. X    time_t tms_uchildsys;    /* so these names are a guess :-) */
  1342. X    }
  1343. X#endif
  1344. X#ifndef TIMES
  1345. X#include <sys/timeb.h>
  1346. X#endif
  1347. X#include "des.h"
  1348. X
  1349. X/* The following if from times(3) man page.  It may need to be changed */
  1350. X#ifndef CLK_TCK
  1351. X#ifndef VMS
  1352. X#define HZ    60.0
  1353. X#else /* VMS */
  1354. X#define HZ    100.0
  1355. X#endif
  1356. X#else /* CLK_TCK */
  1357. X#define HZ ((double)CLK_TCK)
  1358. X#endif
  1359. X
  1360. X#define BUFSIZE    ((long)1024*8)
  1361. Xlong run=0;
  1362. X
  1363. X#ifdef SIGALRM
  1364. X#ifdef __STDC__
  1365. X#define SIGRETTYPE void
  1366. X#else
  1367. X#define SIGRETTYPE int
  1368. X#endif 
  1369. X
  1370. XSIGRETTYPE sig_done(sig)
  1371. Xint sig;
  1372. X    {
  1373. X    signal(SIGALRM,sig_done);
  1374. X    run=0;
  1375. X    }
  1376. X#endif
  1377. X
  1378. X#define START    0
  1379. X#define STOP    1
  1380. X
  1381. Xdouble Time_F(s)
  1382. Xint s;
  1383. X    {
  1384. X    double ret;
  1385. X#ifdef TIMES
  1386. X    static struct tms tstart,tend;
  1387. X
  1388. X    if (s == START)
  1389. X        {
  1390. X        times(&tstart);
  1391. X        return(0);
  1392. X        }
  1393. X    else
  1394. X        {
  1395. X        times(&tend);
  1396. X        ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  1397. X        return((ret == 0.0)?1e-6:ret);
  1398. X        }
  1399. X#else /* !times() */
  1400. X    static struct timeb tstart,tend;
  1401. X    long i;
  1402. X
  1403. X    if (s == START)
  1404. X        {
  1405. X        ftime(&tstart);
  1406. X        return(0);
  1407. X        }
  1408. X    else
  1409. X        {
  1410. X        ftime(&tend);
  1411. X        i=(long)tend.millitm-(long)tstart.millitm;
  1412. X        ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
  1413. X        return((ret == 0.0)?1e-6:ret);
  1414. X        }
  1415. X#endif
  1416. X    }
  1417. X
  1418. Xmain(argc,argv)
  1419. Xint argc;
  1420. Xchar *argv[];
  1421. X    {
  1422. X    long count;
  1423. X    static unsigned char buf[BUFSIZE];
  1424. X    static des_cblock key={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
  1425. X    des_key_schedule sch;
  1426. X    double d,a,b,c;
  1427. X    long ca,cb,cc,cd;
  1428. X
  1429. X#ifndef TIMES
  1430. X    printf("To get the most acurate results, try to run this\n");
  1431. X    printf("program when this computer is idle.\n");
  1432. X#endif
  1433. X
  1434. X#ifndef SIGALRM
  1435. X    printf("First we calculate the aproximate speed ...\n");
  1436. X    des_set_key((C_Block *)key,sch);
  1437. X    count=10;
  1438. X    do    {
  1439. X        int i;
  1440. X        count*=2;
  1441. X        Time_F(START);
  1442. X        for (i=count; i; i--)
  1443. X            des_ecb_encrypt((C_Block *)buf,(C_Block *)buf,
  1444. X                &(sch[0]),DES_ENCRYPT);
  1445. X        d=Time_F(STOP);
  1446. X        } while (d <3);
  1447. X    ca=count;
  1448. X    cb=count*10;
  1449. X    cc=count*10*8/BUFSIZE+1;
  1450. X    cd=count/20+1;
  1451. X    printf("Doing set_key %ld times\n",ca);
  1452. X#define COND(d)    (count != (d))
  1453. X#define COUNT(d) (d)
  1454. X#else
  1455. X#define COND(c)    (run)
  1456. X#define COUNT(d) (count)
  1457. X    signal(SIGALRM,sig_done);
  1458. X    printf("Doing set_key for 10 seconds\n");
  1459. X    alarm(10);
  1460. X#endif
  1461. X
  1462. X    Time_F(START);
  1463. X    for (count=0,run=1; COND(ca); count++)
  1464. X        des_set_key((C_Block *)key,sch);
  1465. X    d=Time_F(STOP);
  1466. X    printf("%ld set_key's in %.2f seconds\n",count,d);
  1467. X    a=((double)COUNT(ca))/d;
  1468. X
  1469. X#ifdef SIGALRM
  1470. X    printf("Doing des_ecb_encrypt's for 10 seconds\n");
  1471. X    alarm(10);
  1472. X#else
  1473. X    printf("Doing des_ecb_encrypt %ld times\n",cb);
  1474. X#endif
  1475. X    Time_F(START);
  1476. X    for (count=0,run=1; COND(cb); count++)
  1477. X        des_ecb_encrypt((C_Block *)buf,(C_Block *)buf,
  1478. X            &(sch[0]),DES_ENCRYPT);
  1479. X    d=Time_F(STOP);
  1480. X    printf("%ld des_ecb_encrypt's in %.2f second\n",count,d);
  1481. X    b=((double)COUNT(cb)*8)/d;
  1482. X
  1483. X#ifdef SIGALRM
  1484. X    printf("Doing des_cbc_encrypt on %ld byte blocks for 10 seconds\n",
  1485. X        BUFSIZE);
  1486. X    alarm(10);
  1487. X#else
  1488. X    printf("Doing des_cbc_encrypt %ld times on %ld byte blocks\n",cc,
  1489. X        BUFSIZE);
  1490. X#endif
  1491. X    Time_F(START);
  1492. X    for (count=0,run=1; COND(cc); count++)
  1493. X        des_cbc_encrypt((C_Block *)buf,(C_Block *)buf,BUFSIZE,&(sch[0]),
  1494. X            (C_Block *)&(key[0]),DES_ENCRYPT);
  1495. X    d=Time_F(STOP);
  1496. X    printf("%ld des_cbc_encrypt's of %ld byte blocks in %.2f second\n",
  1497. X        count,BUFSIZE,d);
  1498. X    c=((double)COUNT(cc)*BUFSIZE)/d;
  1499. X
  1500. X#ifdef SIGALRM
  1501. X    printf("Doing crypt for 10 seconds\n");
  1502. X    alarm(10);
  1503. X#else
  1504. X    printf("Doing crypt %ld times\n",cd);
  1505. X#endif
  1506. X    Time_F(START);
  1507. X    for (count=0,run=1; COND(cd); count++)
  1508. X        crypt("testing1","ef");
  1509. X    d=Time_F(STOP);
  1510. X    printf("%ld crypts in %.2f second\n",count,d);
  1511. X    d=((double)COUNT(cd))/d;
  1512. X
  1513. X    printf("set_key       per sec = %12.2f (%5.1fuS)\n",a,1.0e6/a);
  1514. X    printf("DES ecb bytes per sec = %12.2f (%5.1fuS)\n",b,8.0e6/b);
  1515. X    printf("DES cbc bytes per sec = %12.2f (%5.1fuS)\n",c,8.0e6/c);
  1516. X    printf("crypt         per sec = %12.2f (%5.1fuS)\n",d,1.0e6/d);
  1517. X    }
  1518. END_OF_FILE
  1519.   if test 4296 -ne `wc -c <'speed.c'`; then
  1520.     echo shar: \"'speed.c'\" unpacked with wrong size!
  1521.   fi
  1522.   # end of 'speed.c'
  1523. fi
  1524. if test -f 'str2key.c' -a "${1}" != "-c" ; then 
  1525.   echo shar: Will not clobber existing file \"'str2key.c'\"
  1526. else
  1527.   echo shar: Extracting \"'str2key.c'\" \(2341 characters\)
  1528.   sed "s/^X//" >'str2key.c' <<'END_OF_FILE'
  1529. X/* str2key.c */
  1530. X/* Copyright (C) 1993 Eric Young - see README for more details */
  1531. X#include "des_locl.h"
  1532. X
  1533. Xextern int des_check_key;
  1534. X
  1535. Xint des_string_to_key(str,key)
  1536. Xchar *str;
  1537. Xdes_cblock *key;
  1538. X    {
  1539. X    des_key_schedule ks;
  1540. X    int i,length;
  1541. X    register unsigned char j;
  1542. X
  1543. X    bzero(key,8);
  1544. X    length=strlen(str);
  1545. X#ifdef OLD_STR_TO_KEY
  1546. X    for (i=0; i<length; i++)
  1547. X        (*key)[i%8]^=(str[i]<<1);
  1548. X#else /* MIT COMPATIBLE */
  1549. X    for (i=0; i<length; i++)
  1550. X        {
  1551. X        j=str[i];
  1552. X        if ((i%16) < 8)
  1553. X            (*key)[i%8]^=(j<<1);
  1554. X        else
  1555. X            {
  1556. X            /* Reverse the bit order 05/05/92 eay */
  1557. X            j=((j<<4)&0xf0)|((j>>4)&0x0f);
  1558. X            j=((j<<2)&0xcc)|((j>>2)&0x33);
  1559. X            j=((j<<1)&0xaa)|((j>>1)&0x55);
  1560. X            (*key)[7-(i%8)]^=j;
  1561. X            }
  1562. X        }
  1563. X#endif
  1564. X    des_set_odd_parity((des_cblock *)key);
  1565. X    i=des_check_key;
  1566. X    des_check_key=0;
  1567. X    des_set_key((des_cblock *)key,ks);
  1568. X    des_check_key=i;
  1569. X    des_cbc_cksum((des_cblock *)str,(des_cblock *)key,(long)length,ks,
  1570. X        (des_cblock *)key);
  1571. X    bzero(ks,sizeof(ks));
  1572. X    des_set_odd_parity((des_cblock *)key);
  1573. X    return(0);
  1574. X    }
  1575. X
  1576. Xint des_string_to_2keys(str,key1,key2)
  1577. Xchar *str;
  1578. Xdes_cblock *key1,*key2;
  1579. X    {
  1580. X    des_key_schedule ks;
  1581. X    int i,length;
  1582. X    register unsigned char j;
  1583. X
  1584. X    bzero(key1,8);
  1585. X    bzero(key2,8);
  1586. X    length=strlen(str);
  1587. X#ifdef OLD_STR_TO_KEY
  1588. X    if (length <= 8)
  1589. X        {
  1590. X        for (i=0; i<length; i++)
  1591. X            {
  1592. X            (*key2)[i]=(*key1)[i]=(str[i]<<1);
  1593. X            }
  1594. X        }
  1595. X    else
  1596. X        {
  1597. X        for (i=0; i<length; i++)
  1598. X            {
  1599. X            if ((i/8)&1)
  1600. X                (*key2)[i%8]^=(str[i]<<1);
  1601. X            else
  1602. X                (*key1)[i%8]^=(str[i]<<1);
  1603. X            }
  1604. X        }
  1605. X#else /* MIT COMPATIBLE */
  1606. X    for (i=0; i<length; i++)
  1607. X        {
  1608. X        j=str[i];
  1609. X        if ((i%32) < 16)
  1610. X            {
  1611. X            if ((i%16) < 8)
  1612. X                (*key1)[i%8]^=(j<<1);
  1613. X            else
  1614. X                (*key2)[i%8]^=(j<<1);
  1615. X            }
  1616. X        else
  1617. X            {
  1618. X            j=((j<<4)&0xf0)|((j>>4)&0x0f);
  1619. X            j=((j<<2)&0xcc)|((j>>2)&0x33);
  1620. X            j=((j<<1)&0xaa)|((j>>1)&0x55);
  1621. X            if ((i%16) < 8)
  1622. X                (*key1)[7-(i%8)]^=j;
  1623. X            else
  1624. X                (*key2)[7-(i%8)]^=j;
  1625. X            }
  1626. X        }
  1627. X    if (length <= 8) bcopy(key1,key2,8);
  1628. X#endif
  1629. X    des_set_odd_parity((des_cblock *)key1);
  1630. X    des_set_odd_parity((des_cblock *)key2);
  1631. X    i=des_check_key;
  1632. X    des_check_key=0;
  1633. X    des_set_key((des_cblock *)key1,ks);
  1634. X    des_cbc_cksum((des_cblock *)str,(des_cblock *)key1,(long)length,ks,
  1635. X        (des_cblock *)key1);
  1636. X    des_set_key((des_cblock *)key2,ks);
  1637. X    des_cbc_cksum((des_cblock *)str,(des_cblock *)key2,(long)length,ks,
  1638. X        (des_cblock *)key2);
  1639. X    des_check_key=i;
  1640. X    bzero(ks,sizeof(ks));
  1641. X    des_set_odd_parity(key1);
  1642. X    des_set_odd_parity(key2);
  1643. X    return(0);
  1644. X    }
  1645. END_OF_FILE
  1646.   if test 2341 -ne `wc -c <'str2key.c'`; then
  1647.     echo shar: \"'str2key.c'\" unpacked with wrong size!
  1648.   fi
  1649.   # end of 'str2key.c'
  1650. fi
  1651. if test -f 'times' -a "${1}" != "-c" ; then 
  1652.   echo shar: Will not clobber existing file \"'times'\"
  1653. else
  1654.   echo shar: Extracting \"'times'\" \(2688 characters\)
  1655.   sed "s/^X//" >'times' <<'END_OF_FILE'
  1656. XDEC Alpha DEC 4000/610 AXP OSF/1 v 1.3 - gcc v 2.3.3
  1657. Xset_key       per sec =    101840.19 (  9.8uS)
  1658. XDES ecb bytes per sec =   1223712.35 (  6.5uS)
  1659. XDES cbc bytes per sec =   1230542.98 (  6.5uS)
  1660. Xcrypt         per sec =      6428.75 (155.6uS)
  1661. X
  1662. XDEC Alpha DEC 4000/610 APX OSF/1 v 1.3 - cc -O2 - OSF/1 AXP
  1663. Xset_key       per sec =    114198.91 (  8.8uS)
  1664. XDES ecb bytes per sec =   1022710.93 (  7.8uS)
  1665. XDES cbc bytes per sec =   1008821.93 (  7.9uS)
  1666. Xcrypt         per sec =      5454.13 (183.3uS)
  1667. X
  1668. XDEC Alpha - DEC 3000/500 AXP OSF/1 - cc -O2 - 02/12/92
  1669. Xset_key       per sec =     83587.04 ( 12.0uS)
  1670. XDES ecb bytes per sec =    822620.82 (  9.7uS)
  1671. XDES cbc bytes per sec =    832929.60 (  9.6uS)
  1672. Xcrypt         per sec =      4807.62 (208.0uS)
  1673. X
  1674. Xsun sparc 10/30 - gcc -O2
  1675. Xset_key       per sec =     42005.24 ( 23.8uS)
  1676. XDES ecb bytes per sec =    555949.47 ( 14.4uS)
  1677. XDES cbc bytes per sec =    549440.28 ( 14.6uS)
  1678. Xcrypt         per sec =      2580.25 (387.6uS)
  1679. X
  1680. XPA-RISC 1.1 HP 710
  1681. Xset_key       per sec =     38916.86
  1682. XDES ecb bytes per sec =    505971.82
  1683. XDES cbc bytes per sec =    515381.13
  1684. Xcrypt         per sec =      2438.24
  1685. X
  1686. Xsun sparc 10/30 - cc -O4
  1687. Xset_key       per sec =     38379.86 ( 26.1uS)
  1688. XDES ecb bytes per sec =    460051.34 ( 17.4uS)
  1689. XDES cbc bytes per sec =    464970.54 ( 17.2uS)
  1690. Xcrypt         per sec =      2092.64 (477.9uS)
  1691. X
  1692. Xsun sparc 2 - gcc2 -O2
  1693. Xset_key       per sec =     21559.10
  1694. XDES ecb bytes per sec =    305566.92
  1695. XDES cbc bytes per sec =    303497.50
  1696. Xcrypt         per sec =      1410.48
  1697. X
  1698. XRS/6000 model 320
  1699. Xset_key       per sec =     14371.93
  1700. XDES ecb bytes per sec =    222231.26
  1701. XDES cbc bytes per sec =    223926.79
  1702. Xcrypt         per sec =       981.20
  1703. X
  1704. X68030 HP400
  1705. Xset_key       per sec =      5251.28
  1706. XDES ecb bytes per sec =     56186.56
  1707. XDES cbc bytes per sec =     58681.53
  1708. Xcrypt         per sec =       276.15
  1709. X
  1710. X80486sx/33MHz MSDOS Turbo C v 2.0
  1711. Xset_key       per sec =      1883.22 (531.0uS)
  1712. XDES ecb bytes per sec =     63393.31 (126.2uS)
  1713. XDES cbc bytes per sec =     63416.83 (126.1uS)
  1714. Xcrypt         per sec =       158.71 (6300.6uS)
  1715. X
  1716. X80486sx/33MHz MSDOS djgpp gcc 1.39 (32bit compiler)
  1717. Xset_key       per sec =     12603.08 (79.3)
  1718. XDES ecb bytes per sec =    158875.15 (50.4)
  1719. XDES cbc bytes per sec =    159893.85 (50.0)
  1720. Xcrypt         per sec =       780.24 (1281.7)
  1721. X
  1722. XVersion 1.99 26/08/92
  1723. X8MHz 68000 Atari-ST gcc 2.1 -O2 MiNT 0.94
  1724. Xset_key       per sec =       325.68 (3070.5uS)
  1725. XDES ecb bytes per sec =      4173.67 (1916.8uS)
  1726. XDES cbc bytes per sec =      4249.89 (1882.4uS)
  1727. Xcrypt         per sec =        20.19 (49521.6uS)
  1728. X
  1729. X8088/4.77mh MSDOS Turbo C v 2.0
  1730. Xset_key       per sec =        35.09
  1731. XDES ecb bytes per sec =       563.63
  1732. Xcrypt         per sec =         2.69
  1733. END_OF_FILE
  1734.   if test 2688 -ne `wc -c <'times'`; then
  1735.     echo shar: \"'times'\" unpacked with wrong size!
  1736.   fi
  1737.   # end of 'times'
  1738. fi
  1739. if test -f 'vms.com' -a "${1}" != "-c" ; then 
  1740.   echo shar: Will not clobber existing file \"'vms.com'\"
  1741. else
  1742.   echo shar: Extracting \"'vms.com'\" \(2311 characters\)
  1743.   sed "s/^X//" >'vms.com' <<'END_OF_FILE'
  1744. X$! --- VMS.com ---
  1745. X$!
  1746. X$ GoSub defines
  1747. X$ GoSub linker_options
  1748. X$ If (P1 .nes. "")
  1749. X$ Then 
  1750. X$   GoSub 'P1'
  1751. X$ Else
  1752. X$   GoSub lib
  1753. X$   GoSub destest
  1754. X$   GoSub rpw
  1755. X$   GoSub speed
  1756. X$   GoSub des
  1757. X$ EndIF
  1758. X$!
  1759. X$ Exit
  1760. X$!
  1761. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1762. X$!
  1763. X$DEFINES:
  1764. X$ OPT_FILE := "VAX_LINKER_OPTIONS.OPT"
  1765. X$!
  1766. X$ CC_OPTS := "/NODebug/OPTimize/NOWarn"
  1767. X$!
  1768. X$ LINK_OPTS := "/NODebug/NOTraceback/Contiguous"
  1769. X$!
  1770. X$ OBJS  = "cbc_cksm.obj,cbc_enc.obj,ecb_enc.obj,pcbc_enc.obj," + -
  1771. X          "qud_cksm.obj,rand_key.obj,read_pwd.obj,set_key.obj,"      + -
  1772. X          "str2key.obj,enc_read.obj,enc_writ.obj,fcrypt.obj,"           + -
  1773. X      "cfb_enc.obj,3ecb_enc.obj,ofb_enc.obj"
  1774. X       
  1775. X       
  1776. X$!
  1777. X$ LIBDES = "cbc_cksm.c,cbc_enc.c,ecb_enc.c,enc_read.c,"           + -
  1778. X           "enc_writ.c,pcbc_enc.c,qud_cksm.c,rand_key.c,"         + -
  1779. X           "read_pwd.c,set_key.c,str2key.c,fcrypt.c,"                + -
  1780. X       "cfb_enc.c,3ecb_enc.c,ofb_enc.c"
  1781. X$ Return
  1782. X$!
  1783. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1784. X$!
  1785. X$LINKER_OPTIONS:
  1786. X$ If (f$search(OPT_FILE) .eqs. "")
  1787. X$ Then
  1788. X$   Create 'OPT_FILE'
  1789. X$DECK
  1790. X! Default system options file to link against the sharable C runtime library
  1791. X!
  1792. XSys$Share:VAXcRTL.exe/Share
  1793. X$EOD
  1794. X$ EndIF
  1795. X$ Return
  1796. X$!
  1797. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1798. X$!
  1799. X$LIB:
  1800. X$ CC 'CC_OPTS' 'LIBDES'
  1801. X$ If (f$search("LIBDES.OLB") .nes. "")
  1802. X$ Then Library /Object /Replace libdes 'OBJS'
  1803. X$ Else Library /Create /Object  libdes 'OBJS'
  1804. X$ EndIF
  1805. X$ Return
  1806. X$!
  1807. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1808. X$!
  1809. X$DESTEST:
  1810. X$ CC 'CC_OPTS' destest
  1811. X$ Link 'link_opts' /Exec=destest destest.obj,libdes/LIBRARY,'opt_file'/Option
  1812. X$ Return
  1813. X$!
  1814. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1815. X$!
  1816. X$RPW:
  1817. X$ CC 'CC_OPTS' rpw
  1818. X$ Link 'link_opts' /Exec=rpw  rpw.obj,libdes/LIBRARY,'opt_file'/Option
  1819. X$ Return
  1820. X$!
  1821. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1822. X$!
  1823. X$SPEED:
  1824. X$ CC 'CC_OPTS' speed
  1825. X$ Link 'link_opts' /Exec=speed speed.obj,libdes/LIBRARY,'opt_file'/Option
  1826. X$ Return
  1827. X$!
  1828. X$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1829. X$!
  1830. X$DES:
  1831. X$ CC 'CC_OPTS' des
  1832. X$ Link 'link_opts' /Exec=des des.obj,libdes/LIBRARY,'opt_file'/Option
  1833. X$ Return
  1834. END_OF_FILE
  1835.   if test 2311 -ne `wc -c <'vms.com'`; then
  1836.     echo shar: \"'vms.com'\" unpacked with wrong size!
  1837.   fi
  1838.   # end of 'vms.com'
  1839. fi
  1840. echo shar: End of archive 4 \(of 5\).
  1841. cp /dev/null ark4isdone
  1842. MISSING=""
  1843. for I in 1 2 3 4 5 ; do
  1844.     if test ! -f ark${I}isdone ; then
  1845.     MISSING="${MISSING} ${I}"
  1846.     fi
  1847. done
  1848. if test "${MISSING}" = "" ; then
  1849.     echo You have unpacked all 5 archives.
  1850.     rm -f ark[1-9]isdone
  1851. else
  1852.     echo You still must unpack the following archives:
  1853.     echo "        " ${MISSING}
  1854. fi
  1855. exit 0
  1856. exit 0 # Just in case...
  1857.