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 asNULL
. format describes the format of the MPI as stored in buffer:
GCRYMPI_FMT_STD
- 2-complement stored without a length header.
GCRYMPI_FMT_PGP
- As used by OpenPGP (only defined as unsigned). This is basically
GCRYMPI_FMT_STD
with a 2 byte big endian length header.GCRYMPI_FMT_SSH
- As used in the Secure Shell protocol. This is
GCRYMPI_FMT_STD
with a 4 byte big endian header.GCRYMPI_FMT_HEX
- 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.
GCRYMPI_FMT_USG
- 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
NULL
.