Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/crypto/external/bsd/netpgp/dist/src/lib Simplify and shorten...
details: https://anonhg.NetBSD.org/src/rev/e6c555f6baef
branches: trunk
changeset: 755163:e6c555f6baef
user: agc <agc%NetBSD.org@localhost>
date: Tue May 25 01:05:10 2010 +0000
description:
Simplify and shorten the internals of packet processing by getting rid of
the intermediate pseudo-abstraction layer, which detracted from understanding
and had no benefit whatsoever. Rename some enums and some definitions.
diffstat:
crypto/external/bsd/netpgp/dist/src/lib/create.c | 27 +-
crypto/external/bsd/netpgp/dist/src/lib/create.h | 10 +-
crypto/external/bsd/netpgp/dist/src/lib/crypto.h | 4 +-
crypto/external/bsd/netpgp/dist/src/lib/keyring.c | 54 +-
crypto/external/bsd/netpgp/dist/src/lib/keyring.h | 6 +-
crypto/external/bsd/netpgp/dist/src/lib/memory.h | 2 +-
crypto/external/bsd/netpgp/dist/src/lib/misc.c | 10 +-
crypto/external/bsd/netpgp/dist/src/lib/netpgp.c | 10 +-
crypto/external/bsd/netpgp/dist/src/lib/openssl_crypto.c | 4 +-
crypto/external/bsd/netpgp/dist/src/lib/packet-parse.c | 325 +++-----------
crypto/external/bsd/netpgp/dist/src/lib/packet-parse.h | 2 +-
crypto/external/bsd/netpgp/dist/src/lib/packet-print.c | 102 ++--
crypto/external/bsd/netpgp/dist/src/lib/packet-show.c | 36 +-
crypto/external/bsd/netpgp/dist/src/lib/packet-show.h | 16 +-
crypto/external/bsd/netpgp/dist/src/lib/packet.h | 337 +++-----------
crypto/external/bsd/netpgp/dist/src/lib/reader.c | 21 +-
crypto/external/bsd/netpgp/dist/src/lib/signature.c | 31 +-
crypto/external/bsd/netpgp/dist/src/lib/signature.h | 6 +-
crypto/external/bsd/netpgp/dist/src/lib/ssh2pgp.c | 8 +-
crypto/external/bsd/netpgp/dist/src/lib/validate.c | 16 +-
crypto/external/bsd/netpgp/dist/src/lib/validate.h | 6 +-
crypto/external/bsd/netpgp/dist/src/lib/writer.c | 10 +-
crypto/external/bsd/netpgp/dist/src/lib/writer.h | 2 +-
23 files changed, 329 insertions(+), 716 deletions(-)
diffs (truncated from 2614 to 300 lines):
diff -r 56cde7263463 -r e6c555f6baef crypto/external/bsd/netpgp/dist/src/lib/create.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/create.c Mon May 24 21:04:49 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/create.c Tue May 25 01:05:10 2010 +0000
@@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: create.c,v 1.27 2010/05/08 02:17:15 agc Exp $");
+__RCSID("$NetBSD: create.c,v 1.28 2010/05/25 01:05:10 agc Exp $");
#endif
#include <sys/types.h>
@@ -99,7 +99,7 @@
unsigned
__ops_write_ss_header(__ops_output_t *output,
unsigned length,
- __ops_content_tag_t type)
+ __ops_content_enum type)
{
return __ops_write_length(output, length) &&
__ops_write_scalar(output, (unsigned)(type -
@@ -122,9 +122,9 @@
*/
void
-__ops_fast_create_userid(__ops_userid_t *id, uint8_t *userid)
+__ops_fast_create_userid(uint8_t **id, uint8_t *userid)
{
- id->userid = userid;
+ *id = userid;
}
/**
@@ -135,11 +135,11 @@
* \return 1 if OK, otherwise 0
*/
unsigned
-__ops_write_struct_userid(__ops_output_t *output, __ops_userid_t *id)
+__ops_write_struct_userid(__ops_output_t *output, const uint8_t *id)
{
return __ops_write_ptag(output, OPS_PTAG_CT_USER_ID) &&
- __ops_write_length(output, strlen((char *) id->userid)) &&
- __ops_write(output, id->userid, strlen((char *) id->userid));
+ __ops_write_length(output, strlen((const char *) id)) &&
+ __ops_write(output, id, strlen((const char *) id));
}
/**
@@ -153,10 +153,7 @@
unsigned
__ops_write_userid(const uint8_t *userid, __ops_output_t *output)
{
- __ops_userid_t id;
-
- id.userid = __UNCONST(userid);
- return __ops_write_struct_userid(output, &id);
+ return __ops_write_struct_userid(output, userid);
}
/**
@@ -520,7 +517,7 @@
/* user ids and corresponding signatures */
for (i = 0; i < key->uidc; i++) {
- if (!__ops_write_struct_userid(output, &key->uids[i])) {
+ if (!__ops_write_struct_userid(output, key->uids[i])) {
return 0;
}
for (j = 0; j < key->packetc; j++) {
@@ -579,7 +576,7 @@
/* user ids and corresponding signatures */
for (i = 0; i < key->uidc; i++) {
- if (!__ops_write_struct_userid(output, &key->uids[i])) {
+ if (!__ops_write_struct_userid(output, key->uids[i])) {
return 0;
}
for (j = 0; j < key->packetc; j++) {
@@ -1096,7 +1093,7 @@
__ops_write_litdata(__ops_output_t *output,
const uint8_t *data,
const int maxlen,
- const __ops_litdata_type_t type)
+ const __ops_litdata_enum type)
{
/*
* RFC4880 does not specify a meaning for filename or date.
@@ -1123,7 +1120,7 @@
unsigned
__ops_fileread_litdata(const char *filename,
- const __ops_litdata_type_t type,
+ const __ops_litdata_enum type,
__ops_output_t *output)
{
__ops_memory_t *mem;
diff -r 56cde7263463 -r e6c555f6baef crypto/external/bsd/netpgp/dist/src/lib/create.h
--- a/crypto/external/bsd/netpgp/dist/src/lib/create.h Mon May 24 21:04:49 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/create.h Tue May 25 01:05:10 2010 +0000
@@ -77,8 +77,8 @@
void __ops_build_pubkey(__ops_memory_t *, const __ops_pubkey_t *, unsigned);
unsigned __ops_calc_sesskey_checksum(__ops_pk_sesskey_t *, uint8_t *);
-unsigned __ops_write_struct_userid(__ops_output_t *, __ops_userid_t *);
-unsigned __ops_write_ss_header(__ops_output_t *, unsigned, __ops_content_tag_t);
+unsigned __ops_write_struct_userid(__ops_output_t *, const uint8_t *);
+unsigned __ops_write_ss_header(__ops_output_t *, unsigned, __ops_content_enum);
unsigned __ops_write_struct_seckey(const __ops_seckey_t *,
const uint8_t *,
const size_t,
@@ -90,7 +90,7 @@
unsigned __ops_write_litdata(__ops_output_t *,
const uint8_t *,
const int,
- const __ops_litdata_type_t);
+ const __ops_litdata_enum);
__ops_pk_sesskey_t *__ops_create_pk_sesskey(const __ops_key_t *);
unsigned __ops_write_pk_sesskey(__ops_output_t *, __ops_pk_sesskey_t *);
unsigned __ops_write_xfer_pubkey(__ops_output_t *,
@@ -101,7 +101,7 @@
const size_t,
const unsigned);
-void __ops_fast_create_userid(__ops_userid_t *, uint8_t *);
+void __ops_fast_create_userid(uint8_t **, uint8_t *);
unsigned __ops_write_userid(const uint8_t *, __ops_output_t *);
void __ops_fast_create_rsa_pubkey(__ops_pubkey_t *, time_t, BIGNUM *, BIGNUM *);
unsigned __ops_write_rsa_pubkey(time_t, const BIGNUM *, const BIGNUM *,
@@ -111,7 +111,7 @@
BIGNUM *, BIGNUM *);
unsigned encode_m_buf(const uint8_t *, size_t, const __ops_pubkey_t *,
uint8_t *);
-unsigned __ops_fileread_litdata(const char *, const __ops_litdata_type_t,
+unsigned __ops_fileread_litdata(const char *, const __ops_litdata_enum,
__ops_output_t *);
unsigned __ops_write_symm_enc_data(const uint8_t *, const int,
__ops_output_t *);
diff -r 56cde7263463 -r e6c555f6baef crypto/external/bsd/netpgp/dist/src/lib/crypto.h
--- a/crypto/external/bsd/netpgp/dist/src/lib/crypto.h Mon May 24 21:04:49 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/crypto.h Tue May 25 01:05:10 2010 +0000
@@ -148,7 +148,7 @@
unsigned __ops_block_size(__ops_symm_alg_t);
unsigned __ops_key_size(__ops_symm_alg_t);
-int __ops_decrypt_data(__ops_content_tag_t, __ops_region_t *,
+int __ops_decrypt_data(__ops_content_enum, __ops_region_t *,
__ops_stream_t *);
int __ops_crypt_any(__ops_crypt_t *, __ops_symm_alg_t);
@@ -210,7 +210,7 @@
/* Keys */
__ops_key_t *__ops_rsa_new_selfsign_key(const int,
- const unsigned long, __ops_userid_t *, const char *);
+ const unsigned long, uint8_t *, const char *);
int __ops_dsa_size(const __ops_dsa_pubkey_t *);
DSA_SIG *__ops_dsa_sign(uint8_t *, unsigned,
diff -r 56cde7263463 -r e6c555f6baef crypto/external/bsd/netpgp/dist/src/lib/keyring.c
--- a/crypto/external/bsd/netpgp/dist/src/lib/keyring.c Mon May 24 21:04:49 2010 +0000
+++ b/crypto/external/bsd/netpgp/dist/src/lib/keyring.c Tue May 25 01:05:10 2010 +0000
@@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
-__RCSID("$NetBSD: keyring.c,v 1.36 2010/05/21 14:28:44 agc Exp $");
+__RCSID("$NetBSD: keyring.c,v 1.37 2010/05/25 01:05:10 agc Exp $");
#endif
#ifdef HAVE_FCNTL_H
@@ -267,7 +267,7 @@
return OPS_FINISHED;
case OPS_PARSER_ERROR:
- fprintf(stderr, "parse error: %s\n", content->error.error);
+ fprintf(stderr, "parse error: %s\n", content->error);
return OPS_FINISHED;
case OPS_PTAG_CT_SECRET_KEY:
@@ -363,7 +363,7 @@
const uint8_t *
__ops_get_userid(const __ops_key_t *key, unsigned subscript)
{
- return key->uids[subscript].userid;
+ return key->uids[subscript];
}
/**
@@ -396,21 +396,21 @@
\param src Source User ID
\note If dst already has a userid, it will be freed.
*/
-static __ops_userid_t *
-__ops_copy_userid(__ops_userid_t *dst, const __ops_userid_t *src)
+static uint8_t *
+__ops_copy_userid(uint8_t **dst, const uint8_t *src)
{
size_t len;
- len = strlen((char *) src->userid);
- if (dst->userid) {
- free(dst->userid);
+ len = strlen((const char *) src);
+ if (*dst) {
+ free(*dst);
}
- if ((dst->userid = calloc(1, len + 1)) == NULL) {
+ if ((*dst = calloc(1, len + 1)) == NULL) {
(void) fprintf(stderr, "__ops_copy_userid: bad alloc\n");
} else {
- (void) memcpy(dst->userid, src->userid, len);
+ (void) memcpy(*dst, src, len);
}
- return dst;
+ return *dst;
}
/* \todo check where pkt pointers are copied */
@@ -443,15 +443,15 @@
\param userid User ID to add
\return Pointer to new User ID
*/
-__ops_userid_t *
-__ops_add_userid(__ops_key_t *key, const __ops_userid_t *userid)
+uint8_t *
+__ops_add_userid(__ops_key_t *key, const uint8_t *userid)
{
- __ops_userid_t *uidp;
+ uint8_t **uidp;
EXPAND_ARRAY(key, uid);
/* initialise new entry in array */
uidp = &key->uids[key->uidc++];
- uidp->userid = NULL;
+ *uidp = NULL;
/* now copy it */
return __ops_copy_userid(uidp, userid);
}
@@ -487,7 +487,7 @@
\return 1 if OK; else 0
*/
unsigned
-__ops_add_selfsigned_userid(__ops_key_t *key, __ops_userid_t *userid)
+__ops_add_selfsigned_userid(__ops_key_t *key, uint8_t *userid)
{
__ops_create_sig_t *sig;
__ops_subpacket_t sigpacket;
@@ -540,7 +540,7 @@
\param type OPS_PTAG_CT_PUBLIC_KEY or OPS_PTAG_CT_SECRET_KEY
*/
void
-__ops_keydata_init(__ops_key_t *keydata, const __ops_content_tag_t type)
+__ops_keydata_init(__ops_key_t *keydata, const __ops_content_enum type)
{
if (keydata->type != OPS_PTAG_CT_RESERVED) {
(void) fprintf(stderr,
@@ -598,24 +598,24 @@
case OPS_PTAG_SS_KEY_EXPIRY:
EXPAND_ARRAY(keyring, key);
if (keyring->keyc > 0) {
- keyring->keys[keyring->keyc - 1].key.pubkey.duration = pkt->u.ss_time.time;
+ keyring->keys[keyring->keyc - 1].key.pubkey.duration = pkt->u.ss_time;
}
break;
case OPS_PTAG_SS_ISSUER_KEY_ID:
key = &keyring->keys[keyring->keyc - 1];
(void) memcpy(&key->subsigs[key->subsigc - 1].sig.info.signer_id,
- pkt->u.ss_issuer.key_id,
- sizeof(pkt->u.ss_issuer.key_id));
+ pkt->u.ss_issuer,
+ sizeof(pkt->u.ss_issuer));
key->subsigs[key->subsigc - 1].sig.info.signer_id_set = 1;
break;
case OPS_PTAG_SS_CREATION_TIME:
key = &keyring->keys[keyring->keyc - 1];
- key->subsigs[key->subsigc - 1].sig.info.birthtime = pkt->u.ss_time.time;
+ key->subsigs[key->subsigc - 1].sig.info.birthtime = pkt->u.ss_time;
key->subsigs[key->subsigc - 1].sig.info.birthtime_set = 1;
break;
case OPS_PTAG_SS_EXPIRATION_TIME:
key = &keyring->keys[keyring->keyc - 1];
- key->subsigs[key->subsigc - 1].sig.info.duration = pkt->u.ss_time.time;
+ key->subsigs[key->subsigc - 1].sig.info.duration = pkt->u.ss_time;
key->subsigs[key->subsigc - 1].sig.info.duration_set = 1;
break;
case OPS_PTAG_SS_PRIMARY_USER_ID:
@@ -884,7 +884,7 @@
unsigned *from)
{
const __ops_key_t *kp;
- __ops_userid_t *uidp;
+ uint8_t **uidp;
unsigned i = 0;
__ops_key_t *keyp;
unsigned savedstart;
@@ -922,12 +922,10 @@
for (i = 0 ; i < keyp->uidc; i++, uidp++) {
if (__ops_get_debug_level(__FILE__)) {
(void) fprintf(io->outs,
- "keyid \"%s\" len %"
Home |
Main Index |
Thread Index |
Old Index