home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / libdes / part02 < prev    next >
Encoding:
Internet Message Format  |  1993-10-14  |  53.7 KB

  1. From: eay@psych.psy.uq.oz.au (Eric Young)
  2. Newsgroups: comp.sources.misc
  3. Subject: v40i009: libdes - DES encryption library, Part02/05
  4. Date: 14 Oct 1993 18:01:45 +0100
  5. Sender: aem@aber.ac.uk
  6. Approved: aem@aber.ac.uk
  7. Message-ID: <29k0lp$1m2@uk-usenet.uk.sun.com>
  8. X-Md4-Signature: 866c2241740292272090a787e511ecf8
  9.  
  10. Submitted-by: eay@psych.psy.uq.oz.au (Eric Young)
  11. Posting-number: Volume 40, Issue 9
  12. Archive-name: libdes/part02
  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:  des.c destest.c doPC2 fcrypt.c
  22. # Wrapped by alecm@uk-usenet on Wed Oct 13 10:33:49 1993
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 2 (of 5)."'
  26. if test -f 'des.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'des.c'\"
  28. else
  29.   echo shar: Extracting \"'des.c'\" \(16298 characters\)
  30.   sed "s/^X//" >'des.c' <<'END_OF_FILE'
  31. X/* des.c */
  32. X/* Copyright (C) 1993 Eric Young - see README for more details */
  33. X#include <stdio.h>
  34. X#ifdef VMS
  35. X#include <types.h>
  36. X#include <stat.h>
  37. X#else
  38. X#ifndef _IRIX
  39. X#include <sys/types.h>
  40. X#endif
  41. X#include <sys/stat.h>
  42. X#endif
  43. X#include "des.h"
  44. X
  45. X#if defined(__STDC__) || defined(VMS) || defined(M_XENIX) || defined(MSDOS)
  46. X#include <string.h>
  47. X#define bcopy(f,t,n)    memcpy(t,f,(size_t)(n))
  48. X#define bzero(s,n)    memset(s,0,(size_t)(n))
  49. X#define bcmp(a,b,n)    memcmp(a, b,(size_t)(n))
  50. X#define index(s,c)    strchr(s,c)
  51. X#endif
  52. X
  53. X#ifdef PROTO
  54. Xint usage(void);
  55. Xint doencryption(void);
  56. Xint uufwrite(char *data, int size, int num, FILE *fp);
  57. Xint uufwriteEnd(FILE *fp);
  58. Xint uufread(char *out,int size,int num,FILE *fp);
  59. Xint uuencode(unsigned char *in,int num,unsigned char *out);
  60. Xint uudecode(unsigned char *in,int num,unsigned char *out);
  61. X#else
  62. Xint usage();
  63. Xint doencryption();
  64. Xint uufwrite();
  65. Xint uufwriteEnd();
  66. Xint uufread();
  67. Xint uuencode();
  68. Xint uudecode();
  69. X#endif
  70. X
  71. X#ifdef VMS
  72. X#define EXIT(a) exit(a&0x10000000)
  73. X#else
  74. X#define EXIT(a) exit(a)
  75. X#endif
  76. X
  77. X#define BUFSIZE (8*1024)
  78. X#define VERIFY  1
  79. X#define KEYSIZ    8
  80. X#define KEYSIZB 1024 /* should hit tty line limit first :-) */
  81. Xchar key[KEYSIZB+1];
  82. Xint do_encrypt,longk=0;
  83. Xchar *in=NULL,*out=NULL;
  84. XFILE *DES_IN,*DES_OUT,*CKSUM_OUT;
  85. Xchar uuname[200];
  86. Xchar uubuf[50];
  87. Xint uubufnum;
  88. X#define INUUBUFN    (45*100)
  89. X#define OUTUUBUF    (65*100)
  90. Xchar b[OUTUUBUF];
  91. Xchar bb[300];
  92. Xdes_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  93. Xchar cksumname[200]="";
  94. X
  95. Xint cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
  96. X
  97. Xmain(argc,argv)
  98. Xint argc;
  99. Xchar *argv[];
  100. X    {
  101. X    int i;
  102. X    struct stat ins,outs;
  103. X    char *p;
  104. X
  105. X    cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0,error=0;
  106. X    bzero(key,sizeof(key));
  107. X
  108. X    for (i=1; i<argc; i++)
  109. X        {
  110. X        p=argv[i];
  111. X        if ((p[0] == '-') && (p[1] != '\0'))
  112. X            {
  113. X            p++;
  114. X            while (*p)
  115. X                {
  116. X                switch (*(p++))
  117. X                    {
  118. X                case '3':
  119. X                    flag3=1;
  120. X                /*    bflag=0; */
  121. X                    longk=1;
  122. X                    break;
  123. X                case 'c':
  124. X                    cflag=1;
  125. X                    strncpy(cksumname,p,200);
  126. X                    p+=strlen(cksumname);
  127. X                    break;
  128. X                case 'C':
  129. X                    cflag=1;
  130. X                    longk=1;
  131. X                    strncpy(cksumname,p,200);
  132. X                    p+=strlen(cksumname);
  133. X                    break;
  134. X                case 'e':
  135. X                    eflag=1;
  136. X                    break;
  137. X                case 'E':
  138. X                    eflag=1;
  139. X                    longk=1;
  140. X                    break;
  141. X                case 'd':
  142. X                    dflag=1;
  143. X                    break;
  144. X                case 'D':
  145. X                    dflag=1;
  146. X                    longk=1;
  147. X                    break;
  148. X                case 'b':
  149. X                    bflag=1;
  150. X                    flag3=0;
  151. X                    break;
  152. X                case 'f':
  153. X                    fflag=1;
  154. X                    break;
  155. X                case 's':
  156. X                    sflag=1;
  157. X                    break;
  158. X                case 'u':
  159. X                    uflag=1;
  160. X                    strncpy(uuname,p,200);
  161. X                    p+=strlen(uuname);
  162. X                    break;
  163. X                case 'h':
  164. X                    hflag=1;
  165. X                    break;
  166. X                case 'k':
  167. X                    kflag=1;
  168. X                    if ((i+1) == argc)
  169. X                        {
  170. X                        fputs("must have a key with the -k option\n",stderr);
  171. X                        error=1;
  172. X                        }
  173. X                    else
  174. X                        {
  175. X                        int j;
  176. X
  177. X                        i++;
  178. X                        strncpy(key,argv[i],KEYSIZB);
  179. X                        for (j=strlen(argv[i])-1; j>=0; j--)
  180. X                            argv[i][j]='\0';
  181. X                        }
  182. X                    break;
  183. X                default:
  184. X                    fprintf(stderr,"'%c' unknown flag\n",p[-1]);
  185. X                    error=1;
  186. X                    break;
  187. X                    }
  188. X                }
  189. X            }
  190. X        else
  191. X            {
  192. X            if (in == NULL)
  193. X                in=argv[i];
  194. X            else if (out == NULL)
  195. X                out=argv[i];
  196. X            else
  197. X                error=1;
  198. X            }
  199. X        }
  200. X    if (error) usage();
  201. X    /* We either
  202. X     * do checksum or
  203. X     * do encrypt or
  204. X     * do decrypt or
  205. X     * do decrypt then ckecksum or
  206. X     * do checksum then encrypt
  207. X     */
  208. X    if (((eflag+dflag) == 1) || cflag)
  209. X        {
  210. X        if (eflag) do_encrypt=DES_ENCRYPT;
  211. X        if (dflag) do_encrypt=DES_DECRYPT;
  212. X        }
  213. X    else
  214. X        usage();
  215. X
  216. X    if (    (in != NULL) &&
  217. X        (out != NULL) &&
  218. X#ifndef MSDOS
  219. X        (stat(in,&ins) != -1) &&
  220. X        (stat(out,&outs) != -1) &&
  221. X        (ins.st_dev == outs.st_dev) &&
  222. X        (ins.st_ino == outs.st_ino))
  223. X#else /* MSDOS */
  224. X        (strcmp(in,out) == 0))
  225. X#endif
  226. X            {
  227. X            fputs("input and output file are the same\n",stderr);
  228. X            EXIT(3);
  229. X            }
  230. X
  231. X    if (!kflag)
  232. X        if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
  233. X            {
  234. X            fputs("password error\n",stderr);
  235. X            EXIT(2);
  236. X            }
  237. X
  238. X    if (in == NULL)
  239. X        DES_IN=stdin;
  240. X    else if ((DES_IN=fopen(in,"r")) == NULL)
  241. X        {
  242. X        perror("opening input file");
  243. X        EXIT(4);
  244. X        }
  245. X
  246. X    CKSUM_OUT=stdout;
  247. X    if (out == NULL)
  248. X        {
  249. X        DES_OUT=stdout;
  250. X        CKSUM_OUT=stderr;
  251. X        }
  252. X    else if ((DES_OUT=fopen(out,"w")) == NULL)
  253. X        {
  254. X        perror("opening output file");
  255. X        EXIT(5);
  256. X        }
  257. X
  258. X#ifdef MSDOS
  259. X    /* This should set the file to binary mode. */
  260. X    {
  261. X#include <fcntl.h>
  262. X    if (!(uflag && dflag))
  263. X        setmode(fileno(DES_IN),O_BINARY);
  264. X    if (!(uflag && eflag))
  265. X        setmode(fileno(DES_OUT),O_BINARY);
  266. X    }
  267. X#endif
  268. X
  269. X    doencryption();
  270. X    fclose(DES_IN);
  271. X    fclose(DES_OUT);
  272. X    EXIT(0);
  273. X    }
  274. X
  275. Xusage()
  276. X    {
  277. X    char **u;
  278. X    static char *usage[]={
  279. X"des <options> [input-file [output-file]]",
  280. X"options:",
  281. X"-e         : encrypt using sunOS compatible user key to DES key conversion.",
  282. X"-E         : encrypt ",
  283. X"-d         : decrypt using sunOS compatible user key to DES key conversion.",
  284. X"-D         : decrypt ",
  285. X"-c[ckname] : generate a cbc_cksum using sunOS compatible user key to",
  286. X"             DES key conversion and output to ckname (stdout default,",
  287. X"             stderr if data being output on stdout).  The checksum is",
  288. X"             generated before encryption and after decryption if used",
  289. X"             in conjunction with -[eEdD].",
  290. X"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
  291. X"-k key     : use key 'key'",
  292. X"-h         : the key that is entered will be a hexidecimal number",
  293. X"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded",
  294. X"             data if -[eE] (uuname is the filename to put in the",
  295. X"             uuencode header).",
  296. X"-b         : encrypt using DES in ecb encryption mode, the defaut is",
  297. X"             cbc mode.",
  298. X"-3         : encrypt using tripple DES encryption.  This uses 2 keys",
  299. X"             generated from the input key.  If the input key is less",
  300. X"             than 8 characters long, this is equivelent to normal",
  301. X"             encryption.  Default is tripple cbc, -b makes it tripple ecb.",
  302. XNULL
  303. X};
  304. X    for (u=usage; *u; u++)
  305. X        {
  306. X        fputs(*u,stderr);
  307. X        fputc('\n',stderr);
  308. X        }
  309. X
  310. X    EXIT(1);
  311. X    }
  312. X
  313. Xdoencryption()
  314. X    {
  315. X    register int i;
  316. X    des_key_schedule ks,ks2;
  317. X    unsigned char iv[8],iv2[8],iv3[8];
  318. X    char *p;
  319. X    int num=0,j,k,l,rem,ll,len,last,ex=0;
  320. X    des_cblock kk,k2;
  321. X    FILE *O;
  322. X    int Exit=0;
  323. X#ifndef MSDOS
  324. X    static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
  325. X#else
  326. X    static unsigned char *buf=NULL,*obuf=NULL;
  327. X
  328. X    if (buf == NULL)
  329. X        {
  330. X        if (    (( buf=(unsigned char *)malloc(BUFSIZE+8)) == NULL) ||
  331. X            ((obuf=(unsigned char *)malloc(BUFSIZE+8)) == NULL))
  332. X            {
  333. X            fputs("Not enough memory\n",stderr);
  334. X            Exit=10;
  335. X            goto problems;
  336. X            }
  337. X        }
  338. X#endif
  339. X
  340. X    if (hflag)
  341. X        {
  342. X        j=(flag3?16:8);
  343. X        p=key;
  344. X        for (i=0; i<j; i++)
  345. X            {
  346. X            k=0;
  347. X            if ((*p <= '9') && (*p >= '0'))
  348. X                k=(*p-'0')<<4;
  349. X            else if ((*p <= 'f') && (*p >= 'a'))
  350. X                k=(*p-'a'+10)<<4;
  351. X            else if ((*p <= 'F') && (*p >= 'A'))
  352. X                k=(*p-'A'+10)<<4;
  353. X            else
  354. X                {
  355. X                fputs("Bad hex key\n",stderr);
  356. X                Exit=9;
  357. X                goto problems;
  358. X                }
  359. X            p++;
  360. X            if ((*p <= '9') && (*p >= '0'))
  361. X                k|=(*p-'0');
  362. X            else if ((*p <= 'f') && (*p >= 'a'))
  363. X                k|=(*p-'a'+10);
  364. X            else if ((*p <= 'F') && (*p >= 'A'))
  365. X                k|=(*p-'A'+10);
  366. X            else
  367. X                {
  368. X                fputs("Bad hex key\n",stderr);
  369. X                Exit=9;
  370. X                goto problems;
  371. X                }
  372. X            p++;
  373. X            if (i < 8)
  374. X                kk[i]=k;
  375. X            else
  376. X                k2[i-8]=k;
  377. X            }
  378. X        des_set_key((C_Block *)k2,ks2);
  379. X        bzero(k2,sizeof(k2));
  380. X        }
  381. X    else if (longk || flag3)
  382. X        {
  383. X        if (flag3)
  384. X            {
  385. X            des_string_to_2keys(key,(C_Block *)kk,(C_Block *)k2);
  386. X            des_set_key((C_Block *)k2,ks2);
  387. X            bzero(k2,sizeof(k2));
  388. X            }
  389. X        else
  390. X            des_string_to_key(key,(C_Block *)kk);
  391. X        }
  392. X    else
  393. X        for (i=0; i<KEYSIZ; i++)
  394. X            {
  395. X            l=0;
  396. X            k=key[i];
  397. X            for (j=0; j<8; j++)
  398. X                {
  399. X                if (k&1) l++;
  400. X                k>>=1;
  401. X                }
  402. X            if (l & 1)
  403. X                kk[i]=key[i]&0x7f;
  404. X            else
  405. X                kk[i]=key[i]|0x80;
  406. X            }
  407. X
  408. X    des_set_key((C_Block *)kk,ks);
  409. X    bzero(key,sizeof(key));
  410. X    bzero(kk,sizeof(kk));
  411. X    /* woops - A bug that does not showup under unix :-( */
  412. X    bzero(iv,sizeof(iv));
  413. X    bzero(iv2,sizeof(iv2));
  414. X    bzero(iv3,sizeof(iv3));
  415. X
  416. X    l=1;
  417. X    rem=0;
  418. X    /* first read */
  419. X    if (eflag || (!dflag && cflag))
  420. X        {
  421. X        for (;;)
  422. X            {
  423. X            num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
  424. X            l+=rem;
  425. X            num+=rem;
  426. X            if (l < 0)
  427. X                {
  428. X                perror("read error");
  429. X                Exit=6;
  430. X                goto problems;
  431. X                }
  432. X
  433. X            rem=l%8;
  434. X            len=l-rem;
  435. X            if (feof(DES_IN))
  436. X                {
  437. X                srand(time(NULL));
  438. X                for (i=7-rem; i>0; i--)
  439. X                    buf[l++]=rand()&0xff;
  440. X                buf[l++]=rem;
  441. X                ex=1;
  442. X                len+=rem;
  443. X                }
  444. X            else
  445. X                l-=rem;
  446. X
  447. X            if (cflag)
  448. X                {
  449. X                des_cbc_cksum((C_Block *)buf,(C_Block *)cksum,
  450. X                    (long)len,ks,(C_Block *)cksum);
  451. X                if (!eflag)
  452. X                    {
  453. X                    if (feof(DES_IN)) break;
  454. X                    else continue;
  455. X                    }
  456. X                }
  457. X
  458. X            if (bflag && !flag3)
  459. X                for (i=0; i<l; i+=8)
  460. X                    des_ecb_encrypt(
  461. X                        (des_cblock *)&(buf[i]),
  462. X                        (des_cblock *)&(obuf[i]),
  463. X                        ks,do_encrypt);
  464. X            else if (flag3 && bflag)
  465. X                for (i=0; i<l; i+=8)
  466. X                    des_3ecb_encrypt(
  467. X                        (des_cblock *)&(buf[i]),
  468. X                        (des_cblock *)&(obuf[i]),
  469. X                        ks,ks2,do_encrypt);
  470. X            else if (flag3 && !bflag)
  471. X                {
  472. X                char tmpbuf[8];
  473. X
  474. X                if (rem) bcopy(&(buf[l]),tmpbuf,rem);
  475. X                des_3cbc_encrypt(
  476. X                    (des_cblock *)buf,(des_cblock *)obuf,
  477. X                    (long)l,ks,ks2,(des_cblock *)iv,
  478. X                    (des_cblock *)iv2,do_encrypt);
  479. X                if (rem) bcopy(tmpbuf,&(buf[l]),rem);
  480. X                }
  481. X            else
  482. X                {
  483. X                des_cbc_encrypt(
  484. X                    (des_cblock *)buf,(des_cblock *)obuf,
  485. X                    (long)l,ks,(des_cblock *)iv,do_encrypt);
  486. X                if (l >= 8) bcopy(&(obuf[l-8]),iv,8);
  487. X                }
  488. X            if (rem) bcopy(&(buf[l]),buf,rem);
  489. X
  490. X            i=0;
  491. X            while (i < l)
  492. X                {
  493. X                if (uflag)
  494. X                    j=uufwrite(obuf,1,l-i,DES_OUT);
  495. X                else
  496. X                    j=fwrite(obuf,1,l-i,DES_OUT);
  497. X                if (j == -1)
  498. X                    {
  499. X                    perror("Write error");
  500. X                    Exit=7;
  501. X                    goto problems;
  502. X                    }
  503. X                i+=j;
  504. X                }
  505. X            if (feof(DES_IN))
  506. X                {
  507. X                if (uflag) uufwriteEnd(DES_OUT);
  508. X                break;
  509. X                }
  510. X            }
  511. X        }
  512. X    else /* decrypt */
  513. X        {
  514. X        ex=1;
  515. X        for (;;)
  516. X            {
  517. X            if (ex) {
  518. X                if (uflag)
  519. X                    l=uufread(buf,1,BUFSIZE,DES_IN);
  520. X                else
  521. X                    l=fread(buf,1,BUFSIZE,DES_IN);
  522. X                ex=0;
  523. X                rem=l%8;
  524. X                l-=rem;
  525. X                }
  526. X            if (l < 0)
  527. X                {
  528. X                perror("read error");
  529. X                Exit=6;
  530. X                goto problems;
  531. X                }
  532. X
  533. X            if (bflag && !flag3)
  534. X                for (i=0; i<l; i+=8)
  535. X                    des_ecb_encrypt(
  536. X                        (des_cblock *)&(buf[i]),
  537. X                        (des_cblock *)&(obuf[i]),
  538. X                        ks,do_encrypt);
  539. X            else if (flag3 && bflag)
  540. X                for (i=0; i<l; i+=8)
  541. X                    des_3ecb_encrypt(
  542. X                        (des_cblock *)&(buf[i]),
  543. X                        (des_cblock *)&(obuf[i]),
  544. X                        ks,ks2,do_encrypt);
  545. X            else if (flag3 && !bflag)
  546. X                {
  547. X                des_3cbc_encrypt(
  548. X                    (des_cblock *)buf,(des_cblock *)obuf,
  549. X                    (long)l,ks,ks2,(des_cblock *)iv,
  550. X                    (des_cblock *)iv2,do_encrypt);
  551. X                }
  552. X            else
  553. X                {
  554. X                des_cbc_encrypt(
  555. X                    (des_cblock *)buf,(des_cblock *)obuf,
  556. X                     (long)l,ks,(des_cblock *)iv,do_encrypt);
  557. X                if (l >= 8) bcopy(&(buf[l-8]),iv,8);
  558. X                }
  559. X
  560. X            if (uflag)
  561. X                ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
  562. X            else
  563. X                ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
  564. X            ll+=rem;
  565. X            rem=ll%8;
  566. X            ll-=rem;
  567. X            if (feof(DES_IN) && (ll == 0))
  568. X                {
  569. X                last=obuf[l-1];
  570. X
  571. X                if ((last > 7) || (last < 0))
  572. X                    {
  573. X                    fputs("The file was not decrypted correctly.\n",
  574. X                        stderr);
  575. X                    /*Exit=8;
  576. X                    goto problems;*/
  577. X                    last=0;
  578. X                    }
  579. X                l=l-8+last;
  580. X                }
  581. X            i=0;
  582. X            if (cflag) des_cbc_cksum((C_Block *)obuf,
  583. X                (C_Block *)cksum,(long)l/8*8,ks,
  584. X                (C_Block *)cksum);
  585. X            while (i != l)
  586. X                {
  587. X                j=fwrite(obuf,1,l-i,DES_OUT);
  588. X                if (j == -1)
  589. X                    {
  590. X                    perror("Write error");
  591. X                    Exit=7;
  592. X                    goto problems;
  593. X                    }
  594. X                i+=j;
  595. X                }
  596. X            l=ll;
  597. X            if ((l == 0) && feof(DES_IN)) break;
  598. X            }
  599. X        }
  600. X    if (cflag)
  601. X        {
  602. X        l=0;
  603. X        if (cksumname[0] != '\0')
  604. X            {
  605. X            if ((O=fopen(cksumname,"w")) != NULL)
  606. X                {
  607. X                CKSUM_OUT=O;
  608. X                l=1;
  609. X                }
  610. X            }
  611. X        for (i=0; i<8; i++)
  612. X            fprintf(CKSUM_OUT,"%02X",cksum[i]);
  613. X        fprintf(CKSUM_OUT,"\n");
  614. X        if (l) fclose(CKSUM_OUT);
  615. X        }
  616. Xproblems:
  617. X    bzero(buf,sizeof(buf));
  618. X    bzero(obuf,sizeof(obuf));
  619. X    bzero(ks,sizeof(ks));
  620. X    bzero(ks2,sizeof(ks2));
  621. X    bzero(iv,sizeof(iv));
  622. X    bzero(iv2,sizeof(iv2));
  623. X    bzero(iv3,sizeof(iv3));
  624. X    bzero(kk,sizeof(kk));
  625. X    bzero(k2,sizeof(k2));
  626. X    bzero(uubuf,sizeof(uubuf));
  627. X    bzero(b,sizeof(b));
  628. X    bzero(bb,sizeof(bb));
  629. X    bzero(cksum,sizeof(cksum));
  630. X    if (Exit) EXIT(Exit);
  631. X    }
  632. X
  633. Xint uufwrite(data,size,num,fp)
  634. Xchar *data;
  635. Xint size; /* We ignore this parameter but it should be > ~50 I believe */
  636. Xint num;
  637. XFILE *fp;
  638. X    {
  639. X    int i,j,left,rem,ret=num;
  640. X    static int start=1;
  641. X
  642. X    if (start)
  643. X        {
  644. X        fprintf(fp,"begin 600 %s\n",
  645. X            (uuname[0] == '\0')?"text.d":uuname);
  646. X        start=0;
  647. X        }
  648. X
  649. X    if (uubufnum)
  650. X        {
  651. X        if (uubufnum+num < 45)
  652. X            {
  653. X            bcopy(data,&(uubuf[uubufnum]),num);
  654. X            uubufnum+=num;
  655. X            return(num);
  656. X            }
  657. X        else
  658. X            {
  659. X            i=45-uubufnum;
  660. X            bcopy(data,&(uubuf[uubufnum]),i);
  661. X            j=uuencode(uubuf,45,b);
  662. X            fwrite(b,1,j,fp);
  663. X            uubufnum=0;
  664. X            data+=i;
  665. X            num-=i;
  666. X            }
  667. X        }
  668. X
  669. X    for (i=0; i<(num-INUUBUFN); i+=INUUBUFN)
  670. X        {
  671. X        j=uuencode(&(data[i]),INUUBUFN,b);
  672. X        fwrite(b,1,j,fp);
  673. X        }
  674. X    rem=(num-i)%45;
  675. X    left=(num-i-rem);
  676. X    if (left)
  677. X        {
  678. X        j=uuencode(&(data[i]),left,b);
  679. X        fwrite(b,1,j,fp);
  680. X        i+=left;
  681. X        }
  682. X    if (i != num)
  683. X        {
  684. X        bcopy(&(data[i]),uubuf,rem);
  685. X        uubufnum=rem;
  686. X        }
  687. X    return(ret);
  688. X    }
  689. X
  690. Xint uufwriteEnd(fp)
  691. XFILE *fp;
  692. X    {
  693. X    int j;
  694. X    static char *end=" \nend\n";
  695. X
  696. X    if (uubufnum != 0)
  697. X        {
  698. X        uubuf[uubufnum]='\0';
  699. X        uubuf[uubufnum+1]='\0';
  700. X        uubuf[uubufnum+2]='\0';
  701. X        j=uuencode(uubuf,uubufnum,b);
  702. X        fwrite(b,1,j,fp);
  703. X        }
  704. X    fwrite(end,1,strlen(end),fp);
  705. X    }
  706. X
  707. Xint uufread(out,size,num,fp)
  708. Xchar *out;
  709. Xint size; /* should always be > ~ 60; I actually ignore this parameter :-) */
  710. Xint num;
  711. XFILE *fp;
  712. X    {
  713. X    int i,j,tot;
  714. X    static int done=0;
  715. X    static int valid=0;
  716. X    static int start=1;
  717. X
  718. X    if (start)
  719. X        {
  720. X        for (;;)
  721. X            {
  722. X            b[0]='\0';
  723. X            fgets(b,300,fp);
  724. X            if (b[0] == '\0')
  725. X                {
  726. X                fprintf(stderr,"no 'begin' found in uuencoded input\n");
  727. X                return(-1);
  728. X                }
  729. X            if (strncmp(b,"begin ",6) == 0) break;
  730. X            }
  731. X        start=0;
  732. X        }
  733. X    if (done) return(0);
  734. X    tot=0;
  735. X    if (valid)
  736. X        {
  737. X        bcopy(bb,out,valid);
  738. X        tot=valid;
  739. X        valid=0;
  740. X        }
  741. X    for (;;)
  742. X        {
  743. X        b[0]='\0';
  744. X        fgets(b,300,fp);
  745. X        if (b[0] == '\0') break;
  746. X        i=strlen(b);
  747. X        if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
  748. X            {
  749. X            done=1;
  750. X            while (!feof(fp))
  751. X                {
  752. X                fgets(b,300,fp);
  753. X                }
  754. X            break;
  755. X            }
  756. X        i=uudecode(b,i,bb);
  757. X        if (i < 0) break;
  758. X        if ((i+tot+8) > num)
  759. X            {
  760. X            /* num to copy to make it a multiple of 8 */
  761. X            j=(num/8*8)-tot-8;
  762. X            bcopy(bb,&(out[tot]),j);
  763. X            tot+=j;
  764. X            bcopy(&(bb[j]),bb,i-j);
  765. X            valid=i-j;
  766. X            break;
  767. X            }
  768. X        bcopy(bb,&(out[tot]),i);
  769. X        tot+=i;
  770. X        }
  771. X    return(tot);
  772. X    }
  773. X
  774. X#define ccc2l(c,l)      (l =((unsigned long)(*((c)++)))<<16, \
  775. X             l|=((unsigned long)(*((c)++)))<< 8, \
  776. X              l|=((unsigned long)(*((c)++))))
  777. X
  778. X#define l2ccc(l,c)      (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
  779. X                         *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
  780. X                         *((c)++)=(unsigned char)(((l)    )&0xff))
  781. X
  782. X
  783. Xint uuencode(in,num,out)
  784. Xunsigned char *in;
  785. Xint num;
  786. Xunsigned char *out;
  787. X    {
  788. X    int j,i,k,n,tot=0;
  789. X    unsigned long l;
  790. X    register unsigned char *p;
  791. X    p=out;
  792. X
  793. X    for (j=0; j<num; j+=45)
  794. X        {
  795. X        if (j+45 > num)
  796. X            i=(num-j);
  797. X        else    i=45;
  798. X        *(p++)=i+' ';
  799. X        for (n=0; n<i; n+=3)
  800. X            {
  801. X            ccc2l(in,l);
  802. X            *(p++)=((l>>18)&0x3f)+' ';
  803. X            *(p++)=((l>>12)&0x3f)+' ';
  804. X            *(p++)=((l>> 6)&0x3f)+' ';
  805. X            *(p++)=((l    )&0x3f)+' ';
  806. X            tot+=4;
  807. X            }
  808. X        *(p++)='\n';
  809. X        tot+=2;
  810. X        }
  811. X    *p='\0';
  812. X    l=0;
  813. X    return(tot);
  814. X    }
  815. X
  816. Xint uudecode(in,num,out)
  817. Xunsigned char *in;
  818. Xint num;
  819. Xunsigned char *out;
  820. X    {
  821. X    int j,i,k;
  822. X    unsigned int n,space=0;
  823. X    unsigned long l;
  824. X    unsigned long w,x,y,z;
  825. X    unsigned int blank='\n'-' ';
  826. X
  827. X    for (j=0; j<num; )
  828. X        {
  829. X        n= *(in++)-' ';
  830. X        if (n == blank)
  831. X            {
  832. X            n=0;
  833. X            in--;
  834. X            }
  835. X        if (n > 60)
  836. X            {
  837. X            fprintf(stderr,"uuencoded line length too long\n");
  838. X            return(-1);
  839. X            }
  840. X        j++;
  841. X
  842. X        for (i=0; i<n; j+=4,i+=3)
  843. X            {
  844. X            /* the following is for cases where spaces are
  845. X             * removed from lines.
  846. X             */
  847. X            if (space)
  848. X                {
  849. X                w=x=y=z=0;
  850. X                }
  851. X            else
  852. X                {
  853. X                w= *(in++)-' ';
  854. X                x= *(in++)-' ';
  855. X                y= *(in++)-' ';
  856. X                z= *(in++)-' ';
  857. X                }
  858. X            if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
  859. X                {
  860. X                k=0;
  861. X                if (w == blank) k=1;
  862. X                if (x == blank) k=2;
  863. X                if (y == blank) k=3;
  864. X                if (z == blank) k=4;
  865. X                space=1;
  866. X                switch (k) {
  867. X                case 1:    w=0; in--;
  868. X                case 2: x=0; in--;
  869. X                case 3: y=0; in--;
  870. X                case 4: z=0; in--;
  871. X                    break;
  872. X                case 0:
  873. X                    space=0;
  874. X                    fprintf(stderr,"bad uuencoded data values\n");
  875. X                    w=x=y=z=0;
  876. X                    return(-1);
  877. X                    break;
  878. X                    }
  879. X                }
  880. X            l=(w<<18)|(x<<12)|(y<< 6)|(z    );
  881. X            l2ccc(l,out);
  882. X            }
  883. X        if (*(in++) != '\n')
  884. X            {
  885. X            fprintf(stderr,"missing nl in uuencoded line\n");
  886. X            w=x=y=z=0;
  887. X            return(-1);
  888. X            }
  889. X        j++;
  890. X        }
  891. X    *out='\0';
  892. X    w=x=y=z=0;
  893. X    return(n);
  894. X    }
  895. END_OF_FILE
  896.   if test 16298 -ne `wc -c <'des.c'`; then
  897.     echo shar: \"'des.c'\" unpacked with wrong size!
  898.   fi
  899.   # end of 'des.c'
  900. fi
  901. if test -f 'destest.c' -a "${1}" != "-c" ; then 
  902.   echo shar: Will not clobber existing file \"'destest.c'\"
  903. else
  904.   echo shar: Extracting \"'destest.c'\" \(12238 characters\)
  905.   sed "s/^X//" >'destest.c' <<'END_OF_FILE'
  906. X/* destest.c */
  907. X/* Copyright (C) 1993 Eric Young - see README for more details */
  908. X#include <stdio.h>
  909. X#include "des_locl.h" /* for des.h and bcopy macros */
  910. X/* tisk tisk - the test keys don't all have odd parity :-( */
  911. X
  912. X/* test data */
  913. X#define NUM_TESTS 34
  914. Xstatic unsigned char key_data[NUM_TESTS][8]={
  915. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  916. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  917. X    0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  918. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  919. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  920. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  921. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  922. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10,
  923. X    0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57,
  924. X    0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E,
  925. X    0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86,
  926. X    0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E,
  927. X    0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6,
  928. X    0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE,
  929. X    0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6,
  930. X    0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE,
  931. X    0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16,
  932. X    0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F,
  933. X    0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46,
  934. X    0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E,
  935. X    0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76,
  936. X    0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07,
  937. X    0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F,
  938. X    0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7,
  939. X    0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF,
  940. X    0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6,
  941. X    0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF,
  942. X    0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  943. X    0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E,
  944. X    0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE,
  945. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  946. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  947. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  948. X    0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
  949. X
  950. Xstatic unsigned char plain_data[NUM_TESTS][8]={
  951. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  952. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  953. X    0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  954. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  955. X    0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,
  956. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  957. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  958. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  959. X    0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42,
  960. X    0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA,
  961. X    0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72,
  962. X    0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A,
  963. X    0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2,
  964. X    0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A,
  965. X    0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2,
  966. X    0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A,
  967. X    0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02,
  968. X    0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A,
  969. X    0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32,
  970. X    0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA,
  971. X    0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62,
  972. X    0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2,
  973. X    0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA,
  974. X    0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92,
  975. X    0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A,
  976. X    0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2,
  977. X    0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A,
  978. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  979. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  980. X    0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,
  981. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  982. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  983. X    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  984. X    0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
  985. X
  986. Xstatic unsigned char cipher_data[NUM_TESTS][8]={
  987. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  988. X    0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58,
  989. X    0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B,
  990. X    0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33,
  991. X    0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D,
  992. X    0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD,
  993. X    0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7,
  994. X    0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4,
  995. X    0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B,
  996. X    0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71,
  997. X    0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A,
  998. X    0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A,
  999. X    0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95,
  1000. X    0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B,
  1001. X    0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09,
  1002. X    0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A,
  1003. X    0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F,
  1004. X    0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88,
  1005. X    0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77,
  1006. X    0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A,
  1007. X    0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56,
  1008. X    0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56,
  1009. X    0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56,
  1010. X    0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC,
  1011. X    0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A,
  1012. X    0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41,
  1013. X    0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93,
  1014. X    0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00,
  1015. X    0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06,
  1016. X    0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7,
  1017. X    0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51,
  1018. X    0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE,
  1019. X    0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D,
  1020. X    0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2};
  1021. X
  1022. Xstatic unsigned char cbc_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  1023. Xstatic unsigned char cbc_iv[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
  1024. Xstatic unsigned char cbc_data[40]="7654321 Now is the time for ";
  1025. X
  1026. Xstatic unsigned char cbc_ok[32]={
  1027. X    0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
  1028. X    0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
  1029. X    0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
  1030. X    0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
  1031. X
  1032. Xstatic unsigned char pcbc_ok[32]={
  1033. X    0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
  1034. X    0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
  1035. X    0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
  1036. X    0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
  1037. X
  1038. Xstatic unsigned char cksum_ok[8]={
  1039. X    0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
  1040. X
  1041. Xstatic unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  1042. Xstatic unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
  1043. Xstatic unsigned char cfb_buf1[24],cfb_buf2[24],cfb_tmp[8];
  1044. Xstatic unsigned char cfb_plain[24]=
  1045. X    {
  1046. X    0x4e,0x6f,0x77,0x20,0x69,0x73,
  1047. X    0x20,0x74,0x68,0x65,0x20,0x74,
  1048. X    0x69,0x6d,0x65,0x20,0x66,0x6f,
  1049. X    0x72,0x20,0x61,0x6c,0x6c,0x20
  1050. X    };
  1051. Xstatic unsigned char cfb_cipher[24]=
  1052. X    {
  1053. X    0xf3,0x1f,0xda,0x07,0x01,0x14,
  1054. X    0x62,0xee,0x18,0x7f,0x43,0xd8,
  1055. X    0x0a,0x7c,0xd9,0xb5,0xb0,0xd2,
  1056. X    0x90,0xda,0x6e,0x5b,0x9a,0x87
  1057. X    };
  1058. X
  1059. Xstatic unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
  1060. Xstatic unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
  1061. Xstatic unsigned char ofb_plain[24]=
  1062. X    {
  1063. X    0x4e,0x6f,0x77,0x20,0x69,0x73,
  1064. X    0x20,0x74,0x68,0x65,0x20,0x74,
  1065. X    0x69,0x6d,0x65,0x20,0x66,0x6f,
  1066. X    0x72,0x20,0x61,0x6c,0x6c,0x20
  1067. X    };
  1068. Xstatic unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
  1069. Xstatic unsigned char ofb_cipher[24]=
  1070. X    {
  1071. X    0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
  1072. X    0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
  1073. X    0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
  1074. X    };
  1075. X
  1076. Xchar *malloc();
  1077. Xchar *pt();
  1078. X
  1079. Xmain()
  1080. X    {
  1081. X    int i,j;
  1082. X    des_cblock in,out,outin;
  1083. X    des_key_schedule ks;
  1084. X    unsigned char cbc_in[40],cbc_out[40];
  1085. X    unsigned long cs;
  1086. X    unsigned char qret[4][4];
  1087. X    unsigned long lqret[4];
  1088. X    char *str;
  1089. X
  1090. X    printf("Doing ecb\n");
  1091. X    for (i=0; i<NUM_TESTS; i++)
  1092. X        {
  1093. X        if ((j=key_sched((C_Block *)(key_data[i]),ks)) != 0)
  1094. X            printf("Key error %2d:%d\n",i+1,j);
  1095. X        bcopy(plain_data[i],in,8);
  1096. X        bzero(out,8);
  1097. X        bzero(outin,8);
  1098. X        des_ecb_encrypt((C_Block *)in,(C_Block *)out,ks,DES_ENCRYPT);
  1099. X        des_ecb_encrypt((C_Block *)out,(C_Block *)outin,ks,DES_DECRYPT);
  1100. X
  1101. X        if (bcmp(out,cipher_data[i],8) != 0)
  1102. X            {
  1103. X            printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
  1104. X                i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
  1105. X                pt(out));
  1106. X            }
  1107. X        if (bcmp(in,outin,8) != 0)
  1108. X            {
  1109. X            printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
  1110. X                i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
  1111. X            }
  1112. X        }
  1113. X
  1114. X    printf("Doing cbc\n");
  1115. X    if ((j=key_sched((C_Block *)cbc_key,ks)) != 0)
  1116. X        printf("Key error %2d:%d\n",i+1,j);
  1117. X    bzero(cbc_out,40);
  1118. X    bzero(cbc_in,40);
  1119. X    des_cbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
  1120. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_ENCRYPT);
  1121. X    if (bcmp(cbc_out,cbc_ok,32) != 0)
  1122. X        printf("cbc_encrypt encrypt error\n");
  1123. X    des_cbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
  1124. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_DECRYPT);
  1125. X    if (bcmp(cbc_in,cbc_data,32) != 0)
  1126. X        printf("cbc_encrypt decrypt error\n");
  1127. X
  1128. X    printf("Doing pcbc\n");
  1129. X    if ((j=key_sched((C_Block *)cbc_key,ks)) != 0)
  1130. X        printf("Key error %2d:%d\n",i+1,j);
  1131. X    bzero(cbc_out,40);
  1132. X    bzero(cbc_in,40);
  1133. X    des_pcbc_encrypt((C_Block *)cbc_data,(C_Block *)cbc_out,
  1134. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_ENCRYPT);
  1135. X    if (bcmp(cbc_out,pcbc_ok,32) != 0)
  1136. X        printf("pcbc_encrypt encrypt error\n");
  1137. X    des_pcbc_encrypt((C_Block *)cbc_out,(C_Block *)cbc_in,
  1138. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,DES_DECRYPT);
  1139. X    if (bcmp(cbc_in,cbc_data,32) != 0)
  1140. X        printf("pcbc_encrypt decrypt error\n");
  1141. X
  1142. X    printf("Doing cfb\n");
  1143. X    key_sched((C_Block *)cfb_key,ks);
  1144. X    bcopy(cfb_iv,cfb_tmp,sizeof(cfb_iv));
  1145. X    des_cfb_encrypt(cfb_plain,cfb_buf1,8,(long)sizeof(cfb_plain),ks,
  1146. X        (C_Block *)cfb_tmp,DES_ENCRYPT);
  1147. X    if (bcmp(cfb_cipher,cfb_buf1,sizeof(cfb_buf1)) != 0)
  1148. X        printf("cfb_encrypt encrypt error\n");
  1149. X    bcopy(cfb_iv,cfb_tmp,sizeof(cfb_iv));
  1150. X    des_cfb_encrypt(cfb_buf1,cfb_buf2,8,(long)sizeof(cfb_buf1),ks,
  1151. X        (C_Block *)cfb_tmp,DES_DECRYPT);
  1152. X    if (bcmp(cfb_plain,cfb_buf2,sizeof(cfb_buf2)) != 0)
  1153. X        printf("cfb_encrypt decrypt error\n");
  1154. X
  1155. X    bcopy(cfb_iv,cfb_tmp,sizeof(cfb_iv));
  1156. X    for (i=0; i<sizeof(cfb_plain); i++)
  1157. X        des_cfb_encrypt(&(cfb_plain[i]),&(cfb_buf1[i]),
  1158. X            8,(long)1,ks,(C_Block *)cfb_tmp,DES_ENCRYPT);
  1159. X    if (bcmp(cfb_cipher,cfb_buf1,sizeof(cfb_buf1)) != 0)
  1160. X        printf("cfb_encrypt small encrypt error\n");
  1161. X
  1162. X    bcopy(cfb_iv,cfb_tmp,sizeof(cfb_iv));
  1163. X    for (i=0; i<sizeof(cfb_plain); i++)
  1164. X        des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
  1165. X            8,(long)1,ks,(C_Block *)cfb_tmp,DES_DECRYPT);
  1166. X    if (bcmp(cfb_plain,cfb_buf2,sizeof(cfb_buf2)) != 0)
  1167. X        printf("cfb_encrypt small decrypt error\n");
  1168. X
  1169. X    printf("Doing ofb\n");
  1170. X    key_sched((C_Block *)ofb_key,ks);
  1171. X    bcopy(ofb_iv,ofb_tmp,sizeof(ofb_iv));
  1172. X    des_ofb_encrypt(ofb_plain,ofb_buf1,64,(long)sizeof(cfb_plain)/8,ks,
  1173. X        (C_Block *)ofb_tmp);
  1174. X    if (bcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
  1175. X        printf("ofb_encrypt encrypt error\n");
  1176. X    bcopy(ofb_iv,ofb_tmp,sizeof(ofb_iv));
  1177. X    des_ofb_encrypt(ofb_buf1,ofb_buf2,64,(long)sizeof(ofb_buf1)/8,ks,
  1178. X        (C_Block *)ofb_tmp);
  1179. X    if (bcmp(ofb_plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
  1180. X        printf("ofb_encrypt decrypt error\n");
  1181. X
  1182. X    printf("Doing cbc_cksum\n");
  1183. X    des_cbc_cksum((C_Block *)cbc_data,(C_Block *)cbc_out,
  1184. X        (long)strlen(cbc_data),ks,(C_Block *)cbc_iv);
  1185. X    if (bcmp(cbc_out,cksum_ok,8) != 0)
  1186. X        printf("cbc_cksum error\n");
  1187. X
  1188. X    printf("Doing quad_cksum\n");
  1189. X    cs=quad_cksum((C_Block *)cbc_data,(C_Block *)qret,
  1190. X        (long)strlen(cbc_data),2,(C_Block *)cbc_iv);
  1191. X    for (i=0; i<4; i++)
  1192. X        {
  1193. X        lqret[i]=0;
  1194. X        bcopy(&(qret[i][0]),&(lqret[i]),4);
  1195. X        }
  1196. X    { /* Big-endian fix */
  1197. X    static unsigned long l=1;
  1198. X    static unsigned char *c=(unsigned char *)&l;
  1199. X    unsigned long ll;
  1200. X
  1201. X    if (!c[0])
  1202. X        {
  1203. X        ll=lqret[0]^lqret[3];
  1204. X        lqret[0]^=ll;
  1205. X        lqret[3]^=ll;
  1206. X        ll=lqret[1]^lqret[2];
  1207. X        lqret[1]^=ll;
  1208. X        lqret[2]^=ll;
  1209. X        }
  1210. X    }
  1211. X    if (cs != 0x70d7a63a)
  1212. X        printf("quad_cksum error, ret %08x should be 70d7a63a\n",cs);
  1213. X    if (lqret[0] != 0x327eba8d)
  1214. X        printf("quad_cksum error, out[0] %08x is not %08x\n",
  1215. X            lqret[0],0x327eba8d);
  1216. X    if (lqret[1] != 0x201a49cc)
  1217. X        printf("quad_cksum error, out[1] %08x is not %08x\n",
  1218. X            lqret[1],0x201a49cc);
  1219. X    if (lqret[2] != 0x70d7a63a)
  1220. X        printf("quad_cksum error, out[2] %08x is not %08x\n",
  1221. X            lqret[2],0x70d7a63a);
  1222. X    if (lqret[3] != 0x501c2c26)
  1223. X        printf("quad_cksum error, out[3] %08x is not %08x\n",
  1224. X            lqret[3],0x501c2c26);
  1225. X
  1226. X    printf("input word alignment test");
  1227. X    for (i=0; i<4; i++)
  1228. X        {
  1229. X        printf(" %d",i);
  1230. X        des_cbc_encrypt((C_Block *)&(cbc_out[i]),(C_Block *)cbc_in,
  1231. X            (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,
  1232. X            DES_ENCRYPT);
  1233. X        }
  1234. X    printf("\noutput word alignment test");
  1235. X    for (i=0; i<4; i++)
  1236. X        {
  1237. X        printf(" %d",i);
  1238. X        des_cbc_encrypt((C_Block *)cbc_out,(C_Block *)&(cbc_in[i]),
  1239. X            (long)strlen(cbc_data),ks,(C_Block *)cbc_iv,
  1240. X            DES_ENCRYPT);
  1241. X        }
  1242. X    printf("\n");
  1243. X    printf("fast crypt test ");
  1244. X    str=crypt("testing","ef");
  1245. X    if (strcmp("efGnQx2725bI2",str) != 0)
  1246. X        printf("fast crypt error, %x should be efGnQx2725bI2\n",str);
  1247. X    str=crypt("bca76;23","yA");
  1248. X    if (strcmp("yA1Rp/1hZXIJk",str) != 0)
  1249. X        printf("fast crypt error, %x should be yA1Rp/1hZXIJk\n",str);
  1250. X    printf("\n");
  1251. X    exit(0);
  1252. X    }
  1253. X
  1254. Xchar *pt(p)
  1255. Xunsigned char *p;
  1256. X    {
  1257. X    char *ret;
  1258. X    int i;
  1259. X    static char *f="0123456789ABCDEF";
  1260. X
  1261. X    ret=(char *)malloc(17);
  1262. X    for (i=0; i<8; i++)
  1263. X        {
  1264. X        ret[i*2]=f[(p[i]>>4)&0xf];
  1265. X        ret[i*2+1]=f[p[i]&0xf];
  1266. X        }
  1267. X    ret[16]='\0';
  1268. X    return(ret);
  1269. X    }
  1270. X    
  1271. END_OF_FILE
  1272.   if test 12238 -ne `wc -c <'destest.c'`; then
  1273.     echo shar: \"'destest.c'\" unpacked with wrong size!
  1274.   fi
  1275.   # end of 'destest.c'
  1276. fi
  1277. if test -f 'doPC2' -a "${1}" != "-c" ; then 
  1278.   echo shar: Will not clobber existing file \"'doPC2'\"
  1279. else
  1280.   echo shar: Extracting \"'doPC2'\" \(1578 characters\)
  1281.   sed "s/^X//" >'doPC2' <<'END_OF_FILE'
  1282. X#!/usr/local/bin/perl
  1283. X
  1284. X@PC2_C=(14,17,11,24, 1, 5,
  1285. X     3,28,15, 6,21,10,
  1286. X    23,19,12, 4,26, 8,
  1287. X    16, 7,27,20,13, 2,
  1288. X    );
  1289. X
  1290. X@PC2_D=(41,52,31,37,47,55,
  1291. X    30,40,51,45,33,48,
  1292. X    44,49,39,56,34,53,
  1293. X    46,42,50,36,29,32,
  1294. X    );
  1295. X
  1296. X$i=0;
  1297. Xforeach (@PC2_C) {
  1298. X    $_--;
  1299. X#    printf "%2d,",$_;
  1300. X    $C{$_}=$i;
  1301. X    ++$i;
  1302. X#    print "\n" if ((($i) % 8) == 0);
  1303. X    }
  1304. X$i=0;
  1305. X#print "\n";
  1306. Xforeach (@PC2_D) {
  1307. X    $_-=28;
  1308. X    $_--;
  1309. X#    printf "%2d,",$_;
  1310. X    $D{$_}=$i;
  1311. X    $i++;
  1312. X#    print "\n" if ((($i) % 8) == 0);
  1313. X    }
  1314. X
  1315. X#print "\n";
  1316. Xforeach $i (0 .. 27)
  1317. X    {
  1318. X    $_=$C{$i};
  1319. X#    printf "%2d,",$_;
  1320. X    $i++;
  1321. X#    print "\n" if ((($i) % 8) == 0);
  1322. X    }
  1323. X#print "\n";
  1324. X
  1325. X#print "\n";
  1326. Xforeach $i (0 .. 27)
  1327. X    {
  1328. X    $_=$D{$i};
  1329. X#    printf "%2d,",$_;
  1330. X    $i++;
  1331. X#    print "\n" if ((($i) % 8) == 0);
  1332. X    }
  1333. X#print "\n";
  1334. X
  1335. Xprint "static ulong skb[8][64]={\n";
  1336. X&doit("C",*C, 0, 1, 2, 3, 4, 5);
  1337. X&doit("C",*C, 6, 7, 9,10,11,12);
  1338. X&doit("C",*C,13,14,15,16,18,19);
  1339. X&doit("C",*C,20,22,23,25,26,27);
  1340. X
  1341. X&doit("D",*D, 0, 1, 2, 3, 4, 5);
  1342. X&doit("D",*D, 7, 8,10,11,12,13);
  1343. X&doit("D",*D,15,16,17,18,19,20);
  1344. X&doit("D",*D,21,22,23,24,26,27);
  1345. Xprint "};\n";
  1346. X
  1347. Xsub doit
  1348. X    {
  1349. X    local($l,*A,@b)=@_;
  1350. X    local(@out);
  1351. X
  1352. X    printf("/* for $l bits (numbered as per FIPS 46) %d %d %d %d %d %d */\n",
  1353. X        $b[0]+1, $b[1]+1, $b[2]+1, $b[3]+1, $b[4]+1, $b[5]+1);
  1354. X    for ($i=0; $i<64; $i++)
  1355. X        {
  1356. X        $out[$i]=0;
  1357. X        $j=1;
  1358. X#print "\n";
  1359. X        for ($k=0; $k<6; $k++)
  1360. X            {
  1361. X            $l=$A{$b[$k]};
  1362. X#print"$l - ";
  1363. X            if ((1<<$k) & $i)
  1364. X                {
  1365. X                $ll=int($l/6)*8+($l%6);
  1366. X                $out[$i]|=1<<($ll);
  1367. X                }
  1368. X            }
  1369. X        $pp=$out[$i];
  1370. X        $pp=($pp&0xff0000ff)|   (($pp&0x00ff0000)>>8)|
  1371. X                    (($pp&0x0000ff00)<<8);
  1372. X        printf("0x%08X,",$pp);
  1373. X        print "\n" if (($i+1) % 4 == 0);
  1374. X        }
  1375. X    }
  1376. END_OF_FILE
  1377.   if test 1578 -ne `wc -c <'doPC2'`; then
  1378.     echo shar: \"'doPC2'\" unpacked with wrong size!
  1379.   fi
  1380.   # end of 'doPC2'
  1381. fi
  1382. if test -f 'fcrypt.c' -a "${1}" != "-c" ; then 
  1383.   echo shar: Will not clobber existing file \"'fcrypt.c'\"
  1384. else
  1385.   echo shar: Extracting \"'fcrypt.c'\" \(20174 characters\)
  1386.   sed "s/^X//" >'fcrypt.c' <<'END_OF_FILE'
  1387. X/* fcrypt.c */
  1388. X/* Copyright (C) 1993 Eric Young - see README for more details */
  1389. X#include <stdio.h>
  1390. X
  1391. X/* Eric Young.
  1392. X * This version of crypt has been developed from my MIT compatable
  1393. X * DES library.
  1394. X * The library is available at pub/DES at ftp.psy.uq.oz.au
  1395. X * eay@psych.psy.uq.oz.au
  1396. X */
  1397. X
  1398. Xtypedef unsigned char des_cblock[8];
  1399. X
  1400. Xtypedef struct des_ks_struct
  1401. X    {
  1402. X    union    {
  1403. X        des_cblock _;
  1404. X        /* make sure things are correct size on machines with
  1405. X         * 8 byte longs */
  1406. X        unsigned long pad[2];
  1407. X        } ks;
  1408. X#define _    ks._
  1409. X    } des_key_schedule[16];
  1410. X
  1411. X#define DES_KEY_SZ     (sizeof(des_cblock))
  1412. X#define DES_ENCRYPT    1
  1413. X#define DES_DECRYPT    0
  1414. X
  1415. X#define ITERATIONS 16
  1416. X#define HALF_ITERATIONS 8
  1417. X
  1418. X#define c2l(c,l)    (l =((unsigned long)(*((c)++)))    , \
  1419. X             l|=((unsigned long)(*((c)++)))<< 8, \
  1420. X             l|=((unsigned long)(*((c)++)))<<16, \
  1421. X             l|=((unsigned long)(*((c)++)))<<24)
  1422. X
  1423. X#define l2c(l,c)    (*((c)++)=(unsigned char)(((l)    )&0xff), \
  1424. X             *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
  1425. X             *((c)++)=(unsigned char)(((l)>>16)&0xff), \
  1426. X             *((c)++)=(unsigned char)(((l)>>24)&0xff))
  1427. X
  1428. Xstatic unsigned long SPtrans[8][64]={
  1429. X/* nibble 0 */
  1430. X0x00820200, 0x00020000, 0x80800000, 0x80820200,
  1431. X0x00800000, 0x80020200, 0x80020000, 0x80800000,
  1432. X0x80020200, 0x00820200, 0x00820000, 0x80000200,
  1433. X0x80800200, 0x00800000, 0x00000000, 0x80020000,
  1434. X0x00020000, 0x80000000, 0x00800200, 0x00020200,
  1435. X0x80820200, 0x00820000, 0x80000200, 0x00800200,
  1436. X0x80000000, 0x00000200, 0x00020200, 0x80820000,
  1437. X0x00000200, 0x80800200, 0x80820000, 0x00000000,
  1438. X0x00000000, 0x80820200, 0x00800200, 0x80020000,
  1439. X0x00820200, 0x00020000, 0x80000200, 0x00800200,
  1440. X0x80820000, 0x00000200, 0x00020200, 0x80800000,
  1441. X0x80020200, 0x80000000, 0x80800000, 0x00820000,
  1442. X0x80820200, 0x00020200, 0x00820000, 0x80800200,
  1443. X0x00800000, 0x80000200, 0x80020000, 0x00000000,
  1444. X0x00020000, 0x00800000, 0x80800200, 0x00820200,
  1445. X0x80000000, 0x80820000, 0x00000200, 0x80020200,
  1446. X/* nibble 1 */
  1447. X0x10042004, 0x00000000, 0x00042000, 0x10040000,
  1448. X0x10000004, 0x00002004, 0x10002000, 0x00042000,
  1449. X0x00002000, 0x10040004, 0x00000004, 0x10002000,
  1450. X0x00040004, 0x10042000, 0x10040000, 0x00000004,
  1451. X0x00040000, 0x10002004, 0x10040004, 0x00002000,
  1452. X0x00042004, 0x10000000, 0x00000000, 0x00040004,
  1453. X0x10002004, 0x00042004, 0x10042000, 0x10000004,
  1454. X0x10000000, 0x00040000, 0x00002004, 0x10042004,
  1455. X0x00040004, 0x10042000, 0x10002000, 0x00042004,
  1456. X0x10042004, 0x00040004, 0x10000004, 0x00000000,
  1457. X0x10000000, 0x00002004, 0x00040000, 0x10040004,
  1458. X0x00002000, 0x10000000, 0x00042004, 0x10002004,
  1459. X0x10042000, 0x00002000, 0x00000000, 0x10000004,
  1460. X0x00000004, 0x10042004, 0x00042000, 0x10040000,
  1461. X0x10040004, 0x00040000, 0x00002004, 0x10002000,
  1462. X0x10002004, 0x00000004, 0x10040000, 0x00042000,
  1463. X/* nibble 2 */
  1464. X0x41000000, 0x01010040, 0x00000040, 0x41000040,
  1465. X0x40010000, 0x01000000, 0x41000040, 0x00010040,
  1466. X0x01000040, 0x00010000, 0x01010000, 0x40000000,
  1467. X0x41010040, 0x40000040, 0x40000000, 0x41010000,
  1468. X0x00000000, 0x40010000, 0x01010040, 0x00000040,
  1469. X0x40000040, 0x41010040, 0x00010000, 0x41000000,
  1470. X0x41010000, 0x01000040, 0x40010040, 0x01010000,
  1471. X0x00010040, 0x00000000, 0x01000000, 0x40010040,
  1472. X0x01010040, 0x00000040, 0x40000000, 0x00010000,
  1473. X0x40000040, 0x40010000, 0x01010000, 0x41000040,
  1474. X0x00000000, 0x01010040, 0x00010040, 0x41010000,
  1475. X0x40010000, 0x01000000, 0x41010040, 0x40000000,
  1476. X0x40010040, 0x41000000, 0x01000000, 0x41010040,
  1477. X0x00010000, 0x01000040, 0x41000040, 0x00010040,
  1478. X0x01000040, 0x00000000, 0x41010000, 0x40000040,
  1479. X0x41000000, 0x40010040, 0x00000040, 0x01010000,
  1480. X/* nibble 3 */
  1481. X0x00100402, 0x04000400, 0x00000002, 0x04100402,
  1482. X0x00000000, 0x04100000, 0x04000402, 0x00100002,
  1483. X0x04100400, 0x04000002, 0x04000000, 0x00000402,
  1484. X0x04000002, 0x00100402, 0x00100000, 0x04000000,
  1485. X0x04100002, 0x00100400, 0x00000400, 0x00000002,
  1486. X0x00100400, 0x04000402, 0x04100000, 0x00000400,
  1487. X0x00000402, 0x00000000, 0x00100002, 0x04100400,
  1488. X0x04000400, 0x04100002, 0x04100402, 0x00100000,
  1489. X0x04100002, 0x00000402, 0x00100000, 0x04000002,
  1490. X0x00100400, 0x04000400, 0x00000002, 0x04100000,
  1491. X0x04000402, 0x00000000, 0x00000400, 0x00100002,
  1492. X0x00000000, 0x04100002, 0x04100400, 0x00000400,
  1493. X0x04000000, 0x04100402, 0x00100402, 0x00100000,
  1494. X0x04100402, 0x00000002, 0x04000400, 0x00100402,
  1495. X0x00100002, 0x00100400, 0x04100000, 0x04000402,
  1496. X0x00000402, 0x04000000, 0x04000002, 0x04100400,
  1497. X/* nibble 4 */
  1498. X0x02000000, 0x00004000, 0x00000100, 0x02004108,
  1499. X0x02004008, 0x02000100, 0x00004108, 0x02004000,
  1500. X0x00004000, 0x00000008, 0x02000008, 0x00004100,
  1501. X0x02000108, 0x02004008, 0x02004100, 0x00000000,
  1502. X0x00004100, 0x02000000, 0x00004008, 0x00000108,
  1503. X0x02000100, 0x00004108, 0x00000000, 0x02000008,
  1504. X0x00000008, 0x02000108, 0x02004108, 0x00004008,
  1505. X0x02004000, 0x00000100, 0x00000108, 0x02004100,
  1506. X0x02004100, 0x02000108, 0x00004008, 0x02004000,
  1507. X0x00004000, 0x00000008, 0x02000008, 0x02000100,
  1508. X0x02000000, 0x00004100, 0x02004108, 0x00000000,
  1509. X0x00004108, 0x02000000, 0x00000100, 0x00004008,
  1510. X0x02000108, 0x00000100, 0x00000000, 0x02004108,
  1511. X0x02004008, 0x02004100, 0x00000108, 0x00004000,
  1512. X0x00004100, 0x02004008, 0x02000100, 0x00000108,
  1513. X0x00000008, 0x00004108, 0x02004000, 0x02000008,
  1514. X/* nibble 5 */
  1515. X0x20000010, 0x00080010, 0x00000000, 0x20080800,
  1516. X0x00080010, 0x00000800, 0x20000810, 0x00080000,
  1517. X0x00000810, 0x20080810, 0x00080800, 0x20000000,
  1518. X0x20000800, 0x20000010, 0x20080000, 0x00080810,
  1519. X0x00080000, 0x20000810, 0x20080010, 0x00000000,
  1520. X0x00000800, 0x00000010, 0x20080800, 0x20080010,
  1521. X0x20080810, 0x20080000, 0x20000000, 0x00000810,
  1522. X0x00000010, 0x00080800, 0x00080810, 0x20000800,
  1523. X0x00000810, 0x20000000, 0x20000800, 0x00080810,
  1524. X0x20080800, 0x00080010, 0x00000000, 0x20000800,
  1525. X0x20000000, 0x00000800, 0x20080010, 0x00080000,
  1526. X0x00080010, 0x20080810, 0x00080800, 0x00000010,
  1527. X0x20080810, 0x00080800, 0x00080000, 0x20000810,
  1528. X0x20000010, 0x20080000, 0x00080810, 0x00000000,
  1529. X0x00000800, 0x20000010, 0x20000810, 0x20080800,
  1530. X0x20080000, 0x00000810, 0x00000010, 0x20080010,
  1531. X/* nibble 6 */
  1532. X0x00001000, 0x00000080, 0x00400080, 0x00400001,
  1533. X0x00401081, 0x00001001, 0x00001080, 0x00000000,
  1534. X0x00400000, 0x00400081, 0x00000081, 0x00401000,
  1535. X0x00000001, 0x00401080, 0x00401000, 0x00000081,
  1536. X0x00400081, 0x00001000, 0x00001001, 0x00401081,
  1537. X0x00000000, 0x00400080, 0x00400001, 0x00001080,
  1538. X0x00401001, 0x00001081, 0x00401080, 0x00000001,
  1539. X0x00001081, 0x00401001, 0x00000080, 0x00400000,
  1540. X0x00001081, 0x00401000, 0x00401001, 0x00000081,
  1541. X0x00001000, 0x00000080, 0x00400000, 0x00401001,
  1542. X0x00400081, 0x00001081, 0x00001080, 0x00000000,
  1543. X0x00000080, 0x00400001, 0x00000001, 0x00400080,
  1544. X0x00000000, 0x00400081, 0x00400080, 0x00001080,
  1545. X0x00000081, 0x00001000, 0x00401081, 0x00400000,
  1546. X0x00401080, 0x00000001, 0x00001001, 0x00401081,
  1547. X0x00400001, 0x00401080, 0x00401000, 0x00001001,
  1548. X/* nibble 7 */
  1549. X0x08200020, 0x08208000, 0x00008020, 0x00000000,
  1550. X0x08008000, 0x00200020, 0x08200000, 0x08208020,
  1551. X0x00000020, 0x08000000, 0x00208000, 0x00008020,
  1552. X0x00208020, 0x08008020, 0x08000020, 0x08200000,
  1553. X0x00008000, 0x00208020, 0x00200020, 0x08008000,
  1554. X0x08208020, 0x08000020, 0x00000000, 0x00208000,
  1555. X0x08000000, 0x00200000, 0x08008020, 0x08200020,
  1556. X0x00200000, 0x00008000, 0x08208000, 0x00000020,
  1557. X0x00200000, 0x00008000, 0x08000020, 0x08208020,
  1558. X0x00008020, 0x08000000, 0x00000000, 0x00208000,
  1559. X0x08200020, 0x08008020, 0x08008000, 0x00200020,
  1560. X0x08208000, 0x00000020, 0x00200020, 0x08008000,
  1561. X0x08208020, 0x00200000, 0x08200000, 0x08000020,
  1562. X0x00208000, 0x00008020, 0x08008020, 0x08200000,
  1563. X0x00000020, 0x08208000, 0x00208020, 0x00000000,
  1564. X0x08000000, 0x08200020, 0x00008000, 0x00208020};
  1565. Xstatic unsigned long skb[8][64]={
  1566. X/* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  1567. X0x00000000,0x00000010,0x20000000,0x20000010,
  1568. X0x00010000,0x00010010,0x20010000,0x20010010,
  1569. X0x00000800,0x00000810,0x20000800,0x20000810,
  1570. X0x00010800,0x00010810,0x20010800,0x20010810,
  1571. X0x00000020,0x00000030,0x20000020,0x20000030,
  1572. X0x00010020,0x00010030,0x20010020,0x20010030,
  1573. X0x00000820,0x00000830,0x20000820,0x20000830,
  1574. X0x00010820,0x00010830,0x20010820,0x20010830,
  1575. X0x00080000,0x00080010,0x20080000,0x20080010,
  1576. X0x00090000,0x00090010,0x20090000,0x20090010,
  1577. X0x00080800,0x00080810,0x20080800,0x20080810,
  1578. X0x00090800,0x00090810,0x20090800,0x20090810,
  1579. X0x00080020,0x00080030,0x20080020,0x20080030,
  1580. X0x00090020,0x00090030,0x20090020,0x20090030,
  1581. X0x00080820,0x00080830,0x20080820,0x20080830,
  1582. X0x00090820,0x00090830,0x20090820,0x20090830,
  1583. X/* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */
  1584. X0x00000000,0x02000000,0x00002000,0x02002000,
  1585. X0x00200000,0x02200000,0x00202000,0x02202000,
  1586. X0x00000004,0x02000004,0x00002004,0x02002004,
  1587. X0x00200004,0x02200004,0x00202004,0x02202004,
  1588. X0x00000400,0x02000400,0x00002400,0x02002400,
  1589. X0x00200400,0x02200400,0x00202400,0x02202400,
  1590. X0x00000404,0x02000404,0x00002404,0x02002404,
  1591. X0x00200404,0x02200404,0x00202404,0x02202404,
  1592. X0x10000000,0x12000000,0x10002000,0x12002000,
  1593. X0x10200000,0x12200000,0x10202000,0x12202000,
  1594. X0x10000004,0x12000004,0x10002004,0x12002004,
  1595. X0x10200004,0x12200004,0x10202004,0x12202004,
  1596. X0x10000400,0x12000400,0x10002400,0x12002400,
  1597. X0x10200400,0x12200400,0x10202400,0x12202400,
  1598. X0x10000404,0x12000404,0x10002404,0x12002404,
  1599. X0x10200404,0x12200404,0x10202404,0x12202404,
  1600. X/* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */
  1601. X0x00000000,0x00000001,0x00040000,0x00040001,
  1602. X0x01000000,0x01000001,0x01040000,0x01040001,
  1603. X0x00000002,0x00000003,0x00040002,0x00040003,
  1604. X0x01000002,0x01000003,0x01040002,0x01040003,
  1605. X0x00000200,0x00000201,0x00040200,0x00040201,
  1606. X0x01000200,0x01000201,0x01040200,0x01040201,
  1607. X0x00000202,0x00000203,0x00040202,0x00040203,
  1608. X0x01000202,0x01000203,0x01040202,0x01040203,
  1609. X0x08000000,0x08000001,0x08040000,0x08040001,
  1610. X0x09000000,0x09000001,0x09040000,0x09040001,
  1611. X0x08000002,0x08000003,0x08040002,0x08040003,
  1612. X0x09000002,0x09000003,0x09040002,0x09040003,
  1613. X0x08000200,0x08000201,0x08040200,0x08040201,
  1614. X0x09000200,0x09000201,0x09040200,0x09040201,
  1615. X0x08000202,0x08000203,0x08040202,0x08040203,
  1616. X0x09000202,0x09000203,0x09040202,0x09040203,
  1617. X/* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */
  1618. X0x00000000,0x00100000,0x00000100,0x00100100,
  1619. X0x00000008,0x00100008,0x00000108,0x00100108,
  1620. X0x00001000,0x00101000,0x00001100,0x00101100,
  1621. X0x00001008,0x00101008,0x00001108,0x00101108,
  1622. X0x04000000,0x04100000,0x04000100,0x04100100,
  1623. X0x04000008,0x04100008,0x04000108,0x04100108,
  1624. X0x04001000,0x04101000,0x04001100,0x04101100,
  1625. X0x04001008,0x04101008,0x04001108,0x04101108,
  1626. X0x00020000,0x00120000,0x00020100,0x00120100,
  1627. X0x00020008,0x00120008,0x00020108,0x00120108,
  1628. X0x00021000,0x00121000,0x00021100,0x00121100,
  1629. X0x00021008,0x00121008,0x00021108,0x00121108,
  1630. X0x04020000,0x04120000,0x04020100,0x04120100,
  1631. X0x04020008,0x04120008,0x04020108,0x04120108,
  1632. X0x04021000,0x04121000,0x04021100,0x04121100,
  1633. X0x04021008,0x04121008,0x04021108,0x04121108,
  1634. X/* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */
  1635. X0x00000000,0x10000000,0x00010000,0x10010000,
  1636. X0x00000004,0x10000004,0x00010004,0x10010004,
  1637. X0x20000000,0x30000000,0x20010000,0x30010000,
  1638. X0x20000004,0x30000004,0x20010004,0x30010004,
  1639. X0x00100000,0x10100000,0x00110000,0x10110000,
  1640. X0x00100004,0x10100004,0x00110004,0x10110004,
  1641. X0x20100000,0x30100000,0x20110000,0x30110000,
  1642. X0x20100004,0x30100004,0x20110004,0x30110004,
  1643. X0x00001000,0x10001000,0x00011000,0x10011000,
  1644. X0x00001004,0x10001004,0x00011004,0x10011004,
  1645. X0x20001000,0x30001000,0x20011000,0x30011000,
  1646. X0x20001004,0x30001004,0x20011004,0x30011004,
  1647. X0x00101000,0x10101000,0x00111000,0x10111000,
  1648. X0x00101004,0x10101004,0x00111004,0x10111004,
  1649. X0x20101000,0x30101000,0x20111000,0x30111000,
  1650. X0x20101004,0x30101004,0x20111004,0x30111004,
  1651. X/* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */
  1652. X0x00000000,0x08000000,0x00000008,0x08000008,
  1653. X0x00000400,0x08000400,0x00000408,0x08000408,
  1654. X0x00020000,0x08020000,0x00020008,0x08020008,
  1655. X0x00020400,0x08020400,0x00020408,0x08020408,
  1656. X0x00000001,0x08000001,0x00000009,0x08000009,
  1657. X0x00000401,0x08000401,0x00000409,0x08000409,
  1658. X0x00020001,0x08020001,0x00020009,0x08020009,
  1659. X0x00020401,0x08020401,0x00020409,0x08020409,
  1660. X0x02000000,0x0A000000,0x02000008,0x0A000008,
  1661. X0x02000400,0x0A000400,0x02000408,0x0A000408,
  1662. X0x02020000,0x0A020000,0x02020008,0x0A020008,
  1663. X0x02020400,0x0A020400,0x02020408,0x0A020408,
  1664. X0x02000001,0x0A000001,0x02000009,0x0A000009,
  1665. X0x02000401,0x0A000401,0x02000409,0x0A000409,
  1666. X0x02020001,0x0A020001,0x02020009,0x0A020009,
  1667. X0x02020401,0x0A020401,0x02020409,0x0A020409,
  1668. X/* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */
  1669. X0x00000000,0x00000100,0x00080000,0x00080100,
  1670. X0x01000000,0x01000100,0x01080000,0x01080100,
  1671. X0x00000010,0x00000110,0x00080010,0x00080110,
  1672. X0x01000010,0x01000110,0x01080010,0x01080110,
  1673. X0x00200000,0x00200100,0x00280000,0x00280100,
  1674. X0x01200000,0x01200100,0x01280000,0x01280100,
  1675. X0x00200010,0x00200110,0x00280010,0x00280110,
  1676. X0x01200010,0x01200110,0x01280010,0x01280110,
  1677. X0x00000200,0x00000300,0x00080200,0x00080300,
  1678. X0x01000200,0x01000300,0x01080200,0x01080300,
  1679. X0x00000210,0x00000310,0x00080210,0x00080310,
  1680. X0x01000210,0x01000310,0x01080210,0x01080310,
  1681. X0x00200200,0x00200300,0x00280200,0x00280300,
  1682. X0x01200200,0x01200300,0x01280200,0x01280300,
  1683. X0x00200210,0x00200310,0x00280210,0x00280310,
  1684. X0x01200210,0x01200310,0x01280210,0x01280310,
  1685. X/* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */
  1686. X0x00000000,0x04000000,0x00040000,0x04040000,
  1687. X0x00000002,0x04000002,0x00040002,0x04040002,
  1688. X0x00002000,0x04002000,0x00042000,0x04042000,
  1689. X0x00002002,0x04002002,0x00042002,0x04042002,
  1690. X0x00000020,0x04000020,0x00040020,0x04040020,
  1691. X0x00000022,0x04000022,0x00040022,0x04040022,
  1692. X0x00002020,0x04002020,0x00042020,0x04042020,
  1693. X0x00002022,0x04002022,0x00042022,0x04042022,
  1694. X0x00000800,0x04000800,0x00040800,0x04040800,
  1695. X0x00000802,0x04000802,0x00040802,0x04040802,
  1696. X0x00002800,0x04002800,0x00042800,0x04042800,
  1697. X0x00002802,0x04002802,0x00042802,0x04042802,
  1698. X0x00000820,0x04000820,0x00040820,0x04040820,
  1699. X0x00000822,0x04000822,0x00040822,0x04040822,
  1700. X0x00002820,0x04002820,0x00042820,0x04042820,
  1701. X0x00002822,0x04002822,0x00042822,0x04042822,
  1702. X};
  1703. X
  1704. X/* See ecb_encrypt.c for a pseudo description of these macros. */
  1705. X#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
  1706. X    (b)^=(t),\
  1707. X    (a)^=((t)<<(n)))
  1708. X
  1709. X#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
  1710. X    (a)=(a)^(t)^(t>>(16-(n))))\
  1711. X
  1712. Xstatic char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
  1713. X
  1714. Xstatic int body();
  1715. Xstatic int des_set_key();
  1716. X
  1717. Xstatic int des_set_key(key,schedule)
  1718. Xdes_cblock *key;
  1719. Xdes_key_schedule schedule;
  1720. X    {
  1721. X    register unsigned long c,d,t,s;
  1722. X    register unsigned char *in;
  1723. X    register unsigned long *k;
  1724. X    register int i;
  1725. X
  1726. X    k=(unsigned long *)schedule;
  1727. X    in=(unsigned char *)key;
  1728. X
  1729. X    c2l(in,c);
  1730. X    c2l(in,d);
  1731. X
  1732. X    /* I now do it in 47 simple operations :-)
  1733. X     * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
  1734. X     * for the inspiration. :-) */
  1735. X    PERM_OP (d,c,t,4,0x0f0f0f0f);
  1736. X    HPERM_OP(c,t,-2,0xcccc0000);
  1737. X    HPERM_OP(d,t,-2,0xcccc0000);
  1738. X    PERM_OP (d,c,t,1,0x55555555);
  1739. X    PERM_OP (c,d,t,8,0x00ff00ff);
  1740. X    PERM_OP (d,c,t,1,0x55555555);
  1741. X    d=    (((d&0x000000ff)<<16)| (d&0x0000ff00)     |
  1742. X         ((d&0x00ff0000)>>16)|((c&0xf0000000)>>4));
  1743. X    c&=0x0fffffff;
  1744. X
  1745. X    for (i=0; i<ITERATIONS; i++)
  1746. X        {
  1747. X        if (shifts2[i])
  1748. X            { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
  1749. X        else
  1750. X            { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
  1751. X        c&=0x0fffffff;
  1752. X        d&=0x0fffffff;
  1753. X        /* could be a few less shifts but I am to lazy at this
  1754. X         * point in time to investigate */
  1755. X        s=    skb[0][ (c    )&0x3f                ]|
  1756. X            skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
  1757. X            skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
  1758. X            skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
  1759. X                                  ((c>>22)&0x38)];
  1760. X        t=    skb[4][ (d    )&0x3f                ]|
  1761. X            skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
  1762. X            skb[6][ (d>>15)&0x3f                ]|
  1763. X            skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
  1764. X
  1765. X        /* table contained 0213 4657 */
  1766. X        *(k++)=((t<<16)|(s&0x0000ffff))&0xffffffff;
  1767. X        s=     ((s>>16)|(t&0xffff0000));
  1768. X        
  1769. X        s=(s<<4)|(s>>28);
  1770. X        *(k++)=s&0xffffffff;
  1771. X        }
  1772. X    return(0);
  1773. X    }
  1774. X
  1775. X/******************************************************************
  1776. X * modified stuff for crypt.
  1777. X ******************************************************************/
  1778. X
  1779. X/* The changes to this macro may help or hinder, depending on the
  1780. X * compiler and the achitecture.  gcc2 always seems to do well :-). 
  1781. X * Inspired by Dana How <how@isl.stanford.edu>
  1782. X * DO NOT use the alternative version on machines with 8 byte longs.
  1783. X */
  1784. X#ifdef ALT_ECB
  1785. X#define D_ENCRYPT(L,R,S) \
  1786. X    v=(R^(R>>16)); \
  1787. X    u=(v&E0); \
  1788. X    v=(v&E1); \
  1789. X    u=((u^(u<<16))^R^s[S  ])<<2; \
  1790. X    t=(v^(v<<16))^R^s[S+1]; \
  1791. X    t=(t>>2)|(t<<30); \
  1792. X    L^= \
  1793. X    *(unsigned long *)(des_SP+0x0100+((t    )&0xfc))+ \
  1794. X    *(unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
  1795. X    *(unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
  1796. X    *(unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
  1797. X    *(unsigned long *)(des_SP+       ((u    )&0xfc))+ \
  1798. X      *(unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
  1799. X      *(unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
  1800. X     *(unsigned long *)(des_SP+0x0600+((u>>24)&0xfc));
  1801. X#else /* original version */
  1802. X#define D_ENCRYPT(L,R,S)    \
  1803. X    v=(R^(R>>16)); \
  1804. X    u=(v&E0); \
  1805. X    v=(v&E1); \
  1806. X    u=(u^(u<<16))^R^s[S  ]; \
  1807. X    t=(v^(v<<16))^R^s[S+1]; \
  1808. X    t=(t>>4)|(t<<28); \
  1809. X    L^=    SPtrans[1][(t    )&0x3f]| \
  1810. X        SPtrans[3][(t>> 8)&0x3f]| \
  1811. X        SPtrans[5][(t>>16)&0x3f]| \
  1812. X        SPtrans[7][(t>>24)&0x3f]| \
  1813. X        SPtrans[0][(u    )&0x3f]| \
  1814. X        SPtrans[2][(u>> 8)&0x3f]| \
  1815. X        SPtrans[4][(u>>16)&0x3f]| \
  1816. X        SPtrans[6][(u>>24)&0x3f];
  1817. X#endif
  1818. X
  1819. Xunsigned char con_salt[128]={
  1820. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1821. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1822. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1823. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1824. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  1825. X0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
  1826. X0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
  1827. X0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A,
  1828. X0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,
  1829. X0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,
  1830. X0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,
  1831. X0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24,
  1832. X0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,
  1833. X0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,
  1834. X0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,
  1835. X0x3D,0x3E,0x3F,0x00,0x00,0x00,0x00,0x00,
  1836. X};
  1837. X
  1838. Xunsigned char cov_2char[64]={
  1839. X0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,
  1840. X0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,
  1841. X0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,
  1842. X0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,
  1843. X0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62,
  1844. X0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,
  1845. X0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,
  1846. X0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
  1847. X};
  1848. X
  1849. Xchar *crypt(buf,salt)
  1850. Xchar *buf;
  1851. Xchar *salt;
  1852. X    {
  1853. X    unsigned int i,j,x,y;
  1854. X    unsigned long Eswap0=0,Eswap1=0;
  1855. X    unsigned long out[2],ll;
  1856. X    des_cblock key;
  1857. X    des_key_schedule ks;
  1858. X    static unsigned char buff[20];
  1859. X    unsigned char bb[9];
  1860. X    unsigned char *b=bb;
  1861. X    unsigned char c,u;
  1862. X
  1863. X    /* eay 25/08/92
  1864. X     * If you call crypt("pwd","*") as often happens when you
  1865. X     * have * as the pwd field in /etc/passwd, the function
  1866. X     * returns *\0XXXXXXXXX
  1867. X     * The \0 makes the string look like * so the pwd "*" would
  1868. X     * crypt to "*".  This was found when replacing the crypt in
  1869. X     * our shared libraries.  People found that the disbled
  1870. X     * accounts effectivly had no passwd :-(. */
  1871. X    if (salt[0] == '\0') salt[0]='A';
  1872. X    if (salt[1] == '\0') salt[1]='A';
  1873. X    x=buff[0]=salt[0];
  1874. X    Eswap0=con_salt[x];
  1875. X    x=buff[1]=salt[1];
  1876. X    Eswap1=con_salt[x]<<4;
  1877. X
  1878. X    for (i=0; i<8; i++)
  1879. X        {
  1880. X        c= *(buf++);
  1881. X        if (!c) break;
  1882. X        key[i]=(c<<1);
  1883. X        }
  1884. X    for (; i<8; i++)
  1885. X        key[i]=0;
  1886. X
  1887. X    des_set_key((des_cblock *)(key),ks);
  1888. X    body(&out[0],&out[1],ks,Eswap0,Eswap1);
  1889. X
  1890. X    ll=out[0]; l2c(ll,b);
  1891. X    ll=out[1]; l2c(ll,b);
  1892. X    y=0;
  1893. X    u=0x80;
  1894. X    bb[8]=0;
  1895. X    for (i=2; i<13; i++)
  1896. X        {
  1897. X        c=0;
  1898. X        for (j=0; j<6; j++)
  1899. X            {
  1900. X            c<<=1;
  1901. X            if (bb[y] & u) c|=1;
  1902. X            u>>=1;
  1903. X            if (!u)
  1904. X                {
  1905. X                y++;
  1906. X                u=0x80;
  1907. X                }
  1908. X            }
  1909. X        buff[i]=cov_2char[c];
  1910. X        }
  1911. X    return((char *)buff);
  1912. X    }
  1913. X
  1914. Xstatic int body(out0,out1,ks,Eswap0,Eswap1)
  1915. Xunsigned long *out0,*out1;
  1916. Xdes_key_schedule *ks;
  1917. Xunsigned long Eswap0,Eswap1;
  1918. X    {
  1919. X    register unsigned long l,r,t,u,v;
  1920. X#ifdef ALT_ECB
  1921. X    register unsigned char *des_SP=(unsigned char *)SPtrans;
  1922. X#endif
  1923. X    register unsigned long *s;
  1924. X    register int i,j;
  1925. X    register unsigned long E0,E1;
  1926. X
  1927. X    l=0;
  1928. X    r=0;
  1929. X
  1930. X    s=(unsigned long *)ks;
  1931. X    E0=Eswap0;
  1932. X    E1=Eswap1;
  1933. X
  1934. X    for (j=0; j<25; j++)
  1935. X        {
  1936. X        for (i=0; i<(ITERATIONS*2); i+=4)
  1937. X            {
  1938. X            D_ENCRYPT(l,r,  i);    /*  1 */
  1939. X            D_ENCRYPT(r,l,  i+2);    /*  2 */
  1940. X            }
  1941. X        t=l;
  1942. X        l=r;
  1943. X        r=t;
  1944. X        }
  1945. X    t=r;
  1946. X    r=(l>>1)|(l<<31);
  1947. X    l=(t>>1)|(t<<31);
  1948. X    /* clear the top bits on machines with 8byte longs */
  1949. X    l&=0xffffffff;
  1950. X    r&=0xffffffff;
  1951. X
  1952. X    PERM_OP(r,l,t, 1,0x55555555);
  1953. X    PERM_OP(l,r,t, 8,0x00ff00ff);
  1954. X    PERM_OP(r,l,t, 2,0x33333333);
  1955. X    PERM_OP(l,r,t,16,0x0000ffff);
  1956. X    PERM_OP(r,l,t, 4,0x0f0f0f0f);
  1957. X
  1958. X    *out0=l;
  1959. X    *out1=r;
  1960. X    return(0);
  1961. X    }
  1962. X
  1963. END_OF_FILE
  1964.   if test 20174 -ne `wc -c <'fcrypt.c'`; then
  1965.     echo shar: \"'fcrypt.c'\" unpacked with wrong size!
  1966.   fi
  1967.   # end of 'fcrypt.c'
  1968. fi
  1969. echo shar: End of archive 2 \(of 5\).
  1970. cp /dev/null ark2isdone
  1971. MISSING=""
  1972. for I in 1 2 3 4 5 ; do
  1973.     if test ! -f ark${I}isdone ; then
  1974.     MISSING="${MISSING} ${I}"
  1975.     fi
  1976. done
  1977. if test "${MISSING}" = "" ; then
  1978.     echo You have unpacked all 5 archives.
  1979.     rm -f ark[1-9]isdone
  1980. else
  1981.     echo You still must unpack the following archives:
  1982.     echo "        " ${MISSING}
  1983. fi
  1984. exit 0
  1985. exit 0 # Just in case...
  1986.