|
|
@ -143,14 +143,14 @@ unsigned |
|
|
|
pgp_write_mpi(pgp_output_t *output, const BIGNUM *bn) |
|
|
|
#endif |
|
|
|
#ifdef HAVE_GSKSSL |
|
|
|
pgp_write_mpi(pgp_output_t *output, gsk_buffer bn) |
|
|
|
pgp_write_mpi(pgp_output_t *output, gsk_buffer *bn) |
|
|
|
#endif |
|
|
|
{ |
|
|
|
unsigned bits; |
|
|
|
uint8_t buf[NETPGP_BUFSIZ]; |
|
|
|
memset(buf,0,NETPGP_BUFSIZ); |
|
|
|
#if defined(HAVE_GSKSSL) |
|
|
|
bits = (unsigned)bn.length*8-1; |
|
|
|
bits = (unsigned)((bn->length*8)-((bn->length%2)*7)); |
|
|
|
#elif defined(HAVE_OPENSSL) |
|
|
|
bits = (unsigned)BN_num_bits(bn); |
|
|
|
#endif |
|
|
@ -161,10 +161,9 @@ pgp_write_mpi(pgp_output_t *output, gsk_buffer bn) |
|
|
|
#if defined(HAVE_OPENSSL) |
|
|
|
BN_bn2bin(bn, buf); |
|
|
|
#elif defined(HAVE_GSKSSL) |
|
|
|
memcpy(buf,bn.data,bn.length); |
|
|
|
memcpy(buf,bn->data,bn->length); |
|
|
|
#endif |
|
|
|
return pgp_write_scalar(output, bits, 2) && |
|
|
|
pgp_write(output, buf, (bits + 7) / 8); |
|
|
|
return pgp_write_scalar(output, bits, 2) && pgp_write(output, buf, (bits + 7) / 8); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -177,8 +176,7 @@ pgp_write_mpi(pgp_output_t *output, gsk_buffer bn) |
|
|
|
unsigned |
|
|
|
pgp_write_ptag(pgp_output_t *output, pgp_content_enum tag) |
|
|
|
{ |
|
|
|
uint8_t c; |
|
|
|
|
|
|
|
uint8_t c; |
|
|
|
c = tag | PGP_PTAG_ALWAYS_SET | PGP_PTAG_NEW_FORMAT; |
|
|
|
return base_write(output, &c, 1); |
|
|
|
} |
|
|
@ -194,7 +192,6 @@ unsigned |
|
|
|
pgp_write_length(pgp_output_t *output, unsigned len) |
|
|
|
{ |
|
|
|
uint8_t c[2]; |
|
|
|
|
|
|
|
if (len < 192) { |
|
|
|
c[0] = len; |
|
|
|
return base_write(output, c, 1); |
|
|
@ -204,8 +201,7 @@ pgp_write_length(pgp_output_t *output, unsigned len) |
|
|
|
c[1] = (len - 192) % 256; |
|
|
|
return base_write(output, c, 2); |
|
|
|
} |
|
|
|
return pgp_write_scalar(output, 0xff, 1) && |
|
|
|
pgp_write_scalar(output, len, 4); |
|
|
|
return pgp_write_scalar(output, 0xff, 1) && pgp_write_scalar(output, len, 4); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@ -320,11 +316,9 @@ pgp_writer_pop(pgp_output_t *output) |
|
|
|
|
|
|
|
/* Make sure the finaliser has been called. */ |
|
|
|
if (output->writer.finaliser) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_pop: finaliser not called\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_pop: finaliser not called\n"); |
|
|
|
} else if (output->writer.next == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_pop: not a stacked writer\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_pop: not a stacked writer\n"); |
|
|
|
} else { |
|
|
|
if (output->writer.destroyer) { |
|
|
|
output->writer.destroyer(&output->writer); |
|
|
@ -780,16 +774,14 @@ pgp_writer_push_armor_msg(pgp_output_t *output) |
|
|
|
pgp_write(output, header, (unsigned)(sizeof(header) - 1)); |
|
|
|
pgp_write(output, "\r\n", 2); |
|
|
|
if ((linebreak = calloc(1, sizeof(*linebreak))) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_push_armor_msg: bad lb alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_push_armor_msg: bad lb alloc\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
pgp_writer_push(output, linebreak_writer, NULL, |
|
|
|
generic_destroyer, |
|
|
|
linebreak); |
|
|
|
if ((base64 = calloc(1, sizeof(*base64))) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_push_armor_msg: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_push_armor_msg: bad alloc\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
base64->checksum = CRC24_INIT; |
|
|
@ -906,13 +898,11 @@ pgp_writer_push_armoured(pgp_output_t *output, pgp_armor_type_t type) |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_push_armoured: unusual type\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_push_armoured: unusual type\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((linebreak = calloc(1, sizeof(*linebreak))) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_push_armoured: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_push_armoured: bad alloc\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
pgp_write(output, header, hdrsize); |
|
|
@ -920,8 +910,7 @@ pgp_writer_push_armoured(pgp_output_t *output, pgp_armor_type_t type) |
|
|
|
generic_destroyer, |
|
|
|
linebreak); |
|
|
|
if ((base64 = calloc(1, sizeof(*base64))) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_writer_push_armoured: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_writer_push_armoured: bad alloc\n"); |
|
|
|
free(linebreak); |
|
|
|
return; |
|
|
|
} |
|
|
@ -964,8 +953,7 @@ encrypt_writer(const uint8_t *src, |
|
|
|
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, size); |
|
|
|
pgp_encrypt->crypt->cfb_encrypt(pgp_encrypt->crypt, encbuf, src + done, size); |
|
|
|
|
|
|
|
if (pgp_get_debug_level(__FILE__)) { |
|
|
|
hexdump(stderr, "unencrypted", &src[done], 16); |
|
|
@ -973,8 +961,7 @@ encrypt_writer(const uint8_t *src, |
|
|
|
} |
|
|
|
if (!stacked_write(writer, encbuf, size, errors)) { |
|
|
|
if (pgp_get_debug_level(__FILE__)) { |
|
|
|
fprintf(stderr, |
|
|
|
"encrypted_writer: stacked write\n"); |
|
|
|
fprintf(stderr, "encrypted_writer: stacked write\n"); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -1056,9 +1043,7 @@ pgp_push_enc_se_ip(pgp_output_t *output, const pgp_keyring_t *pubkeys, const cha |
|
|
|
|
|
|
|
for (n = 0; n < pubkeys->keyc; ++n) { |
|
|
|
/* Create and write encrypted PK session key */ |
|
|
|
if ((encrypted_pk_sesskey = |
|
|
|
pgp_create_pk_sesskey(&pubkeys->keys[n], |
|
|
|
cipher, initial_sesskey)) == NULL) { |
|
|
|
if ((encrypted_pk_sesskey = pgp_create_pk_sesskey(&pubkeys->keys[n], cipher, initial_sesskey)) == NULL) { |
|
|
|
(void) fprintf(stderr, "pgp_push_enc_se_ip: null pk sesskey\n"); |
|
|
|
free(se_ip); |
|
|
|
return 0; |
|
|
@ -1155,8 +1140,7 @@ encrypt_se_ip_writer(const uint8_t *src, |
|
|
|
(unsigned)pgp_mem_len(zmem), |
|
|
|
se_ip->crypt); |
|
|
|
if (pgp_mem_len(localmem) <= pgp_mem_len(zmem)) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"encrypt_se_ip_writer: bad comp len\n"); |
|
|
|
(void) fprintf(stderr, "encrypt_se_ip_writer: bad comp len\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
@ -1229,9 +1213,7 @@ pgp_write_se_ip_pktset(pgp_output_t *output, |
|
|
|
/* and write it out */ |
|
|
|
pgp_push_enc_crypt(output, crypted); |
|
|
|
if (pgp_get_debug_level(__FILE__)) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"writing %" PRIsize "u + %u + %" PRIsize "u\n", |
|
|
|
preamblesize, len, pgp_mem_len(mdc)); |
|
|
|
(void) fprintf(stderr, "writing %" PRIsize "u + %u + %" PRIsize "u\n", preamblesize, len, pgp_mem_len(mdc)); |
|
|
|
} |
|
|
|
if (!pgp_write(output, preamble, (unsigned)preamblesize) || |
|
|
|
!pgp_write(output, data, len) || |
|
|
@ -1523,8 +1505,7 @@ pgp_push_stream_enc_se_ip(pgp_output_t *output, pgp_key_t *pubkey, const char *c |
|
|
|
uint8_t *iv; |
|
|
|
|
|
|
|
if ((se_ip = calloc(1, sizeof(*se_ip))) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_push_stream_enc_se_ip: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_push_stream_enc_se_ip: bad alloc\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
encrypted_pk_sesskey = pgp_create_pk_sesskey(pubkey, cipher, NULL); |
|
|
@ -1541,8 +1522,7 @@ pgp_push_stream_enc_se_ip(pgp_output_t *output, pgp_key_t *pubkey, const char *c |
|
|
|
if ((iv = calloc(1, encrypted->blocksize)) == NULL) { |
|
|
|
free(encrypted); |
|
|
|
free(se_ip); |
|
|
|
(void) fprintf(stderr, |
|
|
|
"pgp_push_stream_enc_se_ip: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "pgp_push_stream_enc_se_ip: bad alloc\n"); |
|
|
|
return; |
|
|
|
} |
|
|
|
encrypted->set_iv(encrypted, iv); |
|
|
@ -1643,8 +1623,7 @@ stream_write_litdata_first(pgp_output_t *output, |
|
|
|
sz_towrite = 1 + 1 + 4 + len; |
|
|
|
sz_pd = (size_t)partial_data_len(sz_towrite); |
|
|
|
if (sz_pd < 512) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"stream_write_litdata_first: bad sz_pd\n"); |
|
|
|
(void) fprintf(stderr, "stream_write_litdata_first: bad sz_pd\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
pgp_write_ptag(output, PGP_PTAG_CT_LITDATA); |
|
|
@ -1675,7 +1654,7 @@ stream_write_se_ip(pgp_output_t *output, |
|
|
|
unsigned len, |
|
|
|
str_enc_se_ip_t *se_ip) |
|
|
|
{ |
|
|
|
size_t pdlen; |
|
|
|
size_t pdlen; |
|
|
|
|
|
|
|
while (len > 0) { |
|
|
|
pdlen = partial_data_len(len); |
|
|
@ -1709,15 +1688,13 @@ stream_write_se_ip_first(pgp_output_t *output, |
|
|
|
preamblesize = blocksize + 2; |
|
|
|
sz_towrite = preamblesize + 1 + len; |
|
|
|
if ((preamble = calloc(1, preamblesize)) == NULL) { |
|
|
|
(void) fprintf(stderr, |
|
|
|
"stream_write_se_ip_first: bad alloc\n"); |
|
|
|
(void) fprintf(stderr, "stream_write_se_ip_first: bad alloc\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
sz_pd = (size_t)partial_data_len((unsigned)sz_towrite); |
|
|
|
if (sz_pd < 512) { |
|
|
|
free(preamble); |
|
|
|
(void) fprintf(stderr, |
|
|
|
"stream_write_se_ip_first: bad sz_pd\n"); |
|
|
|
(void) fprintf(stderr, "stream_write_se_ip_first: bad sz_pd\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
pgp_write_ptag(output, PGP_PTAG_CT_SE_IP_DATA); |
|
|
@ -1731,8 +1708,7 @@ stream_write_se_ip_first(pgp_output_t *output, |
|
|
|
pgp_hash_any(&se_ip->hash, PGP_HASH_SHA1); |
|
|
|
if (!se_ip->hash.init(&se_ip->hash)) { |
|
|
|
free(preamble); |
|
|
|
(void) fprintf(stderr, |
|
|
|
"stream_write_se_ip_first: bad hash init\n"); |
|
|
|
(void) fprintf(stderr, "stream_write_se_ip_first: bad hash init\n"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
pgp_write(output, preamble, (unsigned)preamblesize); |
|
|
|