1997-11-18 15:06:00 +01:00
|
|
|
/* packet.h - packet read/write stuff
|
1998-02-24 19:50:46 +01:00
|
|
|
* Copyright (C) 1998 Free Software Foundation, Inc.
|
1997-11-18 15:06:00 +01:00
|
|
|
*
|
1998-02-24 19:50:46 +01:00
|
|
|
* This file is part of GNUPG.
|
1997-11-18 15:06:00 +01:00
|
|
|
*
|
1998-02-24 19:50:46 +01:00
|
|
|
* GNUPG is free software; you can redistribute it and/or modify
|
1997-11-18 15:06:00 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
1998-02-24 19:50:46 +01:00
|
|
|
* GNUPG is distributed in the hope that it will be useful,
|
1997-11-18 15:06:00 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef G10_PACKET_H
|
|
|
|
#define G10_PACKET_H
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "iobuf.h"
|
|
|
|
#include "mpi.h"
|
|
|
|
#include "cipher.h"
|
|
|
|
#include "filter.h"
|
|
|
|
|
1998-04-08 21:49:02 +02:00
|
|
|
#ifndef HAVE_RSA_CIPHER
|
|
|
|
/* although we don't have RSA we need these structures to handle keyrings */
|
|
|
|
typedef struct { MPI e, n; } RSA_public_key;
|
|
|
|
typedef struct { MPI e, n, p, q, d, u; } RSA_secret_key;
|
|
|
|
#endif
|
|
|
|
|
1997-12-01 11:33:23 +01:00
|
|
|
typedef enum {
|
|
|
|
PKT_NONE =0,
|
|
|
|
PKT_PUBKEY_ENC =1, /* public key encrypted packet */
|
|
|
|
PKT_SIGNATURE =2, /* secret key encrypted packet */
|
1998-05-03 17:42:08 +02:00
|
|
|
PKT_SYMKEY_ENC =3, /* session key packet (OpenPGP)*/
|
1997-12-01 11:33:23 +01:00
|
|
|
PKT_ONEPASS_SIG =4, /* one pass sig packet (OpenPGP)*/
|
|
|
|
PKT_SECRET_CERT =5, /* secret key certificate */
|
|
|
|
PKT_PUBLIC_CERT =6, /* public key certificate */
|
|
|
|
PKT_SECKEY_SUBCERT =7, /* secret subkey certificate (OpenPGP) */
|
|
|
|
PKT_COMPRESSED =8, /* compressed data packet */
|
|
|
|
PKT_ENCRYPTED =9, /* conventional encrypted data */
|
|
|
|
PKT_MARKER =10, /* marker packet (OpenPGP) */
|
|
|
|
PKT_PLAINTEXT =11, /* plaintext data with filename and mode */
|
|
|
|
PKT_RING_TRUST =12, /* keyring trust packet */
|
|
|
|
PKT_USER_ID =13, /* user id packet */
|
|
|
|
PKT_PUBKEY_SUBCERT=14, /* subkey certificate (OpenPGP) */
|
1998-05-03 21:35:33 +02:00
|
|
|
PKT_OLD_COMMENT =16, /* comment packet from an OpenPGP draft */
|
|
|
|
PKT_COMMENT =61 /* new comment packet (private) */
|
1997-12-01 11:33:23 +01:00
|
|
|
} pkttype_t;
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
typedef struct packet_struct PACKET;
|
|
|
|
|
1998-05-03 17:42:08 +02:00
|
|
|
typedef struct {
|
|
|
|
byte mode;
|
|
|
|
byte hash_algo;
|
|
|
|
byte salt[8];
|
|
|
|
u32 count;
|
|
|
|
} STRING2KEY;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
byte version;
|
|
|
|
byte cipher_algo; /* cipher algorithm used */
|
|
|
|
STRING2KEY s2k;
|
|
|
|
byte seskeylen; /* keylength in byte or 0 for no seskey */
|
|
|
|
byte seskey[1];
|
|
|
|
} PKT_symkey_enc;
|
|
|
|
|
1997-11-18 15:06:00 +01:00
|
|
|
typedef struct {
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
1998-03-19 16:27:29 +01:00
|
|
|
byte version;
|
1997-11-18 15:06:00 +01:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
|
|
|
union {
|
1997-11-24 23:24:04 +01:00
|
|
|
struct {
|
1997-12-01 11:33:23 +01:00
|
|
|
MPI a, b; /* integers with the encrypteded DEK */
|
1997-11-24 23:24:04 +01:00
|
|
|
} elg;
|
1997-12-12 13:03:58 +01:00
|
|
|
struct {
|
|
|
|
MPI rsa_integer; /* integer containing the DEK */
|
|
|
|
} rsa;
|
1997-11-18 15:06:00 +01:00
|
|
|
} d;
|
|
|
|
} PKT_pubkey_enc;
|
|
|
|
|
|
|
|
|
1997-12-02 20:36:53 +01:00
|
|
|
typedef struct {
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
|
|
|
byte sig_class; /* sig classification */
|
|
|
|
byte digest_algo; /* algorithm used for digest */
|
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
|
|
|
byte last; /* a stupid flag */
|
|
|
|
} PKT_onepass_sig;
|
|
|
|
|
|
|
|
|
1997-11-18 15:06:00 +01:00
|
|
|
typedef struct {
|
|
|
|
u32 keyid[2]; /* 64 bit keyid */
|
1998-01-16 22:15:24 +01:00
|
|
|
ulong local_id; /* internal use, valid if > 0 */
|
1997-11-18 15:06:00 +01:00
|
|
|
u32 timestamp; /* signature made */
|
1998-03-09 22:44:06 +01:00
|
|
|
byte version;
|
1997-11-18 15:06:00 +01:00
|
|
|
byte sig_class; /* sig classification, append for MD calculation*/
|
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
|
|
|
/* (PUBKEY_ALGO_xxx) */
|
1998-03-09 22:44:06 +01:00
|
|
|
byte digest_algo; /* algorithm used for digest (DIGEST_ALGO_xxxx) */
|
|
|
|
byte *hashed_data; /* all subpackets with hashed data (v4 only) */
|
|
|
|
byte *unhashed_data; /* ditto for unhashed data */
|
|
|
|
byte digest_start[2]; /* first 2 bytes of the digest */
|
1997-11-18 15:06:00 +01:00
|
|
|
union {
|
|
|
|
struct {
|
1997-12-12 13:03:58 +01:00
|
|
|
MPI a, b; /* integers with the digest */
|
|
|
|
} elg;
|
1997-11-24 23:24:04 +01:00
|
|
|
struct {
|
1998-03-09 22:44:06 +01:00
|
|
|
MPI r, s; /* integers with the digest */
|
|
|
|
} dsa;
|
|
|
|
struct {
|
1997-12-12 13:03:58 +01:00
|
|
|
MPI rsa_integer; /* the encrypted digest */
|
|
|
|
} rsa;
|
1997-11-18 15:06:00 +01:00
|
|
|
} d;
|
|
|
|
} PKT_signature;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 timestamp; /* certificate made */
|
|
|
|
u16 valid_days; /* valid for this number of days */
|
1998-01-16 22:15:24 +01:00
|
|
|
byte hdrbytes; /* number of header bytes */
|
|
|
|
byte version;
|
1997-11-18 15:06:00 +01:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
1998-01-16 22:15:24 +01:00
|
|
|
ulong local_id; /* internal use, valid if > 0 */
|
1997-11-18 15:06:00 +01:00
|
|
|
union {
|
1998-04-08 21:49:02 +02:00
|
|
|
ELG_public_key elg;
|
|
|
|
DSA_public_key dsa;
|
|
|
|
RSA_public_key rsa;
|
1997-11-18 15:06:00 +01:00
|
|
|
} d;
|
1997-12-01 11:33:23 +01:00
|
|
|
} PKT_public_cert;
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 timestamp; /* certificate made */
|
|
|
|
u16 valid_days; /* valid for this number of days */
|
1998-01-16 22:15:24 +01:00
|
|
|
byte hdrbytes; /* number of header bytes */
|
|
|
|
byte version;
|
1997-11-18 15:06:00 +01:00
|
|
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
1998-04-14 19:51:16 +02:00
|
|
|
byte is_protected; /* The secret info is protected and must */
|
|
|
|
/* be decrypted before use, the protected */
|
1998-04-02 12:30:03 +02:00
|
|
|
/* MPIs are simply (void*) pointers to memory */
|
|
|
|
/* and should never be passed to a mpi_xxx() */
|
|
|
|
struct {
|
1998-04-14 19:51:16 +02:00
|
|
|
byte algo; /* cipher used to protect the secret information*/
|
1998-05-03 17:42:08 +02:00
|
|
|
STRING2KEY s2k;
|
1998-04-02 12:30:03 +02:00
|
|
|
byte iv[8]; /* initialization vector for CFB mode */
|
|
|
|
} protect;
|
1997-11-18 15:06:00 +01:00
|
|
|
union {
|
1998-04-08 21:49:02 +02:00
|
|
|
ELG_secret_key elg;
|
|
|
|
DSA_secret_key dsa;
|
|
|
|
RSA_secret_key rsa;
|
1997-11-18 15:06:00 +01:00
|
|
|
} d;
|
1998-04-02 12:30:03 +02:00
|
|
|
u16 csum; /* checksum */
|
1997-12-01 11:33:23 +01:00
|
|
|
} PKT_secret_cert;
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int len; /* length of data */
|
|
|
|
char data[1];
|
|
|
|
} PKT_comment;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int len; /* length of the name */
|
|
|
|
char name[1];
|
|
|
|
} PKT_user_id;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 len; /* reserved */
|
|
|
|
byte algorithm;
|
|
|
|
IOBUF buf; /* IOBUF reference */
|
|
|
|
} PKT_compressed;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 len; /* length of encrypted data */
|
|
|
|
IOBUF buf; /* IOBUF reference */
|
1997-12-01 11:33:23 +01:00
|
|
|
} PKT_encrypted;
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
u32 len; /* length of encrypted data */
|
|
|
|
IOBUF buf; /* IOBUF reference */
|
|
|
|
int mode;
|
|
|
|
u32 timestamp;
|
|
|
|
int namelen;
|
|
|
|
char name[1];
|
|
|
|
} PKT_plaintext;
|
|
|
|
|
|
|
|
/* combine all packets into a union */
|
|
|
|
struct packet_struct {
|
1997-12-01 11:33:23 +01:00
|
|
|
pkttype_t pkttype;
|
1997-11-18 15:06:00 +01:00
|
|
|
union {
|
|
|
|
void *generic;
|
1998-05-03 17:42:08 +02:00
|
|
|
PKT_symkey_enc *symkey_enc; /* PKT_SYMKEY_ENC */
|
1997-12-01 11:33:23 +01:00
|
|
|
PKT_pubkey_enc *pubkey_enc; /* PKT_PUBKEY_ENC */
|
1997-12-02 20:36:53 +01:00
|
|
|
PKT_onepass_sig *onepass_sig; /* PKT_ONEPASS_SIG */
|
1997-12-01 11:33:23 +01:00
|
|
|
PKT_signature *signature; /* PKT_SIGNATURE */
|
|
|
|
PKT_public_cert *public_cert; /* PKT_PUBLIC_CERT */
|
|
|
|
PKT_secret_cert *secret_cert; /* PKT_SECRET_CERT */
|
1997-11-18 15:06:00 +01:00
|
|
|
PKT_comment *comment; /* PKT_COMMENT */
|
|
|
|
PKT_user_id *user_id; /* PKT_USER_ID */
|
|
|
|
PKT_compressed *compressed; /* PKT_COMPRESSED */
|
1997-12-01 11:33:23 +01:00
|
|
|
PKT_encrypted *encrypted; /* PKT_ENCRYPTED */
|
1997-11-18 15:06:00 +01:00
|
|
|
PKT_plaintext *plaintext; /* PKT_PLAINTEXT */
|
|
|
|
} pkt;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define init_packet(a) do { (a)->pkttype = 0; \
|
|
|
|
(a)->pkt.generic = NULL; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/*-- mainproc.c --*/
|
|
|
|
int proc_packets( IOBUF a );
|
1998-03-09 22:44:06 +01:00
|
|
|
int proc_signature_packets( IOBUF a, STRLIST signedfiles );
|
|
|
|
int proc_encryption_packets( IOBUF a );
|
1998-01-02 21:40:10 +01:00
|
|
|
int list_packets( IOBUF a );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- parse-packet.c --*/
|
|
|
|
int set_packet_list_mode( int mode );
|
1997-12-12 13:03:58 +01:00
|
|
|
int search_packet( IOBUF inp, PACKET *pkt, int pkttype, ulong *retpos );
|
1997-11-18 15:06:00 +01:00
|
|
|
int parse_packet( IOBUF inp, PACKET *ret_pkt);
|
1998-02-11 04:25:44 +01:00
|
|
|
int copy_all_packets( IOBUF inp, IOBUF out );
|
|
|
|
int copy_some_packets( IOBUF inp, IOBUF out, ulong stopoff );
|
|
|
|
int skip_some_packets( IOBUF inp, unsigned n );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- build-packet.c --*/
|
|
|
|
int build_packet( IOBUF inp, PACKET *pkt );
|
|
|
|
u32 calc_packet_length( PACKET *pkt );
|
1998-01-12 11:18:17 +01:00
|
|
|
void hash_public_cert( MD_HANDLE md, PKT_public_cert *pkc );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- free-packet.c --*/
|
1998-05-03 17:42:08 +02:00
|
|
|
void free_symkey_enc( PKT_symkey_enc *enc );
|
1997-11-18 15:06:00 +01:00
|
|
|
void free_pubkey_enc( PKT_pubkey_enc *enc );
|
|
|
|
void free_seckey_enc( PKT_signature *enc );
|
1998-01-30 17:23:16 +01:00
|
|
|
int digest_algo_from_sig( PKT_signature *sig );
|
1998-01-13 20:04:23 +01:00
|
|
|
void release_public_cert_parts( PKT_public_cert *cert );
|
1997-12-01 11:33:23 +01:00
|
|
|
void free_public_cert( PKT_public_cert *cert );
|
1998-01-13 20:04:23 +01:00
|
|
|
void release_secret_cert_parts( PKT_secret_cert *cert );
|
1997-12-01 11:33:23 +01:00
|
|
|
void free_secret_cert( PKT_secret_cert *cert );
|
1997-11-18 15:06:00 +01:00
|
|
|
void free_user_id( PKT_user_id *uid );
|
|
|
|
void free_comment( PKT_comment *rem );
|
|
|
|
void free_packet( PACKET *pkt );
|
1997-12-01 11:33:23 +01:00
|
|
|
PKT_public_cert *copy_public_cert( PKT_public_cert *d, PKT_public_cert *s );
|
|
|
|
PKT_secret_cert *copy_secret_cert( PKT_secret_cert *d, PKT_secret_cert *s );
|
1998-02-17 21:48:52 +01:00
|
|
|
int cmp_public_certs( PKT_public_cert *a, PKT_public_cert *b );
|
1998-01-13 20:04:23 +01:00
|
|
|
int cmp_public_secret_cert( PKT_public_cert *pkc, PKT_secret_cert *skc );
|
1998-02-17 21:48:52 +01:00
|
|
|
int cmp_user_ids( PKT_user_id *a, PKT_user_id *b );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*-- sig-check.c --*/
|
1998-01-12 11:18:17 +01:00
|
|
|
int signature_check( PKT_signature *sig, MD_HANDLE digest );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- seckey-cert.c --*/
|
1998-01-06 22:01:36 +01:00
|
|
|
int is_secret_key_protected( PKT_secret_cert *cert );
|
1997-12-01 11:33:23 +01:00
|
|
|
int check_secret_key( PKT_secret_cert *cert );
|
1997-12-09 13:46:23 +01:00
|
|
|
int protect_secret_key( PKT_secret_cert *cert, DEK *dek );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- pubkey-enc.c --*/
|
|
|
|
int get_session_key( PKT_pubkey_enc *k, DEK *dek );
|
|
|
|
|
1997-11-23 16:38:27 +01:00
|
|
|
/*-- compress.c --*/
|
1998-03-09 22:44:06 +01:00
|
|
|
int handle_compressed( PKT_compressed *cd,
|
|
|
|
int (*callback)(IOBUF, void *), void *passthru );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- encr-data.c --*/
|
1997-12-01 11:33:23 +01:00
|
|
|
int decrypt_data( PKT_encrypted *ed, DEK *dek );
|
|
|
|
int encrypt_data( PKT_encrypted *ed, DEK *dek );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
/*-- plaintext.c --*/
|
1997-11-24 12:04:11 +01:00
|
|
|
int handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx );
|
1997-12-23 18:30:18 +01:00
|
|
|
int ask_for_detached_datafile( md_filter_context_t *mfx, const char *inname );
|
1997-11-24 12:04:11 +01:00
|
|
|
|
|
|
|
/*-- comment.c --*/
|
|
|
|
int write_comment( IOBUF out, const char *s );
|
|
|
|
|
1997-12-09 13:46:23 +01:00
|
|
|
/*-- sign.c --*/
|
|
|
|
int make_keysig_packet( PKT_signature **ret_sig, PKT_public_cert *pkc,
|
|
|
|
PKT_user_id *uid, PKT_secret_cert *skc,
|
|
|
|
int sigclass, int digest_algo );
|
1997-11-18 15:06:00 +01:00
|
|
|
|
|
|
|
#endif /*G10_PACKET_H*/
|