An MPI data type is allowed to be “misused” to store an arbitrary value. Two functions implement this kludge:
Store nbits of the value p points to in a and mark a as an opaque value (i.e. an value that can't be used for any math calculation and is only used to store an arbitrary bit pattern in a). Ownership of p is taken by this function and thus the user may not use dereference the passed value anymore. It is required that them memory referenced by p has been allocated in a way that
gcry_free
is able to release it.WARNING: Never use an opaque MPI for actual math operations. The only valid functions are gcry_mpi_get_opaque and gcry_mpi_release. Use gcry_mpi_scan to convert a string of arbitrary bytes into an MPI.
Same as
gcry_mpi_set_opaque
but ownership of p is not taken instead a copy of p is used.
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.
Each MPI has an associated set of flags for special purposes. The currently defined flags are:
GCRYMPI_FLAG_SECURE
GCRYMPI_FLAG_OPAQUE
GCRYMPI_FLAG_IMMUTABLE
GCRYMPI_FLAG_CONST
GCRYMPI_CONST_ONE
, GCRYMPI_CONST_TWO
,
GCRYMPI_CONST_THREE
, GCRYMPI_CONST_FOUR
, and
GCRYMPI_CONST_EIGHT
.
GCRYMPI_FLAG_USER1
GCRYMPI_FLAG_USER2
GCRYMPI_FLAG_USER3
GCRYMPI_FLAG_USER4
Set the flag for the MPI a. The only allowed flags are
GCRYMPI_FLAG_SECURE
,GCRYMPI_FLAG_IMMUTABLE
, andGCRYMPI_FLAG_CONST
.
Clear flag for the multi-precision-integers a. The only allowed flag is
GCRYMPI_FLAG_IMMUTABLE
but only ifGCRYMPI_FLAG_CONST
is not set. IfGCRYMPI_FLAG_CONST
is set, clearingGCRYMPI_FLAG_IMMUTABLE
will simply be ignored.
Return true if flag is set for a.
To put a random value into an MPI, the following convenience function may be used:
Set the multi-precision-integers w to a random non-negative number of nbits, using random data quality of level level. In case nbits is not a multiple of a byte, nbits is rounded up to the next byte boundary. When using a level of
GCRY_WEAK_RANDOM
this function makes use ofgcry_create_nonce
.