aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cert/cvc/asn1_eac_tm.cpp2
-rw-r--r--src/math/bigint/bigint.cpp10
-rw-r--r--src/math/numbertheory/mp_numth.cpp2
-rw-r--r--src/utils/rounding.h20
4 files changed, 21 insertions, 13 deletions
diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp
index 51b9c7513..b048d3aa5 100644
--- a/src/cert/cvc/asn1_eac_tm.cpp
+++ b/src/cert/cvc/asn1_eac_tm.cpp
@@ -26,7 +26,7 @@ SecureVector<byte> enc_two_digit(u32bit in)
result.append(0x00);
else
{
- u32bit y_first_pos = round_down(in, 10) / 10;
+ u32bit y_first_pos = round_down<u32bit>(in, 10) / 10;
result.append(static_cast<byte>(y_first_pos));
}
diff --git a/src/math/bigint/bigint.cpp b/src/math/bigint/bigint.cpp
index 1f3255175..7feec4d59 100644
--- a/src/math/bigint/bigint.cpp
+++ b/src/math/bigint/bigint.cpp
@@ -35,7 +35,7 @@ BigInt::BigInt(u64bit n)
*/
BigInt::BigInt(Sign s, u32bit size)
{
- reg.resize(round_up(size, 8));
+ reg.resize(round_up<u32bit>(size, 8));
signedness = s;
}
@@ -48,7 +48,7 @@ BigInt::BigInt(const BigInt& b)
if(b_words)
{
- reg.resize(round_up(b_words, 8));
+ reg.resize(round_up<u32bit>(b_words, 8));
reg.copy(b.data(), b_words);
set_sign(b.sign());
}
@@ -114,7 +114,7 @@ void BigInt::swap(BigInt& other)
*/
void BigInt::grow_reg(u32bit n)
{
- reg.grow_to(round_up(size() + n, 8));
+ reg.grow_to(round_up<u32bit>(size() + n, 8));
}
/*
@@ -123,7 +123,7 @@ void BigInt::grow_reg(u32bit n)
void BigInt::grow_to(u32bit n)
{
if(n > size())
- reg.grow_to(round_up(n, 8));
+ reg.grow_to(round_up<u32bit>(n, 8));
}
/*
@@ -348,7 +348,7 @@ void BigInt::binary_decode(const byte buf[], u32bit length)
{
const u32bit WORD_BYTES = sizeof(word);
- reg.resize(round_up((length / WORD_BYTES) + 1, 8));
+ reg.resize(round_up<u32bit>((length / WORD_BYTES) + 1, 8));
for(u32bit j = 0; j != length / WORD_BYTES; ++j)
{
diff --git a/src/math/numbertheory/mp_numth.cpp b/src/math/numbertheory/mp_numth.cpp
index 03eb8d9db..4edc694e5 100644
--- a/src/math/numbertheory/mp_numth.cpp
+++ b/src/math/numbertheory/mp_numth.cpp
@@ -19,7 +19,7 @@ BigInt square(const BigInt& x)
{
const u32bit x_sw = x.sig_words();
- BigInt z(BigInt::Positive, round_up(2*x_sw, 16));
+ BigInt z(BigInt::Positive, round_up<u32bit>(2*x_sw, 16));
SecureVector<word> workspace(z.size());
bigint_sqr(z.get_reg(), z.size(), workspace,
diff --git a/src/utils/rounding.h b/src/utils/rounding.h
index 11ab90b8d..c77ab9b52 100644
--- a/src/utils/rounding.h
+++ b/src/utils/rounding.h
@@ -12,20 +12,28 @@
namespace Botan {
-/*
-* Round up n to multiple of align_to
+/**
+* Round up
+* @param n an integer
+* @param align_to the alignment boundary
+* @return n rounded up to a multiple of align_to
*/
-inline u32bit round_up(u32bit n, u32bit align_to)
+template<typename T>
+inline T round_up(T n, T align_to)
{
if(n % align_to || n == 0)
n += align_to - (n % align_to);
return n;
}
-/*
-* Round down n to multiple of align_to
+/**
+* Round down
+* @param n an integer
+* @param align_to the alignment boundary
+* @return n rounded down to a multiple of align_to
*/
-inline u32bit round_down(u32bit n, u32bit align_to)
+template<typename T>
+inline T round_down(T n, T align_to)
{
return (n - (n % align_to));
}