mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-23 10:29:58 +01:00
ecc-sos: SOS as Strange Octet String.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
1c4291c395
commit
2fc7fbc46b
@ -349,13 +349,13 @@ gpg_mpi_write (iobuf_t out, gcry_mpi_t a, unsigned int *r_nwritten)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write the mpi A to the output stream OUT as "SOS" (Simply Octet
|
* Write the mpi A to the output stream OUT as "SOS" (Strange Octet
|
||||||
* String). If R_NWRITTEN is not NULL the number of bytes written is
|
* String). If R_NWRITTEN is not NULL the number of bytes written is
|
||||||
* stored there. To only get the number of bytes which would be
|
* stored there. To only get the number of bytes which would be
|
||||||
* written, NULL may be passed for OUT.
|
* written, NULL may be passed for OUT.
|
||||||
*/
|
*/
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
sos_write (iobuf_t out, gcry_mpi_t a, unsigned int *r_nwritten, int compat)
|
sos_write (iobuf_t out, gcry_mpi_t a, unsigned int *r_nwritten)
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
unsigned int nwritten = 0;
|
unsigned int nwritten = 0;
|
||||||
@ -371,7 +371,7 @@ sos_write (iobuf_t out, gcry_mpi_t a, unsigned int *r_nwritten, int compat)
|
|||||||
/* gcry_log_debug (" [%u bit]\n", nbits); */
|
/* gcry_log_debug (" [%u bit]\n", nbits); */
|
||||||
/* gcry_log_debughex (" ", p, (nbits+7)/8); */
|
/* gcry_log_debughex (" ", p, (nbits+7)/8); */
|
||||||
|
|
||||||
if (p && *p && compat)
|
if (p && *p)
|
||||||
{
|
{
|
||||||
nbits = ((nbits + 7) / 8) * 8;
|
nbits = ((nbits + 7) / 8) * 8;
|
||||||
|
|
||||||
@ -620,13 +620,12 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
|
|
||||||
for (i=0; i < npkey; i++ )
|
for (i=0; i < npkey; i++ )
|
||||||
{
|
{
|
||||||
/* FIXME: For newer curve, sos_write should be called with COMPAT=0. */
|
|
||||||
if ( (pk->pubkey_algo == PUBKEY_ALGO_ECDSA && (i == 0))
|
if ( (pk->pubkey_algo == PUBKEY_ALGO_ECDSA && (i == 0))
|
||||||
|| (pk->pubkey_algo == PUBKEY_ALGO_EDDSA && (i == 0))
|
|| (pk->pubkey_algo == PUBKEY_ALGO_EDDSA && (i == 0))
|
||||||
|| (pk->pubkey_algo == PUBKEY_ALGO_ECDH && (i == 0 || i == 2)))
|
|| (pk->pubkey_algo == PUBKEY_ALGO_ECDH && (i == 0 || i == 2)))
|
||||||
err = gpg_mpi_write_nohdr (a, pk->pkey[i]);
|
err = gpg_mpi_write_nohdr (a, pk->pkey[i]);
|
||||||
else if (pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
else if (pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
err = sos_write (a, pk->pkey[i], NULL, 1);
|
err = sos_write (a, pk->pkey[i], NULL);
|
||||||
else
|
else
|
||||||
err = gpg_mpi_write (a, pk->pkey[i], NULL);
|
err = gpg_mpi_write (a, pk->pkey[i], NULL);
|
||||||
if (err)
|
if (err)
|
||||||
@ -741,13 +740,12 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
unsigned int n;
|
unsigned int n;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
/* FIXME: For newer curve, sos_write should be called with COMPAT=0. */
|
|
||||||
for (j=i; j < nskey; j++ )
|
for (j=i; j < nskey; j++ )
|
||||||
{
|
{
|
||||||
if (pk->pubkey_algo == PUBKEY_ALGO_EDDSA
|
if (pk->pubkey_algo == PUBKEY_ALGO_EDDSA
|
||||||
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
{
|
{
|
||||||
if ((err = sos_write (NULL, pk->pkey[j], &n, 1)))
|
if ((err = sos_write (NULL, pk->pkey[j], &n)))
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -765,8 +763,7 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
|
|||||||
if (pk->pubkey_algo == PUBKEY_ALGO_EDDSA
|
if (pk->pubkey_algo == PUBKEY_ALGO_EDDSA
|
||||||
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
|| pk->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
{
|
{
|
||||||
/* FIXME: For newer curve, sos_write should be called with COMPAT=0. */
|
if ((err = sos_write (a, pk->pkey[i], NULL)))
|
||||||
if ( (err = sos_write (a, pk->pkey[i], NULL, 1)))
|
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -888,8 +885,7 @@ do_pubkey_enc( IOBUF out, int ctb, PKT_pubkey_enc *enc )
|
|||||||
if (enc->pubkey_algo == PUBKEY_ALGO_ECDH && i == 1)
|
if (enc->pubkey_algo == PUBKEY_ALGO_ECDH && i == 1)
|
||||||
rc = gpg_mpi_write_nohdr (a, enc->data[i]);
|
rc = gpg_mpi_write_nohdr (a, enc->data[i]);
|
||||||
else if (enc->pubkey_algo == PUBKEY_ALGO_ECDH)
|
else if (enc->pubkey_algo == PUBKEY_ALGO_ECDH)
|
||||||
/* FIXME: For newer curve, sos_write should be called with COMPAT=0. */
|
rc = sos_write (a, enc->data[i], NULL);
|
||||||
rc = sos_write (a, enc->data[i], NULL, 1);
|
|
||||||
else
|
else
|
||||||
rc = gpg_mpi_write (a, enc->data[i], NULL);
|
rc = gpg_mpi_write (a, enc->data[i], NULL);
|
||||||
}
|
}
|
||||||
@ -1769,10 +1765,9 @@ do_signature( IOBUF out, int ctb, PKT_signature *sig )
|
|||||||
n = pubkey_get_nsig( sig->pubkey_algo );
|
n = pubkey_get_nsig( sig->pubkey_algo );
|
||||||
if ( !n )
|
if ( !n )
|
||||||
write_fake_data( a, sig->data[0] );
|
write_fake_data( a, sig->data[0] );
|
||||||
/* FIXME: For newer curve, sos_write should be called with COMPAT=0. */
|
|
||||||
if (sig->pubkey_algo == PUBKEY_ALGO_EDDSA)
|
if (sig->pubkey_algo == PUBKEY_ALGO_EDDSA)
|
||||||
for (i=0; i < n && !rc ; i++ )
|
for (i=0; i < n && !rc ; i++ )
|
||||||
rc = sos_write (a, sig->data[i], NULL, 1);
|
rc = sos_write (a, sig->data[i], NULL);
|
||||||
else
|
else
|
||||||
for (i=0; i < n && !rc ; i++ )
|
for (i=0; i < n && !rc ; i++ )
|
||||||
rc = gpg_mpi_write (a, sig->data[i], NULL);
|
rc = gpg_mpi_write (a, sig->data[i], NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user