1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

Fixed the ECC interface to Libgcrypt to be ABI compatible with the previous version.

Quite some changes were needed but in the end we have less code than
before.  Instead of trying to do everything with MPIs and pass them
back and forth between Libgcrypt and GnuPG, we know use the
S-expression based interface and make heavy use of our opaque MPI
feature.

Encryption, decryption, signing and verification work with
self-generared keys.

Import and export does not yet work; thus it was not possible to check
the test keys at https://sites.google.com/site/brainhub/pgpecckeys .
This commit is contained in:
Werner Koch 2011-01-31 15:44:24 +01:00
parent 0fb0bb8d9a
commit 328a642aa5
9 changed files with 119 additions and 147 deletions

View file

@ -157,8 +157,8 @@ build_packet( IOBUF out, PACKET *pkt )
/*
* Write the mpi A to OUT.
*/
static int
mpi_write (iobuf_t out, gcry_mpi_t a)
gpg_error_t
gpg_mpi_write (iobuf_t out, gcry_mpi_t a)
{
int rc;
@ -191,45 +191,6 @@ mpi_write (iobuf_t out, gcry_mpi_t a)
}
/*
* 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;
if (nbytes > sizeof(buffer))
{
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. */
u32
calc_packet_length( PACKET *pkt )
@ -341,7 +302,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
for (i=0; i < npkey; i++ )
{
err = mpi_write (a, pk->pkey[i]);
err = gpg_mpi_write (a, pk->pkey[i]);
if (err)
goto leave;
}
@ -436,7 +397,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
{
/* Non-protected key. */
for ( ; i < nskey; i++ )
if ( (err = mpi_write (a, pk->pkey[i])))
if ( (err = gpg_mpi_write (a, pk->pkey[i])))
goto leave;
write_16 (a, ski->csum );
}
@ -512,7 +473,7 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
write_fake_data( a, enc->data[0] );
for (i=0; i < n && !rc ; i++ )
rc = mpi_write (a, enc->data[i]);
rc = gpg_mpi_write (a, enc->data[i]);
if (!rc)
{
@ -1170,7 +1131,7 @@ do_signature( IOBUF out, int ctb, PKT_signature *sig )
if ( !n )
write_fake_data( a, sig->data[0] );
for (i=0; i < n && !rc ; i++ )
rc = mpi_write(a, sig->data[i] );
rc = gpg_mpi_write (a, sig->data[i] );
if (!rc)
{