mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
g10: fix cmp_public_key and cmp_secret_keys.
* g10/free-packet.c (cmp_public_keys, cmp_secret_keys): Compare opaque data at the first entry of the array when it's unknown algo. * mpi/mpi-cmp.c (mpi_cmp): Backport libgcrypt 1.5.0's semantics. -- (backported from 2.0 commit 43429c7869152f301157e4b24790b3801dce0f0a) GnuPG-bug-id: 1962
This commit is contained in:
parent
506eb6fec6
commit
04667cabef
@ -452,12 +452,15 @@ cmp_public_keys( PKT_public_key *a, PKT_public_key *b )
|
||||
return -1;
|
||||
|
||||
n = pubkey_get_npkey( b->pubkey_algo );
|
||||
if( !n )
|
||||
return -1; /* can't compare due to unknown algorithm */
|
||||
if( !n ) { /* unknown algorithm, rest is in opaque MPI */
|
||||
if( mpi_cmp( a->pkey[0], b->pkey[0] ) )
|
||||
return -1;
|
||||
} else {
|
||||
for(i=0; i < n; i++ ) {
|
||||
if( mpi_cmp( a->pkey[i], b->pkey[i] ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -479,12 +482,15 @@ cmp_secret_keys( PKT_secret_key *a, PKT_secret_key *b )
|
||||
return -1;
|
||||
|
||||
n = pubkey_get_npkey( b->pubkey_algo );
|
||||
if( !n )
|
||||
return -1; /* can't compare due to unknown algorithm */
|
||||
if( !n ) { /* unknown algorithm, rest is in opaque MPI */
|
||||
if( mpi_cmp( a->skey[0], b->skey[0] ) )
|
||||
return -1;
|
||||
} else {
|
||||
for(i=0; i < n; i++ ) {
|
||||
if( mpi_cmp( a->skey[i], b->skey[i] ) )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "mpi-internal.h"
|
||||
|
||||
int
|
||||
@ -49,6 +50,21 @@ mpi_cmp( MPI u, MPI v )
|
||||
mpi_size_t usize, vsize;
|
||||
int cmp;
|
||||
|
||||
if (mpi_is_opaque (u) || mpi_is_opaque (v))
|
||||
{
|
||||
if (mpi_is_opaque (u) && !mpi_is_opaque (v))
|
||||
return -1;
|
||||
if (!mpi_is_opaque (u) && mpi_is_opaque (v))
|
||||
return 1;
|
||||
if (!u->nbits && !v->nbits)
|
||||
return 0; /* Empty buffers are identical. */
|
||||
if (u->nbits < v->nbits)
|
||||
return -1;
|
||||
if (u->nbits > v->nbits)
|
||||
return 1;
|
||||
return memcmp (u->d, v->d, u->nbits);
|
||||
}
|
||||
|
||||
mpi_normalize( u );
|
||||
mpi_normalize( v );
|
||||
usize = u->nlimbs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user