Abstract away all the %zu uses, and use a symbolic constant for them.
With thanks to uwe for the information to make this portable. Expose the ops_memory_t structure, since we're now using it outside its own source file. Various cosmetic changes, mainly for debugging purposes.
This commit is contained in:
parent
ff02cd3e84
commit
8da84dc021
|
@ -1,7 +1,14 @@
|
|||
/* generated by configure from include/openpgpsdk/configure.h.template. Don't edit. */
|
||||
|
||||
#undef HAVE_ALLOCA_H
|
||||
#define TIME_T_FMT "%lld"
|
||||
|
||||
#define PRItime "ll"
|
||||
|
||||
#ifdef WIN32
|
||||
#define PRIsize "I"
|
||||
#else
|
||||
#define PRIsize "z"
|
||||
#endif
|
||||
|
||||
/* for silencing unused parameter warnings */
|
||||
#define OPS_USED(x) /*LINTED*/(void)&(x)
|
||||
|
|
|
@ -31,7 +31,12 @@
|
|||
|
||||
/** ops_memory_t
|
||||
*/
|
||||
typedef struct ops_memory ops_memory_t;
|
||||
typedef struct ops_memory_t {
|
||||
unsigned char *buf;
|
||||
size_t length;
|
||||
size_t allocated;
|
||||
} ops_memory_t;
|
||||
|
||||
|
||||
ops_memory_t *ops_memory_new(void);
|
||||
void ops_memory_free(ops_memory_t *mem);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <openpgpsdk/random.h>
|
||||
#include <openpgpsdk/readerwriter.h>
|
||||
#include <openpgpsdk/writer_armoured.h>
|
||||
#include <openpgpsdk/std_print.h>
|
||||
#include "parse_local.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -57,33 +58,33 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM
|
|||
|
||||
assert(skey->public_key.algorithm == OPS_PKA_RSA);
|
||||
|
||||
/*
|
||||
fprintf(stderr,"\nDECRYPTING\n");
|
||||
fprintf(stderr,"encrypted data : ");
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", encmpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
fprintf(stderr,"\nDECRYPTING\n");
|
||||
fprintf(stderr,"encrypted data : ");
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", encmpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
n=ops_rsa_private_decrypt(mpibuf,encmpibuf,(BN_num_bits(encmpi)+7)/8,
|
||||
&skey->key.rsa,&skey->public_key.key.rsa);
|
||||
assert(n!=-1);
|
||||
|
||||
/*
|
||||
fprintf(stderr,"decrypted encoded m buf : ");
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", mpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
fprintf(stderr,"decrypted encoded m buf : ");
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", mpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
if(n <= 0)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
printf(" decrypted=%d ",n);
|
||||
hexdump(mpibuf,n);
|
||||
printf("\n");
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf(" decrypted=%d ",n);
|
||||
hexdump(mpibuf,n);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// Decode EME-PKCS1_V1_5 (RFC 2437).
|
||||
|
||||
|
@ -104,13 +105,14 @@ int ops_decrypt_and_unencode_mpi(unsigned char *buf,unsigned buflen,const BIGNUM
|
|||
if((unsigned)(n-i) <= buflen)
|
||||
memcpy(buf,mpibuf+i,n-i);
|
||||
|
||||
/*
|
||||
printf("decoded m buf:\n");
|
||||
int j;
|
||||
for (j=0; j<n-i; j++)
|
||||
printf("%2x ",buf[j]);
|
||||
printf("\n");
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
int j;
|
||||
|
||||
printf("decoded m buf:\n");
|
||||
for (j=0; j<n-i; j++)
|
||||
printf("%2x ",buf[j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return n-i;
|
||||
}
|
||||
|
@ -138,13 +140,13 @@ ops_boolean_t ops_rsa_encrypt_mpi(const unsigned char *encoded_m_buf,
|
|||
|
||||
skp->rsa.encrypted_m=BN_bin2bn(encmpibuf, n, NULL);
|
||||
|
||||
/*
|
||||
fprintf(stderr,"encrypted mpi buf : ");
|
||||
int i;
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", encmpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
int i;
|
||||
fprintf(stderr,"encrypted mpi buf : ");
|
||||
for (i=0; i<16; i++)
|
||||
fprintf(stderr,"%2x ", encmpibuf[i]);
|
||||
fprintf(stderr,"\n");
|
||||
}
|
||||
|
||||
return ops_true;
|
||||
}
|
||||
|
@ -338,7 +340,9 @@ callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *
|
|||
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
// ops_print_packet(content_);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
ops_print_packet(content_);
|
||||
}
|
||||
|
||||
if(content_->tag != OPS_PTAG_CT_UNARMOURED_TEXT && skipping)
|
||||
{
|
||||
|
@ -389,10 +393,12 @@ callback_write_parsed(const ops_parser_content_t *content_,ops_parse_cb_info_t *
|
|||
|
||||
default:
|
||||
// return callback_general(content_,cbinfo);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",
|
||||
content_->tag,
|
||||
content_->tag);
|
||||
}
|
||||
break;
|
||||
// fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
|
||||
// content_->tag);
|
||||
// assert(0);
|
||||
}
|
||||
|
||||
return OPS_RELEASE_MEMORY;
|
||||
|
|
|
@ -835,7 +835,7 @@ ops_keyring_find_key_by_userid(const ops_keyring_t *keyring,
|
|||
for (n = 0 ; n < keyring->nkeys ; n++) {
|
||||
for (i = 0; i < keyring->keys[n].nuids; i++) {
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf("keyid ,%s, len %zu, keyid[len] %c\n",
|
||||
printf("keyid ,%s, len %" PRIsize "u, keyid[len] %c\n",
|
||||
(char *)keyring->keys[n].uids[i].user_id, len, keyring->keys[n].uids[i].user_id[len]);
|
||||
}
|
||||
if (strncasecmp((char *)keyring->keys[n].uids[i].user_id, userid, len) == 0 && keyring->keys[n].uids[i].user_id[len] == ' ') {
|
||||
|
@ -854,7 +854,7 @@ ops_keyring_find_key_by_userid(const ops_keyring_t *keyring,
|
|||
*/
|
||||
if ((cp = strrchr((char *)keyring->keys[n].uids[i].user_id, '<')) != NULL) {
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf("cp ,%s, userid ,%s, len %zu ,%c,\n",
|
||||
printf("cp ,%s, userid ,%s, len %" PRIsize "u ,%c,\n",
|
||||
cp + 1, userid, len, *(cp + len + 1));
|
||||
}
|
||||
if (strncasecmp(cp + 1, userid, len) == 0 &&
|
||||
|
|
|
@ -29,13 +29,6 @@
|
|||
|
||||
#include <openpgpsdk/final.h>
|
||||
|
||||
struct ops_memory
|
||||
{
|
||||
unsigned char *buf;
|
||||
size_t length;
|
||||
size_t allocated;
|
||||
};
|
||||
|
||||
/**
|
||||
\ingroup HighLevel_Memory
|
||||
\brief Memory to initialise
|
||||
|
|
|
@ -2516,7 +2516,7 @@ static int parse_pk_session_key(ops_region_t *region,
|
|||
// \todo FIXME RW
|
||||
// const size_t sz_unencoded_m_buf=CAST_KEY_LENGTH+1+2;
|
||||
unsigned char unencoded_m_buf[1024];
|
||||
|
||||
|
||||
if(!limited_read(c,1,region,pinfo))
|
||||
return 0;
|
||||
C.pk_session_key.version=c[0];
|
||||
|
@ -2529,8 +2529,9 @@ static int parse_pk_session_key(ops_region_t *region,
|
|||
}
|
||||
|
||||
if(!limited_read(C.pk_session_key.key_id,
|
||||
sizeof C.pk_session_key.key_id,region,pinfo))
|
||||
sizeof C.pk_session_key.key_id,region,pinfo)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ops_get_debug_level(__FILE__))
|
||||
{
|
||||
|
@ -2549,8 +2550,9 @@ static int parse_pk_session_key(ops_region_t *region,
|
|||
{
|
||||
case OPS_PKA_RSA:
|
||||
if(!limited_read_mpi(&C.pk_session_key.parameters.rsa.encrypted_m,
|
||||
region,pinfo))
|
||||
region,pinfo)) {
|
||||
return 0;
|
||||
}
|
||||
enc_m=C.pk_session_key.parameters.rsa.encrypted_m;
|
||||
break;
|
||||
|
||||
|
@ -2558,8 +2560,9 @@ static int parse_pk_session_key(ops_region_t *region,
|
|||
if(!limited_read_mpi(&C.pk_session_key.parameters.elgamal.g_to_k,
|
||||
region,pinfo)
|
||||
|| !limited_read_mpi(&C.pk_session_key.parameters.elgamal.encrypted_m,
|
||||
region,pinfo))
|
||||
region,pinfo)) {
|
||||
return 0;
|
||||
}
|
||||
enc_m=C.pk_session_key.parameters.elgamal.encrypted_m;
|
||||
break;
|
||||
|
||||
|
|
|
@ -384,7 +384,7 @@ static void print_hex(const unsigned char *src,size_t length)
|
|||
|
||||
static void showtime(const char *name,time_t t)
|
||||
{
|
||||
printf("%s=" TIME_T_FMT " (%.24s)",name,(long long)t,ctime(&t));
|
||||
printf("%s=%" PRItime "d (%.24s)",name,(int64_t)t,ctime(&t));
|
||||
}
|
||||
static void showtime_short(time_t t)
|
||||
{
|
||||
|
@ -456,7 +456,7 @@ static void print_duration(const char *name, time_t t)
|
|||
|
||||
print_indent();
|
||||
printf("%s: ",name);
|
||||
printf("duration " TIME_T_FMT " seconds",(long long)t);
|
||||
printf("duration %" PRItime "d seconds",(long long)t);
|
||||
|
||||
mins=t/60;
|
||||
hours=mins/60;
|
||||
|
|
|
@ -167,12 +167,12 @@ static int se_ip_data_reader(void *dest_, size_t len, ops_error_t **errors,
|
|||
{
|
||||
unsigned int i=0;
|
||||
|
||||
fprintf(stderr,"\nplaintext (len=%zu): ",sz_plaintext);
|
||||
fprintf(stderr,"\nplaintext (len=%" PRIsize "u): ",sz_plaintext);
|
||||
for (i=0; i<sz_plaintext;i++)
|
||||
fprintf(stderr," 0x%02x", plaintext[i]);
|
||||
fprintf(stderr,"\n");
|
||||
|
||||
fprintf(stderr,"\nmdc (len=%zu): ",sz_mdc);
|
||||
fprintf(stderr,"\nmdc (len=%" PRIsize "u): ",sz_mdc);
|
||||
for (i=0; i<sz_mdc;i++)
|
||||
fprintf(stderr," 0x%02x", mdc[i]);
|
||||
fprintf(stderr,"\n");
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include <openpgpsdk/readerwriter.h>
|
||||
#include <openpgpsdk/std_print.h>
|
||||
#include <openpgpsdk/callback.h>
|
||||
|
||||
#include "parse_local.h"
|
||||
|
@ -89,7 +90,7 @@ void ops_setup_memory_read(ops_parse_info_t **pinfo, ops_memory_t *mem,
|
|||
ops_boolean_t accumulate)
|
||||
{
|
||||
/*
|
||||
* initialise needed uctures for reading
|
||||
* initialise needed structures for reading
|
||||
*/
|
||||
|
||||
*pinfo=ops_parse_info_new();
|
||||
|
@ -249,6 +250,9 @@ int ops_setup_file_read(ops_parse_info_t **pinfo, const char *filename,
|
|||
if (accumulate)
|
||||
(*pinfo)->rinfo.accumulate=ops_true;
|
||||
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf("ops_setup_file_read: accumulate %d\n", accumulate);
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -272,7 +276,9 @@ callback_literal_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *
|
|||
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
// ops_print_packet(content_);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
ops_print_packet(content_);
|
||||
}
|
||||
|
||||
// Read data from packet into static buffer
|
||||
switch(content_->tag)
|
||||
|
@ -311,13 +317,17 @@ callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t
|
|||
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
// ops_print_packet(content_);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
ops_print_packet(content_);
|
||||
}
|
||||
|
||||
// Read data from packet into static buffer
|
||||
switch(content_->tag)
|
||||
{
|
||||
case OPS_PTAG_CT_PK_SESSION_KEY:
|
||||
// printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
|
||||
}
|
||||
assert(cbinfo->cryptinfo.keyring);
|
||||
cbinfo->cryptinfo.keydata=ops_keyring_find_key_by_id(cbinfo->cryptinfo.keyring,
|
||||
content->pk_session_key.key_id);
|
||||
|
@ -356,7 +366,9 @@ callback_cmd_get_secret_key(const ops_parser_content_t *content_,ops_parse_cb_in
|
|||
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
// ops_print_packet(content_);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
ops_print_packet(content_);
|
||||
}
|
||||
|
||||
switch(content_->tag)
|
||||
{
|
||||
|
@ -425,7 +437,9 @@ callback_cmd_get_passphrase_from_cmdline(const ops_parser_content_t *content_,op
|
|||
|
||||
OPS_USED(cbinfo);
|
||||
|
||||
// ops_print_packet(content_);
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
ops_print_packet(content_);
|
||||
}
|
||||
|
||||
switch(content_->tag)
|
||||
{
|
||||
|
|
|
@ -260,7 +260,8 @@ static void dsa_sign(ops_hash_t *hash,
|
|||
}
|
||||
|
||||
static ops_boolean_t rsa_verify(ops_hash_algorithm_t type,
|
||||
const unsigned char *hash,size_t hash_length,
|
||||
const unsigned char *hash,
|
||||
size_t hash_length,
|
||||
const ops_rsa_signature_t *sig,
|
||||
const ops_rsa_public_key_t *rsa)
|
||||
{
|
||||
|
@ -291,12 +292,22 @@ static ops_boolean_t rsa_verify(ops_hash_algorithm_t type,
|
|||
if(hashbuf_from_sig[0] != 0 || hashbuf_from_sig[1] != 1)
|
||||
return ops_false;
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case OPS_HASH_MD5: prefix=prefix_md5; plen=sizeof prefix_md5; break;
|
||||
case OPS_HASH_SHA1: prefix=prefix_sha1; plen=sizeof prefix_sha1; break;
|
||||
case OPS_HASH_SHA256: prefix=prefix_sha256; plen=sizeof prefix_sha256; break;
|
||||
default: assert(0); break;
|
||||
switch(type) {
|
||||
case OPS_HASH_MD5:
|
||||
prefix=prefix_md5;
|
||||
plen=sizeof(prefix_md5);
|
||||
break;
|
||||
case OPS_HASH_SHA1:
|
||||
prefix=prefix_sha1;
|
||||
plen=sizeof(prefix_sha1);
|
||||
break;
|
||||
case OPS_HASH_SHA256:
|
||||
prefix=prefix_sha256;
|
||||
plen=sizeof(prefix_sha256);
|
||||
break;
|
||||
default:
|
||||
(void) fprintf(stderr, "Unknown hash algorithm: %d\n", type);
|
||||
return ops_false;
|
||||
}
|
||||
|
||||
if(keysize-plen-hash_length < 10)
|
||||
|
@ -334,8 +345,8 @@ static ops_boolean_t rsa_verify(ops_hash_algorithm_t type,
|
|||
{ printf("%02x ", hash[uu]); }
|
||||
printf("\n");
|
||||
}
|
||||
if(memcmp(&hashbuf_from_sig[n],prefix,plen)
|
||||
|| memcmp(&hashbuf_from_sig[n+plen],hash,hash_length))
|
||||
if(memcmp(&hashbuf_from_sig[n],prefix,plen) != 0
|
||||
|| memcmp(&hashbuf_from_sig[n+plen],hash,hash_length) != 0)
|
||||
return ops_false;
|
||||
|
||||
return ops_true;
|
||||
|
@ -403,11 +414,11 @@ ops_boolean_t ops_check_signature(const unsigned char *hash,unsigned length,
|
|||
{
|
||||
ops_boolean_t ret;
|
||||
|
||||
/*
|
||||
printf(" hash=");
|
||||
// hashout[0]=0;
|
||||
hexdump(hash,length);
|
||||
*/
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
printf("ops_check_signature: (length %d) hash=", length);
|
||||
// hashout[0]=0;
|
||||
hexdump(hash, length);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
switch(sig->info.key_algorithm)
|
||||
|
@ -714,8 +725,9 @@ void ops_signature_start_message_signature(ops_create_signature_t *sig,
|
|||
void ops_signature_add_data(ops_create_signature_t *sig,const void *buf,
|
||||
size_t length)
|
||||
{
|
||||
if (ops_get_debug_level(__FILE__))
|
||||
{ fprintf(stderr,"ops_signature_add_data adds to hash\n"); }
|
||||
if (ops_get_debug_level(__FILE__)) {
|
||||
fprintf(stderr,"ops_signature_add_data adds to hash\n");
|
||||
}
|
||||
sig->hash.add(&sig->hash,buf,length);
|
||||
}
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ ops_boolean_t ops_write_se_ip_pktset(const unsigned char *data,
|
|||
#ifdef DEBUG
|
||||
if (ops_get_debug_level(__FILE__))
|
||||
{
|
||||
fprintf(stderr,"writing %zu + %d + %zu\n", sz_preamble, len, ops_memory_get_length(mem_mdc));
|
||||
fprintf(stderr,"writing %" PRIsize "u + %d + %" PRIsize "u\n", sz_preamble, len, ops_memory_get_length(mem_mdc));
|
||||
}
|
||||
#endif /*DEBUG*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue