home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xntp3.zip / authstuff / authcert.c < prev    next >
C/C++ Source or Header  |  1992-08-04  |  1KB  |  86 lines

  1. /*
  2.  * This file, and the certdata file, shamelessly stolen
  3.  * from Phil Karn's DES implementation.
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <sys/types.h>
  8. #include <sys/socket.h>
  9. #include <netinet/in.h>
  10.  
  11. u_char ekeys[128];
  12. u_char dkeys[128];
  13.  
  14. main()
  15. {
  16.     u_long key[2], plain[2], cipher[2], answer[2];
  17.     int i;
  18.     int test;
  19.     int fail;
  20.  
  21.     for(test=0;!feof(stdin);test++){
  22.         get8(key);
  23.         DESauth_subkeys(key, ekeys, dkeys);
  24.         printf(" K: "); put8(key);
  25.  
  26.         get8(plain);
  27.         printf(" P: "); put8(plain);
  28.  
  29.         get8(answer);
  30.         printf(" C: "); put8(answer);
  31.  
  32.  
  33.         for(i=0;i<2;i++)
  34.             cipher[i] = htonl(plain[i]);
  35.         DESauth_des(cipher, ekeys);
  36.  
  37.         for(i=0;i<2;i++)
  38.             if(ntohl(cipher[i]) != answer[i])
  39.                 break;
  40.         fail = 0;
  41.         if(i != 2){
  42.             printf(" Encrypt FAIL");
  43.             fail++;
  44.         }
  45.         DESauth_des(cipher, dkeys);
  46.         for(i=0;i<2;i++)
  47.             if(ntohl(cipher[i]) != plain[i])
  48.                 break;
  49.         if(i != 2){
  50.             printf(" Decrypt FAIL");
  51.             fail++;
  52.         }
  53.         if(fail == 0)
  54.             printf(" OK");
  55.         printf("\n");
  56.     }
  57. }
  58. get8(lp)
  59. u_long *lp;
  60. {
  61.     int t;
  62.     u_long l[2];
  63.     int i;
  64.  
  65.     l[0] = l[1] = 0L;
  66.     for(i=0;i<8;i++){
  67.         scanf("%2x",&t);
  68.         if(feof(stdin))
  69.             exit(0);
  70.         l[i/4] <<= 8;
  71.         l[i/4] |= (u_long)(t & 0xff);
  72.     }
  73.     *lp = l[0];
  74.     *(lp+1) = l[1];
  75. }
  76. put8(lp)
  77. u_long *lp;
  78. {
  79.     int i;
  80.  
  81.     
  82.     for(i=0;i<2;i++){
  83.         printf("%08x",*lp++);
  84.     }
  85. }
  86.