summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog147
-rw-r--r--src/Makefile.am10
-rw-r--r--src/ath.c14
-rw-r--r--src/ath.h4
-rw-r--r--src/benchmark.c63
-rw-r--r--src/cipher.h30
-rw-r--r--src/g10lib.h60
-rw-r--r--src/gcrypt.h1014
-rw-r--r--src/global.c279
-rw-r--r--src/missing-string.c2
-rw-r--r--src/module.c7
-rw-r--r--src/mpi.h26
-rw-r--r--src/secmem.c29
-rw-r--r--src/secmem.h4
-rw-r--r--src/sexp.c851
-rw-r--r--src/stdmem.c4
-rw-r--r--src/testapi.c8
-rw-r--r--src/types.h81
18 files changed, 1699 insertions, 934 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 83f4b2a0..aead129f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,150 @@
+2003-06-09 Moritz Schulte <moritz@g10code.com>
+
+ * Makefile.am: Support for libgpg-error.
+
+2003-06-08 Moritz Schulte <moritz@g10code.com>
+
+ * sexp.c (gcry_sexp_create): Expect sane error values from
+ gcry_sexp_canon_len instead of the `historical' values.
+
+2003-06-07 Moritz Schulte <moritz@g10code.com>
+
+ * ath.c, ath.c, ath-pth.c, ath-pthread.c, benchmark.c, cipher.h,
+ g10lib.h, gcrypt.h, global.c, misc.c, missing-string.c, module.c,
+ mpi.h, secmem.c, secmem.h, sexp.c, stdmem.c, stdmem.h, testapi.c,
+ types.h: Edited all preprocessor instructions to remove whitespace
+ before the '#'. This is not required by C89, but there are some
+ compilers out there that don't like it. Replaced any occurence of
+ the now deprecated type names with the new ones.
+
+ * gcrypt.h: Re-organized checking for gcc features; New macro:
+ _GCRY_GCC_ATTR_DEPRECATED.
+ Include copy of libgpg-error's gpg-error.h in order to make it
+ easy to build libgcrypt without needing libgpg-error.h.
+
+ (GCRY_MPI, GcryMPI, GCRY_SEXP, GcrySexp, GCRY_CIPHER_HD,
+ GcryCipherHd, GCRY_MD_HD, GcryMDHd): Declared deprecated.
+ (gcry_mpi_t, gcry_sexp_t, gcry_cipher_hd_t, gcry_md_hd_t): New
+ types.
+
+2003-06-04 Moritz Schulte <moritz@g10code.com>
+
+ * sexp.c (sexp_sscan): New argument: arg_list, adjusted all
+ callers.
+ (ARG_NEXT): New macro.
+ (sexp_sscan): Use ARG_NEXT for receiving format string arguments.
+ (gcry_sexp_build_array): New function.
+
+2003-06-02 Moritz Schulte <moritz@g10code.com>
+
+ * gcrypt.h: Added some comments describing the gcry_sexp_*
+ functions.
+ Include <gpg-error.h> instead of <gpg/error.h>.
+
+2003-06-01 Moritz Schulte <moritz@g10code.com>
+
+ * sexp.c (OLDPARSECODE): Removed macro...
+ (gcry_sexp_canon_len): ... and do not use it.
+
+ * gcrypt.h (gcry_errno): Removed declaration.
+
+ * g10lib.h (string_to_pubkey_algo, pubkey_algo_to_string,
+ pubkey_nbits): Removed declarations for non-existing functions.
+
+2003-05-31 Moritz Schulte <moritz@g10code.com>
+
+ * cipher.h (is_RSA, is_ELGAMAL): Removed macros.
+
+ * g10lib.h (set_lasterr): Removed macro.
+ (_gcry_set_lasterr): Removed declaration.
+
+ * gcrypt.h: Changed declarations for: gcry_pk_algo_info,
+ gcry_md_open, gcry_md_copy, gcry_md_algo_info, gcry_md_info,
+ gcry_md_get_algo, gcry_random_add_bytes.
+
+ (gcry_md_is_secure): Adjust macro for new API.
+
+2003-05-29 Moritz Schulte <moritz@g10code.com>
+
+ * gcrypt.h: Changed declarations for: gcry_cipher_open,
+ gcry_cipher_info, gcry_cipher_algo_info.
+ (gcry_cipher_get_algo_keylen): Adjuster for new
+ gcry_cipher_algo_info interface.
+ (gcry_cipher_get_algo_blklen): Likewise.
+
+ * global.c (gcry_errno): Removed function.
+ (gcry_strerror): Do not use gcry_errno.
+ (_gcry_set_lasterr): Removed function.
+ (last_ec): Removed variable.
+
+2003-05-27 Moritz Schulte <moritz@g10code.com>
+
+ * gcrypt.h (enum gcry_cipher_algos): Make Serpent IDs do not
+ conflict with OpenPGP. Reported by Timo Schulz.
+
+ * global.c (gcry_control): Fixed name of enum list.
+
+2003-05-25 Moritz Schulte <moritz@g10code.com>
+
+ * cipher.h (gcry_cipher_spec): Adjust return type of `setkey' for
+ libgpg-error.
+ (gcry_pubkey_spec): Adjust return type of `generate',
+ `check_secret_key', `encrypt', `decrypt', `sign' and `verify' for
+ libgpg-error.
+
+ * sexp.c (gcry_sexp_canon_len): Adjusted for libgpg-error.
+ (gcry_sexp_create): Likewise.
+ (gcry_sexp_new): Likewise.
+ (sexp_sscan): Likewise.
+ (gcry_sexp_build): Likewise.
+ (gcry_sexp_sscan): Likewise.
+
+ * module.c (_gcry_module_add): Likewise.
+
+ * global.c (last_ec): Change type to gpg_error_t.
+ (gcry_control): Adjust for libgpg-error.
+ (gcry_errno): Likewise.
+ (gcry_strerror): Likewise.
+ (_gcry_set_lasterr): Likewise.
+ (gcry_xmalloc): Likewise.
+ (gcry_xrealloc): Likewise.
+
+2003-05-22 Moritz Schulte <moritz@g10code.com>
+
+ * types.h: Merged code from GnuPG regarding U64_C.
+
+ * missing-string.c (strsep): Removed function.
+
+ * g10lib.h: Removed declarations: strsep, strlwr.
+
+ * secmem.c (secmem_lock): New variable.
+ (SECMEM_LOCK, SECMEM_UNLOCK): New macros.
+ (_gcry_secmem_set_flags): Use SECMEM_LOCK and SECMEM_UNLOCK.
+ (_gcry_secmem_get_flags): Likewise.
+ (_gcry_secmem_init): Likewie.
+ (_gcry_secmem_malloc): Likewise.
+ (_gcry_secmem_free): Likewise.
+ (_gcry_secmem_malloc): Renamed to ...
+ (_gcry_secmem_malloc_internal): ... this.
+ (_gcry_secmem_malloc): New function, use SECMEM_LOCK,
+ SECMEM_UNLOCK, call _gcry_secmem_malloc_internal.
+ (_gcry_secmem_free): Renamed to ...
+ (_gcry_secmem_free_internal): ... this.
+ (_gcry_secmem_free): New function, use SECMEM_LOCK, SECMEM_UNLOCK,
+ call _gcry_secmem_free_internal.
+ (_gcry_secmem_realloc): Use SECMEM_LOCK, SECMEM_UNLOCK, call
+ _gcry_secmem_malloc_internal and _gcry_secmem_free_internal.
+ (_gcry_private_is_secure): Use SECMEM_LOCK, SECMEM_UNLOCK.
+ (_gcry_secmem_dump_stats): Likewise.
+ (_gcry_secmem_malloc_internal): Removed unused variable:
+ compressed.
+ Include "ath.h".
+
+2003-05-21 Moritz Schulte <moritz@g10code.com>
+
+ * gcrypt.h (GCRY_CIPHER_SERPENT128, GCRY_CIPHER_SERPENT192,
+ GCRY_CIPHER_SERPENT256): New symbols.
+
2003-05-19 Moritz Schulte <moritz@g10code.com>
* gcrypt.h: Reversed changes from 2003-03-03 since they would have
diff --git a/src/Makefile.am b/src/Makefile.am
index 27654f96..6f7bade3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,6 +42,13 @@ benchmark_LDADD = libgcrypt.la
include_HEADERS = gcrypt.h
+if USE_LIBGPG_ERROR
+ libgpg_error_link = -lgpg-error
+ libgpg_error_compile = -DUSE_LIBGPG_ERROR
+else
+ libgpg_error_link =
+ libgpg_error_compile =
+endif
if HAVE_PTHREAD
ath_components_pthread = ath-pthread.c
@@ -83,5 +90,4 @@ libgcrypt_la_SOURCES = g10lib.h \
libgcrypt_la_DEPENDENCIES = ../cipher/libcipher.la ../mpi/libmpi.la \
$(srcdir)/libgcrypt.vers
-libgcrypt_la_LIBADD = ../cipher/libcipher.la ../mpi/libmpi.la
-
+libgcrypt_la_LIBADD = ../cipher/libcipher.la ../mpi/libmpi.la $(libgpg_error_link)
diff --git a/src/ath.c b/src/ath.c
index d08d2003..33f82d20 100644
--- a/src/ath.c
+++ b/src/ath.c
@@ -25,13 +25,13 @@
#include <unistd.h>
#ifndef HAVE_DOSISH_SYSTEM
-# ifdef HAVE_SYS_SELECT_H
-# include <sys/select.h>
-# else
-# include <sys/time.h>
-# endif
-# include <sys/types.h>
-# include <sys/wait.h>
+#ifdef HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#else
+#include <sys/time.h>
+#endif
+#include <sys/types.h>
+#include <sys/wait.h>
#endif /*HAVE_DOSISH_SYSTEM*/
#include "ath.h"
diff --git a/src/ath.h b/src/ath.h
index 8e3e246c..37d8c247 100644
--- a/src/ath.h
+++ b/src/ath.h
@@ -25,8 +25,8 @@
#include <sys/types.h>
#ifdef HAVE_DOSISH_SYSTEM
-# include <windows.h> /* for fd_set */
-# include <process.h> /* for pid_t */
+#include <windows.h> /* for fd_set */
+#include <process.h> /* for pid_t */
typedef unsigned int ssize_t;
#endif
diff --git a/src/benchmark.c b/src/benchmark.c
index 61de3077..3b01bf46 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -94,18 +94,19 @@ static void
md_bench ( const char *algoname )
{
int algo = gcry_md_map_name (algoname);
- GcryMDHd hd;
+ gcry_md_hd_t hd;
int i;
char buf[1000];
+ gpg_error_t err = GPG_ERR_NO_ERROR;
if (!algo)
{
fprintf (stderr, PGM ": invalid hash algorithm `%s'\n", algoname);
exit (1);
}
-
- hd = gcry_md_open (algo, 0);
- if (!hd)
+
+ err = gcry_md_open (&hd, algo, 0);
+ if (err)
{
fprintf (stderr, PGM ": error opeing hash algorithm `%s'/n", algoname);
exit (1);
@@ -148,8 +149,8 @@ cipher_bench ( const char *algoname )
{
static int header_printed;
int algo = gcry_cipher_map_name (algoname);
- GcryCipherHd hd;
- int err, i;
+ gcry_cipher_hd_t hd;
+ int i;
int keylen, blklen;
char key[128];
char outbuf[1000], buf[1000];
@@ -163,6 +164,7 @@ cipher_bench ( const char *algoname )
{0}
};
int modeidx;
+ gpg_error_t err = GPG_ERR_NO_ERROR;
if (!header_printed)
{
@@ -183,7 +185,13 @@ cipher_bench ( const char *algoname )
exit (1);
}
- keylen = gcry_cipher_get_algo_keylen (algo);
+ err = gcry_cipher_get_algo_keylen (algo, &keylen);
+ if (err)
+ {
+ fprintf (stderr, PGM ": failed to get key length for algorithm `%s': %s\n",
+ algoname, gpg_strerror (err));
+ exit (1);
+ }
if ( keylen > sizeof key )
{
fprintf (stderr, PGM ": algo %d, keylength problem (%d)\n",
@@ -193,7 +201,13 @@ cipher_bench ( const char *algoname )
for (i=0; i < keylen; i++)
key[i] = i + (clock () & 0xff);
- blklen = gcry_cipher_get_algo_blklen (algo);
+ err = gcry_cipher_get_algo_blklen (algo, &blklen);
+ if (err)
+ {
+ fprintf (stderr, PGM ": failed to get block length for algorithm `%s': %s\n",
+ algoname, gpg_strerror (err));
+ exit (1);
+ }
printf ("%-10s", gcry_cipher_algo_name (algo));
fflush (stdout);
@@ -210,17 +224,18 @@ cipher_bench ( const char *algoname )
for (i=0; i < sizeof buf; i++)
buf[i] = i;
- hd = gcry_cipher_open (algo, modes[modeidx].mode, 0);
- if (!hd)
+ err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
+ if (err)
{
fprintf (stderr, PGM ": error opening cipher `%s'\n", algoname);
exit (1);
}
- if (gcry_cipher_setkey (hd, key, keylen))
- {
+ err = gcry_cipher_setkey (hd, key, keylen);
+ if (err)
+ {
fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
- gcry_strerror (-1) );
+ gpg_strerror (err));
gcry_cipher_close (hd);
exit (1);
}
@@ -230,7 +245,7 @@ cipher_bench ( const char *algoname )
buflen = (buflen / blklen) * blklen;
start_timer ();
- for (i=err=0; !err && i < 1000; i++)
+ for (i=err=0; !err && i < 10; i++)
err = gcry_cipher_encrypt ( hd, outbuf, buflen, buf, buflen);
stop_timer ();
printf (" %s", elapsed_time ());
@@ -243,23 +258,24 @@ cipher_bench ( const char *algoname )
exit (1);
}
- hd = gcry_cipher_open (algo, modes[modeidx].mode, 0);
- if (!hd)
+ err = gcry_cipher_open (&hd, algo, modes[modeidx].mode, 0);
+ if (err)
{
fprintf (stderr, PGM ": error opening cipher `%s'/n", algoname);
exit (1);
}
- if (gcry_cipher_setkey (hd, key, keylen))
+ err = gcry_cipher_setkey (hd, key, keylen);
+ if (err)
{
fprintf (stderr, "gcry_cipher_setkey failed: %s\n",
- gcry_strerror (-1) );
+ gpg_strerror (err));
gcry_cipher_close (hd);
exit (1);
}
start_timer ();
- for (i=err=0; !err && i < 1000; i++)
+ for (i=err=0; !err && i < 10; i++)
err = gcry_cipher_decrypt ( hd, outbuf, buflen, buf, buflen);
stop_timer ();
printf (" %s", elapsed_time ());
@@ -280,8 +296,9 @@ cipher_bench ( const char *algoname )
static void
do_powm ( const char *n_str, const char *e_str, const char *m_str)
{
- GcryMPI e, n, msg, cip;
- int i, err;
+ gcry_mpi_t e, n, msg, cip;
+ gpg_error_t err;
+ int i;
err = gcry_mpi_scan (&n, GCRYMPI_FMT_HEX, n_str, 0 );
if (err) BUG ();
@@ -339,10 +356,6 @@ mpi_bench (void)
}
-
-
-
-
int
main( int argc, char **argv )
{
diff --git a/src/cipher.h b/src/cipher.h
index 2e2e910b..5ee83540 100644
--- a/src/cipher.h
+++ b/src/cipher.h
@@ -25,12 +25,7 @@
#include "../cipher/random.h"
-#define PUBKEY_FLAG_NO_BLINDING 0x00000001
-
-#define is_RSA(a) ((a)==GCRY_PK_RSA || (a)==GCRY_PK_RSA_E \
- || (a)==GCRY_PK_RSA_S )
-#define is_ELGAMAL(a) ((a)==GCRY_PK_ELG || (a)==GCRY_PK_ELG_E)
-
+#define PUBKEY_FLAG_NO_BLINDING 1 << 0
/*-- rmd160.c --*/
void _gcry_rmd160_hash_buffer( char *outbuf, const char *buffer, size_t length );
@@ -63,15 +58,15 @@ typedef struct gcry_pubkey_spec
const char *elements_sig;
const char *elements_grip;
int use;
- int (*generate) (int algo, unsigned int nbits, unsigned long use_e,
- GcryMPI *skey, GcryMPI **retfactors);
- int (*check_secret_key) (int algo, GcryMPI *skey);
- int (*encrypt) (int algo, GcryMPI *resarr, GcryMPI data, GcryMPI *pkey, int flags);
- int (*decrypt) (int algo, GcryMPI *result, GcryMPI *data, GcryMPI *skey, int flags);
- int (*sign) (int algo, GcryMPI *resarr, GcryMPI data, GcryMPI *skey);
- int (*verify) (int algo, GcryMPI hash, GcryMPI *data, GcryMPI *pkey,
- int (*cmp)(void *, GcryMPI), void *opaquev);
- unsigned (*get_nbits) (int algo, GcryMPI *pkey);
+ gpg_err_code_t (*generate) (int algo, unsigned int nbits, unsigned long use_e,
+ gcry_mpi_t *skey, gcry_mpi_t **retfactors);
+ gpg_err_code_t (*check_secret_key) (int algo, gcry_mpi_t *skey);
+ gpg_err_code_t (*encrypt) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *pkey, int flags);
+ gpg_err_code_t (*decrypt) (int algo, gcry_mpi_t *result, gcry_mpi_t *data, gcry_mpi_t *skey, int flags);
+ gpg_err_code_t (*sign) (int algo, gcry_mpi_t *resarr, gcry_mpi_t data, gcry_mpi_t *skey);
+ gpg_err_code_t (*verify) (int algo, gcry_mpi_t hash, gcry_mpi_t *data, gcry_mpi_t *pkey,
+ int (*cmp)(void *, gcry_mpi_t), void *opaquev);
+ unsigned (*get_nbits) (int algo, gcry_mpi_t *pkey);
} GcryPubkeySpec;
typedef struct gcry_digest_spec
@@ -95,7 +90,7 @@ typedef struct gcry_cipher_spec
size_t blocksize;
size_t keylen;
size_t contextsize;
- int (*setkey) (void *c, const unsigned char *key, unsigned keylen);
+ gpg_err_code_t (*setkey) (void *c, const unsigned char *key, unsigned keylen);
void (*encrypt) (void *c, unsigned char *outbuf, const unsigned char *inbuf);
void (*decrypt) (void *c, unsigned char *outbuf, const unsigned char *inbuf);
void (*stencrypt) (void *c, unsigned char *outbuf, const unsigned char *inbuf,
@@ -115,6 +110,9 @@ extern GcryCipherSpec cipher_spec_aes192;
extern GcryCipherSpec cipher_spec_aes256;
extern GcryCipherSpec cipher_spec_twofish;
extern GcryCipherSpec cipher_spec_twofish128;
+extern GcryCipherSpec cipher_spec_serpent128;
+extern GcryCipherSpec cipher_spec_serpent192;
+extern GcryCipherSpec cipher_spec_serpent256;
/* Declarations for the digest specifications. */
extern GcryDigestSpec digest_spec_crc32;
diff --git a/src/g10lib.h b/src/g10lib.h
index 36460a23..4459d92b 100644
--- a/src/g10lib.h
+++ b/src/g10lib.h
@@ -37,30 +37,30 @@
#include "types.h"
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
-# define JNLIB_GCC_M_FUNCTION 1
-# define JNLIB_GCC_A_NR __attribute__ ((noreturn))
-# define JNLIB_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
-# define JNLIB_GCC_A_NR_PRINTF( f, a ) \
+#define JNLIB_GCC_M_FUNCTION 1
+#define JNLIB_GCC_A_NR __attribute__ ((noreturn))
+#define JNLIB_GCC_A_PRINTF( f, a ) __attribute__ ((format (printf,f,a)))
+#define JNLIB_GCC_A_NR_PRINTF( f, a ) \
__attribute__ ((noreturn, format (printf,f,a)))
-# define GCC_ATTR_NORETURN __attribute__ ((__noreturn__))
+#define GCC_ATTR_NORETURN __attribute__ ((__noreturn__))
#else
-# define JNLIB_GCC_A_NR
-# define JNLIB_GCC_A_PRINTF( f, a )
-# define JNLIB_GCC_A_NR_PRINTF( f, a )
-# define GCC_ATTR_NORETURN
+#define JNLIB_GCC_A_NR
+#define JNLIB_GCC_A_PRINTF( f, a )
+#define JNLIB_GCC_A_NR_PRINTF( f, a )
+#define GCC_ATTR_NORETURN
#endif
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96 )
-# define GCC_ATTR_PURE __attribute__ ((__pure__))
+#define GCC_ATTR_PURE __attribute__ ((__pure__))
#else
-# define GCC_ATTR_PURE
+#define GCC_ATTR_PURE
#endif
/* (The malloc attribute might be defined prior to 3.2 - I am just not sure) */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2 )
-# define GCC_ATTR_MALLOC __attribute__ ((__malloc__))
+#define GCC_ATTR_MALLOC __attribute__ ((__malloc__))
#else
-# define GCC_ATTR_MALLOC
+#define GCC_ATTR_MALLOC
#endif
#ifdef G10_I18N_H
@@ -70,10 +70,6 @@
#define _(a) _gcry_gettext(a)
#define N_(a) (a)
-/*-- gcrypt/global.c --*/
-#define set_lasterr(a) _gcry_set_lasterr ((a))
-int _gcry_set_lasterr (int err);
-
void _gcry_check_heap( const void *a );
int _gcry_get_debug_flag( unsigned int mask );
@@ -102,9 +98,9 @@ void _gcry_set_log_verbosity( int level );
int _gcry_log_verbosity( int level );
#ifdef JNLIB_GCC_M_FUNCTION
- #define BUG() _gcry_bug( __FILE__ , __LINE__, __FUNCTION__ )
+#define BUG() _gcry_bug( __FILE__ , __LINE__, __FUNCTION__ )
#else
- #define BUG() _gcry_bug( __FILE__ , __LINE__ )
+#define BUG() _gcry_bug( __FILE__ , __LINE__ )
#endif
#define log_hexdump _gcry_log_hexdump
@@ -122,19 +118,13 @@ int _gcry_log_verbosity( int level );
#ifndef DID_MPI_TYPEDEF
typedef struct gcry_mpi * MPI;
- #define DID_MPI_TYPEDEF
+#define DID_MPI_TYPEDEF
#endif
#ifndef mpi_powm
- #define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
+#define mpi_powm(w,b,e,m) gcry_mpi_powm( (w), (b), (e), (m) )
#endif
-int string_to_pubkey_algo( const char *string );
-const char * pubkey_algo_to_string( int algo );
-unsigned pubkey_nbits( int algo, MPI *pkey );
-
-
-
/*-- primegen.c --*/
MPI _gcry_generate_secret_prime (unsigned int nbits,
int (*extra_check)(void*, MPI),
@@ -159,25 +149,25 @@ int strcasecmp (const char *a, const char *b) GCC_ATTR_PURE;
/* macros used to rename missing functions */
#ifndef HAVE_STRTOUL
- #define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
+#define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
#endif
#ifndef HAVE_MEMMOVE
- #define memmove(d, s, n) bcopy((s), (d), (n))
+#define memmove(d, s, n) bcopy((s), (d), (n))
#endif
#ifndef HAVE_STRICMP
- #define stricmp(a,b) strcasecmp( (a), (b) )
+#define stricmp(a,b) strcasecmp( (a), (b) )
#endif
#ifndef HAVE_ATEXIT
- #define atexit(a) (on_exit((a),0))
+#define atexit(a) (on_exit((a),0))
#endif
#ifndef HAVE_RAISE
- #define raise(a) kill(getpid(), (a))
+#define raise(a) kill(getpid(), (a))
#endif
/* some handy macros */
#ifndef STR
- #define STR(v) #v
+#define STR(v) #v
#endif
#define STR2(v) STR(v)
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
@@ -214,8 +204,8 @@ typedef struct gcry_module GcryModule;
/* Flags for the `flags' member of GcryModule. */
#define FLAG_MODULE_DISABLED 1 << 0
-int _gcry_module_add (GcryModule **entries, void *spec,
- GcryModule **module);
+gpg_err_code_t _gcry_module_add (GcryModule **entries, void *spec,
+ GcryModule **module);
typedef int (*GcryModuleLookup) (void *spec, void *data);
diff --git a/src/gcrypt.h b/src/gcrypt.h
index 8ee9d696..0ea8455a 100644
--- a/src/gcrypt.h
+++ b/src/gcrypt.h
@@ -24,6 +24,461 @@
#include <stdarg.h>
#include <string.h>
+#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_GCRYPT
+
+/* Support for libgpg-error. */
+#ifdef USE_LIBGPG_ERROR
+#include <gpg-error.h>
+#else
+
+/* Only use free slots, never change or reorder the existing
+ entries. */
+typedef enum
+ {
+ GPG_ERR_SOURCE_GCRYPT = 1,
+
+ /* This is one more than the largest allowed entry. */
+ GPG_ERR_SOURCE_DIM = 256
+ } gpg_err_source_t;
+
+
+/* The error code type gpg_err_code_t. */
+
+/* Only use free slots, never change or reorder the existing
+ entries. */
+typedef enum
+ {
+ GPG_ERR_NO_ERROR = 0, /* An error that is not an error. */
+ GPG_ERR_GENERAL = 1,
+ GPG_ERR_UNKNOWN_PACKET = 2,
+ GPG_ERR_UNKNOWN_VERSION = 3, /* Unknown version (in packet). */
+ GPG_ERR_PUBKEY_ALGO = 4, /* Invalid public key algorithm. */
+ GPG_ERR_DIGEST_ALGO = 5, /* Invalid digest algorithm. */
+ GPG_ERR_BAD_PUBKEY = 6, /* Bad public key. */
+ GPG_ERR_BAD_SECKEY = 7, /* Bad secret key. */
+ GPG_ERR_BAD_SIGNATURE = 8, /* Bad signature. */
+ GPG_ERR_NO_PUBKEY = 9, /* Public key not found. */
+ GPG_ERR_CHECKSUM = 10, /* Checksum error. */
+ GPG_ERR_BAD_PASSPHRASE = 11, /* Bad passphrase. */
+ GPG_ERR_CIPHER_ALGO = 12, /* Invalid cipher algorithm. */
+ GPG_ERR_KEYRING_OPEN = 13,
+ GPG_ERR_INV_PACKET = 14,
+ GPG_ERR_INV_ARMOR = 15,
+ GPG_ERR_NO_USER_ID = 16,
+ GPG_ERR_NO_SECKEY = 17, /* Secret key not available. */
+ GPG_ERR_WRONG_SECKEY = 18, /* Wrong secret key used. */
+ GPG_ERR_BAD_KEY = 19, /* Bad (session) key. */
+ GPG_ERR_COMPR_ALGO = 20, /* Unknown compress algorithm. */
+
+ /* Codes 21 to 29 are free to be used. */
+
+ GPG_ERR_BAD_MPI = 30, /* Problem with an MPI's value. */
+ GPG_ERR_INV_PASSPHRASE = 31, /* Invalid passphrase. */
+ GPG_ERR_SIG_CLASS = 32,
+ GPG_ERR_RESOURCE_LIMIT = 33,
+ GPG_ERR_INV_KEYRING = 34,
+ GPG_ERR_TRUSTDB = 35, /* A problem with the trustdb. */
+ GPG_ERR_BAD_CERT = 36, /* Bad certificate. */
+ GPG_ERR_INV_USER_ID = 37,
+ GPG_ERR_UNEXPECTED = 38,
+ GPG_ERR_TIME_CONFLICT = 39,
+ GPG_ERR_KEYSERVER = 40,
+ GPG_ERR_WRONG_PUBKEY_ALGO = 41, /* Wrong public key algorithm. */
+ GPG_ERR_TRIBUTE_TO_D_A = 42,
+ GPG_ERR_WEAK_KEY = 43, /* Weak encryption key. */
+ GPG_ERR_INV_KEYLEN = 44, /* Invalid length of a key. */
+ GPG_ERR_INV_ARG = 45, /* Invalid argument. */
+ GPG_ERR_BAD_URI = 46, /* Syntax error in URI. */
+ GPG_ERR_INV_URI = 47, /* Unsupported scheme and similar. */
+ GPG_ERR_NETWORK = 48, /* General network error. */
+ GPG_ERR_UNKNOWN_HOST = 49,
+ GPG_ERR_SELFTEST_FAILED = 50,
+ GPG_ERR_NOT_ENCRYPTED = 51,
+ GPG_ERR_NOT_PROCESSED = 52,
+ GPG_ERR_UNUSABLE_PUBKEY = 53,
+ GPG_ERR_UNUSABLE_SECKEY = 54,
+ GPG_ERR_INV_VALUE = 55,
+ GPG_ERR_BAD_CERT_CHAIN = 56,
+ GPG_ERR_MISSING_CERT = 57,
+ GPG_ERR_NO_DATA = 58,
+ GPG_ERR_BUG = 59,
+ GPG_ERR_NOT_SUPPORTED = 60,
+ GPG_ERR_INV_OP = 61, /* Invalid operation code. */
+ GPG_ERR_TIMEOUT = 62, /* Something timed out. */
+ GPG_ERR_INTERNAL = 63, /* Internal error. */
+ GPG_ERR_EOF_GCRYPT = 64, /* Compatibility for gcrypt. */
+ GPG_ERR_INV_OBJ = 65, /* An object is not valid. */
+ GPG_ERR_TOO_SHORT = 66, /* Provided object is too short. */
+ GPG_ERR_TOO_LARGE = 67, /* Provided object is too large. */
+ GPG_ERR_NO_OBJ = 68, /* Missing item in an object. */
+ GPG_ERR_NOT_IMPLEMENTED = 69, /* Not implemented. */
+ GPG_ERR_CONFLICT = 70, /* Conflicting use. */
+ GPG_ERR_INV_CIPHER_MODE = 71, /* Invalid cipher mode. */
+ GPG_ERR_INV_FLAG = 72, /* Invalid flag. */
+ GPG_ERR_INV_HANDLE = 73, /* Invalid handle. */
+
+ /* Code 74 is free to be used. */
+
+ GPG_ERR_INCOMPLETE_LINE = 75,
+ GPG_ERR_INV_RESPONSE = 76,
+ GPG_ERR_NO_AGENT = 77,
+ GPG_ERR_AGENT = 78,
+ GPG_ERR_INV_DATA = 79,
+ GPG_ERR_ASSUAN_SERVER_FAULT = 80,
+ GPG_ERR_ASSUAN = 81, /* Catch all assuan error. */
+ GPG_ERR_INV_SESSION_KEY = 82,
+ GPG_ERR_INV_SEXP = 83,
+ GPG_ERR_UNSUPPORTED_ALGORITHM = 84,
+ GPG_ERR_NO_PIN_ENTRY = 85,
+ GPG_ERR_PIN_ENTRY = 86,
+ GPG_ERR_BAD_PIN = 87,
+ GPG_ERR_INV_NAME = 88,
+ GPG_ERR_BAD_DATA = 89,
+ GPG_ERR_INV_PARAMETER = 90,
+
+ /* Code 91 is free to be used. */
+
+ GPG_ERR_NO_DIRMNGR = 92,
+ GPG_ERR_DIRMNGR = 93,
+ GPG_ERR_CERT_REVOKED = 94,
+ GPG_ERR_NO_CRL_KNOWN = 95,
+ GPG_ERR_CRL_TOO_OLD = 96,
+ GPG_ERR_LINE_TOO_LONG = 97,
+ GPG_ERR_NOT_TRUSTED = 98,
+ GPG_ERR_CANCELED = 109,
+ GPG_ERR_BAD_CA_CERT = 100,
+ GPG_ERR_CERT_EXPIRED = 101, /* Key signature expired. */
+ GPG_ERR_CERT_TOO_YOUNG = 102,
+ GPG_ERR_UNSUPPORTED_CERT = 103,
+ GPG_ERR_UNKNOWN_SEXP = 104,
+ GPG_ERR_UNSUPPORTED_PROTECTION = 105,
+ GPG_ERR_CORRUPTED_PROTECTION = 106,
+ GPG_ERR_AMBIGUOUS_NAME = 107,
+ GPG_ERR_CARD = 108,
+ GPG_ERR_CARD_RESET = 109,
+ GPG_ERR_CARD_REMOVED = 110,
+ GPG_ERR_INV_CARD = 111,
+ GPG_ERR_CARD_NOT_PRESENT = 112,
+ GPG_ERR_NO_PKCS15_APP = 113,
+ GPG_ERR_NOT_CONFIRMED = 114,
+ GPG_ERR_CONFIGURATION = 115,
+ GPG_ERR_NO_POLICY_MATCH = 116,
+ GPG_ERR_INV_INDEX = 117,
+ GPG_ERR_INV_ID = 118,
+ GPG_ERR_NO_SCDAEMON = 119,
+ GPG_ERR_SCDAEMON = 120,
+ GPG_ERR_UNSUPPORTED_PROTOCOL = 121,
+ GPG_ERR_BAD_PIN_METHOD = 122,
+ GPG_ERR_CARD_NOT_INITIALIZED = 123,
+ GPG_ERR_UNSUPPORTED_OPERATION = 124,
+ GPG_ERR_WRONG_KEY_USAGE = 125,
+ GPG_ERR_NOTHING_FOUND = 126, /* Operation failed due to an
+ unsuccessful find operation. */
+ GPG_ERR_WRONG_BLOB_TYPE = 127, /* Keybox BLOB of wrong type. */
+ GPG_ERR_MISSING_VALUE = 128, /* A required value is missing. */
+
+ /* 129 to 149 are free to be used. */
+
+ GPG_ERR_INV_ENGINE = 150,
+ GPG_ERR_PUBKEY_NOT_TRUSTED = 151,
+ GPG_ERR_DECRYPT_FAILED = 152,
+ GPG_ERR_KEY_EXPIRED = 153,
+ GPG_ERR_SIG_EXPIRED = 154, /* Data signature expired. */
+
+ /* 155 to 200 are free to be used. */
+
+ /* Error codes pertaining to S-expressions. */
+ GPG_ERR_SEXP_INV_LEN_SPEC = 201,
+ GPG_ERR_SEXP_STRING_TOO_LONG = 202,
+ GPG_ERR_SEXP_UNMATCHED_PAREN = 203,
+ GPG_ERR_SEXP_NOT_CANONICAL = 204,
+ GPG_ERR_SEXP_BAD_CHARACTER = 205,
+ GPG_ERR_SEXP_BAD_QUOTATION = 206, /* Or invalid hex or octal value. */
+ GPG_ERR_SEXP_ZERO_PREFIX = 207, /* First character of length is 0. */
+ GPG_ERR_SEXP_NESTED_DH = 208, /* Nested display hints. */
+ GPG_ERR_SEXP_UNMATCHED_DH = 209, /* Unmatched display hint. */
+ GPG_ERR_SEXP_UNEXPECTED_PUNC = 210, /* Unexpected reserved punctuation. */
+ GPG_ERR_SEXP_BAD_HEX_CHAR = 211,
+ GPG_ERR_SEXP_ODD_HEX_NUMBERS = 212,
+ GPG_ERR_SEXP_BAD_OCT_CHAR = 213,
+
+ /* 213 to 1023 are free to be used. */
+
+ /* For free use by non-GnuPG components. */
+ GPG_ERR_USER_1 = 1024,
+ GPG_ERR_USER_2 = 1025,
+ GPG_ERR_USER_3 = 1026,
+ GPG_ERR_USER_4 = 1027,
+ GPG_ERR_USER_5 = 1028,
+ GPG_ERR_USER_6 = 1029,
+ GPG_ERR_USER_7 = 1030,
+ GPG_ERR_USER_8 = 1031,
+ GPG_ERR_USER_9 = 1032,
+ GPG_ERR_USER_10 = 1033,
+ GPG_ERR_USER_11 = 1034,
+ GPG_ERR_USER_12 = 1035,
+ GPG_ERR_USER_13 = 1036,
+ GPG_ERR_USER_14 = 1037,
+ GPG_ERR_USER_15 = 1038,
+ GPG_ERR_USER_16 = 1039,
+
+ /* 1040 to 16381 are free to be used. */
+
+ GPG_ERR_UNKNOWN_ERRNO = 16382,
+ GPG_ERR_EOF = 16383, /* This was once a -1. Pity. */
+
+ /* The following error codes are used to map system errors. */
+ GPG_ERR_E2BIG = 16384,
+ GPG_ERR_EACCES = 16385,
+ GPG_ERR_EADDRINUSE = 16386,
+ GPG_ERR_EADDRNOTAVAIL = 16387,
+ GPG_ERR_EADV = 16388,
+ GPG_ERR_EAFNOSUPPORT = 16389,
+ GPG_ERR_EAGAIN = 16390,
+ GPG_ERR_EALREADY = 16391,
+ GPG_ERR_EAUTH = 16392,
+ GPG_ERR_EBACKGROUND = 16393,
+ GPG_ERR_EBADE = 16394,
+ GPG_ERR_EBADF = 16395,
+ GPG_ERR_EBADFD = 16396,
+ GPG_ERR_EBADMSG = 16397,
+ GPG_ERR_EBADR = 16398,
+ GPG_ERR_EBADRPC = 16399,
+ GPG_ERR_EBADRQC = 16400,
+ GPG_ERR_EBADSLT = 16401,
+ GPG_ERR_EBFONT = 16402,
+ GPG_ERR_EBUSY = 16403,
+ GPG_ERR_ECANCELED = 16404,
+ GPG_ERR_ECHILD = 16405,
+ GPG_ERR_ECHRNG = 16406,
+ GPG_ERR_ECOMM = 16407,
+ GPG_ERR_ECONNABORTED = 16408,
+ GPG_ERR_ECONNREFUSED = 16409,
+ GPG_ERR_ECONNRESET = 16410,
+ GPG_ERR_ED = 16411,
+ GPG_ERR_EDEADLK = 16412,
+ GPG_ERR_EDEADLOCK = 16413,
+ GPG_ERR_EDESTADDRREQ = 16414,
+ GPG_ERR_EDIED = 16415,
+ GPG_ERR_EDOM = 16416,
+ GPG_ERR_EDOTDOT = 16417,
+ GPG_ERR_EDQUOT = 16418,
+ GPG_ERR_EEXIST = 16419,
+ GPG_ERR_EFAULT = 16420,
+ GPG_ERR_EFBIG = 16421,
+ GPG_ERR_EFTYPE = 16422,
+ GPG_ERR_EGRATUITOUS = 16423,
+ GPG_ERR_EGREGIOUS = 16424,
+ GPG_ERR_EHOSTDOWN = 16425,
+ GPG_ERR_EHOSTUNREACH = 16426,
+ GPG_ERR_EIDRM = 16427,
+ GPG_ERR_EIEIO = 16428,
+ GPG_ERR_EILSEQ = 16429,
+ GPG_ERR_EINPROGRESS = 16430,
+ GPG_ERR_EINTR = 16431,
+ GPG_ERR_EINVAL = 16432,
+ GPG_ERR_EIO = 16433,
+ GPG_ERR_EISCONN = 16434,
+ GPG_ERR_EISDIR = 16435,
+ GPG_ERR_EISNAM = 16436,
+ GPG_ERR_EL2HLT = 16437,
+ GPG_ERR_EL2NSYNC = 16438,
+ GPG_ERR_EL3HLT = 16439,
+ GPG_ERR_EL3RST = 16440,
+ GPG_ERR_ELIBACC = 16441,
+ GPG_ERR_ELIBBAD = 16442,
+ GPG_ERR_ELIBEXEC = 16443,
+ GPG_ERR_ELIBMAX = 16444,
+ GPG_ERR_ELIBSCN = 16445,
+ GPG_ERR_ELNRNG = 16446,
+ GPG_ERR_ELOOP = 16447,
+ GPG_ERR_EMEDIUMTYPE = 16448,
+ GPG_ERR_EMFILE = 16449,
+ GPG_ERR_EMLINK = 16450,
+ GPG_ERR_EMSGSIZE = 16451,
+ GPG_ERR_EMULTIHOP = 16452,
+ GPG_ERR_ENAMETOOLONG = 16453,
+ GPG_ERR_ENAVAIL = 16454,
+ GPG_ERR_ENEEDAUTH = 16455,
+ GPG_ERR_ENETDOWN = 16456,
+ GPG_ERR_ENETRESET = 16457,
+ GPG_ERR_ENETUNREACH = 16458,
+ GPG_ERR_ENFILE = 16459,
+ GPG_ERR_ENOANO = 16460,
+ GPG_ERR_ENOBUFS = 16461,
+ GPG_ERR_ENOCSI = 16462,
+ GPG_ERR_ENODATA = 16463,
+ GPG_ERR_ENODEV = 16464,
+ GPG_ERR_ENOENT = 16465,
+ GPG_ERR_ENOEXEC = 16466,
+ GPG_ERR_ENOLCK = 16467,
+ GPG_ERR_ENOLINK = 16468,
+ GPG_ERR_ENOMEDIUM = 16469,
+ GPG_ERR_ENOMEM = 16470,
+ GPG_ERR_ENOMSG = 16471,
+ GPG_ERR_ENONET = 16472,
+ GPG_ERR_ENOPKG = 16473,
+ GPG_ERR_ENOPROTOOPT = 16474,
+ GPG_ERR_ENOSPC = 16475,
+ GPG_ERR_ENOSR = 16476,
+ GPG_ERR_ENOSTR = 16477,
+ GPG_ERR_ENOSYS = 16478,
+ GPG_ERR_ENOTBLK = 16479,
+ GPG_ERR_ENOTCONN = 16480,
+ GPG_ERR_ENOTDIR = 16481,
+ GPG_ERR_ENOTEMPTY = 16482,
+ GPG_ERR_ENOTNAM = 16483,
+ GPG_ERR_ENOTSOCK = 16484,
+ GPG_ERR_ENOTSUP = 16485,
+ GPG_ERR_ENOTTY = 16486,
+ GPG_ERR_ENOTUNIQ = 16487,
+ GPG_ERR_ENXIO = 16488,
+ GPG_ERR_EOPNOTSUPP = 16489,
+ GPG_ERR_EOVERFLOW = 16490,
+ GPG_ERR_EPERM = 16491,
+ GPG_ERR_EPFNOSUPPORT = 16492,
+ GPG_ERR_EPIPE = 16493,
+ GPG_ERR_EPROCLIM = 16494,
+ GPG_ERR_EPROCUNAVAIL = 16495,
+ GPG_ERR_EPROGMISMATCH = 16496,
+ GPG_ERR_EPROGUNAVAIL = 16497,
+ GPG_ERR_EPROTO = 16498,
+ GPG_ERR_EPROTONOSUPPORT = 16499,
+ GPG_ERR_EPROTOTYPE = 16500,
+ GPG_ERR_ERANGE = 16501,
+ GPG_ERR_EREMCHG = 16502,
+ GPG_ERR_EREMOTE = 16503,
+ GPG_ERR_EREMOTEIO = 16504,
+ GPG_ERR_ERESTART = 16505,
+ GPG_ERR_EROFS = 16506,
+ GPG_ERR_ERPCMISMATCH = 16507,
+ GPG_ERR_ESHUTDOWN = 16508,
+ GPG_ERR_ESOCKTNOSUPPORT = 16509,
+ GPG_ERR_ESPIPE = 16510,
+ GPG_ERR_ESRCH = 16511,
+ GPG_ERR_ESRMNT = 16512,
+ GPG_ERR_ESTALE = 16513,
+ GPG_ERR_ESTRPIPE = 16514,
+ GPG_ERR_ETIME = 16515,
+ GPG_ERR_ETIMEDOUT = 16516,
+ GPG_ERR_ETOOMANYREFS = 16517,
+ GPG_ERR_ETXTBSY = 16518,
+ GPG_ERR_EUCLEAN = 16519,
+ GPG_ERR_EUNATCH = 16520,
+ GPG_ERR_EUSERS = 16521,
+ GPG_ERR_EWOULDBLOCK = 16522,
+ GPG_ERR_EXDEV = 16523,
+ GPG_ERR_EXFULL = 16524,
+
+ /* 16525 to 32677 are free to be used for more system errors. */
+
+ /* This is one more than the largest allowed entry. */
+ GPG_ERR_CODE_DIM = 32768
+ } gpg_err_code_t;
+
+
+/* The error value type gpg_error_t. */
+
+/* We would really like to use bit-fields in a struct, but using
+ structs as return values can cause binary compatibility issues, in
+ particular if you want to do it effeciently (also see
+ -freg-struct-return option to GCC). */
+typedef unsigned int gpg_error_t;
+
+/* We use the lowest 16 bits of gpg_error_t for error codes. The 17th
+ bit indicates system errors. */
+#define GPG_ERR_CODE_MASK (GPG_ERR_CODE_DIM - 1)
+#define GPG_ERR_SYSTEM_ERROR 16384
+
+/* Bits 18 to 24 are reserved. */
+
+/* We use the upper 8 bits of gpg_error_t for error sources. */
+#define GPG_ERR_SOURCE_MASK (GPG_ERR_SOURCE_DIM - 1)
+#define GPG_ERR_SOURCE_SHIFT 24
+
+
+/* Constructor and accessor functions. */
+
+/* Construct an error value from an error code and source. Within a
+ subsystem, use gpg_error. */
+static __inline__ gpg_error_t
+gpg_err_make (gpg_err_source_t source, gpg_err_code_t code)
+{
+ return code == GPG_ERR_NO_ERROR ? GPG_ERR_NO_ERROR
+ : (((source & GPG_ERR_SOURCE_MASK) << GPG_ERR_SOURCE_SHIFT)
+ | (code & GPG_ERR_CODE_MASK));
+}
+
+
+/* The user should define GPG_ERR_SOURCE_DEFAULT before including this
+ file to specify a default source for gpg_error. */
+#ifndef GPG_ERR_SOURCE_DEFAULT
+#define GPG_ERR_SOURCE_DEFAULT GPG_ERR_SOURCE_UNKNOWN
+#endif
+
+static __inline__ gpg_error_t
+gpg_error (gpg_err_code_t code)
+{
+ return gpg_err_make (GPG_ERR_SOURCE_DEFAULT, code);
+}
+
+
+/* Retrieve the error code from an error value. */
+static __inline__ gpg_err_code_t
+gpg_err_code (gpg_error_t err)
+{
+ return err & GPG_ERR_CODE_MASK;
+}
+
+
+/* Retrieve the error source from an error value. */
+static __inline__ gpg_err_source_t
+gpg_err_source (gpg_error_t err)
+{
+ return (err >> GPG_ERR_SOURCE_SHIFT) & GPG_ERR_SOURCE_MASK;
+}
+
+
+/* String functions. */
+
+/* Return a pointer to a string containing a description of the error
+ code in the error value ERR. */
+const char *gpg_strerror (gpg_error_t err);
+
+/* Return a pointer to a string containing a description of the error
+ source in the error value ERR. */
+const char *gpg_strsource (gpg_error_t err);
+
+
+/* Mapping of system errors (errno). */
+
+/* Retrieve the error code for the system error ERR. This returns
+ GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped (report
+ this). */
+gpg_err_code_t gpg_err_code_from_errno (int err);
+
+
+/* Retrieve the system error for the error code CODE. This returns 0
+ if CODE is not a system error code. */
+int gpg_err_code_to_errno (gpg_err_code_t code);
+
+
+/* Self-documenting convenience functions. */
+
+static __inline__ gpg_error_t
+gpg_err_make_from_errno (gpg_err_source_t source, int err)
+{
+ return gpg_err_make (source, gpg_err_code_from_errno (err));
+}
+
+
+static __inline__ gpg_error_t
+gpg_error_from_errno (int err)
+{
+ return gpg_error (gpg_err_code_from_errno (err));
+}
+#endif
+
#ifdef __cplusplus
extern "C" {
#if 0 /* keep Emacsens's auto-indent happy */
@@ -42,95 +497,151 @@ extern "C" {
/* Internal: We can't use the convenience macros for the multi
precision integer functions when building this library. */
#ifdef _GCRYPT_IN_LIBGCRYPT
-# ifndef GCRYPT_NO_MPI_MACROS
-# define GCRYPT_NO_MPI_MACROS 1
-# endif
+#ifndef GCRYPT_NO_MPI_MACROS
+#define GCRYPT_NO_MPI_MACROS 1
+#endif
#endif
/* We want to use gcc attributes when possible. Warning: Don't use
these macros in your progranms: As indicated by the leading
underscore they are subject to change without notice. */
-#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96 )
-# define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__))
-#else
-# define _GCRY_GCC_ATTR_PURE
+#ifdef __GNUC__
+
+#define _GCRY_GCC_VERSION (__GNUC__ * 10000 \
+ + __GNUC_MINOR__ * 100 \
+ + __GNUC_PATCHLEVEL__)
+
+#if _GCRY_GCC_VERSION >= 30100
+#define _GCRY_GCC_ATTR_DEPRECATED __attribute__ ((__deprecated__))
#endif
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 2 )
-# define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__))
-#else
-# define _GCRY_GCC_ATTR_MALLOC
+
+#if _GCRY_GCC_VERSION >= 29600
+#define _GCRY_GCC_ATTR_PURE __attribute__ ((__pure__))
+#endif
+
+#if _GCRY_GCC_VERSION >= 300200
+#define _GCRY_GCC_ATTR_MALLOC __attribute__ ((__malloc__))
+#endif
+
#endif
+#ifndef _GCRY_GCC_ATTR_DEPRECATED
+#define _GCRY_GCC_ATTR_DEPRECATED
+#endif
+#ifndef _GCRY_GCC_ATTR_PURE
+#define _GCRY_GCC_ATTR_PURE
+#endif
+#ifndef _GCRY_GCC_ATTR_MALLOC
+#define _GCRY_GCC_ATTR_MALLOC
+#endif
-/* The data object used to hold a multi precision integer. GcryMPI is
- the preferred one. */
+/* The data object used to hold a multi precision integer. */
struct gcry_mpi;
-typedef struct gcry_mpi *GCRY_MPI;
-typedef struct gcry_mpi *GcryMPI;
+typedef struct gcry_mpi *gcry_mpi_t;
+
+typedef struct gcry_mpi *GCRY_MPI _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_mpi *GcryMPI _GCRY_GCC_ATTR_DEPRECATED;
-/* Error handling etc. */
+/* The error numbers used by Libgcrypt. */
-/* The error numbers used by Libgcrypt. */
-/* FIXME: We should use the same values as they were used in GnuPG
- 1.0. gpg --status-fd may print some of these values. */
+/* These definitions provide some API compatibility. */
+
+#ifndef USE_LIBGPG_ERROR
+/* FIXME!!!! */
+
+#define gpg_strerror(x) gcry_strerror (x)
+
+#endif
+
+
+/* This is here for API compatibility. */
enum
{
- GCRYERR_SUCCESS = 0, /* "no error" (this is guaranteed to be 0) */
- GCRYERR_GENERAL = 1, /* catch all the other errors code */
-
- GCRYERR_INV_PK_ALGO = 4, /* invalid public key algorithm */
- GCRYERR_INV_MD_ALGO = 5, /* invalid message digest algorithm */
- GCRYERR_BAD_PUBLIC_KEY = 6, /* Bad public key */
- GCRYERR_BAD_SECRET_KEY = 7, /* Bad secret key */
- GCRYERR_BAD_SIGNATURE = 8, /* Bad signature */
-
- GCRYERR_INV_CIPHER_ALGO = 12, /* invalid cipher algorithm */
- GCRYERR_BAD_MPI = 30, /* problem with an MPI's value*/
- GCRYERR_WRONG_PK_ALGO = 41, /* wrong public key algorithm */
- GCRYERR_WEAK_KEY = 43, /* weak encryption key */
- GCRYERR_INV_KEYLEN = 44, /* invalid length of a key*/
- GCRYERR_INV_ARG = 45, /* invalid argument */
- GCRYERR_SELFTEST = 50, /* selftest failed */
-
- /* error codes not used in GnuPG 1.0 */
- GCRYERR_INV_OP = 61, /* invalid operation code or ctl command */
- GCRYERR_NO_MEM = 62, /* out of core */
- GCRYERR_INTERNAL = 63, /* internal error */
- GCRYERR_EOF = 64, /* (-1) is remapped to this value */
- GCRYERR_INV_OBJ = 65, /* an object is not valid */
- GCRYERR_TOO_SHORT = 66, /* provided buffer/object too short */
- GCRYERR_TOO_LARGE = 67, /* object is too large */
- GCRYERR_NO_OBJ = 68, /* Missing item in an object */
- GCRYERR_NOT_IMPL = 69, /* Not implemented */
- GCRYERR_CONFLICT = 70, /* conflicting use of functions/values */
- GCRYERR_INV_CIPHER_MODE = 71, /* invalid/unsupported cipher mode */
- GCRYERR_INV_FLAG = 72, /* invalid flag */
-
- /* error codes pertaining to S-expressions */
- GCRYERR_SEXP_INV_LEN_SPEC = 201,
- GCRYERR_SEXP_STRING_TOO_LONG = 202,
- GCRYERR_SEXP_UNMATCHED_PAREN = 203,
- GCRYERR_SEXP_NOT_CANONICAL = 204,
- GCRYERR_SEXP_BAD_CHARACTER = 205,
- GCRYERR_SEXP_BAD_QUOTATION = 206,/* or invalid hex or octal value */
- GCRYERR_SEXP_ZERO_PREFIX = 207,/* first character of a length is 0 */
- GCRYERR_SEXP_NESTED_DH = 208,/* nested display hints */
- GCRYERR_SEXP_UNMATCHED_DH = 209,/* unmatched display hint */
- GCRYERR_SEXP_UNEXPECTED_PUNC = 210,/* unexpected reserved punctuation */
- GCRYERR_SEXP_BAD_HEX_CHAR = 211,
- GCRYERR_SEXP_ODD_HEX_NUMBERS = 212,
- GCRYERR_SEXP_BAD_OCT_CHAR = 213
+ GCRYERR_SUCCESS = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_NO_ERROR & 0xFFFF),
+ GCRYERR_GENERAL = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_GENERAL & 0xFFFF),
+ GCRYERR_INV_PK_ALGO = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_PUBKEY_ALGO & 0xFFFF),
+ GCRYERR_INV_MD_ALGO = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_DIGEST_ALGO & 0xFFFF),
+ GCRYERR_BAD_PUBLIC_KEY = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_BAD_PUBKEY & 0xFFFF),
+ GCRYERR_BAD_SECRET_KEY = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_BAD_SECKEY & 0xFFFF),
+ GCRYERR_BAD_SIGNATURE = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_BAD_SIGNATURE & 0xFFFF),
+ GCRYERR_INV_CIPHER_ALGO = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_CIPHER_ALGO & 0xFFFF),
+ GCRYERR_BAD_MPI = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_BAD_MPI & 0xFFFF),
+ GCRYERR_WRONG_PK_ALGO = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_WRONG_PUBKEY_ALGO & 0xFFFF),
+ GCRYERR_WEAK_KEY = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_WEAK_KEY & 0xFFFF),
+ GCRYERR_INV_KEYLEN = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_KEYLEN & 0xFFFF),
+ GCRYERR_INV_ARG = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_ARG & 0xFFFF),
+ GCRYERR_SELFTEST = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SELFTEST_FAILED & 0xFFFF),
+ GCRYERR_INV_OP = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_OP & 0xFFFF),
+
+ GCRYERR_INTERNAL = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INTERNAL & 0xFFFF),
+
+ GCRYERR_INV_OBJ = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_OBJ & 0xFFFF),
+ GCRYERR_TOO_SHORT = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_TOO_SHORT & 0xFFFF),
+ GCRYERR_TOO_LARGE = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_TOO_LARGE & 0xFFFF),
+ GCRYERR_NO_OBJ = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_NO_OBJ & 0xFFFF),
+ GCRYERR_NOT_IMPL = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_NOT_IMPLEMENTED & 0xFFFF),
+ GCRYERR_CONFLICT = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_CONFLICT & 0xFFFF),
+ GCRYERR_INV_CIPHER_MODE = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_CIPHER_MODE & 0xFFFF),
+ GCRYERR_INV_FLAG = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_INV_FLAG & 0xFFFF),
+ GCRYERR_SEXP_INV_LEN_SPEC = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_INV_LEN_SPEC & 0xFFFF),
+ GCRYERR_SEXP_STRING_TOO_LONG = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_STRING_TOO_LONG & 0xFFFF),
+ GCRYERR_SEXP_UNMATCHED_PAREN = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_UNMATCHED_PAREN & 0xFFFF),
+ GCRYERR_SEXP_NOT_CANONICAL = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_NOT_CANONICAL & 0xFFFF),
+ GCRYERR_SEXP_BAD_CHARACTER = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_BAD_CHARACTER & 0xFFFF),
+ GCRYERR_SEXP_BAD_QUOTATION = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_BAD_QUOTATION & 0xFFFF),
+ GCRYERR_SEXP_ZERO_PREFIX = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_ZERO_PREFIX & 0xFFFF),
+ GCRYERR_SEXP_NESTED_DH = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_NESTED_DH & 0xFFFF),
+ GCRYERR_SEXP_UNMATCHED_DH = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_UNMATCHED_DH & 0xFFFF),
+ GCRYERR_SEXP_UNEXPECTED_PUNC = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_UNEXPECTED_PUNC & 0xFFFF),
+ GCRYERR_SEXP_BAD_HEX_CHAR = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_BAD_HEX_CHAR & 0xFFFF),
+ GCRYERR_SEXP_ODD_HEX_NUMBERS = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_ODD_HEX_NUMBERS & 0xFFFF),
+ GCRYERR_SEXP_BAD_OCT_CHAR = ((GPG_ERR_SOURCE_DEFAULT & 0xFF) << 24)
+ | (GPG_ERR_SEXP_BAD_OCT_CHAR & 0xFFFF),
+
};
/* Check that the library fulfills the version requirement. */
const char *gcry_check_version (const char *req_version);
-/* Return the error number for the last failed function call. */
-int gcry_errno(void) _GCRY_GCC_ATTR_PURE;
-
/* Map an error number to a string. */
-const char *gcry_strerror (int ec);
+const char *gcry_strerror (gpg_error_t ec);
/* Codes for function dispatchers. */
@@ -183,76 +694,126 @@ enum gcry_ctl_cmds
};
/* Perform various operations defined by CMD. */
-int gcry_control (enum gcry_ctl_cmds CMD, ...);
+gpg_error_t gcry_control (enum gcry_ctl_cmds CMD, ...);
/* S-expression management. */
/* The object to represent an S-expression as used with the public key
- functions. GcrySexp is the preferred form. */
+ functions. */
struct gcry_sexp;
-typedef struct gcry_sexp *GCRY_SEXP;
-typedef struct gcry_sexp *GcrySexp;
+typedef struct gcry_sexp *gcry_sexp_t;
+
+typedef struct gcry_sexp *GCRY_SEXP _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_sexp *GcrySexp _GCRY_GCC_ATTR_DEPRECATED;
/* The possible values for the S-expression format. */
-enum gcry_sexp_format {
+enum gcry_sexp_format
+ {
GCRYSEXP_FMT_DEFAULT = 0,
GCRYSEXP_FMT_CANON = 1,
GCRYSEXP_FMT_BASE64 = 2,
GCRYSEXP_FMT_ADVANCED = 3
-};
+ };
/* Create an new S-expression object from BUFFER of size LENGTH and
return it in RETSEXP. With AUTODETECT set to 0 the data in BUFFER
- is expected to be in canonized format */
-int gcry_sexp_new (GcrySexp *retsexp, const void *buffer, size_t length,
- int autodetect);
+ is expected to be in canonized format. */
+gpg_error_t gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length,
+ int autodetect);
-/* Same as gcry_sexp_new but allows to pass a FREEFNC which has the
- effect to transfer ownership of BUFFER to the created object. */
-int gcry_sexp_create (GcrySexp *retsexp, void *buffer, size_t length,
- int autodetect, void (*freefnc)(void*) );
+ /* Same as gcry_sexp_new but allows to pass a FREEFNC which has the
+ effect to transfer ownership of BUFFER to the created object. */
+gpg_error_t gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length,
+ int autodetect, void (*freefnc) (void *));
/* Scan BUFFER and return a new S-expression object in RETSEXP. This
- function expects a printf like string in BUFFER. */
-int gcry_sexp_sscan (GcrySexp *retsexp, size_t *erroff,
- const char *buffer, size_t length );
+ function expects a printf like string in BUFFER. */
+gpg_error_t gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *buffer, size_t length);
/* Same as gcry_sexp_sscan but expects a string in FORMAT and can thus
- only be used for certain encodings. */
-int gcry_sexp_build (GcrySexp *retsexp, size_t *erroff,
- const char *format, ... );
+ only be used for certain encodings. */
+gpg_error_t gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, ...);
+
+/* Like gcry_sexp_build, but uses an array instead of variable
+ function arguments. */
+gpg_error_t gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, void **arg_list);
/* Release the S-expression object SEXP */
-void gcry_sexp_release (GcrySexp sexp);
+void gcry_sexp_release (gcry_sexp_t sexp);
/* Calculate the length of an canonized S-expresion in BUFFER and
check for a valid encoding. */
size_t gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
- size_t *erroff, int *errcode);
+ size_t *erroff, gpg_error_t *errcode);
/* Copies the S-expression object SEXP into BUFFER using the format
- specified in MODE. */
-size_t gcry_sexp_sprint (GCRY_SEXP sexp, int mode, char *buffer,
- size_t maxlength );
-
-void gcry_sexp_dump( const GCRY_SEXP a );
-GCRY_SEXP gcry_sexp_cons( const GCRY_SEXP a, const GCRY_SEXP b );
-GCRY_SEXP gcry_sexp_alist( const GCRY_SEXP *array );
-GCRY_SEXP gcry_sexp_vlist( const GCRY_SEXP a, ... );
-GCRY_SEXP gcry_sexp_append( const GCRY_SEXP a, const GCRY_SEXP n );
-GCRY_SEXP gcry_sexp_prepend( const GCRY_SEXP a, const GCRY_SEXP n );
-GCRY_SEXP gcry_sexp_find_token( GCRY_SEXP list,
- const char *tok, size_t toklen );
-int gcry_sexp_length( const GCRY_SEXP list );
-GCRY_SEXP gcry_sexp_nth( const GCRY_SEXP list, int number );
-GCRY_SEXP gcry_sexp_car( const GCRY_SEXP list );
-GCRY_SEXP gcry_sexp_cdr( const GCRY_SEXP list );
-GCRY_SEXP gcry_sexp_cadr( const GCRY_SEXP list );
-const char *gcry_sexp_nth_data( const GCRY_SEXP list, int number,
- size_t *datalen );
-GCRY_MPI gcry_sexp_nth_mpi( GCRY_SEXP list, int number, int mpifmt );
+ specified in MODE. */
+size_t gcry_sexp_sprint (gcry_sexp_t sexp, int mode, char *buffer,
+ size_t maxlength);
+
+/* Dumps the S-expression object A in a aformat suitable for debugging
+ to Libgcrypt's logging stream. */
+void gcry_sexp_dump (const gcry_sexp_t a);
+
+
+gcry_sexp_t gcry_sexp_cons (const gcry_sexp_t a, const gcry_sexp_t b);
+gcry_sexp_t gcry_sexp_alist (const gcry_sexp_t *array);
+gcry_sexp_t gcry_sexp_vlist (const gcry_sexp_t a, ...);
+gcry_sexp_t gcry_sexp_append (const gcry_sexp_t a, const gcry_sexp_t n);
+gcry_sexp_t gcry_sexp_prepend (const gcry_sexp_t a, const gcry_sexp_t n);
+
+/* Scan the S-expression for a sublist with a type (the car of the
+ list) matching the string TOKEN. If TOKLEN is not 0, the token is
+ assumed to be raw memory of this length. The function returns a
+ newly allocated S-expression consisting of the found sublist or
+ `NULL' when not found. */
+gcry_sexp_t gcry_sexp_find_token (gcry_sexp_t list,
+ const char *tok, size_t toklen);
+/* Return the length of the LIST. For a valid S-expression this
+ should be at least 1. */
+int gcry_sexp_length (const gcry_sexp_t list);
+
+/* Create and return a new S-expression from the element with index
+ NUMBER in LIST. Note that the first element has the index 0. If
+ there is no such element, `NULL' is returned. */
+gcry_sexp_t gcry_sexp_nth (const gcry_sexp_t list, int number);
+
+/* Create and return a new S-expression from the first element in
+ LIST; this called the "type" and should always exist and be a
+ string. `NULL' is returned in case of a problem. */
+gcry_sexp_t gcry_sexp_car (const gcry_sexp_t list);
+
+/* Create and return a new list form all elements except for the first
+ one. Note, that this function may return an invalid S-expression
+ because it is not guaranteed, that the type exists and is a string.
+ However, for parsing a complex S-expression it might be useful for
+ intermediate lists. Returns `NULL' on error. */
+gcry_sexp_t gcry_sexp_cdr (const gcry_sexp_t list);
+
+gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list);
+
+
+/* This function is used to get data from a LIST. A pointer to the
+ actual data with index NUMBER is returned and the length of this
+ data will be stored to DATALEN. If there is no data at the given
+ index or the index represents another list, `NULL' is returned.
+ *Note:* The returned pointer is valid as long as LIST is not
+ modified or released. */
+const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number,
+ size_t *datalen);
+
+/* This function is used to get and convert data from a LIST. This
+ data is assumed to be an MPI stored in the format described by
+ MPIFMT and returned as a standard Libgcrypt MPI. The caller must
+ release this returned value using `gcry_mpi_release'. If there is
+ no data at the given index, the index represents a list or the
+ value can't be converted to an MPI, `NULL' is returned. */
+gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt);
@@ -285,157 +846,163 @@ enum gcry_mpi_flag
/* Allocate a new big integer object, initialize it with 0 and
initially allocate memory for a number of at least NBITS. */
-GcryMPI gcry_mpi_new (unsigned int nbits);
+gcry_mpi_t gcry_mpi_new (unsigned int nbits);
/* Same as gcry_mpi_new() but allocate in "secure" memory. */
-GcryMPI gcry_mpi_snew (unsigned int nbits);
+gcry_mpi_t gcry_mpi_snew (unsigned int nbits);
/* Release the number A and free all associated resources. */
-void gcry_mpi_release (GcryMPI a);
+void gcry_mpi_release (gcry_mpi_t a);
/* Create a new number with the same value as A. */
-GcryMPI gcry_mpi_copy (const GcryMPI a);
+gcry_mpi_t gcry_mpi_copy (const gcry_mpi_t a);
/* Store the big integer value U in W. */
-GcryMPI gcry_mpi_set (GcryMPI w, const GcryMPI u);
+gcry_mpi_t gcry_mpi_set (gcry_mpi_t w, const gcry_mpi_t u);
/* Store the unsigned integer value U in W. */
-GcryMPI gcry_mpi_set_ui (GcryMPI w, unsigned long u);
+gcry_mpi_t gcry_mpi_set_ui (gcry_mpi_t w, unsigned long u);
/* Swap the values of A and B. */
-void gcry_mpi_swap (GcryMPI a, GcryMPI b);
+void gcry_mpi_swap (gcry_mpi_t a, gcry_mpi_t b);
/* Compare the big integer number U and V returning 0 for equality, a
positive value for U > V and a negative for U < V. */
-int gcry_mpi_cmp (const GcryMPI u, const GcryMPI v);
+int gcry_mpi_cmp (const gcry_mpi_t u, const gcry_mpi_t v);
/* Compare the big integer number U with the unsigned integer V
returning 0 for equality, a positive value for U > V and a negative
for U < V. */
-int gcry_mpi_cmp_ui (const GcryMPI u, unsigned long v);
+int gcry_mpi_cmp_ui (const gcry_mpi_t u, unsigned long v);
/* Convert the external representation of an integer stored in BUFFER
with a size of (*NBYTES) in a newly create MPI returned in RET_MPI.
For certain formats a length is not required and may be passed as
NULL. After a successful operation NBYTES received the number of
bytes actually scanned. */
-int gcry_mpi_scan (GcryMPI *ret_mpi, enum gcry_mpi_format format,
+gpg_error_t gcry_mpi_scan (gcry_mpi_t *ret_mpi, enum gcry_mpi_format format,
const char *buffer, size_t *nbytes);
/* Convert the big integer A into the external representation
described by FORMAT and store it in the provided BUFFER which has
the size (*NBYTES). NBYTES receives the actual length of the
external representation. */
-int gcry_mpi_print (enum gcry_mpi_format format,
- char *buffer, size_t *nbytes, const GcryMPI a);
+gpg_error_t gcry_mpi_print (enum gcry_mpi_format format,
+ char *buffer, size_t *nbytes, const gcry_mpi_t a);
/* Convert the big integer A int the external representation desribed
by FORMAT and store it in a newly allocated buffer which address
will be put into BUFFER. NBYTES receives the actual lengths of the
external representation. */
-int gcry_mpi_aprint (enum gcry_mpi_format format,
- void **buffer, size_t *nbytes, const GcryMPI a);
+gpg_error_t gcry_mpi_aprint (enum gcry_mpi_format format,
+ void **buffer, size_t *nbytes, const gcry_mpi_t a);
/* W = U + V. */
-void gcry_mpi_add (GcryMPI w, GcryMPI u, GcryMPI v);
+void gcry_mpi_add (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
/* W = U + V. V is an unsigned integer. */
-void gcry_mpi_add_ui (GcryMPI w, GcryMPI u, unsigned long v);
+void gcry_mpi_add_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v);
/* W = U + V mod M. */
-void gcry_mpi_addm (GcryMPI w, GcryMPI u, GcryMPI v, GcryMPI m);
+void gcry_mpi_addm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
/* W = U - V. */
-void gcry_mpi_sub (GcryMPI w, GcryMPI u, GcryMPI v);
+void gcry_mpi_sub (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
/* W = U - V. V is an unsigned integer. */
-void gcry_mpi_sub_ui (GcryMPI w, GcryMPI u, unsigned long v );
+void gcry_mpi_sub_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
/* W = U - V mod M */
-void gcry_mpi_subm (GcryMPI w, GcryMPI u, GcryMPI v, GcryMPI m);
+void gcry_mpi_subm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
/* W = U * V. */
-void gcry_mpi_mul (GcryMPI w, GcryMPI u, GcryMPI v);
+void gcry_mpi_mul (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v);
/* W = U * V. V is an unsigned integer. */
-void gcry_mpi_mul_ui (GcryMPI w, GcryMPI u, unsigned long v );
+void gcry_mpi_mul_ui (gcry_mpi_t w, gcry_mpi_t u, unsigned long v );
/* W = U * V mod M. */
-void gcry_mpi_mulm (GcryMPI w, GcryMPI u, GcryMPI v, GcryMPI m);
+void gcry_mpi_mulm (gcry_mpi_t w, gcry_mpi_t u, gcry_mpi_t v, gcry_mpi_t m);
/* W = U * (2 ^ CNT). */
-void gcry_mpi_mul_2exp (GcryMPI w, GcryMPI u, unsigned long cnt);
+void gcry_mpi_mul_2exp (gcry_mpi_t w, gcry_mpi_t u, unsigned long cnt);
/* Q = DIVIDEND / DIVISOR, R = DIVIDEND % DIVISOR,
Q or R may be passed as NULL. ROUND should be negative or 0. */
-void gcry_mpi_div (GcryMPI q, GcryMPI r,
- GcryMPI dividend, GcryMPI divisor, int round);
+void gcry_mpi_div (gcry_mpi_t q, gcry_mpi_t r,
+ gcry_mpi_t dividend, gcry_mpi_t divisor, int round);
/* R = DIVIDEND % DIVISOR */
-void gcry_mpi_mod (GcryMPI r, GcryMPI dividend, GcryMPI divisor);
+void gcry_mpi_mod (gcry_mpi_t r, gcry_mpi_t dividend, gcry_mpi_t divisor);
/* W = B ^ E mod M. */
-void gcry_mpi_powm (GcryMPI w,
- const GcryMPI b, const GcryMPI e, const GcryMPI m);
+void gcry_mpi_powm (gcry_mpi_t w,
+ const gcry_mpi_t b, const gcry_mpi_t e, const gcry_mpi_t m);
/* Set G to the greatest common divisor of A and B.
Return true if the G is 1. */
-int gcry_mpi_gcd (GcryMPI g, GcryMPI a, GcryMPI b);
+int gcry_mpi_gcd (gcry_mpi_t g, gcry_mpi_t a, gcry_mpi_t b);
/* Set X to the multiplicative inverse of A mod M.
Return true if the value exists. */
-int gcry_mpi_invm (GcryMPI x, GcryMPI a, GcryMPI m);
+int gcry_mpi_invm (gcry_mpi_t x, gcry_mpi_t a, gcry_mpi_t m);
/* Return the number of bits required to represent A. */
-unsigned int gcry_mpi_get_nbits (GcryMPI a);
+unsigned int gcry_mpi_get_nbits (gcry_mpi_t a);
/* Return true when bit number N (counting from 0) is set in A. */
-int gcry_mpi_test_bit (GcryMPI a, unsigned int n);
+int gcry_mpi_test_bit (gcry_mpi_t a, unsigned int n);
/* Set bit number N in A. */
-void gcry_mpi_set_bit (GcryMPI a, unsigned int n);
+void gcry_mpi_set_bit (gcry_mpi_t a, unsigned int n);
/* Clear bit number N in A. */
-void gcry_mpi_clear_bit (GcryMPI a, unsigned int n);
+void gcry_mpi_clear_bit (gcry_mpi_t a, unsigned int n);
/* Set bit number N in A and clear all bits greater than N. */
-void gcry_mpi_set_highbit (GcryMPI a, unsigned int n);
+void gcry_mpi_set_highbit (gcry_mpi_t a, unsigned int n);
/* Clear bit number N in A and all bits greater than N. */
-void gcry_mpi_clear_highbit (GcryMPI a, unsigned int n);
+void gcry_mpi_clear_highbit (gcry_mpi_t a, unsigned int n);
/* Shift the value of A by N bits to the right and store the result in X. */
-void gcry_mpi_rshift (GcryMPI x, GcryMPI a, unsigned int n);
+void gcry_mpi_rshift (gcry_mpi_t x, gcry_mpi_t a, unsigned int n);
/* Store NBITS of the value P points to in A and mark A as an opaque
value. */
-GcryMPI gcry_mpi_set_opaque (GcryMPI a, void *p, unsigned int nbits);
+gcry_mpi_t gcry_mpi_set_opaque (gcry_mpi_t a, void *p, unsigned int nbits);
/* Return a pointer to an opaque value stored in A and return its size
in NBITS. Note that the returned pointer is still owned by A and
that the function should never be used for an non-opaque MPI. */
-void *gcry_mpi_get_opaque (GcryMPI a, unsigned int *nbits);
+void *gcry_mpi_get_opaque (gcry_mpi_t a, unsigned int *nbits);
/* Set the FLAG for the big integer A. Currently only the flag
GCRYMPI_FLAG_SECURE is allowed to convert A into an big intger
stored in "secure" memory. */
-void gcry_mpi_set_flag (GcryMPI a, enum gcry_mpi_flag flag);
+void gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
/* Clear FLAG for the big integer A. Note that this function is
currently useless as no flags are allowed. */
-void gcry_mpi_clear_flag (GcryMPI a, enum gcry_mpi_flag flag);
+void gcry_mpi_clear_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
/* Return true when the FLAG is set for A. */
-int gcry_mpi_get_flag (GcryMPI a, enum gcry_mpi_flag flag);
+int gcry_mpi_get_flag (gcry_mpi_t a, enum gcry_mpi_flag flag);
/* Unless the GCRYPT_NO_MPI_MACROS is used, provide a couple of
convenience macors for the big integer functions. */
#ifndef GCRYPT_NO_MPI_MACROS
#define mpi_new(n) gcry_mpi_new( (n) )
#define mpi_secure_new( n ) gcry_mpi_snew( (n) )
-#define mpi_release( a ) do { gcry_mpi_release( (a) ); \
- (a) = NULL; } while(0)
+#define mpi_release(a) \
+ do \
+ { \
+ gcry_mpi_release ((a)); \
+ (a) = NULL; \
+ } \
+ while (0)
+
#define mpi_copy( a ) gcry_mpi_copy( (a) )
#define mpi_set( w, u) gcry_mpi_set( (w), (u) )
#define mpi_set_ui( w, u) gcry_mpi_set_ui( (w), (u) )
@@ -479,11 +1046,12 @@ int gcry_mpi_get_flag (GcryMPI a, enum gcry_mpi_flag flag);
* *
************************************/
-/* The data object used to hold a handle to an encryption object.
- GcryCipherHd is the preferred one. */
+/* The data object used to hold a handle to an encryption object. */
struct gcry_cipher_handle;
-typedef struct gcry_cipher_handle *GCRY_CIPHER_HD;
-typedef struct gcry_cipher_handle *GcryCipherHd;
+typedef struct gcry_cipher_handle *gcry_cipher_hd_t;
+
+typedef struct gcry_cipher_handle *GCRY_CIPHER_HD _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_cipher_handle *GcryCipherHd _GCRY_GCC_ATTR_DEPRECATED;
/* All symmetric encryption algorithms are identified by their IDs.
More IDs may be registered at runtime. */
@@ -500,12 +1068,13 @@ enum gcry_cipher_algos
GCRY_CIPHER_AES192 = 8,
GCRY_CIPHER_AES256 = 9,
GCRY_CIPHER_TWOFISH = 10,
- GCRY_CIPHER_SERPENT128 = 11,
- GCRY_CIPHER_SERPENT192 = 12,
- GCRY_CIPHER_SERPENT256 = 13,
+
/* other cipher numbers are above 300 for OpenPGP reasons. */
GCRY_CIPHER_ARCFOUR = 301, /* fully compatible with RSA's RC4 (tm). */
- GCRY_CIPHER_DES = 302 /* Yes, this is single key 56 bit DES. */
+ GCRY_CIPHER_DES = 302, /* Yes, this is single key 56 bit DES. */
+ GCRY_CIPHER_SERPENT128 = 303,
+ GCRY_CIPHER_SERPENT192 = 304,
+ GCRY_CIPHER_SERPENT256 = 305,
};
/* The Rijndael algorithm is basically AES, so provide some macros. */
@@ -540,19 +1109,23 @@ enum gcry_cipher_flags
/* Create a handle for algorithm ALGO to be used in MODE. FLAGS may
be given as an bitwise OR of the gcry_cipher_flags values. */
-GcryCipherHd gcry_cipher_open (int algo, int mode, unsigned int flags);
+gpg_error_t gcry_cipher_open (gcry_cipher_hd_t *handle,
+ int algo, int mode, unsigned int flags);
/* Close the cioher handle H and release all resource. */
-void gcry_cipher_close (GcryCipherHd h);
+void gcry_cipher_close (gcry_cipher_hd_t h);
/* Perform various operations on the cipher object H. */
-int gcry_cipher_ctl( GcryCipherHd h, int cmd, void *buffer, size_t buflen);
+gpg_error_t gcry_cipher_ctl (gcry_cipher_hd_t h, int cmd, void *buffer,
+ size_t buflen);
/* Retrieve various information about the cipher object H. */
-int gcry_cipher_info( GcryCipherHd h, int what, void *buffer, size_t *nbytes);
+gpg_error_t gcry_cipher_info (gcry_cipher_hd_t h, int what, void *buffer,
+ size_t *nbytes);
/* Retrieve various information about the cipher algorithm ALGO. */
-int gcry_cipher_algo_info (int algo, int what, void *buffer, size_t *nbytes);
+gpg_error_t gcry_cipher_algo_info (int algo, int what, void *buffer,
+ size_t *nbytes);
/* Map the cipher algorithm id ALGO to a string representation of that
algorithm name. For unknown algorithms this functions returns an
@@ -571,15 +1144,15 @@ int gcry_cipher_mode_from_oid (const char *string) _GCRY_GCC_ATTR_PURE;
/* Encrypt the plaintext of size INLEN in IN using the cipher handle H
into the buffer OUT which has an allocated length of OUTSIZE. For
most algorithms it is possible to pass NULL for in and 0 for INLEN
- and do a in-place decryption of the data provided in OUT. */
-int gcry_cipher_encrypt (GcryCipherHd h,
- unsigned char *out, size_t outsize,
- const unsigned char *in, size_t inlen);
+ and do a in-place decryption of the data provided in OUT. */
+gpg_error_t gcry_cipher_encrypt (gcry_cipher_hd_t h,
+ unsigned char *out, size_t outsize,
+ const unsigned char *in, size_t inlen);
-/* The counterpart to gcry_cipher_encrypt. */
-int gcry_cipher_decrypt (GcryCipherHd h,
- unsigned char *out, size_t outsize,
- const unsigned char *in, size_t inlen);
+/* The counterpart to gcry_cipher_encrypt. */
+gpg_error_t gcry_cipher_decrypt (gcry_cipher_hd_t h,
+ unsigned char *out, size_t outsize,
+ const unsigned char *in, size_t inlen);
/* Set key K of length L for the cipher handle H. (We have to cast
away a const char* here - this catch-all ctl function was probably
@@ -609,12 +1182,12 @@ int gcry_cipher_decrypt (GcryCipherHd h,
(char*)(k), (l) )
/* Retrieved the key length used with algorithm A. */
-#define gcry_cipher_get_algo_keylen(a) \
- gcry_cipher_algo_info( (a), GCRYCTL_GET_KEYLEN, NULL, NULL )
+#define gcry_cipher_get_algo_keylen(a, b) \
+ gcry_cipher_algo_info( (a), GCRYCTL_GET_KEYLEN, NULL, b)
/* Retrieve the block length used with algorithm A. */
-#define gcry_cipher_get_algo_blklen(a) \
- gcry_cipher_algo_info( (a), GCRYCTL_GET_BLKLEN, NULL, NULL )
+#define gcry_cipher_get_algo_blklen(a, b) \
+ gcry_cipher_algo_info( (a), GCRYCTL_GET_BLKLEN, NULL, b)
/* Return 0 if the algorithm A is available for use. */
#define gcry_cipher_test_algo(a) \
@@ -645,32 +1218,32 @@ enum gcry_pk_algos
/* Encrypt the DATA using the public key PKEY and store the result as
a newly created S-expression at RESULT. */
-int gcry_pk_encrypt (GcrySexp *result, GcrySexp data, GcrySexp pkey);
+gpg_error_t gcry_pk_encrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t pkey);
/* Decrypt the DATA using the private key SKEY and store the result as
a newly created S-expression at RESULT. */
-int gcry_pk_decrypt (GcrySexp *result, GcrySexp data, GcrySexp skey);
+gpg_error_t gcry_pk_decrypt (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey);
/* Sign the DATA using the private key SKEY and store the result as
a newly created S-expression at RESULT. */
-int gcry_pk_sign (GcrySexp *result, GcrySexp data, GcrySexp skey);
+gpg_error_t gcry_pk_sign (gcry_sexp_t *result, gcry_sexp_t data, gcry_sexp_t skey);
/* Check the signature SIGVAL on DATA using the public key PKEY. */
-int gcry_pk_verify (GcrySexp sigval, GcrySexp data, GcrySexp pkey);
+gpg_error_t gcry_pk_verify (gcry_sexp_t sigval, gcry_sexp_t data, gcry_sexp_t pkey);
/* Check that KEY (either private or public) is sane. */
-int gcry_pk_testkey (GcrySexp key);
+gpg_error_t gcry_pk_testkey (gcry_sexp_t key);
/* Generate a new key pair according to the parameters given in
S_PARMS. The new key pair is returned in as an S-expression in
R_KEY. */
-int gcry_pk_genkey (GcrySexp *r_key, GcrySexp s_parms);
+gpg_error_t gcry_pk_genkey (gcry_sexp_t *r_key, gcry_sexp_t s_parms);
/* Catch all function for miscellaneous operations. */
-int gcry_pk_ctl (int cmd, void *buffer, size_t buflen);
+gpg_error_t gcry_pk_ctl (int cmd, void *buffer, size_t buflen);
/* Retrieve information about the public key algorithm ALGO. */
-int gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes);
+gpg_error_t gcry_pk_algo_info (int algo, int what, void *buffer, size_t *nbytes);
/* Map the public key algorithm id ALGO to a string representation of the
algorithm name. For unknown algorithms this functions returns an
@@ -683,11 +1256,11 @@ int gcry_pk_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
/* Return what is commonly referred as the key length for the given
public or private KEY. */
-unsigned int gcry_pk_get_nbits (GcrySexp key) _GCRY_GCC_ATTR_PURE;
+unsigned int gcry_pk_get_nbits (gcry_sexp_t key) _GCRY_GCC_ATTR_PURE;
/* Please note that keygrip is still experimental and should not be
used without contacting the author. */
-unsigned char *gcry_pk_get_keygrip (GcrySexp key, unsigned char *array);
+unsigned char *gcry_pk_get_keygrip (gcry_sexp_t key, unsigned char *array);
/* Return 0 if the public key algorithm A is available for use. */
#define gcry_pk_test_algo(a) \
@@ -729,8 +1302,7 @@ enum gcry_md_flags
};
-/* This object is used to hold a handle to an message digest object.
- GcryCipherHd is the preferred type. */
+/* This object is used to hold a handle to an message digest object. */
struct gcry_md_context;
struct gcry_md_handle
{ /* This structure is private - only to be used by the gcry_md_ macros. */
@@ -739,39 +1311,42 @@ struct gcry_md_handle
int bufsize;
unsigned char buf[1];
};
-typedef struct gcry_md_handle *GCRY_MD_HD;
-typedef struct gcry_md_handle *GcryMDHd;
+typedef struct gcry_md_handle *gcry_md_hd_t;
+
+typedef struct gcry_md_handle *GCRY_MD_HD _GCRY_GCC_ATTR_DEPRECATED;
+typedef struct gcry_md_handle *GcryMDHd _GCRY_GCC_ATTR_DEPRECATED;
/* Create a message digest object for algorithm ALGO. FLAGS may be
given as an bitwise OR of the gcry_md_flags values. ALGO may be
given as 0 if the algorithms to be used are later set using
gcry_md_enable. */
-GcryMDHd gcry_md_open (int algo, unsigned int flags);
+gpg_error_t gcry_md_open (gcry_md_hd_t *h, int algo, unsigned int flags);
/* Release the message digest object HD. */
-void gcry_md_close (GcryMDHd hd);
+void gcry_md_close (gcry_md_hd_t hd);
/* Add the message digest algorithm ALGO to the digest object HD. */
-int gcry_md_enable( GcryMDHd hd, int algo );
+gpg_error_t gcry_md_enable( gcry_md_hd_t hd, int algo );
/* Create a new digest object as an exact copy of the object HD. */
-GcryMDHd gcry_md_copy (GcryMDHd hd);
+gpg_error_t gcry_md_copy (gcry_md_hd_t ahd, gcry_md_hd_t *bhd);
/* Reset the digest object HD to its initial state. */
-void gcry_md_reset (GcryMDHd hd);
+void gcry_md_reset (gcry_md_hd_t hd);
/* Perform various operations on the digets object HD. */
-int gcry_md_ctl (GcryMDHd hd, int cmd, unsigned char *buffer, size_t buflen);
+gpg_error_t gcry_md_ctl (gcry_md_hd_t hd, int cmd, unsigned char *buffer,
+ size_t buflen);
/* Pass LENGTH bytes of data in BUFFER to the digest object HD so that
it can update the digest values. This is the actual hash
function. */
-void gcry_md_write (GcryMDHd hd, const void *buffer, size_t length);
+void gcry_md_write (gcry_md_hd_t hd, const void *buffer, size_t length);
/* Read out the final digest from HD return the digest value for
algorithm ALGO. */
-unsigned char *gcry_md_read (GcryMDHd hd, int algo);
+unsigned char *gcry_md_read (gcry_md_hd_t hd, int algo);
/* Convenience function to calculate the hash from the data in BUFFER
of size LENGTH using the algorithm ALGO avoiding the creating of a
@@ -783,17 +1358,19 @@ void gcry_md_hash_buffer (int algo, void *digest,
/* Retrieve the algorithm used with HD. This does not work reliable
if more than one algorithm is enabled in HD. */
-int gcry_md_get_algo (GcryMDHd hd);
+gpg_error_t gcry_md_get_algo (gcry_md_hd_t hd, int *algo);
/* Retrieve the length in bytes of the digest yielded by algorithm
ALGO. */
unsigned int gcry_md_get_algo_dlen (int algo);
-/* Retrieve various information about the object H. */
-int gcry_md_info (GcryMDHd h, int what, void *buffer, size_t *nbytes);
+/* Retrieve various information about the object H. */
+gpg_error_t gcry_md_info (gcry_md_hd_t h, int what, void *buffer,
+ size_t *nbytes);
-/* Retrieve various information about the algorithm ALGO. */
-int gcry_md_algo_info( int algo, int what, void *buffer, size_t *nbytes);
+/* Retrieve various information about the algorithm ALGO. */
+gpg_error_t gcry_md_algo_info (int algo, int what, void *buffer,
+ size_t *nbytes);
/* Map the digest algorithm id ALGO to a string representation of the
algorithm name. For unknown algorithms this functions returns an
@@ -806,13 +1383,13 @@ int gcry_md_map_name (const char* name) _GCRY_GCC_ATTR_PURE;
/* For use with the HMAC feature, the set MAC key to the KEY of
KEYLEN. */
-int gcry_md_setkey (GcryMDHd hd, const void *key, size_t keylen);
+gpg_error_t gcry_md_setkey (gcry_md_hd_t hd, const void *key, size_t keylen);
/* Update the hash(s) of H with the character C. This is a buffered
version of the gcry_md_write function. */
#define gcry_md_putc(h,c) \
do { \
- GcryMDHd h__ = (h); \
+ gcry_md_hd_t h__ = (h); \
if( (h__)->bufpos == (h__)->bufsize ) \
gcry_md_write( (h__), NULL, 0 ); \
(h__)->buf[(h__)->bufpos++] = (c) & 0xff; \
@@ -824,8 +1401,8 @@ int gcry_md_setkey (GcryMDHd hd, const void *key, size_t keylen);
gcry_md_ctl ((a), GCRYCTL_FINALIZE, NULL, 0)
/* Return true when the digest object is allocated in "secure" memory. */
-#define gcry_md_is_secure(a) \
- gcry_md_info( (a), GCRYCTL_IS_SECURE, NULL, NULL )
+#define gcry_md_is_secure(a, b) \
+ gcry_md_info ((a), GCRYCTL_IS_SECURE, NULL, (b))
/* Return 0 if the algorithm A is available for use. */
#define gcry_md_test_algo(a) \
@@ -876,7 +1453,8 @@ void gcry_randomize (unsigned char *buffer, size_t length,
/* Add the external random from BUFFER with LENGTH bytes into the
pool. QUALITY should either be -1 for unknown or in the range of 0
to 100 */
-int gcry_random_add_bytes (const void *buffer, size_t length, int quality);
+gpg_error_t gcry_random_add_bytes (const void *buffer, size_t length,
+ int quality);
/* Return NBYTES of allocated random using a random numbers of quality
LEVEL. */
@@ -892,7 +1470,7 @@ void *gcry_random_bytes_secure (size_t nbytes, enum gcry_random_level level)
/* Set the big inetger W to a random value of NBITS using a random
generator with quality LEVEL. */
-void gcry_mpi_randomize (GcryMPI w,
+void gcry_mpi_randomize (gcry_mpi_t w,
unsigned int nbits, enum gcry_random_level level);
@@ -968,13 +1546,19 @@ void gcry_free (void *a);
/* Return true if A is allocated in "secure" memory. */
int gcry_is_secure (const void *a) _GCRY_GCC_ATTR_PURE;
+#if 0
+/* FIXME. */
#ifndef GCRYPT_NO_MPI_MACROS
-# ifndef DID_MPI_TYPEDEF
+#ifndef DID_MPI_TYPEDEF
typedef struct gcry_mpi *MPI;
-# define DID_MPI_TYPEDEF
-# endif
+#define DID_MPI_TYPEDEF
+#endif
#endif /* GCRYPT_NO_MPI_MACROS */
+#endif
+#if 0 /* keep Emacsens's auto-indent happy */
+{
+#endif
#ifdef __cplusplus
}
#endif
diff --git a/src/global.c b/src/global.c
index 005e9d0a..7842c36a 100644
--- a/src/global.c
+++ b/src/global.c
@@ -39,7 +39,6 @@
* 1 : general MPI debug
*/
static unsigned int debug_flags;
-static int last_ec; /* fixme: make thread safe */
static void *(*alloc_func)(size_t n) = NULL;
static void *(*alloc_secure_func)(size_t n) = NULL;
@@ -136,146 +135,142 @@ gcry_check_version( const char *req_version )
return NULL;
}
-
-int
-gcry_control( enum gcry_ctl_cmds cmd, ... )
+gpg_error_t
+gcry_control (enum gcry_ctl_cmds cmd, ...)
{
- static int init_finished = 0;
- va_list arg_ptr ;
-
- va_start( arg_ptr, cmd ) ;
- switch( cmd ) {
+ gpg_err_code_t err = GPG_ERR_NO_ERROR;
+ static int init_finished = 0;
+ va_list arg_ptr;
+
+ va_start (arg_ptr, cmd);
+ switch (cmd)
+ {
#if 0
- case GCRYCTL_NO_MEM_IS_FATAL:
- break;
- case GCRYCTL_SET_FATAL_FNC:
- break;
+ case GCRYCTL_NO_MEM_IS_FATAL:
+ break;
+ case GCRYCTL_SET_FATAL_FNC:
+ break;
#endif
- case GCRYCTL_ENABLE_M_GUARD:
- _gcry_private_enable_m_guard();
- break;
-
- case GCRYCTL_ENABLE_QUICK_RANDOM:
- _gcry_quick_random_gen (1);
- break;
-
- case GCRYCTL_DUMP_RANDOM_STATS:
- _gcry_random_dump_stats();
- break;
-
- case GCRYCTL_DUMP_MEMORY_STATS:
- /*m_print_stats("[fixme: prefix]");*/
- break;
-
- case GCRYCTL_DUMP_SECMEM_STATS:
- _gcry_secmem_dump_stats();
- break;
-
- case GCRYCTL_DROP_PRIVS:
- global_init ();
- _gcry_secmem_init( 0 );
- break;
-
- case GCRYCTL_DISABLE_SECMEM:
- global_init ();
- no_secure_memory = 1;
- break;
-
- case GCRYCTL_INIT_SECMEM:
- global_init ();
- _gcry_secmem_init( va_arg( arg_ptr, unsigned int ) );
- break;
-
- case GCRYCTL_TERM_SECMEM:
- global_init ();
- _gcry_secmem_term();
- break;
-
- case GCRYCTL_DISABLE_SECMEM_WARN:
- _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
- | GCRY_SECMEM_FLAG_NO_WARNING));
- break;
-
- case GCRYCTL_SUSPEND_SECMEM_WARN:
- _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
- | GCRY_SECMEM_FLAG_SUSPEND_WARNING));
- break;
-
- case GCRYCTL_RESUME_SECMEM_WARN:
- _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
- & ~GCRY_SECMEM_FLAG_SUSPEND_WARNING));
- break;
-
- case GCRYCTL_USE_SECURE_RNDPOOL:
- global_init ();
- _gcry_secure_random_alloc(); /* put random number into secure memory */
- break;
-
- case GCRYCTL_SET_VERBOSITY:
- _gcry_set_log_verbosity( va_arg( arg_ptr, int ) );
- break;
-
- case GCRYCTL_SET_DEBUG_FLAGS:
- debug_flags |= va_arg( arg_ptr, unsigned int );
- break;
-
- case GCRYCTL_CLEAR_DEBUG_FLAGS:
- debug_flags &= ~va_arg( arg_ptr, unsigned int );
- break;
-
- case GCRYCTL_DISABLE_INTERNAL_LOCKING:
- global_init ();
- /* We waste some bytes by doing it this way. OTOH this
- function is not anymore required becuase it is done
- automagically. */
- ath_deinit ();
- break;
-
- case GCRYCTL_ANY_INITIALIZATION_P:
- va_end(arg_ptr);
- return any_init_done? 1 : 0;
-
- case GCRYCTL_INITIALIZATION_FINISHED_P:
- va_end(arg_ptr);
- return init_finished? 1 : 0;
-
- case GCRYCTL_INITIALIZATION_FINISHED:
- /* This is a hook which should be used by an application after
- all initialization has been done and right before any
- threads are started. It is not really needed but the only
- way to be really sure that all initialization for
- thread-safety has been done. */
- if (!init_finished) {
+ case GCRYCTL_ENABLE_M_GUARD:
+ _gcry_private_enable_m_guard ();
+ break;
+
+ case GCRYCTL_ENABLE_QUICK_RANDOM:
+ _gcry_quick_random_gen (1);
+ break;
+
+ case GCRYCTL_DUMP_RANDOM_STATS:
+ _gcry_random_dump_stats ();
+ break;
+
+ case GCRYCTL_DUMP_MEMORY_STATS:
+ /*m_print_stats("[fixme: prefix]");*/
+ break;
+
+ case GCRYCTL_DUMP_SECMEM_STATS:
+ _gcry_secmem_dump_stats ();
+ break;
+
+ case GCRYCTL_DROP_PRIVS:
+ global_init ();
+ _gcry_secmem_init (0);
+ break;
+
+ case GCRYCTL_DISABLE_SECMEM:
+ global_init ();
+ no_secure_memory = 1;
+ break;
+
+ case GCRYCTL_INIT_SECMEM:
+ global_init ();
+ _gcry_secmem_init (va_arg (arg_ptr, unsigned int));
+ break;
+
+ case GCRYCTL_TERM_SECMEM:
+ global_init ();
+ _gcry_secmem_term ();
+ break;
+
+ case GCRYCTL_DISABLE_SECMEM_WARN:
+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
+ | GCRY_SECMEM_FLAG_NO_WARNING));
+ break;
+
+ case GCRYCTL_SUSPEND_SECMEM_WARN:
+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
+ | GCRY_SECMEM_FLAG_SUSPEND_WARNING));
+ break;
+
+ case GCRYCTL_RESUME_SECMEM_WARN:
+ _gcry_secmem_set_flags ((_gcry_secmem_get_flags ()
+ & ~GCRY_SECMEM_FLAG_SUSPEND_WARNING));
+ break;
+
+ case GCRYCTL_USE_SECURE_RNDPOOL:
+ global_init ();
+ _gcry_secure_random_alloc (); /* put random number into secure memory */
+ break;
+
+ case GCRYCTL_SET_VERBOSITY:
+ _gcry_set_log_verbosity (va_arg (arg_ptr, int));
+ break;
+
+ case GCRYCTL_SET_DEBUG_FLAGS:
+ debug_flags |= va_arg (arg_ptr, unsigned int);
+ break;
+
+ case GCRYCTL_CLEAR_DEBUG_FLAGS:
+ debug_flags &= ~va_arg (arg_ptr, unsigned int);
+ break;
+
+ case GCRYCTL_DISABLE_INTERNAL_LOCKING:
+ global_init ();
+ /* We waste some bytes by doing it this way. OTOH this function
+ is not anymore required becuase it is done automagically. */
+ ath_deinit ();
+ break;
+
+ case GCRYCTL_ANY_INITIALIZATION_P:
+ if (any_init_done)
+ err = GPG_ERR_GENERAL;
+ break;
+
+ case GCRYCTL_INITIALIZATION_FINISHED_P:
+ if (init_finished)
+ err = GPG_ERR_GENERAL;
+ break;
+
+ case GCRYCTL_INITIALIZATION_FINISHED:
+ /* This is a hook which should be used by an application after
+ all initialization has been done and right before any threads
+ are started. It is not really needed but the only way to be
+ really sure that all initialization for thread-safety has
+ been done. */
+ if (! init_finished)
+ {
global_init ();
_gcry_random_initialize ();
init_finished = 1;
- }
+ }
break;
- default:
- va_end(arg_ptr);
- return GCRYERR_INV_OP;
+ default:
+ err = GPG_ERR_INV_OP;
}
- va_end(arg_ptr);
- return 0;
-}
-int
-gcry_errno()
-{
- return last_ec;
+ va_end(arg_ptr);
+ return gpg_error (err);
}
-const char*
-gcry_strerror( int ec )
+const char *
+gcry_strerror (gpg_error_t ec)
{
- const char *s;
- static char buf[20];
+#ifndef USE_LIBGPG_ERROR
+ const char *s;
+ static char buf[20];
- if( ec == -1 )
- ec = gcry_errno();
- #define X(n,a) case GCRYERR_##n : s = a; break;
+#define X(n,a) case GCRYERR_##n : s = a; break;
switch( ec ) {
X(SUCCESS, N_("no error"))
X(GENERAL, N_("general error"))
@@ -295,9 +290,11 @@ gcry_strerror( int ec )
X(SELFTEST, N_("selftest failed"))
X(INV_OP, N_("invalid operation code or ctl command"))
- X(NO_MEM, N_("out of core"))
X(INTERNAL, N_("internal error"))
+#if 0
+ X(NO_MEM, N_("out of core"))
X(EOF, N_("EOF"))
+#endif
X(INV_OBJ, N_("an object is not valid"))
X(TOO_SHORT, N_("provided buffer too short"))
X(TOO_LARGE, N_("object is too large"))
@@ -322,24 +319,18 @@ gcry_strerror( int ec )
X(SEXP_BAD_OCT_CHAR, N_("invalid octal character"))
default:
- sprintf( buf, "ec=%d", ec );
+ sprintf( buf, "ec=%d", (int) gpg_err_code (ec));
s = buf;
}
- #undef X
- return s;
-}
+#undef X
+ return s;
+#else
-int
-_gcry_set_lasterr( int ec )
-{
- if( ec )
- last_ec = ec == -1 ? GCRYERR_EOF : ec;
- return ec;
+ return gpg_strerror (ec);
+#endif
}
-
-
/****************
* NOTE: All 5 functions should be set. */
void
@@ -418,12 +409,12 @@ void
_gcry_check_heap( const void *a )
{
/* FIXME: implement this*/
- #if 0
+#if 0
if( some_handler )
some_handler(a)
else
_gcry_private_check_heap(a)
- #endif
+#endif
}
void *
@@ -504,7 +495,7 @@ gcry_xmalloc( size_t n )
while ( !(p = gcry_malloc( n )) ) {
if( !outofcore_handler
|| !outofcore_handler( outofcore_handler_value, n, 0 ) ) {
- _gcry_fatal_error(GCRYERR_NO_MEM, NULL );
+ _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
}
}
return p;
@@ -518,7 +509,7 @@ gcry_xrealloc( void *a, size_t n )
while ( !(p = gcry_realloc( a, n )) ) {
if( !outofcore_handler
|| !outofcore_handler( outofcore_handler_value, n, 2 ) ) {
- _gcry_fatal_error(GCRYERR_NO_MEM, NULL );
+ _gcry_fatal_error(gpg_err_code_from_errno (errno), NULL );
}
}
return p;
@@ -532,7 +523,7 @@ gcry_xmalloc_secure( size_t n )
while ( !(p = gcry_malloc_secure( n )) ) {
if( !outofcore_handler
|| !outofcore_handler( outofcore_handler_value, n, 1 ) ) {
- _gcry_fatal_error(GCRYERR_NO_MEM,
+ _gcry_fatal_error(gpg_err_code_from_errno (errno),
_("out of core in secure memory"));
}
}
diff --git a/src/missing-string.c b/src/missing-string.c
index 437d66f2..b648d292 100644
--- a/src/missing-string.c
+++ b/src/missing-string.c
@@ -1,5 +1,5 @@
/* missing-string.c - missing string utilities
- * Copyright (C) 1994, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ * Copyright (C) 1994, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
diff --git a/src/module.c b/src/module.c
index 9095f091..beabbf1b 100644
--- a/src/module.c
+++ b/src/module.c
@@ -20,20 +20,21 @@
#include <assert.h>
#include <config.h>
+#include <errno.h>
#include "g10lib.h"
/* Public function. Add a module specification to the list ENTRIES.
The new module has it's use-counter set to one. */
-int
+gpg_err_code_t
_gcry_module_add (GcryModule **entries, void *spec,
GcryModule **module)
{
+ gpg_err_code_t err = 0;
GcryModule *entry;
- int err = 0;
entry = gcry_malloc (sizeof (GcryModule));
if (! entry)
- err = GCRYERR_NO_MEM;
+ err = gpg_err_code_from_errno (errno);
else
{
/* Fill new module entry. */
diff --git a/src/mpi.h b/src/mpi.h
index 44073664..cd84b106 100644
--- a/src/mpi.h
+++ b/src/mpi.h
@@ -34,7 +34,7 @@
#include "../mpi/mpi-asm-defs.h"
#ifndef _GCRYPT_IN_LIBGCRYPT
- #error this file should only be used inside libgcrypt
+#error this file should only be used inside libgcrypt
#endif
#ifndef BITS_PER_MPI_LIMB
@@ -51,7 +51,7 @@
typedef unsigned short int mpi_limb_t;
typedef signed short int mpi_limb_signed_t;
#else
- #error BYTES_PER_MPI_LIMB does not match any C type
+#error BYTES_PER_MPI_LIMB does not match any C type
#endif
#define BITS_PER_MPI_LIMB (8*BYTES_PER_MPI_LIMB)
#endif /*BITS_PER_MPI_LIMB*/
@@ -70,7 +70,7 @@ struct gcry_mpi {
#ifndef DID_MPI_TYPEDEF
typedef struct gcry_mpi *MPI;
- #define DID_MPI_TYPEDEF
+#define DID_MPI_TYPEDEF
#endif
#define MPI_NULL NULL
@@ -81,22 +81,22 @@ struct gcry_mpi {
/*-- mpiutil.c --*/
#ifdef M_DEBUG
- #define mpi_alloc(n) _gcry_mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
- #define mpi_alloc_secure(n) _gcry_mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
- #define mpi_free(a) _gcry_mpi_debug_free((a), M_DBGINFO(__LINE__) )
- #define mpi_resize(a,b) _gcry_mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
- #define mpi_copy(a) _gcry_mpi_debug_copy((a), M_DBGINFO(__LINE__) )
+#define mpi_alloc(n) _gcry_mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
+#define mpi_alloc_secure(n) _gcry_mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
+#define mpi_free(a) _gcry_mpi_debug_free((a), M_DBGINFO(__LINE__) )
+#define mpi_resize(a,b) _gcry_mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
+#define mpi_copy(a) _gcry_mpi_debug_copy((a), M_DBGINFO(__LINE__) )
MPI _gcry_mpi_debug_alloc( unsigned nlimbs, const char *info );
MPI _gcry_mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
void _gcry_mpi_debug_free( MPI a, const char *info );
void _gcry_mpi_debug_resize( MPI a, unsigned nlimbs, const char *info );
MPI _gcry_mpi_debug_copy( MPI a, const char *info );
#else
- #define mpi_alloc(n) _gcry_mpi_alloc((n) )
- #define mpi_alloc_secure(n) _gcry_mpi_alloc_secure((n) )
- #define mpi_free(a) _gcry_mpi_free((a) )
- #define mpi_resize(a,b) _gcry_mpi_resize((a),(b))
- #define mpi_copy(a) _gcry_mpi_copy((a))
+#define mpi_alloc(n) _gcry_mpi_alloc((n) )
+#define mpi_alloc_secure(n) _gcry_mpi_alloc_secure((n) )
+#define mpi_free(a) _gcry_mpi_free((a) )
+#define mpi_resize(a,b) _gcry_mpi_resize((a),(b))
+#define mpi_copy(a) _gcry_mpi_copy((a))
MPI _gcry_mpi_alloc( unsigned nlimbs );
MPI _gcry_mpi_alloc_secure( unsigned nlimbs );
void _gcry_mpi_free( MPI a );
diff --git a/src/secmem.c b/src/secmem.c
index 516037e9..1260b370 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -28,12 +28,12 @@
#include <stddef.h>
#if defined(HAVE_MLOCK) || defined(HAVE_MMAP)
-# include <sys/mman.h>
-# include <sys/types.h>
-# include <fcntl.h>
-# ifdef USE_CAPABILITIES
-# include <sys/capability.h>
-# endif
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#ifdef USE_CAPABILITIES
+#include <sys/capability.h>
+#endif
#endif
#include "ath.h"
@@ -41,7 +41,7 @@
#include "secmem.h"
#if defined (MAP_ANON) && ! defined (MAP_ANONYMOUS)
-# define MAP_ANONYMOUS MAP_ANON
+#define MAP_ANONYMOUS MAP_ANON
#endif
#define DEFAULT_POOL_SIZE 16384
@@ -610,16 +610,18 @@ _gcry_secmem_term ()
void
_gcry_secmem_dump_stats ()
{
- memblock_t *mb;
- int i;
-
+#if 1
SECMEM_LOCK;
-#if 1
- if (pool_okay)
+ if (pool_okay)
log_info ("secmem usage: %u/%u bytes in %u blocks\n",
cur_alloced, pool_size, cur_blocks);
+ SECMEM_UNLOCK;
#else
+ memblock_t *mb;
+ int i;
+
+ SECMEM_LOCK;
for (i = 0, mb = (memblock_t *) pool;
BLOCK_VALID (mb);
@@ -628,7 +630,6 @@ _gcry_secmem_dump_stats ()
(mb->flags & MB_FLAG_ACTIVE) ? "used" : "free",
i,
mb->size);
-#endif
-
SECMEM_UNLOCK;
+#endif
}
diff --git a/src/secmem.h b/src/secmem.h
index 553b3858..54e16ba0 100644
--- a/src/secmem.h
+++ b/src/secmem.h
@@ -32,7 +32,7 @@ unsigned _gcry_secmem_get_flags(void) GCC_ATTR_PURE;
int _gcry_private_is_secure (const void *p) GCC_ATTR_PURE;
/* Flags for _gcry_secmem_{set,get}_flags. */
-#define GCRY_SECMEM_FLAG_NO_WARNING 0x00000001
-#define GCRY_SECMEM_FLAG_SUSPEND_WARNING 0x00000002
+#define GCRY_SECMEM_FLAG_NO_WARNING 1 << 0
+#define GCRY_SECMEM_FLAG_SUSPEND_WARNING 1 << 1
#endif /* G10_SECMEM_H */
diff --git a/src/sexp.c b/src/sexp.c
index 4f8d449e..f2f93f74 100644
--- a/src/sexp.c
+++ b/src/sexp.c
@@ -1,5 +1,5 @@
/* sexp.c - S-Expression handling
- * Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -34,8 +34,9 @@
typedef struct gcry_sexp *NODE;
typedef unsigned short DATALEN;
-struct gcry_sexp {
- byte d[1];
+struct gcry_sexp
+{
+ byte d[1];
};
#define ST_STOP 0
@@ -52,17 +53,14 @@ struct gcry_sexp {
#define TOKEN_SPECIALS "-./_:*+="
-#define OLDPARSECODE(a) (-((GCRYERR_SEXP_ ## a)-GCRYERR_SEXP_INV_LEN_SPEC+1))
-
-
-static int
-sexp_sscan( GCRY_SEXP *retsexp, size_t *erroff ,
- const char *buffer, size_t length, va_list arg_ptr, int argflag);
-
+static gpg_error_t
+sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *buffer, size_t length, int argflag,
+ va_list arg_ptr, void **arg_list);
#if 0
static void
-dump_mpi( GCRY_MPI a )
+dump_mpi( gcry_mpi_t a )
{
char buffer[1000];
size_t n = 1000;
@@ -105,7 +103,7 @@ dump_string (const byte *p, size_t n, int delim )
void
-gcry_sexp_dump (const GCRY_SEXP a)
+gcry_sexp_dump (const gcry_sexp_t a)
{
const byte *p;
int indent = 0;
@@ -153,8 +151,8 @@ gcry_sexp_dump (const GCRY_SEXP a)
* Pass list through except when it is an empty list - in that case
* return NULL and release the passed list.
*/
-static GCRY_SEXP
-normalize ( GCRY_SEXP list )
+static gcry_sexp_t
+normalize ( gcry_sexp_t list )
{
char *p;
if ( !list )
@@ -189,35 +187,35 @@ normalize ( GCRY_SEXP list )
This function returns 0 and and the pointer to the new object in
RETSEXP or an error code in which case RETSEXP is set to NULL. */
-int
-gcry_sexp_create (GCRY_SEXP *retsexp, void *buffer, size_t length,
+gpg_error_t
+gcry_sexp_create (gcry_sexp_t *retsexp, void *buffer, size_t length,
int autodetect, void (*freefnc)(void*) )
{
- int errcode;
- GCRY_SEXP se;
+ gpg_error_t errcode;
+ gcry_sexp_t se;
volatile va_list dummy_arg_ptr;
if (!retsexp)
- return GCRYERR_INV_ARG;
+ return gpg_error (GPG_ERR_INV_ARG);
*retsexp = NULL;
if (autodetect < 0 || autodetect > 1 || !buffer)
- return GCRYERR_INV_ARG;
+ return gpg_error (GPG_ERR_INV_ARG);
if (!length && !autodetect)
{ /* What a brave caller to assume that there is really a canonical
encoded S-expression in buffer */
length = gcry_sexp_canon_len (buffer, 0, NULL, &errcode);
if (!length)
- return 200 - errcode;
+ return errcode;
}
else if (!length && autodetect)
{ /* buffer is a string */
length = strlen ((char *)buffer);
}
- errcode = sexp_sscan (&se, NULL, buffer, length, dummy_arg_ptr, 0);
+ errcode = sexp_sscan (&se, NULL, buffer, length, 0, dummy_arg_ptr, NULL);
if (errcode)
- return 200 - errcode;
+ return errcode;
*retsexp = se;
if (freefnc)
@@ -229,12 +227,12 @@ gcry_sexp_create (GCRY_SEXP *retsexp, void *buffer, size_t length,
GCRYSEXP object and use the BUFFER directly */
freefnc (buffer);
}
- return 0;
+ return gpg_error (GPG_ERR_NO_ERROR);
}
/* Same as gcry_sexp_create but don't transfer ownership */
-int
-gcry_sexp_new (GCRY_SEXP *retsexp, const void *buffer, size_t length,
+gpg_error_t
+gcry_sexp_new (gcry_sexp_t *retsexp, const void *buffer, size_t length,
int autodetect)
{
return gcry_sexp_create (retsexp, (void *)buffer, length, autodetect, NULL);
@@ -245,7 +243,7 @@ gcry_sexp_new (GCRY_SEXP *retsexp, const void *buffer, size_t length,
* Release resource of the given SEXP object.
*/
void
-gcry_sexp_release( GCRY_SEXP sexp )
+gcry_sexp_release( gcry_sexp_t sexp )
{
gcry_free ( sexp );
}
@@ -256,8 +254,8 @@ gcry_sexp_release( GCRY_SEXP sexp )
* Special behaviour: If one is a single element list we put the
* element straight into the new pair.
*/
-GCRY_SEXP
-gcry_sexp_cons( const GCRY_SEXP a, const GCRY_SEXP b )
+gcry_sexp_t
+gcry_sexp_cons( const gcry_sexp_t a, const gcry_sexp_t b )
{
/* NYI: Implementation should be quite easy with our new data representation */
BUG ();
@@ -269,8 +267,8 @@ gcry_sexp_cons( const GCRY_SEXP a, const GCRY_SEXP b )
* Make a list from all items in the array the end of the array is marked
* with a NULL. y a NULL
*/
-GCRY_SEXP
-gcry_sexp_alist( const GCRY_SEXP *array )
+gcry_sexp_t
+gcry_sexp_alist( const gcry_sexp_t *array )
{
/* NYI: Implementaion should be quite easy with our new data representation */
BUG ();
@@ -280,8 +278,8 @@ gcry_sexp_alist( const GCRY_SEXP *array )
/****************
* Make a list from all items, the end of list is indicated by a NULL
*/
-GCRY_SEXP
-gcry_sexp_vlist( const GCRY_SEXP a, ... )
+gcry_sexp_t
+gcry_sexp_vlist( const gcry_sexp_t a, ... )
{
/* NYI: Implementaion should be quite easy with our new data representation */
BUG ();
@@ -293,16 +291,16 @@ gcry_sexp_vlist( const GCRY_SEXP a, ... )
* Append n to the list a
* Returns: a new ist (which maybe a)
*/
-GCRY_SEXP
-gcry_sexp_append( const GCRY_SEXP a, const GCRY_SEXP n )
+gcry_sexp_t
+gcry_sexp_append( const gcry_sexp_t a, const gcry_sexp_t n )
{
/* NYI: Implementaion should be quite easy with our new data representation */
BUG ();
return NULL;
}
-GCRY_SEXP
-gcry_sexp_prepend( const GCRY_SEXP a, const GCRY_SEXP n )
+gcry_sexp_t
+gcry_sexp_prepend( const gcry_sexp_t a, const gcry_sexp_t n )
{
/* NYI: Implementaion should be quite easy with our new data representation */
BUG ();
@@ -315,8 +313,8 @@ gcry_sexp_prepend( const GCRY_SEXP a, const GCRY_SEXP n )
* Locate token in a list. The token must be the car of a sublist.
* Returns: A new list with this sublist or NULL if not found.
*/
-GCRY_SEXP
-gcry_sexp_find_token( const GCRY_SEXP list, const char *tok, size_t toklen )
+gcry_sexp_t
+gcry_sexp_find_token( const gcry_sexp_t list, const char *tok, size_t toklen )
{
const byte *p;
DATALEN n;
@@ -334,7 +332,7 @@ gcry_sexp_find_token( const GCRY_SEXP list, const char *tok, size_t toklen )
p += 2;
memcpy ( &n, p, sizeof n ); p += sizeof n;
if ( n == toklen && !memcmp( p, tok, toklen ) ) { /* found it */
- GCRY_SEXP newlist;
+ gcry_sexp_t newlist;
byte *d;
int level = 1;
@@ -379,7 +377,7 @@ gcry_sexp_find_token( const GCRY_SEXP list, const char *tok, size_t toklen )
* Return the length of the given list
*/
int
-gcry_sexp_length( const GCRY_SEXP list )
+gcry_sexp_length( const gcry_sexp_t list )
{
const byte *p;
DATALEN n;
@@ -416,12 +414,12 @@ gcry_sexp_length( const GCRY_SEXP list )
/****************
* Extract the CAR of the given list
*/
-GCRY_SEXP
-gcry_sexp_nth( const GCRY_SEXP list, int number )
+gcry_sexp_t
+gcry_sexp_nth( const gcry_sexp_t list, int number )
{
const byte *p;
DATALEN n;
- GCRY_SEXP newlist;
+ gcry_sexp_t newlist;
byte *d;
int level = 0;
@@ -493,8 +491,8 @@ gcry_sexp_nth( const GCRY_SEXP list, int number )
return normalize (newlist);
}
-GCRY_SEXP
-gcry_sexp_car( const GCRY_SEXP list )
+gcry_sexp_t
+gcry_sexp_car( const gcry_sexp_t list )
{
return gcry_sexp_nth ( list, 0 );
}
@@ -504,7 +502,7 @@ gcry_sexp_car( const GCRY_SEXP list )
* is not modified.
*/
const char *
-gcry_sexp_nth_data( const GCRY_SEXP list, int number, size_t *datalen )
+gcry_sexp_nth_data( const gcry_sexp_t list, int number, size_t *datalen )
{
const byte *p;
DATALEN n;
@@ -556,8 +554,8 @@ gcry_sexp_nth_data( const GCRY_SEXP list, int number, size_t *datalen )
/****************
* Get a MPI from the car
*/
-GCRY_MPI
-gcry_sexp_nth_mpi( GCRY_SEXP list, int number, int mpifmt )
+gcry_mpi_t
+gcry_sexp_nth_mpi( gcry_sexp_t list, int number, int mpifmt )
{
const byte *p;
DATALEN n;
@@ -615,13 +613,13 @@ gcry_sexp_nth_mpi( GCRY_SEXP list, int number, int mpifmt )
/****************
* Get the CDR
*/
-GCRY_SEXP
-gcry_sexp_cdr( const GCRY_SEXP list )
+gcry_sexp_t
+gcry_sexp_cdr( const gcry_sexp_t list )
{
const byte *p;
const byte *head;
DATALEN n;
- GCRY_SEXP newlist;
+ gcry_sexp_t newlist;
byte *d;
int level = 0;
int skip = 1;
@@ -684,10 +682,10 @@ gcry_sexp_cdr( const GCRY_SEXP list )
return normalize (newlist);
}
-GCRY_SEXP
-gcry_sexp_cadr ( const GCRY_SEXP list )
+gcry_sexp_t
+gcry_sexp_cadr ( const gcry_sexp_t list )
{
- GCRY_SEXP a, b;
+ gcry_sexp_t a, b;
a = gcry_sexp_cdr ( list );
b = gcry_sexp_car ( a );
@@ -721,7 +719,7 @@ hextobyte( const byte *s )
}
struct make_space_ctx {
- GCRY_SEXP sexp;
+ gcry_sexp_t sexp;
size_t allocated;
byte *pos;
};
@@ -732,7 +730,7 @@ make_space ( struct make_space_ctx *c, size_t n )
size_t used = c->pos - c->sexp->d;
if ( used + n + sizeof(DATALEN) + 1 >= c->allocated ) {
- GCRY_SEXP newsexp;
+ gcry_sexp_t newsexp;
byte *newhead;
c->allocated += 2*(n+sizeof(DATALEN)+1);
@@ -835,347 +833,393 @@ unquote_string (const unsigned char *string, size_t length, unsigned char *buf)
* common operation gcry_sexp_cdr_mpi() will always return a secure MPI
* regardless whether it is needed or not.
*/
-static int
-sexp_sscan( GCRY_SEXP *retsexp, size_t *erroff ,
- const char *buffer, size_t length, va_list arg_ptr, int argflag )
+static gpg_error_t
+sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *buffer, size_t length, int argflag,
+ va_list arg_ptr, void **arg_list)
{
- static const char tokenchars[] = "abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "0123456789-./_:*+=";
- const char *p;
- size_t n;
- const char *digptr=NULL;
- const char *quoted=NULL;
- const char *tokenp=NULL;
- const char *hexfmt=NULL;
- const char *base64=NULL;
- const char *disphint=NULL;
- const char *percent=NULL;
- int hexcount=0;
- int quoted_esc=0;
- int datalen=0;
- size_t dummy_erroff;
-
- struct make_space_ctx c;
-
- if( !erroff )
- erroff = &dummy_erroff;
-
- /* FIXME: replace all the returns by a jump to the leave label
- * and invent better error codes. Make sure that everything is cleaned up*/
- #define MAKE_SPACE(n) do { make_space ( &c, (n) ); } while (0)
- #define STORE_LEN(p,n) do { \
+ static const char tokenchars[] = "\
+abcdefghijklmnopqrstuvwxyz\
+ABCDEFGHIJKLMNOPQRSTUVWXYZ\
+0123456789-./_:*+=";
+ const char *p;
+ size_t n;
+ const char *digptr = NULL;
+ const char *quoted = NULL;
+ const char *tokenp = NULL;
+ const char *hexfmt = NULL;
+ const char *base64 = NULL;
+ const char *disphint = NULL;
+ const char *percent = NULL;
+ int hexcount = 0;
+ int quoted_esc = 0;
+ int datalen = 0;
+ size_t dummy_erroff;
+ struct make_space_ctx c;
+ int arg_counter = 0;
+
+ if (! erroff)
+ erroff = &dummy_erroff;
+
+ /* Depending on wether ARG_LIST is non-zero or not, this macro gives
+ us the next argument, either from the variable argument list as
+ specified by ARG_PTR or from the arugment array ARG_LIST. */
+#define ARG_NEXT(storage, type) \
+ do \
+ { \
+ if (! arg_list) \
+ storage = va_arg (arg_ptr, type); \
+ else \
+ storage = *((type *) (arg_list[arg_counter++])); \
+ } \
+ while (0)
+
+ /* FIXME: replace all the returns by a jump to the leave label
+ * and invent better error codes. Make sure that everything is cleaned up*/
+#define MAKE_SPACE(n) do { make_space ( &c, (n) ); } while (0)
+#define STORE_LEN(p,n) do { \
DATALEN ashort = (n); \
memcpy ( (p), &ashort, sizeof(ashort) ); \
(p) += sizeof (ashort); \
} while (0)
- /* We assume that the internal representation takes less memory
- * than the provided one. However, we add space for one extra datalen
- * so that the code which does the ST_CLOSE can use MAKE_SPACE */
- c.allocated = length + sizeof(DATALEN);
- c.sexp = gcry_xmalloc ( sizeof *c.sexp + c.allocated - 1 );
- c.pos = c.sexp->d;
-
- for(p=buffer,n=length; n; p++, n-- ) {
- if( tokenp && !hexfmt ) {
- if( strchr( tokenchars, *p ) )
- continue;
- datalen = p - tokenp;
- MAKE_SPACE ( datalen );
- *c.pos++ = ST_DATA;
- STORE_LEN ( c.pos, datalen );
- memcpy ( c.pos, tokenp, datalen );
- c.pos += datalen;
- tokenp = NULL;
+ /* We assume that the internal representation takes less memory
+ * than the provided one. However, we add space for one extra datalen
+ * so that the code which does the ST_CLOSE can use MAKE_SPACE */
+ c.allocated = length + sizeof(DATALEN);
+ c.sexp = gcry_xmalloc ( sizeof *c.sexp + c.allocated - 1 );
+ c.pos = c.sexp->d;
+
+ for(p=buffer,n=length; n; p++, n-- ) {
+ if( tokenp && !hexfmt ) {
+ if( strchr( tokenchars, *p ) )
+ continue;
+ datalen = p - tokenp;
+ MAKE_SPACE ( datalen );
+ *c.pos++ = ST_DATA;
+ STORE_LEN ( c.pos, datalen );
+ memcpy ( c.pos, tokenp, datalen );
+ c.pos += datalen;
+ tokenp = NULL;
+ }
+ if( quoted ) {
+ if( quoted_esc ) {
+ switch( *p ) {
+ case 'b': case 't': case 'v': case 'n': case 'f':
+ case 'r': case '"': case '\'': case '\\':
+ quoted_esc = 0;
+ break;
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7':
+ if( !(n > 2 && p[1] >= '0' && p[1] <= '7'
+ && p[2] >= '0' && p[2] <= '7') ) {
+ *erroff = p - buffer;
+ /* Invalid octal value. */
+ return gpg_error (GPG_ERR_SEXP_BAD_QUOTATION);
+ }
+ p += 2; n -= 2;
+ quoted_esc = 0;
+ break;
+ case 'x':
+ if( !(n > 2 && isxdigit(p[1]) && isxdigit(p[2]) ) ) {
+ *erroff = p - buffer;
+ /* Invalid hex value. */
+ return gpg_error (GPG_ERR_SEXP_BAD_QUOTATION);
+ }
+ p += 2; n -= 2;
+ quoted_esc = 0;
+ break;
+ case '\r': /* ignore CR[,LF] */
+ if( n && p[1] == '\n' ) {
+ p++; n--;
+ }
+ quoted_esc = 0;
+ break;
+ case '\n': /* ignore LF[,CR] */
+ if( n && p[1] == '\r' ) {
+ p++; n--;
+ }
+ quoted_esc = 0;
+ break;
+ default:
+ *erroff = p - buffer;
+ /* Invalid quoted string escape. */
+ return gpg_error (GPG_ERR_SEXP_BAD_QUOTATION);
}
- if( quoted ) {
- if( quoted_esc ) {
- switch( *p ) {
- case 'b': case 't': case 'v': case 'n': case 'f':
- case 'r': case '"': case '\'': case '\\':
- quoted_esc = 0;
- break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7':
- if( !(n > 2 && p[1] >= '0' && p[1] <= '7'
- && p[2] >= '0' && p[2] <= '7') ) {
- *erroff = p - buffer;
- return -6; /* invalid octal value */
- }
- p += 2; n -= 2;
- quoted_esc = 0;
- break;
- case 'x':
- if( !(n > 2 && isxdigit(p[1]) && isxdigit(p[2]) ) ) {
- *erroff = p - buffer;
- return -6; /* invalid hex value */
- }
- p += 2; n -= 2;
- quoted_esc = 0;
- break;
- case '\r': /* ignore CR[,LF] */
- if( n && p[1] == '\n' ) {
- p++; n--;
- }
- quoted_esc = 0;
- break;
- case '\n': /* ignore LF[,CR] */
- if( n && p[1] == '\r' ) {
- p++; n--;
- }
- quoted_esc = 0;
- break;
- default:
- *erroff = p - buffer;
- return -6; /* invalid quoted string escape */
- }
- }
- else if( *p == '\\' )
- quoted_esc = 1;
- else if( *p == '\"' ) {
- /* keep it easy - we know that the unquoted string will
- never be larger */
- char *save;
- size_t len;
+ }
+ else if( *p == '\\' )
+ quoted_esc = 1;
+ else if( *p == '\"' ) {
+ /* keep it easy - we know that the unquoted string will
+ never be larger */
+ char *save;
+ size_t len;
- quoted++; /* skip leading quote */
- MAKE_SPACE (p - quoted);
- *c.pos++ = ST_DATA;
- save = c.pos;
- STORE_LEN (c.pos, 0); /* will be fixed up later */
- len = unquote_string (quoted, p - quoted, c.pos);
- c.pos += len;
- STORE_LEN (save, len);
- quoted = NULL;
- }
- }
- else if( hexfmt ) {
- if( isxdigit( *p ) )
- hexcount++;
- else if( *p == '#' ) {
- if( (hexcount & 1) ) {
- *erroff = p - buffer;
- return OLDPARSECODE (ODD_HEX_NUMBERS);
- }
-
- datalen = hexcount/2;
- MAKE_SPACE (datalen);
- *c.pos++ = ST_DATA;
- STORE_LEN (c.pos, datalen);
- for( hexfmt++; hexfmt < p; hexfmt++ ) {
- if( isspace( *hexfmt ) )
- continue;
- *c.pos++ = hextobyte( hexfmt );
- hexfmt++;
- }
- hexfmt = NULL;
- }
- else if( !isspace( *p ) ) {
- *erroff = p - buffer;
- return OLDPARSECODE (BAD_HEX_CHAR);
- }
- }
- else if( base64 ) {
- if( *p == '|' )
- base64 = NULL;
- }
- else if( digptr ) {
- if( isdigit(*p) )
- ;
- else if( *p == ':' ) {
- datalen = atoi( digptr ); /* fixme: check for overflow */
- digptr = NULL;
- if( datalen > n-1 ) {
- *erroff = p - buffer;
- return -2; /* buffer too short */
- }
- /* make a new list entry */
- MAKE_SPACE (datalen);
- *c.pos++ = ST_DATA;
- STORE_LEN (c.pos, datalen);
- memcpy (c.pos, p+1, datalen );
- c.pos += datalen;
- n -= datalen;
- p += datalen;
- }
- else if( *p == '\"' ) {
- digptr = NULL; /* we ignore the optional length */
- quoted = p;
- quoted_esc = 0;
- }
- else if( *p == '#' ) {
- digptr = NULL; /* we ignore the optional length */
- hexfmt = p;
- hexcount = 0;
- }
- else if( *p == '|' ) {
- digptr = NULL; /* we ignore the optional length */
- base64 = p;
- }
- else {
- *erroff = p - buffer;
- return -1;
- }
- }
- else if ( percent ) {
- if ( *p == 'm' ) { /* insert an MPI */
- GCRY_MPI m = va_arg (arg_ptr, GCRY_MPI);
- size_t nm = 0;
-
- if ( gcry_mpi_print( GCRYMPI_FMT_STD, NULL, &nm, m ) )
- BUG ();
-
- MAKE_SPACE (nm);
- if ( !gcry_is_secure ( c.sexp->d )
- && gcry_mpi_get_flag ( m, GCRYMPI_FLAG_SECURE ) ) {
- /* we have to switch to secure allocation */
- GCRY_SEXP newsexp;
- byte *newhead;
-
- newsexp = gcry_xmalloc_secure ( sizeof *newsexp
- + c.allocated - 1 );
- newhead = newsexp->d;
- memcpy ( newhead, c.sexp->d, (c.pos - c.sexp->d) );
- c.pos = newhead + ( c.pos - c.sexp->d );
- gcry_free ( c.sexp );
- c.sexp = newsexp;
- }
-
- *c.pos++ = ST_DATA;
- STORE_LEN (c.pos, nm);
- if ( gcry_mpi_print( GCRYMPI_FMT_STD, c.pos, &nm, m ) )
- BUG ();
- c.pos += nm;
- }
- else if ( *p == 's' ) { /* insert an string */
- const char *astr = va_arg (arg_ptr, const char *);
- size_t alen = strlen ( astr );
-
- MAKE_SPACE (alen);
- *c.pos++ = ST_DATA;
- STORE_LEN (c.pos, alen);
- memcpy ( c.pos, astr, alen );
- c.pos += alen;
- }
- else if ( *p == 'd' ) { /* insert an integer as string */
- int aint = va_arg (arg_ptr, int);
- size_t alen;
- char buf[20];
-
- sprintf ( buf, "%d", aint );
- alen = strlen ( buf );
- MAKE_SPACE (alen);
- *c.pos++ = ST_DATA;
- STORE_LEN (c.pos, alen);
- memcpy ( c.pos, buf, alen );
- c.pos += alen;
- }
- else {
- *erroff = p - buffer;
- return -1; /* invalid format specifier */
- }
- percent = NULL;
- }
- else if( *p == '(' ) {
- if( disphint ) {
- *erroff = p - buffer;
- return -9; /* open display hint */
- }
- MAKE_SPACE (0);
- *c.pos++ = ST_OPEN;
- }
- else if( *p == ')' ) { /* walk up */
- if( disphint ) {
- *erroff = p - buffer;
- return -9; /* open display hint */
- }
- MAKE_SPACE (0);
- *c.pos++ = ST_CLOSE;
- }
- else if( *p == '\"' ) {
- quoted = p;
- quoted_esc = 0;
- }
- else if( *p == '#' ) {
- hexfmt = p;
- hexcount = 0;
- }
- else if( *p == '|' )
- base64 = p;
- else if( *p == '[' ) {
- if( disphint ) {
- *erroff = p - buffer;
- return -8; /* nested display hints */
- }
- disphint = p;
- }
- else if( *p == ']' ) {
- if( !disphint ) {
- *erroff = p - buffer;
- return -9; /* unmatched display hint close */
- }
- disphint = NULL;
- }
- else if( isdigit(*p) ) {
- if( *p == '0' ) { /* a length may not begin with zero */
- *erroff = p - buffer;
- return -7;
- }
- digptr = p;
- }
- else if( strchr( tokenchars, *p ) )
- tokenp = p;
- else if( isspace(*p) )
- ;
- else if( *p == '{' ) {
- /* fixme: handle rescanning:
- * we can do this by saving our current state
- * and start over at p+1 -- Hmmm. At this point here
- * we are in a well defined state, so we don't need to save
- * it. Great.
- */
- *erroff = p - buffer;
- return -10; /* unexpected reserved punctuation */
+ quoted++; /* skip leading quote */
+ MAKE_SPACE (p - quoted);
+ *c.pos++ = ST_DATA;
+ save = c.pos;
+ STORE_LEN (c.pos, 0); /* will be fixed up later */
+ len = unquote_string (quoted, p - quoted, c.pos);
+ c.pos += len;
+ STORE_LEN (save, len);
+ quoted = NULL;
+ }
+ }
+ else if( hexfmt ) {
+ if( isxdigit( *p ) )
+ hexcount++;
+ else if( *p == '#' ) {
+ if( (hexcount & 1) ) {
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_ODD_HEX_NUMBERS);
}
- else if( strchr( "&\\", *p ) ) { /*reserved punctuation*/
- *erroff = p - buffer;
- return -10; /* unexpected reserved punctuation */
+
+ datalen = hexcount/2;
+ MAKE_SPACE (datalen);
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, datalen);
+ for( hexfmt++; hexfmt < p; hexfmt++ ) {
+ if( isspace( *hexfmt ) )
+ continue;
+ *c.pos++ = hextobyte( hexfmt );
+ hexfmt++;
}
- else if( argflag && *p == '%' ) {
- percent = p;
+ hexfmt = NULL;
+ }
+ else if( !isspace( *p ) ) {
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_BAD_HEX_CHAR);
+ }
+ }
+ else if( base64 ) {
+ if( *p == '|' )
+ base64 = NULL;
+ }
+ else if( digptr ) {
+ if( isdigit(*p) )
+ ;
+ else if( *p == ':' ) {
+ datalen = atoi( digptr ); /* fixme: check for overflow */
+ digptr = NULL;
+ if( datalen > n-1 ) {
+ *erroff = p - buffer;
+ /* Buffer too short. */
+ return gpg_error (GPG_ERR_SEXP_STRING_TOO_LONG);
}
- else { /* bad or unavailable*/
- *erroff = p - buffer;
- return -5;
+ /* make a new list entry */
+ MAKE_SPACE (datalen);
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, datalen);
+ memcpy (c.pos, p+1, datalen );
+ c.pos += datalen;
+ n -= datalen;
+ p += datalen;
+ }
+ else if( *p == '\"' ) {
+ digptr = NULL; /* we ignore the optional length */
+ quoted = p;
+ quoted_esc = 0;
+ }
+ else if( *p == '#' ) {
+ digptr = NULL; /* we ignore the optional length */
+ hexfmt = p;
+ hexcount = 0;
+ }
+ else if( *p == '|' ) {
+ digptr = NULL; /* we ignore the optional length */
+ base64 = p;
+ }
+ else {
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_INV_LEN_SPEC);
+ }
+ }
+ else if ( percent ) {
+ if ( *p == 'm' ) { /* insert an MPI */
+ gcry_mpi_t m;
+ size_t nm = 0;
+
+ ARG_NEXT (m, gcry_mpi_t);
+
+ if ( gcry_mpi_print( GCRYMPI_FMT_STD, NULL, &nm, m ) )
+ BUG ();
+
+ MAKE_SPACE (nm);
+ if ( !gcry_is_secure ( c.sexp->d )
+ && gcry_mpi_get_flag ( m, GCRYMPI_FLAG_SECURE ) ) {
+ /* we have to switch to secure allocation */
+ gcry_sexp_t newsexp;
+ byte *newhead;
+
+ newsexp = gcry_xmalloc_secure ( sizeof *newsexp
+ + c.allocated - 1 );
+ newhead = newsexp->d;
+ memcpy ( newhead, c.sexp->d, (c.pos - c.sexp->d) );
+ c.pos = newhead + ( c.pos - c.sexp->d );
+ gcry_free ( c.sexp );
+ c.sexp = newsexp;
}
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, nm);
+ if ( gcry_mpi_print( GCRYMPI_FMT_STD, c.pos, &nm, m ) )
+ BUG ();
+ c.pos += nm;
+ }
+ else if ( *p == 's' ) { /* insert an string */
+ const char *astr;
+ size_t alen;
+
+ ARG_NEXT (astr, const char *);
+ alen = strlen (astr);
+
+ MAKE_SPACE (alen);
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, alen);
+ memcpy ( c.pos, astr, alen );
+ c.pos += alen;
+ }
+ else if ( *p == 'd' ) { /* insert an integer as string */
+ int aint;
+ size_t alen;
+ char buf[20];
+
+ ARG_NEXT (aint, int);
+ sprintf ( buf, "%d", aint );
+ alen = strlen ( buf );
+ MAKE_SPACE (alen);
+ *c.pos++ = ST_DATA;
+ STORE_LEN (c.pos, alen);
+ memcpy ( c.pos, buf, alen );
+ c.pos += alen;
+ }
+ else {
+ *erroff = p - buffer;
+ /* Invalid format specifier. */
+ return gpg_error (GPG_ERR_SEXP_INV_LEN_SPEC);
+ }
+ percent = NULL;
+ }
+ else if( *p == '(' ) {
+ if( disphint ) {
+ *erroff = p - buffer;
+ /* Open display hint. */
+ return gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
+ }
+ MAKE_SPACE (0);
+ *c.pos++ = ST_OPEN;
+ }
+ else if( *p == ')' ) { /* walk up */
+ if( disphint ) {
+ *erroff = p - buffer;
+ /* Open display hint. */
+ return gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
+ }
+ MAKE_SPACE (0);
+ *c.pos++ = ST_CLOSE;
+ }
+ else if( *p == '\"' ) {
+ quoted = p;
+ quoted_esc = 0;
+ }
+ else if( *p == '#' ) {
+ hexfmt = p;
+ hexcount = 0;
+ }
+ else if( *p == '|' )
+ base64 = p;
+ else if( *p == '[' ) {
+ if( disphint ) {
+ *erroff = p - buffer;
+ /* Open display hint. */
+ return gpg_error (GPG_ERR_SEXP_NESTED_DH);
+ }
+ disphint = p;
+ }
+ else if( *p == ']' ) {
+ if( !disphint ) {
+ *erroff = p - buffer;
+ /* Open display hint. */
+ return gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
+ }
+ disphint = NULL;
+ }
+ else if( isdigit(*p) ) {
+ if( *p == '0' ) { /* a length may not begin with zero */
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_ZERO_PREFIX);
+ }
+ digptr = p;
+ }
+ else if( strchr( tokenchars, *p ) )
+ tokenp = p;
+ else if( isspace(*p) )
+ ;
+ else if( *p == '{' ) {
+ /* fixme: handle rescanning:
+ * we can do this by saving our current state
+ * and start over at p+1 -- Hmmm. At this point here
+ * we are in a well defined state, so we don't need to save
+ * it. Great.
+ */
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_UNEXPECTED_PUNC);
+ }
+ else if( strchr( "&\\", *p ) ) { /*reserved punctuation*/
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_UNEXPECTED_PUNC);
+ }
+ else if( argflag && *p == '%' ) {
+ percent = p;
+ }
+ else { /* bad or unavailable*/
+ *erroff = p - buffer;
+ return gpg_error (GPG_ERR_SEXP_BAD_CHARACTER);
}
- MAKE_SPACE (0);
- *c.pos++ = ST_STOP;
- *retsexp = normalize ( c.sexp );
- return 0;
- #undef MAKE_SPACE
- #undef STORE_LEN
+ }
+ MAKE_SPACE (0);
+ *c.pos++ = ST_STOP;
+
+ *retsexp = normalize ( c.sexp );
+ return gpg_error (GPG_ERR_NO_ERROR);
+#undef MAKE_SPACE
+#undef STORE_LEN
}
-int
-gcry_sexp_build( GCRY_SEXP *retsexp, size_t *erroff, const char *format, ... )
+gpg_error_t
+gcry_sexp_build (gcry_sexp_t *retsexp, size_t *erroff, const char *format, ...)
{
- int rc;
- va_list arg_ptr ;
+ gpg_error_t rc;
+ va_list arg_ptr;
+
+ va_start (arg_ptr, format);
+ rc = sexp_sscan (retsexp, erroff, format, strlen(format), 1,
+ arg_ptr, NULL);
+ va_end (arg_ptr);
+
+ return rc;
+}
+
+/* Like gcry_sexp_build, but uses an array instead of variable
+ function arguments. */
+gpg_error_t
+gcry_sexp_build_array (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, void **arg_list)
+{
+
+ gpg_error_t rc;
- va_start( arg_ptr, format ) ;
- rc = sexp_sscan( retsexp, erroff, format, strlen(format), arg_ptr, 1 );
- va_end(arg_ptr);
+ rc = sexp_sscan (retsexp, erroff, format, strlen(format), 1,
+ NULL, arg_list);
- return rc;
+ return rc;
}
-int
-gcry_sexp_sscan( GCRY_SEXP *retsexp, size_t *erroff,
- const char *buffer, size_t length )
+gpg_error_t
+gcry_sexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *buffer, size_t length)
{
/* We don't need the va_list because it is controlled by the
following flag, however we have to pass it but can't initialize
@@ -1183,7 +1227,8 @@ gcry_sexp_sscan( GCRY_SEXP *retsexp, size_t *erroff,
suppress the compiler warning */
volatile va_list dummy_arg_ptr;
- return sexp_sscan( retsexp, erroff, buffer, length, dummy_arg_ptr, 0 );
+ return sexp_sscan (retsexp, erroff, buffer, length, 0,
+ dummy_arg_ptr, NULL);
}
@@ -1310,7 +1355,7 @@ convert_to_token (const unsigned char *src, size_t len, unsigned char *dest)
* the required length is returned.
*/
size_t
-gcry_sexp_sprint( const GCRY_SEXP list, int mode,
+gcry_sexp_sprint( const gcry_sexp_t list, int mode,
char *buffer, size_t maxlength )
{
static byte empty[3] = { ST_OPEN, ST_CLOSE, ST_STOP };
@@ -1454,39 +1499,21 @@ gcry_sexp_sprint( const GCRY_SEXP list, int mode,
}
-
-
/* Scan a cannocial encoded buffer with implicit length values and
return the actual length this S-expression uses. For a valid S-Exp
it should never return 0. If LENGTH is not zero, the maximum
length to scan is given - this can be used for syntax checks of
data passed from outside. errorcode and erroff may both be passed as
- NULL
-
- Errorcodes (for historic reasons they are all negative):
- -1 := invalid length specification
- -2 := string too long
- -3 := unmatched parenthesis
- -4 := not a (canonical) S-expression
- -5 := bad character
- -6 := invalid hex octal value or bad quotation
- -7 := a length may not begin with zero
- -8 := nested display hints
- -9 := unmatched display hint close
- -10 := unexpected reserved punctuation
-
- Use this formula to convert the errorcodes:
- gcryerr = 200 - errcode;
- */
+ NULL. */
size_t
gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
- size_t *erroff, int *errcode)
+ size_t *erroff, gpg_error_t *errcode)
{
const unsigned char *p;
const char *disphint=NULL;
unsigned int datalen = 0;
size_t dummy_erroff;
- int dummy_errcode;
+ gpg_error_t dummy_errcode;
size_t count = 0;
int level = 0;
@@ -1495,13 +1522,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (!errcode)
errcode = &dummy_errcode;
- *errcode = 0;
+ *errcode = gpg_error (GPG_ERR_NO_ERROR);
*erroff = 0;
if (!buffer)
return 0;
if (*buffer != '(')
{
- *errcode = OLDPARSECODE (NOT_CANONICAL);
+ *errcode = gpg_error (GPG_ERR_SEXP_NOT_CANONICAL);
return 0;
}
@@ -1510,7 +1537,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (length && count >= length)
{
*erroff = count;
- *errcode = OLDPARSECODE (STRING_TOO_LONG);
+ *errcode = gpg_error (GPG_ERR_SEXP_STRING_TOO_LONG);
return 0;
}
@@ -1521,7 +1548,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (length && (count+datalen) >= length)
{
*erroff = count;
- *errcode = OLDPARSECODE (STRING_TOO_LONG);
+ *errcode = gpg_error (GPG_ERR_SEXP_STRING_TOO_LONG);
return 0;
}
count += datalen;
@@ -1533,7 +1560,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
else
{
*erroff = count;
- *errcode = OLDPARSECODE (INV_LEN_SPEC);
+ *errcode = gpg_error (GPG_ERR_SEXP_INV_LEN_SPEC);
return 0;
}
}
@@ -1542,7 +1569,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (disphint)
{
*erroff = count;
- *errcode = OLDPARSECODE (UNMATCHED_DH);
+ *errcode = gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
return 0;
}
level++;
@@ -1552,13 +1579,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (!level)
{
*erroff = count;
- *errcode = OLDPARSECODE (UNMATCHED_PAREN);
+ *errcode = gpg_error (GPG_ERR_SEXP_UNMATCHED_PAREN);
return 0;
}
if (disphint)
{
*erroff = count;
- *errcode = OLDPARSECODE (UNMATCHED_DH);
+ *errcode = gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
return 0;
}
if (!--level)
@@ -1569,7 +1596,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (disphint)
{
*erroff = count;
- *errcode = OLDPARSECODE (NESTED_DH);
+ *errcode = gpg_error (GPG_ERR_SEXP_NESTED_DH);
return 0;
}
disphint = p;
@@ -1579,7 +1606,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if( !disphint )
{
*erroff = count;
- *errcode = OLDPARSECODE (UNMATCHED_DH);
+ *errcode = gpg_error (GPG_ERR_SEXP_UNMATCHED_DH);
return 0;
}
disphint = NULL;
@@ -1589,7 +1616,7 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
if (*p == '0')
{
*erroff = count;
- *errcode = OLDPARSECODE (ZERO_PREFIX);
+ *errcode = gpg_error (GPG_ERR_SEXP_ZERO_PREFIX);
return 0;
}
datalen = atoi_1 (p);
@@ -1597,13 +1624,13 @@ gcry_sexp_canon_len (const unsigned char *buffer, size_t length,
else if (*p == '&' || *p == '\\')
{
*erroff = count;
- *errcode = OLDPARSECODE (UNEXPECTED_PUNC);
+ *errcode = gpg_error (GPG_ERR_SEXP_UNEXPECTED_PUNC);
return 0;
}
else
{
*erroff = count;
- *errcode = OLDPARSECODE (BAD_CHARACTER);
+ *errcode = gpg_error (GPG_ERR_SEXP_BAD_CHARACTER);
return 0;
}
}
diff --git a/src/stdmem.c b/src/stdmem.c
index 492f3501..659bc4ef 100644
--- a/src/stdmem.c
+++ b/src/stdmem.c
@@ -34,9 +34,9 @@
#define MAGIC_END_BYTE 0xaa
#if SIZEOF_UNSIGNED_LONG == 8
- #define EXTRA_ALIGN 4
+#define EXTRA_ALIGN 4
#else
- #define EXTRA_ALIGN 0
+#define EXTRA_ALIGN 0
#endif
diff --git a/src/testapi.c b/src/testapi.c
index 0dde34c2..5852ea69 100644
--- a/src/testapi.c
+++ b/src/testapi.c
@@ -39,8 +39,8 @@ void
test_sexp ( int argc, char **argv )
{
int rc, nbits;
- GCRY_SEXP sexp;
- GCRY_MPI key[3];
+ gcry_sexp_t sexp;
+ gcry_mpi_t key[3];
size_t n;
char *buf;
@@ -57,7 +57,7 @@ test_sexp ( int argc, char **argv )
key[0], key[1], key[2] );
fputs ( "DUMP of PK:\n", stderr );
gcry_sexp_dump ( sexp );
- { GCRY_SEXP x;
+ { gcry_sexp_t x;
x = gcry_sexp_cdr ( sexp );
fputs ( "DUMP of CDR:\n", stderr );
gcry_sexp_dump ( x );
@@ -78,7 +78,7 @@ void
test_genkey ( int argc, char **argv )
{
int rc, nbits = 1024;
- GCRY_SEXP s_parms, s_key;
+ gcry_sexp_t s_parms, s_key;
gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
rc = gcry_sexp_build ( &s_parms, NULL, "(genkey(dsa(nbits %d)))", nbits );
diff --git a/src/types.h b/src/types.h
index d603a88f..ff052f94 100644
--- a/src/types.h
+++ b/src/types.h
@@ -1,5 +1,5 @@
/* types.h - some common typedefs
- * Copyright (C) 1998, 2000, 2002 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -25,16 +25,16 @@
/* The AC_CHECK_SIZEOF() in configure fails for some machines.
* we provide some fallback values here */
#if !SIZEOF_UNSIGNED_SHORT
- #undef SIZEOF_UNSIGNED_SHORT
- #define SIZEOF_UNSIGNED_SHORT 2
+#undef SIZEOF_UNSIGNED_SHORT
+#define SIZEOF_UNSIGNED_SHORT 2
#endif
#if !SIZEOF_UNSIGNED_INT
- #undef SIZEOF_UNSIGNED_INT
- #define SIZEOF_UNSIGNED_INT 4
+#undef SIZEOF_UNSIGNED_INT
+#define SIZEOF_UNSIGNED_INT 4
#endif
#if !SIZEOF_UNSIGNED_LONG
- #undef SIZEOF_UNSIGNED_LONG
- #define SIZEOF_UNSIGNED_LONG 4
+#undef SIZEOF_UNSIGNED_LONG
+#define SIZEOF_UNSIGNED_LONG 4
#endif
@@ -42,45 +42,45 @@
#ifndef HAVE_BYTE_TYPEDEF
- #undef byte /* maybe there is a macro with this name */
+#undef byte /* maybe there is a macro with this name */
typedef unsigned char byte;
- #define HAVE_BYTE_TYPEDEF
+#define HAVE_BYTE_TYPEDEF
#endif
#ifndef HAVE_USHORT_TYPEDEF
- #undef ushort /* maybe there is a macro with this name */
+#undef ushort /* maybe there is a macro with this name */
typedef unsigned short ushort;
- #define HAVE_USHORT_TYPEDEF
+#define HAVE_USHORT_TYPEDEF
#endif
#ifndef HAVE_ULONG_TYPEDEF
- #undef ulong /* maybe there is a macro with this name */
+#undef ulong /* maybe there is a macro with this name */
typedef unsigned long ulong;
- #define HAVE_ULONG_TYPEDEF
+#define HAVE_ULONG_TYPEDEF
#endif
#ifndef HAVE_U16_TYPEDEF
- #undef u16 /* maybe there is a macro with this name */
- #if SIZEOF_UNSIGNED_INT == 2
+#undef u16 /* maybe there is a macro with this name */
+#if SIZEOF_UNSIGNED_INT == 2
typedef unsigned int u16;
- #elif SIZEOF_UNSIGNED_SHORT == 2
+#elif SIZEOF_UNSIGNED_SHORT == 2
typedef unsigned short u16;
- #else
- #error no typedef for u16
- #endif
- #define HAVE_U16_TYPEDEF
+#else
+#error no typedef for u16
+#endif
+#define HAVE_U16_TYPEDEF
#endif
#ifndef HAVE_U32_TYPEDEF
- #undef u32 /* maybe there is a macro with this name */
- #if SIZEOF_UNSIGNED_INT == 4
+#undef u32 /* maybe there is a macro with this name */
+#if SIZEOF_UNSIGNED_INT == 4
typedef unsigned int u32;
- #elif SIZEOF_UNSIGNED_LONG == 4
+#elif SIZEOF_UNSIGNED_LONG == 4
typedef unsigned long u32;
- #else
- #error no typedef for u32
- #endif
- #define HAVE_U32_TYPEDEF
+#else
+#error no typedef for u32
+#endif
+#define HAVE_U32_TYPEDEF
#endif
/****************
@@ -89,17 +89,24 @@
* Solaris and IRIX.
*/
#ifndef HAVE_U64_TYPEDEF
- #undef u64 /* maybe there is a macro with this name */
- #if SIZEOF_UNSIGNED_INT == 8
+#undef u64 /* maybe there is a macro with this name */
+#if SIZEOF_UNSIGNED_INT == 8
typedef unsigned int u64;
- #define HAVE_U64_TYPEDEF
- #elif SIZEOF_UNSIGNED_LONG == 8
+#define U64_C(c) (c ## U)
+#define HAVE_U64_TYPEDEF
+#elif SIZEOF_UNSIGNED_LONG == 8
typedef unsigned long u64;
- #define HAVE_U64_TYPEDEF
- #elif SIZEOF_UNSIGNED_LONG_LONG == 8
+#define U64_C(c) (c ## UL)
+#define HAVE_U64_TYPEDEF
+#elif SIZEOF_UNSIGNED_LONG_LONG == 8
typedef unsigned long long u64;
- #define HAVE_U64_TYPEDEF
- #endif
+#define U64_C(c) (c ## ULL)
+#define HAVE_U64_TYPEDEF
+#elif SIZEOF_UINT64_T == 8
+ typedef uint64_t u64;
+#define U64_C(c) (UINT64_C(c))
+#define HAVE_U64_TYPEDEF
+#endif
#endif
typedef union {
@@ -107,9 +114,9 @@ typedef union {
short b;
char c[1];
long d;
- #ifdef HAVE_U64_TYPEDEF
+#ifdef HAVE_U64_TYPEDEF
u64 e;
- #endif
+#endif
float f;
double g;
} PROPERLY_ALIGNED_TYPE;