summaryrefslogtreecommitdiff
path: root/integer.cpp
diff options
context:
space:
mode:
authorDevJPM <DevJPM@users.noreply.github.com>2016-01-14 12:24:36 +0100
committerDevJPM <DevJPM@users.noreply.github.com>2016-01-14 12:24:36 +0100
commit07ff7b0d61bd092886d54c3f23e63947011e7952 (patch)
treed7c5d3429ce6afc088b4e0912c5b15bc2a91f5f4 /integer.cpp
parent1839fc40b3a0e886c9aeabfb31b0870aec94cef5 (diff)
downloadcryptopp-git-07ff7b0d61bd092886d54c3f23e63947011e7952.tar.gz
moved BE case before LE to improve performance
Diffstat (limited to 'integer.cpp')
-rw-r--r--integer.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/integer.cpp b/integer.cpp
index 428623c7..c5321680 100644
--- a/integer.cpp
+++ b/integer.cpp
@@ -3044,7 +3044,7 @@ Integer::Integer(word value, size_t length)
template <class T>
static Integer StringToInteger(const T *str, ByteOrder order)
{
- assert(order == LITTLE_ENDIAN_ORDER || order == BIG_ENDIAN_ORDER);
+ assert( order == BIG_ENDIAN_ORDER || order == LITTLE_ENDIAN_ORDER );
int radix, sign = 1;
// GCC workaround
@@ -3088,7 +3088,29 @@ static Integer StringToInteger(const T *str, ByteOrder order)
str += 2, length -= 2;
}
- if(radix == 16 && order == LITTLE_ENDIAN_ORDER)
+ if(order == BIG_ENDIAN_ORDER)
+ {
+ for (unsigned int i=0; i<length; i++)
+ {
+ int digit, ch = static_cast<int>(str[i]);
+
+ if (ch >= '0' && ch <= '9')
+ digit = ch - '0';
+ else if (ch >= 'A' && ch <= 'F')
+ digit = ch - 'A' + 10;
+ else if (ch >= 'a' && ch <= 'f')
+ digit = ch - 'a' + 10;
+ else
+ digit = radix;
+
+ if (digit < radix)
+ {
+ v *= radix;
+ v += digit;
+ }
+ }
+ }
+ else if(radix == 16 && order == LITTLE_ENDIAN_ORDER)
{
// Nibble high, low and count
unsigned int nh, nl, nc = 0;
@@ -3125,7 +3147,7 @@ static Integer StringToInteger(const T *str, ByteOrder order)
if(nc == 1)
v += nh * position;
}
- else if(order == LITTLE_ENDIAN_ORDER)
+ else // LITTLE_ENDIAN_ORDER && radix != 16
{
for (int i=static_cast<int>(length)-1; i>=0; i--)
{
@@ -3147,28 +3169,6 @@ static Integer StringToInteger(const T *str, ByteOrder order)
}
}
}
- else
- {
- for (unsigned int i=0; i<length; i++)
- {
- int digit, ch = static_cast<int>(str[i]);
-
- if (ch >= '0' && ch <= '9')
- digit = ch - '0';
- else if (ch >= 'A' && ch <= 'F')
- digit = ch - 'A' + 10;
- else if (ch >= 'a' && ch <= 'f')
- digit = ch - 'a' + 10;
- else
- digit = radix;
-
- if (digit < radix)
- {
- v *= radix;
- v += digit;
- }
- }
- }
if (sign == -1)
v.Negate();