1: /*
   2: ** idecrypt.c                                     Crypto extension to pidentd.
   3: **
   4: ** This file is in the public domain. -- Planar 1994.02.22
   5: **
   6: ** Decryption utility.
   7: */
   8: 
   9: #ifdef INCLUDE_CRYPT
  10: 
  11: #include <stdio.h>
  12: #include "paths.h"
  13: #include "crypto.h"
  14: 
  15: char is_base_64 [] =
  16: {
  17:     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  18:     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  19:     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1,
  20:     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
  21:     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  22:     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
  23:     0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  24:     1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
  25: };
  26: 
  27: 
  28: void decrypt_file (f)
  29:     FILE *f;
  30: {
  31:     int c;
  32:     int i;
  33:     char buf[32];
  34:     char *cleartext;
  35: 
  36:     while (1)
  37:     {
  38:     c = getc(f);
  39: 
  40:       Same:
  41:     if (c == EOF)
  42:         return;
  43: 
  44:     if (c != '[')
  45:     {
  46:         putchar(c);
  47:         continue;
  48:     }
  49: 
  50:     for (i = 0; i < 32; i++)
  51:     {
  52:         c = getc(f);
  53:         if (c == EOF)
  54:         break;
  55:         if (!is_base_64[c])
  56:         break;
  57:         buf [i] = c;
  58:     }
  59: 
  60:     if (i == 32)
  61:         c = getc(f);
  62: 
  63:     if (i < 32 || c != ']')
  64:     {
  65:         putchar('[');
  66:         fwrite(buf, 1, i, stdout);
  67:         goto Same;
  68:     }
  69: 
  70:     cleartext = decrypt_packet(buf);
  71:     if (cleartext == NULL)
  72:     {
  73:         putchar('[');
  74:         fwrite(buf, 1, 32, stdout);
  75:         putchar(']');
  76:     }
  77:     else
  78:     {
  79:         printf("%s", cleartext);
  80:     }
  81:     }
  82: }
  83: 
  84: main (argc, argv)
  85:      int argc;
  86:      char **argv;
  87: {
  88:     int i;
  89:     FILE *f;
  90:     FILE *key_file;
  91: 
  92:     key_file = fopen(PATH_DESKEY, "r");
  93:     if (key_file == NULL)
  94:     {
  95:     fprintf(stderr, "idecrypt: cannot open key file: ");
  96:     perror(PATH_DESKEY);
  97:     exit (3);
  98:     }
  99: 
 100:     init_decryption(key_file);
 101:     close(key_file);
 102: 
 103:     if (argc < 2)
 104:     {
 105:     decrypt_file(stdin);
 106:     }
 107:     else
 108:     {
 109:     for (i = 1; i < argc; i++)
 110:     {
 111:         if (!strcmp(argv [i], "-"))
 112:         {
 113:         decrypt_file(stdin);
 114:         continue;
 115:         }
 116: 
 117:         f = fopen(argv [i], "r");
 118:         if (f == NULL)
 119:         {
 120:         perror(argv [i]);
 121:         continue;
 122:         }
 123: 
 124:         decrypt_file(f);
 125:         fclose(f);
 126:     }
 127:     }
 128: 
 129:     exit(0);
 130: }
 131: 
 132: #else /* no INCLUDE_CRYPT */
 133: 
 134: #include <stdio.h>
 135: 
 136: int main ()
 137: {
 138:     fprintf(stderr, "idecrypt: compiled without encryption\n");
 139:     exit(2);
 140: }
 141: 
 142: #endif

Defined functions

decrypt_file defined in line 28; used 3 times
main defined in line 136; never used

Defined variables

is_base_64 defined in line 15; used 1 times
  • in line 55
Last modified: 1994-11-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1169
Valid CSS Valid XHTML 1.0 Strict