CHANGES 1.0.0 -> 1.99.1

+ released and tagged version 1.0.0; development version now 1.99.1
+ get rid of some fields which are no longer needed
+ minor name changes
+ add mmapped field to ops_data_t struct to denote that the array needs an
  munmap(2) and not a free(3)
+ add an __ops_mem_readfile() function, and use it for reading files.
  The function does mmap(2), and then falls back to read(2) if that fails.
  Retire unused __ops_fileread() which had an unusual interface
+ drop sign_detached() from netpgp.c down into signature.c as
  __ops_sign_detached()
This commit is contained in:
agc 2009-05-19 05:13:09 +00:00
parent 8ebd73cde8
commit 0df5e957ce
26 changed files with 512 additions and 704 deletions

View File

@ -1,16 +1,14 @@
To Do
=====
RCS Ids
64-bit offsets
detached verification
separate from libcrypto?
need a netpgp_set_{pub,sec}key()? vs _init()?
default compression when signing
default compression when signing?
get rid of ops_memory after used literal_data_body
sort out callback - ops_export_key, packet-parse callback etc
Simplify IO
Make into SHA1Init, SHA1End, SHA1File style of calls
Multiple recipients for encryption
Look at inefficiencies - read() etc
Done
====
@ -53,3 +51,6 @@ print out size of key in --list-keys
decryption - print encrypted key info
get rid of local files
hash algorithm selection
detached verification
RCS Ids
Look at inefficiencies - read() etc

View File

@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.63 for netpgp 20090517.
# Generated by GNU Autoconf 2.63 for netpgp 20090518.
#
# Report bugs to <Alistair Crooks <agc@netbsd.org> c0596823>.
#
@ -596,8 +596,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='netpgp'
PACKAGE_TARNAME='netpgp'
PACKAGE_VERSION='20090517'
PACKAGE_STRING='netpgp 20090517'
PACKAGE_VERSION='20090518'
PACKAGE_STRING='netpgp 20090518'
PACKAGE_BUGREPORT='Alistair Crooks <agc@netbsd.org> c0596823'
ac_unique_file="src/bin/netpgp.c"
@ -1268,7 +1268,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures netpgp 20090517 to adapt to many kinds of systems.
\`configure' configures netpgp 20090518 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@ -1338,7 +1338,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of netpgp 20090517:";;
short | recursive ) echo "Configuration of netpgp 20090518:";;
esac
cat <<\_ACEOF
@ -1418,7 +1418,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
netpgp configure 20090517
netpgp configure 20090518
generated by GNU Autoconf 2.63
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@ -1432,7 +1432,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by netpgp $as_me 20090517, which was
It was created by netpgp $as_me 20090518, which was
generated by GNU Autoconf 2.63. Invocation command line was
$ $0 $@
@ -6161,7 +6161,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by netpgp $as_me 20090517, which was
This file was extended by netpgp $as_me 20090518, which was
generated by GNU Autoconf 2.63. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@ -6220,7 +6220,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_version="\\
netpgp config.status 20090517
netpgp config.status 20090518
configured by $0, generated by GNU Autoconf 2.63,
with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"

View File

@ -1,7 +1,7 @@
dnl $Id: configure.ac,v 1.7 2009/05/18 03:55:42 agc Exp $
dnl $Id: configure.ac,v 1.8 2009/05/19 05:13:09 agc Exp $
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ(2.57)
AC_INIT([netpgp],[20090517],[Alistair Crooks <agc@netbsd.org> c0596823])
AC_INIT([netpgp],[20090518],[Alistair Crooks <agc@netbsd.org> c0596823])
AC_CONFIG_SRCDIR([src/bin/netpgp.c])
AC_CONFIG_HEADER(src/lib/config.h)
AC_ARG_PROGRAM

View File

@ -122,13 +122,13 @@
#define PACKAGE_NAME "netpgp"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "netpgp 20090517"
#define PACKAGE_STRING "netpgp 20090518"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "netpgp"
/* Define to the version of this package. */
#define PACKAGE_VERSION "20090517"
#define PACKAGE_VERSION "20090518"
/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: create.c,v 1.11 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: create.c,v 1.12 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
@ -445,7 +445,7 @@ write_seckey_body(const __ops_seckey_t * key,
(void) fprintf(stderr, "turning encryption on...\n");
}
__ops_writer_push_encrypt_crypt(output, &crypted);
__ops_push_enc_crypt(output, &crypted);
switch (key->pubkey.alg) {
/* case OPS_PKA_DSA: */
@ -516,7 +516,7 @@ write_struct_pubkey(__ops_output_t *output, const __ops_pubkey_t *key)
*/
unsigned
__ops_write_transferable_pubkey(__ops_output_t *output,
__ops_write_xfer_pubkey(__ops_output_t *output,
const __ops_keydata_t *keydata,
unsigned armoured)
{
@ -582,7 +582,7 @@ __ops_write_transferable_pubkey(__ops_output_t *output,
*/
unsigned
__ops_write_transferable_seckey(__ops_output_t *output,
__ops_write_xfer_seckey(__ops_output_t *output,
const __ops_keydata_t *keydata,
const unsigned char *passphrase,
const size_t pplen,
@ -1155,118 +1155,27 @@ __ops_write_litdata(__ops_output_t * output,
unsigned
__ops_fileread_litdata(const char *filename,
const __ops_litdata_type_t type,
__ops_output_t * output)
__ops_output_t *output)
{
unsigned char buf[1024];
unsigned char *mmapped;
__ops_memory_t *mem = NULL;
struct stat st;
size_t len = 0;
int fd = 0;
unsigned ret;
#ifdef O_BINARY
fd = open(filename, O_RDONLY | O_BINARY);
#else
fd = open(filename, O_RDONLY);
#endif
if (fd < 0)
return 0;
size_t len;
mem = __ops_memory_new();
mmapped = MAP_FAILED;
#ifdef USE_MMAP_FOR_FILES
if (fstat(fd, &st) == 0) {
mem->length = (unsigned)st.st_size;
mmapped = mem->buf = mmap(NULL, (size_t)st.st_size, PROT_READ,
MAP_FILE | MAP_PRIVATE, fd, 0);
if (!__ops_mem_readfile(mem, filename)) {
return 0;
}
#endif
if (mmapped == MAP_FAILED) {
__ops_memory_init(mem, (size_t)st.st_size);
for (;;) {
ssize_t n = 0;
if ((n = read(fd, buf, sizeof(buf))) == 0) {
break;
}
__ops_memory_add(mem, buf, (unsigned)n);
}
}
(void) close(fd);
/* \todo do we need to check text data for <cr><lf> line endings ? */
len = __ops_mem_len(mem);
ret = __ops_write_ptag(output, OPS_PTAG_CT_LITERAL_DATA) &&
__ops_write_length(output, 1 + 1 + 4 + len) &&
__ops_write_scalar(output, (unsigned)type, 1) &&
__ops_write_scalar(output, 0, 1) /* filename */ &&
__ops_write_scalar(output, 0, 4) /* date */ &&
__ops_write_scalar(output, 0, 1) /* filename */ &&
__ops_write_scalar(output, 0, 4) /* date */ &&
__ops_write(output, __ops_mem_data(mem), len);
#ifdef USE_MMAP_FOR_FILES
if (mmapped != MAP_FAILED) {
munmap(mmapped, mem->length);
mmapped = buf;
}
#endif
if (mmapped == NULL) {
__ops_memory_free(mem);
}
__ops_memory_free(mem);
return ret;
}
/**
\ingroup HighLevel_General
\brief Reads contents of file into new __ops_memory_t struct.
\param filename Filename to read from
\param errnum Pointer to error
\return new __ops_memory_t pointer containing the contents of the file
\note If there was an error opening the file or reading from it,
errnum is set to the cause
\note It is the caller's responsibility to call __ops_memory_free(mem)
*/
__ops_memory_t *
__ops_fileread(const char *filename, int *errnum)
{
__ops_memory_t *mem = NULL;
unsigned char buf[1024];
struct stat st;
int fd = 0;
*errnum = 0;
#ifdef O_BINARY
fd = open(filename, O_RDONLY | O_BINARY);
#else
fd = open(filename, O_RDONLY);
#endif
if (fd < 0) {
*errnum = errno;
return 0;
}
mem = __ops_memory_new();
(void) fstat(fd, &st);
__ops_memory_init(mem, (unsigned)st.st_size);
for (;;) {
ssize_t n = 0;
n = read(fd, buf, sizeof(buf));
if (n < 0) {
*errnum = errno;
break;
}
if (!n) {
break;
}
__ops_memory_add(mem, buf, (unsigned)n);
}
(void) close(fd);
return mem;
}
/**
\ingroup HighLevel_General

View File

@ -74,7 +74,6 @@ void __ops_output_delete(__ops_output_t *);
int __ops_filewrite(const char *, const char *, const size_t, const unsigned);
__ops_memory_t *__ops_fileread(const char *, int *);
void __ops_build_pubkey(__ops_memory_t *, const __ops_pubkey_t *, unsigned);
unsigned __ops_calc_sesskey_checksum(__ops_pk_sesskey_t *, unsigned char *);
@ -94,9 +93,9 @@ unsigned __ops_write_litdata(__ops_output_t *,
const __ops_litdata_type_t);
__ops_pk_sesskey_t *__ops_create_pk_sesskey(const __ops_keydata_t *);
unsigned __ops_write_pk_sesskey(__ops_output_t *, __ops_pk_sesskey_t *);
unsigned __ops_write_transferable_pubkey(__ops_output_t *,
unsigned __ops_write_xfer_pubkey(__ops_output_t *,
const __ops_keydata_t *, unsigned);
unsigned __ops_write_transferable_seckey(__ops_output_t *,
unsigned __ops_write_xfer_seckey(__ops_output_t *,
const __ops_keydata_t *,
const unsigned char *,
const size_t,

View File

@ -54,7 +54,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: crypto.c,v 1.10 2009/05/18 03:55:42 agc Exp $");
__RCSID("$NetBSD: crypto.c,v 1.11 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
@ -238,58 +238,34 @@ __ops_encrypt_file(const char *infile,
const unsigned use_armour,
const unsigned allow_overwrite)
{
__ops_output_t *create;
struct stat st;
unsigned char *buf;
size_t bufsz;
size_t done;
int fd_in = 0;
__ops_output_t *output;
__ops_memory_t *inmem;
int fd_out = 0;
int n;
#ifdef O_BINARY
fd_in = open(infile, O_RDONLY | O_BINARY);
#else
fd_in = open(infile, O_RDONLY);
#endif
if (fd_in < 0) {
perror(infile);
inmem = __ops_memory_new();
if (!__ops_mem_readfile(inmem, infile)) {
return 0;
}
fd_out = __ops_setup_file_write(&create, outfile, allow_overwrite);
fd_out = __ops_setup_file_write(&output, outfile, allow_overwrite);
if (fd_out < 0) {
__ops_memory_free(inmem);
return 0;
}
/* set armoured/not armoured here */
if (use_armour) {
__ops_writer_push_armor_msg(create);
__ops_writer_push_armor_msg(output);
}
/* Push the encrypted writer */
__ops_writer_push_encrypt_se_ip(create, pubkey);
/* Do the reading */
(void) fstat(fd_in, &st);
bufsz = (size_t)st.st_size;
buf = calloc(1, bufsz);
for (done = 0 ; done < bufsz ; done += n) {
if ((n = read(fd_in, buf + done, bufsz - done)) == 0) {
break;
}
if (n < 0) {
(void) fprintf(stderr, "Problem in read\n");
return 0;
}
}
__ops_push_enc_se_ip(output, pubkey);
/* This does the writing */
__ops_write(create, buf, done);
__ops_write(output, __ops_mem_data(inmem), __ops_mem_len(inmem));
/* tidy up */
(void) close(fd_in);
(void) free(buf);
__ops_teardown_file_write(create, fd_out);
__ops_memory_free(inmem);
__ops_teardown_file_write(output, fd_out);
return 1;
}
@ -393,7 +369,7 @@ __ops_decrypt_file(const char *infile,
return 1;
}
static __ops_parse_cb_return_t
static __ops_parse_cb_return_t
callback_write_parsed(const __ops_packet_t *pkt, __ops_callback_data_t *cbinfo)
{
const __ops_parser_content_union_t *content = &pkt->u;

View File

@ -67,17 +67,17 @@ typedef unsigned __ops_hash_finish_t(__ops_hash_t *, unsigned char *);
/** _ops_hash_t */
struct _ops_hash_t {
__ops_hash_alg_t alg;
size_t size;
const char *name;
__ops_hash_init_t *init;
__ops_hash_add_t *add;
__ops_hash_finish_t *finish;
void *data;
__ops_hash_alg_t alg; /* algorithm */
size_t size; /* size */
const char *name; /* what it's known as */
__ops_hash_init_t *init; /* initialisation func */
__ops_hash_add_t *add; /* add text func */
__ops_hash_finish_t *finish; /* finalise func */
void *data; /* blob for data */
};
typedef void __ops_crypt_set_iv_t(__ops_crypt_t *, const unsigned char *);
typedef void __ops_crypt_set_key_t(__ops_crypt_t *, const unsigned char *);
typedef void __ops_setiv_func_t(__ops_crypt_t *, const unsigned char *);
typedef void __ops_setkey_func_t(__ops_crypt_t *, const unsigned char *);
typedef void __ops_crypt_init_t(__ops_crypt_t *);
typedef void __ops_crypt_resync_t(__ops_crypt_t *);
typedef void __ops_blkenc_t(__ops_crypt_t *, void *, const void *);
@ -93,8 +93,8 @@ struct _ops_crypt_t {
__ops_symm_alg_t alg;
size_t blocksize;
size_t keysize;
__ops_crypt_set_iv_t *set_iv;/* Call before decrypt init! */
__ops_crypt_set_key_t *set_key;/* Call this before init! */
__ops_setiv_func_t *set_iv;/* Call before decrypt init! */
__ops_setkey_func_t *set_key;/* Call this before init! */
__ops_crypt_init_t *base_init;
__ops_crypt_resync_t *decrypt_resync;
/* encrypt/decrypt one block */
@ -186,7 +186,7 @@ unsigned __ops_decrypt_file(const char *, const char *, __ops_keyring_t *,
const unsigned, const unsigned, __ops_cbfunc_t *);
/* Keys */
__ops_keydata_t *__ops_rsa_new_selfsign_keypair(const int,
__ops_keydata_t *__ops_rsa_new_selfsign_key(const int,
const unsigned long, __ops_userid_t *);
int __ops_dsa_size(const __ops_dsa_pubkey_t *);
@ -209,7 +209,7 @@ struct __ops_reader_t {
};
/** __ops_cryptinfo
/** __ops_cryptinfo_t
Encrypt/decrypt settings
*/
struct __ops_cryptinfo_t {
@ -229,11 +229,11 @@ struct __ops_callback_data_t {
__ops_cryptinfo_t cryptinfo; /* used when decrypting */
};
/** __ops_parse_hash_info_t */
/** __ops_hashtype_t */
typedef struct {
__ops_hash_t hash; /* hashes we should hash data with */
unsigned char keyid[OPS_KEY_ID_SIZE];
} __ops_parse_hash_info_t;
} __ops_hashtype_t;
#define NTAGS 0x100 /* == 256 */
@ -270,12 +270,10 @@ struct __ops_parseinfo_t {
__ops_crypt_t decrypt;
__ops_cryptinfo_t cryptinfo;
size_t nhashes;
__ops_parse_hash_info_t *hashes;
__ops_hashtype_t *hashes;
unsigned reading_v3_secret:1;
unsigned reading_mpi_len:1;
unsigned exact_read:1;
void *synthsig; /* synthetic sig */
void *synthlit; /* synthetic literal data */
};
#endif /* CRYPTO_H_ */

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: keyring.c,v 1.9 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: keyring.c,v 1.10 2009/05/19 05:13:10 agc Exp $");
#endif
#ifdef HAVE_FCNTL_H
@ -202,16 +202,23 @@ __ops_get_seckey(const __ops_keydata_t * data)
*/
__ops_seckey_t *
__ops_get_writable_seckey(__ops_keydata_t * data)
__ops_get_writable_seckey(__ops_keydata_t *data)
{
return (data->type == OPS_PTAG_CT_SECRET_KEY) ?
&data->key.seckey : NULL;
}
/* utility function to dispose of a seckey */
void
__ops_seckey_forget(__ops_seckey_t *seckey)
{
(void) memset(seckey, 0x0, sizeof(*seckey));
}
typedef struct {
const __ops_keydata_t *key;
char *pphrase;
__ops_seckey_t *seckey;
__ops_seckey_t *seckey;
} decrypt_t;
static __ops_parse_cb_return_t
@ -374,32 +381,6 @@ __ops_is_key_supported(const __ops_keydata_t *keydata)
return 0;
}
/**
\ingroup HighLevel_KeyringFind
\brief Returns key inside a keyring, chosen by index
\param keyring Pointer to existing keyring
\param index Index of required key
\note Index starts at 0
\note This returns a pointer to the original key, not a copy. You
do not need to free the key after use.
\return Pointer to the required key; or NULL if index too large.
*/
const __ops_keydata_t *
__ops_keyring_get_key_by_index(const __ops_keyring_t * keyring, int subscript)
{
if (subscript >= keyring->nkeys)
return NULL;
return &keyring->keys[subscript];
}
/* \todo check where userid pointers are copied */
/**
\ingroup Core_Keys
@ -549,10 +530,10 @@ __ops_add_selfsigned_userid(__ops_keydata_t *keydata, __ops_userid_t *userid)
sig = __ops_create_sig_new();
__ops_sig_start_key_sig(sig, &keydata->key.seckey.pubkey, userid,
OPS_CERT_POSITIVE);
__ops_sig_add_birthtime(sig, time(NULL));
__ops_sig_add_issuer_key_id(sig, keydata->key_id);
__ops_sig_add_primary_userid(sig, 1);
__ops_sig_hashed_subpackets_end(sig);
__ops_add_birthtime(sig, time(NULL));
__ops_add_issuer_keyid(sig, keydata->key_id);
__ops_add_primary_userid(sig, 1);
__ops_end_hashed_subpkts(sig);
__ops_setup_memory_write(&sigoutput, &mem_sig, 128);
__ops_write_sig(sigoutput, sig, &keydata->key.seckey.pubkey,
@ -972,8 +953,8 @@ __ops_keyring_list(const __ops_keyring_t * keyring)
}
}
unsigned
__ops_get_keydata_content_type(const __ops_keydata_t * keydata)
static unsigned
get_contents_type(const __ops_keydata_t *keydata)
{
return keydata->type;
}
@ -986,10 +967,10 @@ __ops_export_key(const __ops_keydata_t *keydata, unsigned char *passphrase)
__ops_memory_t *mem;
__ops_setup_memory_write(&output, &mem, 128);
if (__ops_get_keydata_content_type(keydata) == OPS_PTAG_CT_PUBLIC_KEY) {
__ops_write_transferable_pubkey(output, keydata, 1);
if (get_contents_type(keydata) == OPS_PTAG_CT_PUBLIC_KEY) {
__ops_write_xfer_pubkey(output, keydata, 1);
} else {
__ops_write_transferable_seckey(output, keydata, passphrase,
__ops_write_xfer_seckey(output, keydata, passphrase,
strlen((char *)passphrase), 1);
}
printf("%s", (char *) __ops_mem_data(mem));

View File

@ -89,13 +89,12 @@ char *__ops_malloc_passphrase(char *);
void __ops_keyring_list(const __ops_keyring_t *);
void __ops_set_seckey(__ops_parser_content_union_t *, const __ops_keydata_t *);
void __ops_seckey_forget(__ops_seckey_t *);
const unsigned char *__ops_get_key_id(const __ops_keydata_t *);
unsigned __ops_get_userid_count(const __ops_keydata_t *);
const unsigned char *__ops_get_userid(const __ops_keydata_t *, unsigned);
unsigned __ops_is_key_supported(const __ops_keydata_t *);
const __ops_keydata_t *__ops_keyring_get_key_by_index(const __ops_keyring_t *,
int);
__ops_userid_t *__ops_add_userid(__ops_keydata_t *, const __ops_userid_t *);
__ops_subpacket_t *__ops_add_subpacket(__ops_keydata_t *,
@ -111,7 +110,6 @@ void __ops_keydata_init(__ops_keydata_t *, const __ops_content_tag_t);
void __ops_copy_userid(__ops_userid_t *, const __ops_userid_t *);
void __ops_copy_packet(__ops_subpacket_t *, const __ops_subpacket_t *);
unsigned __ops_get_keydata_content_type(const __ops_keydata_t *);
int __ops_parse_and_accumulate(__ops_keyring_t *, __ops_parseinfo_t *);

View File

@ -62,6 +62,7 @@ typedef struct __ops_memory_t {
unsigned char *buf;
size_t length;
size_t allocated;
unsigned mmapped;
} __ops_memory_t;
@ -79,6 +80,7 @@ void __ops_writer_set_memory(__ops_output_t *, __ops_memory_t *);
size_t __ops_mem_len(const __ops_memory_t *);
void *__ops_mem_data(__ops_memory_t *);
int __ops_mem_readfile(__ops_memory_t *, const char *);
void __ops_random(void *, size_t);

View File

@ -57,9 +57,13 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: misc.c,v 1.9 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: misc.c,v 1.10 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@ -731,7 +735,7 @@ __ops_calc_mdc_hash(const unsigned char *preamble,
/* plaintext */
hash.add(&hash, plaintext, sz_plaintext);
/* MDC packet tag */
c = 0xD3;
c = MDC_PKT_TAG;
hash.add(&hash, &c, 1);
/* MDC packet len */
c = OPS_SHA1_HASH_SIZE;
@ -876,7 +880,11 @@ __ops_memory_clear(__ops_memory_t *mem)
void
__ops_memory_release(__ops_memory_t *mem)
{
(void) free(mem->buf);
if (mem->mmapped) {
(void) munmap(mem->buf, mem->length);
} else {
(void) free(mem->buf);
}
mem->buf = NULL;
mem->length = 0;
}
@ -934,7 +942,7 @@ void
__ops_memory_free(__ops_memory_t * mem)
{
__ops_memory_release(mem);
free(mem);
(void) free(mem);
}
/**
@ -959,6 +967,44 @@ __ops_mem_data(__ops_memory_t *mem)
return mem->buf;
}
/* read a gile into an __ops_memory_t */
int
__ops_mem_readfile(__ops_memory_t *mem, const char *f)
{
struct stat st;
FILE *fp;
int cc;
if ((fp = fopen(f, "rb")) == NULL) {
(void) fprintf(stderr,
"__ops_mem_readfile: can't open \"%s\"\n", f);
return 0;
}
(void) fstat(fileno(fp), &st);
mem->allocated = (size_t)st.st_size;
mem->buf = mmap(NULL, mem->allocated, PROT_READ,
MAP_FILE | MAP_PRIVATE, fileno(fp), 0);
if (mem->buf == MAP_FAILED) {
/* mmap failed for some reason - try to allocate memory */
if ((mem->buf = calloc(1, mem->allocated)) == NULL) {
(void) fprintf(stderr, "__ops_mem_readfile: calloc\n");
(void) fclose(fp);
return 0;
}
/* read into contents of mem */
for (mem->length = 0 ;
(cc = read(fileno(fp), &mem->buf[mem->length],
mem->allocated - mem->length)) > 0 ;
mem->length += (size_t)cc) {
}
} else {
mem->length = mem->allocated;
mem->mmapped = 1;
}
(void) fclose(fp);
return (mem->allocated == mem->length);
}
typedef struct {
unsigned short sum;
} sum16_t;

View File

@ -34,7 +34,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: netpgp.c,v 1.13 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: netpgp.c,v 1.14 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
@ -99,6 +99,7 @@ conffile(netpgp_t *netpgp, char *homedir, char *userid, size_t length)
char buf[BUFSIZ];
FILE *fp;
__OPS_USED(netpgp);
(void) snprintf(buf, sizeof(buf), "%s/.gnupg/gpg.conf", homedir);
if ((fp = fopen(buf, "r")) == NULL) {
return 0;
@ -167,104 +168,13 @@ psuccess(FILE *fp, char *f, __ops_validation_t *res, __ops_keyring_t *pubring)
}
}
/* sign a file, and put the signature in a separate file */
static int
sign_detached(char *f, char *sigfile, __ops_seckey_t *seckey,
const char *hashstr)
{
__ops_create_sig_t *sig;
__ops_hash_alg_t alg;
__ops_output_t *output;
unsigned char keyid[OPS_KEY_ID_SIZE];
unsigned char *mmapped;
struct stat st;
time_t t;
char fname[MAXPATHLEN];
int fd;
/* find out which hash algorithm to use */
alg = __ops_str_to_hash_alg(hashstr);
if (alg == OPS_HASH_UNKNOWN) {
(void) fprintf(stderr,"Unknown hash algorithm: %s\n", hashstr);
return 0;
}
/* create a new signature */
sig = __ops_create_sig_new();
__ops_start_sig(sig, seckey, alg, OPS_SIG_BINARY);
/* read the contents of 'f' */
fd = open(f, O_RDONLY);
if (fd < 0) {
(void) fprintf(stderr, "can't open file \"%s\" to sign\n",
f);
return 0;
}
/* attempt to mmap(2) the file - if that fails, fall back to
* standard read(2) */
mmapped = MAP_FAILED;
if (fstat(fd, &st) == 0) {
mmapped = mmap(NULL, (size_t)st.st_size, PROT_READ,
MAP_FILE | MAP_PRIVATE, fd, 0);
}
if (mmapped == MAP_FAILED) {
for (;;) {
unsigned char buf[8192];
int n;
if ((n = read(fd, buf, sizeof(buf))) == 0) {
break;
}
if (n < 0) {
(void) fprintf(stderr, "short read \"%s\"\n",
f);
(void) close(fd);
return 0;
}
__ops_sig_add_data(sig, buf, (unsigned)n);
}
} else {
__ops_sig_add_data(sig, mmapped, (unsigned)st.st_size);
(void) munmap(mmapped, (unsigned)st.st_size);
}
(void) close(fd);
/* calculate the signature */
t = time(NULL);
__ops_sig_add_birthtime(sig, t);
__ops_keyid(keyid, OPS_KEY_ID_SIZE, OPS_KEY_ID_SIZE,
&seckey->pubkey);
__ops_sig_add_issuer_key_id(sig, keyid);
__ops_sig_hashed_subpackets_end(sig);
/* write the signature to the detached file */
if (sigfile == NULL) {
(void) snprintf(fname, sizeof(fname), "%s.sig", f);
sigfile = fname;
}
fd = open(sigfile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
(void) fprintf(stderr, "can't write signature to \"%s\"\n",
sigfile);
return 0;
}
output = __ops_output_new();
__ops_writer_set_fd(output, fd);
__ops_write_sig(output, sig, &seckey->pubkey, seckey);
__ops_seckey_free(seckey);
(void) close(fd);
return 1;
}
/***************************************************************************/
/* exported functions start here */
/***************************************************************************/
/* initialise a netpgp_t structure */
int
netpgp_init(netpgp_t *netpgp, char *userid, char *pubring, char *secring)
netpgp_init(netpgp_t *netpgp, char *userid, char *fpubring, char *fsecring)
{
__ops_keyring_t *keyring;
char *homedir;
@ -296,30 +206,30 @@ netpgp_init(netpgp_t *netpgp, char *userid, char *pubring, char *secring)
return 0;
}
(void) netpgp_setvar(netpgp, "userid", id);
if (pubring == NULL) {
if (fpubring == NULL) {
(void) snprintf(ringname, sizeof(ringname),
"%s/.gnupg/pubring.gpg", homedir);
pubring = ringname;
fpubring = ringname;
}
keyring = calloc(1, sizeof(*keyring));
if (!__ops_keyring_fileread(keyring, 0, pubring)) {
(void) fprintf(stderr, "Cannot read pub keyring %s\n", pubring);
if (!__ops_keyring_fileread(keyring, 0, fpubring)) {
(void) fprintf(stderr, "Can't read pub keyring %s\n", fpubring);
return 0;
}
netpgp->pubring = keyring;
netpgp->pubringfile = strdup(pubring);
if (secring == NULL) {
netpgp->pubringfile = strdup(fpubring);
if (fsecring == NULL) {
(void) snprintf(ringname, sizeof(ringname),
"%s/.gnupg/secring.gpg", homedir);
secring = ringname;
fsecring = ringname;
}
keyring = calloc(1, sizeof(*keyring));
if (!__ops_keyring_fileread(keyring, 0, secring)) {
(void) fprintf(stderr, "Cannot read sec keyring %s\n", secring);
if (!__ops_keyring_fileread(keyring, 0, fsecring)) {
(void) fprintf(stderr, "Can't read sec keyring %s\n", fsecring);
return 0;
}
netpgp->secring = keyring;
netpgp->secringfile = strdup(secring);
netpgp->secringfile = strdup(fsecring);
netpgp->userid = strdup(userid);
return 1;
}
@ -410,30 +320,28 @@ netpgp_generate_key(netpgp_t *netpgp, char *id, int numbits)
(void) memset(&uid, 0x0, sizeof(uid));
uid.userid = (unsigned char *) id;
keypair = __ops_rsa_new_selfsign_keypair(numbits,
(const unsigned long)65537, &uid);
keypair = __ops_rsa_new_selfsign_key(numbits, 65537UL, &uid);
if (keypair == NULL) {
(void) fprintf(stderr, "Cannot generate key\n");
return 0;
}
/* write public key */
fd = __ops_setup_file_append(&create, netpgp->pubringfile);
__ops_write_transferable_pubkey(create, keypair, 0);
__ops_write_xfer_pubkey(create, keypair, 0);
__ops_teardown_file_write(create, fd);
__ops_keyring_free(netpgp->pubring);
if (!__ops_keyring_fileread(netpgp->pubring, 0,
netpgp->pubringfile)) {
(void) fprintf(stderr, "Cannot re-read keyring %s\n",
if (!__ops_keyring_fileread(netpgp->pubring, 0, netpgp->pubringfile)) {
(void) fprintf(stderr, "Cannot read pubring %s\n",
netpgp->pubringfile);
return 0;
}
/* write secret key */
fd = __ops_setup_file_append(&create, netpgp->secringfile);
__ops_write_transferable_seckey(create, keypair, NULL, 0, 0);
__ops_write_xfer_seckey(create, keypair, NULL, 0, 0);
__ops_teardown_file_write(create, fd);
__ops_keyring_free(netpgp->secring);
if (!__ops_keyring_fileread(netpgp->secring, 0, netpgp->secringfile)) {
fprintf(stderr, "Cannot re-read keyring %s\n",
(void) fprintf(stderr, "Can't read secring %s\n",
netpgp->secringfile);
return 0;
}
@ -510,36 +418,35 @@ netpgp_sign_file(netpgp_t *netpgp, char *userid, char *f, char *out,
if (cleartext) {
__ops_sign_file_as_cleartext(f, out, seckey, hashalg, 1U);
} else if (detached) {
sign_detached(f, out, seckey, hashalg);
__ops_sign_detached(f, out, seckey, hashalg);
} else {
__ops_sign_file(f, out, seckey, hashalg, (unsigned)armored, 1);
}
(void) memset(passphrase, 0x0, sizeof(passphrase));
__ops_seckey_forget(seckey);
return 1;
}
/* verify a file */
int
netpgp_verify_file(netpgp_t *netpgp, char *infile, const char *outfile,
int armored)
netpgp_verify_file(netpgp_t *netpgp, char *in, const char *out, int armored)
{
__ops_validation_t result;
(void) memset(&result, 0x0, sizeof(result));
if (__ops_validate_file(&result, infile, outfile, armored,
netpgp->pubring)) {
psuccess(stderr, infile, &result, netpgp->pubring);
if (__ops_validate_file(&result, in, out, armored, netpgp->pubring)) {
psuccess(stderr, in, &result, netpgp->pubring);
return 1;
}
if (result.validc + result.invalidc + result.unknownc == 0) {
(void) fprintf(stderr,
"\"%s\": No signatures found - is this a signed file?\n",
infile);
return 0;
}
(void) fprintf(stderr,
in);
} else {
(void) fprintf(stderr,
"\"%s\": verification failure: %d invalid signatures, %d unknown signatures\n",
infile, result.invalidc, result.unknownc);
in, result.invalidc, result.unknownc);
}
return 0;
}

View File

@ -57,7 +57,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: openssl_crypto.c,v 1.10 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: openssl_crypto.c,v 1.11 2009/05/19 05:13:10 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_MD5_H
@ -506,13 +506,13 @@ __ops_hash_sha224(__ops_hash_t * hash)
unsigned
__ops_dsa_verify(const unsigned char *hash, size_t hash_length,
const __ops_dsa_sig_t * sig,
const __ops_dsa_pubkey_t * dsa)
const __ops_dsa_sig_t *sig,
const __ops_dsa_pubkey_t *dsa)
{
unsigned qlen;
DSA_SIG *osig;
DSA *odsa;
int ret;
unsigned int qlen;
osig = DSA_SIG_new();
osig->r = sig->r;
@ -533,8 +533,8 @@ __ops_dsa_verify(const unsigned char *hash, size_t hash_length,
}
(void) fprintf(stderr, "\n");
printf("hash_length=%" PRIsize "d\n", hash_length);
printf("Q=%u\n", BN_num_bytes(odsa->q));
}
/* printf("Q=%d\n", BN_num_bytes(odsa->q)); */
if ((qlen = BN_num_bytes(odsa->q)) < hash_length) {
hash_length = qlen;
}
@ -543,8 +543,7 @@ __ops_dsa_verify(const unsigned char *hash, size_t hash_length,
(void) fprintf(stderr, "ret=%d\n", ret);
}
if (ret < 0) {
(void) fprintf(stderr,
"__ops_do_verify: DSA_do_verify failed\n");
(void) fprintf(stderr, "__ops_dsa_verify: DSA verification\n");
return 0;
}
@ -563,19 +562,21 @@ __ops_dsa_verify(const unsigned char *hash, size_t hash_length,
\param out Where to write decrypted data to
\param in Encrypted data
\param length Length of encrypted data
\param rsa RSA public key
\param pubkey RSA public key
\return size of recovered message digest
*/
int
__ops_rsa_public_decrypt(unsigned char *out, const unsigned char *in,
size_t length, const __ops_rsa_pubkey_t * rsa)
__ops_rsa_public_decrypt(unsigned char *out,
const unsigned char *in,
size_t length,
const __ops_rsa_pubkey_t *pubkey)
{
RSA *orsa;
int n;
orsa = RSA_new();
orsa->n = rsa->n;
orsa->e = rsa->e;
orsa->n = pubkey->n;
orsa->e = pubkey->e;
n = RSA_public_decrypt((int)length, in, out, orsa, RSA_NO_PADDING);
@ -591,28 +592,28 @@ __ops_rsa_public_decrypt(unsigned char *out, const unsigned char *in,
\param out Where to write signature
\param in Data to sign
\param length Length of data
\param srsa RSA secret key
\param rsa RSA public key
\param seckey RSA secret key
\param pubkey RSA public key
\return number of bytes decrypted
*/
int
__ops_rsa_private_encrypt(unsigned char *out,
const unsigned char *in,
size_t length,
const __ops_rsa_seckey_t *srsa,
const __ops_rsa_pubkey_t *rsa)
const __ops_rsa_seckey_t *seckey,
const __ops_rsa_pubkey_t *pubkey)
{
RSA *orsa;
int n;
orsa = RSA_new();
orsa->n = rsa->n; /* XXX: do we need n? */
orsa->d = srsa->d;
orsa->p = srsa->q;
orsa->q = srsa->p;
orsa->n = pubkey->n; /* XXX: do we need n? */
orsa->d = seckey->d;
orsa->p = seckey->q;
orsa->q = seckey->p;
/* debug */
orsa->e = rsa->e;
orsa->e = pubkey->e;
/* If this isn't set, it's very likely that the programmer hasn't */
/* decrypted the secret key. RSA_check_key segfaults in that case. */
/* Use __ops_decrypt_seckey() to do that. */
@ -640,34 +641,36 @@ __ops_rsa_private_encrypt(unsigned char *out,
\param out Where to write the plaintext
\param in Encrypted data
\param length Length of encrypted data
\param srsa RSA secret key
\param rsa RSA public key
\param seckey RSA secret key
\param pubkey RSA public key
\return size of recovered plaintext
*/
int
__ops_rsa_private_decrypt(unsigned char *out, const unsigned char *in,
size_t length, const __ops_rsa_seckey_t * srsa,
const __ops_rsa_pubkey_t * rsa)
__ops_rsa_private_decrypt(unsigned char *out,
const unsigned char *in,
size_t length,
const __ops_rsa_seckey_t *seckey,
const __ops_rsa_pubkey_t *pubkey)
{
RSA *orsa;
RSA *keypair;
int n;
char errbuf[1024];
orsa = RSA_new();
orsa->n = rsa->n; /* XXX: do we need n? */
orsa->d = srsa->d;
orsa->p = srsa->q;
orsa->q = srsa->p;
keypair = RSA_new();
keypair->n = pubkey->n; /* XXX: do we need n? */
keypair->d = seckey->d;
keypair->p = seckey->q;
keypair->q = seckey->p;
/* debug */
orsa->e = rsa->e;
if (RSA_check_key(orsa) != 1) {
keypair->e = pubkey->e;
if (RSA_check_key(keypair) != 1) {
(void) fprintf(stderr, "RSA_check_key is not set\n");
return 0;
}
/* end debug */
n = RSA_private_decrypt((int)length, in, out, orsa, RSA_NO_PADDING);
n = RSA_private_decrypt((int)length, in, out, keypair, RSA_NO_PADDING);
if (__ops_get_debug_level(__FILE__)) {
printf("__ops_rsa_private_decrypt: n=%d\n",n);
@ -676,11 +679,12 @@ __ops_rsa_private_decrypt(unsigned char *out, const unsigned char *in,
errbuf[0] = '\0';
if (n == -1) {
unsigned long err = ERR_get_error();
ERR_error_string(err, &errbuf[0]);
fprintf(stderr, "openssl error : %s\n", errbuf);
(void) fprintf(stderr, "openssl error : %s\n", errbuf);
}
orsa->n = orsa->d = orsa->p = orsa->q = NULL;
RSA_free(orsa);
keypair->n = keypair->d = keypair->p = keypair->q = NULL;
RSA_free(keypair);
return n;
}
@ -691,13 +695,13 @@ __ops_rsa_private_decrypt(unsigned char *out, const unsigned char *in,
\param out Where to write the encrypted data
\param in Plaintext
\param length Size of plaintext
\param rsa RSA Public Key
\param pubkey RSA Public Key
*/
int
__ops_rsa_public_encrypt(unsigned char *out,
const unsigned char *in,
size_t length,
const __ops_rsa_pubkey_t *rsa)
const __ops_rsa_pubkey_t *pubkey)
{
RSA *orsa;
int n;
@ -705,8 +709,8 @@ __ops_rsa_public_encrypt(unsigned char *out,
/* printf("__ops_rsa_public_encrypt: length=%ld\n", length); */
orsa = RSA_new();
orsa->n = rsa->n;
orsa->e = rsa->e;
orsa->n = pubkey->n;
orsa->e = pubkey->e;
/* printf("len: %ld\n", length); */
/* __ops_print_bn("n: ", orsa->n); */
@ -732,7 +736,7 @@ __ops_rsa_public_encrypt(unsigned char *out,
\sa __ops_init()
*/
void
__ops_crypto_init()
__ops_crypto_init(void)
{
#ifdef DMALLOC
CRYPTO_malloc_debug_init();
@ -748,7 +752,7 @@ __ops_crypto_init()
\sa __ops_finish()
*/
void
__ops_crypto_finish()
__ops_crypto_finish(void)
{
CRYPTO_cleanup_all_ex_data();
ERR_remove_state((unsigned long)0);
@ -837,7 +841,7 @@ rsa_generate_keypair(__ops_keydata_t *keydata,
__ops_setup_memory_write(&output, &mem, 128);
__ops_push_skey_checksum_writer(output, seckey);
__ops_push_checksum_writer(output, seckey);
switch (seckey->pubkey.alg) {
/* case OPS_PKA_DSA: */
@ -889,7 +893,7 @@ rsa_generate_keypair(__ops_keydata_t *keydata,
\sa __ops_keydata_free()
*/
__ops_keydata_t *
__ops_rsa_new_selfsign_keypair(const int numbits,
__ops_rsa_new_selfsign_key(const int numbits,
const unsigned long e,
__ops_userid_t *userid)
{

View File

@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: packet-parse.c,v 1.12 2009/05/18 03:55:42 agc Exp $");
__RCSID("$NetBSD: packet-parse.c,v 1.13 2009/05/19 05:13:10 agc Exp $");
#endif
#ifdef HAVE_OPENSSL_CAST_H
@ -2240,7 +2240,7 @@ static void
parse_hash_init(__ops_parseinfo_t *pinfo, __ops_hash_alg_t type,
const unsigned char *keyid)
{
__ops_parse_hash_info_t *hash;
__ops_hashtype_t *hash;
pinfo->hashes = realloc(pinfo->hashes,
(pinfo->nhashes + 1) * sizeof(*pinfo->hashes));
@ -3348,12 +3348,6 @@ __ops_parse(__ops_parseinfo_t *pinfo, int perrors)
unsigned long pktlen;
int r;
if (pinfo->synthlit) {
#if 0
r = __ops_parse_packet(pinfo->synthsig, &pktlen);
r = __ops_parse_packet(pinfo->synthlit, &pktlen);
#endif
}
do {
r = __ops_parse_packet(pinfo, &pktlen);
} while (r != -1);

View File

@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: packet-print.c,v 1.10 2009/05/18 03:55:42 agc Exp $");
__RCSID("$NetBSD: packet-print.c,v 1.11 2009/05/19 05:13:10 agc Exp $");
#endif
#include <string.h>
@ -924,8 +924,7 @@ __ops_print_packet(const __ops_packet_t * pkt)
print_data("Key Server Preferences",
&content->ss_key_server_prefs.data);
text = __ops_showall_ss_key_server_prefs(
content->ss_key_server_prefs);
text = __ops_show_keyserv_prefs(content->ss_key_server_prefs);
print_text_breakdown(text);
__ops_text_free(text);
@ -951,8 +950,7 @@ __ops_print_packet(const __ops_packet_t * pkt)
indent++;
print_data("Flags", &content->ss_notation.flags);
text = __ops_showall_ss_notation_flags(
content->ss_notation);
text = __ops_showall_notation(content->ss_notation);
print_text_breakdown(text);
__ops_text_free(text);

View File

@ -60,7 +60,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: packet-show.c,v 1.6 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: packet-show.c,v 1.7 2009/05/19 05:13:10 agc Exp $");
#endif
#include <stdlib.h>
@ -377,33 +377,20 @@ add_str(__ops_list_t * list, const char *str)
return 1;
}
/* find a bitfield in a map - serial search */
static const char *
str_from_bitfield_or_null(unsigned char octet, __ops_bit_map_t *map)
find_bitfield(__ops_bit_map_t *map, unsigned char octet)
{
__ops_bit_map_t *row;
for (row = map; row->string != NULL; row++) {
if (row->mask == octet) {
return row->string;
}
for (row = map; row->string != NULL && row->mask != octet ; row++) {
}
return NULL;
}
static const char *
str_from_bitfield(unsigned char octet, __ops_bit_map_t *map)
{
const char *str;
if ((str = str_from_bitfield_or_null(octet, map)) != NULL) {
return str;
}
return "Unknown";
return (row->string) ? row->string : "Unknown";
}
/* ! generic function to initialise __ops_text_t structure */
void
__ops_text_init(__ops_text_t * text)
__ops_text_init(__ops_text_t *text)
{
list_init(&text->known);
list_init(&text->unknown);
@ -435,10 +422,9 @@ __ops_text_free(__ops_text_t * text)
/* XXX: should this (and many others) be unsigned? */
/* ! generic function which adds text derived from single octet map to text */
static unsigned
add_str_from_octet_map(__ops_text_t * text, char *str,
unsigned char octet)
add_str_from_octet_map(__ops_text_t *map, char *str, unsigned char octet)
{
if (str && !add_str(&text->known, str)) {
if (str && !add_str(&map->known, str)) {
/*
* value recognised, but there was a problem adding it to the
* list
@ -455,7 +441,7 @@ add_str_from_octet_map(__ops_text_t * text, char *str,
* format, 1 for NUL */
str = calloc(1, len);
(void) snprintf(str, len, "0x%x", octet);
if (!add_str(&text->unknown, str)) {
if (!add_str(&map->unknown, str)) {
return 0;
}
}
@ -464,11 +450,11 @@ add_str_from_octet_map(__ops_text_t * text, char *str,
/* ! generic function which adds text derived from single bit map to text */
static unsigned int
add_str_from_bit_map(__ops_text_t * text, const char *str, unsigned char bit)
add_bitmap_entry(__ops_text_t *map, const char *str, unsigned char bit)
{
const char *fmt_unknown = "Unknown bit(0x%x)";
if (str && !add_str(&text->known, str)) {
if (str && !add_str(&map->known, str)) {
/*
* value recognised, but there was a problem adding it to the
* list
@ -487,7 +473,7 @@ add_str_from_bit_map(__ops_text_t * text, const char *str, unsigned char bit)
str = calloc(1, len);
(void) snprintf(__UNCONST(str), len, fmt_unknown, bit);
if (!add_str(&text->unknown, str)) {
if (!add_str(&map->unknown, str)) {
return 0;
}
}
@ -576,8 +562,8 @@ showall_octets_bits(__ops_data_t * data, __ops_bit_map_t ** map,
bit = data->contents[i] & mask;
if (bit) {
str = (i >= nmap) ? "Unknown" :
str_from_bitfield(bit, map[i]);
if (!add_str_from_bit_map(text, str, bit)) {
find_bitfield(map[i], bit);
if (!add_bitmap_entry(text, str, bit)) {
__ops_text_free(text);
return NULL;
}
@ -763,7 +749,7 @@ __ops_show_ss_feature(unsigned char octet, unsigned offset)
if (offset >= OPS_ARRAY_SIZE(ss_feature_map)) {
return "Unknown";
}
return str_from_bitfield(octet, ss_feature_map[offset]);
return find_bitfield(ss_feature_map[offset], octet);
}
/**
@ -797,7 +783,7 @@ __ops_showall_ss_features(__ops_ss_features_t ss_features)
bit = ss_features.data.contents[i] & mask;
if (bit) {
str = __ops_show_ss_feature(bit, i);
if (!add_str_from_bit_map(text, str, bit)) {
if (!add_bitmap_entry(text, str, bit)) {
__ops_text_free(text);
return NULL;
}
@ -817,7 +803,7 @@ __ops_showall_ss_features(__ops_ss_features_t ss_features)
const char *
__ops_show_ss_key_flag(unsigned char octet, __ops_bit_map_t * map)
{
return str_from_bitfield(octet, map);
return find_bitfield(map, octet);
}
/**
@ -848,7 +834,7 @@ __ops_showall_ss_key_flags(__ops_ss_key_flags_t ss_key_flags)
bit = ss_key_flags.data.contents[0] & mask;
if (bit) {
str = __ops_show_ss_key_flag(bit, &ss_key_flags_map[0]);
if (!add_str_from_bit_map(text, strdup(str), bit)) {
if (!add_bitmap_entry(text, strdup(str), bit)) {
__ops_text_free(text);
return NULL;
}
@ -871,9 +857,9 @@ __ops_showall_ss_key_flags(__ops_ss_key_flags_t ss_key_flags)
* \return string or "Unknown"
*/
const char *
__ops_show_ss_key_server_prefs(unsigned char prefs, __ops_bit_map_t * map)
__ops_show_keyserv_pref(unsigned char prefs, __ops_bit_map_t * map)
{
return str_from_bitfield(prefs, map);
return find_bitfield(map, prefs);
}
/**
@ -885,8 +871,7 @@ __ops_show_ss_key_server_prefs(unsigned char prefs, __ops_bit_map_t * map)
*
*/
__ops_text_t *
__ops_showall_ss_key_server_prefs(
__ops_ss_key_server_prefs_t ss_key_server_prefs)
__ops_show_keyserv_prefs(__ops_ss_key_server_prefs_t prefs)
{
unsigned char mask, bit;
__ops_text_t *text = NULL;
@ -903,11 +888,11 @@ __ops_showall_ss_key_server_prefs(
/* xxx - TBD: extend to handle multiple octets of bits - rachel */
for (i = 0, mask = 0x80; i < 8; i++, mask = (unsigned)mask >> 1) {
bit = ss_key_server_prefs.data.contents[0] & mask;
bit = prefs.data.contents[0] & mask;
if (bit) {
str = __ops_show_ss_key_server_prefs(bit,
&ss_key_server_prefs_map[0]);
if (!add_str_from_bit_map(text, strdup(str), bit)) {
str = __ops_show_keyserv_pref(bit,
ss_key_server_prefs_map);
if (!add_bitmap_entry(text, strdup(str), bit)) {
__ops_text_free(text);
return NULL;
}
@ -929,7 +914,7 @@ __ops_showall_ss_key_server_prefs(
* \return pointer to structure, if no error
*/
__ops_text_t *
__ops_showall_ss_notation_flags(__ops_ss_notation_t ss_notation)
__ops_showall_notation(__ops_ss_notation_t ss_notation)
{
return showall_octets_bits(&ss_notation.flags,
ss_notation_map,

View File

@ -103,9 +103,9 @@ __ops_text_t *__ops_showall_ss_features(__ops_ss_features_t);
__ops_text_t *__ops_showall_ss_key_flags(__ops_ss_key_flags_t);
const char *__ops_show_ss_key_flag(unsigned char, __ops_bit_map_t *);
__ops_text_t *__ops_showall_ss_key_server_prefs(__ops_ss_key_server_prefs_t);
const char *__ops_show_ss_key_server_prefs(unsigned char, __ops_bit_map_t *);
__ops_text_t *__ops_show_keyserv_prefs(__ops_ss_key_server_prefs_t);
const char *__ops_show_keyserv_pref(unsigned char, __ops_bit_map_t *);
__ops_text_t *__ops_showall_ss_notation_flags(__ops_ss_notation_t);
__ops_text_t *__ops_showall_notation(__ops_ss_notation_t);
#endif /* PACKET_SHOW_H_ */

View File

@ -67,6 +67,7 @@
typedef struct {
size_t len;
unsigned char *contents;
uint8_t mmapped; /* contents need an munmap(2) */
} __ops_data_t;
/************************************/
@ -1107,4 +1108,6 @@ struct __ops_keydata {
__ops_keydata_key_t key;
};
#define MDC_PKT_TAG 0xd3
#endif /* PACKET_H_ */

View File

@ -75,12 +75,12 @@ unsigned __ops_write_se_ip_pktset(const unsigned char *,
const unsigned int,
__ops_crypt_t *,
__ops_output_t *);
void __ops_writer_push_encrypt_crypt(__ops_output_t *, __ops_crypt_t *);
void __ops_writer_push_encrypt_se_ip(__ops_output_t *,
void __ops_push_enc_crypt(__ops_output_t *, __ops_crypt_t *);
void __ops_push_enc_se_ip(__ops_output_t *,
const __ops_keydata_t *);
/* Secret Key checksum */
void __ops_push_skey_checksum_writer(__ops_output_t *, __ops_seckey_t *);
void __ops_push_checksum_writer(__ops_output_t *, __ops_seckey_t *);
unsigned __ops_pop_skey_checksum_writer(__ops_output_t *);

View File

@ -57,9 +57,12 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: signature.c,v 1.12 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: signature.c,v 1.13 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
@ -723,7 +726,7 @@ __ops_sig_add_data(__ops_create_sig_t *sig, const void *buf, size_t length)
*/
unsigned
__ops_sig_hashed_subpackets_end(__ops_create_sig_t * sig)
__ops_end_hashed_subpkts(__ops_create_sig_t * sig)
{
sig->hashlen = __ops_mem_len(sig->mem)
- sig->hashoff - 2;
@ -851,13 +854,13 @@ __ops_write_sig(__ops_output_t *output,
/**
* \ingroup Core_Signature
*
* __ops_sig_add_birthtime() adds a creation time to the signature.
* __ops_add_birthtime() adds a creation time to the signature.
*
* \param sig
* \param when
*/
unsigned
__ops_sig_add_birthtime(__ops_create_sig_t * sig, time_t when)
__ops_add_birthtime(__ops_create_sig_t * sig, time_t when)
{
return __ops_write_ss_header(sig->output, 5, OPS_PTAG_SS_CREATION_TIME) &&
__ops_write_scalar(sig->output, (unsigned)when, 4);
@ -873,7 +876,7 @@ __ops_sig_add_birthtime(__ops_create_sig_t * sig, time_t when)
*/
unsigned
__ops_sig_add_issuer_key_id(__ops_create_sig_t * sig,
__ops_add_issuer_keyid(__ops_create_sig_t * sig,
const unsigned char keyid[OPS_KEY_ID_SIZE])
{
return __ops_write_ss_header(sig->output, OPS_KEY_ID_SIZE + 1,
@ -890,8 +893,7 @@ __ops_sig_add_issuer_key_id(__ops_create_sig_t * sig,
* \param primary
*/
void
__ops_sig_add_primary_userid(__ops_create_sig_t * sig,
unsigned primary)
__ops_add_primary_userid(__ops_create_sig_t * sig, unsigned primary)
{
__ops_write_ss_header(sig->output, 2, OPS_PTAG_SS_PRIMARY_USER_ID);
__ops_write_scalar(sig->output, primary, 1);
@ -958,11 +960,10 @@ __ops_sign_file_as_cleartext(const char *inname,
__ops_hash_alg_t hash_alg;
__ops_output_t *output = NULL;
unsigned char keyid[OPS_KEY_ID_SIZE];
unsigned char buf[MAXBUF];
unsigned ret = 0;
unsigned armored = 1;
int fd_out = 0;
int fd_in = 0;
__ops_memory_t *mem;
/* check the hash algorithm */
hash_alg = __ops_str_to_hash_alg(hashname);
@ -973,27 +974,23 @@ __ops_sign_file_as_cleartext(const char *inname,
return 0;
}
/* open file to sign */
#ifdef O_BINARY
fd_in = open(inname, O_RDONLY | O_BINARY);
#else
fd_in = open(inname, O_RDONLY);
#endif
if (fd_in < 0) {
/* read the file to be signed */
mem = __ops_memory_new();
if (!__ops_mem_readfile(mem, inname)) {
return 0;
}
/* set up output file */
fd_out = open_output_file(&output, inname, outname, armored, overwrite);
if (fd_out < 0) {
close(fd_in);
__ops_memory_free(mem);
return 0;
}
/* set up signature */
sig = __ops_create_sig_new();
if (!sig) {
close(fd_in);
__ops_memory_free(mem);
__ops_teardown_file_write(output, fd_out);
return 0;
}
@ -1005,35 +1002,22 @@ __ops_sign_file_as_cleartext(const char *inname,
}
/* Do the signing */
for (;;) {
int n = 0;
n = read(fd_in, buf, sizeof(buf));
if (n == 0) {
break;
}
if (n < 0) {
(void) fprintf(stderr,
"__ops_sign_file_as_cleartext: bad read\n");
return 0;
}
__ops_write(output, buf, (unsigned)n);
}
close(fd_in);
__ops_write(output, __ops_mem_data(mem), __ops_mem_len(mem));
__ops_memory_free(mem);
/* add signature with subpackets: */
/* - creation time */
/* - key id */
ret = __ops_writer_use_armored_sig(output) &&
__ops_sig_add_birthtime(sig, time(NULL));
__ops_add_birthtime(sig, time(NULL));
if (ret == 0) {
__ops_teardown_file_write(output, fd_out);
return 0;
}
__ops_keyid(keyid, OPS_KEY_ID_SIZE, OPS_KEY_ID_SIZE, &seckey->pubkey);
ret = __ops_sig_add_issuer_key_id(sig, keyid) &&
__ops_sig_hashed_subpackets_end(sig) &&
ret = __ops_add_issuer_keyid(sig, keyid) &&
__ops_end_hashed_subpkts(sig) &&
__ops_write_sig(output, sig, &seckey->pubkey, seckey);
__ops_teardown_file_write(output, fd_out);
@ -1106,15 +1090,15 @@ __ops_sign_buf_as_cleartext(const char *cleartext,
ret = __ops_writer_push_clearsigned(output, sig) &&
__ops_write(output, cleartext, len) &&
__ops_writer_use_armored_sig(output) &&
__ops_sig_add_birthtime(sig, time(NULL));
__ops_add_birthtime(sig, time(NULL));
if (ret == 0) {
return 0;
}
__ops_keyid(keyid, OPS_KEY_ID_SIZE, OPS_KEY_ID_SIZE, &seckey->pubkey);
ret = __ops_sig_add_issuer_key_id(sig, keyid) &&
__ops_sig_hashed_subpackets_end(sig) &&
ret = __ops_add_issuer_keyid(sig, keyid) &&
__ops_end_hashed_subpkts(sig) &&
__ops_write_sig(output, sig, &seckey->pubkey, seckey) &&
__ops_writer_close(output);
@ -1149,12 +1133,11 @@ __ops_sign_file(const char *inname,
__ops_create_sig_t *sig = NULL;
__ops_hash_alg_t hash_alg;
__ops_sig_type_t sig_type = OPS_SIG_BINARY;
__ops_memory_t *mem_buf = NULL;
__ops_memory_t *infile = NULL;
__ops_output_t *output = NULL;
unsigned char keyid[OPS_KEY_ID_SIZE];
__ops_hash_t *hash = NULL;
int errnum;
int fd_out = 0;
int fd = 0;
hash_alg = __ops_str_to_hash_alg(hashname);
if (hash_alg == OPS_HASH_UNKNOWN) {
@ -1165,15 +1148,15 @@ __ops_sign_file(const char *inname,
}
/* read input file into buf */
mem_buf = __ops_fileread(inname, &errnum);
if (errnum) {
infile = __ops_memory_new();
if (!__ops_mem_readfile(infile, inname)) {
return 0;
}
/* setup output file */
fd_out = open_output_file(&output, inname, outname, armored, overwrite);
if (fd_out < 0) {
__ops_memory_free(mem_buf);
fd = open_output_file(&output, inname, outname, armored, overwrite);
if (fd < 0) {
__ops_memory_free(infile);
return 0;
}
@ -1191,14 +1174,14 @@ __ops_sign_file(const char *inname,
/* hash file contents */
hash = __ops_sig_get_hash(sig);
hash->add(hash, __ops_mem_data(mem_buf), __ops_mem_len(mem_buf));
hash->add(hash, __ops_mem_data(infile), __ops_mem_len(infile));
/* output file contents as Literal Data packet */
if (__ops_get_debug_level(__FILE__)) {
fprintf(stderr, "** Writing out data now\n");
}
__ops_write_litdata(output, __ops_mem_data(mem_buf),
(const int)__ops_mem_len(mem_buf),
__ops_write_litdata(output, __ops_mem_data(infile),
(const int)__ops_mem_len(infile),
OPS_LDT_BINARY);
if (__ops_get_debug_level(__FILE__)) {
@ -1206,19 +1189,19 @@ __ops_sign_file(const char *inname,
}
/* add creation time to signature */
__ops_sig_add_birthtime(sig, time(NULL));
__ops_add_birthtime(sig, time(NULL));
/* add key id to signature */
__ops_keyid(keyid, OPS_KEY_ID_SIZE, OPS_KEY_ID_SIZE, &seckey->pubkey);
__ops_sig_add_issuer_key_id(sig, keyid);
__ops_sig_hashed_subpackets_end(sig);
__ops_add_issuer_keyid(sig, keyid);
__ops_end_hashed_subpkts(sig);
/* write out sig */
__ops_write_sig(output, sig, &seckey->pubkey, seckey);
/* tidy up */
__ops_teardown_file_write(output, fd_out);
__ops_teardown_file_write(output, fd);
__ops_create_sig_delete(sig);
__ops_memory_free(mem_buf);
__ops_memory_free(infile);
return 1;
}
@ -1287,11 +1270,11 @@ __ops_sign_buf(const void *input,
}
/* add creation time to signature */
__ops_sig_add_birthtime(sig, time(NULL));
__ops_add_birthtime(sig, time(NULL));
/* add key id to signature */
__ops_keyid(keyid, OPS_KEY_ID_SIZE, OPS_KEY_ID_SIZE, &seckey->pubkey);
__ops_sig_add_issuer_key_id(sig, keyid);
__ops_sig_hashed_subpackets_end(sig);
__ops_add_issuer_keyid(sig, keyid);
__ops_end_hashed_subpkts(sig);
/* write out sig */
__ops_write_sig(output, sig, &seckey->pubkey, seckey);
@ -1302,3 +1285,66 @@ __ops_sign_buf(const void *input,
return mem;
}
/* sign a file, and put the signature in a separate file */
int
__ops_sign_detached(char *f,
char *sigfile,
__ops_seckey_t *seckey,
const char *hash)
{
__ops_create_sig_t *sig;
__ops_hash_alg_t alg;
__ops_output_t *output;
__ops_memory_t *mem;
unsigned char keyid[OPS_KEY_ID_SIZE];
time_t t;
char fname[MAXPATHLEN];
int fd;
/* find out which hash algorithm to use */
alg = __ops_str_to_hash_alg(hash);
if (alg == OPS_HASH_UNKNOWN) {
(void) fprintf(stderr,"Unknown hash algorithm: %s\n", hash);
return 0;
}
/* create a new signature */
sig = __ops_create_sig_new();
__ops_start_sig(sig, seckey, alg, OPS_SIG_BINARY);
/* read the contents of 'f', and add that to the signature */
mem = __ops_memory_new();
if (!__ops_mem_readfile(mem, f)) {
return 0;
}
__ops_sig_add_data(sig, __ops_mem_data(mem), __ops_mem_len(mem));
__ops_memory_free(mem);
/* calculate the signature */
t = time(NULL);
__ops_add_birthtime(sig, t);
__ops_keyid(keyid, sizeof(keyid), sizeof(keyid), &seckey->pubkey);
__ops_add_issuer_keyid(sig, keyid);
__ops_end_hashed_subpkts(sig);
/* write the signature to the detached file */
if (sigfile == NULL) {
(void) snprintf(fname, sizeof(fname), "%s.sig", f);
sigfile = fname;
}
fd = open(sigfile, O_CREAT|O_TRUNC|O_WRONLY, 0666);
if (fd < 0) {
(void) fprintf(stderr, "can't write signature to \"%s\"\n",
sigfile);
return 0;
}
output = __ops_output_new();
__ops_writer_set_fd(output, fd);
__ops_write_sig(output, sig, &seckey->pubkey, seckey);
__ops_seckey_free(seckey);
(void) close(fd);
return 1;
}

View File

@ -95,13 +95,13 @@ void __ops_start_sig(__ops_create_sig_t *,
void __ops_sig_add_data(__ops_create_sig_t *, const void *, size_t);
__ops_hash_t *__ops_sig_get_hash(__ops_create_sig_t *);
unsigned __ops_sig_hashed_subpackets_end(__ops_create_sig_t *);
unsigned __ops_end_hashed_subpkts(__ops_create_sig_t *);
unsigned __ops_write_sig(__ops_output_t *, __ops_create_sig_t *,
const __ops_pubkey_t *, const __ops_seckey_t *);
unsigned __ops_sig_add_birthtime(__ops_create_sig_t *, time_t);
unsigned __ops_sig_add_issuer_key_id(__ops_create_sig_t *,
unsigned __ops_add_birthtime(__ops_create_sig_t *, time_t);
unsigned __ops_add_issuer_keyid(__ops_create_sig_t *,
const unsigned char *);
void __ops_sig_add_primary_userid(__ops_create_sig_t *, unsigned);
void __ops_add_primary_userid(__ops_create_sig_t *, unsigned);
/* Standard Interface */
unsigned __ops_sign_file_as_cleartext(const char *,
@ -116,6 +116,8 @@ unsigned __ops_sign_file(const char *,
const unsigned,
const unsigned);
int __ops_sign_detached(char *, char *, __ops_seckey_t *, const char *);
/* armoured stuff */
unsigned __ops_crc24(unsigned, unsigned char);

View File

@ -54,7 +54,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: validate.c,v 1.11 2009/05/18 03:55:42 agc Exp $");
__RCSID("$NetBSD: validate.c,v 1.12 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
@ -360,32 +360,6 @@ __ops_validate_key_cb(const __ops_packet_t *pkt, __ops_callback_data_t *cbinfo)
return OPS_RELEASE_MEMORY;
}
static unsigned char *
readfile(const char *f, size_t *len)
{
unsigned char *buf;
struct stat st;
FILE *fp;
int cc;
int n;
if ((fp = fopen(f, "r")) == NULL) {
(void) fprintf(stderr,
"readfile: can't open \"%s\" for reading\n", f);
return NULL;
}
(void) fstat(fileno(fp), &st);
*len = (size_t)st.st_size;
if ((buf = calloc(1, *len)) != NULL) {
for (n = 0 ;
(cc = read(fileno(fp), &buf[n], *len - n)) > 0 ;
n += cc) {
}
}
(void) fclose(fp);
return buf;
}
__ops_parse_cb_return_t
validate_data_cb(const __ops_packet_t *pkt, __ops_callback_data_t *cbinfo)
{
@ -467,20 +441,11 @@ validate_data_cb(const __ops_packet_t *pkt, __ops_callback_data_t *cbinfo)
data->detachname) {
/* check we have seen some data */
/* if not, need to read from detached name */
unsigned char *detached;
size_t len = 0;
printf(
"netpgp: assuming signed data in \"%s\"\n",
data->detachname);
detached = readfile(data->detachname, &len);
if (detached != NULL) {
data->mem = __ops_memory_new();
__ops_memory_init(data->mem, len);
__ops_memory_add(data->mem, detached,
len);
(void) free(detached);
}
data->mem = __ops_memory_new();
__ops_mem_readfile(data->mem, data->detachname);
}
valid = check_binary_sig(__ops_mem_len(data->mem),
__ops_mem_data(data->mem),

View File

@ -58,7 +58,7 @@
#endif
/* development versions have .99 suffix */
#define NETPGP_BASE_VERSION "1.0.0"
#define NETPGP_BASE_VERSION "1.99.1"
#define NETPGP_VERSION_CAT(a, b) "NetPGP portable " a "/[" b "]"
#define NETPGP_VERSION_STRING \

View File

@ -58,7 +58,7 @@
#if defined(__NetBSD__)
__COPYRIGHT("@(#) Copyright (c) 2009 The NetBSD Foundation, Inc. All rights reserved.");
__RCSID("$NetBSD: writer.c,v 1.8 2009/05/16 06:30:38 agc Exp $");
__RCSID("$NetBSD: writer.c,v 1.9 2009/05/19 05:13:10 agc Exp $");
#endif
#include <sys/types.h>
@ -88,7 +88,6 @@ __RCSID("$NetBSD: writer.c,v 1.8 2009/05/16 06:30:38 agc Exp $");
#include "signature.h"
#include "packet.h"
#include "packet-parse.h"
#include "readerwriter.h"
#include "memory.h"
#include "netpgpdefs.h"
@ -99,41 +98,41 @@ __RCSID("$NetBSD: writer.c,v 1.8 2009/05/16 06:30:38 agc Exp $");
* return 1 if OK, otherwise 0
*/
static unsigned
base_write(const void *src, unsigned length, __ops_output_t *out)
base_write(const void *src, unsigned len, __ops_output_t *out)
{
return out->writer.writer(src, length, &out->errors, &out->writer);
return out->writer.writer(src, len, &out->errors, &out->writer);
}
/**
* \ingroup Core_WritePackets
*
* \param src
* \param length
* \param len
* \param output
* \return 1 if OK, otherwise 0
*/
unsigned
__ops_write(__ops_output_t *output, const void *src, unsigned length)
__ops_write(__ops_output_t *output, const void *src, unsigned len)
{
return base_write(src, length, output);
return base_write(src, len, output);
}
/**
* \ingroup Core_WritePackets
* \param n
* \param length
* \param len
* \param output
* \return 1 if OK, otherwise 0
*/
unsigned
__ops_write_scalar(__ops_output_t *output, unsigned n, unsigned length)
__ops_write_scalar(__ops_output_t *output, unsigned n, unsigned len)
{
unsigned char c;
while (length-- > 0) {
c = n >> (length * 8);
while (len-- > 0) {
c = n >> (len * 8);
if (!base_write(&c, 1, output)) {
return 0;
}
@ -181,27 +180,27 @@ __ops_write_ptag(__ops_output_t *output, __ops_content_tag_t tag)
/**
* \ingroup Core_WritePackets
* \param length
* \param len
* \param output
* \return 1 if OK, otherwise 0
*/
unsigned
__ops_write_length(__ops_output_t *output, unsigned length)
__ops_write_length(__ops_output_t *output, unsigned len)
{
unsigned char c[2];
if (length < 192) {
c[0] = length;
if (len < 192) {
c[0] = len;
return base_write(c, 1, output);
}
if (length < 8192 + 192) {
c[0] = ((length - 192) >> 8) + 192;
c[1] = (length - 192) % 256;
if (len < 8192 + 192) {
c[0] = ((len - 192) >> 8) + 192;
c[1] = (len - 192) % 256;
return base_write(c, 2, output);
}
return __ops_write_scalar(output, 0xff, 1) &&
__ops_write_scalar(output, length, 4);
__ops_write_scalar(output, len, 4);
}
/*
@ -363,16 +362,16 @@ __ops_writer_get_arg(__ops_writer_t *writer)
* Write to the next writer down in the stack.
*
* \param src The data to write.
* \param length The length of src.
* \param len The length of src.
* \param errors A place to store errors.
* \param writer The writer_info structure.
* \return Success - if 0, then errors should contain the error.
*/
unsigned
__ops_stacked_write(const void *src, unsigned length,
__ops_stacked_write(const void *src, unsigned len,
__ops_error_t ** errors, __ops_writer_t *writer)
{
return writer->next->writer(src, length, errors, writer->next);
return writer->next->writer(src, len, errors, writer->next);
}
/**
@ -383,8 +382,8 @@ __ops_stacked_write(const void *src, unsigned length,
*
* \param writer the info structure.
*/
void
__ops_writer_generic_destroyer(__ops_writer_t *writer)
static void
generic_destroyer(__ops_writer_t *writer)
{
(void) free(__ops_writer_get_arg(writer));
}
@ -397,50 +396,50 @@ __ops_writer_generic_destroyer(__ops_writer_t *writer)
*/
unsigned
__ops_writer_passthrough(const unsigned char *src,
unsigned length,
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
return __ops_stacked_write(src, length, errors, writer);
return __ops_stacked_write(src, len, errors, writer);
}
/**************************************************************************/
/**
* \struct dash_escaped_t
* \struct dashesc_t
*/
typedef struct {
unsigned seen_nl:1;
unsigned seen_cr:1;
__ops_create_sig_t *sig;
__ops_memory_t *trailing;
} dash_escaped_t;
} dashesc_t;
static unsigned
dash_escaped_writer(const unsigned char *src,
unsigned length,
dash_esc_writer(const unsigned char *src,
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
dash_escaped_t *dash = __ops_writer_get_arg(writer);
dashesc_t *dash = __ops_writer_get_arg(writer);
unsigned n;
if (__ops_get_debug_level(__FILE__)) {
unsigned int i = 0;
fprintf(stderr, "dash_escaped_writer writing %d:\n", length);
for (i = 0; i < length; i++) {
(void) fprintf(stderr, "dash_esc_writer writing %d:\n", len);
for (i = 0; i < len; i++) {
fprintf(stderr, "0x%02x ", src[i]);
if (!((i + 1) % 16)) {
fprintf(stderr, "\n");
} else if (!((i + 1) % 8)) {
fprintf(stderr, " ");
if (((i + 1) % 16) == 0) {
(void) fprintf(stderr, "\n");
} else if (((i + 1) % 8) == 0) {
(void) fprintf(stderr, " ");
}
}
fprintf(stderr, "\n");
(void) fprintf(stderr, "\n");
}
/* XXX: make this efficient */
for (n = 0; n < length; ++n) {
for (n = 0; n < len; ++n) {
unsigned l;
if (dash->seen_nl) {
@ -487,7 +486,7 @@ dash_escaped_writer(const unsigned char *src,
static void
dash_escaped_destroyer(__ops_writer_t * writer)
{
dash_escaped_t *dash;
dashesc_t *dash;
dash = __ops_writer_get_arg(writer);
__ops_memory_free(dash->trailing);
@ -507,7 +506,7 @@ __ops_writer_push_clearsigned(__ops_output_t * output,
static const char header[] =
"-----BEGIN PGP SIGNED MESSAGE-----\r\nHash: ";
const char *hash = __ops_text_from_hash(__ops_sig_get_hash(sig));
dash_escaped_t *dash = calloc(1, sizeof(*dash));
dashesc_t *dash = calloc(1, sizeof(*dash));
unsigned ret;
ret = (__ops_write(output, header, sizeof(header) - 1) &&
@ -523,7 +522,7 @@ __ops_writer_push_clearsigned(__ops_output_t * output,
dash->seen_nl = 1;
dash->sig = sig;
dash->trailing = __ops_memory_new();
__ops_writer_push(output, dash_escaped_writer, NULL,
__ops_writer_push(output, dash_esc_writer, NULL,
dash_escaped_destroyer, dash);
return ret;
}
@ -536,20 +535,21 @@ typedef struct {
unsigned pos;
unsigned char t;
unsigned checksum;
} base64_t;
} base64_t;
static const char b64map[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static unsigned
base64_writer(const unsigned char *src,
unsigned length, __ops_error_t ** errors,
__ops_writer_t * writer)
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
base64_t *base64 = __ops_writer_get_arg(writer);
unsigned n;
base64_t *base64 = __ops_writer_get_arg(writer);
unsigned n;
for (n = 0; n < length;) {
for (n = 0; n < len;) {
base64->checksum = __ops_crc24(base64->checksum, src[n]);
if (base64->pos == 0) {
/* XXXXXX00 00000000 00000000 */
@ -594,12 +594,11 @@ base64_writer(const unsigned char *src,
}
static unsigned
sig_finaliser(__ops_error_t ** errors,
__ops_writer_t * writer)
sig_finaliser(__ops_error_t **errors, __ops_writer_t *writer)
{
base64_t *base64 = __ops_writer_get_arg(writer);
static const char trailer[] = "\r\n-----END PGP SIGNATURE-----\r\n";
unsigned char c[3];
static const char trail[] = "\r\n-----END PGP SIGNATURE-----\r\n";
unsigned char c[3];
base64_t *base64 = __ops_writer_get_arg(writer);
if (base64->pos) {
if (!__ops_stacked_write(&b64map[base64->t], 1, errors,
@ -630,7 +629,7 @@ sig_finaliser(__ops_error_t ** errors,
return 0;
}
return __ops_stacked_write(trailer, sizeof(trailer) - 1, errors, writer);
return __ops_stacked_write(trail, sizeof(trail) - 1, errors, writer);
}
/**
@ -644,14 +643,14 @@ typedef struct {
static unsigned
linebreak_writer(const unsigned char *src,
unsigned length,
unsigned len,
__ops_error_t ** errors,
__ops_writer_t * writer)
{
linebreak_t *linebreak = __ops_writer_get_arg(writer);
unsigned n;
for (n = 0; n < length; ++n, ++linebreak->pos) {
for (n = 0; n < len; ++n, ++linebreak->pos) {
if (src[n] == '\r' || src[n] == '\n') {
linebreak->pos = 0;
}
@ -691,7 +690,7 @@ __ops_writer_use_armored_sig(__ops_output_t * output)
return 0;
}
__ops_writer_push(output, linebreak_writer, NULL,
__ops_writer_generic_destroyer,
generic_destroyer,
calloc(1, sizeof(linebreak_t)));
base64 = calloc(1, sizeof(*base64));
if (!base64) {
@ -700,13 +699,12 @@ __ops_writer_use_armored_sig(__ops_output_t * output)
}
base64->checksum = CRC24_INIT;
__ops_writer_push(output, base64_writer, sig_finaliser,
__ops_writer_generic_destroyer, base64);
generic_destroyer, base64);
return 1;
}
static unsigned
armoured_message_finaliser(__ops_error_t ** errors,
__ops_writer_t * writer)
armoured_message_finaliser(__ops_error_t **errors, __ops_writer_t *writer)
{
/* TODO: This is same as sig_finaliser apart from trailer. */
base64_t *base64 = __ops_writer_get_arg(writer);
@ -761,12 +759,13 @@ __ops_writer_push_armor_msg(__ops_output_t * output)
base64 = calloc(1, sizeof(*base64));
base64->checksum = CRC24_INIT;
__ops_writer_push(output, base64_writer, armoured_message_finaliser,
__ops_writer_generic_destroyer, base64);
generic_destroyer, base64);
}
static unsigned
armoured_finaliser(__ops_armor_type_t type, __ops_error_t ** errors,
__ops_writer_t * writer)
armoured_finaliser(__ops_armor_type_t type,
__ops_error_t **errors,
__ops_writer_t *writer)
{
static const char tail_pubkey[] =
"\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n";
@ -828,15 +827,13 @@ armoured_finaliser(__ops_armor_type_t type, __ops_error_t ** errors,
}
static unsigned
armoured_pubkey_finaliser(__ops_error_t ** errors,
__ops_writer_t * writer)
armored_pubkey_fini(__ops_error_t **errors, __ops_writer_t *writer)
{
return armoured_finaliser(OPS_PGP_PUBLIC_KEY_BLOCK, errors, writer);
}
static unsigned
armoured_private_key_finaliser(__ops_error_t ** errors,
__ops_writer_t * writer)
armored_privkey_fini(__ops_error_t **errors, __ops_writer_t *writer)
{
return armoured_finaliser(OPS_PGP_PRIVATE_KEY_BLOCK, errors, writer);
}
@ -847,7 +844,7 @@ armoured_private_key_finaliser(__ops_error_t ** errors,
\brief Push Armoured Writer on stack (generic)
*/
void
__ops_writer_push_armoured(__ops_output_t * output, __ops_armor_type_t type)
__ops_writer_push_armoured(__ops_output_t *output, __ops_armor_type_t type)
{
static char hdr_pubkey[] =
"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVersion: "
@ -867,13 +864,13 @@ __ops_writer_push_armoured(__ops_output_t * output, __ops_armor_type_t type)
case OPS_PGP_PUBLIC_KEY_BLOCK:
header = hdr_pubkey;
sz_hdr = sizeof(hdr_pubkey) - 1;
finaliser = armoured_pubkey_finaliser;
finaliser = armored_pubkey_fini;
break;
case OPS_PGP_PRIVATE_KEY_BLOCK:
header = hdr_private_key;
sz_hdr = sizeof(hdr_private_key) - 1;
finaliser = armoured_private_key_finaliser;
finaliser = armored_privkey_fini;
break;
default:
@ -885,13 +882,13 @@ __ops_writer_push_armoured(__ops_output_t * output, __ops_armor_type_t type)
__ops_write(output, header, sz_hdr);
__ops_writer_push(output, linebreak_writer, NULL,
__ops_writer_generic_destroyer,
generic_destroyer,
calloc(1, sizeof(linebreak_t)));
base64 = calloc(1, sizeof(*base64));
base64->checksum = CRC24_INIT;
__ops_writer_push(output, base64_writer, finaliser,
__ops_writer_generic_destroyer, base64);
generic_destroyer, base64);
}
/**************************************************************************/
@ -899,7 +896,7 @@ __ops_writer_push_armoured(__ops_output_t * output, __ops_armor_type_t type)
typedef struct {
__ops_crypt_t *crypt;
int free_crypt;
} crypt_t;
} crypt_t;
/*
* This writer simply takes plaintext as input,
@ -908,53 +905,53 @@ typedef struct {
*/
static unsigned
encrypt_writer(const unsigned char *src,
unsigned length,
__ops_error_t ** errors,
__ops_writer_t * writer)
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
#define BUFSZ 1024 /* arbitrary number */
unsigned char encbuf[BUFSZ];
unsigned remaining = length;
unsigned remaining;
unsigned done = 0;
crypt_t *pgp_encrypt;
crypt_t *pgp_encrypt = (crypt_t *) __ops_writer_get_arg(writer);
remaining = len;
pgp_encrypt = (crypt_t *) __ops_writer_get_arg(writer);
if (!__ops_is_sa_supported(pgp_encrypt->crypt->alg)) {
(void) fprintf(stderr, "encrypt_writer: not supported\n");
return 0;
}
while (remaining) {
unsigned len = remaining < BUFSZ ? remaining : BUFSZ;
/* memcpy(buf,src,len); // \todo copy needed here? */
unsigned size = (remaining < BUFSZ) ? remaining : BUFSZ;
/* memcpy(buf,src,size); // \todo copy needed here? */
pgp_encrypt->crypt->cfb_encrypt(pgp_encrypt->crypt, encbuf,
src + done, len);
src + done, size);
if (__ops_get_debug_level(__FILE__)) {
int i = 0;
fprintf(stderr, "WRITING:\nunencrypted: ");
(void) fprintf(stderr, "WRITING:\nunencrypted: ");
for (i = 0; i < 16; i++) {
fprintf(stderr, "%2x ", src[done + i]);
(void) fprintf(stderr, "%2x ", src[done + i]);
}
fprintf(stderr, "\n");
fprintf(stderr, "encrypted: ");
(void) fprintf(stderr, "\nencrypted: ");
for (i = 0; i < 16; i++) {
fprintf(stderr, "%2x ", encbuf[i]);
(void) fprintf(stderr, "%2x ", encbuf[i]);
}
fprintf(stderr, "\n");
(void) fprintf(stderr, "\n");
}
if (!__ops_stacked_write(encbuf, len, errors, writer)) {
if (!__ops_stacked_write(encbuf, size, errors, writer)) {
if (__ops_get_debug_level(__FILE__)) {
fprintf(stderr,
"encrypted_writer got error from stacked write, returning\n");
"encrypted_writer: stacked write\n");
}
return 0;
}
remaining -= len;
done += len;
remaining -= size;
done += size;
}
return 1;
@ -966,9 +963,9 @@ encrypt_destroyer(__ops_writer_t * writer)
crypt_t *pgp_encrypt = (crypt_t *) __ops_writer_get_arg(writer);
if (pgp_encrypt->free_crypt) {
free(pgp_encrypt->crypt);
(void) free(pgp_encrypt->crypt);
}
free(pgp_encrypt);
(void) free(pgp_encrypt);
}
/**
@ -976,12 +973,10 @@ encrypt_destroyer(__ops_writer_t * writer)
\brief Push Encrypted Writer onto stack (create SE packets)
*/
void
__ops_writer_push_encrypt_crypt(__ops_output_t *output,
__ops_crypt_t *pgp_crypt)
__ops_push_enc_crypt(__ops_output_t *output, __ops_crypt_t *pgp_crypt)
{
/* Create encrypt to be used with this writer */
/* Remember to free this in the destroyer */
crypt_t *pgp_encrypt = calloc(1, sizeof(*pgp_encrypt));
/* Setup the encrypt */
@ -1012,7 +1007,7 @@ static void encrypt_se_ip_destroyer(__ops_writer_t *);
\brief Push Encrypted SE IP Writer onto stack
*/
void
__ops_writer_push_encrypt_se_ip(__ops_output_t *output,
__ops_push_enc_se_ip(__ops_output_t *output,
const __ops_keydata_t *pubkey)
{
unsigned char *iv = NULL;
@ -1022,8 +1017,9 @@ __ops_writer_push_encrypt_se_ip(__ops_output_t *output,
/* Remember to free this in the destroyer */
encrypt_se_ip_t *se_ip = calloc(1, sizeof(*se_ip));
/* Create and write encrypted PK session key */
__ops_pk_sesskey_t *encrypted_pk_sesskey;
/* Create and write encrypted PK session key */
encrypted_pk_sesskey = __ops_create_pk_sesskey(pubkey);
__ops_write_pk_sesskey(output, encrypted_pk_sesskey);
@ -1068,7 +1064,7 @@ encrypt_se_ip_writer(const unsigned char *src,
/* create literal data packet from source data */
__ops_write_litdata(litoutput, src, (const int)len, OPS_LDT_BINARY);
if (__ops_mem_len(litmem) <= len) {
(void) fprintf(stderr, "encrypt_se_ip_writer: bad length\n");
(void) fprintf(stderr, "encrypt_se_ip_writer: bad len\n");
return 0;
}
@ -1081,7 +1077,7 @@ encrypt_se_ip_writer(const unsigned char *src,
se_ip->crypt, output);
if (__ops_mem_len(localmem) <= __ops_mem_len(zmem)) {
(void) fprintf(stderr,
"encrypt_se_ip_writer: bad comp length\n");
"encrypt_se_ip_writer: bad comp len\n");
return 0;
}
@ -1114,7 +1110,7 @@ __ops_write_se_ip_pktset(const unsigned char *data,
__ops_output_t *output)
{
__ops_output_t *mdcoutput;
__ops_memory_t *mdcmem;
__ops_memory_t *mdc;
unsigned char hashed[OPS_SHA1_HASH_SIZE];
unsigned char *preamble;
const size_t sz_mdc = 1 + 1 + OPS_SHA1_HASH_SIZE;
@ -1146,7 +1142,7 @@ __ops_write_se_ip_pktset(const unsigned char *data,
}
/* now construct MDC packet and add to the end of the buffer */
__ops_setup_memory_write(&mdcoutput, &mdcmem, sz_mdc);
__ops_setup_memory_write(&mdcoutput, &mdc, sz_mdc);
__ops_calc_mdc_hash(preamble, sz_preamble, data, len, &hashed[0]);
__ops_write_mdc(hashed, mdcoutput);
@ -1154,7 +1150,7 @@ __ops_write_se_ip_pktset(const unsigned char *data,
unsigned int i = 0;
size_t sz_plaintext = len;
size_t sz_mdc2 = 1 + 1 + OPS_SHA1_HASH_SIZE;
unsigned char *mdc = NULL;
unsigned char *digest = NULL;
(void) fprintf(stderr, "\nplaintext: ");
for (i = 0; i < sz_plaintext; i++) {
@ -1163,24 +1159,23 @@ __ops_write_se_ip_pktset(const unsigned char *data,
(void) fprintf(stderr, "\n");
(void) fprintf(stderr, "\nmdc: ");
mdc = __ops_mem_data(mdcmem);
digest = __ops_mem_data(mdc);
for (i = 0; i < sz_mdc2; i++) {
(void) fprintf(stderr, " 0x%02x", mdc[i]);
(void) fprintf(stderr, " 0x%02x", digest[i]);
}
(void) fprintf(stderr, "\n");
}
/* and write it out */
__ops_writer_push_encrypt_crypt(output, crypted);
__ops_push_enc_crypt(output, crypted);
if (__ops_get_debug_level(__FILE__)) {
(void) fprintf(stderr,
"writing %" PRIsize "u + %d + %" PRIsize "u\n",
sz_preamble, len, __ops_mem_len(mdcmem));
sz_preamble, len, __ops_mem_len(mdc));
}
if (!__ops_write(output, preamble, sz_preamble) ||
!__ops_write(output, data, len) ||
!__ops_write(output, __ops_mem_data(mdcmem),
__ops_mem_len(mdcmem))) {
!__ops_write(output, __ops_mem_data(mdc), __ops_mem_len(mdc))) {
/* \todo fix cleanup here and in old code functions */
return 0;
}
@ -1188,7 +1183,7 @@ __ops_write_se_ip_pktset(const unsigned char *data,
__ops_writer_pop(output);
/* cleanup */
__ops_teardown_memory_write(mdcoutput, mdcmem);
__ops_teardown_memory_write(mdcoutput, mdc);
(void) free(preamble);
return 1;
@ -1199,7 +1194,7 @@ typedef struct {
} writer_fd_t;
static unsigned
fd_writer(const unsigned char *src, unsigned length,
fd_writer(const unsigned char *src, unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
@ -1207,13 +1202,13 @@ fd_writer(const unsigned char *src, unsigned length,
int n;
writerfd = __ops_writer_get_arg(writer);
n = write(writerfd->fd, src, length);
n = write(writerfd->fd, src, len);
if (n == -1) {
OPS_SYSTEM_ERROR_1(errors, OPS_E_W_WRITE_FAILED, "write",
"file descriptor %d", writerfd->fd);
return 0;
}
if ((unsigned) n != length) {
if ((unsigned) n != len) {
OPS_ERROR_1(errors, OPS_E_W_WRITE_TOO_SHORT,
"file descriptor %d", writerfd->fd);
return 0;
@ -1251,15 +1246,16 @@ __ops_writer_set_fd(__ops_output_t *output, int fd)
}
static unsigned
memory_writer(const unsigned char *src, unsigned length,
__ops_error_t **errors,
__ops_writer_t *writer)
memory_writer(const unsigned char *src,
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
__ops_memory_t *mem;
__OPS_USED(errors);
mem = __ops_writer_get_arg(writer);
__ops_memory_add(mem, src, length);
__ops_memory_add(mem, src, len);
return 1;
}
@ -1284,14 +1280,14 @@ __ops_writer_set_memory(__ops_output_t *output, __ops_memory_t *mem)
/**************************************************************************/
typedef struct {
__ops_hash_alg_t hash_alg;
__ops_hash_t hash;
unsigned char *hashed;
__ops_hash_alg_t hash_alg;
__ops_hash_t hash;
unsigned char *hashed;
} skey_checksum_t;
static unsigned
skey_checksum_writer(const unsigned char *src,
const unsigned length,
const unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
@ -1300,9 +1296,9 @@ skey_checksum_writer(const unsigned char *src,
sum = __ops_writer_get_arg(writer);
/* add contents to hash */
sum->hash.add(&sum->hash, src, length);
sum->hash.add(&sum->hash, src, len);
/* write to next stacked writer */
ret = __ops_stacked_write(src, length, errors, writer);
ret = __ops_stacked_write(src, len, errors, writer);
/* tidy up and return */
return ret;
}
@ -1321,7 +1317,7 @@ skey_checksum_finaliser(__ops_error_t **errors, __ops_writer_t *writer)
}
static void
skey_checksum_destroyer(__ops_writer_t * writer)
skey_checksum_destroyer(__ops_writer_t *writer)
{
skey_checksum_t *sum;
@ -1335,8 +1331,7 @@ skey_checksum_destroyer(__ops_writer_t * writer)
\param seckey
*/
void
__ops_push_skey_checksum_writer(__ops_output_t *output,
__ops_seckey_t *seckey)
__ops_push_checksum_writer(__ops_output_t *output, __ops_seckey_t *seckey)
{
/* XXX: push a SHA-1 checksum writer (and change s2k to 254). */
skey_checksum_t *sum;
@ -1369,7 +1364,7 @@ typedef struct {
static unsigned
str_enc_se_ip_writer(const unsigned char *src,
unsigned length,
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer);
@ -1428,15 +1423,15 @@ __ops_push_stream_enc_se_ip(__ops_output_t *output,
}
/* calculate the partial data length */
static unsigned int
__ops_calc_partial_data_length(unsigned int len)
__ops_partial_data_len(unsigned int len)
{
unsigned int mask = MAX_PARTIAL_DATA_LENGTH;
int i;
if (len == 0) {
(void) fprintf(stderr,
"__ops_calc_partial_data_length: 0 len\n");
(void) fprintf(stderr, "__ops_partial_data_len: 0 len\n");
return 0;
}
if (len > MAX_PARTIAL_DATA_LENGTH) {
@ -1452,7 +1447,7 @@ __ops_calc_partial_data_length(unsigned int len)
}
static unsigned
__ops_write_partial_data_length(unsigned int len, __ops_output_t *output)
__ops_write_partial_len(unsigned int len, __ops_output_t *output)
{
/* len must be a power of 2 from 0 to 30 */
unsigned char c;
@ -1473,9 +1468,9 @@ stream_write_litdata(__ops_output_t *output,
unsigned len)
{
while (len > 0) {
size_t pdlen = __ops_calc_partial_data_length(len);
size_t pdlen = __ops_partial_data_len(len);
__ops_write_partial_data_length(pdlen, output);
__ops_write_partial_len(pdlen, output);
__ops_write(output, data, pdlen);
data += pdlen;
len -= pdlen;
@ -1494,7 +1489,7 @@ stream_write_litdata_first(__ops_output_t *output,
/* \todo do we need to check text data for <cr><lf> line endings ? */
size_t sz_towrite = 1 + 1 + 4 + len;
size_t sz_pd = __ops_calc_partial_data_length(sz_towrite);
size_t sz_pd = __ops_partial_data_len(sz_towrite);
if (sz_pd < 512) {
(void) fprintf(stderr,
@ -1503,7 +1498,7 @@ stream_write_litdata_first(__ops_output_t *output,
}
__ops_write_ptag(output, OPS_PTAG_CT_LITERAL_DATA);
__ops_write_partial_data_length(sz_pd, output);
__ops_write_partial_len(sz_pd, output);
__ops_write_scalar(output, (unsigned)type, 1);
__ops_write_scalar(output, 0, 1);
__ops_write_scalar(output, 0, 4);
@ -1525,18 +1520,18 @@ stream_write_litdata_last(__ops_output_t * output,
}
static unsigned
stream_write_se_ip(__ops_output_t * output,
stream_write_se_ip(__ops_output_t *output,
const unsigned char *data,
unsigned int len,
str_enc_se_ip_t * se_ip)
str_enc_se_ip_t *se_ip)
{
size_t pdlen;
while (len > 0) {
pdlen = __ops_calc_partial_data_length(len);
__ops_write_partial_data_length(pdlen, output);
pdlen = __ops_partial_data_len(len);
__ops_write_partial_len(pdlen, output);
__ops_writer_push_encrypt_crypt(output, se_ip->crypt);
__ops_push_enc_crypt(output, se_ip->crypt);
__ops_write(output, data, pdlen);
__ops_writer_pop(output);
@ -1552,7 +1547,7 @@ static unsigned
stream_write_se_ip_first(__ops_output_t *output,
const unsigned char *data,
unsigned int len,
str_enc_se_ip_t * se_ip)
str_enc_se_ip_t *se_ip)
{
unsigned char *preamble;
size_t sz_preamble;
@ -1562,7 +1557,7 @@ stream_write_se_ip_first(__ops_output_t *output,
sz_preamble = se_ip->crypt->blocksize + 2;
sz_towrite = sz_preamble + 1 + len;
preamble = calloc(1, sz_preamble);
sz_pd = __ops_calc_partial_data_length(sz_towrite);
sz_pd = __ops_partial_data_len(sz_towrite);
if (sz_pd < 512) {
(void) fprintf(stderr,
"stream_write_se_ip_first: bad sz_pd\n");
@ -1570,10 +1565,10 @@ stream_write_se_ip_first(__ops_output_t *output,
}
__ops_write_ptag(output, OPS_PTAG_CT_SE_IP_DATA);
__ops_write_partial_data_length(sz_pd, output);
__ops_write_partial_len(sz_pd, output);
__ops_write_scalar(output, SE_IP_DATA_VERSION, 1);
__ops_writer_push_encrypt_crypt(output, se_ip->crypt);
__ops_push_enc_crypt(output, se_ip->crypt);
__ops_random(preamble, se_ip->crypt->blocksize);
preamble[se_ip->crypt->blocksize] =
@ -1603,10 +1598,10 @@ stream_write_se_ip_first(__ops_output_t *output,
}
static unsigned
stream_write_se_ip_last(__ops_output_t * output,
stream_write_se_ip_last(__ops_output_t *output,
const unsigned char *data,
unsigned int len,
str_enc_se_ip_t * se_ip)
str_enc_se_ip_t *se_ip)
{
__ops_output_t *mdcoutput;
__ops_memory_t *mdcmem;
@ -1618,7 +1613,7 @@ stream_write_se_ip_last(__ops_output_t * output,
se_ip->hash.add(&se_ip->hash, data, len);
/* MDC packet tag */
c = 0xD3;
c = MDC_PKT_TAG;
se_ip->hash.add(&se_ip->hash, &c, 1);
/* MDC packet len */
@ -1635,7 +1630,7 @@ stream_write_se_ip_last(__ops_output_t * output,
__ops_write_length(output, sz_buf);
/* encode everting */
__ops_writer_push_encrypt_crypt(output, se_ip->crypt);
__ops_push_enc_crypt(output, se_ip->crypt);
__ops_write(output, data, len);
__ops_write(output, __ops_mem_data(mdcmem), __ops_mem_len(mdcmem));
@ -1649,7 +1644,7 @@ stream_write_se_ip_last(__ops_output_t * output,
static unsigned
str_enc_se_ip_writer(const unsigned char *src,
unsigned length,
unsigned len,
__ops_error_t **errors,
__ops_writer_t *writer)
{
@ -1660,7 +1655,7 @@ str_enc_se_ip_writer(const unsigned char *src,
* is not yet written */
size_t datalength;
__ops_memory_add(se_ip->mem_data, src, length);
__ops_memory_add(se_ip->mem_data, src, len);
datalength = __ops_mem_len(se_ip->mem_data);
/* 4.2.2.4. Partial Body Lengths */
@ -1680,7 +1675,7 @@ str_enc_se_ip_writer(const unsigned char *src,
__ops_mem_data(se_ip->litmem),
__ops_mem_len(se_ip->litmem), se_ip);
} else {
stream_write_litdata(se_ip->litoutput, src, length);
stream_write_litdata(se_ip->litoutput, src, len);
stream_write_se_ip(se_ip->se_ip_out,
__ops_mem_data(se_ip->litmem),
__ops_mem_len(se_ip->litmem), se_ip);

View File

@ -104,7 +104,6 @@ void __ops_writer_push(__ops_output_t *,
__ops_writer_destroyer_t *,
void *);
void __ops_writer_pop(__ops_output_t *);
void __ops_writer_generic_destroyer(__ops_writer_t *);
unsigned __ops_writer_passthrough(const unsigned char *,
unsigned,
__ops_error_t **,