BeeCrypt  4.2.1
mpbarrett.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 Bob Deblier
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 
26 #ifndef _MPBARRETT_H
27 #define _MPBARRETT_H
28 
29 #include "beecrypt/beecrypt.h"
30 #include "beecrypt/mpnumber.h"
31 
32 #ifdef __cplusplus
33 # include <iostream>
34 #endif
35 
36 #ifdef __cplusplus
38 #else
39 struct _mpbarrett
40 #endif
41 {
42  size_t size;
43  mpw* modl; /* (size) words */
44  mpw* mu; /* (size+1) words */
45 
46 #ifdef __cplusplus
47  mpbarrett();
48  mpbarrett(const mpbarrett&);
49  ~mpbarrett();
50 
51  const mpbarrett& operator=(const mpbarrett&);
52 
53  void wipe();
54 
55  size_t bitlength() const;
56 #endif
57 };
58 
59 #ifndef __cplusplus
60 typedef struct _mpbarrett mpbarrett;
61 #else
63 std::ostream& operator<<(std::ostream&, const mpbarrett&);
64 #endif
65 
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
71 void mpbzero(mpbarrett*);
73 void mpbinit(mpbarrett*, size_t);
75 void mpbfree(mpbarrett*);
77 void mpbcopy(mpbarrett*, const mpbarrett*);
79 void mpbwipe(mpbarrett*);
80 
82 void mpbset(mpbarrett*, size_t, const mpw*);
83 
85 int mpbsetbin(mpbarrett*, const byte*, size_t);
87 int mpbsethex(mpbarrett*, const char*);
88 
90 void mpbsubone(const mpbarrett*, mpw*);
91 
93 void mpbmu_w(mpbarrett*, mpw*);
94 
96 void mpbrnd_w (const mpbarrett*, randomGeneratorContext*, mpw*, mpw*);
101 
103 void mpbneg_w(const mpbarrett*, const mpw*, mpw*);
105 void mpbmod_w(const mpbarrett*, const mpw*, mpw*, mpw*);
106 
108 void mpbaddmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*);
110 void mpbsubmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*);
112 void mpbmulmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*);
114 void mpbsqrmod_w(const mpbarrett*, size_t, const mpw*, mpw*, mpw*);
116 void mpbpowmod_w(const mpbarrett*, size_t, const mpw*, size_t, const mpw*, mpw*, mpw*);
118 void mpbpowmodsld_w(const mpbarrett*, const mpw*, size_t, const mpw*, mpw*, mpw*);
120 void mpbtwopowmod_w(const mpbarrett*, size_t, const mpw*, mpw*, mpw*);
121 
122 /* To be added:
123  * simultaneous multiple exponentiation, for use in dsa and elgamal signature verification
124  */
126 void mpbsm2powmod(const mpbarrett*, const mpw*, const mpw*, const mpw*, const mpw*);
128 void mpbsm3powmod(const mpbarrett*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*, const mpw*);
129 
131 int mpbpprime_w(const mpbarrett*, randomGeneratorContext*, int, mpw*);
132 
133 /* the next routines take mpnumbers as parameters */
134 
137 
139 void mpbnmulmod(const mpbarrett*, const mpnumber*, const mpnumber*, mpnumber*);
141 void mpbnsqrmod(const mpbarrett*, const mpnumber*, mpnumber*);
142 
144 void mpbnpowmod (const mpbarrett*, const mpnumber*, const mpnumber*, mpnumber*);
146 void mpbnpowmodsld(const mpbarrett*, const mpw*, const mpnumber*, mpnumber*);
147 
149 size_t mpbbits(const mpbarrett*);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif