Botan  2.7.0
Crypto and TLS for C++11
bigint.h
Go to the documentation of this file.
1 /*
2 * BigInt
3 * (C) 1999-2008,2012 Jack Lloyd
4 * 2007 FlexSecure
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8 
9 #ifndef BOTAN_BIGINT_H_
10 #define BOTAN_BIGINT_H_
11 
12 #include <botan/types.h>
13 #include <botan/secmem.h>
14 #include <botan/exceptn.h>
15 #include <botan/loadstor.h>
16 #include <iosfwd>
17 
18 namespace Botan {
19 
20 class RandomNumberGenerator;
21 
22 /**
23 * Arbitrary precision integer
24 */
25 class BOTAN_PUBLIC_API(2,0) BigInt final
26  {
27  public:
28  /**
29  * Base enumerator for encoding and decoding
30  */
31  enum Base { Decimal = 10, Hexadecimal = 16, Binary = 256 };
32 
33  /**
34  * Sign symbol definitions for positive and negative numbers
35  */
36  enum Sign { Negative = 0, Positive = 1 };
37 
38  /**
39  * DivideByZero Exception
40  */
41  class BOTAN_PUBLIC_API(2,0) DivideByZero final : public Exception
42  {
43  public:
44  DivideByZero() : Exception("BigInt divide by zero") {}
45  };
46 
47  /**
48  * Create empty BigInt
49  */
50  BigInt() = default;
51 
52  /**
53  * Create BigInt from 64 bit integer
54  * @param n initial value of this BigInt
55  */
56  BigInt(uint64_t n);
57 
58  /**
59  * Copy Constructor
60  * @param other the BigInt to copy
61  */
62  BigInt(const BigInt& other);
63 
64  /**
65  * Create BigInt from a string. If the string starts with 0x the
66  * rest of the string will be interpreted as hexadecimal digits.
67  * Otherwise, it will be interpreted as a decimal number.
68  *
69  * @param str the string to parse for an integer value
70  */
71  explicit BigInt(const std::string& str);
72 
73  /**
74  * Create a BigInt from an integer in a byte array
75  * @param buf the byte array holding the value
76  * @param length size of buf
77  */
78  BigInt(const uint8_t buf[], size_t length);
79 
80  /**
81  * Create a BigInt from an integer in a byte array
82  * @param buf the byte array holding the value
83  * @param length size of buf
84  * @param base is the number base of the integer in buf
85  */
86  BigInt(const uint8_t buf[], size_t length, Base base);
87 
88  /**
89  * Create a BigInt from an integer in a byte array
90  * @param buf the byte array holding the value
91  * @param length size of buf
92  * @param max_bits if the resulting integer is more than max_bits,
93  * it will be shifted so it is at most max_bits in length.
94  */
95  BigInt(const uint8_t buf[], size_t length, size_t max_bits);
96 
97  /**
98  * Create a BigInt from an array of words
99  * @param words the words
100  * @param length number of words
101  */
102  BigInt(const word words[], size_t length);
103 
104  /**
105  * \brief Create a random BigInt of the specified size
106  *
107  * @param rng random number generator
108  * @param bits size in bits
109  * @param set_high_bit if true, the highest bit is always set
110  *
111  * @see randomize
112  */
113  BigInt(RandomNumberGenerator& rng, size_t bits, bool set_high_bit = true);
114 
115  /**
116  * Create BigInt of specified size, all zeros
117  * @param sign the sign
118  * @param n size of the internal register in words
119  */
120  BigInt(Sign sign, size_t n);
121 
122  /**
123  * Move constructor
124  */
125  BigInt(BigInt&& other)
126  {
127  this->swap(other);
128  }
129 
130  /**
131  * Move assignment
132  */
134  {
135  if(this != &other)
136  this->swap(other);
137 
138  return (*this);
139  }
140 
141  /**
142  * Copy assignment
143  */
144  BigInt& operator=(const BigInt&) = default;
145 
146  /**
147  * Swap this value with another
148  * @param other BigInt to swap values with
149  */
150  void swap(BigInt& other)
151  {
152  m_reg.swap(other.m_reg);
153  std::swap(m_signedness, other.m_signedness);
154  }
155 
157  {
158  m_reg.swap(reg);
159  }
160 
161  /**
162  * += operator
163  * @param y the BigInt to add to this
164  */
165  BigInt& operator+=(const BigInt& y);
166 
167  /**
168  * += operator
169  * @param y the word to add to this
170  */
171  BigInt& operator+=(word y);
172 
173  /**
174  * -= operator
175  * @param y the BigInt to subtract from this
176  */
177  BigInt& operator-=(const BigInt& y);
178 
179  /**
180  * -= operator
181  * @param y the word to subtract from this
182  */
183  BigInt& operator-=(word y);
184 
185  /**
186  * *= operator
187  * @param y the BigInt to multiply with this
188  */
189  BigInt& operator*=(const BigInt& y);
190 
191  /**
192  * *= operator
193  * @param y the word to multiply with this
194  */
195  BigInt& operator*=(word y);
196 
197  /**
198  * /= operator
199  * @param y the BigInt to divide this by
200  */
201  BigInt& operator/=(const BigInt& y);
202 
203  /**
204  * Modulo operator
205  * @param y the modulus to reduce this by
206  */
207  BigInt& operator%=(const BigInt& y);
208 
209  /**
210  * Modulo operator
211  * @param y the modulus (word) to reduce this by
212  */
213  word operator%=(word y);
214 
215  /**
216  * Left shift operator
217  * @param shift the number of bits to shift this left by
218  */
219  BigInt& operator<<=(size_t shift);
220 
221  /**
222  * Right shift operator
223  * @param shift the number of bits to shift this right by
224  */
225  BigInt& operator>>=(size_t shift);
226 
227  /**
228  * Increment operator
229  */
230  BigInt& operator++() { return (*this += 1); }
231 
232  /**
233  * Decrement operator
234  */
235  BigInt& operator--() { return (*this -= 1); }
236 
237  /**
238  * Postfix increment operator
239  */
240  BigInt operator++(int) { BigInt x = (*this); ++(*this); return x; }
241 
242  /**
243  * Postfix decrement operator
244  */
245  BigInt operator--(int) { BigInt x = (*this); --(*this); return x; }
246 
247  /**
248  * Unary negation operator
249  * @return negative this
250  */
251  BigInt operator-() const;
252 
253  /**
254  * ! operator
255  * @return true iff this is zero, otherwise false
256  */
257  bool operator !() const { return (!is_nonzero()); }
258 
259  BigInt& add(const word y[], size_t y_words, Sign sign);
260  BigInt& sub(const word y[], size_t y_words, Sign sign);
261 
262  /**
263  * Multiply this with y
264  * @param y the BigInt to multiply with this
265  * @param ws a temp workspace
266  */
267  BigInt& mul(const BigInt& y, secure_vector<word>& ws);
268 
269  /**
270  * Square value of *this
271  * @param ws a temp workspace
272  */
274 
275  /**
276  * Set *this to y - *this
277  * @param y the BigInt to subtract from as a sequence of words
278  * @param y_size length of y in words
279  * @param ws a temp workspace
280  */
281  BigInt& rev_sub(const word y[], size_t y_size, secure_vector<word>& ws);
282 
283  /**
284  * Set *this to (*this + y) % mod
285  * This function assumes *this is >= 0 && < mod
286  * @param y the BigInt to add - assumed y >= 0 and y < mod
287  * @param mod the positive modulus
288  * @param ws a temp workspace
289  */
290  BigInt& mod_add(const BigInt& y, const BigInt& mod, secure_vector<word>& ws);
291 
292  /**
293  * Set *this to (*this - y) % mod
294  * This function assumes *this is >= 0 && < mod
295  * @param y the BigInt to subtract - assumed y >= 0 and y < mod
296  * @param mod the positive modulus
297  * @param ws a temp workspace
298  */
299  BigInt& mod_sub(const BigInt& y, const BigInt& mod, secure_vector<word>& ws);
300 
301  /**
302  * Return *this below mod
303  *
304  * Assumes that *this is (if anything) only slightly larger than
305  * mod and performs repeated subtractions. It should not be used if
306  * *this is much larger than mod, instead of modulo operator.
307  */
308  void reduce_below(const BigInt& mod, secure_vector<word> &ws);
309 
310  /**
311  * Zeroize the BigInt. The size of the underlying register is not
312  * modified.
313  */
314  void clear() { zeroise(m_reg); }
315 
316  /**
317  * Compare this to another BigInt
318  * @param n the BigInt value to compare with
319  * @param check_signs include sign in comparison?
320  * @result if (this<n) return -1, if (this>n) return 1, if both
321  * values are identical return 0 [like Perl's <=> operator]
322  */
323  int32_t cmp(const BigInt& n, bool check_signs = true) const;
324 
325  /**
326  * Compare this to an integer
327  * @param n the value to compare with
328  * @result if (this<n) return -1, if (this>n) return 1, if both
329  * values are identical return 0 [like Perl's <=> operator]
330  */
331  int32_t cmp_word(word n) const;
332 
333  /**
334  * Test if the integer has an even value
335  * @result true if the integer is even, false otherwise
336  */
337  bool is_even() const { return (get_bit(0) == 0); }
338 
339  /**
340  * Test if the integer has an odd value
341  * @result true if the integer is odd, false otherwise
342  */
343  bool is_odd() const { return (get_bit(0) == 1); }
344 
345  /**
346  * Test if the integer is not zero
347  * @result true if the integer is non-zero, false otherwise
348  */
349  bool is_nonzero() const { return (!is_zero()); }
350 
351  /**
352  * Test if the integer is zero
353  * @result true if the integer is zero, false otherwise
354  */
355  bool is_zero() const
356  {
357  const size_t sw = sig_words();
358 
359  for(size_t i = 0; i != sw; ++i)
360  if(m_reg[i])
361  return false;
362  return true;
363  }
364 
365  /**
366  * Set bit at specified position
367  * @param n bit position to set
368  */
369  void set_bit(size_t n);
370 
371  /**
372  * Clear bit at specified position
373  * @param n bit position to clear
374  */
375  void clear_bit(size_t n);
376 
377  /**
378  * Clear all but the lowest n bits
379  * @param n amount of bits to keep
380  */
381  void mask_bits(size_t n)
382  {
383  if(n == 0) { clear(); return; }
384 
385  const size_t top_word = n / BOTAN_MP_WORD_BITS;
386  const word mask = (static_cast<word>(1) << (n % BOTAN_MP_WORD_BITS)) - 1;
387 
388  if(top_word < size())
389  {
390  const size_t len = size() - (top_word + 1);
391  if (len > 0)
392  {
393  clear_mem(&m_reg[top_word+1], len);
394  }
395  m_reg[top_word] &= mask;
396  }
397  }
398 
399  /**
400  * Return bit value at specified position
401  * @param n the bit offset to test
402  * @result true, if the bit at position n is set, false otherwise
403  */
404  bool get_bit(size_t n) const
405  {
406  return ((word_at(n / BOTAN_MP_WORD_BITS) >> (n % BOTAN_MP_WORD_BITS)) & 1);
407  }
408 
409  /**
410  * Return (a maximum of) 32 bits of the complete value
411  * @param offset the offset to start extracting
412  * @param length amount of bits to extract (starting at offset)
413  * @result the integer extracted from the register starting at
414  * offset with specified length
415  */
416  uint32_t get_substring(size_t offset, size_t length) const;
417 
418  /**
419  * Convert this value into a uint32_t, if it is in the range
420  * [0 ... 2**32-1], or otherwise throw an exception.
421  * @result the value as a uint32_t if conversion is possible
422  */
423  uint32_t to_u32bit() const;
424 
425  /**
426  * @param n the offset to get a byte from
427  * @result byte at offset n
428  */
429  uint8_t byte_at(size_t n) const
430  {
431  return get_byte(sizeof(word) - (n % sizeof(word)) - 1,
432  word_at(n / sizeof(word)));
433  }
434 
435  /**
436  * Return the word at a specified position of the internal register
437  * @param n position in the register
438  * @return value at position n
439  */
440  word word_at(size_t n) const
441  { return ((n < size()) ? m_reg[n] : 0); }
442 
443  void set_word_at(size_t i, word w)
444  {
445  if(i >= m_reg.size())
446  grow_to(i + 1);
447  m_reg[i] = w;
448  }
449 
450  void set_words(const word w[], size_t len)
451  {
452  m_reg.resize(len);
453  copy_mem(mutable_data(), w, len);
454  }
455 
456  /**
457  * Tests if the sign of the integer is negative
458  * @result true, iff the integer has a negative sign
459  */
460  bool is_negative() const { return (sign() == Negative); }
461 
462  /**
463  * Tests if the sign of the integer is positive
464  * @result true, iff the integer has a positive sign
465  */
466  bool is_positive() const { return (sign() == Positive); }
467 
468  /**
469  * Return the sign of the integer
470  * @result the sign of the integer
471  */
472  Sign sign() const { return (m_signedness); }
473 
474  /**
475  * @result the opposite sign of the represented integer value
476  */
478  {
479  if(sign() == Positive)
480  return Negative;
481  return Positive;
482  }
483 
484  /**
485  * Flip the sign of this BigInt
486  */
487  void flip_sign()
488  {
489  set_sign(reverse_sign());
490  }
491 
492  /**
493  * Set sign of the integer
494  * @param sign new Sign to set
495  */
496  void set_sign(Sign sign)
497  {
498  if(is_zero())
499  m_signedness = Positive;
500  else
501  m_signedness = sign;
502  }
503 
504  /**
505  * @result absolute (positive) value of this
506  */
507  BigInt abs() const;
508 
509  /**
510  * Give size of internal register
511  * @result size of internal register in words
512  */
513  size_t size() const { return m_reg.size(); }
514 
515  /**
516  * Return how many words we need to hold this value
517  * @result significant words of the represented integer value
518  */
519  size_t sig_words() const
520  {
521  const word* x = m_reg.data();
522  size_t sig = m_reg.size();
523 
524  while(sig && (x[sig-1] == 0))
525  sig--;
526  return sig;
527  }
528 
529  /**
530  * Give byte length of the integer
531  * @result byte length of the represented integer value
532  */
533  size_t bytes() const;
534 
535  /**
536  * Get the bit length of the integer
537  * @result bit length of the represented integer value
538  */
539  size_t bits() const;
540 
541  /**
542  * Return a mutable pointer to the register
543  * @result a pointer to the start of the internal register
544  */
545  word* mutable_data() { return m_reg.data(); }
546 
547  /**
548  * Return a const pointer to the register
549  * @result a pointer to the start of the internal register
550  */
551  const word* data() const { return m_reg.data(); }
552 
554  const secure_vector<word>& get_word_vector() const { return m_reg; }
555 
556  /**
557  * Increase internal register buffer to at least n words
558  * @param n new size of register
559  */
560  void grow_to(size_t n);
561 
562  /**
563  * Resize the vector to the minimum word size to hold the integer, or
564  * min_size words, whichever is larger
565  */
566  void shrink_to_fit(size_t min_size = 0)
567  {
568  const size_t words = std::max(min_size, sig_words());
569  m_reg.resize(words);
570  }
571 
572  /**
573  * Fill BigInt with a random number with size of bitsize
574  *
575  * If \p set_high_bit is true, the highest bit will be set, which causes
576  * the entropy to be \a bits-1. Otherwise the highest bit is randomly chosen
577  * by the rng, causing the entropy to be \a bits.
578  *
579  * @param rng the random number generator to use
580  * @param bitsize number of bits the created random value should have
581  * @param set_high_bit if true, the highest bit is always set
582  */
583  void randomize(RandomNumberGenerator& rng, size_t bitsize, bool set_high_bit = true);
584 
585  /**
586  * Store BigInt-value in a given byte array
587  * @param buf destination byte array for the integer value
588  */
589  void binary_encode(uint8_t buf[]) const;
590 
591  /**
592  * Read integer value from a byte array with given size
593  * @param buf byte array buffer containing the integer
594  * @param length size of buf
595  */
596  void binary_decode(const uint8_t buf[], size_t length);
597 
598  /**
599  * Read integer value from a byte array (secure_vector<uint8_t>)
600  * @param buf the array to load from
601  */
603  {
604  binary_decode(buf.data(), buf.size());
605  }
606 
607  /**
608  * @param base the base to measure the size for
609  * @return size of this integer in base base
610  */
611  size_t encoded_size(Base base = Binary) const;
612 
613  /**
614  * Place the value into out, zero-padding up to size words
615  * Throw if *this cannot be represented in size words
616  */
617  void encode_words(word out[], size_t size) const;
618 
619 #if defined(BOTAN_HAS_VALGRIND)
620  void const_time_poison() const;
621  void const_time_unpoison() const;
622 #else
623  void const_time_poison() const {}
624  void const_time_unpoison() const {}
625 #endif
626 
627  /**
628  * @param rng a random number generator
629  * @param min the minimum value (must be non-negative)
630  * @param max the maximum value (must be non-negative and > min)
631  * @return random integer in [min,max)
632  */
633  static BigInt random_integer(RandomNumberGenerator& rng,
634  const BigInt& min,
635  const BigInt& max);
636 
637  /**
638  * Create a power of two
639  * @param n the power of two to create
640  * @return bigint representing 2^n
641  */
642  static BigInt power_of_2(size_t n)
643  {
644  BigInt b;
645  b.set_bit(n);
646  return b;
647  }
648 
649  /**
650  * Encode the integer value from a BigInt to a std::vector of bytes
651  * @param n the BigInt to use as integer source
652  * @param base number-base of resulting byte array representation
653  * @result secure_vector of bytes containing the integer with given base
654  */
655  static std::vector<uint8_t> encode(const BigInt& n, Base base = Binary);
656 
657  /**
658  * Encode the integer value from a BigInt to a secure_vector of bytes
659  * @param n the BigInt to use as integer source
660  * @param base number-base of resulting byte array representation
661  * @result secure_vector of bytes containing the integer with given base
662  */
663  static secure_vector<uint8_t> encode_locked(const BigInt& n,
664  Base base = Binary);
665 
666  /**
667  * Encode the integer value from a BigInt to a byte array
668  * @param buf destination byte array for the encoded integer
669  * value with given base
670  * @param n the BigInt to use as integer source
671  * @param base number-base of resulting byte array representation
672  */
673  static void encode(uint8_t buf[], const BigInt& n, Base base = Binary);
674 
675  /**
676  * Create a BigInt from an integer in a byte array
677  * @param buf the binary value to load
678  * @param length size of buf
679  * @param base number-base of the integer in buf
680  * @result BigInt representing the integer in the byte array
681  */
682  static BigInt decode(const uint8_t buf[], size_t length,
683  Base base = Binary);
684 
685  /**
686  * Create a BigInt from an integer in a byte array
687  * @param buf the binary value to load
688  * @param base number-base of the integer in buf
689  * @result BigInt representing the integer in the byte array
690  */
692  Base base = Binary)
693  {
694  return BigInt::decode(buf.data(), buf.size(), base);
695  }
696 
697  /**
698  * Create a BigInt from an integer in a byte array
699  * @param buf the binary value to load
700  * @param base number-base of the integer in buf
701  * @result BigInt representing the integer in the byte array
702  */
703  static BigInt decode(const std::vector<uint8_t>& buf,
704  Base base = Binary)
705  {
706  return BigInt::decode(buf.data(), buf.size(), base);
707  }
708 
709  /**
710  * Encode a BigInt to a byte array according to IEEE 1363
711  * @param n the BigInt to encode
712  * @param bytes the length of the resulting secure_vector<uint8_t>
713  * @result a secure_vector<uint8_t> containing the encoded BigInt
714  */
715  static secure_vector<uint8_t> encode_1363(const BigInt& n, size_t bytes);
716 
717  static void encode_1363(uint8_t out[], size_t bytes, const BigInt& n);
718 
719  /**
720  * Encode two BigInt to a byte array according to IEEE 1363
721  * @param n1 the first BigInt to encode
722  * @param n2 the second BigInt to encode
723  * @param bytes the length of the encoding of each single BigInt
724  * @result a secure_vector<uint8_t> containing the concatenation of the two encoded BigInt
725  */
726  static secure_vector<uint8_t> encode_fixed_length_int_pair(const BigInt& n1, const BigInt& n2, size_t bytes);
727 
728  /**
729  * Set output = vec[idx].m_reg in constant time
730  * All words of vec must have the same size
731  */
732  static void const_time_lookup(
733  secure_vector<word>& output,
734  const std::vector<BigInt>& vec,
735  size_t idx);
736 
737  private:
738  secure_vector<word> m_reg;
739  Sign m_signedness = Positive;
740  };
741 
742 /*
743 * Arithmetic Operators
744 */
745 BigInt BOTAN_PUBLIC_API(2,0) operator+(const BigInt& x, const BigInt& y);
746 BigInt BOTAN_PUBLIC_API(2,7) operator+(const BigInt& x, word y);
747 inline BigInt operator+(word x, const BigInt& y) { return y + x; }
748 
749 BigInt BOTAN_PUBLIC_API(2,0) operator-(const BigInt& x, const BigInt& y);
750 BigInt BOTAN_PUBLIC_API(2,7) operator-(const BigInt& x, word y);
751 
752 BigInt BOTAN_PUBLIC_API(2,0) operator*(const BigInt& x, const BigInt& y);
753 BigInt BOTAN_PUBLIC_API(2,0) operator/(const BigInt& x, const BigInt& d);
754 BigInt BOTAN_PUBLIC_API(2,0) operator%(const BigInt& x, const BigInt& m);
755 word BOTAN_PUBLIC_API(2,0) operator%(const BigInt& x, word m);
756 BigInt BOTAN_PUBLIC_API(2,0) operator<<(const BigInt& x, size_t n);
757 BigInt BOTAN_PUBLIC_API(2,0) operator>>(const BigInt& x, size_t n);
758 
759 /*
760 * Comparison Operators
761 */
762 inline bool operator==(const BigInt& a, const BigInt& b)
763  { return (a.cmp(b) == 0); }
764 inline bool operator!=(const BigInt& a, const BigInt& b)
765  { return (a.cmp(b) != 0); }
766 inline bool operator<=(const BigInt& a, const BigInt& b)
767  { return (a.cmp(b) <= 0); }
768 inline bool operator>=(const BigInt& a, const BigInt& b)
769  { return (a.cmp(b) >= 0); }
770 inline bool operator<(const BigInt& a, const BigInt& b)
771  { return (a.cmp(b) < 0); }
772 inline bool operator>(const BigInt& a, const BigInt& b)
773  { return (a.cmp(b) > 0); }
774 
775 inline bool operator==(const BigInt& a, word b)
776  { return (a.cmp_word(b) == 0); }
777 inline bool operator!=(const BigInt& a, word b)
778  { return (a.cmp_word(b) != 0); }
779 inline bool operator<=(const BigInt& a, word b)
780  { return (a.cmp_word(b) <= 0); }
781 inline bool operator>=(const BigInt& a, word b)
782  { return (a.cmp_word(b) >= 0); }
783 inline bool operator<(const BigInt& a, word b)
784  { return (a.cmp_word(b) < 0); }
785 inline bool operator>(const BigInt& a, word b)
786  { return (a.cmp_word(b) > 0); }
787 
788 /*
789 * I/O Operators
790 */
791 BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream&, const BigInt&);
792 BOTAN_PUBLIC_API(2,0) std::istream& operator>>(std::istream&, BigInt&);
793 
794 }
795 
796 namespace std {
797 
798 template<>
799 inline void swap<Botan::BigInt>(Botan::BigInt& x, Botan::BigInt& y)
800  {
801  x.swap(y);
802  }
803 
804 }
805 
806 #endif
bool get_bit(size_t n) const
Definition: bigint.h:404
bool operator!=(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:90
bool is_negative() const
Definition: bigint.h:460
BigInt(BigInt &&other)
Definition: bigint.h:125
BigInt operator--(int)
Definition: bigint.h:245
bool operator>=(const X509_Time &t1, const X509_Time &t2)
Definition: asn1_time.cpp:275
BigInt & operator--()
Definition: bigint.h:235
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:131
void clear_mem(T *ptr, size_t n)
Definition: mem_ops.h:97
const secure_vector< word > & get_word_vector() const
Definition: bigint.h:554
void set_bit(size_t n)
Definition: bigint.cpp:201
Sign sign() const
Definition: bigint.h:472
secure_vector< word > & get_word_vector()
Definition: bigint.h:553
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
bool is_zero() const
Definition: bigint.h:355
Definition: bigint.h:796
static BigInt decode(const std::vector< uint8_t > &buf, Base base=Binary)
Definition: bigint.h:703
word * mutable_data()
Definition: bigint.h:545
void swap_reg(secure_vector< word > &reg)
Definition: bigint.h:156
BigInt operator-(const BigInt &x, const BigInt &y)
Definition: big_ops3.cpp:90
bool is_even() const
Definition: bigint.h:337
static BigInt decode(const secure_vector< uint8_t > &buf, Base base=Binary)
Definition: bigint.h:691
void swap(BigInt &other)
Definition: bigint.h:150
bool is_nonzero() const
Definition: bigint.h:349
uint32_t to_u32bit(const std::string &str)
Definition: parsing.cpp:31
word word_at(size_t n) const
Definition: bigint.h:440
void mask_bits(size_t n)
Definition: bigint.h:381
const word * data() const
Definition: bigint.h:551
BigInt & operator++()
Definition: bigint.h:230
uint8_t byte_at(size_t n) const
Definition: bigint.h:429
void const_time_poison() const
Definition: bigint.h:623
bool operator<(const OID &a, const OID &b)
Definition: asn1_oid.cpp:105
BigInt abs(const BigInt &n)
Definition: numthry.h:55
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
void binary_decode(const secure_vector< uint8_t > &buf)
Definition: bigint.h:602
BigInt operator++(int)
Definition: bigint.h:240
int32_t cmp_word(word n) const
Definition: bigint.cpp:116
bool is_odd() const
Definition: bigint.h:343
BigInt square(const BigInt &x)
Definition: mp_numth.cpp:19
std::vector< T, Alloc > & operator+=(std::vector< T, Alloc > &out, const std::vector< T, Alloc2 > &in)
Definition: secmem.h:133
Sign reverse_sign() const
Definition: bigint.h:477
size_t size() const
Definition: bigint.h:513
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:68
void set_words(const word w[], size_t len)
Definition: bigint.h:450
static BigInt power_of_2(size_t n)
Definition: bigint.h:642
void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:108
Definition: alg_id.cpp:13
size_t sig_words() const
Definition: bigint.h:519
void clear()
Definition: bigint.h:314
T is_zero(T x)
Definition: ct_utils.h:130
void const_time_unpoison() const
Definition: bigint.h:624
void set_word_at(size_t i, word w)
Definition: bigint.h:443
uint8_t get_byte(size_t byte_num, T input)
Definition: loadstor.h:39
BigInt & operator=(BigInt &&other)
Definition: bigint.h:133
bool operator==(const AlgorithmIdentifier &a1, const AlgorithmIdentifier &a2)
Definition: alg_id.cpp:75
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
void flip_sign()
Definition: bigint.h:487
void shrink_to_fit(size_t min_size=0)
Definition: bigint.h:566
bool operator>(const X509_Time &t1, const X509_Time &t2)
Definition: asn1_time.cpp:280
void set_sign(Sign sign)
Definition: bigint.h:496
bool is_positive() const
Definition: bigint.h:466
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114
bool operator<=(const X509_Time &t1, const X509_Time &t2)
Definition: asn1_time.cpp:273
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:183