aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog13
-rw-r--r--g10/Makefile.am2
-rw-r--r--g10/armor.c6
-rw-r--r--g10/build-packet.c14
-rw-r--r--g10/cipher.c1
-rw-r--r--g10/comment.c28
-rw-r--r--g10/compress.c18
-rw-r--r--g10/dearmor.c2
-rw-r--r--g10/decrypt.c2
-rw-r--r--g10/delkey.c4
-rw-r--r--g10/encode.c42
-rw-r--r--g10/encr-data.c1
-rw-r--r--g10/export.c2
-rw-r--r--g10/free-packet.c44
-rw-r--r--g10/g10.c83
-rw-r--r--g10/getkey.c67
-rw-r--r--g10/gpgd.c12
-rw-r--r--g10/hkp.c12
-rw-r--r--g10/import.c18
-rw-r--r--g10/kbnode.c12
-rw-r--r--g10/keyedit.c48
-rw-r--r--g10/keygen.c103
-rw-r--r--g10/keyid.c41
-rw-r--r--g10/keylist.c8
-rw-r--r--g10/main.h1
-rw-r--r--g10/mainproc.c41
-rw-r--r--g10/mdfilter.c2
-rw-r--r--g10/misc.c61
-rw-r--r--g10/openfile.c32
-rw-r--r--g10/options.h1
-rw-r--r--g10/parse-packet.c32
-rw-r--r--g10/passphrase.c28
-rw-r--r--g10/pkclist.c57
-rw-r--r--g10/plaintext.c24
-rw-r--r--g10/pubkey-enc.c20
-rw-r--r--g10/revoke.c6
-rw-r--r--g10/ringedit.c76
-rw-r--r--g10/seckey-cert.c41
-rw-r--r--g10/seskey.c37
-rw-r--r--g10/sig-check.c27
-rw-r--r--g10/sign.c21
-rw-r--r--g10/signal.c4
-rw-r--r--g10/skclist.c11
-rw-r--r--g10/status.c18
-rw-r--r--g10/tdbdump.c6
-rw-r--r--g10/tdbio.c14
-rw-r--r--g10/textfilter.c3
-rw-r--r--g10/trustdb.c50
-rw-r--r--g10/verify.c2
49 files changed, 626 insertions, 572 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index 45f6af4db..e73bae4c1 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,16 @@
+Mon Jan 24 13:04:28 CET 2000 Werner Koch <[email protected]>
+
+ * misc.c (mpi_print): Use gcry_mpi_aprint.
+ (pubkey_nbits): Kludge to use the gcry_pk_ API.
+
+ * seskey.c (encode_session_key): Replaced mpi_set_buffer by *_scan.
+ (do_encode_md): Ditto.
+ (encode_md_value): Ditto.
+ * seckey-cert.c (protect_secret_key): Ditto.
+ * comment.c (make_mpi_comment_node): Replaced mpi_get_buffer by _print.
+ * pubkey-enc.c (get_it): Ditto.
+ * sig-check.c (do_signature_check): Ditto.
+
Fri Dec 31 12:48:31 CET 1999 Werner Koch <[email protected]>
* keyid.c (do_fingerprint_md): Replaced mpi_get_buffer by gcry_mpi_print.
diff --git a/g10/Makefile.am b/g10/Makefile.am
index 7c2450f12..f0f6068c5 100644
--- a/g10/Makefile.am
+++ b/g10/Makefile.am
@@ -4,7 +4,7 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/intl
EXTRA_DIST = OPTIONS pubring.asc options.skel
OMIT_DEPENDENCIES = zlib.h zconf.h
LDFLAGS = @LDFLAGS@ @DYNLINK_LDFLAGS@
-needed_libs = ../util/libutil.la ../gcrypt/libgcrypt.la
+needed_libs = ../util/libutil.la ../gcrypt/libgcrypt.la ../jnlib/libjnlib.la
#noinst_PROGRAMS = gpgd
bin_PROGRAMS = gpg
diff --git a/g10/armor.c b/g10/armor.c
index 192a4188c..828113b0c 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -28,7 +28,7 @@
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "filter.h"
#include "packet.h"
@@ -1014,7 +1014,7 @@ armor_filter( void *opaque, int control,
if( afx->qp_detected )
log_error(_("quoted printable character in armor - "
"probably a buggy MTA has been used\n") );
- m_free( afx->buffer );
+ gcry_free( afx->buffer );
afx->buffer = NULL;
}
else if( control == IOBUFCTRL_DESC )
@@ -1031,7 +1031,7 @@ make_radix64_string( const byte *data, size_t len )
{
char *buffer, *p;
- buffer = p = m_alloc( (len+2)/3*4 + 1 );
+ buffer = p = gcry_xmalloc( (len+2)/3*4 + 1 );
for( ; len >= 3 ; len -= 3, data += 3 ) {
*p++ = bintoasc[(data[0] >> 2) & 077];
*p++ = bintoasc[(((data[0] <<4)&060)|((data[1] >> 4)&017))&077];
diff --git a/g10/build-packet.c b/g10/build-packet.c
index 84ca3a8db..34fd4ae1d 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -29,7 +29,7 @@
#include "iobuf.h"
#include "util.h"
#include "dummy-cipher.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "options.h"
#include "main.h"
@@ -667,16 +667,16 @@ build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
| sig->hashed_data[1]) : 0;
n = n0 + nlen + 1 + buflen; /* length, type, buffer */
realloced = !!sig->hashed_data;
- data = sig->hashed_data ? m_realloc( sig->hashed_data, n+2 )
- : m_alloc( n+2 );
+ data = sig->hashed_data ? gcry_xrealloc( sig->hashed_data, n+2 )
+ : gcry_xmalloc( n+2 );
}
else {
n0 = sig->unhashed_data ? ((*sig->unhashed_data << 8)
| sig->unhashed_data[1]) : 0;
n = n0 + nlen + 1 + buflen; /* length, type, buffer */
realloced = !!sig->unhashed_data;
- data = sig->unhashed_data ? m_realloc( sig->unhashed_data, n+2 )
- : m_alloc( n+2 );
+ data = sig->unhashed_data ? gcry_xrealloc( sig->unhashed_data, n+2 )
+ : gcry_xmalloc( n+2 );
}
if( critical )
@@ -707,12 +707,12 @@ build_sig_subpkt( PKT_signature *sig, sigsubpkttype_t type,
if( hashed ) {
if( !realloced )
- m_free(sig->hashed_data);
+ gcry_free(sig->hashed_data);
sig->hashed_data = data;
}
else {
if( !realloced )
- m_free(sig->unhashed_data);
+ gcry_free(sig->unhashed_data);
sig->unhashed_data = data;
}
}
diff --git a/g10/cipher.c b/g10/cipher.c
index ef4c86502..48dde31cc 100644
--- a/g10/cipher.c
+++ b/g10/cipher.c
@@ -28,7 +28,6 @@
#include <gcrypt.h>
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
#include "util.h"
#include "filter.h"
#include "packet.h"
diff --git a/g10/comment.c b/g10/comment.c
index 6d27e481b..f0abd0bac 100644
--- a/g10/comment.c
+++ b/g10/comment.c
@@ -29,7 +29,7 @@
#include "packet.h"
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "keydb.h"
@@ -45,13 +45,13 @@ write_comment( IOBUF out, const char *s )
pkt.pkttype = PKT_COMMENT;
if( *s != '#' ) {
- pkt.pkt.comment = m_alloc( sizeof *pkt.pkt.comment + n );
+ pkt.pkt.comment = gcry_xmalloc( sizeof *pkt.pkt.comment + n );
pkt.pkt.comment->len = n+1;
*pkt.pkt.comment->data = '#';
strcpy(pkt.pkt.comment->data+1, s);
}
else {
- pkt.pkt.comment = m_alloc( sizeof *pkt.pkt.comment + n - 1 );
+ pkt.pkt.comment = gcry_xmalloc( sizeof *pkt.pkt.comment + n - 1 );
pkt.pkt.comment->len = n;
strcpy(pkt.pkt.comment->data, s);
}
@@ -68,9 +68,9 @@ make_comment_node( const char *s )
PACKET *pkt;
size_t n = strlen(s);
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_COMMENT;
- pkt->pkt.comment = m_alloc( sizeof *pkt->pkt.comment + n - 1 );
+ pkt->pkt.comment = gcry_xmalloc( sizeof *pkt->pkt.comment + n - 1 );
pkt->pkt.comment->len = n;
strcpy(pkt->pkt.comment->data, s);
return new_kbnode( pkt );
@@ -81,22 +81,20 @@ KBNODE
make_mpi_comment_node( const char *s, MPI a )
{
PACKET *pkt;
- byte *buf, *p, *pp;
- unsigned n1, nb1;
+ char *buf, *pp;
+ unsigned n1;
size_t n = strlen(s);
- nb1 = mpi_get_nbits( a );
- p = buf = mpi_get_buffer( a, &n1, NULL );
- pkt = m_alloc_clear( sizeof *pkt );
+ if( gcry_mpi_aprint( GCRYMPI_FMT_PGP, &buf, &n1, a ) )
+ BUG();
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_COMMENT;
- pkt->pkt.comment = m_alloc( sizeof *pkt->pkt.comment + n + 2 + n1 );
+ pkt->pkt.comment = gcry_xmalloc( sizeof *pkt->pkt.comment + n + 1 + n1 );
pkt->pkt.comment->len = n+1+2+n1;
pp = pkt->pkt.comment->data;
memcpy(pp, s, n+1);
- pp[n+1] = nb1 >> 8;
- pp[n+2] = nb1 ;
- memcpy(pp+n+3, p, n1 );
- m_free(buf);
+ memcpy(pp+n+1, buf, n1 );
+ gcry_free(buf);
return new_kbnode( pkt );
}
diff --git a/g10/compress.c b/g10/compress.c
index 4862346ad..478da5684 100644
--- a/g10/compress.c
+++ b/g10/compress.c
@@ -28,7 +28,7 @@
#include <zlib.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "packet.h"
#include "filter.h"
#include "options.h"
@@ -63,7 +63,7 @@ init_compress( compress_filter_context_t *zfx, z_stream *zs )
}
zfx->outbufsize = 8192;
- zfx->outbuf = m_alloc( zfx->outbufsize );
+ zfx->outbuf = gcry_xmalloc( zfx->outbufsize );
}
static int
@@ -121,7 +121,7 @@ init_uncompress( compress_filter_context_t *zfx, z_stream *zs )
}
zfx->inbufsize = 2048;
- zfx->inbuf = m_alloc( zfx->inbufsize );
+ zfx->inbuf = gcry_xmalloc( zfx->inbufsize );
zs->avail_in = 0;
}
@@ -196,7 +196,7 @@ compress_filter( void *opaque, int control,
if( control == IOBUFCTRL_UNDERFLOW ) {
if( !zfx->status ) {
- zs = zfx->opaque = m_alloc_clear( sizeof *zs );
+ zs = zfx->opaque = gcry_xcalloc( 1, sizeof *zs );
init_uncompress( zfx, zs );
zfx->status = 1;
}
@@ -221,7 +221,7 @@ compress_filter( void *opaque, int control,
pkt.pkt.compressed = &cd;
if( build_packet( a, &pkt ))
log_bug("build_packet(PKT_COMPRESSED) failed\n");
- zs = zfx->opaque = m_alloc_clear( sizeof *zs );
+ zs = zfx->opaque = gcry_xcalloc( 1, sizeof *zs );
init_compress( zfx, zs );
zfx->status = 2;
}
@@ -233,18 +233,18 @@ compress_filter( void *opaque, int control,
else if( control == IOBUFCTRL_FREE ) {
if( zfx->status == 1 ) {
inflateEnd(zs);
- m_free(zs);
+ gcry_free(zs);
zfx->opaque = NULL;
- m_free(zfx->outbuf); zfx->outbuf = NULL;
+ gcry_free(zfx->outbuf); zfx->outbuf = NULL;
}
else if( zfx->status == 2 ) {
zs->next_in = buf;
zs->avail_in = 0;
do_compress( zfx, zs, Z_FINISH, a );
deflateEnd(zs);
- m_free(zs);
+ gcry_free(zs);
zfx->opaque = NULL;
- m_free(zfx->outbuf); zfx->outbuf = NULL;
+ gcry_free(zfx->outbuf); zfx->outbuf = NULL;
}
}
else if( control == IOBUFCTRL_DESC )
diff --git a/g10/dearmor.c b/g10/dearmor.c
index e87dffcd9..70255629c 100644
--- a/g10/dearmor.c
+++ b/g10/dearmor.c
@@ -27,7 +27,7 @@
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "filter.h"
#include "packet.h"
diff --git a/g10/decrypt.c b/g10/decrypt.c
index df6b0a7c0..c742a92d4 100644
--- a/g10/decrypt.c
+++ b/g10/decrypt.c
@@ -30,7 +30,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "i18n.h"
diff --git a/g10/delkey.c b/g10/delkey.c
index a324fd631..9de3a7b08 100644
--- a/g10/delkey.c
+++ b/g10/delkey.c
@@ -31,7 +31,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "trustdb.h"
@@ -125,7 +125,7 @@ delete_key( const char *username, int secret )
keyid[1], datestr_from_pk(pk) );
p = get_user_id( keyid, &n );
tty_print_utf8_string( p, n );
- m_free(p);
+ gcry_free(p);
tty_printf("\n\n");
yes = cpr_get_answer_is_yes( secret? "delete_key.secret.okay"
diff --git a/g10/encode.c b/g10/encode.c
index 15761d09d..e4d701e30 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -30,7 +30,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "filter.h"
@@ -98,7 +98,7 @@ encode_simple( const char *filename, int mode )
cfx.dek = NULL;
if( mode ) {
- s2k = m_alloc_clear( sizeof *s2k );
+ s2k = gcry_xcalloc( 1, sizeof *s2k );
s2k->mode = opt.rfc1991? 0:opt.s2k_mode;
s2k->hash_algo = opt.def_digest_algo ? opt.def_digest_algo
: opt.s2k_digest_algo;
@@ -107,8 +107,8 @@ encode_simple( const char *filename, int mode )
: opt.s2k_cipher_algo , s2k, 2 );
if( !cfx.dek || !cfx.dek->keylen ) {
rc = G10ERR_PASSPHRASE;
- m_free(cfx.dek);
- m_free(s2k);
+ gcry_free(cfx.dek);
+ gcry_free(s2k);
iobuf_close(inp);
log_error(_("error creating passphrase: %s\n"), g10_errstr(rc) );
return rc;
@@ -117,8 +117,8 @@ encode_simple( const char *filename, int mode )
if( (rc = open_outfile( filename, opt.armor? 1:0, &out )) ) {
iobuf_close(inp);
- m_free(cfx.dek);
- m_free(s2k);
+ gcry_free(cfx.dek);
+ gcry_free(s2k);
return rc;
}
@@ -133,7 +133,7 @@ encode_simple( const char *filename, int mode )
}
#endif
if( s2k && !opt.rfc1991 ) {
- PKT_symkey_enc *enc = m_alloc_clear( sizeof *enc );
+ PKT_symkey_enc *enc = gcry_xcalloc( 1, sizeof *enc );
enc->version = 4;
enc->cipher_algo = cfx.dek->algo;
enc->s2k = *s2k;
@@ -141,7 +141,7 @@ encode_simple( const char *filename, int mode )
pkt.pkt.symkey_enc = enc;
if( (rc = build_packet( out, &pkt )) )
log_error("build symkey packet failed: %s\n", g10_errstr(rc) );
- m_free(enc);
+ gcry_free(enc);
}
if (!opt.no_literal) {
@@ -149,13 +149,13 @@ encode_simple( const char *filename, int mode )
if( filename || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename
: filename );
- pt = m_alloc( sizeof *pt + strlen(s) - 1 );
+ pt = gcry_xmalloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );
- m_free(s);
+ gcry_free(s);
}
else { /* no filename */
- pt = m_alloc( sizeof *pt - 1 );
+ pt = gcry_xmalloc( sizeof *pt - 1 );
pt->namelen = 0;
}
}
@@ -221,8 +221,8 @@ encode_simple( const char *filename, int mode )
if (pt)
pt->buf = NULL;
free_packet(&pkt);
- m_free(cfx.dek);
- m_free(s2k);
+ gcry_free(cfx.dek);
+ gcry_free(s2k);
return rc;
}
@@ -283,7 +283,7 @@ encode_crypt( const char *filename, STRLIST remusr )
}
#endif
/* create a session key */
- cfx.dek = m_alloc_secure( sizeof *cfx.dek );
+ cfx.dek = gcry_xmalloc_secure( sizeof *cfx.dek );
if( !opt.def_cipher_algo ) { /* try to get it from the prefs */
cfx.dek->algo = select_algo_from_prefs( pk_list, PREFTYPE_SYM );
if( cfx.dek->algo == -1 )
@@ -303,13 +303,13 @@ encode_crypt( const char *filename, STRLIST remusr )
/* setup the inner packet */
if( filename || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename : filename );
- pt = m_alloc( sizeof *pt + strlen(s) - 1 );
+ pt = gcry_xmalloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );
- m_free(s);
+ gcry_free(s);
}
else { /* no filename */
- pt = m_alloc( sizeof *pt - 1 );
+ pt = gcry_xmalloc( sizeof *pt - 1 );
pt->namelen = 0;
}
}
@@ -377,7 +377,7 @@ encode_crypt( const char *filename, STRLIST remusr )
if( pt )
pt->buf = NULL;
free_packet(&pkt);
- m_free(cfx.dek);
+ gcry_free(cfx.dek);
release_pk_list( pk_list );
return rc;
}
@@ -401,7 +401,7 @@ encrypt_filter( void *opaque, int control,
}
else if( control == IOBUFCTRL_FLUSH ) { /* encrypt */
if( !efx->header_okay ) {
- efx->cfx.dek = m_alloc_secure( sizeof *efx->cfx.dek );
+ efx->cfx.dek = gcry_xmalloc_secure( sizeof *efx->cfx.dek );
if( !opt.def_cipher_algo ) { /* try to get it from the prefs */
efx->cfx.dek->algo =
@@ -453,7 +453,7 @@ write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out )
pk = pk_list->pk;
print_pubkey_algo_note( pk->pubkey_algo );
- enc = m_alloc_clear( sizeof *enc );
+ enc = gcry_xcalloc( 1, sizeof *enc );
enc->pubkey_algo = pk->pubkey_algo;
keyid_from_pk( pk, enc->keyid );
enc->throw_keyid = opt.throw_keyid;
@@ -483,7 +483,7 @@ write_pubkey_enc_from_list( PK_LIST pk_list, DEK *dek, IOBUF out )
log_info(_("%s/%s encrypted for: %s\n"),
gcry_pk_algo_name(enc->pubkey_algo),
gcry_cipher_algo_name(dek->algo), ustr );
- m_free(ustr);
+ gcry_free(ustr);
}
/* and write it */
init_packet(&pkt);
diff --git a/g10/encr-data.c b/g10/encr-data.c
index c4c9ff2f0..286475003 100644
--- a/g10/encr-data.c
+++ b/g10/encr-data.c
@@ -25,7 +25,6 @@
#include <assert.h>
#include <gcrypt.h>
#include "util.h"
-#include "memory.h"
#include "packet.h"
#include "dummy-cipher.h"
#include "options.h"
diff --git a/g10/export.c b/g10/export.c
index 911a71599..4021c050f 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -29,7 +29,7 @@
#include "packet.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "i18n.h"
diff --git a/g10/free-packet.c b/g10/free-packet.c
index 93c93de19..56a65d7ae 100644
--- a/g10/free-packet.c
+++ b/g10/free-packet.c
@@ -28,14 +28,14 @@
#include "iobuf.h"
#include "util.h"
#include "dummy-cipher.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "options.h"
#include "main.h"
void
free_symkey_enc( PKT_symkey_enc *enc )
{
- m_free(enc);
+ gcry_free(enc);
}
void
@@ -47,7 +47,7 @@ free_pubkey_enc( PKT_pubkey_enc *enc )
mpi_release(enc->data[0]);
for(i=0; i < n; i++ )
mpi_release( enc->data[i] );
- m_free(enc);
+ gcry_free(enc);
}
void
@@ -59,9 +59,9 @@ free_seckey_enc( PKT_signature *sig )
mpi_release(sig->data[0]);
for(i=0; i < n; i++ )
mpi_release( sig->data[i] );
- m_free(sig->hashed_data);
- m_free(sig->unhashed_data);
- m_free(sig);
+ gcry_free(sig->hashed_data);
+ gcry_free(sig->unhashed_data);
+ gcry_free(sig);
}
@@ -78,7 +78,7 @@ release_public_key_parts( PKT_public_key *pk )
pk->pkey[i] = NULL;
}
if( pk->namehash ) {
- m_free(pk->namehash);
+ gcry_free(pk->namehash);
pk->namehash = NULL;
}
}
@@ -88,7 +88,7 @@ void
free_public_key( PKT_public_key *pk )
{
release_public_key_parts( pk );
- m_free(pk);
+ gcry_free(pk);
}
@@ -101,7 +101,7 @@ cp_data_block( byte *s )
if( !s )
return NULL;
len = (s[0] << 8) | s[1];
- d = m_alloc( len+2 );
+ d = gcry_xmalloc( len+2 );
memcpy(d, s, len+2);
return d;
}
@@ -114,14 +114,14 @@ copy_public_key_new_namehash( PKT_public_key *d, PKT_public_key *s,
int n, i;
if( !d )
- d = m_alloc(sizeof *d);
+ d = gcry_xmalloc(sizeof *d);
memcpy( d, s, sizeof *d );
if( namehash ) {
- d->namehash = m_alloc( 20 );
+ d->namehash = gcry_xmalloc( 20 );
memcpy(d->namehash, namehash, 20 );
}
else if( s->namehash ) {
- d->namehash = m_alloc( 20 );
+ d->namehash = gcry_xmalloc( 20 );
memcpy(d->namehash, s->namehash, 20 );
}
n = pubkey_get_npkey( s->pubkey_algo );
@@ -146,7 +146,7 @@ copy_signature( PKT_signature *d, PKT_signature *s )
int n, i;
if( !d )
- d = m_alloc(sizeof *d);
+ d = gcry_xmalloc(sizeof *d);
memcpy( d, s, sizeof *d );
n = pubkey_get_nsig( s->pubkey_algo );
if( !n )
@@ -165,7 +165,7 @@ PKT_user_id *
copy_user_id( PKT_user_id *d, PKT_user_id *s )
{
if( !d )
- d = m_alloc(sizeof *d + s->len - 1 );
+ d = gcry_xmalloc(sizeof *d + s->len - 1 );
memcpy( d, s, sizeof *d + s->len - 1 );
return d;
}
@@ -190,7 +190,7 @@ void
free_secret_key( PKT_secret_key *sk )
{
release_secret_key_parts( sk );
- m_free(sk);
+ gcry_free(sk);
}
PKT_secret_key *
@@ -199,7 +199,7 @@ copy_secret_key( PKT_secret_key *d, PKT_secret_key *s )
int n, i;
if( !d )
- d = m_alloc(sizeof *d);
+ d = gcry_xmalloc(sizeof *d);
memcpy( d, s, sizeof *d );
n = pubkey_get_nskey( s->pubkey_algo );
if( !n )
@@ -214,13 +214,13 @@ copy_secret_key( PKT_secret_key *d, PKT_secret_key *s )
void
free_comment( PKT_comment *rem )
{
- m_free(rem);
+ gcry_free(rem);
}
void
free_user_id( PKT_user_id *uid )
{
- m_free(uid);
+ gcry_free(uid);
}
void
@@ -232,7 +232,7 @@ free_compressed( PKT_compressed *zd )
while( iobuf_read( zd->buf, NULL, 1<<30 ) != -1 )
;
}
- m_free(zd);
+ gcry_free(zd);
}
void
@@ -253,7 +253,7 @@ free_encrypted( PKT_encrypted *ed )
}
}
}
- m_free(ed);
+ gcry_free(ed);
}
@@ -275,7 +275,7 @@ free_plaintext( PKT_plaintext *pt )
}
}
}
- m_free(pt);
+ gcry_free(pt);
}
/****************
@@ -324,7 +324,7 @@ free_packet( PACKET *pkt )
free_plaintext( pkt->pkt.plaintext );
break;
default:
- m_free( pkt->pkt.generic );
+ gcry_free( pkt->pkt.generic );
break;
}
pkt->pkt.generic = NULL;
diff --git a/g10/g10.c b/g10/g10.c
index 871f31026..192ac4ae4 100644
--- a/g10/g10.c
+++ b/g10/g10.c
@@ -30,7 +30,6 @@
#include "packet.h"
#include "iobuf.h"
-#include "memory.h"
#include "util.h"
#include "main.h"
#include "options.h"
@@ -422,13 +421,14 @@ build_list( const char *text, const char * (*mapf)(int), int (*chkf)(int) )
size_t n=strlen(text)+2;
char *list, *p;
- if( maybe_setuid )
- secmem_init( 0 ); /* drop setuid */
+ if( maybe_setuid ) {
+ gcry_control( GCRYCTL_DROP_PRIVS ); /* drop setuid */
+ }
for(i=1; i < 110; i++ )
if( !chkf(i) )
n += strlen(mapf(i)) + 2;
- list = m_alloc( 21 + n ); *list = 0;
+ list = gcry_xmalloc( 21 + n ); *list = 0;
for(p=NULL, i=1; i < 110; i++ ) {
if( !chkf(i) ) {
if( !p )
@@ -480,7 +480,7 @@ make_username( const char *string )
if( utf8_strings )
p = native_to_utf8( string );
else
- p = m_strdup(string);
+ p = gcry_xstrdup(string);
return p;
}
@@ -498,7 +498,7 @@ register_extension( const char *mainpgm, const char *fname )
else
tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
register_cipher_extension( mainpgm, tmp );
- m_free(tmp);
+ gcry_free(tmp);
}
else
register_cipher_extension( mainpgm, fname );
@@ -510,10 +510,13 @@ register_extension( const char *mainpgm, const char *fname )
static void
set_debug(void)
{
+ #if 0
+ #warning memory debuggig not enabled
if( opt.debug & DBG_MEMORY_VALUE )
memory_debug_mode = 1;
if( opt.debug & DBG_MEMSTAT_VALUE )
memory_stat_debug_mode = 1;
+ #endif
if( opt.debug & DBG_MPI_VALUE )
gcry_control( GCRYCTL_SET_DEBUG_FLAGS, 2 );
@@ -588,7 +591,7 @@ main( int argc, char **argv )
trap_unaligned();
set_strusage( my_strusage );
- secmem_set_flags( secmem_get_flags() | 2 ); /* suspend warnings */
+ gcry_control( GCRYCTL_SUSPEND_SECMEM_WARN );
/* Please note that we may running SUID(ROOT), so be very CAREFUL
* when adding any stuff between here and the call to
* secmem_init() somewhere after the option parsing
@@ -667,7 +670,7 @@ main( int argc, char **argv )
}
#endif
/* initialize the secure memory. */
- secmem_init( 16384 );
+ gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
maybe_setuid = 0;
/* Okay, we are now working under our real uid */
@@ -695,7 +698,7 @@ main( int argc, char **argv )
configname, strerror(errno) );
g10_exit(2);
}
- m_free(configname); configname = NULL;
+ gcry_free(configname); configname = NULL;
}
if( parse_debug && configname )
log_info(_("reading options from `%s'\n"), configname );
@@ -774,8 +777,8 @@ main( int argc, char **argv )
case oOptions:
/* config files may not be nested (silently ignore them) */
if( !configfp ) {
- m_free(configname);
- configname = m_strdup(pargs.r.ret_str);
+ gcry_free(configname);
+ configname = gcry_xstrdup(pargs.r.ret_str);
goto next_pass;
}
break;
@@ -799,11 +802,11 @@ main( int argc, char **argv )
opt.def_recipient = make_username(pargs.r.ret_str);
break;
case oDefRecipientSelf:
- m_free(opt.def_recipient); opt.def_recipient = NULL;
+ gcry_free(opt.def_recipient); opt.def_recipient = NULL;
opt.def_recipient_self = 1;
break;
case oNoDefRecipient:
- m_free(opt.def_recipient); opt.def_recipient = NULL;
+ gcry_free(opt.def_recipient); opt.def_recipient = NULL;
opt.def_recipient_self = 0;
break;
case oNoOptions: break; /* no-options */
@@ -856,8 +859,8 @@ main( int argc, char **argv )
case oForceV3Sigs: opt.force_v3_sigs = 1; break;
case oForceMDC: opt.force_mdc = 1; break;
case oS2KMode: opt.s2k_mode = pargs.r.ret_int; break;
- case oS2KDigest: s2k_digest_string = m_strdup(pargs.r.ret_str); break;
- case oS2KCipher: s2k_cipher_string = m_strdup(pargs.r.ret_str); break;
+ case oS2KDigest: s2k_digest_string = gcry_xstrdup(pargs.r.ret_str); break;
+ case oS2KCipher: s2k_cipher_string = gcry_xstrdup(pargs.r.ret_str); break;
case oNoEncryptTo: opt.no_encrypt_to = 1; break;
case oEncryptTo: /* store the recipient in the second list */
@@ -874,9 +877,9 @@ main( int argc, char **argv )
break;
case oCompress: opt.compress = pargs.r.ret_int; break;
case oPasswdFD: pwfd = pargs.r.ret_int; break;
- case oCipherAlgo: def_cipher_string = m_strdup(pargs.r.ret_str); break;
- case oDigestAlgo: def_digest_string = m_strdup(pargs.r.ret_str); break;
- case oNoSecmemWarn: secmem_set_flags( secmem_get_flags() | 1 ); break;
+ case oCipherAlgo: def_cipher_string = gcry_xstrdup(pargs.r.ret_str); break;
+ case oDigestAlgo: def_digest_string = gcry_xstrdup(pargs.r.ret_str); break;
+ case oNoSecmemWarn: gcry_control( GCRYCTL_DISABLE_SECMEM_WARN ); break;
case oCharset:
if( set_native_charset( pargs.r.ret_str ) )
log_error(_("%s is not a valid character set\n"),
@@ -925,10 +928,10 @@ main( int argc, char **argv )
if( configfp ) {
fclose( configfp );
configfp = NULL;
- m_free(configname); configname = NULL;
+ gcry_free(configname); configname = NULL;
goto next_pass;
}
- m_free( configname ); configname = NULL;
+ gcry_free( configname ); configname = NULL;
if( log_get_errorcount(0) )
g10_exit(2);
if( nogreeting )
@@ -962,7 +965,7 @@ main( int argc, char **argv )
if( opt.batch )
tty_batchmode( 1 );
- secmem_set_flags( secmem_get_flags() & ~2 ); /* resume warnings */
+ gcry_control( GCRYCTL_RESUME_SECMEM_WARN );
set_debug();
/* FIXME: should set filenames of libgcrypt explicitly
@@ -972,25 +975,25 @@ main( int argc, char **argv )
* may try to load a module */
if( def_cipher_string ) {
opt.def_cipher_algo = gcry_cipher_map_name(def_cipher_string);
- m_free(def_cipher_string); def_cipher_string = NULL;
+ gcry_free(def_cipher_string); def_cipher_string = NULL;
if( openpgp_cipher_test_algo(opt.def_cipher_algo) )
log_error(_("selected cipher algorithm is invalid\n"));
}
if( def_digest_string ) {
opt.def_digest_algo = gcry_md_map_name(def_digest_string);
- m_free(def_digest_string); def_digest_string = NULL;
+ gcry_free(def_digest_string); def_digest_string = NULL;
if( openpgp_md_test_algo(opt.def_digest_algo) )
log_error(_("selected digest algorithm is invalid\n"));
}
if( s2k_cipher_string ) {
opt.s2k_cipher_algo = gcry_cipher_map_name(s2k_cipher_string);
- m_free(s2k_cipher_string); s2k_cipher_string = NULL;
+ gcry_free(s2k_cipher_string); s2k_cipher_string = NULL;
if( openpgp_cipher_test_algo(opt.s2k_cipher_algo) )
log_error(_("selected cipher algorithm is invalid\n"));
}
if( s2k_digest_string ) {
opt.s2k_digest_algo = gcry_md_map_name(s2k_digest_string);
- m_free(s2k_digest_string); s2k_digest_string = NULL;
+ gcry_free(s2k_digest_string); s2k_digest_string = NULL;
if( openpgp_md_test_algo(opt.s2k_digest_algo) )
log_error(_("selected digest algorithm is invalid\n"));
}
@@ -1125,7 +1128,7 @@ main( int argc, char **argv )
if( argc > 1 )
wrong_args(_("--sign [filename]"));
if( argc ) {
- sl = m_alloc_clear( sizeof *sl + strlen(fname));
+ sl = gcry_xcalloc( 1, sizeof *sl + strlen(fname));
strcpy(sl->d, fname);
}
}
@@ -1138,7 +1141,7 @@ main( int argc, char **argv )
if( argc > 1 )
wrong_args(_("--sign --encrypt [filename]"));
if( argc ) {
- sl = m_alloc_clear( sizeof *sl + strlen(fname));
+ sl = gcry_xcalloc( 1, sizeof *sl + strlen(fname));
strcpy(sl->d, fname);
}
else
@@ -1173,7 +1176,7 @@ main( int argc, char **argv )
wrong_args(_("--sign-key user-id"));
username = make_username( fname );
keyedit_menu(fname, locusr, NULL, 1 );
- m_free(username);
+ gcry_free(username);
break;
case aLSignKey:
@@ -1181,7 +1184,7 @@ main( int argc, char **argv )
wrong_args(_("--lsign-key user-id"));
username = make_username( fname );
keyedit_menu(fname, locusr, NULL, 2 );
- m_free(username);
+ gcry_free(username);
break;
case aEditKey: /* Edit a key signature */
@@ -1197,7 +1200,7 @@ main( int argc, char **argv )
}
else
keyedit_menu(username, locusr, NULL, 0 );
- m_free(username);
+ gcry_free(username);
break;
case aDeleteSecretKey:
@@ -1209,7 +1212,7 @@ main( int argc, char **argv )
username = make_username( fname );
if( (rc = delete_key(username, cmd==aDeleteSecretKey)) )
log_error("%s: delete key failed: %s\n", username, g10_errstr(rc) );
- m_free(username);
+ gcry_free(username);
break;
@@ -1294,7 +1297,7 @@ main( int argc, char **argv )
wrong_args("--gen-revoke user-id");
username = make_username(*argv);
gen_revoke( username );
- m_free( username );
+ gcry_free( username );
break;
case aDeArmor:
@@ -1365,7 +1368,7 @@ main( int argc, char **argv )
p = gcry_random_bytes( n, level );
fwrite( p, n, 1, stdout );
- m_free(p);
+ gcry_free(p);
if( !endless )
count -= n;
}
@@ -1424,7 +1427,7 @@ main( int argc, char **argv )
for( ; argc; argc--, argv++ ) {
username = make_username( *argv );
check_trustdb( username );
- m_free(username);
+ gcry_free(username);
}
}
break;
@@ -1441,7 +1444,7 @@ main( int argc, char **argv )
for( ; argc; argc--, argv++ ) {
username = make_username( *argv );
list_trust_path( username );
- m_free(username);
+ gcry_free(username);
}
break;
@@ -1501,12 +1504,12 @@ void
g10_exit( int rc )
{
if( opt.debug & DBG_MEMSTAT_VALUE ) {
- m_print_stats("on exit");
+ gcry_control( GCRYCTL_DUMP_MEMORY_STATS );
gcry_control( GCRYCTL_DUMP_RANDOM_STATS );
}
if( opt.debug )
gcry_control( GCRYCTL_DUMP_SECMEM_STATS );
- secmem_term();
+ gcry_control( GCRYCTL_TERM_SECMEM );
rc = rc? rc : log_get_errorcount(0)? 2 :
g10_errors_seen? 1 : 0;
/*write_status( STATUS_LEAVE );*/
@@ -1562,16 +1565,16 @@ print_mds( const char *fname, int algo )
if( !fname ) {
fp = stdin;
- pname = m_strdup("[stdin]: ");
+ pname = gcry_xstrdup("[stdin]: ");
}
else {
- pname = m_alloc(strlen(fname)+3);
+ pname = gcry_xmalloc(strlen(fname)+3);
strcpy(stpcpy(pname,fname),": ");
fp = fopen( fname, "rb" );
}
if( !fp ) {
log_error("%s%s\n", pname, strerror(errno) );
- m_free(pname);
+ gcry_free(pname);
return;
}
diff --git a/g10/getkey.c b/g10/getkey.c
index a94b5de48..bf36fcb96 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -27,7 +27,6 @@
#include <gcrypt.h>
#include "util.h"
#include "packet.h"
-#include "memory.h"
#include "iobuf.h"
#include "keydb.h"
#include "options.h"
@@ -208,7 +207,7 @@ cache_public_key( PKT_public_key *pk )
return;
}
pk_cache_entries++;
- ce = m_alloc( sizeof *ce );
+ ce = gcry_xmalloc( sizeof *ce );
ce->next = pk_cache;
pk_cache = ce;
ce->pk = copy_public_key( NULL, pk );
@@ -237,10 +236,10 @@ cache_user_id( PKT_user_id *uid, u32 *keyid )
/* fixme: use another algorithm to free some cache slots */
r = user_id_db;
user_id_db = r->next;
- m_free(r);
+ gcry_free(r);
uid_cache_entries--;
}
- r = m_alloc( sizeof *r + uid->len-1 );
+ r = gcry_xmalloc( sizeof *r + uid->len-1 );
r->keyid[0] = keyid[0];
r->keyid[1] = keyid[1];
r->len = uid->len;
@@ -259,7 +258,7 @@ getkey_disable_caches()
keyid_list_t kl, kl2;
for( kl = unknown_keyids; kl; kl = kl2 ) {
kl2 = kl->next;
- m_free(kl);
+ gcry_free(kl);
}
unknown_keyids = NULL;
unk_cache_disabled = 1;
@@ -272,7 +271,7 @@ getkey_disable_caches()
for( ce = pk_cache; ce; ce = ce2 ) {
ce2 = ce->next;
free_public_key( ce->pk );
- m_free( ce );
+ gcry_free( ce );
}
pk_cache_disabled=1;
pk_cache_entries = 0;
@@ -317,7 +316,7 @@ get_pubkey( PKT_public_key *pk, u32 *keyid )
#endif
/* more init stuff */
if( !pk ) {
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
internal++;
}
@@ -348,7 +347,7 @@ get_pubkey( PKT_public_key *pk, u32 *keyid )
else {
keyid_list_t kl;
- kl = m_alloc( sizeof *kl );
+ kl = gcry_xmalloc( sizeof *kl );
kl->keyid[0] = keyid[0];
kl->keyid[1] = keyid[1];
kl->next = unknown_keyids;
@@ -369,7 +368,7 @@ get_pubkey( PKT_public_key *pk, u32 *keyid )
KBNODE
get_pubkeyblock( u32 *keyid )
{
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
struct getkey_ctx_s ctx;
int rc = 0;
KBNODE keyblock = NULL;
@@ -454,7 +453,7 @@ seckey_available( u32 *keyid )
struct getkey_ctx_s ctx;
PKT_secret_key *sk;
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
memset( &ctx, 0, sizeof ctx );
ctx.not_allocated = 1;
ctx.nitems = 1;
@@ -704,7 +703,7 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
/* and we don't have mode 6 */
for(n=0, r=namelist; r; r = r->next )
n++;
- ctx = m_alloc_clear( sizeof *ctx + (n-1)*sizeof ctx->items );
+ ctx = gcry_xcalloc( 1, sizeof *ctx + (n-1)*sizeof ctx->items );
ctx->nitems = n;
for(n=0, r=namelist; r; r = r->next, n++ ) {
@@ -714,7 +713,7 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
&ctx->items[n].name,
NULL );
if( !ctx->items[n].mode ) {
- m_free( ctx );
+ gcry_free( ctx );
return G10ERR_INV_USER_ID;
}
if( ctx->items[n].mode == 6 ) {
@@ -736,8 +735,8 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
/* Hmmm, why not get_pubkey-end here?? */
enum_keyblocks( 2, &ctx->kbpos, NULL ); /* close */
for(n=0; n < ctx->nitems; n++ )
- m_free( ctx->items[n].namebuf );
- m_free( ctx );
+ gcry_free( ctx->items[n].namebuf );
+ gcry_free( ctx );
}
return rc;
@@ -754,7 +753,7 @@ get_pubkey_byname( GETKEY_CTX *retctx, PKT_public_key *pk,
if( !pk ) {
/* Performance Hint: key_byname should not need a pk here */
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = key_byname( retctx, namelist, pk, NULL, ret_keyblock );
free_public_key( pk );
}
@@ -773,7 +772,7 @@ get_pubkey_bynames( GETKEY_CTX *retctx, PKT_public_key *pk,
if( !pk ) {
/* Performance Hint: key_byname should not need a pk here */
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = key_byname( retctx, names, pk, NULL, ret_keyblock );
free_public_key( pk );
}
@@ -790,7 +789,7 @@ get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock )
if( !pk ) {
/* Performance Hint: lookup_read should not need a pk in this case */
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = lookup_pk( ctx, pk, ret_keyblock );
free_public_key( pk );
}
@@ -807,9 +806,9 @@ get_pubkey_end( GETKEY_CTX ctx )
enum_keyblocks( 2, &ctx->kbpos, NULL ); /* close */
for(n=0; n < ctx->nitems; n++ )
- m_free( ctx->items[n].namebuf );
+ gcry_free( ctx->items[n].namebuf );
if( !ctx->not_allocated )
- m_free( ctx );
+ gcry_free( ctx );
}
}
@@ -845,7 +844,7 @@ get_keyblock_byfprint( KBNODE *ret_keyblock, const byte *fprint,
size_t fprint_len )
{
int rc;
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
if( fprint_len == 20 || fprint_len == 16 ) {
struct getkey_ctx_s ctx;
@@ -873,7 +872,7 @@ int
get_keyblock_bylid( KBNODE *ret_keyblock, ulong lid )
{
int rc;
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
struct getkey_ctx_s ctx;
u32 kid[2];
@@ -942,7 +941,7 @@ get_seckey_bynames( GETKEY_CTX *retctx, PKT_secret_key *sk,
if( !sk ) {
/* Performance Hint: key_byname should not need a sk here */
- sk = m_alloc_secure_clear( sizeof *sk );
+ sk = gcry_xcalloc_secure( 1, sizeof *sk );
rc = key_byname( retctx, names, NULL, sk, ret_keyblock );
free_secret_key( sk );
}
@@ -960,7 +959,7 @@ get_seckey_next( GETKEY_CTX ctx, PKT_secret_key *sk, KBNODE *ret_keyblock )
if( !sk ) {
/* Performance Hint: lookup_read should not need a pk in this case */
- sk = m_alloc_secure_clear( sizeof *sk );
+ sk = gcry_xcalloc_secure( 1, sizeof *sk );
rc = lookup_sk( ctx, sk, ret_keyblock );
free_secret_key( sk );
}
@@ -977,9 +976,9 @@ get_seckey_end( GETKEY_CTX ctx )
enum_keyblocks( 2, &ctx->kbpos, NULL ); /* close */
for(n=0; n < ctx->nitems; n++ )
- m_free( ctx->items[n].namebuf );
+ gcry_free( ctx->items[n].namebuf );
if( !ctx->not_allocated )
- m_free( ctx );
+ gcry_free( ctx );
}
}
@@ -1051,7 +1050,7 @@ prepare_word_match( const byte *name )
int c;
/* the original length is always enough for the pattern */
- p = pattern = m_alloc(strlen(name)+1);
+ p = pattern = gcry_xmalloc(strlen(name)+1);
do {
/* skip leading delimiters */
while( *name && !word_match_chars[*name] )
@@ -1817,7 +1816,7 @@ enum_secret_keys( void **context, PKT_secret_key *sk, int with_subkeys )
if( !c ) { /* make a new context */
- c = m_alloc_clear( sizeof *c );
+ c = gcry_xcalloc( 1, sizeof *c );
*context = c;
c->sequence = 0;
c->name = enum_keyblock_resources( &c->sequence, 1 );
@@ -1826,7 +1825,7 @@ enum_secret_keys( void **context, PKT_secret_key *sk, int with_subkeys )
if( !sk ) { /* free the context */
if( c->iobuf )
iobuf_close(c->iobuf);
- m_free( c );
+ gcry_free( c );
*context = NULL;
return 0;
}
@@ -1878,12 +1877,12 @@ get_user_id_string( u32 *keyid )
do {
for(r=user_id_db; r; r = r->next )
if( r->keyid[0] == keyid[0] && r->keyid[1] == keyid[1] ) {
- p = m_alloc( r->len + 10 );
+ p = gcry_xmalloc( r->len + 10 );
sprintf(p, "%08lX %.*s", (ulong)keyid[1], r->len, r->name );
return p;
}
} while( ++pass < 2 && !get_pubkey( NULL, keyid ) );
- p = m_alloc( 15 );
+ p = gcry_xmalloc( 15 );
sprintf(p, "%08lX [?]", (ulong)keyid[1] );
return p;
}
@@ -1898,13 +1897,13 @@ get_long_user_id_string( u32 *keyid )
do {
for(r=user_id_db; r; r = r->next )
if( r->keyid[0] == keyid[0] && r->keyid[1] == keyid[1] ) {
- p = m_alloc( r->len + 20 );
+ p = gcry_xmalloc( r->len + 20 );
sprintf(p, "%08lX%08lX %.*s",
(ulong)keyid[0], (ulong)keyid[1], r->len, r->name );
return p;
}
} while( ++pass < 2 && !get_pubkey( NULL, keyid ) );
- p = m_alloc( 25 );
+ p = gcry_xmalloc( 25 );
sprintf(p, "%08lX%08lX [?]", (ulong)keyid[0], (ulong)keyid[1] );
return p;
}
@@ -1919,13 +1918,13 @@ get_user_id( u32 *keyid, size_t *rn )
do {
for(r=user_id_db; r; r = r->next )
if( r->keyid[0] == keyid[0] && r->keyid[1] == keyid[1] ) {
- p = m_alloc( r->len );
+ p = gcry_xmalloc( r->len );
memcpy(p, r->name, r->len );
*rn = r->len;
return p;
}
} while( ++pass < 2 && !get_pubkey( NULL, keyid ) );
- p = m_alloc( 19 );
+ p = gcry_xmalloc( 19 );
memcpy(p, "[User id not found]", 19 );
*rn = 19;
return p;
diff --git a/g10/gpgd.c b/g10/gpgd.c
index 6ee87ec8a..50eb7db59 100644
--- a/g10/gpgd.c
+++ b/g10/gpgd.c
@@ -112,7 +112,7 @@ build_list( const char *text, const char * (*mapf)(int), int (*chkf)(int) )
for(i=1; i < 100; i++ )
if( !chkf(i) && (s=mapf(i)) )
n += strlen(s) + 2;
- list = m_alloc( 21 + n ); *list = 0;
+ list = gcry_xmalloc( 21 + n ); *list = 0;
for(p=NULL, i=1; i < 100; i++ ) {
if( !chkf(i) && (s=mapf(i)) ) {
if( !p )
@@ -203,7 +203,7 @@ main( int argc, char **argv )
configname, strerror(errno) );
g10_exit(1);
}
- m_free(configname); configname = NULL;
+ gcry_free(configname); configname = NULL;
}
if( parse_debug && configname )
log_info("reading options from `%s'\n", configname );
@@ -216,8 +216,8 @@ main( int argc, char **argv )
case 'v': opt.verbose++; break;
case 501:
if( !configfp ) {
- m_free(configname);
- configname = m_strdup(pargs.r.ret_str);
+ gcry_free(configname);
+ configname = gcry_xstrdup(pargs.r.ret_str);
goto next_pass;
}
break;
@@ -230,10 +230,10 @@ main( int argc, char **argv )
if( configfp ) {
fclose( configfp );
configfp = NULL;
- m_free(configname); configname = NULL;
+ gcry_free(configname); configname = NULL;
goto next_pass;
}
- m_free( configname ); configname = NULL;
+ gcry_free( configname ); configname = NULL;
if( log_get_errorcount(0) )
g10_exit(2);
diff --git a/g10/hkp.c b/g10/hkp.c
index 507bc5ce1..a608f001d 100644
--- a/g10/hkp.c
+++ b/g10/hkp.c
@@ -30,7 +30,7 @@
#include "util.h"
#include "ttyio.h"
#include "i18n.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "options.h"
#include "filter.h"
#include "http.h"
@@ -61,7 +61,7 @@ hkp_ask_import( u32 *keyid )
return -1;
log_info("requesting key %08lX from %s ...\n", (ulong)keyid[1],
opt.keyserver_name );
- request = m_alloc( strlen( opt.keyserver_name ) + 100 );
+ request = gcry_xmalloc( strlen( opt.keyserver_name ) + 100 );
/* hkp does not accept the long keyid - we should really write a
* nicer one */
sprintf( request, "x-hkp://%s:11371/pks/lookup?op=get&search=0x%08lX",
@@ -77,7 +77,7 @@ hkp_ask_import( u32 *keyid )
http_close( &hd );
}
- m_free( request );
+ gcry_free( request );
return rc;
#endif
}
@@ -141,7 +141,7 @@ hkp_export( STRLIST users )
iobuf_flush_temp( temp );
- request = m_alloc( strlen( opt.keyserver_name ) + 100 );
+ request = gcry_xmalloc( strlen( opt.keyserver_name ) + 100 );
sprintf( request, "x-hkp://%s:11371/pks/add", opt.keyserver_name );
rc = http_open( &hd, HTTP_REQ_POST, request , 0 );
if( rc ) {
@@ -150,14 +150,14 @@ hkp_export( STRLIST users )
rc == G10ERR_NETWORK? strerror(errno)
: g10_errstr(rc) );
iobuf_close(temp);
- m_free( request );
+ gcry_free( request );
return rc;
}
sprintf( request, "Content-Length: %u\n",
(unsigned)iobuf_get_temp_length(temp) + 9 );
iobuf_writestr( hd.fp_write, request );
- m_free( request );
+ gcry_free( request );
http_start_data( &hd );
iobuf_writestr( hd.fp_write, "keytext=" );
diff --git a/g10/import.c b/g10/import.c
index 368ea8b75..01f70dbd4 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -29,7 +29,7 @@
#include "packet.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "trustdb.h"
#include "main.h"
@@ -145,7 +145,7 @@ import( IOBUF inp, int fast, const char* fname )
getkey_disable_caches();
if( !opt.no_armor ) { /* armored reading is not disabled */
- armor_filter_context_t *afx = m_alloc_clear( sizeof *afx );
+ armor_filter_context_t *afx = gcry_xcalloc( 1, sizeof *afx );
afx->only_keyblocks = 1;
iobuf_push_filter2( inp, armor_filter, afx, 1 );
}
@@ -244,7 +244,7 @@ read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root )
}
else
in_cert = 0;
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
while( (rc=parse_packet(a, pkt)) != -1 ) {
if( rc ) { /* ignore errors */
@@ -276,7 +276,7 @@ read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root )
goto ready;
}
{
- compress_filter_context_t *cfx = m_alloc_clear( sizeof *cfx );
+ compress_filter_context_t *cfx = gcry_xcalloc( 1, sizeof *cfx );
cfx->algo = pkt->pkt.compressed->algorithm;
pkt->pkt.compressed->buf = NULL;
iobuf_push_filter2( a, compress_filter, cfx, 1 );
@@ -300,7 +300,7 @@ read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root )
root = new_kbnode( pkt );
else
add_kbnode( root, new_kbnode( pkt ) );
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
}
init_packet(pkt);
break;
@@ -315,7 +315,7 @@ read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root )
else
*ret_root = root;
free_packet( pkt );
- m_free( pkt );
+ gcry_free( pkt );
return rc;
}
@@ -383,7 +383,7 @@ import_one( const char *fname, KBNODE keyblock, int fast )
/* do we have this key already in one of our pubrings ? */
- pk_orig = m_alloc_clear( sizeof *pk_orig );
+ pk_orig = gcry_xcalloc( 1, sizeof *pk_orig );
rc = get_pubkey( pk_orig, keyid );
if( rc && rc != G10ERR_NO_PUBKEY ) {
log_error( _("key %08lX: public key not found: %s\n"),
@@ -411,7 +411,7 @@ import_one( const char *fname, KBNODE keyblock, int fast )
if( is_status_enabled() ) {
char *us = get_long_user_id_string( keyid );
write_status_text( STATUS_IMPORTED, us );
- m_free(us);
+ gcry_free(us);
}
stats.imported++;
if( is_RSA( pk->pubkey_algo ) )
@@ -609,7 +609,7 @@ import_revoke_cert( const char *fname, KBNODE node )
keyid[0] = node->pkt->pkt.signature->keyid[0];
keyid[1] = node->pkt->pkt.signature->keyid[1];
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = get_pubkey( pk, keyid );
if( rc == G10ERR_NO_PUBKEY ) {
log_info( _("key %08lX: no public key - "
diff --git a/g10/kbnode.c b/g10/kbnode.c
index 282d8b42e..79c1386aa 100644
--- a/g10/kbnode.c
+++ b/g10/kbnode.c
@@ -24,7 +24,7 @@
#include <string.h>
#include <assert.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "packet.h"
#include "keydb.h"
@@ -41,7 +41,7 @@ alloc_node(void)
if( n )
unused_nodes = n->next;
else
- n = m_alloc( sizeof *n );
+ n = gcry_xmalloc( sizeof *n );
n->next = NULL;
n->pkt = NULL;
n->flag = 0;
@@ -58,7 +58,7 @@ free_node( KBNODE n )
n->next = unused_nodes;
unused_nodes = n;
#else
- m_free( n );
+ gcry_free( n );
#endif
}
}
@@ -94,7 +94,7 @@ release_kbnode( KBNODE n )
n2 = n->next;
if( !is_cloned_kbnode(n) ) {
free_packet( n->pkt );
- m_free( n->pkt );
+ gcry_free( n->pkt );
}
free_node( n );
n = n2;
@@ -266,7 +266,7 @@ commit_kbnode( KBNODE *root )
nl->next = n->next;
if( !is_cloned_kbnode(n) ) {
free_packet( n->pkt );
- m_free( n->pkt );
+ gcry_free( n->pkt );
}
free_node( n );
changed = 1;
@@ -290,7 +290,7 @@ remove_kbnode( KBNODE *root, KBNODE node )
nl->next = n->next;
if( !is_cloned_kbnode(n) ) {
free_packet( n->pkt );
- m_free( n->pkt );
+ gcry_free( n->pkt );
}
free_node( n );
}
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 91bba4723..74f97aa95 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -31,7 +31,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "trustdb.h"
@@ -158,7 +158,7 @@ print_and_check_one_sig( KBNODE keyblock, KBNODE node,
size_t n;
char *p = get_user_id( sig->keyid, &n );
tty_print_utf8_string( p, n > 40? 40 : n );
- m_free(p);
+ gcry_free(p);
}
tty_printf("\n");
}
@@ -331,7 +331,7 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified, int local )
"with your key: \""));
p = get_user_id( sk_keyid, &n );
tty_print_utf8_string( p, n );
- m_free(p); p = NULL;
+ gcry_free(p); p = NULL;
tty_printf("\"\n\n");
if( local )
@@ -373,7 +373,7 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified, int local )
*ret_modified = 1; /* we changed the keyblock */
upd_trust = 1;
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = sig;
insert_kbnode( node, new_kbnode(pkt), PKT_SIGNATURE );
@@ -443,7 +443,7 @@ change_passphrase( KBNODE keyblock )
tty_printf(_("Can't edit this key: %s\n"), g10_errstr(rc));
else {
DEK *dek = NULL;
- STRING2KEY *s2k = m_alloc_secure( sizeof *s2k );
+ STRING2KEY *s2k = gcry_xmalloc_secure( sizeof *s2k );
tty_printf(_("Enter the new passphrase for this secret key.\n\n") );
@@ -483,12 +483,12 @@ change_passphrase( KBNODE keyblock )
break;
}
}
- m_free(s2k);
- m_free(dek);
+ gcry_free(s2k);
+ gcry_free(dek);
}
leave:
- m_free( passphrase );
+ gcry_free( passphrase );
set_next_passphrase( NULL );
return changed && !rc;
}
@@ -665,14 +665,14 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
redisplay = 0;
}
do {
- m_free(answer);
+ gcry_free(answer);
if( have_commands ) {
if( commands ) {
- answer = m_strdup( commands->d );
+ answer = gcry_xstrdup( commands->d );
commands = commands->next;
}
else if( opt.batch ) {
- answer = m_strdup("quit");
+ answer = gcry_xstrdup("quit");
}
else
have_commands = 0;
@@ -980,7 +980,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
leave:
release_kbnode( keyblock );
release_kbnode( sec_keyblock );
- m_free(answer);
+ gcry_free(answer);
}
@@ -1020,7 +1020,7 @@ show_prefs( KBNODE keyblock, PKT_user_id *uid )
}
tty_printf("\n");
- m_free(p);
+ gcry_free(p);
}
@@ -1224,7 +1224,7 @@ menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock )
}
/* insert/append to secret keyblock */
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_USER_ID;
pkt->pkt.user_id = copy_user_id(NULL, uid);
node = new_kbnode(pkt);
@@ -1232,7 +1232,7 @@ menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock )
insert_kbnode( sec_where, node, 0 );
else
add_kbnode( sec_keyblock, node );
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = copy_signature(NULL, sig);
if( sec_where )
@@ -1240,7 +1240,7 @@ menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock )
else
add_kbnode( sec_keyblock, new_kbnode(pkt) );
/* insert/append to public keyblock */
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_USER_ID;
pkt->pkt.user_id = uid;
node = new_kbnode(pkt);
@@ -1248,7 +1248,7 @@ menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock )
insert_kbnode( pub_where, node, 0 );
else
add_kbnode( pub_keyblock, node );
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = copy_signature(NULL, sig);
if( pub_where )
@@ -1521,18 +1521,18 @@ menu_expire( KBNODE pub_keyblock, KBNODE sec_keyblock )
return 0;
}
/* replace the packet */
- newpkt = m_alloc_clear( sizeof *newpkt );
+ newpkt = gcry_xcalloc( 1, sizeof *newpkt );
newpkt->pkttype = PKT_SIGNATURE;
newpkt->pkt.signature = newsig;
free_packet( node->pkt );
- m_free( node->pkt );
+ gcry_free( node->pkt );
node->pkt = newpkt;
if( sn ) {
- newpkt = m_alloc_clear( sizeof *newpkt );
+ newpkt = gcry_xcalloc( 1, sizeof *newpkt );
newpkt->pkttype = PKT_SIGNATURE;
newpkt->pkt.signature = copy_signature( NULL, newsig );
free_packet( sn->pkt );
- m_free( sn->pkt );
+ gcry_free( sn->pkt );
sn->pkt = newpkt;
}
}
@@ -1815,7 +1815,7 @@ menu_revsig( KBNODE keyblock )
memset( &attrib, 0, sizeof attrib );
node->flag &= ~NODFLG_MARK_A;
- sk = m_alloc_secure_clear( sizeof *sk );
+ sk = gcry_xcalloc_secure( 1, sizeof *sk );
if( get_seckey( sk, node->pkt->pkt.signature->keyid ) ) {
log_info(_("no secret key\n"));
continue;
@@ -1835,7 +1835,7 @@ menu_revsig( KBNODE keyblock )
changed = 1; /* we changed the keyblock */
upd_trust = 1;
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = sig;
insert_kbnode( unode, new_kbnode(pkt), 0 );
@@ -1884,7 +1884,7 @@ menu_revkey( KBNODE pub_keyblock, KBNODE sec_keyblock )
changed = 1; /* we changed the keyblock */
upd_trust = 1;
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = sig;
insert_kbnode( node, new_kbnode(pkt), 0 );
diff --git a/g10/keygen.c b/g10/keygen.c
index 10f27952a..805160696 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -26,7 +26,7 @@
#include <errno.h>
#include <assert.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "main.h"
#include "packet.h"
#include "dummy-cipher.h"
@@ -40,11 +40,11 @@
static void
write_uid( KBNODE root, const char *s )
{
- PACKET *pkt = m_alloc_clear(sizeof *pkt );
+ PACKET *pkt = gcry_xcalloc( 1,sizeof *pkt );
size_t n = strlen(s);
pkt->pkttype = PKT_USER_ID;
- pkt->pkt.user_id = m_alloc( sizeof *pkt->pkt.user_id + n - 1 );
+ pkt->pkt.user_id = gcry_xmalloc( sizeof *pkt->pkt.user_id + n - 1 );
pkt->pkt.user_id->len = n;
strcpy(pkt->pkt.user_id->name, s);
add_kbnode( root, new_kbnode( pkt ) );
@@ -141,7 +141,7 @@ write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_key *sk )
return rc;
}
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = sig;
add_kbnode( root, new_kbnode( pkt ) );
@@ -182,7 +182,7 @@ write_keybinding( KBNODE root, KBNODE pub_root, PKT_secret_key *sk )
return rc;
}
- pkt = m_alloc_clear( sizeof *pkt );
+ pkt = gcry_xcalloc( 1, sizeof *pkt );
pkt->pkttype = PKT_SIGNATURE;
pkt->pkt.signature = sig;
add_kbnode( root, new_kbnode( pkt ) );
@@ -210,8 +210,8 @@ gen_elg(int algo, unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
return rc;
}
- sk = m_alloc_clear( sizeof *sk );
- pk = m_alloc_clear( sizeof *pk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
sk->timestamp = pk->timestamp = make_timestamp();
sk->version = pk->version = version;
if( expireval ) {
@@ -244,14 +244,14 @@ gen_elg(int algo, unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
}
}
- pkt = m_alloc_clear(sizeof *pkt);
+ pkt = gcry_xcalloc( 1,sizeof *pkt);
pkt->pkttype = ret_sk ? PKT_PUBLIC_KEY : PKT_PUBLIC_SUBKEY;
pkt->pkt.public_key = pk;
add_kbnode(pub_root, new_kbnode( pkt ));
/* don't know whether it makes sense to have the factors, so for now
* we store them in the secret keyring (but they are not secret) */
- pkt = m_alloc_clear(sizeof *pkt);
+ pkt = gcry_xcalloc( 1,sizeof *pkt);
pkt->pkttype = ret_sk ? PKT_SECRET_KEY : PKT_SECRET_SUBKEY;
pkt->pkt.secret_key = sk;
add_kbnode(sec_root, new_kbnode( pkt ));
@@ -287,8 +287,8 @@ gen_dsa(unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
return rc;
}
- sk = m_alloc_clear( sizeof *sk );
- pk = m_alloc_clear( sizeof *pk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
sk->timestamp = pk->timestamp = make_timestamp();
sk->version = pk->version = 4;
if( expireval ) {
@@ -323,7 +323,7 @@ gen_dsa(unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
}
}
- pkt = m_alloc_clear(sizeof *pkt);
+ pkt = gcry_xcalloc( 1,sizeof *pkt);
pkt->pkttype = ret_sk ? PKT_PUBLIC_KEY : PKT_PUBLIC_SUBKEY;
pkt->pkt.public_key = pk;
add_kbnode(pub_root, new_kbnode( pkt ));
@@ -334,7 +334,7 @@ gen_dsa(unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
* We store only f1 to f_n-1; fn can be calculated because p and q
* are known.
*/
- pkt = m_alloc_clear(sizeof *pkt);
+ pkt = gcry_xcalloc( 1,sizeof *pkt);
pkt->pkttype = ret_sk ? PKT_SECRET_KEY : PKT_SECRET_SUBKEY;
pkt->pkt.secret_key = sk;
add_kbnode(sec_root, new_kbnode( pkt ));
@@ -400,7 +400,7 @@ ask_algo( int *ret_v4, int addmode )
answer = cpr_get("keygen.algo",_("Your selection? "));
cpr_kill_prompt();
algo = *answer? atoi(answer): 1;
- m_free(answer);
+ gcry_free(answer);
if( algo == 1 && !addmode ) {
algo = 0; /* create both keys */
break;
@@ -450,7 +450,7 @@ ask_keysize( int algo )
_("What keysize do you want? (1024) "));
cpr_kill_prompt();
nbits = *answer? atoi(answer): 1024;
- m_free(answer);
+ gcry_free(answer);
if( algo == GCRY_PK_DSA && (nbits < 512 || nbits > 1024) )
tty_printf(_("DSA only allows keysizes from 512 to 1024\n"));
else if( nbits < 768 )
@@ -523,7 +523,7 @@ ask_expire_interval(void)
u32 abs_date=0;
u32 curtime=0;;
- m_free(answer);
+ gcry_free(answer);
answer = cpr_get("keygen.valid",_("Key is valid for? (0) "));
cpr_kill_prompt();
trim_spaces(answer);
@@ -564,7 +564,7 @@ ask_expire_interval(void)
_("Is this correct (y/n)? ")) )
break;
}
- m_free(answer);
+ gcry_free(answer);
return interval;
}
@@ -614,7 +614,7 @@ ask_user_id( int mode )
if( !aname ) {
for(;;) {
- m_free(aname);
+ gcry_free(aname);
aname = cpr_get("keygen.name",_("Real name: "));
trim_spaces(aname);
cpr_kill_prompt();
@@ -630,7 +630,7 @@ ask_user_id( int mode )
}
if( !amail ) {
for(;;) {
- m_free(amail);
+ gcry_free(amail);
amail = cpr_get("keygen.email",_("Email address: "));
trim_spaces(amail);
cpr_kill_prompt();
@@ -649,7 +649,7 @@ ask_user_id( int mode )
}
if( !acomment ) {
for(;;) {
- m_free(acomment);
+ gcry_free(acomment);
acomment = cpr_get("keygen.comment",_("Comment: "));
trim_spaces(acomment);
cpr_kill_prompt();
@@ -662,8 +662,8 @@ ask_user_id( int mode )
}
}
- m_free(uid);
- uid = p = m_alloc(strlen(aname)+strlen(amail)+strlen(acomment)+12+10);
+ gcry_free(uid);
+ uid = p = gcry_xmalloc(strlen(aname)+strlen(amail)+strlen(acomment)+12+10);
p = stpcpy(p, aname );
if( *acomment )
p = stpcpy(stpcpy(stpcpy(p," ("), acomment),")");
@@ -672,8 +672,11 @@ ask_user_id( int mode )
/* append a warning if we do not have dev/random
* or it is switched into quick testmode */
+ #warning quick_random_gen() not available
+ #if 0
if( quick_random_gen(-1) )
strcpy(p, " (INSECURE!)" );
+ #endif
/* print a note in case that UTF8 mapping has to be done */
for(p=uid; *p; p++ ) {
@@ -692,7 +695,7 @@ ask_user_id( int mode )
if( strlen(ansstr) != 10 )
BUG();
if( cpr_enabled() ) {
- answer = m_strdup(ansstr+6);
+ answer = gcry_xstrdup(ansstr+6);
answer[1] = 0;
}
else {
@@ -703,40 +706,40 @@ ask_user_id( int mode )
if( strlen(answer) > 1 )
;
else if( *answer == ansstr[0] || *answer == ansstr[1] ) {
- m_free(aname); aname = NULL;
+ gcry_free(aname); aname = NULL;
break;
}
else if( *answer == ansstr[2] || *answer == ansstr[3] ) {
- m_free(acomment); acomment = NULL;
+ gcry_free(acomment); acomment = NULL;
break;
}
else if( *answer == ansstr[4] || *answer == ansstr[5] ) {
- m_free(amail); amail = NULL;
+ gcry_free(amail); amail = NULL;
break;
}
else if( *answer == ansstr[6] || *answer == ansstr[7] ) {
- m_free(aname); aname = NULL;
- m_free(acomment); acomment = NULL;
- m_free(amail); amail = NULL;
+ gcry_free(aname); aname = NULL;
+ gcry_free(acomment); acomment = NULL;
+ gcry_free(amail); amail = NULL;
break;
}
else if( *answer == ansstr[8] || *answer == ansstr[9] ) {
- m_free(aname); aname = NULL;
- m_free(acomment); acomment = NULL;
- m_free(amail); amail = NULL;
- m_free(uid); uid = NULL;
+ gcry_free(aname); aname = NULL;
+ gcry_free(acomment); acomment = NULL;
+ gcry_free(amail); amail = NULL;
+ gcry_free(uid); uid = NULL;
break;
}
- m_free(answer);
+ gcry_free(answer);
}
- m_free(answer);
+ gcry_free(answer);
if( !amail && !acomment && !amail )
break;
- m_free(uid); uid = NULL;
+ gcry_free(uid); uid = NULL;
}
if( uid ) {
char *p = native_to_utf8( uid );
- m_free( uid );
+ gcry_free( uid );
uid = p;
}
return uid;
@@ -751,7 +754,7 @@ ask_passphrase( STRING2KEY **ret_s2k )
tty_printf(_("You need a Passphrase to protect your secret key.\n\n") );
- s2k = m_alloc_secure( sizeof *s2k );
+ s2k = gcry_xmalloc_secure( sizeof *s2k );
for(;;) {
s2k->mode = opt.s2k_mode;
s2k->hash_algo = opt.s2k_digest_algo;
@@ -760,8 +763,8 @@ ask_passphrase( STRING2KEY **ret_s2k )
tty_printf(_("passphrase not correctly repeated; try again.\n"));
}
else if( !dek->keylen ) {
- m_free(dek); dek = NULL;
- m_free(s2k); s2k = NULL;
+ gcry_free(dek); dek = NULL;
+ gcry_free(s2k); s2k = NULL;
tty_printf(_(
"You don't want a passphrase - this is probably a *bad* idea!\n"
"I will do it anyway. You can change your passphrase at any time,\n"
@@ -825,7 +828,7 @@ generate_user_id()
if( !p )
return NULL;
n = strlen(p);
- uid = m_alloc( sizeof *uid + n - 1 );
+ uid = gcry_xmalloc( sizeof *uid + n - 1 );
uid->len = n;
strcpy(uid->name, p);
return uid;
@@ -977,11 +980,11 @@ generate_keypair()
release_kbnode( sec_root );
if( sk ) /* the unprotected secret key */
free_secret_key(sk);
- m_free(uid);
- m_free(dek);
- m_free(s2k);
- m_free(pub_fname);
- m_free(sec_fname);
+ gcry_free(uid);
+ gcry_free(dek);
+ gcry_free(s2k);
+ gcry_free(pub_fname);
+ gcry_free(sec_fname);
}
@@ -1053,7 +1056,7 @@ generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock )
goto leave;
if( passphrase ) {
- s2k = m_alloc_secure( sizeof *s2k );
+ s2k = gcry_xmalloc_secure( sizeof *s2k );
s2k->mode = opt.s2k_mode;
s2k->hash_algo = opt.s2k_digest_algo;
set_next_passphrase( passphrase );
@@ -1072,9 +1075,9 @@ generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock )
leave:
if( rc )
log_error(_("Key generation failed: %s\n"), g10_errstr(rc) );
- m_free( passphrase );
- m_free( dek );
- m_free( s2k );
+ gcry_free( passphrase );
+ gcry_free( dek );
+ gcry_free( s2k );
if( sk ) /* release the copy of the (now unprotected) secret key */
free_secret_key(sk);
set_next_passphrase( NULL );
diff --git a/g10/keyid.c b/g10/keyid.c
index 774b90a9a..ddaf0d5d3 100644
--- a/g10/keyid.c
+++ b/g10/keyid.c
@@ -28,7 +28,6 @@
#include <gcrypt.h>
#include "util.h"
#include "main.h"
-#include "memory.h"
#include "packet.h"
#include "options.h"
#include "keydb.h"
@@ -70,8 +69,8 @@ do_fingerprint_md( PKT_public_key *pk )
rc = gcry_mpi_print( GCRYMPI_FMT_PGP, NULL, &nbytes, pk->pkey[i] );
assert( !rc );
/* fixme: we should try to allocate a buffer on the stack */
- pp[i] = m_alloc(nbytes);
- rc = gcry_mpi_print( GCRYMPI_FMT_PGP, pp[1], &nbytes, pk->pkey[i] );
+ pp[i] = gcry_xmalloc(nbytes);
+ rc = gcry_mpi_print( GCRYMPI_FMT_PGP, pp[i], &nbytes, pk->pkey[i] );
assert( !rc );
nn[i] = nbytes;
n += nn[i];
@@ -104,7 +103,7 @@ do_fingerprint_md( PKT_public_key *pk )
gcry_md_putc( md, pk->pubkey_algo );
for(i=0; i < npkey; i++ ) {
gcry_md_write( md, pp[i], nn[i] );
- m_free(pp[i]);
+ gcry_free(pp[i]);
}
gcry_md_final( md );
@@ -139,7 +138,7 @@ v3_keyid( MPI a, u32 *ki )
rc = gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, a );
assert( !rc );
/* fixme: allocate it on the stack */
- buffer = m_alloc(nbytes);
+ buffer = gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, buffer, &nbytes, a );
assert( !rc );
if( nbytes < 8 ) { /* oops */
@@ -149,7 +148,7 @@ v3_keyid( MPI a, u32 *ki )
memcpy( ki+0, buffer+nbytes-8, 4);
memcpy( ki+1, buffer+nbytes-4, 4);
}
- m_free( buffer );
+ gcry_free( buffer );
}
@@ -372,10 +371,9 @@ expirestr_from_sk( PKT_secret_key *sk )
byte *
fingerprint_from_pk( PKT_public_key *pk, byte *array, size_t *ret_len )
{
- byte *p, *buf;
+ byte *buf;
const char *dp;
size_t len;
- unsigned n;
if( pk->version < 4 && is_RSA(pk->pubkey_algo) ) {
/* RSA in version 3 packets is special */
@@ -391,23 +389,23 @@ fingerprint_from_pk( PKT_public_key *pk, byte *array, size_t *ret_len )
rc = gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, pk->pkey[0] );
assert( !rc );
/* fixme: allocate it on the stack */
- buf = m_alloc(nbytes);
+ buf = gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, pk->pkey[0] );
assert( !rc );
gcry_md_write( md, buf, nbytes );
- m_free(buf);
+ gcry_free(buf);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, pk->pkey[1] );
assert( !rc );
/* fixme: allocate it on the stack */
- buf = m_alloc(nbytes);
+ buf = gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, pk->pkey[1] );
assert( !rc );
gcry_md_write( md, buf, nbytes );
- m_free(buf);
+ gcry_free(buf);
}
gcry_md_final(md);
if( !array )
- array = m_alloc( 16 );
+ array = gcry_xmalloc( 16 );
len = 16;
memcpy(array, gcry_md_read(md, GCRY_MD_MD5), 16 );
gcry_md_close(md);
@@ -419,7 +417,7 @@ fingerprint_from_pk( PKT_public_key *pk, byte *array, size_t *ret_len )
len = gcry_md_get_algo_dlen( gcry_md_get_algo( md ) );
assert( len <= MAX_FINGERPRINT_LEN );
if( !array )
- array = m_alloc( len );
+ array = gcry_xmalloc( len );
memcpy(array, dp, len );
gcry_md_close(md);
}
@@ -431,10 +429,9 @@ fingerprint_from_pk( PKT_public_key *pk, byte *array, size_t *ret_len )
byte *
fingerprint_from_sk( PKT_secret_key *sk, byte *array, size_t *ret_len )
{
- byte *p, *buf;
+ byte *buf;
const char *dp;
size_t len;
- unsigned n;
if( sk->version < 4 && is_RSA(sk->pubkey_algo) ) {
/* RSA in version 3 packets is special */
@@ -451,23 +448,23 @@ fingerprint_from_sk( PKT_secret_key *sk, byte *array, size_t *ret_len )
rc = gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, sk->skey[1] );
assert( !rc );
/* fixme: allocate it on the stack */
- buf = m_alloc(nbytes);
+ buf = gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, sk->skey[1] );
assert( !rc );
gcry_md_write( md, buf, nbytes );
- m_free(buf);
+ gcry_free(buf);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, NULL, &nbytes, sk->skey[0] );
assert( !rc );
/* fixme: allocate it on the stack */
- buf = m_alloc(nbytes);
+ buf = gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_USG, buf, &nbytes, sk->skey[0] );
assert( !rc );
gcry_md_write( md, buf, nbytes );
- m_free(buf);
+ gcry_free(buf);
}
gcry_md_final(md);
if( !array )
- array = m_alloc( 16 );
+ array = gcry_xmalloc( 16 );
len = 16;
memcpy(array, gcry_md_read(md, GCRY_MD_MD5), 16 );
gcry_md_close(md);
@@ -479,7 +476,7 @@ fingerprint_from_sk( PKT_secret_key *sk, byte *array, size_t *ret_len )
len = gcry_md_get_algo_dlen( gcry_md_get_algo( md ) );
assert( len <= MAX_FINGERPRINT_LEN );
if( !array )
- array = m_alloc( len );
+ array = gcry_xmalloc( len );
memcpy(array, dp, len );
gcry_md_close(md);
}
diff --git a/g10/keylist.c b/g10/keylist.c
index 53e88f468..91e660352 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -29,7 +29,7 @@
#include "packet.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "trustdb.h"
#include "main.h"
@@ -159,7 +159,7 @@ print_key_data( PKT_public_key *pk, u32 *keyid )
int i;
for(i=0; i < n; i++ ) {
- printf("pkd:%d:%u:", i, mpi_get_nbits( pk->pkey[i] ) );
+ printf("pkd:%d:%u:", i, gcry_mpi_get_nbits( pk->pkey[i] ) );
mpi_print(stdout, pk->pkey[i], 1 );
putchar(':');
putchar('\n');
@@ -412,7 +412,7 @@ list_keyblock( KBNODE keyblock, int secret )
print_string( stdout, p, n, ':' );
else
print_utf8_string( stdout, p, n );
- m_free(p);
+ gcry_free(p);
}
if( opt.with_colons )
printf(":%02x:", sig->sig_class );
@@ -463,6 +463,6 @@ fingerprint( PKT_public_key *pk, PKT_secret_key *sk )
}
}
putchar('\n');
- m_free(array);
+ gcry_free(array);
}
diff --git a/g10/main.h b/g10/main.h
index 03cba92c5..9d632db6d 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -71,6 +71,7 @@ int pubkey_get_npkey( int algo );
int pubkey_get_nskey( int algo );
int pubkey_get_nsig( int algo );
int pubkey_get_nenc( int algo );
+unsigned int pubkey_nbits( int algo, MPI *pkey );
/*-- helptext.c --*/
diff --git a/g10/mainproc.c b/g10/mainproc.c
index af26118c7..6facd822b 100644
--- a/g10/mainproc.c
+++ b/g10/mainproc.c
@@ -28,7 +28,6 @@
#include <gcrypt.h>
#include "packet.h"
#include "iobuf.h"
-#include "memory.h"
#include "options.h"
#include "util.h"
#include "keydb.h"
@@ -90,7 +89,7 @@ release_list( CTX c )
release_kbnode( c->list );
while( c->failed_pkenc ) {
struct kidlist_item *tmp = c->failed_pkenc->next;
- m_free( c->failed_pkenc );
+ gcry_free( c->failed_pkenc );
c->failed_pkenc = tmp;
}
c->failed_pkenc = NULL;
@@ -225,10 +224,10 @@ proc_pubkey_enc( CTX c, PACKET *pkt )
|| is_RSA(enc->pubkey_algo) ) {
if ( !c->dek && ((!enc->keyid[0] && !enc->keyid[1])
|| !seckey_available( enc->keyid )) ) {
- c->dek = m_alloc_secure( sizeof *c->dek );
+ c->dek = gcry_xmalloc_secure( sizeof *c->dek );
if( (result = get_session_key( enc, c->dek )) ) {
/* error: delete the DEK */
- m_free(c->dek); c->dek = NULL;
+ gcry_free(c->dek); c->dek = NULL;
}
}
else
@@ -244,7 +243,7 @@ proc_pubkey_enc( CTX c, PACKET *pkt )
log_info( _("public key encrypted data: good DEK\n") );
}
else { /* store it for later display */
- struct kidlist_item *x = m_alloc( sizeof *x );
+ struct kidlist_item *x = gcry_xmalloc( sizeof *x );
x->kid[0] = enc->keyid[0];
x->kid[1] = enc->keyid[1];
x->pubkey_algo = enc->pubkey_algo;
@@ -265,7 +264,7 @@ static void
print_failed_pkenc( struct kidlist_item *list )
{
for( ; list; list = list->next ) {
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
const char *algstr = gcry_pk_algo_name( list->pubkey_algo );
pk->pubkey_algo = list->pubkey_algo;
@@ -278,7 +277,7 @@ print_failed_pkenc( struct kidlist_item *list )
fputs(" \"", log_stream() );
p = get_user_id( list->kid, &n );
print_string( log_stream(), p, n, '"' );
- m_free(p);
+ gcry_free(p);
fputs("\"\n", log_stream() );
}
else {
@@ -323,7 +322,7 @@ proc_encrypted( CTX c, PACKET *pkt )
result = G10ERR_NO_SECKEY;
if( !result )
result = decrypt_data( c, pkt->pkt.encrypted, c->dek );
- m_free(c->dek); c->dek = NULL;
+ gcry_free(c->dek); c->dek = NULL;
if( result == -1 )
;
else if( !result ) {
@@ -851,7 +850,7 @@ list_node( CTX c, KBNODE node )
else {
p = get_user_id( sig->keyid, &n );
print_string( stdout, p, n, opt.with_colons );
- m_free(p);
+ gcry_free(p);
}
if( opt.with_colons )
printf(":%02x:", sig->sig_class );
@@ -866,11 +865,11 @@ int
proc_packets( void *anchor, IOBUF a )
{
int rc;
- CTX c = m_alloc_clear( sizeof *c );
+ CTX c = gcry_xcalloc( 1, sizeof *c );
c->anchor = anchor;
rc = do_proc_packets( c, a );
- m_free( c );
+ gcry_free( c );
return rc;
}
@@ -878,7 +877,7 @@ int
proc_signature_packets( void *anchor, IOBUF a,
STRLIST signedfiles, const char *sigfilename )
{
- CTX c = m_alloc_clear( sizeof *c );
+ CTX c = gcry_xcalloc( 1, sizeof *c );
int rc;
c->anchor = anchor;
@@ -886,20 +885,20 @@ proc_signature_packets( void *anchor, IOBUF a,
c->signed_data = signedfiles;
c->sigfilename = sigfilename;
rc = do_proc_packets( c, a );
- m_free( c );
+ gcry_free( c );
return rc;
}
int
proc_encryption_packets( void *anchor, IOBUF a )
{
- CTX c = m_alloc_clear( sizeof *c );
+ CTX c = gcry_xcalloc( 1, sizeof *c );
int rc;
c->anchor = anchor;
c->encrypt_only = 1;
rc = do_proc_packets( c, a );
- m_free( c );
+ gcry_free( c );
return rc;
}
@@ -907,7 +906,7 @@ proc_encryption_packets( void *anchor, IOBUF a )
int
do_proc_packets( CTX c, IOBUF a )
{
- PACKET *pkt = m_alloc( sizeof *pkt );
+ PACKET *pkt = gcry_xmalloc( sizeof *pkt );
int rc=0;
int any_data=0;
int newpkt;
@@ -1000,7 +999,7 @@ do_proc_packets( CTX c, IOBUF a )
if( newpkt == -1 )
;
else if( newpkt ) {
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
}
else
@@ -1016,9 +1015,9 @@ do_proc_packets( CTX c, IOBUF a )
leave:
release_list( c );
- m_free(c->dek);
+ gcry_free(c->dek);
free_packet( pkt );
- m_free( pkt );
+ gcry_free( pkt );
free_md_filter_context( &c->mfx );
return rc;
}
@@ -1055,7 +1054,7 @@ check_sig_and_print( CTX c, KBNODE node )
us = get_long_user_id_string( sig->keyid );
write_status_text( rc? STATUS_BADSIG : STATUS_GOODSIG, us );
- m_free(us);
+ gcry_free(us);
/* fixme: list only user ids which are valid and add information
* about the trustworthiness of each user id, sort them.
@@ -1085,7 +1084,7 @@ check_sig_and_print( CTX c, KBNODE node )
if( !rc && is_status_enabled() ) {
/* print a status response with the fingerprint */
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
if( !get_pubkey( pk, sig->keyid ) ) {
byte array[MAX_FINGERPRINT_LEN], *p;
diff --git a/g10/mdfilter.c b/g10/mdfilter.c
index 54eadcf6c..abb55d8c1 100644
--- a/g10/mdfilter.c
+++ b/g10/mdfilter.c
@@ -27,7 +27,7 @@
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "filter.h"
diff --git a/g10/misc.c b/g10/misc.c
index a750cca75..1c311a6c0 100644
--- a/g10/misc.c
+++ b/g10/misc.c
@@ -35,7 +35,6 @@
#include <gcrypt.h>
#include "util.h"
#include "main.h"
-#include "memory.h"
#include "options.h"
#include "i18n.h"
@@ -156,7 +155,7 @@ mpi_read(IOBUF inp, unsigned int *ret_nread, int secure)
}
nread = 2;
nbytes = (nbits+7) / 8;
- buf = secure? m_alloc_secure( nbytes+2 ) : m_alloc( nbytes+2 );
+ buf = secure? gcry_xmalloc_secure( nbytes+2 ) : gcry_xmalloc( nbytes+2 );
p = buf;
p[0] = c1;
p[1] = c2;
@@ -169,7 +168,7 @@ mpi_read(IOBUF inp, unsigned int *ret_nread, int secure)
a = NULL;
leave:
- m_free(buf);
+ gcry_free(buf);
if( nread > *ret_nread )
log_bug("mpi larger than packet");
else
@@ -202,7 +201,7 @@ mpi_read_opaque(IOBUF inp, unsigned *ret_nread )
}
nread = 2;
nbytes = (nbits+7) / 8;
- buf = m_alloc( nbytes );
+ buf = gcry_xmalloc( nbytes );
p = buf;
for( i=0 ; i < nbytes; i++ ) {
p[i] = iobuf_get(inp) & 0xff;
@@ -213,7 +212,7 @@ mpi_read_opaque(IOBUF inp, unsigned *ret_nread )
buf = NULL;
leave:
- m_free(buf);
+ gcry_free(buf);
if( nread > *ret_nread )
log_bug("mpi larger than packet");
else
@@ -236,17 +235,13 @@ mpi_print( FILE *fp, MPI a, int mode )
}
else {
int rc;
- byte *buffer;
- size_t nbytes;
+ char *buffer;
- rc = gcry_mpi_print( GCRYMPI_FMT_HEX, NULL, &nbytes, a );
- assert( !rc );
- buffer = m_is_secure(a)? m_alloc_secure(nbytes) : m_alloc(nbytes);
- rc = gcry_mpi_print( GCRYMPI_FMT_HEX, buffer, &nbytes, a );
+ rc = gcry_mpi_aprint( GCRYMPI_FMT_HEX, (void **)&buffer, NULL, a );
assert( !rc );
fputs( buffer, fp );
n += strlen(buffer);
- m_free( buffer );
+ gcry_free( buffer );
}
return n;
}
@@ -286,11 +281,11 @@ checksum_mpi( MPI a )
* should use a stack based buffer and only allocate
* a larger one when the mpi_print return an error
*/
- buffer = m_is_secure(a)? m_alloc_secure(nbytes) : m_alloc(nbytes);
+ buffer = gcry_is_secure(a)? gcry_xmalloc_secure(nbytes) : gcry_xmalloc(nbytes);
rc = gcry_mpi_print( GCRYMPI_FMT_PGP, buffer, &nbytes, a );
assert( !rc );
csum = checksum( buffer, nbytes );
- m_free( buffer );
+ gcry_free( buffer );
return csum;
}
@@ -425,8 +420,42 @@ pubkey_get_nenc( int algo )
return n > 0? n : 0;
}
-int
-pubkey_nbits()
+unsigned int
+pubkey_nbits( int algo, MPI *key )
{
+ int nbits;
+ GCRY_SEXP sexp;
+
+
+ if( algo == GCRY_PK_DSA ) {
+ sexp = SEXP_CONS( SEXP_NEW( "public-key", 0 ),
+ gcry_sexp_vlist( SEXP_NEW( "dsa", 3 ),
+ gcry_sexp_new_name_mpi( "p", key[0] ),
+ gcry_sexp_new_name_mpi( "q", key[1] ),
+ gcry_sexp_new_name_mpi( "g", key[2] ),
+ gcry_sexp_new_name_mpi( "y", key[3] ),
+ NULL ));
+ }
+ else if( algo == GCRY_PK_ELG || algo == GCRY_PK_ELG_E ) {
+ sexp = SEXP_CONS( SEXP_NEW( "public-key", 0 ),
+ gcry_sexp_vlist( SEXP_NEW( "elg", 3 ),
+ gcry_sexp_new_name_mpi( "p", key[0] ),
+ gcry_sexp_new_name_mpi( "g", key[1] ),
+ gcry_sexp_new_name_mpi( "y", key[2] ),
+ NULL ));
+ }
+ else if( algo == GCRY_PK_RSA ) {
+ sexp = SEXP_CONS( SEXP_NEW( "public-key", 0 ),
+ gcry_sexp_vlist( SEXP_NEW( "rsa", 3 ),
+ gcry_sexp_new_name_mpi( "n", key[0] ),
+ gcry_sexp_new_name_mpi( "e", key[1] ),
+ NULL ));
+ }
+ else
+ return 0;
+
+ nbits = gcry_pk_get_nbits( sexp );
+ gcry_sexp_release( sexp );
+ return nbits;
}
diff --git a/g10/openfile.c b/g10/openfile.c
index 4f73334b8..60910031a 100644
--- a/g10/openfile.c
+++ b/g10/openfile.c
@@ -26,7 +26,7 @@
#include <errno.h>
#include <unistd.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "ttyio.h"
#include "options.h"
#include "main.h"
@@ -89,14 +89,14 @@ make_outfile_name( const char *iname )
size_t n;
if( (!iname || (*iname=='-' && !iname[1]) ))
- return m_strdup("-");
+ return gcry_xstrdup("-");
n = strlen(iname);
if( n > 4 && ( !CMP_FILENAME(iname+n-4,".gpg")
|| !CMP_FILENAME(iname+n-4,".pgp")
|| !CMP_FILENAME(iname+n-4,".sig")
|| !CMP_FILENAME(iname+n-4,".asc") ) ) {
- char *buf = m_strdup( iname );
+ char *buf = gcry_xstrdup( iname );
buf[n-4] = 0;
return buf;
}
@@ -127,19 +127,19 @@ ask_outfile_name( const char *name, size_t namelen )
n = strlen(s) + namelen + 10;
defname = name && namelen? make_printable_string( name, namelen, 0): NULL;
- prompt = m_alloc(n);
+ prompt = gcry_xmalloc(n);
if( defname )
sprintf(prompt, "%s [%s]: ", s, defname );
else
sprintf(prompt, "%s: ", s );
fname = cpr_get("openfile.askoutname", prompt );
cpr_kill_prompt();
- m_free(prompt);
+ gcry_free(prompt);
if( !*fname ) {
- m_free( fname ); fname = NULL;
+ gcry_free( fname ); fname = NULL;
fname = defname; defname = NULL;
}
- m_free(defname);
+ gcry_free(defname);
return fname;
}
@@ -187,7 +187,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
const char *newsfx = mode==1 ? ".asc" :
mode==2 ? ".sig" : ".gpg";
- buf = m_alloc(strlen(iname)+4+1);
+ buf = gcry_xmalloc(strlen(iname)+4+1);
strcpy(buf,iname);
dot = strchr(buf, '.' );
if( dot && dot > buf && dot[1] && strlen(dot) <= 4
@@ -199,7 +199,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
else
strcat( buf, newsfx );
#else
- buf = m_alloc(strlen(iname)+4+1);
+ buf = gcry_xmalloc(strlen(iname)+4+1);
strcpy(stpcpy(buf,iname), mode==1 ? ".asc" :
mode==2 ? ".sig" : ".gpg");
#endif
@@ -216,7 +216,7 @@ open_outfile( const char *iname, int mode, IOBUF *a )
}
else
rc = G10ERR_FILE_EXISTS;
- m_free(buf);
+ gcry_free(buf);
}
return rc;
}
@@ -238,12 +238,12 @@ open_sigfile( const char *iname )
if( len > 4 && ( !strcmp(iname + len - 4, ".sig")
|| !strcmp(iname + len - 4, ".asc")) ) {
char *buf;
- buf = m_strdup(iname);
+ buf = gcry_xstrdup(iname);
buf[len-4] = 0 ;
a = iobuf_open( buf );
if( opt.verbose )
log_info(_("assuming signed data in `%s'\n"), buf );
- m_free(buf);
+ gcry_free(buf);
}
}
return a;
@@ -265,12 +265,12 @@ copy_options_file( const char *destdir )
if( opt.dry_run )
return;
- fname = m_alloc( strlen(datadir) + strlen(destdir) + 15 );
+ fname = gcry_xmalloc( strlen(datadir) + strlen(destdir) + 15 );
strcpy(stpcpy(fname, datadir), "/options" SKELEXT );
src = fopen( fname, "r" );
if( !src ) {
log_error(_("%s: can't open: %s\n"), fname, strerror(errno) );
- m_free(fname);
+ gcry_free(fname);
return;
}
strcpy(stpcpy(fname, destdir), "/options" );
@@ -278,7 +278,7 @@ copy_options_file( const char *destdir )
if( !dst ) {
log_error(_("%s: can't create: %s\n"), fname, strerror(errno) );
fclose( src );
- m_free(fname);
+ gcry_free(fname);
return;
}
@@ -293,6 +293,6 @@ copy_options_file( const char *destdir )
fclose( dst );
fclose( src );
log_info(_("%s: new options file created\n"), fname );
- m_free(fname);
+ gcry_free(fname);
}
diff --git a/g10/options.h b/g10/options.h
index 937d452ed..abb0c7ad0 100644
--- a/g10/options.h
+++ b/g10/options.h
@@ -100,6 +100,7 @@ struct {
#define DBG_PACKET (opt.debug & DBG_PACKET_VALUE)
#define DBG_FILTER (opt.debug & DBG_FILTER_VALUE)
+#define DBG_MEMORY (opt.debug & DBG_MEMORY_VALUE)
#define DBG_CACHE (opt.debug & DBG_CACHE_VALUE)
#define DBG_TRUST (opt.debug & DBG_TRUST_VALUE)
#define DBG_CIPHER (opt.debug & DBG_CIPHER_VALUE)
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index e72e16d65..dffb874b0 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -28,7 +28,7 @@
#include "iobuf.h"
#include "util.h"
#include "dummy-cipher.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "filter.h"
#include "options.h"
#include "main.h"
@@ -391,12 +391,12 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos,
switch( pkttype ) {
case PKT_PUBLIC_KEY:
case PKT_PUBLIC_SUBKEY:
- pkt->pkt.public_key = m_alloc_clear(sizeof *pkt->pkt.public_key );
+ pkt->pkt.public_key = gcry_xcalloc( 1,sizeof *pkt->pkt.public_key );
rc = parse_key(inp, pkttype, pktlen, hdr, hdrlen, pkt );
break;
case PKT_SECRET_KEY:
case PKT_SECRET_SUBKEY:
- pkt->pkt.secret_key = m_alloc_clear(sizeof *pkt->pkt.secret_key );
+ pkt->pkt.secret_key = gcry_xcalloc( 1,sizeof *pkt->pkt.secret_key );
rc = parse_key(inp, pkttype, pktlen, hdr, hdrlen, pkt );
break;
case PKT_SYMKEY_ENC:
@@ -406,11 +406,11 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos,
rc = parse_pubkeyenc(inp, pkttype, pktlen, pkt );
break;
case PKT_SIGNATURE:
- pkt->pkt.signature = m_alloc_clear(sizeof *pkt->pkt.signature );
+ pkt->pkt.signature = gcry_xcalloc( 1,sizeof *pkt->pkt.signature );
rc = parse_signature(inp, pkttype, pktlen, pkt->pkt.signature );
break;
case PKT_ONEPASS_SIG:
- pkt->pkt.onepass_sig = m_alloc_clear(sizeof *pkt->pkt.onepass_sig );
+ pkt->pkt.onepass_sig = gcry_xcalloc( 1,sizeof *pkt->pkt.onepass_sig );
rc = parse_onepass_sig(inp, pkttype, pktlen, pkt->pkt.onepass_sig );
break;
case PKT_USER_ID:
@@ -547,7 +547,7 @@ read_rest( IOBUF inp, size_t pktlen )
p = NULL;
}
else {
- p = m_alloc( pktlen );
+ p = gcry_xmalloc( pktlen );
for(i=0; pktlen; pktlen--, i++ )
p[i] = iobuf_get(inp);
}
@@ -597,7 +597,7 @@ parse_symkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
goto leave;
}
seskeylen = pktlen - minlen;
- k = packet->pkt.symkey_enc = m_alloc_clear( sizeof *packet->pkt.symkey_enc
+ k = packet->pkt.symkey_enc = gcry_xcalloc( 1, sizeof *packet->pkt.symkey_enc
+ seskeylen - 1 );
k->version = version;
k->cipher_algo = cipher_algo;
@@ -640,7 +640,7 @@ parse_pubkeyenc( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
int i, ndata;
PKT_pubkey_enc *k;
- k = packet->pkt.pubkey_enc = m_alloc_clear(sizeof *packet->pkt.pubkey_enc);
+ k = packet->pkt.pubkey_enc = gcry_xcalloc( 1,sizeof *packet->pkt.pubkey_enc);
if( pktlen < 12 ) {
log_error("packet(%d) too short\n", pkttype);
goto leave;
@@ -1046,7 +1046,7 @@ parse_signature( IOBUF inp, int pkttype, unsigned long pktlen,
goto leave;
}
if( n ) {
- sig->hashed_data = m_alloc( n + 2 );
+ sig->hashed_data = gcry_xmalloc( n + 2 );
sig->hashed_data[0] = n >> 8;
sig->hashed_data[1] = n;
if( iobuf_read(inp, sig->hashed_data+2, n ) != n ) {
@@ -1063,7 +1063,7 @@ parse_signature( IOBUF inp, int pkttype, unsigned long pktlen,
goto leave;
}
if( n ) {
- sig->unhashed_data = m_alloc( n + 2 );
+ sig->unhashed_data = gcry_xmalloc( n + 2 );
sig->unhashed_data[0] = n >> 8;
sig->unhashed_data[1] = n;
if( iobuf_read(inp, sig->unhashed_data+2, n ) != n ) {
@@ -1473,7 +1473,7 @@ parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
{
byte *p;
- packet->pkt.user_id = m_alloc(sizeof *packet->pkt.user_id + pktlen);
+ packet->pkt.user_id = gcry_xmalloc(sizeof *packet->pkt.user_id + pktlen);
packet->pkt.user_id->len = pktlen;
p = packet->pkt.user_id->name;
for( ; pktlen; pktlen--, p++ )
@@ -1502,7 +1502,7 @@ parse_comment( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
{
byte *p;
- packet->pkt.comment = m_alloc(sizeof *packet->pkt.comment + pktlen - 1);
+ packet->pkt.comment = gcry_xmalloc(sizeof *packet->pkt.comment + pktlen - 1);
packet->pkt.comment->len = pktlen;
p = packet->pkt.comment->data;
for( ; pktlen; pktlen--, p++ )
@@ -1530,7 +1530,7 @@ parse_trust( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *pkt )
int c;
c = iobuf_get_noeof(inp);
- pkt->pkt.ring_trust = m_alloc( sizeof *pkt->pkt.ring_trust );
+ pkt->pkt.ring_trust = gcry_xmalloc( sizeof *pkt->pkt.ring_trust );
pkt->pkt.ring_trust->trustval = c;
if( list_mode )
printf(":trust packet: flag=%02x\n", c );
@@ -1552,7 +1552,7 @@ parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
}
mode = iobuf_get_noeof(inp); if( pktlen ) pktlen--;
namelen = iobuf_get_noeof(inp); if( pktlen ) pktlen--;
- pt = pkt->pkt.plaintext = m_alloc(sizeof *pkt->pkt.plaintext + namelen -1);
+ pt = pkt->pkt.plaintext = gcry_xmalloc(sizeof *pkt->pkt.plaintext + namelen -1);
pt->new_ctb = new_ctb;
pt->mode = mode;
pt->namelen = namelen;
@@ -1601,7 +1601,7 @@ parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen,
* (this should be the last object in a file or
* the compress algorithm should know the length)
*/
- zd = pkt->pkt.compressed = m_alloc(sizeof *pkt->pkt.compressed );
+ zd = pkt->pkt.compressed = gcry_xmalloc(sizeof *pkt->pkt.compressed );
zd->len = 0; /* not yet used */
zd->algorithm = iobuf_get_noeof(inp);
zd->new_ctb = new_ctb;
@@ -1618,7 +1618,7 @@ parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
{
PKT_encrypted *ed;
- ed = pkt->pkt.encrypted = m_alloc(sizeof *pkt->pkt.encrypted );
+ ed = pkt->pkt.encrypted = gcry_xmalloc(sizeof *pkt->pkt.encrypted );
ed->len = pktlen;
ed->buf = NULL;
ed->new_ctb = new_ctb;
diff --git a/g10/passphrase.c b/g10/passphrase.c
index ae937e26d..ef59db0d4 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include <assert.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "options.h"
#include "ttyio.h"
#include "dummy-cipher.h"
@@ -53,10 +53,10 @@ have_static_passphrase()
void
set_next_passphrase( const char *s )
{
- m_free(next_pw);
+ gcry_free(next_pw);
next_pw = NULL;
if( s ) {
- next_pw = m_alloc_secure( strlen(s)+1 );
+ next_pw = gcry_xmalloc_secure( strlen(s)+1 );
strcpy(next_pw, s );
}
}
@@ -87,7 +87,7 @@ read_passphrase_from_fd( int fd )
if( i >= len-1 ) {
char *pw2 = pw;
len += 100;
- pw = m_alloc_secure( len );
+ pw = gcry_xmalloc_secure( len );
if( pw2 )
memcpy(pw, pw2, i );
else
@@ -100,7 +100,7 @@ read_passphrase_from_fd( int fd )
if( !opt.batch )
tty_printf("\b\b\b \n" );
- m_free( fd_passwd );
+ gcry_free( fd_passwd );
fd_passwd = pw;
}
@@ -152,7 +152,7 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
}
if( keyid && !opt.batch && !next_pw ) {
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
size_t n;
char *p;
@@ -160,7 +160,7 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
"user: \"") );
p = get_user_id( keyid, &n );
tty_print_utf8_string( p, n );
- m_free(p);
+ gcry_free(p);
tty_printf("\"\n");
if( !get_pubkey( pk, keyid ) ) {
@@ -183,12 +183,12 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
next_pw = NULL;
}
else if( fd_passwd ) {
- pw = m_alloc_secure( strlen(fd_passwd)+1 );
+ pw = gcry_xmalloc_secure( strlen(fd_passwd)+1 );
strcpy( pw, fd_passwd );
}
else if( opt.batch ) {
log_error(_("can't query password in batchmode\n"));
- pw = m_strdup( "" ); /* return an empty passphrase */
+ pw = gcry_xstrdup( "" ); /* return an empty passphrase */
}
else {
pw = cpr_get_hidden("passphrase.enter", _("Enter passphrase: ") );
@@ -198,24 +198,24 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
_("Repeat passphrase: ") );
tty_kill_prompt();
if( strcmp(pw, pw2) ) {
- m_free(pw2);
- m_free(pw);
+ gcry_free(pw2);
+ gcry_free(pw);
return NULL;
}
- m_free(pw2);
+ gcry_free(pw2);
}
}
if( !pw || !*pw )
write_status( STATUS_MISSING_PASSPHRASE );
- dek = m_alloc_secure( sizeof *dek );
+ dek = gcry_xmalloc_secure( sizeof *dek );
dek->algo = cipher_algo;
if( !*pw && mode == 2 )
dek->keylen = 0;
else
hash_passphrase( dek, pw, s2k, mode==2 );
- m_free(last_pw);
+ gcry_free(last_pw);
last_pw = pw;
return dek;
}
diff --git a/g10/pkclist.c b/g10/pkclist.c
index 4f47e5563..18c1e9860 100644
--- a/g10/pkclist.c
+++ b/g10/pkclist.c
@@ -31,7 +31,6 @@
#include "main.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
#include "util.h"
#include "trustdb.h"
#include "ttyio.h"
@@ -124,7 +123,7 @@ show_paths( ulong lid, int only_first )
return;
}
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = get_pubkey( pk, keyid );
if( rc ) {
log_error("key %08lX: public key not found: %s\n",
@@ -152,7 +151,7 @@ show_paths( ulong lid, int only_first )
p = get_user_id( keyid, &n );
tty_print_utf8_string( p, n ),
- m_free(p);
+ gcry_free(p);
tty_printf("\"\n");
free_public_key( pk );
}
@@ -185,7 +184,7 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust, int defer_help )
return 0;
}
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = get_pubkey( pk, keyid );
if( rc ) {
log_error("key %08lX: public key not found: %s\n",
@@ -206,7 +205,7 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust, int defer_help )
(ulong)keyid[1], datestr_from_pk( pk ) );
p = get_user_id( keyid, &n );
tty_print_utf8_string( p, n ),
- m_free(p);
+ gcry_free(p);
tty_printf("\"\n");
print_fpr( pk );
tty_printf("\n");
@@ -262,10 +261,10 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust, int defer_help )
quit = 1;
break ; /* back to the menu */
}
- m_free(p); p = NULL;
+ gcry_free(p); p = NULL;
}
- m_free(p);
- m_free(pk);
+ gcry_free(p);
+ gcry_free(pk);
return show? -2: quit? -1 : changed;
}
@@ -463,7 +462,7 @@ do_we_trust_pre( PKT_public_key *pk, int trustlevel )
(ulong)keyid[1], datestr_from_pk( pk ) );
p = get_user_id( keyid, &n );
tty_print_utf8_string( p, n ),
- m_free(p);
+ gcry_free(p);
tty_printf("\"\n");
print_fpr( pk );
tty_printf("\n");
@@ -498,7 +497,7 @@ do_we_trust_pre( PKT_public_key *pk, int trustlevel )
int
check_signatures_trust( PKT_signature *sig )
{
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
int trustlevel;
int did_add = 0;
int rc=0;
@@ -622,7 +621,7 @@ release_pk_list( PK_LIST pk_list )
for( ; pk_list; pk_list = pk_rover ) {
pk_rover = pk_list->next;
free_public_key( pk_list->pk );
- m_free( pk_list );
+ gcry_free( pk_list );
}
}
@@ -651,10 +650,10 @@ default_recipient(void)
int i;
if( opt.def_recipient )
- return m_strdup( opt.def_recipient );
+ return gcry_xstrdup( opt.def_recipient );
if( !opt.def_recipient_self )
return NULL;
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
i = get_seckey_byname( sk, NULL, 0 );
if( i ) {
free_secret_key( sk );
@@ -663,7 +662,7 @@ default_recipient(void)
n = MAX_FINGERPRINT_LEN;
fingerprint_from_sk( sk, fpr, &n );
free_secret_key( sk );
- p = m_alloc( 2*n+3 );
+ p = gcry_xmalloc( 2*n+3 );
*p++ = '0';
*p++ = 'x';
for(i=0; i < n; i++ )
@@ -689,7 +688,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
if( !(rov->flags & 1) )
any_recipients = 1;
else if( (use & GCRY_PK_USAGE_ENCR) && !opt.no_encrypt_to ) {
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
pk->pubkey_usage = use;
if( (rc = get_pubkey_byname( NULL, pk, rov->d, NULL )) ) {
free_public_key( pk ); pk = NULL;
@@ -706,7 +705,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
}
else {
PK_LIST r;
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->pk = pk; pk = NULL;
r->next = pk_list;
r->mark = 0;
@@ -731,7 +730,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
"You did not specify a user ID. (you may use \"-r\")\n\n"));
for(;;) {
rc = 0;
- m_free(answer);
+ gcry_free(answer);
if( have_def_rec ) {
answer = def_rec;
def_rec = NULL;
@@ -746,7 +745,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
break;
if( pk )
free_public_key( pk );
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
pk->pubkey_usage = use;
rc = get_pubkey_byname( NULL, pk, answer, NULL );
if( rc )
@@ -759,7 +758,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
"already set as default recipient\n") );
}
else {
- PK_LIST r = m_alloc( sizeof *r );
+ PK_LIST r = gcry_xmalloc( sizeof *r );
r->pk = pk; pk = NULL;
r->next = pk_list;
r->mark = 0;
@@ -790,7 +789,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
else {
PK_LIST r;
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->pk = pk; pk = NULL;
r->next = pk_list;
r->mark = 0;
@@ -801,23 +800,23 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
}
}
}
- m_free(def_rec); def_rec = NULL;
+ gcry_free(def_rec); def_rec = NULL;
have_def_rec = 0;
}
- m_free(answer);
+ gcry_free(answer);
if( pk ) {
free_public_key( pk );
pk = NULL;
}
}
else if( !any_recipients && (def_rec = default_recipient()) ) {
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
pk->pubkey_usage = use;
rc = get_pubkey_byname( NULL, pk, def_rec, NULL );
if( rc )
log_error(_("unknown default recipient `%s'\n"), def_rec );
else if( !(rc=openpgp_pk_test_algo(pk->pubkey_algo, use)) ) {
- PK_LIST r = m_alloc( sizeof *r );
+ PK_LIST r = gcry_xmalloc( sizeof *r );
r->pk = pk; pk = NULL;
r->next = pk_list;
r->mark = 0;
@@ -828,7 +827,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
free_public_key( pk );
pk = NULL;
}
- m_free(def_rec); def_rec = NULL;
+ gcry_free(def_rec); def_rec = NULL;
}
else {
any_recipients = 0;
@@ -836,7 +835,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
if( (remusr->flags & 1) )
continue; /* encrypt-to keys are already handled */
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
pk->pubkey_usage = use;
if( (rc = get_pubkey_byname( NULL, pk, remusr->d, NULL )) ) {
free_public_key( pk ); pk = NULL;
@@ -872,7 +871,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
}
else {
PK_LIST r;
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->pk = pk; pk = NULL;
r->next = pk_list;
r->mark = 0;
@@ -953,7 +952,7 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype )
}
if( preftype == PREFTYPE_SYM )
mask[0] |= (1<<2); /* 3DES is implicitly there */
- m_free(pref);
+ gcry_free(pref);
pref = get_pref_data( pkr->pk->local_id, pkr->pk->namehash, &npref);
any = 0;
if( pref ) {
@@ -1026,7 +1025,7 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype )
i = 1; /* yep; we can use compression algo 1 */
}
- m_free(pref);
+ gcry_free(pref);
return i;
}
diff --git a/g10/plaintext.c b/g10/plaintext.c
index 592455f12..88b76bc70 100644
--- a/g10/plaintext.c
+++ b/g10/plaintext.c
@@ -25,7 +25,7 @@
#include <errno.h>
#include <assert.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "options.h"
#include "packet.h"
#include "ttyio.h"
@@ -56,7 +56,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
if( nooutput )
;
else if( opt.outfile ) {
- fname = m_alloc( strlen( opt.outfile ) + 1);
+ fname = gcry_xmalloc( strlen( opt.outfile ) + 1);
strcpy(fname, opt.outfile );
}
else if( pt->namelen == 8 && !memcmp( pt->name, "_CONSOLE", 8 ) ) {
@@ -120,7 +120,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
else { /* binary mode */
- byte *buffer = m_alloc( 32768 );
+ byte *buffer = gcry_xmalloc( 32768 );
while( pt->len ) {
int len = pt->len > 32768 ? 32768 : pt->len;
len = iobuf_read( pt->buf, buffer, len );
@@ -128,7 +128,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_error("Problem reading source (%u bytes remaining)\n",
(unsigned)pt->len);
rc = G10ERR_READ_FILE;
- m_free( buffer );
+ gcry_free( buffer );
goto leave;
}
if( mfx->md )
@@ -138,13 +138,13 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_error("Error writing to `%s': %s\n",
fname, strerror(errno) );
rc = G10ERR_WRITE_FILE;
- m_free( buffer );
+ gcry_free( buffer );
goto leave;
}
}
pt->len -= len;
}
- m_free( buffer );
+ gcry_free( buffer );
}
}
else if( !clearsig ) {
@@ -165,7 +165,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
}
}
else { /* binary mode */
- byte *buffer = m_alloc( 32768 );
+ byte *buffer = gcry_xmalloc( 32768 );
int eof;
for( eof=0; !eof; ) {
/* Why do we check for len < 32768:
@@ -186,12 +186,12 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
log_error("Error writing to `%s': %s\n",
fname, strerror(errno) );
rc = G10ERR_WRITE_FILE;
- m_free( buffer );
+ gcry_free( buffer );
goto leave;
}
}
}
- m_free( buffer );
+ gcry_free( buffer );
}
pt->buf = NULL;
}
@@ -248,7 +248,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
leave:
if( fp && fp != stdout )
fclose(fp);
- m_free(fname);
+ gcry_free(fname);
return rc;
}
@@ -310,7 +310,7 @@ ask_for_detached_datafile( GCRY_MD_HD md, GCRY_MD_HD md2,
int any=0;
tty_printf(_("Detached signature.\n"));
do {
- m_free(answer);
+ gcry_free(answer);
answer = cpr_get("detached_signature.filename",
_("Please enter name of data file: "));
cpr_kill_prompt();
@@ -342,7 +342,7 @@ ask_for_detached_datafile( GCRY_MD_HD md, GCRY_MD_HD md2,
leave:
- m_free(answer);
+ gcry_free(answer);
return rc;
}
diff --git a/g10/pubkey-enc.c b/g10/pubkey-enc.c
index 94fe2777b..925b5a4d0 100644
--- a/g10/pubkey-enc.c
+++ b/g10/pubkey-enc.c
@@ -24,7 +24,7 @@
#include <string.h>
#include <assert.h>
#include "util.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "packet.h"
#include "main.h"
#include "keydb.h"
@@ -55,7 +55,7 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek )
goto leave;
if( k->keyid[0] || k->keyid[1] ) {
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
sk->pubkey_algo = k->pubkey_algo; /* we want a pubkey with this algo*/
if( !(rc = get_seckey( sk, k->keyid )) )
rc = get_it( k, dek, sk, k->keyid );
@@ -67,7 +67,7 @@ get_session_key( PKT_pubkey_enc *k, DEK *dek )
for(;;) {
if( sk )
free_secret_key( sk );
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
rc=enum_secret_keys( &enum_context, sk, 1);
if( rc ) {
rc = G10ERR_NO_SECKEY;
@@ -102,13 +102,16 @@ get_it( PKT_pubkey_enc *k, DEK *dek, PKT_secret_key *sk, u32 *keyid )
int rc;
MPI plain_dek = NULL;
byte *frame = NULL;
- unsigned n, nframe;
+ unsigned n;
+ size_t nframe;
u16 csum, csum2;
rc = pubkey_decrypt(sk->pubkey_algo, &plain_dek, k->data, sk->skey );
if( rc )
goto leave;
- frame = mpi_get_buffer( plain_dek, &nframe, NULL );
+ if( gcry_mpi_aprint( GCRYMPI_FMT_USG, &frame, &nframe, plain_dek ) )
+ BUG();
+
mpi_release( plain_dek ); plain_dek = NULL;
/* Now get the DEK (data encryption key) from the frame
@@ -121,7 +124,8 @@ get_it( PKT_pubkey_enc *k, DEK *dek, PKT_secret_key *sk, u32 *keyid )
*
* 0 2 RND(n bytes) 0 A DEK(k bytes) CSUM(2 bytes)
*
- * (mpi_get_buffer already removed the leading zero).
+ * (mpi_get_buffer already removed the leading zero - still true
+ * for gcry_mpi_aprint(0 which is used now?)
*
* RND are non-zero randow bytes.
* A is the cipher algorithm
@@ -174,7 +178,7 @@ get_it( PKT_pubkey_enc *k, DEK *dek, PKT_secret_key *sk, u32 *keyid )
log_hexdump("DEK is:", dek->key, dek->keylen );
/* check that the algo is in the preferences */
{
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
if( (rc = get_pubkey( pk, keyid )) )
log_error("public key problem: %s\n", g10_errstr(rc) );
else if( !pk->local_id && query_trust_record(pk) )
@@ -197,7 +201,7 @@ get_it( PKT_pubkey_enc *k, DEK *dek, PKT_secret_key *sk, u32 *keyid )
leave:
mpi_release(plain_dek);
- m_free(frame);
+ gcry_free(frame);
return rc;
}
diff --git a/g10/revoke.c b/g10/revoke.c
index 64c9c764c..e71124515 100644
--- a/g10/revoke.c
+++ b/g10/revoke.c
@@ -29,7 +29,7 @@
#include "packet.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "ttyio.h"
@@ -114,10 +114,10 @@ gen_revoke( const char *uname )
size_t n;
char *p = get_user_id( sk_keyid, &n );
tty_print_utf8_string( p, n );
- m_free(p);
+ gcry_free(p);
tty_printf("\n");
}
- pk = m_alloc_clear( sizeof *pk );
+ pk = gcry_xcalloc( 1, sizeof *pk );
rc = get_pubkey( pk, sk_keyid );
if( rc ) {
log_error(_("no corresponding public key: %s\n"), g10_errstr(rc) );
diff --git a/g10/ringedit.c b/g10/ringedit.c
index b5eedd6ef..b4091f41c 100644
--- a/g10/ringedit.c
+++ b/g10/ringedit.c
@@ -53,7 +53,7 @@
#endif
#include "util.h"
#include "packet.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "iobuf.h"
#include "keydb.h"
#include "host2net.h"
@@ -234,7 +234,7 @@ add_keyblock_resource( const char *url, int force, int secret )
filename = make_filename(opt.homedir, resname, NULL);
}
else
- filename = m_strdup( resname );
+ filename = gcry_xstrdup( resname );
if( !force )
force = secret? !any_secret : !any_public;
@@ -373,7 +373,7 @@ add_keyblock_resource( const char *url, int force, int secret )
/* fixme: avoid duplicate resources */
resource_table[i].used = 1;
resource_table[i].secret = !!secret;
- resource_table[i].fname = m_strdup(filename);
+ resource_table[i].fname = gcry_xstrdup(filename);
resource_table[i].iobuf = iobuf;
resource_table[i].rt = rt;
if( secret )
@@ -388,7 +388,7 @@ add_keyblock_resource( const char *url, int force, int secret )
any_secret = 1;
else
any_public = 1;
- m_free( filename );
+ gcry_free( filename );
return rc;
}
@@ -498,7 +498,7 @@ int
find_keyblock_byname( KBPOS *kbpos, const char *username )
{
PACKET pkt;
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
int rc;
rc = get_pubkey_byname( NULL, pk, username, NULL );
@@ -559,7 +559,7 @@ int
find_secret_keyblock_byname( KBPOS *kbpos, const char *username )
{
PACKET pkt;
- PKT_secret_key *sk = m_alloc_clear( sizeof *sk );
+ PKT_secret_key *sk = gcry_xcalloc( 1, sizeof *sk );
int rc;
rc = get_seckey_byname( sk, username, 0 );
@@ -828,7 +828,7 @@ enum_keyblocks( int mode, KBPOS *kbpos, KBNODE *ret_root )
}
/* release pending packet */
free_packet( kbpos->pkt );
- m_free( kbpos->pkt );
+ gcry_free( kbpos->pkt );
}
return rc;
}
@@ -954,7 +954,7 @@ compile_bm_table( const byte *pattern, size_t len )
ushort *dist;
int i;
- dist = m_alloc_clear( 256 * sizeof *dist );
+ dist = gcry_xcalloc( 1, 256 * sizeof *dist );
for(i=0; i < 256; i++ )
dist[i] = len;
for(i=0; i < len-1; i++ )
@@ -1012,7 +1012,7 @@ scan_user_file_open( const byte *name )
size_t *dist;
int i;
- hd = m_alloc_clear( sizeof *hd );
+ hd = gcry_xcalloc( 1, sizeof *hd );
dist = hd->dist;
/* compile the distance table */
for(i=0; i < 256; i++ )
@@ -1027,7 +1027,7 @@ scan_user_file_open( const byte *name )
static int
scan_user_file_close( SCAN_USER_HANDLE hd )
{
- m_free( hd );
+ gcry_free( hd );
}
static int
@@ -1175,7 +1175,7 @@ keyring_read( KBPOS *kbpos, KBNODE *ret_root )
return G10ERR_KEYRING_OPEN;
}
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
kbpos->count=0;
while( (rc=parse_packet(a, pkt)) != -1 ) {
@@ -1209,7 +1209,7 @@ keyring_read( KBPOS *kbpos, KBNODE *ret_root )
root = new_kbnode( pkt );
else
add_kbnode( root, new_kbnode( pkt ) );
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
break;
}
@@ -1224,7 +1224,7 @@ keyring_read( KBPOS *kbpos, KBNODE *ret_root )
else
*ret_root = root;
free_packet( pkt );
- m_free( pkt );
+ gcry_free( pkt );
iobuf_close(a);
return rc;
}
@@ -1246,7 +1246,7 @@ keyring_enum( KBPOS *kbpos, KBNODE *ret_root, int skipsigs )
kbpos->pkt = NULL;
}
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
while( (rc=parse_packet(kbpos->fp, pkt)) != -1 ) {
if( rc ) { /* ignore errors */
@@ -1275,7 +1275,7 @@ keyring_enum( KBPOS *kbpos, KBNODE *ret_root, int skipsigs )
goto ready;
}
root = new_kbnode( pkt );
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
break;
@@ -1293,7 +1293,7 @@ keyring_enum( KBPOS *kbpos, KBNODE *ret_root, int skipsigs )
break;
}
add_kbnode( root, new_kbnode( pkt ) );
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
break;
}
@@ -1307,7 +1307,7 @@ keyring_enum( KBPOS *kbpos, KBNODE *ret_root, int skipsigs )
else
*ret_root = root;
free_packet( pkt );
- m_free( pkt );
+ gcry_free( pkt );
return rc;
}
@@ -1391,23 +1391,23 @@ keyring_copy( KBPOS *kbpos, int mode, KBNODE root )
*/
if( strlen(rentry->fname) > 4
&& !strcmp(rentry->fname+strlen(rentry->fname)-4, ".gpg") ) {
- bakfname = m_alloc( strlen( rentry->fname ) + 1 );
+ bakfname = gcry_xmalloc( strlen( rentry->fname ) + 1 );
strcpy(bakfname,rentry->fname);
strcpy(bakfname+strlen(rentry->fname)-4, ".bak");
- tmpfname = m_alloc( strlen( rentry->fname ) + 1 );
+ tmpfname = gcry_xmalloc( strlen( rentry->fname ) + 1 );
strcpy(tmpfname,rentry->fname);
strcpy(tmpfname+strlen(rentry->fname)-4, ".tmp");
}
else { /* file does not end with gpg; hmmm */
- bakfname = m_alloc( strlen( rentry->fname ) + 5 );
+ bakfname = gcry_xmalloc( strlen( rentry->fname ) + 5 );
strcpy(stpcpy(bakfname,rentry->fname),".bak");
- tmpfname = m_alloc( strlen( rentry->fname ) + 5 );
+ tmpfname = gcry_xmalloc( strlen( rentry->fname ) + 5 );
strcpy(stpcpy(tmpfname,rentry->fname),".tmp");
}
#else
- bakfname = m_alloc( strlen( rentry->fname ) + 2 );
+ bakfname = gcry_xmalloc( strlen( rentry->fname ) + 2 );
strcpy(stpcpy(bakfname,rentry->fname),"~");
- tmpfname = m_alloc( strlen( rentry->fname ) + 5 );
+ tmpfname = gcry_xmalloc( strlen( rentry->fname ) + 5 );
strcpy(stpcpy(tmpfname,rentry->fname),".tmp");
#endif
newfp = iobuf_create( tmpfname );
@@ -1538,8 +1538,8 @@ keyring_copy( KBPOS *kbpos, int mode, KBNODE root )
leave:
unlock_rentry( rentry );
- m_free(bakfname);
- m_free(tmpfname);
+ gcry_free(bakfname);
+ gcry_free(tmpfname);
return rc;
}
@@ -1704,25 +1704,25 @@ do_gdbm_locate_by_keyid( GDBM_FILE dbf, KBPOS *kbpos, u32 *keyid )
if( content.dsize < 2 ) {
log_error("gdbm_fetch did not return enough data\n" );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return G10ERR_INV_KEYRING;
}
if( *content.dptr != 2 ) {
log_error("gdbm_fetch returned unexpected type %d\n",
*(byte*)content.dptr );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return G10ERR_INV_KEYRING;
}
if( content.dsize < 21 ) {
log_error("gdbm_fetch did not return a complete fingerprint\n" );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return G10ERR_INV_KEYRING;
}
if( content.dsize > 21 )
log_info("gdbm_fetch: WARNING: more than one fingerprint\n" );
rc = do_gdbm_locate( dbf, kbpos, content.dptr+1, 20 );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return rc;
}
@@ -1750,20 +1750,20 @@ do_gdbm_read( KBPOS *kbpos, KBNODE *ret_root )
}
if( content.dsize < 2 ) {
log_error("gdbm_fetch did not return enough data\n" );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return G10ERR_INV_KEYRING;
}
if( *content.dptr != 1 ) {
log_error("gdbm_fetch returned unexpected type %d\n",
*(byte*)content.dptr );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
return G10ERR_INV_KEYRING;
}
a = iobuf_temp_with_content( content.dptr+1, content.dsize-1 );
- free( content.dptr ); /* can't use m_free() here */
+ free( content.dptr ); /* can't use gcry_free() here */
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
kbpos->count=0;
while( (rc=parse_packet(a, pkt)) != -1 ) {
@@ -1784,7 +1784,7 @@ do_gdbm_read( KBPOS *kbpos, KBNODE *ret_root )
root = new_kbnode( pkt );
else
add_kbnode( root, new_kbnode( pkt ) );
- pkt = m_alloc( sizeof *pkt );
+ pkt = gcry_xmalloc( sizeof *pkt );
init_packet(pkt);
}
if( rc == -1 && root )
@@ -1794,7 +1794,7 @@ do_gdbm_read( KBPOS *kbpos, KBNODE *ret_root )
else
*ret_root = root;
free_packet( pkt );
- m_free( pkt );
+ gcry_free( pkt );
iobuf_close(a);
return rc;
}
@@ -1824,18 +1824,18 @@ do_gdbm_enum( KBPOS *kbpos, KBNODE *ret_root )
while( key.dptr && (!key.dsize || *key.dptr != 1) ) {
helpkey = key;
key = gdbm_nextkey( rentry->dbf, helpkey );
- free( helpkey.dptr ); /* free and not m_free() ! */
+ free( helpkey.dptr ); /* free and not gcry_free() ! */
}
if( !key.dptr )
return -1; /* eof */
if( key.dsize < 21 ) {
- free( key.dptr ); /* free and not m_free() ! */
+ free( key.dptr ); /* free and not gcry_free() ! */
log_error("do_gdm_enum: key is too short\n" );
return G10ERR_INV_KEYRING;
}
memcpy( kbpos->keybuf, key.dptr, 21 );
- free( key.dptr ); /* free and not m_free() ! */
+ free( key.dptr ); /* free and not gcry_free() ! */
return do_gdbm_read( kbpos, ret_root );
}
diff --git a/g10/seckey-cert.c b/g10/seckey-cert.c
index af4110590..10f7092d2 100644
--- a/g10/seckey-cert.c
+++ b/g10/seckey-cert.c
@@ -26,7 +26,6 @@
#include <gcrypt.h>
#include "util.h"
-#include "memory.h"
#include "packet.h"
#include "keydb.h"
#include "main.h"
@@ -59,7 +58,7 @@ do_check( PKT_secret_key *sk )
keyid_from_sk( sk, keyid );
keyid[2] = keyid[3] = 0;
if( !sk->is_primary ) {
- PKT_secret_key *sk2 = m_alloc_clear( sizeof *sk2 );
+ PKT_secret_key *sk2 = gcry_xcalloc( 1, sizeof *sk2 );
if( !get_primary_seckey( sk2, keyid ) )
keyid_from_sk( sk2, keyid+2 );
free_secret_key( sk2 );
@@ -77,7 +76,7 @@ do_check( PKT_secret_key *sk )
if( gcry_cipher_setkey( cipher_hd, dek->key, dek->keylen ) )
log_fatal("set key failed: %s\n", gcry_strerror(-1) );
- m_free(dek);
+ gcry_free(dek);
save_sk = copy_secret_key( NULL, sk );
if( gcry_cipher_setiv( cipher_hd, sk->protect.iv, sk->protect.ivlen ))
log_fatal("set IV failed: %s\n", gcry_strerror(-1) );
@@ -91,7 +90,7 @@ do_check( PKT_secret_key *sk )
assert( gcry_mpi_get_flag( sk->skey[i], GCRYMPI_FLAG_OPAQUE ) );
p = gcry_mpi_get_opaque( sk->skey[i], &ndatabits );
ndata = (ndatabits+7)/8;
- data = m_alloc_secure( ndata );
+ data = gcry_xmalloc_secure( ndata );
gcry_cipher_decrypt( cipher_hd, data, ndata, p, ndata );
mpi_release( sk->skey[i] ); sk->skey[i] = NULL ;
p = data;
@@ -109,7 +108,7 @@ do_check( PKT_secret_key *sk )
if( sk->csum == csum ) {
for( ; i < pubkey_get_nskey(sk->pubkey_algo); i++ ) {
nbytes = ndata;
- assert( m_is_secure( p ) );
+ assert( gcry_is_secure( p ) );
res = gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_PGP,
p, &nbytes);
if( res )
@@ -119,7 +118,7 @@ do_check( PKT_secret_key *sk )
p += nbytes;
}
}
- m_free(data);
+ gcry_free(data);
}
else {
for(i=pubkey_get_npkey(sk->pubkey_algo);
@@ -131,7 +130,7 @@ do_check( PKT_secret_key *sk )
assert( gcry_mpi_get_flag( sk->skey[i], GCRYMPI_FLAG_OPAQUE ) );
p = gcry_mpi_get_opaque( sk->skey[i], &ndatabits );
ndata = (ndatabits+7)/8;
- data = m_alloc_secure( ndata );
+ data = gcry_xmalloc_secure( ndata );
gcry_cipher_sync( cipher_hd );
gcry_cipher_decrypt( cipher_hd, data, ndata, p, ndata );
mpi_release( sk->skey[i] ); sk->skey[i] = NULL ;
@@ -142,7 +141,7 @@ do_check( PKT_secret_key *sk )
log_bug("gcry_mpi_scan failed in do_check: rc=%d\n", res);
csum += checksum_mpi( sk->skey[i] );
- m_free( buffer );
+ gcry_free( buffer );
}
}
gcry_cipher_close( cipher_hd );
@@ -287,15 +286,19 @@ protect_secret_key( PKT_secret_key *sk, DEK *dek )
for(j=0, i = pubkey_get_npkey(sk->pubkey_algo);
i < pubkey_get_nskey(sk->pubkey_algo); i++, j++ ) {
assert( !gcry_mpi_get_flag( sk->skey[i], GCRYMPI_FLAG_OPAQUE ) );
- bufarr[j] = mpi_get_buffer( sk->skey[i], &narr[j], NULL );
- nbits[j] = mpi_get_nbits( sk->skey[i] );
+
+ if( gcry_mpi_aprint( GCRYMPI_FMT_USG, (char*)bufarr+j,
+ narr+j, sk->skey[i]))
+ BUG();
+
+ nbits[j] = gcry_mpi_get_nbits( sk->skey[i] );
ndata += narr[j] + 2;
}
for( ; j < NMPIS; j++ )
bufarr[j] = NULL;
ndata += 2; /* for checksum */
- data = m_alloc_secure( ndata );
+ data = gcry_xmalloc_secure( ndata );
p = data;
for(j=0; j < NMPIS && bufarr[j]; j++ ) {
p[0] = nbits[j] >> 8 ;
@@ -303,7 +306,7 @@ protect_secret_key( PKT_secret_key *sk, DEK *dek )
p += 2;
memcpy(p, bufarr[j], narr[j] );
p += narr[j];
- m_free(bufarr[j]);
+ gcry_free(bufarr[j]);
}
#undef NMPIS
csum = checksum( data, ndata-2);
@@ -328,12 +331,20 @@ protect_secret_key( PKT_secret_key *sk, DEK *dek )
for(i=pubkey_get_npkey(sk->pubkey_algo);
i < pubkey_get_nskey(sk->pubkey_algo); i++ ) {
csum += checksum_mpi( sk->skey[i] );
- buffer = mpi_get_buffer( sk->skey[i], &nbytes, NULL );
+
+ if( gcry_mpi_aprint( GCRYMPI_FMT_USG,
+ &buffer, &nbytes, sk->skey[i] ) )
+ BUG();
+
gcry_cipher_sync( cipher_hd );
assert( !gcry_mpi_get_flag( sk->skey[i], GCRYMPI_FLAG_OPAQUE ) );
gcry_cipher_encrypt( cipher_hd, buffer, nbytes, NULL, 0 );
- mpi_set_buffer( sk->skey[i], buffer, nbytes, 0 );
- m_free( buffer );
+ gcry_mpi_release( sk->skey[i] );
+ if( gcry_mpi_scan( &sk->skey[i], GCRYMPI_FMT_USG,
+ buffer,&nbytes ) )
+ BUG();
+
+ gcry_free( buffer );
}
sk->csum = csum;
}
diff --git a/g10/seskey.c b/g10/seskey.c
index eac15c41f..261e904b7 100644
--- a/g10/seskey.c
+++ b/g10/seskey.c
@@ -29,7 +29,6 @@
#include "dummy-cipher.h"
#include "main.h"
#include "i18n.h"
-#include "memory.h"
/****************
@@ -110,7 +109,7 @@ encode_session_key( DEK *dek, unsigned nbits )
for( p = dek->key, i=0; i < dek->keylen; i++ )
csum += *p++;
- frame = m_alloc_secure( nframe );
+ frame = gcry_xmalloc_secure( nframe );
n = 0;
frame[n++] = 0;
frame[n++] = 2;
@@ -133,10 +132,10 @@ encode_session_key( DEK *dek, unsigned nbits )
for(j=0; j < i && k ; j++ )
if( !p[j] )
p[j] = pp[--k];
- m_free(pp);
+ gcry_free(pp);
}
memcpy( frame+n, p, i );
- m_free(p);
+ gcry_free(p);
n += i;
frame[n++] = 0;
frame[n++] = dek->algo;
@@ -144,9 +143,10 @@ encode_session_key( DEK *dek, unsigned nbits )
frame[n++] = csum >>8;
frame[n++] = csum;
assert( n == nframe );
- a = mpi_secure_new( nframe );
- mpi_set_buffer( a, frame, nframe, 0 );
- m_free(frame);
+ if( gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, &nframe ) )
+ BUG();
+ gcry_free(frame);
+
return a;
}
@@ -170,8 +170,8 @@ do_encode_md( GCRY_MD_HD md, int algo, size_t len, unsigned nbits,
*
* PAD consists of FF bytes.
*/
- frame = gcry_md_is_secure(md)? m_alloc_secure( nframe )
- : m_alloc( nframe );
+ frame = gcry_md_is_secure(md)? gcry_xmalloc_secure( nframe )
+ : gcry_xmalloc( nframe );
n = 0;
frame[n++] = 0;
frame[n++] = algo;
@@ -182,9 +182,9 @@ do_encode_md( GCRY_MD_HD md, int algo, size_t len, unsigned nbits,
memcpy( frame+n, asn, asnlen ); n += asnlen;
memcpy( frame+n, gcry_md_read(md, algo), len ); n += len;
assert( n == nframe );
- a = gcry_md_is_secure(md)? mpi_secure_new( nframe ) : mpi_new( nframe );
- mpi_set_buffer( a, frame, nframe, 0 );
- m_free(frame);
+ if( gcry_mpi_scan( &a, GCRYMPI_FMT_USG, frame, &nframe ) )
+ BUG();
+ gcry_free(frame);
return a;
}
@@ -196,11 +196,10 @@ encode_md_value( int pubkey_algo, GCRY_MD_HD md, int hash_algo, unsigned nbits )
MPI frame;
if( pubkey_algo == GCRY_PK_DSA ) {
- frame = gcry_md_is_secure(md)?
- mpi_secure_new( gcry_md_get_algo_dlen(hash_algo) )
- : mpi_new( gcry_md_get_algo_dlen(hash_algo) );
- mpi_set_buffer( frame, gcry_md_read(md, hash_algo),
- gcry_md_get_algo_dlen(hash_algo), 0 );
+ size_t n = gcry_md_get_algo_dlen(hash_algo);
+ if( gcry_mpi_scan( &frame, GCRYMPI_FMT_USG,
+ gcry_md_read(md, hash_algo), &n ) )
+ BUG();
}
else {
byte *asn;
@@ -209,12 +208,12 @@ encode_md_value( int pubkey_algo, GCRY_MD_HD md, int hash_algo, unsigned nbits )
if( gcry_md_algo_info( algo, GCRYCTL_GET_ASNOID, NULL, &asnlen ) )
log_fatal("can't get OID of algo %d: %s\n",
algo, gcry_strerror(-1));
- asn = m_alloc( asnlen );
+ asn = gcry_xmalloc( asnlen );
if( gcry_md_algo_info( algo, GCRYCTL_GET_ASNOID, asn, &asnlen ) )
BUG();
frame = do_encode_md( md, algo, gcry_md_get_algo_dlen( algo ),
nbits, asn, asnlen );
- m_free( asn );
+ gcry_free( asn );
}
return frame;
}
diff --git a/g10/sig-check.c b/g10/sig-check.c
index 842055d17..aec50ab38 100644
--- a/g10/sig-check.c
+++ b/g10/sig-check.c
@@ -27,7 +27,6 @@
#include <gcrypt.h>
#include "util.h"
#include "packet.h"
-#include "memory.h"
#include "keydb.h"
#include "main.h"
#include "status.h"
@@ -138,7 +137,7 @@ signature_check( PKT_signature *sig, GCRY_MD_HD digest )
static int
do_signature_check( PKT_signature *sig, GCRY_MD_HD digest, u32 *r_expire )
{
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
int rc=0;
if( is_RSA(sig->pubkey_algo) )
@@ -176,22 +175,23 @@ do_signature_check( PKT_signature *sig, GCRY_MD_HD digest, u32 *r_expire )
gcry_md_putc( digest, (a >> 8) & 0xff );
gcry_md_putc( digest, a & 0xff );
for(i=0; i < nsig; i++ ) {
- unsigned n = mpi_get_nbits( sig->data[i]);
+ size_t n = gcry_mpi_get_nbits( sig->data[i]);
gcry_md_putc( md, n>>8);
gcry_md_putc( md, n );
- p = mpi_get_buffer( sig->data[i], &n, NULL );
+ if( gcry_mpi_aprint( GCRYMPI_FMT_USG, &p, &n, sig->data[i] ) )
+ BUG();
gcry_md_write( md, p, n );
- m_free(p);
+ gcry_free(p);
}
gcry_md_final( md );
p = make_radix64_string( gcry_md_read( md, 0 ), 20 );
- buffer = m_alloc( strlen(p) + 60 );
+ buffer = gcry_xmalloc( strlen(p) + 60 );
sprintf( buffer, "%s %s %lu",
p, strtimestamp( sig->timestamp ), (ulong)sig->timestamp );
write_status_text( STATUS_SIG_ID, buffer );
- m_free(buffer);
- m_free(p);
+ gcry_free(buffer);
+ gcry_free(p);
gcry_md_close(md);
}
@@ -260,8 +260,11 @@ mdc_kludge_check( PKT_signature *sig, GCRY_MD_HD digest )
log_debug("sig_data[0] is NULL\n");
else {
unsigned s2len;
- byte *s2;
- s2 = mpi_get_buffer( sig->data[0], &s2len, NULL );
+ char *s2;
+
+ if( gcry_mpi_print( GCRYMPI_FMT_USG, &s2, &s2len, sig->data[0] ))
+ BUG();
+
log_hexdump( "MDC stored ", s2, s2len );
if( s2len != s1len )
@@ -270,7 +273,7 @@ mdc_kludge_check( PKT_signature *sig, GCRY_MD_HD digest )
log_debug("MDC check: hashs differ\n");
else
rc = 0;
- m_free(s2);
+ gcry_free(s2);
}
}
@@ -445,7 +448,7 @@ do_check( PKT_public_key *pk, PKT_signature *sig, GCRY_MD_HD digest )
gcry_md_final( digest );
result = encode_md_value( pk->pubkey_algo, digest, sig->digest_algo,
- mpi_get_nbits(pk->pkey[0]));
+ gcry_mpi_get_nbits(pk->pkey[0]));
ctx.sig = sig;
ctx.md = digest;
diff --git a/g10/sign.c b/g10/sign.c
index d65e0e2d1..a227a0c25 100644
--- a/g10/sign.c
+++ b/g10/sign.c
@@ -31,7 +31,6 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
#include "util.h"
#include "main.h"
#include "filter.h"
@@ -124,7 +123,7 @@ mk_notation_and_policy( PKT_signature *sig )
n1 = s - string;
s++;
n2 = strlen(s);
- buf = m_alloc( 8 + n1 + n2 );
+ buf = gcry_xmalloc( 8 + n1 + n2 );
buf[0] = 0x80; /* human readable */
buf[1] = buf[2] = buf[3] = 0;
buf[4] = n1 >> 8;
@@ -179,7 +178,7 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig,
sig->digest_start[0] = dp[0];
sig->digest_start[1] = dp[1];
frame = encode_md_value( sk->pubkey_algo, md,
- digest_algo, mpi_get_nbits(sk->skey[0]));
+ digest_algo, gcry_mpi_get_nbits(sk->skey[0]));
rc = pk_sign( sk->pubkey_algo, sig->data, frame, sk->skey );
mpi_release(frame);
if( rc )
@@ -189,7 +188,7 @@ do_sign( PKT_secret_key *sk, PKT_signature *sig,
char *ustr = get_user_id_string( sig->keyid );
log_info(_("%s signature from: %s\n"),
gcry_pk_algo_name(sk->pubkey_algo), ustr );
- m_free(ustr);
+ gcry_free(ustr);
}
}
return rc;
@@ -391,7 +390,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
break;
sk = sk_rover->sk;
- ops = m_alloc_clear( sizeof *ops );
+ ops = gcry_xcalloc( 1, sizeof *ops );
ops->sig_class = opt.textmode && !outfile ? 0x01 : 0x00;
ops->digest_algo = hash_for(sk->pubkey_algo);
ops->pubkey_algo = sk->pubkey_algo;
@@ -447,13 +446,13 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
if (!opt.no_literal) {
if( fname || opt.set_filename ) {
char *s = make_basename( opt.set_filename ? opt.set_filename : fname );
- pt = m_alloc( sizeof *pt + strlen(s) - 1 );
+ pt = gcry_xmalloc( sizeof *pt + strlen(s) - 1 );
pt->namelen = strlen(s);
memcpy(pt->name, s, pt->namelen );
- m_free(s);
+ gcry_free(s);
}
else { /* no filename */
- pt = m_alloc( sizeof *pt - 1 );
+ pt = gcry_xmalloc( sizeof *pt - 1 );
pt->namelen = 0;
}
}
@@ -513,7 +512,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
/* build the signature packet */
/* fixme: this code is partly duplicated in make_keysig_packet */
- sig = m_alloc_clear( sizeof *sig );
+ sig = gcry_xcalloc( 1, sizeof *sig );
sig->version = old_style || opt.force_v3_sigs ? 3 : sk->version;
keyid_from_sk( sk, sig->keyid );
sig->digest_algo = hash_for(sk->pubkey_algo);
@@ -709,7 +708,7 @@ clearsign_file( const char *fname, STRLIST locusr, const char *outfile )
/* build the signature packet */
/* fixme: this code is duplicated above */
- sig = m_alloc_clear( sizeof *sig );
+ sig = gcry_xcalloc( 1, sizeof *sig );
sig->version = old_style || opt.force_v3_sigs ? 3 : sk->version;
keyid_from_sk( sk, sig->keyid );
sig->digest_algo = hash_for(sk->pubkey_algo);
@@ -840,7 +839,7 @@ make_keysig_packet( PKT_signature **ret_sig, PKT_public_key *pk,
gcry_md_write( md, uid->name, uid->len );
}
/* and make the signature packet */
- sig = m_alloc_clear( sizeof *sig );
+ sig = gcry_xcalloc( 1, sizeof *sig );
sig->version = sk->version;
keyid_from_sk( sk, sig->keyid );
sig->pubkey_algo = sk->pubkey_algo;
diff --git a/g10/signal.c b/g10/signal.c
index 6ed23e5a0..fcb012e02 100644
--- a/g10/signal.c
+++ b/g10/signal.c
@@ -29,7 +29,7 @@
#include "options.h"
#include "errors.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "ttyio.h"
@@ -58,7 +58,7 @@ got_fatal_signal( int sig )
raise( sig );
caught_fatal_sig = 1;
- secmem_term();
+ gcry_control( GCRYCTL_TERM_SECMEM );
#ifdef IS_DEVELOPMENT_VERSION
write(2, "\n", 1 );
s = log_get_name(); if( s ) write(2, s, strlen(s) );
diff --git a/g10/skclist.c b/g10/skclist.c
index be9769185..8d06364d8 100644
--- a/g10/skclist.c
+++ b/g10/skclist.c
@@ -30,7 +30,6 @@
#include "packet.h"
#include "errors.h"
#include "keydb.h"
-#include "memory.h"
#include "util.h"
#include "i18n.h"
#include "dummy-cipher.h"
@@ -45,7 +44,7 @@ release_sk_list( SK_LIST sk_list )
for( ; sk_list; sk_list = sk_rover ) {
sk_rover = sk_list->next;
free_secret_key( sk_list->sk );
- m_free( sk_list );
+ gcry_free( sk_list );
}
}
@@ -60,7 +59,7 @@ build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list, int unlock,
if( !locusr ) { /* use the default one */
PKT_secret_key *sk;
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
sk->pubkey_usage = use;
if( (rc = get_seckey_byname( sk, NULL, unlock )) ) {
free_secret_key( sk ); sk = NULL;
@@ -75,7 +74,7 @@ build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list, int unlock,
free_secret_key( sk ); sk = NULL;
}
else {
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->sk = sk; sk = NULL;
r->next = sk_list;
r->mark = 0;
@@ -91,7 +90,7 @@ build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list, int unlock,
for(; locusr; locusr = locusr->next ) {
PKT_secret_key *sk;
- sk = m_alloc_clear( sizeof *sk );
+ sk = gcry_xcalloc( 1, sizeof *sk );
sk->pubkey_usage = use;
if( (rc = get_seckey_byname( sk, locusr->d, unlock )) ) {
free_secret_key( sk ); sk = NULL;
@@ -107,7 +106,7 @@ build_sk_list( STRLIST locusr, SK_LIST *ret_sk_list, int unlock,
free_secret_key( sk ); sk = NULL;
}
else {
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->sk = sk; sk = NULL;
r->next = sk_list;
r->mark = 0;
diff --git a/g10/status.c b/g10/status.c
index 079c0dbd9..3eeec4648 100644
--- a/g10/status.c
+++ b/g10/status.c
@@ -43,7 +43,7 @@
#include "ttyio.h"
#include "options.h"
#include "main.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "i18n.h"
static int fd = -1;
@@ -257,7 +257,7 @@ do_shm_get( const char *keyword, int hidden, int bool )
if( bool )
return p[0]? "" : NULL;
- string = hidden? m_alloc_secure( n+1 ) : m_alloc( n+1 );
+ string = hidden? gcry_xmalloc_secure( n+1 ) : gcry_xmalloc( n+1 );
memcpy(string, p, n );
string[n] = 0; /* make sure it is a string */
if( hidden ) /* invalidate the memory */
@@ -292,7 +292,7 @@ cpr_get( const char *keyword, const char *prompt )
for(;;) {
p = tty_get( prompt );
if( *p=='?' && !p[1] && !(keyword && !*keyword)) {
- m_free(p);
+ gcry_free(p);
display_online_help( keyword );
}
else
@@ -307,7 +307,7 @@ cpr_get_utf8( const char *keyword, const char *prompt )
p = cpr_get( keyword, prompt );
if( p ) {
char *utf8 = native_to_utf8( p );
- m_free( p );
+ gcry_free( p );
p = utf8;
}
return p;
@@ -325,7 +325,7 @@ cpr_get_hidden( const char *keyword, const char *prompt )
for(;;) {
p = tty_get_hidden( prompt );
if( *p == '?' && !p[1] ) {
- m_free(p);
+ gcry_free(p);
display_online_help( keyword );
}
else
@@ -358,13 +358,13 @@ cpr_get_answer_is_yes( const char *keyword, const char *prompt )
p = tty_get( prompt );
trim_spaces(p); /* it is okay to do this here */
if( *p == '?' && !p[1] ) {
- m_free(p);
+ gcry_free(p);
display_online_help( keyword );
}
else {
tty_kill_prompt();
yes = answer_is_yes(p);
- m_free(p);
+ gcry_free(p);
return yes;
}
}
@@ -384,13 +384,13 @@ cpr_get_answer_yes_no_quit( const char *keyword, const char *prompt )
p = tty_get( prompt );
trim_spaces(p); /* it is okay to do this here */
if( *p == '?' && !p[1] ) {
- m_free(p);
+ gcry_free(p);
display_online_help( keyword );
}
else {
tty_kill_prompt();
yes = answer_is_yes_no_quit(p);
- m_free(p);
+ gcry_free(p);
return yes;
}
}
diff --git a/g10/tdbdump.c b/g10/tdbdump.c
index 1d608bd19..6ffa0465c 100644
--- a/g10/tdbdump.c
+++ b/g10/tdbdump.c
@@ -33,7 +33,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "trustdb.h"
#include "options.h"
@@ -349,7 +349,7 @@ list_trustdb( const char *username )
username, g10_errstr(rc));
}
else if( username ) {
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
int rc;
if( (rc = get_pubkey_byname( NULL, pk, username, NULL )) )
@@ -492,7 +492,7 @@ import_ownertrust( const char *fname )
write_record( &rec );
}
else if( rc == -1 ) { /* not found; get the key from the ring */
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
log_info_f(fname, _("key not in trustdb, searching ring.\n"));
rc = get_pubkey_byfprint( pk, line, fprlen );
diff --git a/g10/tdbio.c b/g10/tdbio.c
index b840d723a..3118d71ac 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -31,7 +31,7 @@
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "options.h"
#include "main.h"
@@ -180,7 +180,7 @@ put_record_into_cache( ulong recno, const char *data )
}
/* see whether we reached the limit */
if( cache_entries < MAX_CACHE_ENTRIES_SOFT ) { /* no */
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->flags.used = 1;
r->recno = recno;
memcpy( r->data, data, TRUST_RECORD_LEN );
@@ -223,7 +223,7 @@ put_record_into_cache( ulong recno, const char *data )
if( cache_entries < MAX_CACHE_ENTRIES_HARD ) { /* no */
if( opt.debug && !(cache_entries % 100) )
log_debug("increasing tdbio cache size\n");
- r = m_alloc( sizeof *r );
+ r = gcry_xmalloc( sizeof *r );
r->flags.used = 1;
r->recno = recno;
memcpy( r->data, data, TRUST_RECORD_LEN );
@@ -421,13 +421,13 @@ tdbio_set_dbname( const char *new_dbname, int create )
atexit( cleanup );
initialized = 1;
}
- fname = new_dbname? m_strdup( new_dbname )
+ fname = new_dbname? gcry_xstrdup( new_dbname )
: make_filename(opt.homedir, "trustdb.gpg", NULL );
if( access( fname, R_OK ) ) {
if( errno != ENOENT ) {
log_error( _("%s: can't access: %s\n"), fname, strerror(errno) );
- m_free(fname);
+ gcry_free(fname);
return G10ERR_TRUSTDB;
}
if( create ) {
@@ -457,7 +457,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
if( !fp )
log_fatal( _("%s: can't create: %s\n"), fname, strerror(errno) );
fclose(fp);
- m_free(db_name);
+ gcry_free(db_name);
db_name = fname;
#ifdef HAVE_DOSISH_SYSTEM
db_fd = open( db_name, O_RDWR | O_BINARY );
@@ -496,7 +496,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
return 0;
}
}
- m_free(db_name);
+ gcry_free(db_name);
db_name = fname;
return 0;
}
diff --git a/g10/textfilter.c b/g10/textfilter.c
index 3588156ad..06f85dc64 100644
--- a/g10/textfilter.c
+++ b/g10/textfilter.c
@@ -28,7 +28,6 @@
#include <gcrypt.h>
#include "errors.h"
#include "iobuf.h"
-#include "memory.h"
#include "util.h"
#include "filter.h"
#include "i18n.h"
@@ -128,7 +127,7 @@ text_filter( void *opaque, int control,
if( tfx->truncated )
log_error(_("can't handle text lines longer than %d characters\n"),
MAX_LINELEN );
- m_free( tfx->buffer );
+ gcry_free( tfx->buffer );
tfx->buffer = NULL;
}
else if( control == IOBUFCTRL_DESC )
diff --git a/g10/trustdb.c b/g10/trustdb.c
index 263bac261..6f0ed59a7 100644
--- a/g10/trustdb.c
+++ b/g10/trustdb.c
@@ -33,7 +33,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "trustdb.h"
#include "options.h"
@@ -222,7 +222,7 @@ new_lid_table(void)
memset( a, 0, sizeof *a );
}
else
- a = m_alloc_clear( sizeof *a );
+ a = gcry_xcalloc( 1, sizeof *a );
return a;
}
@@ -260,7 +260,7 @@ ins_lid_table_item( LOCAL_ID_TABLE tbl, ulong lid, unsigned flag )
if( a )
unused_lid_items = a->next;
else
- a = m_alloc( sizeof *a );
+ a = gcry_xmalloc( sizeof *a );
a->lid = lid;
a->flag = flag;
a->next = tbl->items[lid & 0x0f];
@@ -294,7 +294,7 @@ new_tn(void)
memset( t, 0, sizeof *t );
}
else
- t = m_alloc_clear( sizeof *t );
+ t = gcry_xcalloc( 1, sizeof *t );
if( ++alloced_tns > max_alloced_tns )
max_alloced_tns = alloced_tns;
return t;
@@ -409,7 +409,7 @@ get_dir_record( PKT_public_key *pk, TRUSTREC *rec )
static ulong
lid_from_keyid_no_sdir( u32 *keyid )
{
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
TRUSTREC rec;
ulong lid = 0;
int rc;
@@ -442,8 +442,8 @@ verify_own_keys(void)
{
int rc;
void *enum_context = NULL;
- PKT_secret_key *sk = m_alloc_clear( sizeof *sk );
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_secret_key *sk = gcry_xcalloc( 1, sizeof *sk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
u32 keyid[2];
while( !(rc=enum_secret_keys( &enum_context, sk, 0 ) ) ) {
@@ -531,7 +531,7 @@ setup_trustdb( int level, const char *dbname )
if( trustdb_args.init )
return 0;
trustdb_args.level = level;
- trustdb_args.dbname = dbname? m_strdup(dbname): NULL;
+ trustdb_args.dbname = dbname? gcry_xstrdup(dbname): NULL;
return 0;
}
@@ -595,7 +595,7 @@ print_user_id( FILE *fp, const char *text, u32 *keyid )
tty_print_utf8_string( p, n );
tty_printf( "\"\n" );
}
- m_free(p);
+ gcry_free(p);
}
@@ -654,7 +654,7 @@ print_path( int pathlen, TN ME .........., FILE *fp, ulong highlight )
putc('\"', fp);
print_utf8_string( fp, p, n > 40? 40:n, 0 );
putc('\"', fp);
- m_free(p);
+ gcry_free(p);
putc('\n', fp );
}
}
@@ -948,7 +948,7 @@ make_key_records( KBNODE keyblock, ulong lid, u32 *keyid, int *mainrev )
fingerprint_from_pk( pk, fpr, &fprlen );
/* create the key record */
- k = m_alloc_clear( sizeof *k );
+ k = gcry_xcalloc( 1, sizeof *k );
k->rectype = RECTYPE_KEY;
k->r.key.lid = lid;
k->r.key.pubkey_algo = pk->pubkey_algo;
@@ -971,7 +971,7 @@ make_key_records( KBNODE keyblock, ulong lid, u32 *keyid, int *mainrev )
k->r.key.next = k->next->recnum;
write_record( k );
k2 = k->next;
- m_free( k );
+ gcry_free( k );
}
return keyrecno;
}
@@ -1212,7 +1212,7 @@ make_sig_records( KBNODE keyblock, KBNODE uidnode,
/* create the sig record */
if( !sigidx ) {
- s = m_alloc_clear( sizeof *s );
+ s = gcry_xcalloc( 1, sizeof *s );
s->rectype = RECTYPE_SIG;
s->r.sig.lid = lid;
}
@@ -1245,7 +1245,7 @@ make_sig_records( KBNODE keyblock, KBNODE uidnode,
s->r.sig.next = s->next->recnum;
write_record( s );
s2 = s->next;
- m_free( s );
+ gcry_free( s );
}
return sigrecno;
}
@@ -1286,7 +1286,7 @@ make_pref_record( PKT_signature *sig, ulong lid )
continue;
for( ; n; n--, s++ ) {
if( !idx ) {
- p = m_alloc_clear( sizeof *p );
+ p = gcry_xcalloc( 1, sizeof *p );
p->rectype = RECTYPE_PREF;
p->r.pref.lid = lid;
}
@@ -1313,7 +1313,7 @@ make_pref_record( PKT_signature *sig, ulong lid )
p->r.pref.next = p->next->recnum;
write_record( p );
p2 = p->next;
- m_free( p );
+ gcry_free( p );
}
return precno;
}
@@ -1338,7 +1338,7 @@ make_uid_records( KBNODE keyblock, ulong lid, u32 *keyid, u32 *min_expire )
gcry_md_hash_buffer( GCRY_MD_RMD160, uidhash, uid->name, uid->len );
/* create the uid record */
- u = m_alloc_clear( sizeof *u );
+ u = gcry_xcalloc( 1, sizeof *u );
u->rectype = RECTYPE_UID;
u->r.uid.lid = lid;
memcpy(u->r.uid.namehash, uidhash, 20 );
@@ -1364,7 +1364,7 @@ make_uid_records( KBNODE keyblock, ulong lid, u32 *keyid, u32 *min_expire )
u->r.uid.next = u->next->recnum;
write_record( u );
u2 = u->next;
- m_free( u );
+ gcry_free( u );
}
return uidrecno;
}
@@ -1768,7 +1768,7 @@ build_cert_tree( ulong lid, int depth, int max_depth, TN helproot )
if( dirrec.rectype != RECTYPE_SDIR )
log_debug("lid %lu, has rectype %d"
" - skipped\n", lid, dirrec.rectype );
- m_free(keynode);
+ gcry_free(keynode);
return NULL;
}
@@ -2356,7 +2356,7 @@ list_trust_path( const char *username )
ulong lid;
TRUSTREC rec;
TN tree;
- PKT_public_key *pk = m_alloc_clear( sizeof *pk );
+ PKT_public_key *pk = gcry_xcalloc( 1, sizeof *pk );
init_trustdb();
if( (rc = get_pubkey_byname(NULL, pk, username, NULL )) )
@@ -2430,7 +2430,7 @@ enum_cert_paths( void **context, ulong *lid,
ctx = *context;
for(tsl = ctx->tsl_head; tsl; tsl = tsl2 ) {
tsl2 = tsl->next;
- m_free( tsl );
+ gcry_free( tsl );
}
*context = NULL;
}
@@ -2444,15 +2444,15 @@ enum_cert_paths( void **context, ulong *lid,
if( !*lid )
return -1;
- ctx = m_alloc_clear( sizeof *ctx );
+ ctx = gcry_xcalloc( 1, sizeof *ctx );
*context = ctx;
/* collect the paths */
#if 0
read_record( *lid, &rec, RECTYPE_DIR );
- tmppath = m_alloc_clear( (opt.max_cert_depth+1)* sizeof *tmppath );
+ tmppath = gcry_xcalloc( 1, (opt.max_cert_depth+1)* sizeof *tmppath );
tsl = NULL;
collect_paths( 0, opt.max_cert_depth, 1, &rec, tmppath, &tsl );
- m_free( tmppath );
+ gcry_free( tmppath );
sort_tsl_list( &tsl );
#endif
/* setup the context */
@@ -2555,7 +2555,7 @@ get_pref_data( ulong lid, const byte *namehash, size_t *ret_n )
read_record( rec.r.uid.prefrec, &rec, RECTYPE_PREF );
if( rec.r.pref.next )
log_info(_("WARNING: can't yet handle long pref records\n"));
- buf = m_alloc( ITEMS_PER_PREF_RECORD );
+ buf = gcry_xmalloc( ITEMS_PER_PREF_RECORD );
memcpy( buf, rec.r.pref.data, ITEMS_PER_PREF_RECORD );
*ret_n = ITEMS_PER_PREF_RECORD;
return buf;
diff --git a/g10/verify.c b/g10/verify.c
index 589b1b7bb..bdb6f178f 100644
--- a/g10/verify.c
+++ b/g10/verify.c
@@ -30,7 +30,7 @@
#include "errors.h"
#include "iobuf.h"
#include "keydb.h"
-#include "memory.h"
+#include <gcrypt.h>
#include "util.h"
#include "main.h"
#include "filter.h"