3 Bignum operations that are missing from gmp.
5 Copyright (C) 2001 Niels Möller
7 This file is part of GNU Nettle.
9 GNU Nettle is free software: you can redistribute it and/or
10 modify it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free
19 Software Foundation; either version 2 of the License, or (at your
20 option) any later version.
22 or both in parallel, as here.
24 GNU Nettle is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 General Public License for more details.
29 You should have received copies of the GNU General Public License and
30 the GNU Lesser General Public License along with this program. If
31 not, see http://www.gnu.org/licenses/.
34 #ifndef NETTLE_BIGNUM_H_INCLUDED
35 #define NETTLE_BIGNUM_H_INCLUDED
37 #include "nettle-meta.h"
40 #include "nettle-types.h"
46 /* Size needed for signed encoding, including extra sign byte if
49 nettle_mpz_sizeinbase_256_s(const mpz_t x);
51 /* Size needed for unsigned encoding */
53 nettle_mpz_sizeinbase_256_u(const mpz_t x);
55 /* Writes an integer as length octets, using big endian byte order,
56 * and two's complement for negative numbers. */
58 nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x);
60 /* Reads a big endian, two's complement, integer. */
62 nettle_mpz_set_str_256_s(mpz_t x,
63 size_t length, const uint8_t *s);
66 nettle_mpz_init_set_str_256_s(mpz_t x,
67 size_t length, const uint8_t *s);
69 /* Similar, but for unsigned format. These function don't interpret
70 * the most significant bit as the sign. */
72 nettle_mpz_set_str_256_u(mpz_t x,
73 size_t length, const uint8_t *s);
76 nettle_mpz_init_set_str_256_u(mpz_t x,
77 size_t length, const uint8_t *s);
79 /* Returns a uniformly distributed random number 0 <= x < 2^n */
81 nettle_mpz_random_size(mpz_t x,
82 void *ctx, nettle_random_func *random,
85 /* Returns a number x, almost uniformly random in the range
88 nettle_mpz_random(mpz_t x,
89 void *ctx, nettle_random_func *random,
93 nettle_next_prime(mpz_t p, mpz_t n, unsigned count, unsigned prime_limit,
94 void *progress_ctx, nettle_progress_func *progress);
97 nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
98 void *ctx, nettle_random_func *random,
99 void *progress_ctx, nettle_progress_func *progress);
102 _nettle_generate_pocklington_prime (mpz_t p, mpz_t r,
103 unsigned bits, int top_bits_set,
104 void *ctx, nettle_random_func *random,
110 struct sexp_iterator;
112 /* If LIMIT is non-zero, the number must be at most LIMIT bits.
113 * Implies sexp_iterator_next. */
115 nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
119 struct asn1_der_iterator;
122 nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator,
123 mpz_t x, unsigned max_bits);
129 #endif /* NETTLE_BIGNUM_H_INCLUDED */