mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-31 11:41:32 +01:00
Function name cleanups
Also nuked some trailing spaces.
This commit is contained in:
parent
d879c287ac
commit
358afc0dc8
@ -1,3 +1,15 @@
|
|||||||
|
2011-01-26 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
|
* misc.c (ecdsa_qbits_from_Q): Use unsigned int.
|
||||||
|
|
||||||
|
* misc.c (iobuf_read_size_body): Move and rename to ..
|
||||||
|
* parse-packet.c (read_size_body): .. here. Make static.
|
||||||
|
* misc.c (iobuf_write_size_body_mpi): Move and rename to ..
|
||||||
|
* build-packet.c (write_size_body_mpi): .. here.
|
||||||
|
(iobuf_name_oid_write, ecdh_kek_params_write, ecdh_esk_write):
|
||||||
|
Remove macros. Replace users by direct calls to
|
||||||
|
write_size_body_mpi.
|
||||||
|
|
||||||
2011-01-25 Werner Koch <wk@g10code.com>
|
2011-01-25 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
* ecdh.c (pk_ecdh_default_params_to_mpi): Remove.
|
* ecdh.c (pk_ecdh_default_params_to_mpi): Remove.
|
||||||
|
@ -178,17 +178,44 @@ mpi_write (iobuf_t out, gcry_mpi_t a)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the name OID, encoded as an mpi, to OUT. The format of the
|
|
||||||
* content of the MPI is one byte LEN, following by LEN bytes that are
|
|
||||||
* DER representation of an ASN.1 OID. This is true for each of the 3
|
|
||||||
* following functions. */
|
|
||||||
#define iobuf_name_oid_write iobuf_write_size_body_mpi
|
|
||||||
|
|
||||||
/* Write the value of KEK fields for ECDH. */
|
/*
|
||||||
#define ecdh_kek_params_write iobuf_write_size_body_mpi
|
* Write a special size+body mpi A, to OUT. The format of the content
|
||||||
|
* of the MPI is one byte LEN, following by LEN bytes.
|
||||||
|
*/
|
||||||
|
gpg_error_t
|
||||||
|
write_size_body_mpi (iobuf_t out, gcry_mpi_t a)
|
||||||
|
{
|
||||||
|
gpg_error_t err;
|
||||||
|
byte buffer[256]; /* Fixed buffer for a public parameter, max possible */
|
||||||
|
size_t nbytes = (mpi_get_nbits (a)+7)/8;
|
||||||
|
|
||||||
/* Write the value of encrypted filed for ECDH. */
|
if (nbytes > sizeof(buffer))
|
||||||
#define ecdh_esk_write iobuf_write_size_body_mpi
|
{
|
||||||
|
log_error("mpi with size+body is too large (%u bytes)\n", nbytes);
|
||||||
|
return gpg_error (GPG_ERR_TOO_LARGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gcry_mpi_print (GCRYMPI_FMT_USG, buffer, sizeof(buffer), &nbytes, a);
|
||||||
|
if (err)
|
||||||
|
{
|
||||||
|
log_error ("failed to exported size+body mpi\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
if (nbytes < 2 || buffer[0] != nbytes-1)
|
||||||
|
{
|
||||||
|
if (nbytes > 2)
|
||||||
|
log_error ("internal size mismatch in mpi size+body: "
|
||||||
|
"%02x != %02x (other bytes: %02x %02x ... %02x %02x)\n",
|
||||||
|
buffer[0], nbytes-1, buffer[1], buffer[2], buffer[nbytes-2],
|
||||||
|
buffer[nbytes-1]);
|
||||||
|
else
|
||||||
|
log_error ("internal size mismatch in mpi size+body: "
|
||||||
|
"only %d bytes\n", nbytes);
|
||||||
|
return gpg_error (GPG_ERR_INV_DATA);
|
||||||
|
}
|
||||||
|
return iobuf_write (out, buffer, nbytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Calculate the length of a packet described by PKT. */
|
/* Calculate the length of a packet described by PKT. */
|
||||||
@ -228,11 +255,11 @@ calc_packet_length( PACKET *pkt )
|
|||||||
static void
|
static void
|
||||||
write_fake_data (IOBUF out, gcry_mpi_t a)
|
write_fake_data (IOBUF out, gcry_mpi_t a)
|
||||||
{
|
{
|
||||||
if (a)
|
if (a)
|
||||||
{
|
{
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
p = gcry_mpi_get_opaque ( a, &n );
|
p = gcry_mpi_get_opaque ( a, &n );
|
||||||
iobuf_write (out, p, (n+7)/8 );
|
iobuf_write (out, p, (n+7)/8 );
|
||||||
}
|
}
|
||||||
@ -281,18 +308,18 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
ndays = 0;
|
ndays = 0;
|
||||||
write_16(a, ndays);
|
write_16(a, ndays);
|
||||||
}
|
}
|
||||||
|
|
||||||
iobuf_put (a, pk->pubkey_algo );
|
iobuf_put (a, pk->pubkey_algo );
|
||||||
|
|
||||||
/* Get number of secret and public parameters. They are held in one
|
/* Get number of secret and public parameters. They are held in one
|
||||||
array first the public ones, then the secret ones. */
|
array first the public ones, then the secret ones. */
|
||||||
nskey = pubkey_get_nskey (pk->pubkey_algo);
|
nskey = pubkey_get_nskey (pk->pubkey_algo);
|
||||||
npkey = pubkey_get_npkey (pk->pubkey_algo);
|
npkey = pubkey_get_npkey (pk->pubkey_algo);
|
||||||
|
|
||||||
/* If we don't have any public parameters - which is the case if we
|
/* If we don't have any public parameters - which is the case if we
|
||||||
don't know the algorithm used - the parameters are stored as one
|
don't know the algorithm used - the parameters are stored as one
|
||||||
blob in a faked (opaque) MPI. */
|
blob in a faked (opaque) MPI. */
|
||||||
if (!npkey)
|
if (!npkey)
|
||||||
{
|
{
|
||||||
write_fake_data (a, pk->pkey[0]);
|
write_fake_data (a, pk->pkey[0]);
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -305,7 +332,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
{
|
{
|
||||||
/* Write DER of OID with preceeding length byte. */
|
/* Write DER of OID with preceeding length byte. */
|
||||||
err = iobuf_name_oid_write (a, pk->pkey[0]);
|
err = write_size_body_mpi (a, pk->pkey[0]);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
/* Write point Q, the public key. */
|
/* Write point Q, the public key. */
|
||||||
@ -316,7 +343,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
/* Write one more public field for ECDH. */
|
/* Write one more public field for ECDH. */
|
||||||
if (pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
if (pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
{
|
{
|
||||||
err = ecdh_kek_params_write(a,pk->pkey[2]);
|
err = write_size_body_mpi (a, pk->pkey[2]);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -328,14 +355,14 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (pk->seckey_info)
|
if (pk->seckey_info)
|
||||||
{
|
{
|
||||||
/* This is a secret key packet. */
|
/* This is a secret key packet. */
|
||||||
struct seckey_info *ski = pk->seckey_info;
|
struct seckey_info *ski = pk->seckey_info;
|
||||||
|
|
||||||
/* Build the header for protected (encrypted) secret parameters. */
|
/* Build the header for protected (encrypted) secret parameters. */
|
||||||
if (ski->is_protected)
|
if (ski->is_protected)
|
||||||
{
|
{
|
||||||
if ( is_RSA (pk->pubkey_algo) && pk->version < 4 && !ski->s2k.mode )
|
if ( is_RSA (pk->pubkey_algo) && pk->version < 4 && !ski->s2k.mode )
|
||||||
{
|
{
|
||||||
@ -355,12 +382,12 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
viewed as a private/experimental extension (this
|
viewed as a private/experimental extension (this
|
||||||
is not specified in rfc2440 but the same scheme
|
is not specified in rfc2440 but the same scheme
|
||||||
is used for all other algorithm identifiers). */
|
is used for all other algorithm identifiers). */
|
||||||
iobuf_put (a, 101);
|
iobuf_put (a, 101);
|
||||||
iobuf_put (a, ski->s2k.hash_algo);
|
iobuf_put (a, ski->s2k.hash_algo);
|
||||||
iobuf_write (a, "GNU", 3 );
|
iobuf_write (a, "GNU", 3 );
|
||||||
iobuf_put (a, ski->s2k.mode - 1000);
|
iobuf_put (a, ski->s2k.mode - 1000);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
iobuf_put (a, ski->s2k.mode);
|
iobuf_put (a, ski->s2k.mode);
|
||||||
iobuf_put (a, ski->s2k.hash_algo);
|
iobuf_put (a, ski->s2k.hash_algo);
|
||||||
@ -370,7 +397,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
iobuf_write (a, ski->s2k.salt, 8);
|
iobuf_write (a, ski->s2k.salt, 8);
|
||||||
|
|
||||||
if (ski->s2k.mode == 3)
|
if (ski->s2k.mode == 3)
|
||||||
iobuf_put (a, ski->s2k.count);
|
iobuf_put (a, ski->s2k.count);
|
||||||
|
|
||||||
/* For our special modes 1001, 1002 we do not need an IV. */
|
/* For our special modes 1001, 1002 we do not need an IV. */
|
||||||
if (ski->s2k.mode != 1001 && ski->s2k.mode != 1002)
|
if (ski->s2k.mode != 1001 && ski->s2k.mode != 1002)
|
||||||
@ -381,10 +408,10 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
iobuf_put (a, 0 );
|
iobuf_put (a, 0 );
|
||||||
|
|
||||||
if (ski->s2k.mode == 1001)
|
if (ski->s2k.mode == 1001)
|
||||||
; /* GnuPG extension - don't write a secret key at all. */
|
; /* GnuPG extension - don't write a secret key at all. */
|
||||||
else if (ski->s2k.mode == 1002)
|
else if (ski->s2k.mode == 1002)
|
||||||
{
|
{
|
||||||
/* GnuPG extension - divert to OpenPGP smartcard. */
|
/* GnuPG extension - divert to OpenPGP smartcard. */
|
||||||
/* Length of the serial number or 0 for no serial number. */
|
/* Length of the serial number or 0 for no serial number. */
|
||||||
iobuf_put (a, ski->ivlen );
|
iobuf_put (a, ski->ivlen );
|
||||||
/* The serial number gets stored in the IV field. */
|
/* The serial number gets stored in the IV field. */
|
||||||
@ -395,19 +422,19 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
/* The secret key is protected - write it out as it is. */
|
/* The secret key is protected - write it out as it is. */
|
||||||
byte *p;
|
byte *p;
|
||||||
unsigned int ndatabits;
|
unsigned int ndatabits;
|
||||||
|
|
||||||
assert (gcry_mpi_get_flag (pk->pkey[npkey], GCRYMPI_FLAG_OPAQUE));
|
assert (gcry_mpi_get_flag (pk->pkey[npkey], GCRYMPI_FLAG_OPAQUE));
|
||||||
p = gcry_mpi_get_opaque (pk->pkey[npkey], &ndatabits);
|
p = gcry_mpi_get_opaque (pk->pkey[npkey], &ndatabits);
|
||||||
iobuf_write (a, p, (ndatabits+7)/8 );
|
iobuf_write (a, p, (ndatabits+7)/8 );
|
||||||
}
|
}
|
||||||
else if (ski->is_protected)
|
else if (ski->is_protected)
|
||||||
{
|
{
|
||||||
/* The secret key is protected the old v4 way. */
|
/* The secret key is protected the old v4 way. */
|
||||||
for ( ; i < nskey; i++ )
|
for ( ; i < nskey; i++ )
|
||||||
{
|
{
|
||||||
byte *p;
|
byte *p;
|
||||||
unsigned int ndatabits;
|
unsigned int ndatabits;
|
||||||
|
|
||||||
assert (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_OPAQUE));
|
assert (gcry_mpi_get_flag (pk->pkey[i], GCRYMPI_FLAG_OPAQUE));
|
||||||
p = gcry_mpi_get_opaque (pk->pkey[i], &ndatabits);
|
p = gcry_mpi_get_opaque (pk->pkey[i], &ndatabits);
|
||||||
iobuf_write (a, p, (ndatabits+7)/8);
|
iobuf_write (a, p, (ndatabits+7)/8);
|
||||||
@ -476,9 +503,9 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
int n, i;
|
int n, i;
|
||||||
IOBUF a = iobuf_temp();
|
IOBUF a = iobuf_temp();
|
||||||
|
|
||||||
write_version( a, ctb );
|
write_version( a, ctb );
|
||||||
if ( enc->throw_keyid )
|
if ( enc->throw_keyid )
|
||||||
{
|
{
|
||||||
write_32(a, 0 ); /* Don't tell Eve who can decrypt the message. */
|
write_32(a, 0 ); /* Don't tell Eve who can decrypt the message. */
|
||||||
write_32(a, 0 );
|
write_32(a, 0 );
|
||||||
@ -500,7 +527,7 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
|
|||||||
assert (n == 2);
|
assert (n == 2);
|
||||||
rc = mpi_write (a, enc->data[0]);
|
rc = mpi_write (a, enc->data[0]);
|
||||||
if (!rc)
|
if (!rc)
|
||||||
rc = ecdh_esk_write (a, enc->data[1]);
|
rc = write_size_body_mpi (a, enc->data[1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -545,7 +572,7 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
|
|||||||
for(i=0; i < pt->namelen; i++ )
|
for(i=0; i < pt->namelen; i++ )
|
||||||
iobuf_put(out, pt->name[i] );
|
iobuf_put(out, pt->name[i] );
|
||||||
rc = write_32(out, pt->timestamp );
|
rc = write_32(out, pt->timestamp );
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
@ -661,7 +688,7 @@ delete_sig_subpkt (subpktarea_t *area, sigsubpkttype_t reqtype )
|
|||||||
}
|
}
|
||||||
if( buflen < n )
|
if( buflen < n )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
type = *buffer & 0x7f;
|
type = *buffer & 0x7f;
|
||||||
if( type == reqtype ) {
|
if( type == reqtype ) {
|
||||||
buffer++;
|
buffer++;
|
||||||
@ -695,7 +722,7 @@ delete_sig_subpkt (subpktarea_t *area, sigsubpkttype_t reqtype )
|
|||||||
* Note: All pointers into sig->[un]hashed (e.g. returned by
|
* Note: All pointers into sig->[un]hashed (e.g. returned by
|
||||||
* parse_sig_subpkt) are not valid after a call to this function. The
|
* parse_sig_subpkt) are not valid after a call to this function. The
|
||||||
* data to put into the subpaket should be in a buffer with a length
|
* data to put into the subpaket should be in a buffer with a length
|
||||||
* of buflen.
|
* of buflen.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
build_sig_subpkt (PKT_signature *sig, sigsubpkttype_t type,
|
build_sig_subpkt (PKT_signature *sig, sigsubpkttype_t type,
|
||||||
@ -798,7 +825,7 @@ build_sig_subpkt (PKT_signature *sig, sigsubpkttype_t type,
|
|||||||
case SIGSUBPKT_SIGNATURE:
|
case SIGSUBPKT_SIGNATURE:
|
||||||
hashed = 0;
|
hashed = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
hashed = 1;
|
hashed = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -849,7 +876,7 @@ build_sig_subpkt (PKT_signature *sig, sigsubpkttype_t type,
|
|||||||
memcpy (p, buffer, buflen);
|
memcpy (p, buffer, buflen);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashed)
|
if (hashed)
|
||||||
sig->hashed = newarea;
|
sig->hashed = newarea;
|
||||||
else
|
else
|
||||||
sig->unhashed = newarea;
|
sig->unhashed = newarea;
|
||||||
@ -1135,7 +1162,7 @@ do_signature( IOBUF out, int ctb, PKT_signature *sig )
|
|||||||
if ( sig->version < 4 )
|
if ( sig->version < 4 )
|
||||||
iobuf_put (a, 5 ); /* Constant */
|
iobuf_put (a, 5 ); /* Constant */
|
||||||
iobuf_put (a, sig->sig_class );
|
iobuf_put (a, sig->sig_class );
|
||||||
if ( sig->version < 4 )
|
if ( sig->version < 4 )
|
||||||
{
|
{
|
||||||
write_32(a, sig->timestamp );
|
write_32(a, sig->timestamp );
|
||||||
write_32(a, sig->keyid[0] );
|
write_32(a, sig->keyid[0] );
|
||||||
@ -1143,7 +1170,7 @@ do_signature( IOBUF out, int ctb, PKT_signature *sig )
|
|||||||
}
|
}
|
||||||
iobuf_put(a, sig->pubkey_algo );
|
iobuf_put(a, sig->pubkey_algo );
|
||||||
iobuf_put(a, sig->digest_algo );
|
iobuf_put(a, sig->digest_algo );
|
||||||
if ( sig->version >= 4 )
|
if ( sig->version >= 4 )
|
||||||
{
|
{
|
||||||
size_t nn;
|
size_t nn;
|
||||||
/* Timestamp and keyid must have been packed into the subpackets
|
/* Timestamp and keyid must have been packed into the subpackets
|
||||||
|
@ -161,7 +161,7 @@ pk_ecdh_encrypt_with_shared_point (int is_encrypt, gcry_mpi_t shared_mpi,
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
IOBUF obuf = iobuf_temp();
|
IOBUF obuf = iobuf_temp();
|
||||||
err = iobuf_write_size_body_mpi ( obuf, pkey[2] ); /* KEK params */
|
err = write_size_body_mpi (obuf, pkey[2]); /* KEK params */
|
||||||
|
|
||||||
kdf_params_size = iobuf_temp_to_buffer (obuf,
|
kdf_params_size = iobuf_temp_to_buffer (obuf,
|
||||||
kdf_params, sizeof(kdf_params));
|
kdf_params, sizeof(kdf_params));
|
||||||
@ -198,11 +198,11 @@ pk_ecdh_encrypt_with_shared_point (int is_encrypt, gcry_mpi_t shared_mpi,
|
|||||||
|
|
||||||
obuf = iobuf_temp();
|
obuf = iobuf_temp();
|
||||||
/* variable-length field 1, curve name OID */
|
/* variable-length field 1, curve name OID */
|
||||||
err = iobuf_write_size_body_mpi ( obuf, pkey[0] );
|
err = write_size_body_mpi (obuf, pkey[0]);
|
||||||
/* fixed-length field 2 */
|
/* fixed-length field 2 */
|
||||||
iobuf_put (obuf, PUBKEY_ALGO_ECDH);
|
iobuf_put (obuf, PUBKEY_ALGO_ECDH);
|
||||||
/* variable-length field 3, KDF params */
|
/* variable-length field 3, KDF params */
|
||||||
err = (err ? err : iobuf_write_size_body_mpi ( obuf, pkey[2] ));
|
err = (err ? err : write_size_body_mpi ( obuf, pkey[2] ));
|
||||||
/* fixed-length field 4 */
|
/* fixed-length field 4 */
|
||||||
iobuf_write (obuf, "Anonymous Sender ", 20);
|
iobuf_write (obuf, "Anonymous Sender ", 20);
|
||||||
/* fixed-length field 5, recipient fp */
|
/* fixed-length field 5, recipient fp */
|
||||||
|
@ -161,11 +161,7 @@ int pubkey_get_nsig( int algo );
|
|||||||
int pubkey_get_nenc( int algo );
|
int pubkey_get_nenc( int algo );
|
||||||
unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
|
unsigned int pubkey_nbits( int algo, gcry_mpi_t *pkey );
|
||||||
int mpi_print (estream_t stream, gcry_mpi_t a, int mode);
|
int mpi_print (estream_t stream, gcry_mpi_t a, int mode);
|
||||||
int iobuf_write_size_body_mpi (iobuf_t out, gcry_mpi_t a);
|
unsigned int ecdsa_qbits_from_Q (unsigned int qbits);
|
||||||
int iobuf_read_size_body (iobuf_t inp, byte *body, int body_max_size,
|
|
||||||
int pktlen, gcry_mpi_t *out);
|
|
||||||
|
|
||||||
int ecdsa_qbits_from_Q( int qbits );
|
|
||||||
|
|
||||||
/*-- status.c --*/
|
/*-- status.c --*/
|
||||||
void set_status_fd ( int fd );
|
void set_status_fd ( int fd );
|
||||||
|
92
g10/misc.c
92
g10/misc.c
@ -1459,7 +1459,6 @@ pubkey_nbits( int algo, gcry_mpi_t *key )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* FIXME: Use gcry_mpi_print directly. */
|
|
||||||
int
|
int
|
||||||
mpi_print (estream_t fp, gcry_mpi_t a, int mode)
|
mpi_print (estream_t fp, gcry_mpi_t a, int mode)
|
||||||
{
|
{
|
||||||
@ -1487,98 +1486,15 @@ mpi_print (estream_t fp, gcry_mpi_t a, int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Write a special size+body mpi A, to OUT. The format of the content
|
|
||||||
* of the MPI is one byte LEN, following by LEN bytes.
|
|
||||||
*/
|
|
||||||
/* FIXME: Rename this function: it is not in iobuf.c */
|
|
||||||
int
|
|
||||||
iobuf_write_size_body_mpi (iobuf_t out, gcry_mpi_t a)
|
|
||||||
{
|
|
||||||
byte buffer[256]; /* Fixed buffer for a public parameter, max possible */
|
|
||||||
size_t nbytes = (mpi_get_nbits (a)+7)/8;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if( nbytes > sizeof(buffer) ) {
|
|
||||||
log_error("mpi with size+body is too large (%u bytes)\n", nbytes);
|
|
||||||
return gpg_error (GPG_ERR_TOO_LARGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = gcry_mpi_print (GCRYMPI_FMT_USG, buffer, sizeof(buffer), &nbytes, a);
|
|
||||||
if( rc ) {
|
|
||||||
log_error("Failed to exported size+body mpi\n");
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
if( nbytes < 2 || buffer[0] != nbytes-1 ) {
|
|
||||||
if( nbytes > 2 )
|
|
||||||
log_error("Internal size mismatch in mpi size+body: %02x != %02x (other bytes: %02x %02x ... %02x %02x)\n",
|
|
||||||
buffer[0], nbytes-1, buffer[1], buffer[2], buffer[nbytes-2], buffer[nbytes-1]);
|
|
||||||
else
|
|
||||||
log_error("Internal size mismatch in mpi size+body: only %d bytes\n", nbytes );
|
|
||||||
return gpg_error (GPG_ERR_INV_DATA);
|
|
||||||
}
|
|
||||||
return iobuf_write( out, buffer, nbytes );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Read a special size+body from inp into body[body_max_size] and
|
|
||||||
* return it in a buffer and as MPI. On success the number of
|
|
||||||
* consumed bytes will body[0]+1. The format of the content of the
|
|
||||||
* returned MPI is one byte LEN, following by LEN bytes. Caller is
|
|
||||||
* expected to pre-allocate fixed-size 255 byte buffer (or smaller
|
|
||||||
* when appropriate).
|
|
||||||
*/
|
|
||||||
/* FIXME: Rename this function: it is not in iobuf.c */
|
|
||||||
int
|
|
||||||
iobuf_read_size_body (iobuf_t inp, byte *body, int body_max_size,
|
|
||||||
int pktlen, gcry_mpi_t *out )
|
|
||||||
{
|
|
||||||
unsigned n;
|
|
||||||
int rc;
|
|
||||||
gcry_mpi_t result;
|
|
||||||
|
|
||||||
*out = NULL;
|
|
||||||
|
|
||||||
if( (n = iobuf_readbyte(inp)) == -1 )
|
|
||||||
{
|
|
||||||
return G10ERR_INVALID_PACKET;
|
|
||||||
}
|
|
||||||
if ( n >= body_max_size || n < 2)
|
|
||||||
{
|
|
||||||
log_error("invalid size+body field\n");
|
|
||||||
return G10ERR_INVALID_PACKET;
|
|
||||||
}
|
|
||||||
body[0] = n;
|
|
||||||
if ((n = iobuf_read(inp, body+1, n)) == -1)
|
|
||||||
{
|
|
||||||
log_error("invalid size+body field\n");
|
|
||||||
return G10ERR_INVALID_PACKET;
|
|
||||||
}
|
|
||||||
if (n+1 > pktlen)
|
|
||||||
{
|
|
||||||
log_error("size+body field is larger than the packet\n");
|
|
||||||
return G10ERR_INVALID_PACKET;
|
|
||||||
}
|
|
||||||
rc = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, body, n+1, NULL);
|
|
||||||
if (rc)
|
|
||||||
log_fatal ("mpi_scan failed: %s\n", gpg_strerror (rc));
|
|
||||||
|
|
||||||
*out = result;
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* pkey[1] or skey[1] is Q for ECDSA, which is an uncompressed point,
|
/* pkey[1] or skey[1] is Q for ECDSA, which is an uncompressed point,
|
||||||
i.e. 04 <x> <y> */
|
i.e. 04 <x> <y> */
|
||||||
int
|
unsigned int
|
||||||
ecdsa_qbits_from_Q (int qbits )
|
ecdsa_qbits_from_Q (unsigned int qbits)
|
||||||
{
|
{
|
||||||
if ((qbits%8) > 3)
|
if ((qbits%8) > 3)
|
||||||
{
|
{
|
||||||
log_error(_("ECDSA public key is expected to be in SEC encoding "
|
log_error (_("ECDSA public key is expected to be in SEC encoding "
|
||||||
"multiple of 8 bits\n"));
|
"multiple of 8 bits\n"));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
qbits -= qbits%8;
|
qbits -= qbits%8;
|
||||||
|
@ -444,6 +444,7 @@ PACKET *create_gpg_control ( ctrlpkttype_t type,
|
|||||||
|
|
||||||
/*-- build-packet.c --*/
|
/*-- build-packet.c --*/
|
||||||
int build_packet( iobuf_t inp, PACKET *pkt );
|
int build_packet( iobuf_t inp, PACKET *pkt );
|
||||||
|
gpg_error_t write_size_body_mpi (iobuf_t out, gcry_mpi_t a);
|
||||||
u32 calc_packet_length( PACKET *pkt );
|
u32 calc_packet_length( PACKET *pkt );
|
||||||
void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
|
void build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
|
||||||
const byte *buffer, size_t buflen );
|
const byte *buffer, size_t buflen );
|
||||||
|
@ -741,6 +741,55 @@ read_rest (IOBUF inp, size_t pktlen, int partial)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read a special size+body from inp into body[body_max_size] and
|
||||||
|
* return it in a buffer and as MPI. On success the number of
|
||||||
|
* consumed bytes will body[0]+1. The format of the content of the
|
||||||
|
* returned MPI is one byte LEN, following by LEN bytes. Caller is
|
||||||
|
* expected to pre-allocate fixed-size 255 byte buffer (or smaller
|
||||||
|
* when appropriate).
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
read_size_body (iobuf_t inp, byte *body, int body_max_size,
|
||||||
|
int pktlen, gcry_mpi_t *out )
|
||||||
|
{
|
||||||
|
unsigned int n;
|
||||||
|
int rc;
|
||||||
|
gcry_mpi_t result;
|
||||||
|
|
||||||
|
*out = NULL;
|
||||||
|
|
||||||
|
if( (n = iobuf_readbyte(inp)) == -1 )
|
||||||
|
{
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
if ( n >= body_max_size || n < 2)
|
||||||
|
{
|
||||||
|
log_error("invalid size+body field\n");
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
body[0] = n;
|
||||||
|
if ((n = iobuf_read(inp, body+1, n)) == -1)
|
||||||
|
{
|
||||||
|
log_error("invalid size+body field\n");
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
if (n+1 > pktlen)
|
||||||
|
{
|
||||||
|
log_error("size+body field is larger than the packet\n");
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
rc = gcry_mpi_scan (&result, GCRYMPI_FMT_USG, body, n+1, NULL);
|
||||||
|
if (rc)
|
||||||
|
log_fatal ("mpi_scan failed: %s\n", gpg_strerror (rc));
|
||||||
|
|
||||||
|
*out = result;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse a marker packet. */
|
||||||
static int
|
static int
|
||||||
parse_marker (IOBUF inp, int pkttype, unsigned long pktlen)
|
parse_marker (IOBUF inp, int pkttype, unsigned long pktlen)
|
||||||
{
|
{
|
||||||
@ -947,8 +996,8 @@ parse_pubkeyenc (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
n = pktlen;
|
n = pktlen;
|
||||||
k->data[0] = mpi_read (inp, &n, 0);
|
k->data[0] = mpi_read (inp, &n, 0);
|
||||||
pktlen -= n;
|
pktlen -= n;
|
||||||
rc = iobuf_read_size_body (inp, encr_buf, sizeof(encr_buf),
|
rc = read_size_body (inp, encr_buf, sizeof(encr_buf),
|
||||||
pktlen, k->data+1);
|
pktlen, k->data+1);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
@ -1958,8 +2007,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
/* FIXME: The code in this function ignores the errors. */
|
/* FIXME: The code in this function ignores the errors. */
|
||||||
byte name_oid[256];
|
byte name_oid[256];
|
||||||
|
|
||||||
err = iobuf_read_size_body (inp, name_oid, sizeof(name_oid),
|
err = read_size_body (inp, name_oid, sizeof(name_oid),
|
||||||
pktlen, pk->pkey+0);
|
pktlen, pk->pkey+0);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
n = name_oid[0];
|
n = name_oid[0];
|
||||||
@ -1984,8 +2033,8 @@ parse_key (IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
if (algorithm == PUBKEY_ALGO_ECDH)
|
if (algorithm == PUBKEY_ALGO_ECDH)
|
||||||
{
|
{
|
||||||
/* (NAMEOID holds the KEK params.) */
|
/* (NAMEOID holds the KEK params.) */
|
||||||
err = iobuf_read_size_body (inp, name_oid, sizeof(name_oid),
|
err = read_size_body (inp, name_oid, sizeof(name_oid),
|
||||||
pktlen, pk->pkey+2);
|
pktlen, pk->pkey+2);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
n = name_oid[0];
|
n = name_oid[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user