summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2018-09-18 00:51:05 +0300
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2018-09-18 16:24:21 +0300
commit2152e7437bdea200b8aa4f05d83a9620e8cff974 (patch)
tree938026d1da156f7df1fc26a2b4242b56c94e6df4
parentd165c2a37f7d072cc88db88ec97f057a9ac6e4aa (diff)
downloadgnutls-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.c26
-rw-r--r--lib/mpi.h1
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/mpi.c b/lib/mpi.c
index 083afe0fa7..2bc970d7cd 100644
--- a/lib/mpi.c
+++ b/lib/mpi.c
@@ -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)
{
diff --git a/lib/mpi.h b/lib/mpi.h
index e9747e391d..e26dff5024 100644
--- a/lib/mpi.h
+++ b/lib/mpi.h
@@ -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,