summaryrefslogtreecommitdiff
path: root/plugins/MirOTR/Libgcrypt/src/g10lib.h
diff options
context:
space:
mode:
authorRené Schümann <white06tiger@gmail.com>2015-03-20 12:32:29 +0000
committerRené Schümann <white06tiger@gmail.com>2015-03-20 12:32:29 +0000
commit539705d58fc39a28388ff18c695dd406f4ffd1d9 (patch)
tree51db7a37a66c09f41734ba5573d972aae9f30d71 /plugins/MirOTR/Libgcrypt/src/g10lib.h
parent90171f125f36488dc08f5cfe0b0d4b78d995f08d (diff)
MirOTR: Libgcrypt and Libgpg-error update
Libgcrypt 1.4.6 => 1.6.3 Libgpg-error 1.9 => 1.18 git-svn-id: http://svn.miranda-ng.org/main/trunk@12449 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR/Libgcrypt/src/g10lib.h')
-rw-r--r--plugins/MirOTR/Libgcrypt/src/g10lib.h211
1 files changed, 142 insertions, 69 deletions
diff --git a/plugins/MirOTR/Libgcrypt/src/g10lib.h b/plugins/MirOTR/Libgcrypt/src/g10lib.h
index 7deb90c419..238871d0e9 100644
--- a/plugins/MirOTR/Libgcrypt/src/g10lib.h
+++ b/plugins/MirOTR/Libgcrypt/src/g10lib.h
@@ -1,6 +1,6 @@
/* g10lib.h - Internal definitions for libgcrypt
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2005
- * 2007 Free Software Foundation, Inc.
+ * 2007, 2011 Free Software Foundation, Inc.
*
* This file is part of Libgcrypt.
*
@@ -29,7 +29,7 @@
#error gcrypt.h already included
#endif
-#ifndef _GCRYPT_IN_LIBGCRYPT
+#ifndef _GCRYPT_IN_LIBGCRYPT
#error something is wrong with config.h
#endif
@@ -55,17 +55,25 @@
#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 GCC_ATTR_NORETURN
#endif
-#if __GNUC__ >= 3
+#if __GNUC__ >= 3
/* According to glibc this attribute is available since 2.8 however we
better play safe and use it only with gcc 3 or newer. */
#define GCC_ATTR_FORMAT_ARG(a) __attribute__ ((format_arg (a)))
#else
-#define GCC_ATTR_FORMAT_ARG(a)
+#define GCC_ATTR_FORMAT_ARG(a)
#endif
+/* I am not sure since when the unused attribute is really supported.
+ In any case it it only needed for gcc versions which print a
+ warning. Thus let us require gcc >= 3.5. */
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 5 )
+#define GCC_ATTR_UNUSED __attribute__ ((unused))
+#else
+#define GCC_ATTR_UNUSED
+#endif
/* Gettext macros. */
@@ -88,6 +96,36 @@ gcry_error_t _gcry_vcontrol (enum gcry_ctl_cmds cmd, va_list arg_ptr);
void _gcry_check_heap (const void *a);
int _gcry_get_debug_flag (unsigned int mask);
+/* Malloc functions and common wrapper macros. */
+void *_gcry_malloc (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_calloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_malloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_calloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_realloc (void *a, size_t n);
+char *_gcry_strdup (const char *string) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_xmalloc (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_xcalloc (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_xmalloc_secure (size_t n) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_xcalloc_secure (size_t n, size_t m) _GCRY_GCC_ATTR_MALLOC;
+void *_gcry_xrealloc (void *a, size_t n);
+char *_gcry_xstrdup (const char * a) _GCRY_GCC_ATTR_MALLOC;
+void _gcry_free (void *a);
+int _gcry_is_secure (const void *a) _GCRY_GCC_ATTR_PURE;
+
+#define xtrymalloc(a) _gcry_malloc ((a))
+#define xtrycalloc(a,b) _gcry_calloc ((a),(b))
+#define xtrymalloc_secure(a) _gcry_malloc_secure ((a))
+#define xtrycalloc_secure(a,b) _gcry_calloc_secure ((a),(b))
+#define xtryrealloc(a,b) _gcry_realloc ((a),(b))
+#define xtrystrdup(a) _gcry_strdup ((a))
+#define xmalloc(a) _gcry_xmalloc ((a))
+#define xcalloc(a,b) _gcry_xcalloc ((a),(b))
+#define xmalloc_secure(a) _gcry_xmalloc_secure ((a))
+#define xcalloc_secure(a,b) _gcry_xcalloc_secure ((a),(b))
+#define xrealloc(a,b) _gcry_xrealloc ((a),(b))
+#define xstrdup(a) _gcry_xstrdup ((a))
+#define xfree(a) _gcry_free ((a))
+
/*-- src/misc.c --*/
@@ -101,8 +139,12 @@ void _gcry_bug (const char *file, int line);
void _gcry_assert_failed (const char *expr, const char *file, int line);
#endif
+void _gcry_divide_by_zero (void) JNLIB_GCC_A_NR;
+
const char *_gcry_gettext (const char *key) GCC_ATTR_FORMAT_ARG(1);
void _gcry_fatal_error(int rc, const char *text ) JNLIB_GCC_A_NR;
+void _gcry_logv (int level,
+ const char *fmt, va_list arg_ptr) JNLIB_GCC_A_PRINTF(2,0);
void _gcry_log( int level, const char *fmt, ... ) JNLIB_GCC_A_PRINTF(2,3);
void _gcry_log_bug( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
void _gcry_log_fatal( const char *fmt, ... ) JNLIB_GCC_A_NR_PRINTF(1,2);
@@ -113,6 +155,8 @@ int _gcry_log_info_with_dummy_fp (FILE *fp, const char *fmt, ... )
void _gcry_log_debug( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
void _gcry_log_printf ( const char *fmt, ... ) JNLIB_GCC_A_PRINTF(1,2);
void _gcry_log_printhex (const char *text, const void *buffer, size_t length);
+void _gcry_log_printmpi (const char *text, gcry_mpi_t mpi);
+void _gcry_log_printsxp (const char *text, gcry_sexp_t sexp);
void _gcry_set_log_verbosity( int level );
int _gcry_log_verbosity( int level );
@@ -139,6 +183,11 @@ int _gcry_log_verbosity( int level );
#define log_debug _gcry_log_debug
#define log_printf _gcry_log_printf
#define log_printhex _gcry_log_printhex
+#define log_printmpi _gcry_log_printmpi
+#define log_printsxp _gcry_log_printsxp
+
+/* Compatibility macro. */
+#define log_mpidump _gcry_log_printmpi
/*-- src/hwfeatures.c --*/
@@ -148,8 +197,22 @@ int _gcry_log_verbosity( int level );
#define HWF_PADLOCK_SHA 4
#define HWF_PADLOCK_MMUL 8
-unsigned int _gcry_get_hw_features (void);
+#define HWF_INTEL_CPU 16
+#define HWF_INTEL_BMI2 32
+#define HWF_INTEL_SSSE3 64
+#define HWF_INTEL_PCLMUL 128
+#define HWF_INTEL_AESNI 256
+#define HWF_INTEL_RDRAND 512
+#define HWF_INTEL_AVX 1024
+#define HWF_INTEL_AVX2 2048
+
+#define HWF_ARM_NEON 4096
+
+
+gpg_err_code_t _gcry_disable_hw_feature (const char *name);
void _gcry_detect_hw_features (void);
+unsigned int _gcry_get_hw_features (void);
+const char *_gcry_enum_hw_features (int idx, unsigned int *r_feature);
/*-- mpi/mpiutil.c --*/
@@ -164,6 +227,7 @@ const char *_gcry_mpi_get_hw_config (void);
#endif
/*-- primegen.c --*/
+gcry_err_code_t _gcry_primegen_init (void);
gcry_mpi_t _gcry_generate_secret_prime (unsigned int nbits,
gcry_random_level_t random_level,
int (*extra_check)(void*, gcry_mpi_t),
@@ -172,10 +236,13 @@ gcry_mpi_t _gcry_generate_public_prime (unsigned int nbits,
gcry_random_level_t random_level,
int (*extra_check)(void*, gcry_mpi_t),
void *extra_check_arg);
-gcry_mpi_t _gcry_generate_elg_prime (int mode,
- unsigned int pbits, unsigned int qbits,
- gcry_mpi_t g, gcry_mpi_t **factors);
-gcry_mpi_t _gcry_derive_x931_prime (const gcry_mpi_t xp,
+gcry_err_code_t _gcry_generate_elg_prime (int mode,
+ unsigned int pbits,
+ unsigned int qbits,
+ gcry_mpi_t g,
+ gcry_mpi_t *r_prime,
+ gcry_mpi_t **factors);
+gcry_mpi_t _gcry_derive_x931_prime (const gcry_mpi_t xp,
const gcry_mpi_t xp1, const gcry_mpi_t xp2,
const gcry_mpi_t e,
gcry_mpi_t *r_p1, gcry_mpi_t *r_p2);
@@ -185,7 +252,7 @@ gpg_err_code_t _gcry_generate_fips186_2_prime
gcry_mpi_t *r_q, gcry_mpi_t *r_p,
int *r_counter,
void **r_seed, size_t *r_seedlen);
-gpg_err_code_t _gcry_generate_fips186_3_prime
+gpg_err_code_t _gcry_generate_fips186_3_prime
(unsigned int pbits, unsigned int qbits,
const void *seed, size_t seedlen,
gcry_mpi_t *r_q, gcry_mpi_t *r_p,
@@ -201,6 +268,9 @@ char *stpcpy (char *a, const char *b);
int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE;
#endif
+#include "../compat/libcompat.h"
+
+
/* Macros used to rename missing functions. */
#ifndef HAVE_STRTOUL
#define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c)))
@@ -221,7 +291,16 @@ int strcasecmp (const char *a, const char *b) _GCRY_GCC_ATTR_PURE;
/* Stack burning. */
-void _gcry_burn_stack (int bytes);
+#ifdef HAVE_GCC_ASM_VOLATILE_MEMORY
+#define __gcry_burn_stack_dummy() asm volatile ("":::"memory")
+#else
+void __gcry_burn_stack_dummy (void);
+#endif
+
+void __gcry_burn_stack (unsigned int bytes);
+#define _gcry_burn_stack(bytes) \
+ do { __gcry_burn_stack (bytes); \
+ __gcry_burn_stack_dummy (); } while(0)
/* To avoid that a compiler optimizes certain memset calls away, these
@@ -229,10 +308,48 @@ void _gcry_burn_stack (int bytes);
#define wipememory2(_ptr,_set,_len) do { \
volatile char *_vptr=(volatile char *)(_ptr); \
size_t _vlen=(_len); \
- while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
+ unsigned char _vset=(_set); \
+ fast_wipememory2(_vptr,_vset,_vlen); \
+ while(_vlen) { *_vptr=(_vset); _vptr++; _vlen--; } \
} while(0)
#define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
+#ifdef HAVE_U64_TYPEDEF
+ #define FASTWIPE_T u64
+ #define FASTWIPE_MULT (U64_C(0x0101010101010101))
+#else
+ #define FASTWIPE_T u32
+ #define FASTWIPE_MULT (0x01010101U)
+#endif
+
+/* Following architectures can handle unaligned accesses fast. */
+#if defined(__i386__) || defined(__x86_64__) || \
+ defined(__powerpc__) || defined(__powerpc64__) || \
+ (defined(__arm__) && defined(__ARM_FEATURE_UNALIGNED)) || \
+ defined(__aarch64__)
+#define fast_wipememory2_unaligned_head(_ptr,_set,_len) /*do nothing*/
+#else
+#define fast_wipememory2_unaligned_head(_vptr,_vset,_vlen) do { \
+ while((size_t)(_vptr)&(sizeof(FASTWIPE_T)-1) && _vlen) \
+ { *_vptr=(_vset); _vptr++; _vlen--; } \
+ } while(0)
+#endif
+
+/* fast_wipememory2 may leave tail bytes unhandled, in which case tail bytes
+ are handled by wipememory2. */
+#define fast_wipememory2(_vptr,_vset,_vlen) do { \
+ FASTWIPE_T _vset_long = _vset; \
+ fast_wipememory2_unaligned_head(_vptr,_vset,_vlen); \
+ if (_vlen < sizeof(FASTWIPE_T)) \
+ break; \
+ _vset_long *= FASTWIPE_MULT; \
+ do { \
+ volatile FASTWIPE_T *_vptr_long = (volatile void *)_vptr; \
+ *_vptr_long = _vset_long; \
+ _vlen -= sizeof(FASTWIPE_T); \
+ _vptr += sizeof(FASTWIPE_T); \
+ } while (_vlen >= sizeof(FASTWIPE_T)); \
+ } while (0)
/* Digit predicates. */
@@ -245,70 +362,24 @@ void _gcry_burn_stack (int bytes);
|| (*(a) >= 'A' && *(a) <= 'F') \
|| (*(a) >= 'a' && *(a) <= 'f'))
-/* Management for ciphers/digests/pubkey-ciphers. */
-
-/* Structure for each registered `module'. */
-struct gcry_module
-{
- struct gcry_module *next; /* List pointers. */
- struct gcry_module **prevp;
- void *spec; /* Pointer to the subsystem-specific
- specification structure. */
- void *extraspec; /* Pointer to the subsystem-specific
- extra specification structure. */
- int flags; /* Associated flags. */
- int counter; /* Use counter. */
- unsigned int mod_id; /* ID of this module. */
-};
-
-/* Flags for the `flags' member of gcry_module_t. */
-#define FLAG_MODULE_DISABLED (1 << 0)
-
-gcry_err_code_t _gcry_module_add (gcry_module_t *entries,
- unsigned int id,
- void *spec,
- void *extraspec,
- gcry_module_t *module);
-
-typedef int (*gcry_module_lookup_t) (void *spec, void *data);
-
-/* Lookup a module specification by it's ID. After a successfull
- lookup, the module has it's resource counter incremented. */
-gcry_module_t _gcry_module_lookup_id (gcry_module_t entries,
- unsigned int id);
-
-/* Internal function. Lookup a module specification. */
-gcry_module_t _gcry_module_lookup (gcry_module_t entries, void *data,
- gcry_module_lookup_t func);
-
-/* Release a module. In case the use-counter reaches zero, destroy
- the module. */
-void _gcry_module_release (gcry_module_t entry);
-
-/* Add a reference to a module. */
-void _gcry_module_use (gcry_module_t module);
-
-/* Return a list of module IDs. */
-gcry_err_code_t _gcry_module_list (gcry_module_t modules,
- int *list, int *list_length);
+/* Init functions. */
gcry_err_code_t _gcry_cipher_init (void);
gcry_err_code_t _gcry_md_init (void);
gcry_err_code_t _gcry_pk_init (void);
-gcry_err_code_t _gcry_ac_init (void);
-
-gcry_err_code_t _gcry_pk_module_lookup (int id, gcry_module_t *module);
-void _gcry_pk_module_release (gcry_module_t module);
-gcry_err_code_t _gcry_pk_get_elements (int algo, char **enc, char **sig);
+gcry_err_code_t _gcry_secmem_module_init (void);
+gcry_err_code_t _gcry_mpi_init (void);
/* Memory management. */
#define GCRY_ALLOC_FLAG_SECURE (1 << 0)
/*-- sexp.c --*/
-gcry_error_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
- const char *format, va_list arg_ptr);
+gcry_err_code_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff,
+ const char *format, va_list arg_ptr);
char *_gcry_sexp_nth_string (const gcry_sexp_t list, int number);
+gpg_err_code_t _gcry_sexp_vextract_param (gcry_sexp_t sexp, const char *path,
+ const char *list, va_list arg_ptr);
/*-- fips.c --*/
@@ -320,12 +391,14 @@ int _gcry_fips_mode (void);
int _gcry_enforced_fips_mode (void);
+void _gcry_set_enforced_fips_mode (void);
+
void _gcry_inactivate_fips_mode (const char *text);
int _gcry_is_fips_mode_inactive (void);
-void _gcry_fips_signal_error (const char *srcfile,
- int srcline,
+void _gcry_fips_signal_error (const char *srcfile,
+ int srcline,
const char *srcfunc,
int is_fatal,
const char *description);
@@ -343,7 +416,7 @@ void _gcry_fips_signal_error (const char *srcfile,
int _gcry_fips_is_operational (void);
#define fips_is_operational() (_gcry_global_is_operational ())
-#define fips_not_operational() (GCRY_GPG_ERR_NOT_OPERATIONAL)
+#define fips_not_operational() (GPG_ERR_NOT_OPERATIONAL)
int _gcry_fips_test_operational (void);
int _gcry_fips_test_error_or_operational (void);