home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / libdes / part02 < prev    next >
Encoding:
Internet Message Format  |  1992-04-03  |  48.4 KB

  1. From: eay@psych.psy.uq.oz.au (Eric Young)
  2. Newsgroups: comp.sources.misc
  3. Subject: v29i044: libdes - DES encryption library, Part02/04
  4. Message-ID: <1992Apr3.224108.29579@aber.ac.uk>
  5. Date: 3 Apr 92 22:41:08 GMT
  6. Approved: aem@aber.ac.uk
  7. X-Md4-Signature: e275604d77dcfb04f30ce3736e9acb73
  8.  
  9. Submitted-by: eay@psych.psy.uq.oz.au (Eric Young)
  10. Posting-number: Volume 29, Issue 44
  11. Archive-name: libdes/part02
  12. Environment: UNIX
  13.  
  14. #! /bin/sh
  15. # it by saving it into a file and typing "sh file".  To overwrite existing
  16. # files, type "sh file -c".  You can also feed this as standard input via
  17. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  18. # will see the following message at the end:
  19. #        "End of archive 2 (of 4)."
  20. # Contents:  des.c des_crypt.man destest.c set_key.c sk.h sp.h
  21. #   testdes.pl
  22. # Wrapped by aem@aberfa on Wed Apr  1 15:53:23 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'des.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'des.c'\"
  26. else
  27. echo shar: Extracting \"'des.c'\" \(4336 characters\)
  28. sed "s/^X//" >'des.c' <<'END_OF_FILE'
  29. X/* des.c */
  30. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  31. X#include <stdio.h>
  32. X#include <sys/types.h>
  33. X#include <sys/stat.h>
  34. X#include "des.h"
  35. X
  36. X#define VERIFY  1
  37. X#define KEYSIZ    8
  38. Xchar key[KEYSIZ+1];
  39. Xint encrypt;
  40. Xchar *in=NULL,*out=NULL;
  41. XFILE *IN,*OUT;
  42. X
  43. Xint eflag,dflag,kflag,bflag,fflag,sflag,error;
  44. X
  45. Xmain(argc,argv)
  46. Xint argc;
  47. Xchar *argv[];
  48. X    {
  49. X    int i;
  50. X    struct stat ins,outs;
  51. X
  52. X    eflag=dflag=kflag=bflag=fflag=sflag=0,error=0;
  53. X    memset(key,0,sizeof(key));
  54. X
  55. X    for (i=1; i<argc; i++)
  56. X        {
  57. X        if ((argv[i][0] == '-') && (argv[i][1] != '\0') &&
  58. X            (argv[i][2] == '\0'))
  59. X            {
  60. X            switch (argv[i][1])
  61. X                {
  62. X            case 'e':
  63. X                eflag=1;
  64. X                break;
  65. X            case 'd':
  66. X                dflag=1;
  67. X                break;
  68. X            case 'b':
  69. X                bflag=1;
  70. X                break;
  71. X            case 'f':
  72. X                fflag=1;
  73. X                break;
  74. X            case 's':
  75. X                sflag=1;
  76. X                break;
  77. X            case 'k':
  78. X                kflag=1;
  79. X                if ((i+1) == argc)
  80. X                    {
  81. X                    fputs("must have a key with the -k option\n",stderr);
  82. X                    error=1;
  83. X                    }
  84. X                else
  85. X                    {
  86. X                    int j;
  87. X
  88. X                    i++;
  89. X                    strncpy(key,argv[i],KEYSIZ);
  90. X                    for (j=strlen(argv[i])-1; j>=0; j--)
  91. X                        argv[i][j]='\0';
  92. X                    }
  93. X                break;
  94. X            default:
  95. X                fprintf(stderr,"'%s' unknown flag\n",argv[i]);
  96. X                error=1;
  97. X                break;
  98. X                }
  99. X            }
  100. X        else
  101. X            {
  102. X            if (in == NULL)
  103. X                in=argv[i];
  104. X            else if (out == NULL)
  105. X                out=argv[i];
  106. X            else
  107. X                error=1;
  108. X            }
  109. X        }
  110. X    if (error) usage();
  111. X    if ((eflag+dflag) == 1)
  112. X        {
  113. X        if (eflag) encrypt=DES_ENCRYPT;
  114. X        if (dflag) encrypt=DES_DECRYPT;
  115. X        }
  116. X    else
  117. X        usage();
  118. X
  119. X    if (    (in != NULL) &&
  120. X        (out != NULL) &&
  121. X        (stat(in,&ins) != -1) &&
  122. X        (stat(out,&outs) != -1) &&
  123. X        (ins.st_dev == outs.st_dev) &&
  124. X        (ins.st_ino == outs.st_ino))
  125. X            {
  126. X            fputs("input and output file are the same\n",stderr);
  127. X            exit(3);
  128. X            }
  129. X
  130. X    if (!kflag)
  131. X        if (des_read_pw_string(key,KEYSIZ+1,"Enter key:",eflag?VERIFY:0))
  132. X            {
  133. X            fputs("password error\n",stderr);
  134. X            exit(2);
  135. X            }
  136. X
  137. X    if (in == NULL)
  138. X        IN=stdin;
  139. X    else if ((IN=fopen(in,"r")) == NULL)
  140. X        {
  141. X        perror("opening input file");
  142. X        exit(4);
  143. X        }
  144. X
  145. X    if (out == NULL)
  146. X        OUT=stdout;
  147. X    else if ((OUT=fopen(out,"w")) == NULL)
  148. X        {
  149. X        perror("opening output file");
  150. X        exit(5);
  151. X        }
  152. X
  153. X    doencryption();
  154. X    fclose(IN);
  155. X    fclose(OUT);
  156. X    exit(0);
  157. X    }
  158. X
  159. Xusage()
  160. X    {
  161. X    fputs("des -e | -d [ -bfs ] [ -k key ] [ input-file [ output-file]\n",
  162. X        stderr);
  163. X    exit(1);
  164. X    }
  165. X
  166. Xdoencryption()
  167. X    {
  168. X    char buf[1024*8+8];
  169. X    char obuf[1024*8+8];
  170. X    des_key_schedule ks;
  171. X    char iv[8];
  172. X    int i,j,k,l,ll,last,ex=0;
  173. X
  174. X    for (i=0; i<KEYSIZ; i++)
  175. X        {
  176. X        l=0;
  177. X        k=key[i];
  178. X        for (j=0; j<8; j++)
  179. X            {
  180. X            if (k&1) l++;
  181. X            k>>=1;
  182. X            }
  183. X        if (l & 1)
  184. X            key[i]=key[i]&0x7f;
  185. X        else
  186. X            key[i]=key[i]|0x80;
  187. X        }
  188. X
  189. X    des_set_key(key,ks);
  190. X    memset(key,0,sizeof(key));
  191. X
  192. X    l=1;
  193. X    /* first read */
  194. X    if (encrypt == DES_ENCRYPT)
  195. X        {
  196. X        for (;;)
  197. X            {
  198. X            l=fread(buf,1,1024*8,IN);
  199. X            if (l < 0)
  200. X                {
  201. X                perror("read error");
  202. X                exit(6);
  203. X                }
  204. X
  205. X            if (feof(IN))
  206. X                {
  207. X                last=l%8;
  208. X                srand(time(NULL));
  209. X                for (i=7-last; i>0; i--)
  210. X                    buf[l++]=rand()&0xff;
  211. X                buf[l++]=last;
  212. X                ex=1;
  213. X                }
  214. X
  215. X            if (bflag)
  216. X                for (i=0; i<l; i+=8)
  217. X                    des_ecb_encrypt(
  218. X                        (des_cblock *)&(buf[i]),
  219. X                        (des_cblock *)&(obuf[i]),
  220. X                        ks,encrypt);
  221. X            else
  222. X                {
  223. X                des_cbc_encrypt(
  224. X                    (des_cblock *)buf,(des_cblock *)obuf,
  225. X                    l,ks,(des_cblock *)iv,encrypt);
  226. X                if (l >= 8) bcopy(&(obuf[l-8]),iv,8);
  227. X                }
  228. X
  229. X            i=0;
  230. X            while (i != l)
  231. X                {
  232. X                j=fwrite(obuf,1,l-i,OUT);
  233. X                if (j == -1)
  234. X                    {
  235. X                    perror("Write error");
  236. X                    exit(7);
  237. X                    }
  238. X                i+=j;
  239. X                }
  240. X            if (feof(IN)) break;
  241. X            }
  242. X        }
  243. X    else /* decrypt */
  244. X        {
  245. X        ex=1;
  246. X        for (;;)
  247. X            {
  248. X            if (ex) {
  249. X                l=fread(buf,1,1024*8,IN);
  250. X                ex=0;
  251. X                }
  252. X            if (l < 0)
  253. X                {
  254. X                perror("read error");
  255. X                exit(6);
  256. X                }
  257. X
  258. X            if (bflag)
  259. X                for (i=0; i<l; i+=8)
  260. X                    des_ecb_encrypt(
  261. X                        (des_cblock *)&(buf[i]),
  262. X                        (des_cblock *)&(obuf[i]),
  263. X                        ks,encrypt);
  264. X            else
  265. X                {
  266. X                des_cbc_encrypt(
  267. X                    (des_cblock *)buf,(des_cblock *)obuf,
  268. X                    l,ks,(des_cblock *)iv,encrypt);
  269. X                if (l >= 8) bcopy(&(buf[l-8]),iv,8);
  270. X                }
  271. X
  272. X            if (!ex) ll=fread(buf,1,1024*8,IN);
  273. X            if (feof(IN) && (ll == 0))
  274. X                {
  275. X                last=obuf[l-1];
  276. X                if ((last > 7) || (last < 0))
  277. X                    {
  278. X                    fputs("The file was not decrypted correctly.\n",
  279. X                        stderr);
  280. X                    exit(8);
  281. X                    }
  282. X                l=l-8+last;
  283. X                }
  284. X            i=0;
  285. X            while (i != l)
  286. X                {
  287. X                j=fwrite(obuf,1,l-i,OUT);
  288. X                if (j == -1)
  289. X                    {
  290. X                    perror("Write error");
  291. X                    exit(7);
  292. X                    }
  293. X                i+=j;
  294. X                }
  295. X            l=ll;
  296. X            if ((l == 0) && feof(IN)) break;
  297. X            }
  298. X        }
  299. X    }
  300. END_OF_FILE
  301. if test 4336 -ne `wc -c <'des.c'`; then
  302.     echo shar: \"'des.c'\" unpacked with wrong size!
  303. fi
  304. # end of 'des.c'
  305. fi
  306. if test -f 'des_crypt.man' -a "${1}" != "-c" ; then 
  307.   echo shar: Will not clobber existing file \"'des_crypt.man'\"
  308. else
  309. echo shar: Extracting \"'des_crypt.man'\" \(8756 characters\)
  310. sed "s/^X//" >'des_crypt.man' <<'END_OF_FILE'
  311. X.TH DES_CRYPT 3 
  312. X.SH NAME
  313. Xdes_read_password, des_string_to_key, des_read_pw_string,
  314. Xdes_random_key, des_set_key,
  315. Xdes_key_sched, des_ecb_encrypt, des_cbc_encrypt,
  316. Xdes_pcbc_encrypt, des_cbc_cksum, des_quad_cksum,
  317. Xdes_enc_read, des_enc_write, des_set_odd_parity,
  318. Xdes_is_weak_key, crypt \- (non USA) DES encryption
  319. X.SH SYNOPSIS
  320. X.nf
  321. X.nj
  322. X.ft B
  323. X#include <des.h>
  324. X.PP
  325. X.B int des_read_password(key,prompt,verify)
  326. Xdes_cblock *key;
  327. Xchar *prompt;
  328. Xint verify;
  329. X.PP
  330. X.B int des_string_to_key(str,key)
  331. Xchar *str;
  332. Xdes_cblock *key;
  333. X.PP
  334. X.B int des_read_pw_string(buf,length,prompt,verify)
  335. Xchar *buf;
  336. Xint length;
  337. Xchar *prompt;
  338. Xint verify;
  339. X.PP
  340. X.B int des_random_key(key)
  341. Xdes_cblock *key;
  342. X.PP
  343. X.B int des_set_key(key,schedule)
  344. Xdes_cblock *key;
  345. Xdes_key_schedule schedule;
  346. X.PP
  347. X.B int des_key_sched(key,schedule)
  348. Xdes_cblock *key;
  349. Xdes_key_schedule schedule;
  350. X.PP
  351. X.B int des_ecb_encrypt(input,output,schedule,encrypt)
  352. Xdes_cblock *input;
  353. Xdes_cblock *output;
  354. Xdes_key_schedule schedule;
  355. Xint encrypt;
  356. X.PP
  357. X.B int des_cbc_encrypt(input,output,length,schedule,ivec,encrypt)
  358. Xdes_cblock *input;
  359. Xdes_cblock *output;
  360. Xlong length;
  361. Xdes_key_schedule schedule;
  362. Xdes_cblock *ivec;
  363. Xint encrypt;
  364. X.PP
  365. X.B int des_pcbc_encrypt(input,output,length,schedule,ivec,encrypt)
  366. Xdes_cblock *input;
  367. Xdes_cblock *output;
  368. Xlong length;
  369. Xdes_key_schedule schedule;
  370. Xdes_cblock *ivec;
  371. Xint encrypt;
  372. X.PP
  373. X.B unsigned long des_cbc_cksum(input,output,length,schedule,ivec)
  374. Xdes_cblock *input;
  375. Xdes_cblock *output;
  376. Xlong length;
  377. Xdes_key_schedule schedule;
  378. Xdes_cblock *ivec;
  379. X.PP
  380. X.B unsigned long des_quad_cksum(input,output,length,out_count,seed)
  381. Xdes_cblock *input;
  382. Xdes_cblock *output;
  383. Xlong length;
  384. Xint out_count;
  385. Xdes_cblock *seed;
  386. X.PP
  387. X.B int des_check_key;
  388. X.PP
  389. X.B int des_enc_read(fd,buf,len,sched,iv)
  390. Xint fd;
  391. Xchar *buf;
  392. Xint len;
  393. Xdes_key_schedule sched;
  394. Xdes_cblock *iv;
  395. X.PP
  396. X.B int des_enc_write(fd,buf,len,sched,iv)
  397. Xint fd;
  398. Xchar *buf;
  399. Xint len;
  400. Xdes_key_schedule sched;
  401. Xdes_cblock *iv;
  402. X.PP
  403. X.B extern int des_rw_mode;
  404. X.PP
  405. X.B void des_set_odd_parity(key)
  406. Xdes_cblock *key;
  407. X.PP
  408. X.B int des_is_weak_key(key)
  409. Xdes_cblock *key;
  410. X.PP
  411. X.B char *crypt(passwd,salt)
  412. Xchar *passwd;
  413. Xchar *salt;
  414. X.PP
  415. X.fi
  416. X.SH DESCRIPTION
  417. XThis library contains a fast implementation of the DES encryption
  418. Xalgorithm.
  419. X.PP
  420. XThere are two phases to the use of DES encryption.
  421. XThe first is the generation of a
  422. X.I des_key_schedule
  423. Xfrom a key,
  424. Xthe second is the actual encryption.
  425. XA des key is of type
  426. X.I des_cblock.
  427. XThis type is made from 8 characters with odd parity.
  428. XThe least significant bit in the character is the parity bit.
  429. XThe key schedule is an expanded form of the key; it is used to speed the
  430. Xencryption process.
  431. X.PP
  432. X.I des_read_password
  433. Xwrites the string specified by prompt to the standard output,
  434. Xturns off echo and reads an input string from standard input
  435. Xuntil terminated with a newline.
  436. XIf verify is non-zero, it prompts and reads input again and verifies
  437. Xthat both entered passwords are the same.
  438. XThe entered string is converted into a des key by using the
  439. X.I des_string_to_key
  440. Xroutine.
  441. XThe new key is placed in the
  442. X.I des_cblock
  443. Xthat was passed (by reference) to the routine.
  444. XIf there were no errors,
  445. X.I des_read_password
  446. Xreturns 0,
  447. X-1 is returned if there was a terminal error and 1 is returned
  448. Xany other error.
  449. X.PP
  450. X.I des_read_pw_string
  451. Xis called by
  452. X.I des_read_password
  453. Xto read and verify a string from stdin.
  454. XThe string is returned in
  455. X.I buf.
  456. XThe size of but is passed to the routine via the
  457. X.I length
  458. Xparameter.
  459. X.PP
  460. X.I des_string_to_key
  461. Xconverts a string into a valid des key.
  462. X.PP
  463. X.I des_random_key
  464. Xreturns a random key that is made of a combination of process id,
  465. Xtime and an increasing counter.
  466. X.PP
  467. XBefore a des key can be used it is converted into a
  468. X.I des_key_schedule
  469. Xvia the
  470. X.I des_set_key
  471. Xroutine.
  472. XIf the
  473. X.I des_check_key
  474. Xflag is non-zero,
  475. X.I des_set_key
  476. Xwill check that the key passed is of odd parity and is not a week or
  477. Xsemi-weak key.
  478. XIf the parity is wrong,
  479. Xthen -1 is returned.
  480. XIf the key is a weak key,
  481. Xthen -2 is returned.
  482. XIf an error is returned,
  483. Xthe key schedule is not generated.
  484. X.PP
  485. X.I des_key_sched
  486. Xis another name for the
  487. X.I des_set_key
  488. Xfunction.
  489. X.PP
  490. XThe following routines all operate on an input and output stream of
  491. X.I des_cblock's.
  492. X.PP
  493. X.I des_ecb_encrypt
  494. Xis the basic DES encryption routine that encrypts or decrypts a single 8-byte
  495. X.I des_cblock
  496. Xin
  497. X.I electronic code book
  498. Xmode.
  499. XIt always transforms the input data, pointed to by
  500. X.I input,
  501. Xinto the output data,
  502. Xpointed to by the
  503. X.I output
  504. Xargument.
  505. XIf the
  506. X.I encrypt
  507. Xargument is non-zero (DES_ENCRYPT),
  508. Xthe
  509. X.I input
  510. X(cleartext) is encrypted in to the
  511. X.I output
  512. X(ciphertext) using the key_schedule specified by the
  513. X.I schedule
  514. Xargument,
  515. Xpreviously set via
  516. X.I des_set_key.
  517. XIf
  518. X.I encrypt
  519. Xis zero (DES_DECRYPT),
  520. Xthe
  521. X.I input
  522. X(now ciphertext)
  523. Xis decrypted into the
  524. X.I output
  525. X(now cleartext).
  526. XInput and output may overlap.
  527. XNo meaningful value is returned.
  528. X.PP
  529. X.I des_cbc_encrypt
  530. Xencrypts/decrypts using the
  531. X.I cipher-block-chaining
  532. Xmode of DES.
  533. XIf the
  534. X.I encrypt
  535. Xargument is non-zero,
  536. Xthe routine cipher-block-chain encrypts the cleartext data pointed to by the
  537. X.I input
  538. Xargument into the ciphertext pointed to by the
  539. X.I output
  540. Xargument,
  541. Xusing the key schedule provided by the
  542. X.I schedule
  543. Xargument,
  544. Xand initialization vector provided by the
  545. X.I ivec
  546. Xargument.
  547. XIf the
  548. X.I length
  549. Xargument is not an integral multiple of eight bytes, 
  550. Xthe last block is copied to a temporary area and zero filled.
  551. XThe output is always
  552. Xan integral multiple of eight bytes.
  553. X.PP
  554. X.I des_pcbc_encrypt
  555. Xencrypt/decrypts using a modified block chaining mode.
  556. XIt provides better error propagation characteristics than cbc
  557. Xencryption.
  558. X.PP
  559. X.I des_cbc_cksum
  560. Xproduces an 8 byte checksum based on the input stream (via cbc encryption).
  561. XThe last 4 bytes of the checksum is returned and the complete 8 bytes is
  562. Xplaced in
  563. X.I output.
  564. X.PP
  565. X.I des_quad_cksum
  566. Xreturns a 4 byte checksum from the input bytes.
  567. XThe algorithm can be iterated over the input,
  568. Xdepending on
  569. X.I out_count,
  570. X1, 2, 3 or 4 times.
  571. XIf
  572. X.I output
  573. Xis non-NULL,
  574. Xthe 4 bytes generated by each pass are written into
  575. X.I output.
  576. X.PP
  577. X.I des_enc_write
  578. Xis used to write
  579. X.I len
  580. Xbytes
  581. Xto file descriptor
  582. X.I fd
  583. Xfrom buffer
  584. X.I buf.
  585. XThe data is encrypted via
  586. X.I pcbc_encrypt
  587. X(default) using
  588. X.I sched
  589. Xfor the key and
  590. X.I iv
  591. Xas a starting vector.
  592. XThe actual data send down
  593. X.I fd
  594. Xconsists of 4 bytes (in network byte order) containing the length of the
  595. Xfollowing encrypted data.  The encrypted data then follows, padded with random
  596. Xdata out to a multiple of 8 bytes.
  597. X.PP
  598. X.I des_enc_read
  599. Xis used to read
  600. X.I len
  601. Xbytes
  602. Xfrom file descriptor
  603. X.I fd
  604. Xinto buffer
  605. X.I buf.
  606. XThe data being read from
  607. X.I fd
  608. Xis assumed to have come from
  609. X.I des_enc_write
  610. Xand is decrypted using
  611. X.I sched
  612. Xfor the key schedule and
  613. X.I iv
  614. Xfor the initial vector.
  615. XThe
  616. X.I des_enc_read/des_enc_write
  617. Xpair can be used to read/write to files, pipes and sockets.
  618. XI have used them in implementing a version of rlogin in which all
  619. Xdata is encrypted.
  620. X.PP
  621. X.I des_rw_mode
  622. Xis used to specify the encryption mode to use with 
  623. X.I des_enc_read
  624. Xand 
  625. X.I des_end_write.
  626. XIf set to
  627. X.I DES_PCBC_MODE
  628. X(the defualt), des_pcbc_encrypt is used.
  629. XIf set to
  630. X.I DES_CBC_MODE
  631. Xdes_cbc_encrypt is used.
  632. XThese two routines and the variable are not part of the normal MIT library.
  633. X.PP
  634. X.I des_set_odd_parity
  635. Xsets the parity of the passed
  636. X.I key
  637. Xto odd.  This routine is not part of the standard MIT library.
  638. X.PP
  639. X.I des_is_weak_key
  640. Xreturns 1 is the passed key is a weak key (pick again :-),
  641. X0 if it is ok.
  642. XThis routine is not part of the standard MIT library.
  643. X.PP
  644. X.I crypt
  645. Xis a replacement for the normal system crypt.
  646. XIt is much faster than the system crypt.
  647. X.PP
  648. X.SH FILES
  649. X/usr/include/des.h
  650. X.br
  651. X/usr/lib/libdes.a
  652. X.PP
  653. XThe encryption routines have been tested on VAX,
  654. Xsun 3 (68020), sun 4 (Sparc), DECstation 3100 (MIPS R2000).
  655. X.PP
  656. X.SH BUGS
  657. X.PP
  658. XIf you think this manual is sparse,
  659. Xread the des_crypt(3) manual from the MIT kerberos (or bones outside
  660. Xof the USA) distribution.
  661. X.PP
  662. X.I des_read_pw_string
  663. Xonly really works under bsd based systems.
  664. X.PP
  665. X.I des_string_to_key
  666. Xis almost definitely different from the MIT version since there are lots
  667. Xof fun ways to implement one-way encryption of a text string.
  668. X.PP
  669. X.I des_quad_cksum
  670. Xis almost definitely different from the MIT version since the algorithm
  671. Xcalls for 64-bit multiplication.
  672. XMy fudge is probably different from MIT's
  673. X.PP
  674. XThe routines are optimized for 32 bit machines and so are not efficient
  675. Xon IBM PCs.
  676. X.SH AUTHOR
  677. XEric Young (eay@psych.psy.uq.oz.au),
  678. XPsychology Department,
  679. XUniversity of Queensland, Australia.
  680. X.SH RESTRICTIONS
  681. XThere are none.
  682. XSince I am not a US citizen,
  683. Xthis software can
  684. Xbe freely exported outside of the US without a special license
  685. Xfrom the US Dept of Commerce :-).
  686. XThis has been implemented from FIPS publication 46 which I has
  687. Xbeen in my local library for several years.
  688. END_OF_FILE
  689. if test 8756 -ne `wc -c <'des_crypt.man'`; then
  690.     echo shar: \"'des_crypt.man'\" unpacked with wrong size!
  691. fi
  692. # end of 'des_crypt.man'
  693. fi
  694. if test -f 'destest.c' -a "${1}" != "-c" ; then 
  695.   echo shar: Will not clobber existing file \"'destest.c'\"
  696. else
  697. echo shar: Extracting \"'destest.c'\" \(8656 characters\)
  698. sed "s/^X//" >'destest.c' <<'END_OF_FILE'
  699. X/* destest.c */
  700. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  701. X#include <stdio.h>
  702. X#include "des_local.h"
  703. X/* tisk tisk - the test keys don't all have odd parity :-( */
  704. X
  705. X/* test data */
  706. X#define NUM_TESTS 34
  707. Xstatic unsigned char key_data[NUM_TESTS][8]={
  708. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  709. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  710. X    0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  711. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  712. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  713. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  714. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  715. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
  716. X    0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57,
  717. X    0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E,
  718. X    0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86,
  719. X    0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E,
  720. X    0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6,
  721. X    0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE,
  722. X    0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6,
  723. X    0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE,
  724. X    0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16,
  725. X    0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F,
  726. X    0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46,
  727. X    0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E,
  728. X    0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76,
  729. X    0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07,
  730. X    0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F,
  731. X    0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7,
  732. X    0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF,
  733. X    0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6,
  734. X    0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF,
  735. X    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  736. X    0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E,
  737. X    0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE,
  738. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  739. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  740. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  741. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
  742. X
  743. Xstatic unsigned char plain_data[NUM_TESTS][8]={
  744. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  745. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  746. X    0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  747. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  748. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  749. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  750. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  751. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  752. X    0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42,
  753. X    0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA,
  754. X    0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72,
  755. X    0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A,
  756. X    0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2,
  757. X    0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A,
  758. X    0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2,
  759. X    0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A,
  760. X    0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02,
  761. X    0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A,
  762. X    0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32,
  763. X    0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA,
  764. X    0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62,
  765. X    0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2,
  766. X    0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA,
  767. X    0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92,
  768. X    0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A,
  769. X    0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2,
  770. X    0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A,
  771. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  772. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  773. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  774. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  775. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  776. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  777. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  778. X
  779. Xstatic unsigned char cipher_data[NUM_TESTS][8]={
  780. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  781. X    0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58,
  782. X    0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B,
  783. X    0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33,
  784. X    0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D,
  785. X    0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD,
  786. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  787. X    0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4,
  788. X    0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B,
  789. X    0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71,
  790. X    0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A,
  791. X    0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A,
  792. X    0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95,
  793. X    0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B,
  794. X    0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09,
  795. X    0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A,
  796. X    0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F,
  797. X    0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88,
  798. X    0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77,
  799. X    0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A,
  800. X    0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56,
  801. X    0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56,
  802. X    0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56,
  803. X    0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC,
  804. X    0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A,
  805. X    0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41,
  806. X    0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93,
  807. X    0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00,
  808. X    0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06,
  809. X    0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7,
  810. X    0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51,
  811. X    0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE,
  812. X    0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D,
  813. X    0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2};
  814. X
  815. Xstatic unsigned char cbc_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  816. Xstatic unsigned char cbc_iv[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
  817. Xstatic unsigned char cbc_data[40]="7654321 Now is the time for ";
  818. X
  819. Xstatic unsigned char cbc_ok[32]={
  820. X    0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
  821. X    0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
  822. X    0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
  823. X    0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
  824. X
  825. Xstatic unsigned char pcbc_ok[32]={
  826. X    0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
  827. X    0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
  828. X    0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
  829. X    0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
  830. X
  831. Xstatic unsigned char cksum_ok[8]={
  832. X    0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
  833. X
  834. Xchar *pt();
  835. X
  836. Xmain()
  837. X    {
  838. X    int i,j;
  839. X    des_cblock in,out,outin;
  840. X    des_key_schedule ks;
  841. X    unsigned char cbc_in[40],cbc_out[40];
  842. X    ulong cs;
  843. X    char *str;
  844. X
  845. X    printf("Doing ecb\n");
  846. X    for (i=0; i<NUM_TESTS; i++)
  847. X        {
  848. X        if ((j=key_sched((C_Block *)(key_data[i]),ks)) != 0)
  849. X            printf("Key error %2d:%d\n",i+1,j);
  850. X        bcopy(plain_data[i],in,8);
  851. X        bzero(out,8);
  852. X        bzero(outin,8);
  853. X        des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT);
  854. X        des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT);
  855. X
  856. X        if (bcmp(out,cipher_data[i],8) != 0)
  857. X            {
  858. X            printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
  859. X                i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
  860. X                pt(out));
  861. X            }
  862. X        if (bcmp(in,outin,8) != 0)
  863. X            {
  864. X            printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
  865. X                i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
  866. X            }
  867. X        }
  868. X
  869. X    printf("Doing cbc\n");
  870. X    if ((j=key_sched((C_Block *)cbc_key,ks)) != 0)
  871. X        printf("Key error %2d:%d\n",i+1,j);
  872. X    bzero(cbc_out,40);
  873. X    bzero(cbc_in,40);
  874. X    des_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
  875. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_ENCRYPT);
  876. X    if (bcmp(cbc_out,cbc_ok,32) != 0)
  877. X        printf("cbc_encrypt encrypt error\n");
  878. X    des_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
  879. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_DECRYPT);
  880. X    if (bcmp(cbc_in,cbc_data,32) != 0)
  881. X        printf("cbc_encrypt decrypt error\n");
  882. X
  883. X    printf("Doing pcbc\n");
  884. X    if ((j=key_sched((C_Block *)cbc_key,ks)) != 0)
  885. X        printf("Key error %2d:%d\n",i+1,j);
  886. X    bzero(cbc_out,40);
  887. X    bzero(cbc_in,40);
  888. X    des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
  889. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_ENCRYPT);
  890. X    if (bcmp(cbc_out,pcbc_ok,32) != 0)
  891. X        printf("pcbc_encrypt encrypt error\n");
  892. X    des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
  893. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_DECRYPT);
  894. X    if (bcmp(cbc_in,cbc_data,32) != 0)
  895. X        printf("pcbc_encrypt decrypt error\n");
  896. X
  897. X    printf("Doing cbc_cksum\n");
  898. X    des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cbc_out,
  899. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
  900. X    if (bcmp(cbc_out,cksum_ok,8) != 0)
  901. X        printf("cbc_cksum error\n");
  902. X    printf("Doing quad_cksum\n");
  903. X    cs=quad_cksum((C_Block *)cbc_data,NULL,(long)strlen(cbc_data),1,
  904. X        (C_Block *)cbc_iv);
  905. X    if (cs != 0x327eba8d)
  906. X        printf("quad_cksum error, %08x should be 327eba8d\n",cs);
  907. X
  908. X    printf("input word alignment test");
  909. X    for (i=0; i<4; i++)
  910. X        {
  911. X        printf(" %d",i);
  912. X        des_cbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in,
  913. X            (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,
  914. X            DES_ENCRYPT);
  915. X        }
  916. X    printf("\noutput word alignment test");
  917. X    for (i=0; i<4; i++)
  918. X        {
  919. X        printf(" %d",i);
  920. X        des_cbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]),
  921. X            (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,
  922. X            DES_ENCRYPT);
  923. X        }
  924. X    printf("\n");
  925. X    printf("fast crypt test ");
  926. X    str=crypt("testing","ef");
  927. X    if (strcmp("efGnQx2725bI2",str) != 0)
  928. X        printf("fast crypt error, %x should be efGnQx2725bI2\n",str);
  929. X    str=crypt("bca76;23","yA");
  930. X    if (strcmp("yA1Rp/1hZXIJk",str) != 0)
  931. X        printf("fast crypt error, %x should be yA1Rp/1hZXIJk\n",str);
  932. X    printf("\n");
  933. X    exit(0);
  934. X    }
  935. X
  936. Xchar *pt(p)
  937. Xunsigned char *p;
  938. X    {
  939. X    char *ret;
  940. X    int i;
  941. X    static char *f="0123456789ABCDEF";
  942. X
  943. X    ret=(char *)malloc(17);
  944. X    for (i=0; i<8; i++)
  945. X        {
  946. X        ret[i*2]=f[(p[i]>>4)&0xf];
  947. X        ret[i*2+1]=f[p[i]&0xf];
  948. X        }
  949. X    ret[16]='\0';
  950. X    return(ret);
  951. X    }
  952. X    
  953. END_OF_FILE
  954. if test 8656 -ne `wc -c <'destest.c'`; then
  955.     echo shar: \"'destest.c'\" unpacked with wrong size!
  956. fi
  957. # end of 'destest.c'
  958. fi
  959. if test -f 'set_key.c' -a "${1}" != "-c" ; then 
  960.   echo shar: Will not clobber existing file \"'set_key.c'\"
  961. else
  962. echo shar: Extracting \"'set_key.c'\" \(4144 characters\)
  963. sed "s/^X//" >'set_key.c' <<'END_OF_FILE'
  964. X/* set_key.c */
  965. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  966. X/* set_key.c v 1.4 eay 24/9/91
  967. X * 1.4 Speed up by 400% :-)
  968. X * 1.3 added register declarations.
  969. X * 1.2 unrolled make_key_sched a bit more
  970. X * 1.1 added norm_expand_bits
  971. X * 1.0 First working version
  972. X */
  973. X#include "des_local.h"
  974. X#include "podd.h"
  975. X#include "sk.h"
  976. X
  977. Xstatic int check_parity();
  978. X
  979. Xint des_check_key=0;
  980. X
  981. Xvoid des_set_odd_parity(key)
  982. Xdes_cblock *key;
  983. X    {
  984. X    int i;
  985. X
  986. X    for (i=0; i<DES_KEY_SZ; i++)
  987. X        (*key)[i]=odd_parity[(*key)[i]];
  988. X    }
  989. X
  990. Xstatic int check_parity(key)
  991. Xdes_cblock *key;
  992. X    {
  993. X    int i;
  994. X
  995. X    for (i=0; i<DES_KEY_SZ; i++)
  996. X        {
  997. X        if ((*key)[i] != odd_parity[(*key)[i]])
  998. X            return(0);
  999. X        }
  1000. X    return(1);
  1001. X    }
  1002. X
  1003. X/* Weak and semi week keys as take from
  1004. X * %A D.W. Davies
  1005. X * %A W.L. Price
  1006. X * %T Security for Computer Networks
  1007. X * %I John Wiley & Sons
  1008. X * %D 1984
  1009. X * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference
  1010. X * (and actual cblock values).
  1011. X */
  1012. X#define NUM_WEAK_KEY    16
  1013. Xstatic des_cblock weak_keys[NUM_WEAK_KEY]={
  1014. X    /* weak keys */
  1015. X    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1016. X    0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
  1017. X    0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
  1018. X    0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,
  1019. X    /* semi-weak keys */
  1020. X    0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,
  1021. X    0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,
  1022. X    0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1,
  1023. X    0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E,
  1024. X    0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,
  1025. X    0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01,
  1026. X    0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE,
  1027. X    0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,
  1028. X    0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,
  1029. X    0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01,
  1030. X    0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE,
  1031. X    0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1};
  1032. X
  1033. Xint des_is_weak_key(key)
  1034. Xdes_cblock *key;
  1035. X    {
  1036. X    ulong *lp;
  1037. X    register ulong l,r;
  1038. X    int i;
  1039. X
  1040. X    c2l(key,l);
  1041. X    c2l(key,r);
  1042. X    /* the weak_keys bytes should be aligned */
  1043. X    lp=(ulong *)weak_keys;
  1044. X    for (i=0; i<NUM_WEAK_KEY; i++)
  1045. X        {
  1046. X        if ((l == lp[0]) && (r == lp[1]))
  1047. X            return(1);
  1048. X        lp+=2;
  1049. X        }
  1050. X    return(0);
  1051. X    }
  1052. X
  1053. X/* See ecb_encrypt.c for a pseudo description of these macros. */
  1054. X#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
  1055. X    (b)^=(t),\
  1056. X    (a)^=((t)<<(n)))
  1057. X
  1058. X#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
  1059. X    (a)=(a)^(t)^(t>>(16-(n))))\
  1060. X
  1061. Xstatic char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
  1062. X
  1063. X/* return 0 if key parity is odd (correct),
  1064. X * return -1 if key parity error,
  1065. X * return -2 if illegal weak key.
  1066. X */
  1067. Xint des_set_key(key,schedule)
  1068. Xdes_cblock *key;
  1069. Xdes_key_schedule schedule;
  1070. X    {
  1071. X    register ulong c,d,t,s;
  1072. X    register uchar *in;
  1073. X    register ulong *k;
  1074. X    register int i;
  1075. X
  1076. X    if (des_check_key)
  1077. X        {
  1078. X        if (!check_parity(key))
  1079. X            return(-1);
  1080. X
  1081. X        if (des_is_weak_key(key))
  1082. X            return(-2);
  1083. X        }
  1084. X
  1085. X    k=(ulong *)schedule;
  1086. X    in=(uchar *)key;
  1087. X
  1088. X    c2l(in,c);
  1089. X    c2l(in,d);
  1090. X
  1091. X    /* do PC1 in 60 simple operations */ 
  1092. X    PERM_OP(d,c,t,4,0x0f0f0f0f);
  1093. X    HPERM_OP(c,t,-2, 0xcccc0000);
  1094. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  1095. X    HPERM_OP(c,t, 8, 0x00ff0000);
  1096. X    HPERM_OP(c,t,-1, 0xaaaa0000);
  1097. X    HPERM_OP(d,t,-8, 0xff000000);
  1098. X    HPERM_OP(d,t, 8, 0x00ff0000);
  1099. X    HPERM_OP(d,t, 2, 0x33330000);
  1100. X    d=((d&0x00aa00aa)<<7)|((d&0x55005500)>>7)|(d&0xaa55aa55);
  1101. X    d=(d>>8)|((c&0xf0000000)>>4);
  1102. X    c&=0x0fffffff;
  1103. X
  1104. X    for (i=0; i<ITERATIONS; i++)
  1105. X        {
  1106. X        if (shifts2[i])
  1107. X            { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
  1108. X        else
  1109. X            { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
  1110. X        c&=0x0fffffff;
  1111. X        d&=0x0fffffff;
  1112. X        /* could be a few less shifts but I am to lazy at this
  1113. X         * point in time to investigate */
  1114. X        s=    des_skb[0][ (c    )&0x3f                ]|
  1115. X            des_skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
  1116. X            des_skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
  1117. X            des_skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
  1118. X                                  ((c>>22)&0x38)];
  1119. X        t=    des_skb[4][ (d    )&0x3f                ]|
  1120. X            des_skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
  1121. X            des_skb[6][ (d>>15)&0x3f                ]|
  1122. X            des_skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
  1123. X
  1124. X        /* table contained 0213 4657 */
  1125. X        *(k++)=((t<<16)|(s&0x0000ffff));
  1126. X        s=     ((s>>16)|(t&0xffff0000));
  1127. X        
  1128. X        s=(s<<4)|(s>>28);
  1129. X        *(k++)=s;
  1130. X        }
  1131. X    return(0);
  1132. X    }
  1133. X
  1134. Xint key_sched(key,schedule)
  1135. Xdes_cblock *key;
  1136. Xdes_key_schedule schedule;
  1137. X    {
  1138. X    return(des_set_key(key,schedule));
  1139. X    }
  1140. END_OF_FILE
  1141. if test 4144 -ne `wc -c <'set_key.c'`; then
  1142.     echo shar: \"'set_key.c'\" unpacked with wrong size!
  1143. fi
  1144. # end of 'set_key.c'
  1145. fi
  1146. if test -f 'sk.h' -a "${1}" != "-c" ; then 
  1147.   echo shar: Will not clobber existing file \"'sk.h'\"
  1148. else
  1149. echo shar: Extracting \"'sk.h'\" \(6343 characters\)
  1150. sed "s/^X//" >'sk.h' <<'END_OF_FILE'
  1151. X/* sk.h */
  1152. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  1153. Xstatic ulong des_skb[8][64]={
  1154. X/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  1155. X0x00000000,0x00000010,0x20000000,0x20000010,
  1156. X0x00010000,0x00010010,0x20010000,0x20010010,
  1157. X0x00000800,0x00000810,0x20000800,0x20000810,
  1158. X0x00010800,0x00010810,0x20010800,0x20010810,
  1159. X0x00000020,0x00000030,0x20000020,0x20000030,
  1160. X0x00010020,0x00010030,0x20010020,0x20010030,
  1161. X0x00000820,0x00000830,0x20000820,0x20000830,
  1162. X0x00010820,0x00010830,0x20010820,0x20010830,
  1163. X0x00080000,0x00080010,0x20080000,0x20080010,
  1164. X0x00090000,0x00090010,0x20090000,0x20090010,
  1165. X0x00080800,0x00080810,0x20080800,0x20080810,
  1166. X0x00090800,0x00090810,0x20090800,0x20090810,
  1167. X0x00080020,0x00080030,0x20080020,0x20080030,
  1168. X0x00090020,0x00090030,0x20090020,0x20090030,
  1169. X0x00080820,0x00080830,0x20080820,0x20080830,
  1170. X0x00090820,0x00090830,0x20090820,0x20090830,
  1171. X/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
  1172. X0x00000000,0x02000000,0x00002000,0x02002000,
  1173. X0x00200000,0x02200000,0x00202000,0x02202000,
  1174. X0x00000004,0x02000004,0x00002004,0x02002004,
  1175. X0x00200004,0x02200004,0x00202004,0x02202004,
  1176. X0x00000400,0x02000400,0x00002400,0x02002400,
  1177. X0x00200400,0x02200400,0x00202400,0x02202400,
  1178. X0x00000404,0x02000404,0x00002404,0x02002404,
  1179. X0x00200404,0x02200404,0x00202404,0x02202404,
  1180. X0x10000000,0x12000000,0x10002000,0x12002000,
  1181. X0x10200000,0x12200000,0x10202000,0x12202000,
  1182. X0x10000004,0x12000004,0x10002004,0x12002004,
  1183. X0x10200004,0x12200004,0x10202004,0x12202004,
  1184. X0x10000400,0x12000400,0x10002400,0x12002400,
  1185. X0x10200400,0x12200400,0x10202400,0x12202400,
  1186. X0x10000404,0x12000404,0x10002404,0x12002404,
  1187. X0x10200404,0x12200404,0x10202404,0x12202404,
  1188. X/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
  1189. X0x00000000,0x00000001,0x00040000,0x00040001,
  1190. X0x01000000,0x01000001,0x01040000,0x01040001,
  1191. X0x00000002,0x00000003,0x00040002,0x00040003,
  1192. X0x01000002,0x01000003,0x01040002,0x01040003,
  1193. X0x00000200,0x00000201,0x00040200,0x00040201,
  1194. X0x01000200,0x01000201,0x01040200,0x01040201,
  1195. X0x00000202,0x00000203,0x00040202,0x00040203,
  1196. X0x01000202,0x01000203,0x01040202,0x01040203,
  1197. X0x08000000,0x08000001,0x08040000,0x08040001,
  1198. X0x09000000,0x09000001,0x09040000,0x09040001,
  1199. X0x08000002,0x08000003,0x08040002,0x08040003,
  1200. X0x09000002,0x09000003,0x09040002,0x09040003,
  1201. X0x08000200,0x08000201,0x08040200,0x08040201,
  1202. X0x09000200,0x09000201,0x09040200,0x09040201,
  1203. X0x08000202,0x08000203,0x08040202,0x08040203,
  1204. X0x09000202,0x09000203,0x09040202,0x09040203,
  1205. X/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
  1206. X0x00000000,0x00100000,0x00000100,0x00100100,
  1207. X0x00000008,0x00100008,0x00000108,0x00100108,
  1208. X0x00001000,0x00101000,0x00001100,0x00101100,
  1209. X0x00001008,0x00101008,0x00001108,0x00101108,
  1210. X0x04000000,0x04100000,0x04000100,0x04100100,
  1211. X0x04000008,0x04100008,0x04000108,0x04100108,
  1212. X0x04001000,0x04101000,0x04001100,0x04101100,
  1213. X0x04001008,0x04101008,0x04001108,0x04101108,
  1214. X0x00020000,0x00120000,0x00020100,0x00120100,
  1215. X0x00020008,0x00120008,0x00020108,0x00120108,
  1216. X0x00021000,0x00121000,0x00021100,0x00121100,
  1217. X0x00021008,0x00121008,0x00021108,0x00121108,
  1218. X0x04020000,0x04120000,0x04020100,0x04120100,
  1219. X0x04020008,0x04120008,0x04020108,0x04120108,
  1220. X0x04021000,0x04121000,0x04021100,0x04121100,
  1221. X0x04021008,0x04121008,0x04021108,0x04121108,
  1222. X/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  1223. X0x00000000,0x10000000,0x00010000,0x10010000,
  1224. X0x00000004,0x10000004,0x00010004,0x10010004,
  1225. X0x20000000,0x30000000,0x20010000,0x30010000,
  1226. X0x20000004,0x30000004,0x20010004,0x30010004,
  1227. X0x00100000,0x10100000,0x00110000,0x10110000,
  1228. X0x00100004,0x10100004,0x00110004,0x10110004,
  1229. X0x20100000,0x30100000,0x20110000,0x30110000,
  1230. X0x20100004,0x30100004,0x20110004,0x30110004,
  1231. X0x00001000,0x10001000,0x00011000,0x10011000,
  1232. X0x00001004,0x10001004,0x00011004,0x10011004,
  1233. X0x20001000,0x30001000,0x20011000,0x30011000,
  1234. X0x20001004,0x30001004,0x20011004,0x30011004,
  1235. X0x00101000,0x10101000,0x00111000,0x10111000,
  1236. X0x00101004,0x10101004,0x00111004,0x10111004,
  1237. X0x20101000,0x30101000,0x20111000,0x30111000,
  1238. X0x20101004,0x30101004,0x20111004,0x30111004,
  1239. X/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
  1240. X0x00000000,0x08000000,0x00000008,0x08000008,
  1241. X0x00000400,0x08000400,0x00000408,0x08000408,
  1242. X0x00020000,0x08020000,0x00020008,0x08020008,
  1243. X0x00020400,0x08020400,0x00020408,0x08020408,
  1244. X0x00000001,0x08000001,0x00000009,0x08000009,
  1245. X0x00000401,0x08000401,0x00000409,0x08000409,
  1246. X0x00020001,0x08020001,0x00020009,0x08020009,
  1247. X0x00020401,0x08020401,0x00020409,0x08020409,
  1248. X0x02000000,0x0A000000,0x02000008,0x0A000008,
  1249. X0x02000400,0x0A000400,0x02000408,0x0A000408,
  1250. X0x02020000,0x0A020000,0x02020008,0x0A020008,
  1251. X0x02020400,0x0A020400,0x02020408,0x0A020408,
  1252. X0x02000001,0x0A000001,0x02000009,0x0A000009,
  1253. X0x02000401,0x0A000401,0x02000409,0x0A000409,
  1254. X0x02020001,0x0A020001,0x02020009,0x0A020009,
  1255. X0x02020401,0x0A020401,0x02020409,0x0A020409,
  1256. X/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
  1257. X0x00000000,0x00000100,0x00080000,0x00080100,
  1258. X0x01000000,0x01000100,0x01080000,0x01080100,
  1259. X0x00000010,0x00000110,0x00080010,0x00080110,
  1260. X0x01000010,0x01000110,0x01080010,0x01080110,
  1261. X0x00200000,0x00200100,0x00280000,0x00280100,
  1262. X0x01200000,0x01200100,0x01280000,0x01280100,
  1263. X0x00200010,0x00200110,0x00280010,0x00280110,
  1264. X0x01200010,0x01200110,0x01280010,0x01280110,
  1265. X0x00000200,0x00000300,0x00080200,0x00080300,
  1266. X0x01000200,0x01000300,0x01080200,0x01080300,
  1267. X0x00000210,0x00000310,0x00080210,0x00080310,
  1268. X0x01000210,0x01000310,0x01080210,0x01080310,
  1269. X0x00200200,0x00200300,0x00280200,0x00280300,
  1270. X0x01200200,0x01200300,0x01280200,0x01280300,
  1271. X0x00200210,0x00200310,0x00280210,0x00280310,
  1272. X0x01200210,0x01200310,0x01280210,0x01280310,
  1273. X/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
  1274. X0x00000000,0x04000000,0x00040000,0x04040000,
  1275. X0x00000002,0x04000002,0x00040002,0x04040002,
  1276. X0x00002000,0x04002000,0x00042000,0x04042000,
  1277. X0x00002002,0x04002002,0x00042002,0x04042002,
  1278. X0x00000020,0x04000020,0x00040020,0x04040020,
  1279. X0x00000022,0x04000022,0x00040022,0x04040022,
  1280. X0x00002020,0x04002020,0x00042020,0x04042020,
  1281. X0x00002022,0x04002022,0x00042022,0x04042022,
  1282. X0x00000800,0x04000800,0x00040800,0x04040800,
  1283. X0x00000802,0x04000802,0x00040802,0x04040802,
  1284. X0x00002800,0x04002800,0x00042800,0x04042800,
  1285. X0x00002802,0x04002802,0x00042802,0x04042802,
  1286. X0x00000820,0x04000820,0x00040820,0x04040820,
  1287. X0x00000822,0x04000822,0x00040822,0x04040822,
  1288. X0x00002820,0x04002820,0x00042820,0x04042820,
  1289. X0x00002822,0x04002822,0x00042822,0x04042822,
  1290. X};
  1291. END_OF_FILE
  1292. if test 6343 -ne `wc -c <'sk.h'`; then
  1293.     echo shar: \"'sk.h'\" unpacked with wrong size!
  1294. fi
  1295. # end of 'sk.h'
  1296. fi
  1297. if test -f 'sp.h' -a "${1}" != "-c" ; then 
  1298.   echo shar: Will not clobber existing file \"'sp.h'\"
  1299. else
  1300. echo shar: Extracting \"'sp.h'\" \(6392 characters\)
  1301. sed "s/^X//" >'sp.h' <<'END_OF_FILE'
  1302. X/* sp.h */
  1303. X/* Copyright (C) 1992 Eric Young - see COPYING for more details */
  1304. Xstatic unsigned long des_SPtrans[8][64]={
  1305. X/* nibble 0 */
  1306. X0x00410100, 0x00010000, 0x40400000, 0x40410100,
  1307. X0x00400000, 0x40010100, 0x40010000, 0x40400000,
  1308. X0x40010100, 0x00410100, 0x00410000, 0x40000100,
  1309. X0x40400100, 0x00400000, 0x00000000, 0x40010000,
  1310. X0x00010000, 0x40000000, 0x00400100, 0x00010100,
  1311. X0x40410100, 0x00410000, 0x40000100, 0x00400100,
  1312. X0x40000000, 0x00000100, 0x00010100, 0x40410000,
  1313. X0x00000100, 0x40400100, 0x40410000, 0x00000000,
  1314. X0x00000000, 0x40410100, 0x00400100, 0x40010000,
  1315. X0x00410100, 0x00010000, 0x40000100, 0x00400100,
  1316. X0x40410000, 0x00000100, 0x00010100, 0x40400000,
  1317. X0x40010100, 0x40000000, 0x40400000, 0x00410000,
  1318. X0x40410100, 0x00010100, 0x00410000, 0x40400100,
  1319. X0x00400000, 0x40000100, 0x40010000, 0x00000000,
  1320. X0x00010000, 0x00400000, 0x40400100, 0x00410100,
  1321. X0x40000000, 0x40410000, 0x00000100, 0x40010100,
  1322. X
  1323. X/* nibble 1 */
  1324. X0x08021002, 0x00000000, 0x00021000, 0x08020000,
  1325. X0x08000002, 0x00001002, 0x08001000, 0x00021000,
  1326. X0x00001000, 0x08020002, 0x00000002, 0x08001000,
  1327. X0x00020002, 0x08021000, 0x08020000, 0x00000002,
  1328. X0x00020000, 0x08001002, 0x08020002, 0x00001000,
  1329. X0x00021002, 0x08000000, 0x00000000, 0x00020002,
  1330. X0x08001002, 0x00021002, 0x08021000, 0x08000002,
  1331. X0x08000000, 0x00020000, 0x00001002, 0x08021002,
  1332. X0x00020002, 0x08021000, 0x08001000, 0x00021002,
  1333. X0x08021002, 0x00020002, 0x08000002, 0x00000000,
  1334. X0x08000000, 0x00001002, 0x00020000, 0x08020002,
  1335. X0x00001000, 0x08000000, 0x00021002, 0x08001002,
  1336. X0x08021000, 0x00001000, 0x00000000, 0x08000002,
  1337. X0x00000002, 0x08021002, 0x00021000, 0x08020000,
  1338. X0x08020002, 0x00020000, 0x00001002, 0x08001000,
  1339. X0x08001002, 0x00000002, 0x08020000, 0x00021000,
  1340. X
  1341. X/* nibble 2 */
  1342. X0x20800000, 0x00808020, 0x00000020, 0x20800020,
  1343. X0x20008000, 0x00800000, 0x20800020, 0x00008020,
  1344. X0x00800020, 0x00008000, 0x00808000, 0x20000000,
  1345. X0x20808020, 0x20000020, 0x20000000, 0x20808000,
  1346. X0x00000000, 0x20008000, 0x00808020, 0x00000020,
  1347. X0x20000020, 0x20808020, 0x00008000, 0x20800000,
  1348. X0x20808000, 0x00800020, 0x20008020, 0x00808000,
  1349. X0x00008020, 0x00000000, 0x00800000, 0x20008020,
  1350. X0x00808020, 0x00000020, 0x20000000, 0x00008000,
  1351. X0x20000020, 0x20008000, 0x00808000, 0x20800020,
  1352. X0x00000000, 0x00808020, 0x00008020, 0x20808000,
  1353. X0x20008000, 0x00800000, 0x20808020, 0x20000000,
  1354. X0x20008020, 0x20800000, 0x00800000, 0x20808020,
  1355. X0x00008000, 0x00800020, 0x20800020, 0x00008020,
  1356. X0x00800020, 0x00000000, 0x20808000, 0x20000020,
  1357. X0x20800000, 0x20008020, 0x00000020, 0x00808000,
  1358. X
  1359. X/* nibble 3 */
  1360. X0x00080201, 0x02000200, 0x00000001, 0x02080201,
  1361. X0x00000000, 0x02080000, 0x02000201, 0x00080001,
  1362. X0x02080200, 0x02000001, 0x02000000, 0x00000201,
  1363. X0x02000001, 0x00080201, 0x00080000, 0x02000000,
  1364. X0x02080001, 0x00080200, 0x00000200, 0x00000001,
  1365. X0x00080200, 0x02000201, 0x02080000, 0x00000200,
  1366. X0x00000201, 0x00000000, 0x00080001, 0x02080200,
  1367. X0x02000200, 0x02080001, 0x02080201, 0x00080000,
  1368. X0x02080001, 0x00000201, 0x00080000, 0x02000001,
  1369. X0x00080200, 0x02000200, 0x00000001, 0x02080000,
  1370. X0x02000201, 0x00000000, 0x00000200, 0x00080001,
  1371. X0x00000000, 0x02080001, 0x02080200, 0x00000200,
  1372. X0x02000000, 0x02080201, 0x00080201, 0x00080000,
  1373. X0x02080201, 0x00000001, 0x02000200, 0x00080201,
  1374. X0x00080001, 0x00080200, 0x02080000, 0x02000201,
  1375. X0x00000201, 0x02000000, 0x02000001, 0x02080200,
  1376. X
  1377. X/* nibble 4 */
  1378. X0x01000000, 0x00002000, 0x00000080, 0x01002084,
  1379. X0x01002004, 0x01000080, 0x00002084, 0x01002000,
  1380. X0x00002000, 0x00000004, 0x01000004, 0x00002080,
  1381. X0x01000084, 0x01002004, 0x01002080, 0x00000000,
  1382. X0x00002080, 0x01000000, 0x00002004, 0x00000084,
  1383. X0x01000080, 0x00002084, 0x00000000, 0x01000004,
  1384. X0x00000004, 0x01000084, 0x01002084, 0x00002004,
  1385. X0x01002000, 0x00000080, 0x00000084, 0x01002080,
  1386. X0x01002080, 0x01000084, 0x00002004, 0x01002000,
  1387. X0x00002000, 0x00000004, 0x01000004, 0x01000080,
  1388. X0x01000000, 0x00002080, 0x01002084, 0x00000000,
  1389. X0x00002084, 0x01000000, 0x00000080, 0x00002004,
  1390. X0x01000084, 0x00000080, 0x00000000, 0x01002084,
  1391. X0x01002004, 0x01002080, 0x00000084, 0x00002000,
  1392. X0x00002080, 0x01002004, 0x01000080, 0x00000084,
  1393. X0x00000004, 0x00002084, 0x01002000, 0x01000004,
  1394. X
  1395. X/* nibble 5 */
  1396. X0x10000008, 0x00040008, 0x00000000, 0x10040400,
  1397. X0x00040008, 0x00000400, 0x10000408, 0x00040000,
  1398. X0x00000408, 0x10040408, 0x00040400, 0x10000000,
  1399. X0x10000400, 0x10000008, 0x10040000, 0x00040408,
  1400. X0x00040000, 0x10000408, 0x10040008, 0x00000000,
  1401. X0x00000400, 0x00000008, 0x10040400, 0x10040008,
  1402. X0x10040408, 0x10040000, 0x10000000, 0x00000408,
  1403. X0x00000008, 0x00040400, 0x00040408, 0x10000400,
  1404. X0x00000408, 0x10000000, 0x10000400, 0x00040408,
  1405. X0x10040400, 0x00040008, 0x00000000, 0x10000400,
  1406. X0x10000000, 0x00000400, 0x10040008, 0x00040000,
  1407. X0x00040008, 0x10040408, 0x00040400, 0x00000008,
  1408. X0x10040408, 0x00040400, 0x00040000, 0x10000408,
  1409. X0x10000008, 0x10040000, 0x00040408, 0x00000000,
  1410. X0x00000400, 0x10000008, 0x10000408, 0x10040400,
  1411. X0x10040000, 0x00000408, 0x00000008, 0x10040008,
  1412. X
  1413. X/* nibble 6 */
  1414. X0x00000800, 0x00000040, 0x00200040, 0x80200000,
  1415. X0x80200840, 0x80000800, 0x00000840, 0x00000000,
  1416. X0x00200000, 0x80200040, 0x80000040, 0x00200800,
  1417. X0x80000000, 0x00200840, 0x00200800, 0x80000040,
  1418. X0x80200040, 0x00000800, 0x80000800, 0x80200840,
  1419. X0x00000000, 0x00200040, 0x80200000, 0x00000840,
  1420. X0x80200800, 0x80000840, 0x00200840, 0x80000000,
  1421. X0x80000840, 0x80200800, 0x00000040, 0x00200000,
  1422. X0x80000840, 0x00200800, 0x80200800, 0x80000040,
  1423. X0x00000800, 0x00000040, 0x00200000, 0x80200800,
  1424. X0x80200040, 0x80000840, 0x00000840, 0x00000000,
  1425. X0x00000040, 0x80200000, 0x80000000, 0x00200040,
  1426. X0x00000000, 0x80200040, 0x00200040, 0x00000840,
  1427. X0x80000040, 0x00000800, 0x80200840, 0x00200000,
  1428. X0x00200840, 0x80000000, 0x80000800, 0x80200840,
  1429. X0x80200000, 0x00200840, 0x00200800, 0x80000800,
  1430. X
  1431. X/* nibble 7 */
  1432. X0x04100010, 0x04104000, 0x00004010, 0x00000000,
  1433. X0x04004000, 0x00100010, 0x04100000, 0x04104010,
  1434. X0x00000010, 0x04000000, 0x00104000, 0x00004010,
  1435. X0x00104010, 0x04004010, 0x04000010, 0x04100000,
  1436. X0x00004000, 0x00104010, 0x00100010, 0x04004000,
  1437. X0x04104010, 0x04000010, 0x00000000, 0x00104000,
  1438. X0x04000000, 0x00100000, 0x04004010, 0x04100010,
  1439. X0x00100000, 0x00004000, 0x04104000, 0x00000010,
  1440. X0x00100000, 0x00004000, 0x04000010, 0x04104010,
  1441. X0x00004010, 0x04000000, 0x00000000, 0x00104000,
  1442. X0x04100010, 0x04004010, 0x04004000, 0x00100010,
  1443. X0x04104000, 0x00000010, 0x00100010, 0x04004000,
  1444. X0x04104010, 0x00100000, 0x04100000, 0x04000010,
  1445. X0x00104000, 0x00004010, 0x04004010, 0x04100000,
  1446. X0x00000010, 0x04104000, 0x00104010, 0x00000000,
  1447. X0x04000000, 0x04100010, 0x00004000, 0x00104010};
  1448. END_OF_FILE
  1449. if test 6392 -ne `wc -c <'sp.h'`; then
  1450.     echo shar: \"'sp.h'\" unpacked with wrong size!
  1451. fi
  1452. # end of 'sp.h'
  1453. fi
  1454. if test -f 'testdes.pl' -a "${1}" != "-c" ; then 
  1455.   echo shar: Will not clobber existing file \"'testdes.pl'\"
  1456. else
  1457. echo shar: Extracting \"'testdes.pl'\" \(5644 characters\)
  1458. sed "s/^X//" >'testdes.pl' <<'END_OF_FILE'
  1459. X#!/usr/local/bin/perl
  1460. X
  1461. X# des.pl tesing code
  1462. X
  1463. Xrequire 'des.pl';
  1464. X
  1465. X$num_tests=34;
  1466. X@key_data=(
  1467. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1468. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  1469. X    0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1470. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  1471. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1472. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  1473. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1474. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
  1475. X    0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57,
  1476. X    0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E,
  1477. X    0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86,
  1478. X    0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E,
  1479. X    0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6,
  1480. X    0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE,
  1481. X    0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6,
  1482. X    0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE,
  1483. X    0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16,
  1484. X    0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F,
  1485. X    0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46,
  1486. X    0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E,
  1487. X    0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76,
  1488. X    0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07,
  1489. X    0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F,
  1490. X    0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7,
  1491. X    0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF,
  1492. X    0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6,
  1493. X    0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF,
  1494. X    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  1495. X    0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E,
  1496. X    0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE,
  1497. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1498. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  1499. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1500. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
  1501. X    );
  1502. X
  1503. X@plain_data=(
  1504. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1505. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  1506. X    0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  1507. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  1508. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  1509. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1510. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1511. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1512. X    0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42,
  1513. X    0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA,
  1514. X    0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72,
  1515. X    0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A,
  1516. X    0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2,
  1517. X    0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A,
  1518. X    0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2,
  1519. X    0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A,
  1520. X    0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02,
  1521. X    0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A,
  1522. X    0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32,
  1523. X    0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA,
  1524. X    0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62,
  1525. X    0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2,
  1526. X    0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA,
  1527. X    0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92,
  1528. X    0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A,
  1529. X    0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2,
  1530. X    0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A,
  1531. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1532. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1533. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  1534. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  1535. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1536. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1537. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
  1538. X
  1539. X@cipher_data=(
  1540. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  1541. X    0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58,
  1542. X    0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B,
  1543. X    0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33,
  1544. X    0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D,
  1545. X    0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD,
  1546. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  1547. X    0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4,
  1548. X    0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B,
  1549. X    0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71,
  1550. X    0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A,
  1551. X    0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A,
  1552. X    0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95,
  1553. X    0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B,
  1554. X    0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09,
  1555. X    0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A,
  1556. X    0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F,
  1557. X    0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88,
  1558. X    0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77,
  1559. X    0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A,
  1560. X    0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56,
  1561. X    0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56,
  1562. X    0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56,
  1563. X    0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC,
  1564. X    0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A,
  1565. X    0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41,
  1566. X    0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93,
  1567. X    0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00,
  1568. X    0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06,
  1569. X    0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7,
  1570. X    0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51,
  1571. X    0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE,
  1572. X    0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D,
  1573. X    0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2);
  1574. X
  1575. Xprint "Doing ecb tests\n";
  1576. Xfor ($i=0; $i<$num_tests; $i++)
  1577. X    {
  1578. X    printf "Doing test $i\n";
  1579. X    $key =pack("C8",splice(@key_data   ,0,8));
  1580. X    $data=pack("C8",splice(@plain_data ,0,8));
  1581. X    $res =pack("C8",splice(@cipher_data,0,8));
  1582. X
  1583. X    @ks=  &des_set_key($key);
  1584. X    $out1= &des_ecb_encrypt(*ks,1,$data);
  1585. X    $out2= &des_ecb_encrypt(*ks,0,$out1);
  1586. X    $out3= &des_ecb_encrypt(*ks,0,$res);
  1587. X    &eprint("encryption failure",$res,$out1)
  1588. X        if ($out1 ne $res);
  1589. X    &eprint("encryption/decryption failure",$data,$out2)
  1590. X        if ($out2 ne $data);
  1591. X    &eprint("decryption failure",$data,$out3)
  1592. X        if ($data ne $out3);
  1593. X    }
  1594. Xprint "Done\n";
  1595. X
  1596. Xprint "doing speed test over 30 seconds\n";
  1597. X$SIG{'ALRM'}='done';
  1598. Xsub done {$done=1;}
  1599. X$done=0;
  1600. X
  1601. X$count=0;
  1602. X$d=pack("C8",0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef);
  1603. X@ks=  &des_set_key($d);
  1604. Xalarm(30);
  1605. X$start=(times)[0];
  1606. Xwhile (!$done)
  1607. X    {
  1608. X    $count++;
  1609. X    $d=&des_ecb_encrypt(*ks,1,$d);
  1610. X    }
  1611. X$end=(times)[0];
  1612. X$t=$end-$start;
  1613. Xprintf "$count DESs in %.2f seconds is %.2f DESs/sec or %.2f bytes/sec\n",
  1614. X    1.0*$t,1.0*$count/$t,$count*8.0/$t;
  1615. X
  1616. Xsub eprint
  1617. X    {
  1618. X    local($s,$c,$e)=@_;
  1619. X    local(@k);
  1620. X
  1621. X    @k=unpack("C8",$c);
  1622. X    printf "%02x%02x%02x%02x %02x%02x%02x%02x - ",unpack("C8",$c);
  1623. X    printf "%02x%02x%02x%02x %02x%02x%02x%02x :",unpack("C8",$e);
  1624. X    print " $s\n";
  1625. X    }
  1626. END_OF_FILE
  1627. if test 5644 -ne `wc -c <'testdes.pl'`; then
  1628.     echo shar: \"'testdes.pl'\" unpacked with wrong size!
  1629. fi
  1630. # end of 'testdes.pl'
  1631. fi
  1632. echo shar: End of archive 2 \(of 4\).
  1633. cp /dev/null ark2isdone
  1634. MISSING=""
  1635. for I in 1 2 3 4 ; do
  1636.     if test ! -f ark${I}isdone ; then
  1637.     MISSING="${MISSING} ${I}"
  1638.     fi
  1639. done
  1640. if test "${MISSING}" = "" ; then
  1641.     echo You have unpacked all 4 archives.
  1642.     rm -f ark[1-9]isdone
  1643. else
  1644.     echo You still need to unpack the following archives:
  1645.     echo "        " ${MISSING}
  1646. fi
  1647. ##  End of shell archive.
  1648. exit 0
  1649. exit 0 # Just in case...
  1650.