nettle  3.7.3
About: Nettle is a low-level cryptographic library.
  Fossies Dox: nettle-3.7.3.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

bignum.h
Go to the documentation of this file.
1 /* bignum.h
2 
3  Bignum operations that are missing from gmp.
4 
5  Copyright (C) 2001 Niels Möller
6 
7  This file is part of GNU Nettle.
8 
9  GNU Nettle is free software: you can redistribute it and/or
10  modify it under the terms of either:
11 
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.
15 
16  or
17 
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.
21 
22  or both in parallel, as here.
23 
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.
28 
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/.
32 */
33 
34 #ifndef NETTLE_BIGNUM_H_INCLUDED
35 #define NETTLE_BIGNUM_H_INCLUDED
36 
37 #include "nettle-types.h"
38 
39 /* For NETTLE_USE_MINI_GMP */
40 #include "version.h"
41 
42 #if NETTLE_USE_MINI_GMP
43 # include "mini-gmp.h"
44 
45 # define GMP_NUMB_MASK (~(mp_limb_t) 0)
46 
47 /* Side-channel silent powm not available in mini-gmp. */
48 # define mpz_powm_sec mpz_powm
49 #else
50 # include <gmp.h>
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /* Size needed for signed encoding, including extra sign byte if
58  * necessary. */
59 size_t
61 
62 /* Size needed for unsigned encoding */
63 size_t
65 
66 /* Writes an integer as length octets, using big endian byte order,
67  * and two's complement for negative numbers. */
68 void
69 nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x);
70 
71 /* Reads a big endian, two's complement, integer. */
72 void
74  size_t length, const uint8_t *s);
75 
76 void
78  size_t length, const uint8_t *s);
79 
80 /* Similar, but for unsigned format. These function don't interpret
81  * the most significant bit as the sign. */
82 void
84  size_t length, const uint8_t *s);
85 
86 void
88  size_t length, const uint8_t *s);
89 
90 /* Returns a uniformly distributed random number 0 <= x < 2^n */
91 void
93  void *ctx, nettle_random_func *random,
94  unsigned bits);
95 
96 /* Returns a number x, almost uniformly random in the range
97  * 0 <= x < n. */
98 void
100  void *ctx, nettle_random_func *random,
101  const mpz_t n);
102 
103 void
104 nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set,
105  void *ctx, nettle_random_func *random,
106  void *progress_ctx, nettle_progress_func *progress);
107 
108 
109 /* sexp parsing */
110 struct sexp_iterator;
111 
112 /* If LIMIT is non-zero, the number must be at most LIMIT bits.
113  * Implies sexp_iterator_next. */
114 int
115 nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
116 
117 
118 /* der parsing */
119 struct asn1_der_iterator;
120 
121 int
123  mpz_t x, unsigned max_bits);
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif /* NETTLE_BIGNUM_H_INCLUDED */
void nettle_mpz_set_str_256_u(mpz_t x, size_t length, const uint8_t *s)
Definition: bignum.c:143
void nettle_mpz_init_set_str_256_u(mpz_t x, size_t length, const uint8_t *s)
Definition: bignum.c:150
void nettle_mpz_init_set_str_256_s(mpz_t x, size_t length, const uint8_t *s)
Definition: bignum.c:181
void nettle_mpz_get_str_256(size_t length, uint8_t *s, const mpz_t x)
Definition: bignum.c:109
size_t nettle_mpz_sizeinbase_256_s(const mpz_t x)
Definition: bignum.c:58
void nettle_mpz_random(mpz_t x, void *ctx, nettle_random_func *random, const mpz_t n)
Definition: bignum-random.c:64
int nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i)
Definition: sexp2bignum.c:40
void nettle_mpz_random_size(mpz_t x, void *ctx, nettle_random_func *random, unsigned bits)
Definition: bignum-random.c:44
int nettle_asn1_der_get_bignum(struct asn1_der_iterator *iterator, mpz_t x, unsigned max_bits)
Definition: der-iterator.c:259
void nettle_mpz_set_str_256_s(mpz_t x, size_t length, const uint8_t *s)
Definition: bignum.c:158
void nettle_random_prime(mpz_t p, unsigned bits, int top_bits_set, void *ctx, nettle_random_func *random, void *progress_ctx, nettle_progress_func *progress)
size_t nettle_mpz_sizeinbase_256_u(const mpz_t x)
Definition: bignum.c:78
#define x
#define i
__mpz_struct mpz_t[1]
Definition: mini-gmp.h:77
void nettle_random_func(void *ctx, size_t length, uint8_t *dst)
Definition: nettle-types.h:75
void nettle_progress_func(void *ctx, int c)
Definition: nettle-types.h:79