summaryrefslogtreecommitdiffabout
path: root/pwmanager/libcrypt/crypt/mpi.h
Unidiff
Diffstat (limited to 'pwmanager/libcrypt/crypt/mpi.h') (more/less context) (ignore whitespace changes)
-rw-r--r--pwmanager/libcrypt/crypt/mpi.h199
1 files changed, 199 insertions, 0 deletions
diff --git a/pwmanager/libcrypt/crypt/mpi.h b/pwmanager/libcrypt/crypt/mpi.h
new file mode 100644
index 0000000..9e0037e
--- a/dev/null
+++ b/pwmanager/libcrypt/crypt/mpi.h
@@ -0,0 +1,199 @@
1/* mpi.h - Multi Precision Integers
2 * Copyright (C) 1994, 1996, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
3 *
4 * This file is part of Libgcrypt.
5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser general Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 *
20 * Note: This code is heavily based on the GNU MP Library.
21 * Actually it's the same code with only minor changes in the
22 * way the data is stored; this is to support the abstraction
23 * of an optional secure memory allocation which may be used
24 * to avoid revealing of sensitive data due to paging etc.
25 */
26
27#ifndef G10_MPI_H
28#define G10_MPI_H
29
30#include <config.h>
31#include <stdio.h>
32#include "types.h"
33#include "memory.h"
34#include "../mpi/mpi-asm-defs.h"
35
36#include "g10lib.h"
37
38#ifndef _GCRYPT_IN_LIBGCRYPT
39#error this file should only be used inside libgcrypt
40#endif
41
42#ifndef BITS_PER_MPI_LIMB
43#if BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_INT
44 typedef unsigned int mpi_limb_t;
45 typedef signed int mpi_limb_signed_t;
46#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG
47 typedef unsigned long int mpi_limb_t;
48 typedef signed long int mpi_limb_signed_t;
49#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_LONG_LONG
50 typedef unsigned long long int mpi_limb_t;
51 typedef signed long long int mpi_limb_signed_t;
52#elif BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_SHORT
53 typedef unsigned short int mpi_limb_t;
54 typedef signed short int mpi_limb_signed_t;
55#else
56#error BYTES_PER_MPI_LIMB does not match any C type
57#endif
58#define BITS_PER_MPI_LIMB (8*BYTES_PER_MPI_LIMB)
59#endif /*BITS_PER_MPI_LIMB*/
60
61#define DBG_MPI _gcry_get_debug_flag( 2 );
62
63struct gcry_mpi {
64 int alloced; /* array size (# of allocated limbs) */
65 int nlimbs; /* number of valid limbs */
66 int sign; /* indicates a negative number and is used for opaque
67 * MPIs to store the length */
68 unsigned flags; /* bit 0: array must be allocated in secure memory space */
69 /* bit 2: the limb is a pointer to some m_alloced data */
70 mpi_limb_t *d; /* array with the limbs */
71};
72
73#define MPI_NULL NULL
74
75#define mpi_get_nlimbs(a) ((a)->nlimbs)
76 #define mpi_is_neg(a) ((a)->sign)
77
78/*-- mpiutil.c --*/
79
80#ifdef M_DEBUG
81 #define mpi_alloc(n)_gcry_mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) )
82#define mpi_alloc_secure(n) _gcry_mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) )
83 #define mpi_free(a)_gcry_mpi_debug_free((a), M_DBGINFO(__LINE__) )
84#define mpi_resize(a,b) _gcry_mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) )
85 #define mpi_copy(a) _gcry_mpi_debug_copy((a), M_DBGINFO(__LINE__) )
86 gcry_mpi_t _gcry_mpi_debug_alloc( unsigned nlimbs, const char *info );
87 gcry_mpi_t _gcry_mpi_debug_alloc_secure( unsigned nlimbs, const char *info );
88 void _gcry_mpi_debug_free( gcry_mpi_t a, const char *info );
89 void _gcry_mpi_debug_resize( gcry_mpi_t a, unsigned nlimbs, const char *info );
90 gcry_mpi_t _gcry_mpi_debug_copy( gcry_mpi_t a, const char *info);
91#else
92 #define mpi_alloc(n) _gcry_mpi_alloc((n) )
93#define mpi_alloc_secure(n) _gcry_mpi_alloc_secure((n) )
94 #define mpi_free(a) _gcry_mpi_free((a) )
95#define mpi_resize(a,b) _gcry_mpi_resize((a),(b))
96 #define mpi_copy(a) _gcry_mpi_copy((a))
97 gcry_mpi_t _gcry_mpi_alloc( unsigned nlimbs );
98 gcry_mpi_t _gcry_mpi_alloc_secure( unsigned nlimbs );
99 void _gcry_mpi_free( gcry_mpi_t a );
100 void _gcry_mpi_resize( gcry_mpi_t a, unsigned nlimbs );
101 gcry_mpi_t _gcry_mpi_copy( gcry_mpi_t a );
102#endif
103#define mpi_is_opaque(a) ((a) && ((a)->flags&4))
104#define mpi_is_secure(a) ((a) && ((a)->flags&1))
105#define mpi_clear(a) _gcry_mpi_clear ((a))
106#define mpi_alloc_like(a) _gcry_mpi_alloc_like((a))
107#define mpi_set(a,b) _gcry_mpi_set ((a),(b))
108#define mpi_set_ui(a,b) _gcry_mpi_set_ui ((a),(b))
109#define mpi_alloc_set_ui(a) _gcry_mpi_alloc_set_ui ((a))
110#define mpi_m_check(a) _gcry_mpi_m_check ((a))
111#define mpi_swap(a,b) _gcry_mpi_swap ((a),(b))
112
113void _gcry_mpi_clear( gcry_mpi_t a );
114gcry_mpi_t _gcry_mpi_alloc_like( gcry_mpi_t a );
115void _gcry_mpi_set( gcry_mpi_t w, gcry_mpi_t u);
116void _gcry_mpi_set_ui( gcry_mpi_t w, ulong u);
117gcry_mpi_t _gcry_mpi_alloc_set_ui( unsigned long u);
118void _gcry_mpi_m_check( gcry_mpi_t a );
119void _gcry_mpi_swap( gcry_mpi_t a, gcry_mpi_t b);
120
121/*-- mpicoder.c --*/
122void _gcry_log_mpidump( const char *text, gcry_mpi_t a );
123u32 _gcry_mpi_get_keyid( gcry_mpi_t a, u32 *keyid );
124byte *_gcry_mpi_get_buffer( gcry_mpi_t a, unsigned *nbytes, int *sign );
125byte *_gcry_mpi_get_secure_buffer( gcry_mpi_t a, unsigned *nbytes, int *sign );
126void _gcry_mpi_set_buffer( gcry_mpi_t a, const byte *buffer, unsigned nbytes, int sign );
127
128#define log_mpidump _gcry_log_mpidump
129
130/*-- mpi-add.c --*/
131#define mpi_add_ui(w,u,v) gcry_mpi_add_ui((w),(u),(v))
132#define mpi_add(w,u,v) gcry_mpi_add ((w),(u),(v))
133#define mpi_addm(w,u,v,m) gcry_mpi_addm ((w),(u),(v),(m))
134#define mpi_sub_ui(w,u,v) gcry_mpi_sub_ui ((w),(u),(v))
135#define mpi_sub(w,u,v) gcry_mpi_sub ((w),(u),(v))
136#define mpi_subm(w,u,v,m) gcry_mpi_subm ((w),(u),(v),(m))
137
138
139/*-- mpi-mul.c --*/
140#define mpi_mul_ui(w,u,v) gcry_mpi_mul_ui ((w),(u),(v))
141#define mpi_mul_2exp(w,u,v) gcry_mpi_mul_2exp ((w),(u),(v))
142#define mpi_mul(w,u,v) gcry_mpi_mul ((w),(u),(v))
143#define mpi_mulm(w,u,v,m) gcry_mpi_mulm ((w),(u),(v),(m))
144
145
146/*-- mpi-div.c --*/
147#define mpi_fdiv_r_ui(a,b,c) _gcry_mpi_fdiv_r_ui((a),(b),(c))
148#define mpi_fdiv_r(a,b,c) _gcry_mpi_fdiv_r((a),(b),(c))
149#define mpi_fdiv_q(a,b,c) _gcry_mpi_fdiv_q((a),(b),(c))
150#define mpi_fdiv_qr(a,b,c,d) _gcry_mpi_fdiv_qr((a),(b),(c),(d))
151#define mpi_tdiv_r(a,b,c) _gcry_mpi_tdiv_r((a),(b),(c))
152#define mpi_tdiv_qr(a,b,c,d) _gcry_mpi_tdiv_qr((a),(b),(c),(d))
153#define mpi_tdiv_q_2exp(a,b,c) _gcry_mpi_tdiv_q_2exp((a),(b),(c))
154#define mpi_divisible_ui(a,b) _gcry_mpi_divisible_ui((a),(b))
155ulong _gcry_mpi_fdiv_r_ui( gcry_mpi_t rem, gcry_mpi_t dividend, ulong divisor );
156void _gcry_mpi_fdiv_r( gcry_mpi_t rem, gcry_mpi_t dividend, gcry_mpi_t divisor );
157void _gcry_mpi_fdiv_q( gcry_mpi_t quot, gcry_mpi_t dividend, gcry_mpi_t divisor );
158void _gcry_mpi_fdiv_qr( gcry_mpi_t quot, gcry_mpi_t rem, gcry_mpi_t dividend, gcry_mpi_t divisor );
159void _gcry_mpi_tdiv_r( gcry_mpi_t rem, gcry_mpi_t num, gcry_mpi_t den);
160void _gcry_mpi_tdiv_qr( gcry_mpi_t quot, gcry_mpi_t rem, gcry_mpi_t num, gcry_mpi_t den);
161void _gcry_mpi_tdiv_q_2exp( gcry_mpi_t w, gcry_mpi_t u, unsigned count );
162int _gcry_mpi_divisible_ui(gcry_mpi_t dividend, ulong divisor );
163
164/*-- mpi-gcd.c --*/
165
166/*-- mpi-mpow.c --*/
167#define mpi_mulpowm(a,b,c,d) _gcry_mpi_mulpowm ((a),(b),(c),(d))
168void _gcry_mpi_mulpowm( gcry_mpi_t res, gcry_mpi_t *basearray, gcry_mpi_t *exparray, gcry_mpi_t mod);
169
170/*-- mpi-cmp.c --*/
171#define mpi_cmp_ui(a,b) gcry_mpi_cmp_ui ((a),(b))
172#define mpi_cmp(a,b) gcry_mpi_cmp ((a),(b))
173int gcry_mpi_cmp_ui( gcry_mpi_t u, ulong v );
174int gcry_mpi_cmp( gcry_mpi_t u, gcry_mpi_t v );
175
176/*-- mpi-scan.c --*/
177#define mpi_trailing_zeros(a) _gcry_mpi_trailing_zeros ((a))
178int _gcry_mpi_getbyte( gcry_mpi_t a, unsigned idx );
179void _gcry_mpi_putbyte( gcry_mpi_t a, unsigned idx, int value );
180unsigned _gcry_mpi_trailing_zeros( gcry_mpi_t a );
181
182/*-- mpi-bit.c --*/
183#define mpi_normalize(a) _gcry_mpi_normalize ((a))
184#define mpi_get_nbits(a) gcry_mpi_get_nbits ((a))
185#define mpi_test_bit(a,b) gcry_mpi_test_bit ((a),(b))
186#define mpi_set_bit(a,b) gcry_mpi_set_bit ((a),(b))
187#define mpi_set_highbit(a,b) gcry_mpi_set_highbit ((a),(b))
188#define mpi_clear_bit(a,b) gcry_mpi_clear_bit ((a),(b))
189#define mpi_clear_highbit(a,b) gcry_mpi_clear_highbit ((a),(b))
190#define mpi_rshift(a,b,c) gcry_mpi_rshift ((a),(b),(c))
191
192void _gcry_mpi_normalize( gcry_mpi_t a );
193
194/*-- mpi-inv.c --*/
195#define mpi_invm(a,b,c) _gcry_mpi_invm ((a),(b),(c))
196void _gcry_mpi_invm( gcry_mpi_t x, gcry_mpi_t u, gcry_mpi_t v );
197
198
199#endif /*G10_MPI_H*/