• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE Support
  • Sitemap
  • Contact Us
 

qca

bigint.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 1999-2007 The Botan Project. All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, for any use, with or without
00005 modification, is permitted provided that the following conditions are met:
00006 
00007 1. Redistributions of source code must retain the above copyright notice, this
00008 list of conditions, and the following disclaimer.
00009 
00010 2. Redistributions in binary form must reproduce the above copyright notice,
00011 this list of conditions, and the following disclaimer in the documentation
00012 and/or other materials provided with the distribution.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) "AS IS" AND ANY EXPRESS OR IMPLIED
00015 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00016 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED.
00017 
00018 IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTOR(S) BE LIABLE FOR ANY DIRECT,
00019 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00020 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00021 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00022 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00023 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00024 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 */
00026 // LICENSEHEADER_END
00027 namespace QCA { // WRAPNS_LINE
00028 /*************************************************
00029 * BigInt Header File                             *
00030 * (C) 1999-2007 The Botan Project                *
00031 *************************************************/
00032 
00033 #ifndef BOTAN_BIGINT_H__
00034 #define BOTAN_BIGINT_H__
00035 
00036 #ifdef BOTAN_MINIMAL_BIGINT
00037 } // WRAPNS_LINE
00038 # include <botan/secmem.h>
00039 namespace QCA { // WRAPNS_LINE
00040 } // WRAPNS_LINE
00041 # include <botan/exceptn.h>
00042 namespace QCA { // WRAPNS_LINE
00043 #else
00044 } // WRAPNS_LINE
00045 # include <botan/base.h>
00046 namespace QCA { // WRAPNS_LINE
00047 #endif
00048 
00049 } // WRAPNS_LINE
00050 #include <botan/mp_types.h>
00051 namespace QCA { // WRAPNS_LINE
00052 } // WRAPNS_LINE
00053 #include <iosfwd>
00054 namespace QCA { // WRAPNS_LINE
00055 
00056 namespace Botan {
00057 
00058 /*************************************************
00059 * BigInt                                         *
00060 *************************************************/
00061 class BigInt
00062    {
00063    public:
00064       enum Base { Octal = 8, Decimal = 10, Hexadecimal = 16, Binary = 256 };
00065       enum Sign { Negative = 0, Positive = 1 };
00066       enum NumberType { Random, Power2 };
00067 
00068       struct DivideByZero : public Exception
00069          { DivideByZero() : Exception("BigInt divide by zero") {} };
00070 
00071       BigInt& operator+=(const BigInt&);
00072       BigInt& operator-=(const BigInt&);
00073 
00074       BigInt& operator*=(const BigInt&);
00075       BigInt& operator/=(const BigInt&);
00076       BigInt& operator%=(const BigInt&);
00077       word    operator%=(word);
00078       BigInt& operator<<=(u32bit);
00079       BigInt& operator>>=(u32bit);
00080 
00081       BigInt& operator++() { return (*this += 1); }
00082       BigInt& operator--() { return (*this -= 1); }
00083       BigInt  operator++(int) { BigInt x = (*this); ++(*this); return x; }
00084       BigInt  operator--(int) { BigInt x = (*this); --(*this); return x; }
00085 
00086       BigInt operator-() const;
00087       bool operator !() const { return (!is_nonzero()); }
00088 
00089       s32bit cmp(const BigInt&, bool = true) const;
00090       bool is_even() const { return (get_bit(0) == 0); }
00091       bool is_odd()  const { return (get_bit(0) == 1); }
00092       bool is_nonzero() const { return (!is_zero()); }
00093       bool is_zero() const;
00094 
00095       void set_bit(u32bit);
00096       void clear_bit(u32bit);
00097       void mask_bits(u32bit);
00098 
00099       bool get_bit(u32bit) const;
00100       u32bit get_substring(u32bit, u32bit) const;
00101       byte byte_at(u32bit) const;
00102       word word_at(u32bit n) const
00103          { return ((n < size()) ? reg[n] : 0); }
00104 
00105       u32bit to_u32bit() const;
00106 
00107       bool is_negative() const { return (sign() == Negative); }
00108       bool is_positive() const { return (sign() == Positive); }
00109       Sign sign() const { return (signedness); }
00110       Sign reverse_sign() const;
00111       void flip_sign();
00112       void set_sign(Sign);
00113       BigInt abs() const;
00114 
00115       u32bit size() const { return reg.size(); }
00116       u32bit sig_words() const;
00117       u32bit bytes() const;
00118       u32bit bits() const;
00119 
00120       const word* data() const { return reg.begin(); }
00121       SecureVector<word>& get_reg() { return reg; }
00122       void grow_reg(u32bit) const;
00123 
00124       word& operator[](u32bit index) { return reg[index]; }
00125       word operator[](u32bit index) const { return reg[index]; }
00126       void clear() { reg.clear(); }
00127 
00128 #ifndef BOTAN_MINIMAL_BIGINT
00129       void randomize(u32bit = 0);
00130 #endif
00131 
00132       void binary_encode(byte[]) const;
00133       void binary_decode(const byte[], u32bit);
00134       u32bit encoded_size(Base = Binary) const;
00135 
00136       static SecureVector<byte> encode(const BigInt&, Base = Binary);
00137       static void encode(byte[], const BigInt&, Base = Binary);
00138       static BigInt decode(const byte[], u32bit, Base = Binary);
00139       static BigInt decode(const MemoryRegion<byte>&, Base = Binary);
00140       static SecureVector<byte> encode_1363(const BigInt&, u32bit);
00141 
00142       void swap(BigInt&);
00143 
00144       BigInt() { signedness = Positive; }
00145       BigInt(u64bit);
00146       BigInt(const BigInt&);
00147       BigInt(const std::string&);
00148       BigInt(const byte[], u32bit, Base = Binary);
00149       BigInt(Sign, u32bit);
00150 #ifndef BOTAN_MINIMAL_BIGINT
00151       BigInt(NumberType, u32bit);
00152 #endif
00153    private:
00154       void grow_to(u32bit) const;
00155       SecureVector<word> reg;
00156       Sign signedness;
00157    };
00158 
00159 /*************************************************
00160 * Arithmetic Operators                           *
00161 *************************************************/
00162 BigInt operator+(const BigInt&, const BigInt&);
00163 BigInt operator-(const BigInt&, const BigInt&);
00164 BigInt operator*(const BigInt&, const BigInt&);
00165 BigInt operator/(const BigInt&, const BigInt&);
00166 BigInt operator%(const BigInt&, const BigInt&);
00167 word   operator%(const BigInt&, word);
00168 BigInt operator<<(const BigInt&, u32bit);
00169 BigInt operator>>(const BigInt&, u32bit);
00170 
00171 /*************************************************
00172 * Comparison Operators                           *
00173 *************************************************/
00174 inline bool operator==(const BigInt& a, const BigInt& b)
00175    { return (a.cmp(b) == 0); }
00176 inline bool operator!=(const BigInt& a, const BigInt& b)
00177    { return (a.cmp(b) != 0); }
00178 inline bool operator<=(const BigInt& a, const BigInt& b)
00179    { return (a.cmp(b) <= 0); }
00180 inline bool operator>=(const BigInt& a, const BigInt& b)
00181    { return (a.cmp(b) >= 0); }
00182 inline bool operator<(const BigInt& a, const BigInt& b)
00183    { return (a.cmp(b) < 0); }
00184 inline bool operator>(const BigInt& a, const BigInt& b)
00185    { return (a.cmp(b) > 0); }
00186 
00187 /*************************************************
00188 * I/O Operators                                  *
00189 *************************************************/
00190 #ifndef BOTAN_MINIMAL_BIGINT
00191 std::ostream& operator<<(std::ostream&, const BigInt&);
00192 std::istream& operator>>(std::istream&, BigInt&);
00193 #endif
00194 
00195 }
00196 
00197 #ifndef BOTAN_MINIMAL_BIGINT
00198 } // WRAPNS_LINE
00199 namespace std {
00200 
00201 inline void swap(Botan::BigInt& a, Botan::BigInt& b) { a.swap(b); }
00202 
00203 }
00204 namespace QCA { // WRAPNS_LINE
00205 #endif
00206 
00207 #endif
00208 } // WRAPNS_LINE

qca

Skip menu "qca"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE Support

Skip menu "KDE Support"
  • akonadi
  • Decibel
  • grantlee
  • kdewin
  • phonon
  •     Backend
  • polkit-qt
  • qca
  • qimageblitz
  • soprano
  • strigi
  •     searchclient
  •     streamanalyzer
  •     streams
Generated for KDE Support by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal