diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2018-09-18 00:51:05 +0300 |
---|---|---|
committer | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2018-09-18 16:24:21 +0300 |
commit | 2152e7437bdea200b8aa4f05d83a9620e8cff974 (patch) | |
tree | 938026d1da156f7df1fc26a2b4242b56c94e6df4 | |
parent | d165c2a37f7d072cc88db88ec97f057a9ac6e4aa (diff) | |
download | gnutls-2152e7437bdea200b8aa4f05d83a9620e8cff974.tar.gz |
mpi: add function to dprint mpi in little endianness
Add little endian counterpart to _gnutls_mpi_dprint and
_gnutls_mpi_dprint_le.
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
-rw-r--r-- | lib/mpi.c | 26 | ||||
-rw-r--r-- | lib/mpi.h | 1 |
2 files changed, 27 insertions, 0 deletions
@@ -175,6 +175,32 @@ _gnutls_mpi_init_scan_le(bigint_t * ret_mpi, const void *buffer, size_t nbytes) return 0; } +int _gnutls_mpi_dprint_le(const bigint_t a, gnutls_datum_t * dest) +{ + int ret; + uint8_t *buf = NULL; + size_t bytes = 0; + + if (dest == NULL || a == NULL) + return GNUTLS_E_INVALID_REQUEST; + + _gnutls_mpi_print_le(a, NULL, &bytes); + if (bytes != 0) + buf = gnutls_malloc(bytes); + if (buf == NULL) + return GNUTLS_E_MEMORY_ERROR; + + ret = _gnutls_mpi_print_le(a, buf, &bytes); + if (ret < 0) { + gnutls_free(buf); + return ret; + } + + dest->data = buf; + dest->size = bytes; + return 0; +} + /* Always has the first bit zero */ int _gnutls_mpi_dprint_lz(const bigint_t a, gnutls_datum_t * dest) { @@ -79,6 +79,7 @@ int _gnutls_mpi_init_scan_nz(bigint_t * ret_mpi, const void *buffer, int _gnutls_mpi_init_scan_le(bigint_t * ret_mpi, const void *buffer, size_t nbytes); +int _gnutls_mpi_dprint_le(const bigint_t a, gnutls_datum_t * dest); int _gnutls_mpi_dprint_lz(const bigint_t a, gnutls_datum_t * dest); int _gnutls_mpi_dprint(const bigint_t a, gnutls_datum_t * dest); int _gnutls_mpi_dprint_size(const bigint_t a, gnutls_datum_t * dest, |