3 * bignum operations that are missing from gmp.
6 /* nettle, low-level cryptographics library
8 * Copyright (C) 2001 Niels Möller
10 * The nettle library is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 of the License, or (at your
13 * option) any later version.
15 * The nettle library is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with the nettle library; see the file COPYING.LIB. If not, write to
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26 #ifndef NETTLE_BIGNUM_H_INCLUDED
27 #define NETTLE_BIGNUM_H_INCLUDED
29 #include "nettle-meta.h"
32 #include "nettle-types.h"
38 /* Size needed for signed encoding, including extra sign byte if
41 nettle_mpz_sizeinbase_256_s(const mpz_t x
);
43 /* Size needed for unsigned encoding */
45 nettle_mpz_sizeinbase_256_u(const mpz_t x
);
47 /* Writes an integer as length octets, using big endian byte order,
48 * and two's complement for negative numbers. */
50 nettle_mpz_get_str_256(unsigned length
, uint8_t *s
, const mpz_t x
);
52 /* Reads a big endian, two's complement, integer. */
54 nettle_mpz_set_str_256_s(mpz_t x
,
55 unsigned length
, const uint8_t *s
);
58 nettle_mpz_init_set_str_256_s(mpz_t x
,
59 unsigned length
, const uint8_t *s
);
61 /* Similar, but for unsigned format. These function don't interpret
62 * the most significant bit as the sign. */
64 nettle_mpz_set_str_256_u(mpz_t x
,
65 unsigned length
, const uint8_t *s
);
68 nettle_mpz_init_set_str_256_u(mpz_t x
,
69 unsigned length
, const uint8_t *s
);
71 /* Returns a uniformly distributed random number 0 <= x < 2^n */
73 nettle_mpz_random_size(mpz_t x
,
74 void *ctx
, nettle_random_func
*random
,
77 /* Returns a number x, almost uniformly random in the range
80 nettle_mpz_random(mpz_t x
,
81 void *ctx
, nettle_random_func
*random
,
85 nettle_next_prime(mpz_t p
, mpz_t n
, unsigned count
, unsigned prime_limit
,
86 void *progress_ctx
, nettle_progress_func
*progress
);
89 nettle_random_prime(mpz_t p
, unsigned bits
, int top_bits_set
,
90 void *ctx
, nettle_random_func
*random
,
91 void *progress_ctx
, nettle_progress_func
*progress
);
94 _nettle_generate_pocklington_prime (mpz_t p
, mpz_t r
,
95 unsigned bits
, int top_bits_set
,
96 void *ctx
, nettle_random_func
*random
,
102 struct sexp_iterator
;
104 /* If LIMIT is non-zero, the number must be at most LIMIT bits.
105 * Implies sexp_iterator_next. */
107 nettle_mpz_set_sexp(mpz_t x
, unsigned limit
, struct sexp_iterator
*i
);
111 struct asn1_der_iterator
;
114 nettle_asn1_der_get_bignum(struct asn1_der_iterator
*iterator
,
115 mpz_t x
, unsigned max_bits
);
121 #endif /* NETTLE_BIGNUM_H_INCLUDED */