From 1fecae98ee7e0fa49b29f98efa6817ca121ed98a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 12 Mar 2013 20:20:42 +0100 Subject: Add GCRYMPI_FLAG_IMMUTABLE to help debugging. * src/gcrypt.h.in (GCRYMPI_FLAG_IMMUTABLE): New. * src/mpi.h (mpi_is_immutable): New macro. * mpi/mpiutil.c (gcry_mpi_set_flag, gcry_mpi_clear_flag) (gcry_mpi_get_flag): Implement new flag (_gcry_mpi_immutable_failed): New. * mpi/mpiutil.c (_gcry_mpi_clear, _gcry_mpi_free, gcry_mpi_snatch) (gcry_mpi_set, gcry_mpi_randomize): Act upon the immutable flag. * mpi/mpi-bit.c (gcry_mpi_set_bit, gcry_mpi_set_highbit) (gcry_mpi_clear_highbit, gcry_mpi_clear_bit) (_gcry_mpi_rshift_limbs, gcry_mpi_lshift): Ditto. * mpi/mpicoder.c (_gcry_mpi_set_buffer): Ditto. -- Note that this flag is currently only checked by a few MPI functions. The reason why we eventually need such a flag is to help implementing a generic way to retrieve and set ECC parameters without accidentally changing a curve parameter taken from a list of predefined curves. --- src/mpi.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/mpi.h') diff --git a/src/mpi.h b/src/mpi.h index 23afa683..93ad8897 100644 --- a/src/mpi.h +++ b/src/mpi.h @@ -69,7 +69,8 @@ struct gcry_mpi int sign; /* Indicates a negative number and is also used for opaque MPIs to store the length. */ unsigned int flags; /* Bit 0: Array to be allocated in secure memory space.*/ - /* Bit 2: the limb is a pointer to some m_alloced data.*/ + /* Bit 2: The limb is a pointer to some m_alloced data.*/ + /* Bit 4: Const MPI - the MPI may not be modified. */ mpi_limb_t *d; /* Array with the limbs */ }; @@ -104,8 +105,12 @@ struct gcry_mpi gcry_mpi_t _gcry_mpi_copy( gcry_mpi_t a ); #endif -#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) -#define mpi_is_secure(a) ((a) && ((a)->flags&1)) +void _gcry_mpi_immutable_failed (void); +#define mpi_immutable_failed() _gcry_mpi_immutable_failed () + +#define mpi_is_immutable(a) ((a) && ((a)->flags&16)) +#define mpi_is_opaque(a) ((a) && ((a)->flags&4)) +#define mpi_is_secure(a) ((a) && ((a)->flags&1)) #define mpi_clear(a) _gcry_mpi_clear ((a)) #define mpi_alloc_like(a) _gcry_mpi_alloc_like((a)) #define mpi_snatch(a,b) _gcry_mpi_snatch ((a),(b)) -- cgit v1.2.1