The unified diff between revisions [90deb244..] and [b3f30c54..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'src/big_base.cpp'
#
#
# patch "src/big_base.cpp"
# from [0e889535d578b076a1658120398b1b12125eb59d]
# to [49d72ebee65b11eb77fa3b7bf209e9db372b6e04]
#
============================================================
--- src/big_base.cpp 0e889535d578b076a1658120398b1b12125eb59d
+++ src/big_base.cpp 49d72ebee65b11eb77fa3b7bf209e9db372b6e04
@@ -1,11 +1,11 @@
/*************************************************
* BigInt Base Source File *
-* (C) 1999-2007 The Botan Project *
+* (C) 1999-2007 Jack Lloyd *
*************************************************/
#include <botan/bigint.h>
#include <botan/mp_core.h>
-#include <botan/bit_ops.h>
+#include <botan/loadstor.h>
#include <botan/parsing.h>
#include <botan/util.h>
@@ -25,7 +25,7 @@ BigInt::BigInt(u64bit n)
reg.create(4*limbs_needed);
for(u32bit j = 0; j != limbs_needed; ++j)
- reg[j] = (word)((n >> (j*MP_WORD_BITS)) & MP_WORD_MASK);
+ reg[j] = ((n >> (j*MP_WORD_BITS)) & MP_WORD_MASK);
}
/*************************************************
@@ -73,7 +73,7 @@ BigInt::BigInt(const std::string& str)
else if(str.length() > markers + 1 && str[markers] == '0')
{ markers += 1; base = Octal; }
- *this = decode((const byte*)str.data() + markers,
+ *this = decode(reinterpret_cast<const byte*>(str.data()) + markers,
str.length() - markers, base);
if(negative) set_sign(Negative);
@@ -191,7 +191,7 @@ void BigInt::set_bit(u32bit n)
void BigInt::set_bit(u32bit n)
{
const u32bit which = n / MP_WORD_BITS;
- const word mask = (word)1 << (n % MP_WORD_BITS);
+ const word mask = static_cast<word>(1) << (n % MP_WORD_BITS);
if(which >= size()) grow_to(which + 1);
reg[which] |= mask;
}
@@ -202,7 +202,7 @@ void BigInt::clear_bit(u32bit n)
void BigInt::clear_bit(u32bit n)
{
const u32bit which = n / MP_WORD_BITS;
- const word mask = (word)1 << (n % MP_WORD_BITS);
+ const word mask = static_cast<word>(1) << (n % MP_WORD_BITS);
if(which < size())
reg[which] &= ~mask;
}
@@ -216,7 +216,7 @@ void BigInt::mask_bits(u32bit n)
if(n >= bits()) return;
const u32bit top_word = n / MP_WORD_BITS;
- const word mask = ((word)1 << (n % MP_WORD_BITS)) - 1;
+ const word mask = (static_cast<word>(1) << (n % MP_WORD_BITS)) - 1;
if(top_word < size())
for(u32bit j = top_word + 1; j != size(); ++j)
@@ -283,7 +283,7 @@ u32bit BigInt::encoded_size(Base base) c
else if(base == Octal)
return ((bits() + 2) / 3);
else if(base == Decimal)
- return (u32bit)((bits() * LOG_2_BASE_10) + 1);
+ return static_cast<u32bit>((bits() * LOG_2_BASE_10) + 1);
else
throw Invalid_Argument("Unknown base for BigInt encoding");
}
@@ -338,6 +338,23 @@ BigInt BigInt::operator-() const
}
/*************************************************
+* Return a reference to the indexed word *
+*************************************************/
+word& BigInt::operator[](u32bit index)
+ {
+ reg.grow_to(index+1);
+ return reg[index];
+ }
+
+/*************************************************
+* Return the value of the indexed word *
+*************************************************/
+word BigInt::operator[](u32bit index) const
+ {
+ return (index < size()) ? reg[index] : 0;
+ }
+
+/*************************************************
* Return the absolute value of this number *
*************************************************/
BigInt BigInt::abs() const
@@ -375,4 +392,12 @@ void BigInt::binary_decode(const byte bu
reg[length / WORD_BYTES] = (reg[length / WORD_BYTES] << 8) | buf[j];
}
+/*************************************************
+* Set this number to the value in buf *
+*************************************************/
+void BigInt::binary_decode(const MemoryRegion<byte>& buf)
+ {
+ binary_decode(buf, buf.size());
+ }
+
}