To work with MPIs, storage must be allocated and released for the numbers. This can be done with one of these functions:
Allocate a new MPI object, initialize it to 0 and initially allocate enough memory for a number of at least nbits. This pre-allocation is only a small performance issue and not actually necessary because Libgcrypt automatically re-allocates the required memory.
This is identical to
gcry_mpi_new
but allocates the MPI in the so called "secure memory" which in turn will take care that all derived values will also be stored in this "secure memory". Use this for highly confidential data like private key parameters.
Release the MPI a and free all associated resources. Passing
NULL
is allowed and ignored. When a MPI stored in the "secure memory" is released, that memory gets wiped out immediately.
The simplest operations are used to assign a new value to an MPI:
Assign the value of u to w and return w. If
NULL
is passed for w, a new MPI is allocated, set to the value of u and returned.
Assign the value of u to w and return w. If
NULL
is passed for w, a new MPI is allocated, set to the value of u and returned. This function takes anunsigned int
as type for u and thus it is only possible to set w to small values (usually up to the word size of the CPU).