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)  

gmp-glue.h
Go to the documentation of this file.
1 /* gmp-glue.h
2 
3  Copyright (C) 2013 Niels Möller
4  Copyright (C) 2013 Red Hat
5 
6  This file is part of GNU Nettle.
7 
8  GNU Nettle is free software: you can redistribute it and/or
9  modify it under the terms of either:
10 
11  * the GNU Lesser General Public License as published by the Free
12  Software Foundation; either version 3 of the License, or (at your
13  option) any later version.
14 
15  or
16 
17  * the GNU General Public License as published by the Free
18  Software Foundation; either version 2 of the License, or (at your
19  option) any later version.
20 
21  or both in parallel, as here.
22 
23  GNU Nettle is distributed in the hope that it will be useful,
24  but WITHOUT ANY WARRANTY; without even the implied warranty of
25  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26  General Public License for more details.
27 
28  You should have received copies of the GNU General Public License and
29  the GNU Lesser General Public License along with this program. If
30  not, see http://www.gnu.org/licenses/.
31 */
32 
33 #ifndef NETTLE_GMP_GLUE_H_INCLUDED
34 #define NETTLE_GMP_GLUE_H_INCLUDED
35 
36 #include "bignum.h"
37 
38 #define mpz_limbs_cmp _nettle_mpz_limbs_cmp
39 #define mpz_limbs_read_n _nettle_mpz_limbs_read_n
40 #define mpz_limbs_copy _nettle_mpz_limbs_copy
41 #define mpz_set_n _nettle_mpz_set_n
42 #define mpn_set_base256 _nettle_mpn_set_base256
43 #define mpn_set_base256_le _nettle_mpn_set_base256_le
44 #define mpn_get_base256 _nettle_mpn_get_base256
45 #define mpn_get_base256_le _nettle_mpn_get_base256_le
46 #define gmp_alloc_limbs _nettle_gmp_alloc_limbs
47 #define gmp_free_limbs _nettle_gmp_free_limbs
48 #define gmp_free _nettle_gmp_free
49 #define gmp_alloc _nettle_gmp_alloc
50 
51 #define TMP_GMP_DECL(name, type) type *name; \
52  size_t tmp_##name##_size
53 #define TMP_GMP_ALLOC(name, size) do { \
54  tmp_##name##_size = (size); \
55  (name) = gmp_alloc(sizeof (*name) * (size)); \
56  } while (0)
57 #define TMP_GMP_FREE(name) (gmp_free(name, tmp_##name##_size))
58 
59 #if NETTLE_USE_MINI_GMP
61 mpn_cnd_add_n (mp_limb_t cnd, mp_limb_t *rp,
62  const mp_limb_t *ap, const mp_limb_t *bp, mp_size_t n);
63 
65 mpn_cnd_sub_n (mp_limb_t cnd, mp_limb_t *rp,
66  const mp_limb_t *ap, const mp_limb_t *bp, mp_size_t n);
67 
68 void
69 mpn_cnd_swap (mp_limb_t cnd, volatile mp_limb_t *ap, volatile mp_limb_t *bp, mp_size_t n);
70 #endif
71 
72 #define NETTLE_OCTET_SIZE_TO_LIMB_SIZE(n) \
73  (((n) * 8 + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
74 
75 /* Convenience functions */
76 int
78 
79 /* Get a pointer to an n limb area, for read-only operation. n must be
80  greater or equal to the current size, and the mpz is zero-padded if
81  needed. */
82 const mp_limb_t *
84 
85 /* Copy limbs, with zero-padding. */
86 /* FIXME: Reorder arguments, on the theory that the first argument of
87  an _mpz_* function should be an mpz_t? Or rename to _mpz_get_limbs,
88  with argument order consistent with mpz_get_*. */
89 void
91 
92 void
93 mpz_set_n (mpz_t r, const mp_limb_t *xp, mp_size_t xn);
94 
95 /* Like mpn_set_str, but always writes rn limbs. If input is larger,
96  higher bits are ignored. */
97 void
99  const uint8_t *xp, size_t xn);
100 
101 void
103  const uint8_t *xp, size_t xn);
104 
105 void
106 mpn_get_base256 (uint8_t *rp, size_t rn,
107  const mp_limb_t *xp, mp_size_t xn);
108 
109 void
110 mpn_get_base256_le (uint8_t *rp, size_t rn,
111  const mp_limb_t *xp, mp_size_t xn);
112 
113 
114 mp_limb_t *
116 
117 void
119 
120 void *gmp_alloc(size_t n);
121 void gmp_free(void *p, size_t n);
122 
123 #endif /* NETTLE_GMP_GLUE_H_INCLUDED */
#define x
#define xp
#define bp
#define ap
#define rp
#define mpn_get_base256_le
Definition: gmp-glue.h:45
#define mpz_limbs_read_n
Definition: gmp-glue.h:39
#define gmp_alloc_limbs
Definition: gmp-glue.h:46
#define gmp_free_limbs
Definition: gmp-glue.h:47
#define mpn_get_base256
Definition: gmp-glue.h:44
#define mpn_set_base256_le
Definition: gmp-glue.h:43
#define mpz_limbs_cmp
Definition: gmp-glue.h:38
#define gmp_alloc
Definition: gmp-glue.h:49
#define gmp_free
Definition: gmp-glue.h:48
#define mpz_set_n
Definition: gmp-glue.h:41
#define mpn_set_base256
Definition: gmp-glue.h:42
#define mpz_limbs_copy
Definition: gmp-glue.h:40
__mpz_struct mpz_t[1]
Definition: mini-gmp.h:77
long mp_size_t
Definition: mini-gmp.h:61
unsigned long mp_limb_t
Definition: mini-gmp.h:60