summaryrefslogtreecommitdiff
path: root/bignum.h
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2002-11-15 08:57:42 +0100
committerNiels Möller <nisse@lysator.liu.se>2002-11-15 08:57:42 +0100
commit43152353176dfadc83a880dcec2f21312bf6fa19 (patch)
tree1d0f8ef41280da69cc11c4f0fe6eacbd3c523e1b /bignum.h
parent52c695fff9d1a7e24d7b63247421a46b07b94346 (diff)
downloadnettle-43152353176dfadc83a880dcec2f21312bf6fa19.tar.gz
(nettle_mpz_sizeinbase_256_s): New function.
(nettle_mpz_sizeinbase_256_u): New name, was nettle_mpz_sizeinbase_256. (nettle_mpz_to_octets): New function. (nettle_mpz_get_str_256): Handle negative numbers. (nettle_mpz_from_octets): New function. (nettle_mpz_set_str_256_u): New name, was nettle_mpz_set_str_256. (nettle_mpz_init_set_str_256_u): New name, was nettle_mpz_init_set_str_256. (nettle_mpz_set_str_256_s): New function, handling negative two's complement numbers. (nettle_mpz_init_set_str_256_s): And an init variant. Rev: src/nettle/bignum.c:1.5 Rev: src/nettle/bignum.h:1.6
Diffstat (limited to 'bignum.h')
-rw-r--r--bignum.h32
1 files changed, 25 insertions, 7 deletions
diff --git a/bignum.h b/bignum.h
index f4c9ed07..3ba8ea5d 100644
--- a/bignum.h
+++ b/bignum.h
@@ -31,21 +31,39 @@
#include <gmp.h>
#include <inttypes.h>
+/* Size needed for signed encoding, including extra sign byte if
+ * necessary. */
unsigned
-nettle_mpz_sizeinbase_256(const mpz_t x);
+nettle_mpz_sizeinbase_256_s(const mpz_t x);
-/* Writes an unsigned integer as length octets, using big endian byte
- * order. */
+/* Size needed for unsigned encoding */
+unsigned
+nettle_mpz_sizeinbase_256_u(const mpz_t x);
+
+/* Writes an integer as length octets, using big endian byte order,
+ * and two's complement for negative numbers. */
+/* FIXME: Change order of arguments, putting the mpz_t first? */
void
nettle_mpz_get_str_256(unsigned length, uint8_t *s, const mpz_t x);
+/* Reads a big endian, two's complement, integer. */
+void
+nettle_mpz_set_str_256_s(mpz_t x,
+ unsigned length, const uint8_t *s);
+
+void
+nettle_mpz_init_set_str_256_s(mpz_t x,
+ unsigned length, const uint8_t *s);
+
+/* Similar, but for unsigned format. These function don't interpret
+ * the most significant bit as the sign. */
void
-nettle_mpz_set_str_256(mpz_t x,
- unsigned length, const uint8_t *s);
+nettle_mpz_set_str_256_u(mpz_t x,
+ unsigned length, const uint8_t *s);
void
-nettle_mpz_init_set_str_256(mpz_t x,
- unsigned length, const uint8_t *s);
+nettle_mpz_init_set_str_256_u(mpz_t x,
+ unsigned length, const uint8_t *s);
/* Returns a uniformly distributed random number 0 <= x < 2^n */
void