/*
* Copyright (C) 1997-1999 Thomas Roessler <roessler@guug.de>
*
* This program is free software; you can redistribute it
* and/or modify 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.
*
* This program is distributed in the hope that it will be
* useful, 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., 675 Mass Ave, Cambridge, MA
* 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include "sha.h"
#include "mutt.h"
#include "pgp.h"
#include "charset.h"
#define CHUNKSIZE 1024
static unsigned char *pbuf = NULL;
static size_t plen = 0;
enum packet_tags
{
PT_RES0 = 0, /* reserved */
PT_ESK, /* Encrypted Session Key */
PT_SIG, /* Signature Packet */
PT_CESK, /* Conventionally Encrypted Session Key Packet */
PT_OPS, /* One-Pass Signature Packet */
PT_SECKEY, /* Secret Key Packet */
PT_PUBKEY, /* Public Key Packet */
PT_SUBSECKEY, /* Secret Subkey Packet */
PT_COMPRESSED, /* Compressed Data Packet */
PT_SKE, /* Symmetrically Encrypted Data Packet */
PT_MARKER, /* Marker Packet */
PT_LITERAL, /* Literal Data Packet */
PT_TRUST, /* Trust Packet */
PT_NAME, /* Name Packet */
PT_SUBKEY, /* Subkey Packet */
PT_RES15, /* Reserved */
PT_COMMENT /* Comment Packet */
};
/* FIXME I can't find where those strings are displayed! */
const char *pgp_packet_name[] =
{
N_("reserved"),
N_("Encrypted Session Key"),
N_("Signature Packet"),
N_("Conventionally Encrypted Session Key Packet"),
N_("One-Pass Signature Packet"),
N_("Secret Key Packet"),
N_("Public Key Packet"),
N_("Secret Subkey Packet"),
N_("Compressed Data Packet"),
N_("Symmetrically Encrypted Data Packet"),
N_("Marker Packet"),
N_("Literal Data Packet"),
N_("Trust Packet"),
N_("Name Packet"),
N_("Subkey Packet"),
N_("Reserved"),
N_("Comment Packet")
};
const char *pgp_pkalgbytype (unsigned char type)
{
switch (type)
{
case 1:
return "RSA";
case 2:
return "RSA";
case 3:
return "RSA";
case 16:
return "ElG";
case 17:
return "DSA";
case 20:
return "ElG";
default:
return "unk";
}
}
static struct
{
char *pkalg;
char *micalg;
}
pktomic[] =
{
{
"RSA", "pgp-md5"
}
,
{
"ElG", "pgp-rmd160"
}
,
{
"DSA", "pgp-sha1"
}
,
{
NULL, "x-unknown"
}
};
const char *pgp_pkalg_to_mic (const char *alg)
{
int i;
for (i = 0; pktomic[i].pkalg; i++)
{
if (!mutt_strcasecmp (pktomic[i].pkalg, alg))
break;
}
return pktomic[i].micalg;
}
/* unused */
#if 0
static const char *hashalgbytype (unsigned char type)
{
switch (type)
{
case 1:
return "MD5";
case 2:
return "SHA1";
case 3:
return "RIPE-MD/160";
case 4:
return "HAVAL";
default:
return "unknown";
}
}
#endif
short pgp_canencrypt (unsigned char type)
{
switch (type)
{
case 1:
case 2:
case 16:
case 20:
return 1;
default:
return 0;
}
}
short pgp_cansign (unsigned char type)
{
switch (type)
{
case 1:
case 3:
case 17:
case 20:
return 1;
default:
return 0;
}
}
/* return values:
* 1 = sign only
* 2 = encrypt only
* 3 = both
*/
short pgp_get_abilities (unsigned char type)
{
return (pgp_canencrypt (type) << 1) | pgp_cansign