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., 59 Temple Place - Suite 330, Boston,
26
#ifndef NETTLE_BIGNUM_H_INCLUDED
27
#define NETTLE_BIGNUM_H_INCLUDED
29
#include "nettle-meta.h"
32
#include "nettle-types.h"
34
/* Size needed for signed encoding, including extra sign byte if
37
nettle_mpz_sizeinbase_256_s(const mpz_t x);
39
/* Size needed for unsigned encoding */
41
nettle_mpz_sizeinbase_256_u(const mpz_t x);
43
/* Writes an integer as length octets, using big endian byte order,
44
* and two's complement for negative numbers. */
45
/* FIXME: Change order of arguments, putting the mpz_t first? */
47
nettle_mpz_get_str_256(unsigned length, uint8_t *s, const mpz_t x);
49
/* Reads a big endian, two's complement, integer. */
51
nettle_mpz_set_str_256_s(mpz_t x,
52
unsigned length, const uint8_t *s);
55
nettle_mpz_init_set_str_256_s(mpz_t x,
56
unsigned length, const uint8_t *s);
58
/* Similar, but for unsigned format. These function don't interpret
59
* the most significant bit as the sign. */
61
nettle_mpz_set_str_256_u(mpz_t x,
62
unsigned length, const uint8_t *s);
65
nettle_mpz_init_set_str_256_u(mpz_t x,
66
unsigned length, const uint8_t *s);
68
/* Returns a uniformly distributed random number 0 <= x < 2^n */
70
nettle_mpz_random_size(mpz_t x,
71
void *ctx, nettle_random_func random,
74
/* Returns a number x, almost uniformly random in the range
77
nettle_mpz_random(mpz_t x,
78
void *ctx, nettle_random_func random,
83
/* If LIMIT is non-zero, the number must be at most LIMIT bits.
84
* Implies sexp_iterator_next. */
86
nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
88
#endif /* NETTLE_BIGNUM_H_INCLUDED */