The following functions are used to convert between an external representation of an MPI and the internal one of Libgcrypt.
Convert the external representation of an integer stored in buffer with a length of buflen into a newly created MPI returned which will be stored at the address of r_mpi. For certain formats the length argument is not required and should be passed as
0. After a successful operation the variable nscanned receives the number of bytes actually scanned unless nscanned was given as
NULL. format describes the format of the MPI as stored in buffer:
- 2-complement stored without a length header.
- As used by OpenPGP (only defined as unsigned). This is basically
GCRYMPI_FMT_STDwith a 2 byte big endian length header.
- As used in the Secure Shell protocol. This is
GCRYMPI_FMT_STDwith a 4 byte big endian header.
- Stored as a C style string with each byte of the MPI encoded as 2 hex digits. When using this format, buflen must be zero.
- Simple unsigned integer.
Note that all of the above formats store the integer in big-endian format (MSB first).
Convert the MPI a into an external representation described by format (see above) and store it in the provided buffer which has a usable length of at least the buflen bytes. If nwritten is not NULL, it will receive the number of bytes actually stored in buffer after a successful operation.
Convert the MPI a into an external representation described by format (see above) and store it in a newly allocated buffer which address will be stored in the variable buffer points to. The number of bytes stored in this buffer will be stored in the variable nbytes points to, unless nbytes is