| 1 |
/* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
|
| 2 |
|
| 3 |
Mixmaster may be redistributed and modified under certain conditions.
|
| 4 |
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
|
| 5 |
ANY KIND, either express or implied. See the file COPYRIGHT for
|
| 6 |
details.
|
| 7 |
|
| 8 |
OpenPGP messages
|
| 9 |
$Id: pgp.h,v 1.5 2002/08/16 19:03:37 rabbi Exp $ */
|
| 10 |
|
| 11 |
|
| 12 |
#ifdef USE_PGP
|
| 13 |
#ifndef _PGP_H
|
| 14 |
#include "mix3.h"
|
| 15 |
#ifdef USE_OPENSSL
|
| 16 |
#include <openssl/opensslv.h>
|
| 17 |
#endif
|
| 18 |
|
| 19 |
/* try to make the messages look similar to PGP 2.6.3i output
|
| 20 |
(compression is not always the same though). */
|
| 21 |
#define MIMIC
|
| 22 |
|
| 23 |
/* packet types */
|
| 24 |
#define PGP_SESKEY 1
|
| 25 |
#define PGP_SIG 2
|
| 26 |
#define PGP_SYMSESKEY 3
|
| 27 |
#define PGP_OSIG 4
|
| 28 |
#define PGP_SECKEY 5
|
| 29 |
#define PGP_PUBKEY 6
|
| 30 |
#define PGP_SECSUBKEY 7
|
| 31 |
#define PGP_COMPRESSED 8
|
| 32 |
#define PGP_ENCRYPTED 9
|
| 33 |
#define PGP_MARKER 10
|
| 34 |
#define PGP_LITERAL 11
|
| 35 |
#define PGP_TRUST 12
|
| 36 |
#define PGP_USERID 13
|
| 37 |
#define PGP_PUBSUBKEY 14
|
| 38 |
#define PGP_ENCRYPTEDMDC 18
|
| 39 |
#define PGP_MDC 19
|
| 40 |
|
| 41 |
/* symmetric algorithms */
|
| 42 |
#define PGP_K_IDEA 1
|
| 43 |
#define PGP_K_3DES 2
|
| 44 |
#define PGP_K_CAST5 3
|
| 45 |
#define PGP_K_BF 4
|
| 46 |
#define PGP_K_AES128 7
|
| 47 |
#define PGP_K_AES192 8
|
| 48 |
#define PGP_K_AES256 9
|
| 49 |
|
| 50 |
/* hash algorithms */
|
| 51 |
#define PGP_H_MD5 1
|
| 52 |
#define PGP_H_SHA1 2
|
| 53 |
#define PGP_H_RIPEMD 3
|
| 54 |
|
| 55 |
/* signature types */
|
| 56 |
#define PGP_SIG_BINARY 0
|
| 57 |
#define PGP_SIG_CANONIC 1
|
| 58 |
#define PGP_SIG_CERT 0x10
|
| 59 |
#define PGP_SIG_BINDSUBKEY 0x18
|
| 60 |
|
| 61 |
/* signature subpacket types */
|
| 62 |
#define PGP_SUB_CREATIME 2
|
| 63 |
#define PGP_SUB_PSYMMETRIC 11
|
| 64 |
#define PGP_SUB_ISSUER 16
|
| 65 |
#define PGP_SUB_FEATURES 30
|
| 66 |
|
| 67 |
#define ARMORED 1
|
| 68 |
|
| 69 |
/* publick key algorithm operation modes */
|
| 70 |
|
| 71 |
#define PK_ENCRYPT 1
|
| 72 |
#define PK_DECRYPT 2
|
| 73 |
#define PK_SIGN 3
|
| 74 |
#define PK_VERIFY 4
|
| 75 |
|
| 76 |
#define MD5PREFIX "\x30\x20\x30\x0C\x06\x08\x2A\x86\x48\x86\xF7\x0D\x02\x05\x05\x00\x04\x10"
|
| 77 |
#define SHA1PREFIX "\x30\x21\x30\x09\x06\x05\x2b\x0E\x03\x02\x1A\x05\x00\x04\x14"
|
| 78 |
|
| 79 |
typedef struct {
|
| 80 |
int ok;
|
| 81 |
BUFFER *userid;
|
| 82 |
byte sigtype;
|
| 83 |
long sigtime;
|
| 84 |
byte hash[16];
|
| 85 |
} pgpsig;
|
| 86 |
|
| 87 |
/* internal error codes */
|
| 88 |
#define PGP_SIGVRFY 99 /* valid signature packet to be verified */
|
| 89 |
|
| 90 |
/* pgpdata.c */
|
| 91 |
int pgp_getsk(BUFFER *p, BUFFER *pass, BUFFER *key);
|
| 92 |
int pgp_makesk(BUFFER *out, BUFFER *key, int sym, int type, int hash,
|
| 93 |
BUFFER *pass);
|
| 94 |
void pgp_iteratedsk(BUFFER *salted, BUFFER *salt, BUFFER *pass, byte c);
|
| 95 |
int pgp_expandsk(BUFFER *key, int skalgo, int hashalgo, BUFFER *data);
|
| 96 |
int skcrypt(BUFFER *data, int skalgo, BUFFER *key, BUFFER *iv, int enc);
|
| 97 |
int mpi_get(BUFFER *buf, BUFFER *mpi);
|
| 98 |
int mpi_put(BUFFER *buf, BUFFER *mpi);
|
| 99 |
int pgp_rsa(BUFFER *buf, BUFFER *key, int mode);
|
| 100 |
void pgp_sigcanonic(BUFFER *msg);
|
| 101 |
int pgp_makepubkey(BUFFER *seckey, BUFFER *outtxt, BUFFER *pubkey,
|
| 102 |
BUFFER *pass, int keyalgo);
|
| 103 |
int pgp_getkey(int mode, int algo, int *sym, int *mdc, BUFFER *keypacket, BUFFER *key,
|
| 104 |
BUFFER *keyid, BUFFER *userid, BUFFER *pass);
|
| 105 |
int pgp_rsakeygen(int bits, BUFFER *userid, BUFFER *pass, char *pubring,
|
| 106 |
char *secring, int remail);
|
| 107 |
int pgp_dhkeygen(int bits, BUFFER *userid, BUFFER *pass, char *pubring,
|
| 108 |
char *secring, int remail);
|
| 109 |
int pgp_dosign(int algo, BUFFER *data, BUFFER *key);
|
| 110 |
int pgp_elgencrypt(BUFFER *b, BUFFER *key);
|
| 111 |
int pgp_elgdecrypt(BUFFER *b, BUFFER *key);
|
| 112 |
int pgp_keyid(BUFFER *key, BUFFER *id);
|
| 113 |
int pgp_keylen(int symalgo);
|
| 114 |
int pgp_blocklen(int symalgo);
|
| 115 |
|
| 116 |
/* pgpget.c */
|
| 117 |
int pgp_getmsg(BUFFER *in, BUFFER *key, BUFFER *sig, char *pubring,
|
| 118 |
char *secring);
|
| 119 |
int pgp_ispacket(BUFFER *buf);
|
| 120 |
int pgp_isconventional(BUFFER *buf);
|
| 121 |
int pgp_packettype(BUFFER *buf, long *len, int *partial);
|
| 122 |
int pgp_packetpartial(BUFFER *buf, long *len, int *partial);
|
| 123 |
int pgp_getpacket(BUFFER *buf, BUFFER *p);
|
| 124 |
int pgp_getsig(BUFFER *p, pgpsig *sig, char *pubring);
|
| 125 |
void pgp_verify(BUFFER *msg, BUFFER *detached, pgpsig *sig);
|
| 126 |
int pgp_getsymmetric(BUFFER *buf, BUFFER *key, int algo, int type);
|
| 127 |
int pgp_getliteral(BUFFER *buf);
|
| 128 |
int pgp_uncompress(BUFFER *buf);
|
| 129 |
int pgp_getsessionkey(BUFFER *buf, BUFFER *pass, char *secring);
|
| 130 |
int pgp_getsymsessionkey(BUFFER *buf, BUFFER *pass);
|
| 131 |
|
| 132 |
/* pgpcreat.c */
|
| 133 |
int pgp_packet(BUFFER *buf, int type);
|
| 134 |
int pgp_packet3(BUFFER *buf, int type);
|
| 135 |
int pgp_symmetric(BUFFER *buf, BUFFER *key, int mdc);
|
| 136 |
int pgp_literal(BUFFER *buf, char *filename, int text);
|
| 137 |
int pgp_compress(BUFFER *buf);
|
| 138 |
int pgp_sessionkey(BUFFER *buf, BUFFER *user, BUFFER *keyid, BUFFER *seskey,
|
| 139 |
char *pubring);
|
| 140 |
void pgp_marker(BUFFER *buf);
|
| 141 |
int pgp_symsessionkey(BUFFER *buf, BUFFER *seskey, BUFFER *pass);
|
| 142 |
int pgp_sign(BUFFER *msg, BUFFER *msg2, BUFFER *sig, BUFFER *userid,
|
| 143 |
BUFFER *pass, int type, int self, long now, int remail,
|
| 144 |
BUFFER *seckey, char *secring);
|
| 145 |
int pgp_digest(int hashalgo, BUFFER *in, BUFFER *d);
|
| 146 |
|
| 147 |
/* pgpdb.c */
|
| 148 |
|
| 149 |
int pgpdb_getkey(int mode, int algo, int *sym, int *mdc, BUFFER *key, BUFFER *user,
|
| 150 |
BUFFER *founduid, BUFFER *keyid, char *keyring, BUFFER *pass);
|
| 151 |
|
| 152 |
typedef struct {
|
| 153 |
int filetype;
|
| 154 |
BUFFER *db;
|
| 155 |
LOCK *lock;
|
| 156 |
int modified;
|
| 157 |
char filename[LINELEN];
|
| 158 |
BUFFER *encryptkey;
|
| 159 |
} KEYRING;
|
| 160 |
|
| 161 |
KEYRING *pgpdb_new(char *keyring, int filetype, BUFFER *encryptkey);
|
| 162 |
KEYRING *pgpdb_open(char *keyring, BUFFER *encryptkey, int writer);
|
| 163 |
int pgpdb_append(KEYRING *keydb, BUFFER *p);
|
| 164 |
int pgpdb_getnext(KEYRING *keydb, BUFFER *p, BUFFER *keyid, BUFFER *userid);
|
| 165 |
int pgpdb_close(KEYRING *keydb);
|
| 166 |
|
| 167 |
#endif /* _PGP_H */
|
| 168 |
#endif /* USE_PGP */
|