Browse Source

z/OS support: gsk_buffers are pointers now

master
David Lanzendörfer 12 months ago
parent
commit
e03e061b53
1 changed files with 35 additions and 17 deletions
  1. +35
    -17
      src/crypto.c

+ 35
- 17
src/crypto.c View File

@ -94,8 +94,8 @@ pgp_decrypt_decode_mpi(uint8_t *buf,
const BIGNUM *encmpi,
#endif
#ifdef HAVE_GSKSSL
const gsk_buffer g_to_k,
const gsk_buffer encmpi,
const gsk_buffer *g_to_k,
const gsk_buffer *encmpi,
#endif
const pgp_seckey_t *seckey)
{
@ -107,8 +107,11 @@ pgp_decrypt_decode_mpi(uint8_t *buf,
int i;
int n;
#ifdef HAVE_OPENSSL
#if defined(HAVE_OPENSSL)
mpisize = (unsigned)BN_num_bytes(encmpi);
#elif defined(HAVE_GSKSSL)
mpisize = (unsigned)encmpi->length;
#endif
/* MPI can't be more than 65,536 */
if (mpisize > sizeof(encmpibuf)) {
(void) fprintf(stderr, "mpisize too big %u\n", mpisize);
@ -116,12 +119,20 @@ pgp_decrypt_decode_mpi(uint8_t *buf,
}
switch (seckey->pubkey.alg) {
case PGP_PKA_RSA:
#if defined(HAVE_OPENSSL)
BN_bn2bin(encmpi, encmpibuf);
#elif defined(HAVE_GSKSSL)
memcpy(encmpibuf,encmpi->data,encmpi->length);
#endif
if (pgp_get_debug_level(__FILE__)) {
hexdump(stderr, "encrypted", encmpibuf, 16);
}
n = pgp_rsa_private_decrypt(mpibuf, encmpibuf,
#if defined(HAVE_OPENSSL)
(unsigned)(BN_num_bits(encmpi) + 7) / 8,
#elif defined(HAVE_GSKSSL)
(unsigned)((encmpi->length*8-1) + 7) / 8,
#endif
&seckey->key.rsa, &seckey->pubkey.key.rsa);
if (n == -1) {
(void) fprintf(stderr, "ops_rsa_private_decrypt failure\n");
@ -155,13 +166,22 @@ pgp_decrypt_decode_mpi(uint8_t *buf,
return n - i;
case PGP_PKA_DSA:
case PGP_PKA_ELGAMAL:
#if defined(HAVE_OPENSSL)
(void) BN_bn2bin(g_to_k, gkbuf);
(void) BN_bn2bin(encmpi, encmpibuf);
#elif defined(HAVE_GSKSSL)
memcpy(gkbuf,g_to_k->data,g_to_k->length);
memcpy(encmpibuf,encmpi->data,encmpi->length);
#endif
if (pgp_get_debug_level(__FILE__)) {
hexdump(stderr, "encrypted", encmpibuf, 16);
}
n = pgp_elgamal_private_decrypt(mpibuf, gkbuf, encmpibuf,
#if defined(HAVE_OPENSSL)
(unsigned)BN_num_bytes(encmpi),
#elif defined(HAVE_GSKSSL)
(unsigned)encmpi->length,
#endif
&seckey->key.elgamal, &seckey->pubkey.key.elgamal);
if (n == -1) {
(void) fprintf(stderr, "ops_elgamal_private_decrypt failure\n");
@ -199,7 +219,6 @@ pgp_decrypt_decode_mpi(uint8_t *buf,
(void) fprintf(stderr, "pubkey algorithm wrong\n");
return -1;
}
#endif
}
/**
@ -219,7 +238,7 @@ pgp_rsa_encrypt_mpi(const uint8_t *encoded_m_buf,
#if defined(HAVE_OPENSSL_BN_H)
if (sz_encoded_m_buf != (size_t)BN_num_bytes(pubkey->key.rsa.n)) {
#elif defined(HAVE_GSKSSL)
if (sz_encoded_m_buf != (size_t)pubkey->key.rsa.n.length) {
if (sz_encoded_m_buf != (size_t)pubkey->key.rsa.n->length) {
#endif
(void) fprintf(stderr, "sz_encoded_m_buf wrong\n");
return 0;
@ -238,9 +257,9 @@ pgp_rsa_encrypt_mpi(const uint8_t *encoded_m_buf,
#if defined(HAVE_OPENSSL_BN_H)
skp->rsa.encrypted_m = BN_bin2bn(encmpibuf, n, NULL);
#elif defined(HAVE_GSKSSL)
skp->rsa.encrypted_m.data=malloc(n);
skp->rsa.encrypted_m.length=n;
memcpy(skp->rsa.encrypted_m.data, encmpibuf, n);
skp->rsa.encrypted_m->data=malloc(n);
skp->rsa.encrypted_m->length=n;
memcpy(skp->rsa.encrypted_m->data, encmpibuf, n);
#endif
if (pgp_get_debug_level(__FILE__)) {
@ -267,7 +286,7 @@ pgp_elgamal_encrypt_mpi(const uint8_t *encoded_m_buf,
#if defined(HAVE_OPENSSL_BN_H)
if (sz_encoded_m_buf != (size_t)BN_num_bytes(pubkey->key.elgamal.p)) {
#elif defined(HAVE_GSKSSL)
if (sz_encoded_m_buf != (size_t)pubkey->key.elgamal.p.length) {
if (sz_encoded_m_buf != (size_t)pubkey->key.elgamal.p->length) {
#endif
(void) fprintf(stderr, "sz_encoded_m_buf wrong\n");
return 0;
@ -286,17 +305,17 @@ pgp_elgamal_encrypt_mpi(const uint8_t *encoded_m_buf,
#if defined(HAVE_OPENSSL_BN_H)
skp->elgamal.g_to_k = BN_bin2bn(g_to_k, n / 2, NULL);
#elif defined(HAVE_GSKSSL)
skp->elgamal.g_to_k.data=malloc(n/2);
skp->elgamal.g_to_k.length=n/2;
memcpy(skp->elgamal.g_to_k.data,g_to_k,n/2);
skp->elgamal.g_to_k->data=malloc(n/2);
skp->elgamal.g_to_k->length=n/2;
memcpy(skp->elgamal.g_to_k->data,g_to_k,n/2);
#endif
#if defined(HAVE_OPENSSL_BN_H)
skp->elgamal.encrypted_m = BN_bin2bn(encmpibuf, n / 2, NULL);
#elif defined(HAVE_GSKSSL)
skp->elgamal.encrypted_m.data=malloc(n/2);
skp->elgamal.encrypted_m.length=n/2;
memcpy(skp->elgamal.encrypted_m.data,encmpibuf,n/2);
skp->elgamal.encrypted_m->data=malloc(n/2);
skp->elgamal.encrypted_m->length=n/2;
memcpy(skp->elgamal.encrypted_m->data,encmpibuf,n/2);
#endif
if (pgp_get_debug_level(__FILE__)) {
@ -325,8 +344,7 @@ write_parsed_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
puts("Skipping...");
cbinfo->printstate.skipping = 1;
}
if (fwrite(content->unarmoured_text.data, 1,
content->unarmoured_text.length, stdout) != content->unarmoured_text.length) {
if (fwrite(content->unarmoured_text.data, 1, content->unarmoured_text.length, stdout) != content->unarmoured_text.length) {
fprintf(stderr, "unable to write unarmoured text data\n");
cbinfo->printstate.skipping = 1;
}


Loading…
Cancel
Save