libcryptosec
BigInteger.h
Go to the documentation of this file.
1 #ifndef BIGINTEGER_H_
2 #define BIGINTEGER_H_
3 
4 #include <stdlib.h>
5 #include <time.h>
6 
7 #include <openssl/bn.h>
8 #include <openssl/asn1.h>
9 #include <openssl/asn1t.h>
10 #include <openssl/ossl_typ.h>
11 
13 #include "ByteArray.h"
14 
24 {
25 public:
32 
38  BigInteger(BIGNUM const* bn) throw(BigIntegerException);
39 
45  BigInteger(long val) throw(BigIntegerException);
46 
52  BigInteger(ASN1_INTEGER* val) throw(BigIntegerException);
53 
60 
66  BigInteger(BigInteger const& b) throw(BigIntegerException);
67 
73  BigInteger(std::string dec) throw(BigIntegerException);
74 
78  virtual ~BigInteger();
79 
85  void setValue(const long val = 0) throw(BigIntegerException);
86 
92  double getValue() const throw(BigIntegerException);
93 
98  bool isNegative() const throw();
99 
105  ASN1_INTEGER* getASN1Value() const throw(BigIntegerException);
106 
113  ByteArray* getBinValue() const throw(BigIntegerException);
114 
119  BIGNUM const* getBIGNUM() const throw();
120 
125  std::string toHex() const throw();
126 
131  std::string toDec() const throw();
132 
138  void setHexValue(std::string hex) throw(BigIntegerException); //nao utilizar "0x"
139 
145  void setDecValue(std::string dec) throw(BigIntegerException);
146 
152  void setRandValue(int numBits = 64) throw(BigIntegerException);
153 
158  void setNegative(bool neg = true) throw();
159 
164  int size() const throw();
165 
172  BigInteger& add(BigInteger const& a) throw(BigIntegerException);
173 
174  BigInteger& add(long const a) throw(BigIntegerException);
175 
182  BigInteger& sub(BigInteger const& a) throw(BigIntegerException);
183 
184  BigInteger& sub(long const a) throw(BigIntegerException);
185 
186  BigInteger& mul(BigInteger const& a) throw(BigIntegerException);
187  BigInteger& mul(long const a) throw(BigIntegerException);
188  BigInteger operator*(BigInteger const& a) const throw(BigIntegerException);
189  BigInteger operator*(long const c) const throw(BigIntegerException);
190 
191  BigInteger& div(BigInteger const& a) throw(BigIntegerException);
192  BigInteger& div(long const a) throw(BigIntegerException);
193  BigInteger operator/(BigInteger const& a) const throw(BigIntegerException);
194  BigInteger operator/(long const c) const throw(BigIntegerException);
195 
196  BigInteger& mod(BigInteger const& a) throw(BigIntegerException);
197  BigInteger& mod(long const a) throw(BigIntegerException);
198  BigInteger operator%(BigInteger const& a) const throw(BigIntegerException);
199  BigInteger operator%(long const c) const throw(BigIntegerException);
200 
201 
202  int compare(BigInteger const& a) const throw();
203 
210  BigInteger operator+(BigInteger const& c) const throw(BigIntegerException);
211  BigInteger operator+(long const c) const throw(BigIntegerException);
213  BigInteger& operator+=(long const c) throw(BigIntegerException);
214 
221  BigInteger operator-(BigInteger const& c) const throw(BigIntegerException);
222 
223  BigInteger operator-(long const c) const throw(BigIntegerException);
224 
225  bool operator==(BigInteger const& c) const throw();
226  bool operator==(long const c) const throw(BigIntegerException);
227 
228  bool operator!=(BigInteger const& c) const throw();
229  bool operator!=(long const c) const throw(BigIntegerException);
230 
231  bool operator>(BigInteger const& c) const throw();
232  bool operator>(long const c) const throw(BigIntegerException);
233 
234  bool operator>=(BigInteger const& c) const throw();
235  bool operator>=(long const c) const throw(BigIntegerException);
236 
237  bool operator<(BigInteger const& c) const throw();
238  bool operator<(long const c) const throw(BigIntegerException);
239 
240  bool operator<=(BigInteger const& c) const throw();
241  bool operator<=(long const c) const throw(BigIntegerException);
242 
243  bool operator!() const throw();
244  bool operator||(BigInteger const& c) const throw();
245  bool operator||(long const c) const throw(BigIntegerException);
246 
247  bool operator&&(BigInteger const& c) const throw();
248  bool operator&&(long const c) const throw(BigIntegerException);
249 
250 
258  BigInteger& operator=(long const c) throw(BigIntegerException);
259 
260 
261 protected:
262  BIGNUM* bigInt;
263 };
264 
265 BigInteger operator+(long const c, BigInteger const& d) throw(BigIntegerException);
266 BigInteger operator-(long const c, BigInteger const& d) throw(BigIntegerException);
267 
268 
269 #endif /*BIGINTEGER_H_*/
int compare(BigInteger const &a) const
Definition: BigInteger.cpp:477
BigInteger & operator=(BigInteger const &c)
Definition: BigInteger.cpp:521
Classe usada para representar números grandes. A limitação do tamanho do número depende da memória di...
Definition: BigInteger.h:23
bool operator<=(BigInteger const &c) const
Definition: BigInteger.cpp:592
BigInteger & mod(BigInteger const &a)
Definition: BigInteger.cpp:424
void setValue(const long val=0)
Definition: BigInteger.cpp:83
bool operator<(BigInteger const &c) const
Definition: BigInteger.cpp:581
bool operator!() const
Definition: BigInteger.cpp:603
bool operator>(BigInteger const &c) const
Definition: BigInteger.cpp:559
BigInteger & div(BigInteger const &a)
Definition: BigInteger.cpp:362
bool isNegative() const
Definition: BigInteger.cpp:185
bool operator>=(BigInteger const &c) const
Definition: BigInteger.cpp:570
BigInteger()
Definition: BigInteger.cpp:3
bool operator!=(BigInteger const &c) const
Definition: BigInteger.cpp:548
BigInteger & add(BigInteger const &a)
Definition: BigInteger.cpp:282
ByteArray * getBinValue() const
Definition: BigInteger.cpp:158
BigInteger operator%(BigInteger const &a) const
Definition: BigInteger.cpp:465
std::string toDec() const
Definition: BigInteger.cpp:209
BIGNUM * bigInt
Definition: BigInteger.h:262
virtual ~BigInteger()
Definition: BigInteger.cpp:78
double getValue() const
Definition: BigInteger.cpp:119
BigInteger operator*(BigInteger const &a) const
Definition: BigInteger.cpp:349
void setDecValue(std::string dec)
Definition: BigInteger.cpp:274
Classe usada para transportar dados binários pelo sistema. Pode ser usada para conversão de texto em ...
Definition: ByteArray.h:24
void setRandValue(int numBits=64)
Definition: BigInteger.cpp:221
int size() const
Definition: BigInteger.cpp:261
BigInteger operator/(BigInteger const &a) const
Definition: BigInteger.cpp:410
void setHexValue(std::string hex)
Definition: BigInteger.cpp:266
BigInteger & mul(BigInteger const &a)
Definition: BigInteger.cpp:313
BigInteger & sub(BigInteger const &a)
Definition: BigInteger.cpp:298
bool operator==(BigInteger const &c) const
Definition: BigInteger.cpp:537
bool operator||(BigInteger const &c) const
Definition: BigInteger.cpp:608
Definition: BigIntegerException.h:7
BIGNUM const * getBIGNUM() const
Definition: BigInteger.cpp:180
void setNegative(bool neg=true)
Definition: BigInteger.cpp:107
bool operator &&(BigInteger const &c) const
ASN1_INTEGER * getASN1Value() const
Definition: BigInteger.cpp:141
BigInteger operator-(BigInteger const &c) const
Definition: BigInteger.cpp:507
BigInteger & operator+=(BigInteger const &c)
Definition: BigInteger.cpp:496
std::string toHex() const
Definition: BigInteger.cpp:197
BigInteger operator+(BigInteger const &c) const
Definition: BigInteger.cpp:482