home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / pgp2 / src / h / pgp < prev    next >
Encoding:
Text File  |  1995-03-08  |  9.3 KB  |  258 lines

  1. /*
  2.     Pretty Good(tm) Privacy - RSA public key cryptography for the masses
  3.     Written by Philip Zimmermann, Phil's Pretty Good(tm) Software.
  4.     Version 1.0 - 5 Jun 91, last revised 6 Jul 91 by PRZ
  5.  
  6.     This file defines the various formats, filenames, and general control
  7.     methods used by PGP, as well as a few global switches which control
  8.     the functioning of the driver code.
  9.  
  10. */
  11.  
  12. #ifndef PGP_H
  13. #define PGP_H
  14.  
  15. #include "usuals.h"
  16. #include "more.h"
  17. #include "armor.h"
  18.  
  19. #define KEYFRAGSIZE 8    /* # of bytes in key ID modulus fragment */
  20. #define SIZEOF_TIMESTAMP 4 /* 32-bit timestamp */
  21.  
  22. /* The maximum length of the file path for this system.  Varies on UNIX
  23.    systems */
  24.  
  25. #ifndef    MAX_PATH
  26. #ifdef MSDOS
  27. #define MAX_PATH    64
  28. #else
  29. #define MAX_PATH    256
  30. #endif
  31. #endif
  32.  
  33. /*
  34. **********************************************************************
  35. */
  36.  
  37. /* Cipher Type Byte (CTB) definitions follow...*/
  38. #define CTB_DESIGNATOR 0x80
  39. #define is_ctb(c) (((c) & CTB_DESIGNATOR)==CTB_DESIGNATOR)
  40. #define CTB_TYPE_MASK 0x7c
  41. #define CTB_LLEN_MASK 0x03
  42.  
  43. /* "length of length" field of packet, in bytes (1, 2, 4, 8 bytes): */
  44. #define ctb_llength(ctb) ((int) 1 << (int) ((ctb) & CTB_LLEN_MASK))
  45.  
  46. #define is_ctb_type(ctb,type) (((ctb) & CTB_TYPE_MASK)==(4*type))
  47. #define CTB_BYTE(type,llen) (CTB_DESIGNATOR + (4*type) + llen)
  48.  
  49. #define CTB_PKE_TYPE 1            /* packet encrypted with RSA public
  50.                        key */
  51. #define CTB_SKE_TYPE 2            /* packet signed with RSA secret key */
  52. #define CTB_MD_TYPE 3            /* message digest packet */
  53. #define CTB_CERT_SECKEY_TYPE 5  /* secret key certificate */
  54. #define CTB_CERT_PUBKEY_TYPE 6  /* public key certificate */
  55. #define CTB_COMPRESSED_TYPE 8    /* compressed data packet */
  56. #define CTB_CKE_TYPE 9            /* conventional-key-encrypted data */
  57. #define    CTB_LITERAL_TYPE 10        /* raw data with filename and mode */
  58. #define CTB_LITERAL2_TYPE 11    /* Fixed literal packet */
  59. #define CTB_KEYCTRL_TYPE 12        /* key control packet */
  60. #define CTB_USERID_TYPE 13        /* user id packet */
  61. #define CTB_COMMENT_TYPE 14        /* comment packet */
  62.  
  63. /* Unimplemented CTB packet types follow... */
  64. /* #define CTB_EXTENDED_TYPE 15 */ /* 2-byte CTB, 256 extra CTB types */
  65.  
  66. #define CTB_PKE CTB_BYTE(CTB_PKE_TYPE,1)
  67.     /* CTB_PKE len16 keyID mpi(RSA(CONKEYPKT)) */
  68.     /*      1         2     SIZE  countbytes()+2 */
  69. #define CTB_SKE CTB_BYTE(CTB_SKE_TYPE,1)
  70.     /* CTB_SKE len16 keyID mpi(RSA(MDPKT)) */
  71.     /*      1         2     SIZE  countbytes()+2 */
  72. #define CTB_MD CTB_BYTE(CTB_MD_TYPE,0)
  73.     /* CTB_MD len8 algorithm MD timestamp */
  74. #define CTB_CERT_SECKEY CTB_BYTE(CTB_CERT_SECKEY_TYPE,1)
  75.     /* CTB_CERT_SECKEY len16 timestamp userID mpi(n) mpi(e) mpi(d)
  76.        mpi(p) mpi(q) mpi(u) crc16 */
  77. #define CTB_CERT_PUBKEY CTB_BYTE(CTB_CERT_PUBKEY_TYPE,1)
  78.     /* CTB_CERT_PUBKEY len16 timestamp userID mpi(n) mpi(e) crc16 */
  79.  
  80. #define CTB_KEYCTRL CTB_BYTE(CTB_KEYCTRL_TYPE,0)
  81. #define    CTB_USERID    CTB_BYTE(CTB_USERID_TYPE,0)
  82.  
  83. #define CTB_CKE CTB_BYTE(CTB_CKE_TYPE,3)
  84.     /*    CTB_CKE ciphertext */
  85.  
  86. #define CTB_LITERAL CTB_BYTE(CTB_LITERAL_TYPE,3)
  87. #define CTB_LITERAL2 CTB_BYTE(CTB_LITERAL_TYPE,3)
  88.     /*    CTB_LITERAL data */
  89.  
  90. #define CTB_COMPRESSED CTB_BYTE(CTB_COMPRESSED_TYPE,3)
  91.     /*    CTB_COMPRESSED compressedtext */
  92.  
  93. /*    Public key encryption algorithm selector bytes. */
  94. #define RSA_ALGORITHM_BYTE    1    /*    use RSA    */
  95.  
  96. /*    Conventional encryption algorithm selector bytes. */
  97. #define IDEA_ALGORITHM_BYTE    1    /*    use the IDEA cipher */
  98.  
  99. /*    Message digest algorithm selector bytes. */
  100. #define MD5_ALGORITHM_BYTE 1    /* MD5 message digest algorithm */
  101.  
  102. /*    Data compression algorithm selector bytes. */
  103. #define ZIP2_ALGORITHM_BYTE  1    /* Zip-based deflate compression algorithm */
  104.  
  105. /* Signature classification bytes. */
  106. #define SB_SIGNATURE_BYTE    0x00    /* Signature of a binary msg or doc */
  107. #define SM_SIGNATURE_BYTE    0x01    /* Signature of canonical msg or doc */
  108. #define    K0_SIGNATURE_BYTE    0x10    /* Key certification, generic */
  109. #define    K1_SIGNATURE_BYTE    0x11    /* Key certification, persona */
  110. #define    K2_SIGNATURE_BYTE    0x12    /* Key certification, casual ID */
  111. #define    K3_SIGNATURE_BYTE    0x13    /* Key certification, positive ID */
  112. #define KC_SIGNATURE_BYTE    0x20    /* Key compromise */
  113. #define KR_SIGNATURE_BYTE    0x30    /* Key revocation */
  114. #define    TS_SIGNATURE_BYTE    0x40    /* Timestamp someone else's
  115.                        signature */
  116.  
  117. /* Public key encrypted data classification bytes. */
  118. #define MD_ENCRYPTED_BYTE    1    /* Message digest is encrypted */
  119. #define CK_ENCRYPTED_BYTE    2    /* Conventional key is encrypted */
  120.  
  121. /* Version byte for data structures created by this version of PGP */
  122. #define    VERSION_BYTE_OLD    2    /* PGP2 */
  123. #define    VERSION_BYTE_NEW    3
  124.  
  125. /* Values for trust bits in keycntrl packet after key packet */
  126. #define    KC_OWNERTRUST_MASK    0x07    /* Trust bits for key owner */
  127. #define    KC_OWNERTRUST_UNDEFINED    0x00
  128. #define    KC_OWNERTRUST_UNKNOWN    0x01
  129. #define    KC_OWNERTRUST_NEVER    0x02
  130. /* 2 levels reserved */
  131. #define    KC_OWNERTRUST_USUALLY    0x05
  132. #define    KC_OWNERTRUST_ALWAYS    0x06
  133. #define    KC_OWNERTRUST_ULTIMATE    0x07    /* Only for keys in secret ring */
  134. #define    KC_BUCKSTOP        0x80    /* This key is in secret ring */
  135. #define    KC_DISABLED        0x20    /* key is disabled */
  136.  
  137. /* Values for trust bits in keycntrl packet after userid packet */
  138. #define    KC_LEGIT_MASK        0x03    /* Key legit bits for key */
  139. #define    KC_LEGIT_UNKNOWN    0x00
  140. #define KC_LEGIT_UNTRUSTED    0x01
  141. #define KC_LEGIT_MARGINAL    0x02
  142. #define    KC_LEGIT_COMPLETE    0x03
  143. #define    KC_WARNONLY        0x80
  144.  
  145. /* Values for trust bits in keycntrl packet after signature packet */
  146. #define    KC_SIGTRUST_MASK    0x07    /* Trust bits for key owner */
  147. #define    KC_SIGTRUST_UNDEFINED    0x00
  148. #define    KC_SIGTRUST_UNKNOWN    0x01
  149. #define    KC_SIGTRUST_UNTRUSTED    0x02
  150. /* 2 levels reserved */
  151. #define    KC_SIGTRUST_MARGINAL    0x05
  152. #define    KC_SIGTRUST_COMPLETE    0x06
  153. #define    KC_SIGTRUST_ULTIMATE    0x07
  154. #define    KC_SIG_CHECKED        0x40    /* This sig has been checked */
  155. #define    KC_CONTIG        0x80    /* This sig is on a cert. path */
  156.  
  157. #define is_secret_key(ctb) is_ctb_type(ctb,CTB_CERT_SECKEY_TYPE)
  158.  
  159. #define MPILEN (2+MAX_BYTE_PRECISION)
  160. #define MAX_SIGCERT_LENGTH (1+2+1 +1+7 +KEYFRAGSIZE+2+2+MPILEN)
  161. #define MAX_KEYCERT_LENGTH (1+2+1+4+2+1 +(2*MPILEN) +1+8 +(4*MPILEN) +2)
  162.  
  163. /* Modes for CTB_LITERAL2 packet */
  164. #define    MODE_BINARY    'b'
  165. #define    MODE_TEXT    't'
  166. #define MODE_LOCAL    'l'
  167.  
  168. /* Prototype for the 'more' function, which blorts a file to the screen with
  169.    page breaks, intelligent handling of line terminators, truncation of
  170.    overly long lines, and zapping of illegal chars.  Implemented in MORE.C */
  171.  
  172. int more_file(char *fileName);
  173.  
  174. /* Prototypes for the transport armor routines */
  175.  
  176. boolean is_armor_file(char *infile, long startline);
  177. int armor_file(char *infile, char *outfile, char *filename, char *clearname);
  178. int de_armor_file(char *infile, char *outfile, long *curline);
  179.  
  180. void user_error(void);
  181.  
  182. /* Global filenames and system-wide file extensions... */
  183. extern char PGP_EXTENSION[];
  184. extern char ASC_EXTENSION[];
  185. extern char SIG_EXTENSION[];
  186. extern char BAK_EXTENSION[];
  187. extern char CONSOLE_FILENAME[];
  188. extern char rel_version[];
  189.  
  190. /* These files use the environmental variable PGPPATH as a default path: */
  191. extern char globalPubringName[MAX_PATH];
  192. extern char globalSecringName[MAX_PATH];
  193. extern char globalRandseedName[MAX_PATH];
  194. extern char globalCommentString[128];
  195.  
  196. /* Variables which are global across the driver code */
  197. extern boolean    filter_mode;
  198. extern boolean    moreflag;
  199. extern FILE    *pgpout;    /* FILE structure for routine output */
  200.  
  201. /* Variables settable by config.pgp and referenced in config.c ... */
  202. extern char language[];    /* foreign language prefix code for language.pgp
  203.                file */
  204. extern char charset[];
  205. /* my_name is substring of default userid for secret key to make signatures */
  206. extern char my_name[];
  207. extern char floppyring[]; /* for comparing secret keys with backup on floppy */
  208. extern char literal_mode;    /* text or binary mode for literal packet */
  209. extern boolean emit_radix_64;
  210. extern boolean showpass;
  211. extern boolean keepctx;
  212. extern boolean verbose;    /* display maximum information */
  213. extern boolean compress_enabled; /* attempt compression before encryption */
  214. extern boolean clear_signatures;
  215. extern boolean encrypt_to_self; /* Should I encrypt to myself? */
  216. extern boolean batchmode;    /* for batch processing */
  217. extern boolean quietmode;    /* less verbose */
  218. extern boolean force_flag;    /* overwrite existing file without asking */
  219. /* Ask for each key separately if it should be added to the keyring */
  220. extern boolean interactive_add;
  221. extern long timeshift;    /* seconds from GMT timezone */
  222. extern boolean signature_checked;
  223. extern int pem_lines;
  224. extern int marg_min;    /* number of marginally trusted signatures needed to
  225.                            make a key fully-legit */
  226. extern int compl_min;    /* number of fully trusted signatures needed */
  227. extern int max_cert_depth;
  228. extern char pager[];    /* file lister command */
  229. extern int version_byte;
  230. extern boolean nomanual;
  231. extern int makerandom;    /* Fill in file with this many random bytes */
  232.  
  233. /* These lists store hashed passwords for future use. */
  234. /* passwds are passwords of as-yet-unknown purpose; keypasswds
  235.    are passwords used to decrypt keys. */
  236. struct hashedpw {
  237.     struct hashedpw *next;
  238.     byte hash[16];
  239. };
  240. extern struct hashedpw *keypasswds, *passwds;
  241.  
  242. extern boolean strip_spaces;
  243.  
  244. #ifdef VMS
  245. /*
  246.  * FDL Support Prototypes, Currently Used Only In SYSTEM.C and CRYPTO.C
  247.  */
  248.  
  249. int fdl_generate(char *in_file, char **fdl, short *len);
  250. VOID *fdl_create( char *fdl, short len, char *outfile, char *preserved_name);
  251. int fdl_copyfile2bin(FILE *f, VOID *rab, word32 longcount); 
  252. void fdl_close( VOID *rab);
  253. #endif /* VMS */
  254.  
  255. extern int compressSignature(byte *header);
  256.  
  257. #endif /* PGP_H */
  258.