Browse Source

z/OS support: bit calculation

master
David Lanzendörfer 12 months ago
parent
commit
511504aa22
1 changed files with 32 additions and 23 deletions
  1. +32
    -23
      src/create.c

+ 32
- 23
src/create.c View File

@ -51,6 +51,16 @@
*/
#include "config.h"
/*
** Check to see if this machine uses EBCDIC. (Yes, believe it or
** not, there are still machines out there that use EBCDIC.)
*/
#if 'A' == '\301'
# define NETPGP_EBCDIC 1
#else
# define NETPGP_ASCII 1
#endif
#ifdef HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
@ -145,11 +155,18 @@ pgp_fast_create_userid(uint8_t **id, uint8_t *userid)
* \return 1 if OK, otherwise 0
*/
unsigned
pgp_write_struct_userid(pgp_output_t *output, const uint8_t*id)
pgp_write_struct_userid(pgp_output_t *output, const uint8_t *uid)
{
return pgp_write_ptag(output, PGP_PTAG_CT_USER_ID) &&
pgp_write_length(output, (unsigned)strlen((const char *) id)) &&
pgp_write(output, id, (unsigned)strlen((const char *) id));
char *id = (char *)uid;
unsigned len = (unsigned)strlen(id);
#if defined(NETPGP_EBCDIC)
// __e2a_l(id,len);
#endif
return (
pgp_write_ptag(output, PGP_PTAG_CT_USER_ID)
&& pgp_write_length(output, len)
&& pgp_write(output, id, len)
);
}
/**
@ -173,13 +190,13 @@ pgp_write_userid(const uint8_t *userid, pgp_output_t *output)
static unsigned
mpi_length(const BIGNUM *bn)
{
return (unsigned)(2 + (BN_num_bits(bn) + 7) / 8);
return (unsigned)(2 +(BN_num_bits(bn)+7)/8);
}
#elif defined(HAVE_GSKSSL)
static unsigned
mpi_length(gsk_buffer *bn)
{
return (unsigned)(2 + ( (bn->length*8-1) + 7) / 8);
return (unsigned)(2 + bn->length);
}
#endif
@ -200,8 +217,7 @@ pubkey_length(const pgp_pubkey_t *key)
mpi_length(key->key.elgamal.y);
default:
(void) fprintf(stderr,
"pubkey_length: unknown key algorithm\n");
(void) fprintf(stderr, "pubkey_length: unknown key algorithm\n");
}
return 0;
}
@ -225,8 +241,7 @@ seckey_length(const pgp_seckey_t *key)
mpi_length(key->key.dsa.x) + pubkey_length(&key->pubkey));
default:
(void) fprintf(stderr,
"seckey_length: unknown key algorithm\n");
(void) fprintf(stderr, "seckey_length: unknown key algorithm\n");
}
return 0;
}
@ -681,11 +696,9 @@ pgp_write_xfer_seckey(pgp_output_t *output,
*/
void
pgp_build_pubkey(pgp_memory_t *out, const pgp_pubkey_t *key,
unsigned make_packet)
pgp_build_pubkey(pgp_memory_t *out, const pgp_pubkey_t *key, unsigned make_packet)
{
pgp_output_t *output;
output = pgp_output_new();
pgp_memory_init(out, 128);
pgp_writer_set_memory(output, out);
@ -906,10 +919,9 @@ encode_m_buf(const uint8_t *M, size_t mLen, const pgp_pubkey_t * pubkey,
/* implementation of EME-PKCS1-v1_5-ENCODE, as defined in OpenPGP RFC */
switch (pubkey->alg) {
case PGP_PKA_RSA:
#ifdef HAVE_OPENSSL
#if defined(HAVE_OPENSSL)
k = (unsigned)BN_num_bytes(pubkey->key.rsa.n);
#endif
#ifdef HAVE_GSKSSL
#elif defined(HAVE_GSKSSL)
k = (unsigned)pubkey->key.rsa.n->length;
#endif
if (mLen > k - 11) {
@ -919,11 +931,10 @@ encode_m_buf(const uint8_t *M, size_t mLen, const pgp_pubkey_t * pubkey,
break;
case PGP_PKA_DSA:
case PGP_PKA_ELGAMAL:
#ifdef HAVE_OPENSSL
#if defined(HAVE_OPENSSL)
k = (unsigned)BN_num_bytes(pubkey->key.elgamal.p);
#endif
#ifdef HAVE_GSKSSL
k = pubkey->key.elgamal.p->length;
#elif defined(HAVE_GSKSSL)
k = (unsigned)pubkey->key.elgamal.p->length;
#endif
if (mLen > k - 11) {
(void) fprintf(stderr, "encode_m_buf: message too long\n");
@ -1122,8 +1133,7 @@ pgp_write_pk_sesskey(pgp_output_t *output, pgp_pk_sesskey_t *pksk)
{
/* XXX - Flexelint - Pointer parameter 'pksk' (line 1076) could be declared as pointing to const */
if (pksk == NULL) {
(void) fprintf(stderr,
"pgp_write_pk_sesskey: NULL pksk\n");
fprintf(stderr, "pgp_write_pk_sesskey: NULL pksk\n");
return 0;
}
switch (pksk->alg) {
@ -1146,7 +1156,6 @@ pgp_write_pk_sesskey(pgp_output_t *output, pgp_pk_sesskey_t *pksk)
case PGP_PKA_ELGAMAL:
return pgp_write_ptag(output, PGP_PTAG_CT_PK_SESSION_KEY) &&
pgp_write_length(output, (unsigned)(1 + 8 + 1 +
#if defined(HAVE_OPENSSL)
BN_num_bytes(pksk->params.elgamal.g_to_k)
#elif defined(HAVE_GSKSSL)


Loading…
Cancel
Save