Adjusted for use with current libgcrypt (1.1.42).

This commit is contained in:
Werner Koch 2003-07-28 08:59:18 +00:00
parent 0fe6a1287f
commit 979ed0ca26
12 changed files with 45 additions and 43 deletions

View File

@ -27,7 +27,7 @@ AC_INIT(gnupg, 1.9.0-cvs, gnupg-devel@gnupg.org)
# feel that the default check for a development version is not # feel that the default check for a development version is not
# sufficient. # sufficient.
development_version=yes development_version=yes
NEED_LIBGCRYPT_VERSION=1.1.8 NEED_LIBGCRYPT_VERSION=1.1.42
NEED_LIBASSUAN_VERSION=0.0.1 NEED_LIBASSUAN_VERSION=0.0.1
NEED_KSBA_VERSION=0.4.6 NEED_KSBA_VERSION=0.4.6
NEED_OPENSC_VERSION=0.7.0 NEED_OPENSC_VERSION=0.7.0

View File

@ -1,3 +1,7 @@
2003-07-27 Werner Koch <wk@gnupg.org>
Adjusted for gcry_mpi_print and gcry_mpi_scan API change.
2003-07-24 Werner Koch <wk@gnupg.org> 2003-07-24 Werner Koch <wk@gnupg.org>
* g10.c: New command --card-status. * g10.c: New command --card-status.

View File

@ -647,7 +647,7 @@ scd_genkey_cb (void *opaque, const char *line)
while (spacep (line)) while (spacep (line))
line++; line++;
rc = gcry_mpi_scan (&a, GCRYMPI_FMT_HEX, line, 0); rc = gcry_mpi_scan (&a, GCRYMPI_FMT_HEX, line, 0, NULL);
if (rc) if (rc)
log_error ("error parsing received key data: %s\n", gpg_strerror (rc)); log_error ("error parsing received key data: %s\n", gpg_strerror (rc));
else if (*name == 'n' && spacep (name+1)) else if (*name == 'n' && spacep (name+1))

View File

@ -86,11 +86,11 @@ make_mpi_comment_node( const char *s, gcry_mpi_t a )
size_t n = strlen(s); size_t n = strlen(s);
nb1 = mpi_get_nbits( a ); nb1 = mpi_get_nbits( a );
if (gcry_mpi_print (GCRYMPI_FMT_PGP, NULL, &n1, a)) if (gcry_mpi_print (GCRYMPI_FMT_PGP, NULL, 0, &n1, a))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buf = xmalloc (n1); buf = xmalloc (n1);
if (gcry_mpi_print (GCRYMPI_FMT_PGP, buf, &n1, a)) if (gcry_mpi_print (GCRYMPI_FMT_PGP, buf, n1, &n1, a))
BUG (); BUG ();
pkt = xcalloc (1, sizeof *pkt ); pkt = xcalloc (1, sizeof *pkt );

View File

@ -441,13 +441,13 @@ static int
write_sexp_keyparm (iobuf_t out, int *indent, const char *name, gcry_mpi_t a) write_sexp_keyparm (iobuf_t out, int *indent, const char *name, gcry_mpi_t a)
{ {
int rc; int rc;
char *buffer; unsigned char *buffer;
write_sexp_line (out, indent, "("); write_sexp_line (out, indent, "(");
iobuf_writestr (out, name); iobuf_writestr (out, name);
iobuf_writestr (out, " #"); iobuf_writestr (out, " #");
rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, (void **)&buffer, NULL, a); rc = gcry_mpi_aprint (GCRYMPI_FMT_HEX, &buffer, NULL, a);
assert (!rc); assert (!rc);
iobuf_writestr (out, buffer); iobuf_writestr (out, buffer);
iobuf_writestr (out, "#)"); iobuf_writestr (out, "#)");

View File

@ -67,11 +67,12 @@ do_fingerprint_md( PKT_public_key *pk )
for(i=0; i < npkey; i++ ) { for(i=0; i < npkey; i++ ) {
size_t nbytes; size_t nbytes;
if (gcry_mpi_print( GCRYMPI_FMT_PGP, NULL, &nbytes, pk->pkey[i] )) if (gcry_mpi_print( GCRYMPI_FMT_PGP, NULL, 0, &nbytes, pk->pkey[i] ))
BUG (); BUG ();
/* fixme: we should try to allocate a buffer on the stack */ /* fixme: we should try to allocate a buffer on the stack */
pp[i] = xmalloc(nbytes); pp[i] = xmalloc(nbytes);
if (gcry_mpi_print ( GCRYMPI_FMT_PGP, pp[i], &nbytes, pk->pkey[i] )) if (gcry_mpi_print ( GCRYMPI_FMT_PGP, pp[i], nbytes, &nbytes,
pk->pkey[i] ))
BUG (); BUG ();
nn[i] = nbytes; nn[i] = nbytes;
n += nn[i]; n += nn[i];
@ -135,11 +136,11 @@ v3_keyid (gcry_mpi_t a, u32 *ki)
byte *buffer; byte *buffer;
size_t nbytes; size_t nbytes;
if (gcry_mpi_print (GCRYMPI_FMT_USG, NULL, &nbytes, a )) if (gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &nbytes, a ))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buffer = xmalloc (nbytes); buffer = xmalloc (nbytes);
if (gcry_mpi_print( GCRYMPI_FMT_USG, buffer, &nbytes, a )) if (gcry_mpi_print( GCRYMPI_FMT_USG, buffer, nbytes, NULL, a ))
BUG (); BUG ();
if (nbytes < 8) /* oops */ if (nbytes < 8) /* oops */
ki[0] = ki[1] = 0; ki[0] = ki[1] = 0;
@ -476,19 +477,20 @@ fingerprint_from_pk( PKT_public_key *pk, byte *array, size_t *ret_len )
if( pubkey_get_npkey( pk->pubkey_algo ) > 1 ) { if( pubkey_get_npkey( pk->pubkey_algo ) > 1 ) {
size_t nbytes; size_t nbytes;
if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, pk->pkey[0])) if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, 0, &nbytes,
pk->pkey[0]))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buf = xmalloc(nbytes); buf = xmalloc(nbytes);
if (gcry_mpi_print (GCRYMPI_FMT_USG, buf, &nbytes, pk->pkey[0])) if (gcry_mpi_print (GCRYMPI_FMT_USG, buf, nbytes, NULL,pk->pkey[0]))
BUG (); BUG ();
gcry_md_write (md, buf, nbytes); gcry_md_write (md, buf, nbytes);
xfree (buf); xfree (buf);
if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, pk->pkey[1])) if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, 0, &nbytes, pk->pkey[1]))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buf = xmalloc(nbytes); buf = xmalloc(nbytes);
if (gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, pk->pkey[1])) if (gcry_mpi_print( GCRYMPI_FMT_USG, buf, nbytes, NULL,pk->pkey[1]))
BUG (); BUG ();
gcry_md_write( md, buf, nbytes ); gcry_md_write( md, buf, nbytes );
xfree(buf); xfree(buf);
@ -533,19 +535,19 @@ fingerprint_from_sk( PKT_secret_key *sk, byte *array, size_t *ret_len )
if( pubkey_get_npkey( sk->pubkey_algo ) > 1 ) { if( pubkey_get_npkey( sk->pubkey_algo ) > 1 ) {
size_t nbytes; size_t nbytes;
if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, sk->skey[0])) if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, 0, &nbytes, sk->skey[0]))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buf = xmalloc(nbytes); buf = xmalloc(nbytes);
if (gcry_mpi_print (GCRYMPI_FMT_USG, buf, &nbytes, sk->skey[0])) if (gcry_mpi_print (GCRYMPI_FMT_USG, buf, nbytes, NULL,sk->skey[0]))
BUG (); BUG ();
gcry_md_write (md, buf, nbytes); gcry_md_write (md, buf, nbytes);
xfree (buf); xfree (buf);
if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, sk->skey[1])) if (gcry_mpi_print( GCRYMPI_FMT_USG, NULL, 0, &nbytes, sk->skey[1]))
BUG (); BUG ();
/* fixme: allocate it on the stack */ /* fixme: allocate it on the stack */
buf = xmalloc(nbytes); buf = xmalloc(nbytes);
if (gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, sk->skey[1])) if (gcry_mpi_print( GCRYMPI_FMT_USG, buf,nbytes, NULL, sk->skey[1]))
BUG (); BUG ();
gcry_md_write( md, buf, nbytes ); gcry_md_write( md, buf, nbytes );
xfree(buf); xfree(buf);

View File

@ -122,14 +122,14 @@ checksum_mpi( gcry_mpi_t a )
byte *buffer; byte *buffer;
size_t nbytes; size_t nbytes;
rc = gcry_mpi_print( GCRYMPI_FMT_PGP, NULL, &nbytes, a ); rc = gcry_mpi_print( GCRYMPI_FMT_PGP, NULL, 0, &nbytes, a );
if (rc) if (rc)
BUG (); BUG ();
/* fixme: for numbers not in secure memory we should use a stack /* fixme: for numbers not in secure memory we should use a stack
* based buffer and only allocate a larger one if mpi_print return * based buffer and only allocate a larger one if mpi_print return
* an error */ * an error */
buffer = gcry_is_secure(a)? gcry_xmalloc_secure(nbytes) : gcry_xmalloc(nbytes); buffer = gcry_is_secure(a)? gcry_xmalloc_secure(nbytes):gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_PGP, buffer, &nbytes, a ); rc = gcry_mpi_print (GCRYMPI_FMT_PGP, buffer, nbytes, NULL, a );
if (rc) if (rc)
BUG (); BUG ();
csum = checksum (buffer, nbytes ); csum = checksum (buffer, nbytes );
@ -827,7 +827,7 @@ mpi_write( iobuf_t out, gcry_mpi_t a )
int rc; int rc;
nbytes = (MAX_EXTERN_MPI_BITS+7)/8; nbytes = (MAX_EXTERN_MPI_BITS+7)/8;
rc = gcry_mpi_print( GCRYMPI_FMT_PGP, buffer, &nbytes, a ); rc = gcry_mpi_print (GCRYMPI_FMT_PGP, buffer, nbytes, &nbytes, a );
if( !rc ) if( !rc )
rc = iobuf_write( out, buffer, nbytes ); rc = iobuf_write( out, buffer, nbytes );
@ -891,7 +891,7 @@ mpi_read(iobuf_t inp, unsigned int *ret_nread, int secure)
nread++; nread++;
} }
nread += nbytes; nread += nbytes;
if( gcry_mpi_scan( &a, GCRYMPI_FMT_PGP, buf, &nread ) ) if( gcry_mpi_scan( &a, GCRYMPI_FMT_PGP, buf, nread, &nread ) )
a = NULL; a = NULL;
leave: leave:
@ -961,9 +961,9 @@ mpi_print( FILE *fp, gcry_mpi_t a, int mode )
} }
else { else {
int rc; int rc;
char *buffer; unsigned char *buffer;
rc = gcry_mpi_aprint( GCRYMPI_FMT_HEX, (void **)&buffer, NULL, a ); rc = gcry_mpi_aprint( GCRYMPI_FMT_HEX, &buffer, NULL, a );
assert( !rc ); assert( !rc );
fputs( buffer, fp ); fputs( buffer, fp );
n += strlen(buffer); n += strlen(buffer);

View File

@ -149,7 +149,7 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
char *rbuf; char *rbuf;
size_t rbuflen; size_t rbuflen;
char *snbuf; char *snbuf;
void *indata = NULL; unsigned char *indata = NULL;
unsigned int indatalen; unsigned int indatalen;
snbuf = serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk); snbuf = serialno_and_fpr_from_sk (sk->protect.iv, sk->protect.ivlen, sk);
@ -170,14 +170,11 @@ get_it( PKT_pubkey_enc *enc, DEK *dek, PKT_secret_key *sk, u32 *keyid )
} }
else else
{ {
void *indata;
rc = pk_decrypt (sk->pubkey_algo, &plain_dek, enc->data, sk->skey); rc = pk_decrypt (sk->pubkey_algo, &plain_dek, enc->data, sk->skey);
if( rc ) if( rc )
goto leave; goto leave;
if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &indata, &nframe, plain_dek)) if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &frame, &nframe, plain_dek))
BUG(); BUG();
frame = indata;
gcry_mpi_release (plain_dek); plain_dek = NULL; gcry_mpi_release (plain_dek); plain_dek = NULL;
} }

View File

@ -161,10 +161,9 @@ do_check( PKT_secret_key *sk, const char *tryagain_text, int mode,
because the length may have an arbitrary value */ because the length may have an arbitrary value */
if( sk->csum == csum ) { if( sk->csum == csum ) {
for( ; i < pubkey_get_nskey(sk->pubkey_algo); i++ ) { for( ; i < pubkey_get_nskey(sk->pubkey_algo); i++ ) {
nbytes = ndata;
assert( gcry_is_secure( p ) ); assert( gcry_is_secure( p ) );
res = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_PGP, res = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_PGP,
p, &nbytes); p, ndata, &nbytes);
if( res ) if( res )
log_bug ("gcry_mpi_scan failed in do_check: %s\n", log_bug ("gcry_mpi_scan failed in do_check: %s\n",
gpg_strerror (res)); gpg_strerror (res));
@ -197,7 +196,7 @@ do_check( PKT_secret_key *sk, const char *tryagain_text, int mode,
csum += checksum (buffer, ndata); csum += checksum (buffer, ndata);
gcry_mpi_release (sk->skey[i]); gcry_mpi_release (sk->skey[i]);
res = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_USG, res = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_USG,
buffer, &ndata ); buffer, ndata, &ndata );
if( res ) if( res )
log_bug ("gcry_mpi_scan failed in do_check: %s\n", log_bug ("gcry_mpi_scan failed in do_check: %s\n",
gpg_strerror (res)); gpg_strerror (res));
@ -352,7 +351,7 @@ protect_secret_key( PKT_secret_key *sk, DEK *dek )
GCRY_STRONG_RANDOM); GCRY_STRONG_RANDOM);
gcry_cipher_setiv( cipher_hd, sk->protect.iv, sk->protect.ivlen ); gcry_cipher_setiv( cipher_hd, sk->protect.iv, sk->protect.ivlen );
if( sk->version >= 4 ) { if( sk->version >= 4 ) {
byte *bufarr[PUBKEY_MAX_NSKEY]; unsigned char *bufarr[PUBKEY_MAX_NSKEY];
unsigned narr[PUBKEY_MAX_NSKEY]; unsigned narr[PUBKEY_MAX_NSKEY];
unsigned nbits[PUBKEY_MAX_NSKEY]; unsigned nbits[PUBKEY_MAX_NSKEY];
int ndata=0; int ndata=0;
@ -363,7 +362,7 @@ protect_secret_key( PKT_secret_key *sk, DEK *dek )
assert( !gcry_mpi_get_flag( sk->skey[i], assert( !gcry_mpi_get_flag( sk->skey[i],
GCRYMPI_FLAG_OPAQUE )); GCRYMPI_FLAG_OPAQUE ));
if( gcry_mpi_aprint( GCRYMPI_FMT_USG, (void**)bufarr+j, if( gcry_mpi_aprint( GCRYMPI_FMT_USG, bufarr+j,
narr+j, sk->skey[i])) narr+j, sk->skey[i]))
BUG(); BUG();

View File

@ -148,7 +148,7 @@ encode_session_key (DEK *dek, unsigned int nbits)
if (DBG_CIPHER) if (DBG_CIPHER)
log_printhex ("encoded session key:", frame, nframe ); log_printhex ("encoded session key:", frame, nframe );
if (gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, &nframe)) if (gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, n, &nframe))
BUG(); BUG();
xfree (frame); xfree (frame);
return a; return a;
@ -185,7 +185,7 @@ do_encode_md( gcry_md_hd_t md, int algo, size_t len, unsigned nbits,
memcpy( frame+n, asn, asnlen ); n += asnlen; memcpy( frame+n, asn, asnlen ); n += asnlen;
memcpy( frame+n, gcry_md_read (md, algo), len ); n += len; memcpy( frame+n, gcry_md_read (md, algo), len ); n += len;
assert( n == nframe ); assert( n == nframe );
if (gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, &nframe )) if (gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, n, &nframe ))
BUG(); BUG();
xfree (frame); xfree (frame);
return a; return a;
@ -214,7 +214,7 @@ encode_md_value (int pubkey_algo, gcry_md_hd_t md, int hash_algo,
return NULL; return NULL;
} }
if (gcry_mpi_scan( &frame, GCRYMPI_FMT_USG, if (gcry_mpi_scan( &frame, GCRYMPI_FMT_USG,
gcry_md_read (md, hash_algo), &n ) ) gcry_md_read (md, hash_algo), n, &n ) )
BUG(); BUG();
} }
else else

View File

@ -111,7 +111,7 @@ signature_check2( PKT_signature *sig, MD_HANDLE digest,
gcry_md_putc( digest, a & 0xff ); gcry_md_putc( digest, a & 0xff );
for(i=0; i < nsig; i++ ) { for(i=0; i < nsig; i++ ) {
size_t n; size_t n;
void *tmp; unsigned char *tmp;
if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &tmp, &n, sig->data[i])) if (gcry_mpi_aprint (GCRYMPI_FMT_USG, &tmp, &n, sig->data[i]))
BUG(); BUG();

View File

@ -304,8 +304,8 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig,
xfree (snbuf); xfree (snbuf);
if (!rc) if (!rc)
{ {
unsigned int nbytes = rbuflen; if (gcry_mpi_scan (&sig->data[0], GCRYMPI_FMT_USG,
if (gcry_mpi_scan (&sig->data[0], GCRYMPI_FMT_USG, rbuf, &nbytes )) rbuf, rbuflen, NULL ))
BUG (); BUG ();
} }
} }
@ -325,8 +325,8 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig,
xfree (snbuf); xfree (snbuf);
if (!rc) if (!rc)
{ {
unsigned int nbytes = rbuflen; if (gcry_mpi_scan (&sig->data[0], GCRYMPI_FMT_USG,
if (gcry_mpi_scan (&sig->data[0], GCRYMPI_FMT_USG, rbuf, &nbytes )) rbuf, rbuflen, NULL))
BUG (); BUG ();
} }
} }