aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/mp
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/mp')
-rw-r--r--src/math/mp/monty_generic/mp_monty.cpp16
-rw-r--r--src/math/mp/mp_asm.cpp74
-rw-r--r--src/math/mp/mp_asm64/mp_asm.h2
-rw-r--r--src/math/mp/mp_core.h72
-rw-r--r--src/math/mp/mp_generic/mp_asm.h2
-rw-r--r--src/math/mp/mp_karat.cpp62
-rw-r--r--src/math/mp/mp_misc.cpp10
-rw-r--r--src/math/mp/mp_shift.cpp26
-rw-r--r--src/math/mp/mp_types.h2
-rw-r--r--src/math/mp/mulop_generic/mp_mulop.cpp22
10 files changed, 144 insertions, 144 deletions
diff --git a/src/math/mp/monty_generic/mp_monty.cpp b/src/math/mp/monty_generic/mp_monty.cpp
index bce35259a..d7f7e0306 100644
--- a/src/math/mp/monty_generic/mp_monty.cpp
+++ b/src/math/mp/monty_generic/mp_monty.cpp
@@ -18,14 +18,14 @@ extern "C" {
/*
* Montgomery Reduction Algorithm
*/
-void bigint_monty_redc(word z[], u32bit z_size,
+void bigint_monty_redc(word z[], size_t z_size,
word ws[],
- const word x[], u32bit x_size,
+ const word x[], size_t x_size,
word u)
{
- const u32bit blocks_of_8 = x_size - (x_size % 8);
+ const size_t blocks_of_8 = x_size - (x_size % 8);
- for(u32bit i = 0; i != x_size; ++i)
+ for(size_t i = 0; i != x_size; ++i)
{
word* z_i = z + i;
@@ -37,10 +37,10 @@ void bigint_monty_redc(word z[], u32bit z_size,
*/
word carry = 0;
- for(u32bit j = 0; j != blocks_of_8; j += 8)
+ for(size_t j = 0; j != blocks_of_8; j += 8)
carry = word8_madd3(z_i + j, x + j, y, carry);
- for(u32bit j = blocks_of_8; j != x_size; ++j)
+ for(size_t j = blocks_of_8; j != x_size; ++j)
z_i[j] = word_madd3(x[j], y, z_i[j], &carry);
word z_sum = z_i[x_size] + carry;
@@ -48,7 +48,7 @@ void bigint_monty_redc(word z[], u32bit z_size,
z_i[x_size] = z_sum;
// Note: not constant time
- for(u32bit j = x_size + 1; carry && j != z_size - i; ++j)
+ for(size_t j = x_size + 1; carry && j != z_size - i; ++j)
{
++z_i[j];
carry = !z_i[j];
@@ -56,7 +56,7 @@ void bigint_monty_redc(word z[], u32bit z_size,
}
word borrow = 0;
- for(u32bit i = 0; i != x_size; ++i)
+ for(size_t i = 0; i != x_size; ++i)
ws[i] = word_sub(z[x_size + i], x[i], &borrow);
ws[x_size] = word_sub(z[x_size+x_size], 0, &borrow);
diff --git a/src/math/mp/mp_asm.cpp b/src/math/mp/mp_asm.cpp
index 4fcdee7a4..d164c1d33 100644
--- a/src/math/mp/mp_asm.cpp
+++ b/src/math/mp/mp_asm.cpp
@@ -19,19 +19,19 @@ extern "C" {
/*
* Two Operand Addition, No Carry
*/
-word bigint_add2_nc(word x[], u32bit x_size, const word y[], u32bit y_size)
+word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size)
{
word carry = 0;
- const u32bit blocks = y_size - (y_size % 8);
+ const size_t blocks = y_size - (y_size % 8);
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
carry = word8_add2(x + i, y + i, carry);
- for(u32bit i = blocks; i != y_size; ++i)
+ for(size_t i = blocks; i != y_size; ++i)
x[i] = word_add(x[i], y[i], &carry);
- for(u32bit i = y_size; i != x_size; ++i)
+ for(size_t i = y_size; i != x_size; ++i)
x[i] = word_add(x[i], 0, &carry);
return carry;
@@ -40,23 +40,23 @@ word bigint_add2_nc(word x[], u32bit x_size, const word y[], u32bit y_size)
/*
* Three Operand Addition, No Carry
*/
-word bigint_add3_nc(word z[], const word x[], u32bit x_size,
- const word y[], u32bit y_size)
+word bigint_add3_nc(word z[], const word x[], size_t x_size,
+ const word y[], size_t y_size)
{
if(x_size < y_size)
{ return bigint_add3_nc(z, y, y_size, x, x_size); }
word carry = 0;
- const u32bit blocks = y_size - (y_size % 8);
+ const size_t blocks = y_size - (y_size % 8);
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
carry = word8_add3(z + i, x + i, y + i, carry);
- for(u32bit i = blocks; i != y_size; ++i)
+ for(size_t i = blocks; i != y_size; ++i)
z[i] = word_add(x[i], y[i], &carry);
- for(u32bit i = y_size; i != x_size; ++i)
+ for(size_t i = y_size; i != x_size; ++i)
z[i] = word_add(x[i], 0, &carry);
return carry;
@@ -65,7 +65,7 @@ word bigint_add3_nc(word z[], const word x[], u32bit x_size,
/*
* Two Operand Addition
*/
-void bigint_add2(word x[], u32bit x_size, const word y[], u32bit y_size)
+void bigint_add2(word x[], size_t x_size, const word y[], size_t y_size)
{
x[x_size] += bigint_add2_nc(x, x_size, y, y_size);
}
@@ -73,8 +73,8 @@ void bigint_add2(word x[], u32bit x_size, const word y[], u32bit y_size)
/*
* Three Operand Addition
*/
-void bigint_add3(word z[], const word x[], u32bit x_size,
- const word y[], u32bit y_size)
+void bigint_add3(word z[], const word x[], size_t x_size,
+ const word y[], size_t y_size)
{
z[(x_size > y_size ? x_size : y_size)] +=
bigint_add3_nc(z, x, x_size, y, y_size);
@@ -83,19 +83,19 @@ void bigint_add3(word z[], const word x[], u32bit x_size,
/*
* Two Operand Subtraction
*/
-word bigint_sub2(word x[], u32bit x_size, const word y[], u32bit y_size)
+word bigint_sub2(word x[], size_t x_size, const word y[], size_t y_size)
{
word borrow = 0;
- const u32bit blocks = y_size - (y_size % 8);
+ const size_t blocks = y_size - (y_size % 8);
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
borrow = word8_sub2(x + i, y + i, borrow);
- for(u32bit i = blocks; i != y_size; ++i)
+ for(size_t i = blocks; i != y_size; ++i)
x[i] = word_sub(x[i], y[i], &borrow);
- for(u32bit i = y_size; i != x_size; ++i)
+ for(size_t i = y_size; i != x_size; ++i)
x[i] = word_sub(x[i], 0, &borrow);
return borrow;
@@ -104,16 +104,16 @@ word bigint_sub2(word x[], u32bit x_size, const word y[], u32bit y_size)
/*
* Two Operand Subtraction x = y - x
*/
-void bigint_sub2_rev(word x[], const word y[], u32bit y_size)
+void bigint_sub2_rev(word x[], const word y[], size_t y_size)
{
word borrow = 0;
- const u32bit blocks = y_size - (y_size % 8);
+ const size_t blocks = y_size - (y_size % 8);
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
borrow = word8_sub2_rev(x + i, y + i, borrow);
- for(u32bit i = blocks; i != y_size; ++i)
+ for(size_t i = blocks; i != y_size; ++i)
x[i] = word_sub(y[i], x[i], &borrow);
if(borrow)
@@ -123,20 +123,20 @@ void bigint_sub2_rev(word x[], const word y[], u32bit y_size)
/*
* Three Operand Subtraction
*/
-word bigint_sub3(word z[], const word x[], u32bit x_size,
- const word y[], u32bit y_size)
+word bigint_sub3(word z[], const word x[], size_t x_size,
+ const word y[], size_t y_size)
{
word borrow = 0;
- const u32bit blocks = y_size - (y_size % 8);
+ const size_t blocks = y_size - (y_size % 8);
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
borrow = word8_sub3(z + i, x + i, y + i, borrow);
- for(u32bit i = blocks; i != y_size; ++i)
+ for(size_t i = blocks; i != y_size; ++i)
z[i] = word_sub(x[i], y[i], &borrow);
- for(u32bit i = y_size; i != x_size; ++i)
+ for(size_t i = y_size; i != x_size; ++i)
z[i] = word_sub(x[i], 0, &borrow);
return borrow;
@@ -145,16 +145,16 @@ word bigint_sub3(word z[], const word x[], u32bit x_size,
/*
* Two Operand Linear Multiply
*/
-void bigint_linmul2(word x[], u32bit x_size, word y)
+void bigint_linmul2(word x[], size_t x_size, word y)
{
- const u32bit blocks = x_size - (x_size % 8);
+ const size_t blocks = x_size - (x_size % 8);
word carry = 0;
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
carry = word8_linmul2(x + i, y, carry);
- for(u32bit i = blocks; i != x_size; ++i)
+ for(size_t i = blocks; i != x_size; ++i)
x[i] = word_madd2(x[i], y, &carry);
x[x_size] = carry;
@@ -163,16 +163,16 @@ void bigint_linmul2(word x[], u32bit x_size, word y)
/*
* Three Operand Linear Multiply
*/
-void bigint_linmul3(word z[], const word x[], u32bit x_size, word y)
+void bigint_linmul3(word z[], const word x[], size_t x_size, word y)
{
- const u32bit blocks = x_size - (x_size % 8);
+ const size_t blocks = x_size - (x_size % 8);
word carry = 0;
- for(u32bit i = 0; i != blocks; i += 8)
+ for(size_t i = 0; i != blocks; i += 8)
carry = word8_linmul3(z + i, x + i, y, carry);
- for(u32bit i = blocks; i != x_size; ++i)
+ for(size_t i = blocks; i != x_size; ++i)
z[i] = word_madd2(x[i], y, &carry);
z[x_size] = carry;
diff --git a/src/math/mp/mp_asm64/mp_asm.h b/src/math/mp/mp_asm64/mp_asm.h
index d9135ace2..625ea1c4f 100644
--- a/src/math/mp/mp_asm64/mp_asm.h
+++ b/src/math/mp/mp_asm64/mp_asm.h
@@ -53,7 +53,7 @@ namespace Botan {
// with 64-bit registers/ALU, but no 64x64->128 multiply.
inline void bigint_2word_mul(word a, word b, word* z1, word* z0)
{
- const u32bit MP_HWORD_BITS = BOTAN_MP_WORD_BITS / 2;
+ const size_t MP_HWORD_BITS = BOTAN_MP_WORD_BITS / 2;
const word MP_HWORD_MASK = ((word)1 << MP_HWORD_BITS) - 1;
const word a_hi = (a >> MP_HWORD_BITS);
diff --git a/src/math/mp/mp_core.h b/src/math/mp/mp_core.h
index 63082795f..e1692006e 100644
--- a/src/math/mp/mp_core.h
+++ b/src/math/mp/mp_core.h
@@ -15,67 +15,67 @@ namespace Botan {
/*
* The size of the word type, in bits
*/
-const u32bit MP_WORD_BITS = BOTAN_MP_WORD_BITS;
+const size_t MP_WORD_BITS = BOTAN_MP_WORD_BITS;
extern "C" {
/*
* Addition/Subtraction Operations
*/
-void bigint_add2(word x[], u32bit x_size,
- const word y[], u32bit y_size);
+void bigint_add2(word x[], size_t x_size,
+ const word y[], size_t y_size);
void bigint_add3(word z[],
- const word x[], u32bit x_size,
- const word y[], u32bit y_size);
+ const word x[], size_t x_size,
+ const word y[], size_t y_size);
-word bigint_add2_nc(word x[], u32bit x_size, const word y[], u32bit y_size);
+word bigint_add2_nc(word x[], size_t x_size, const word y[], size_t y_size);
word bigint_add3_nc(word z[],
- const word x[], u32bit x_size,
- const word y[], u32bit y_size);
+ const word x[], size_t x_size,
+ const word y[], size_t y_size);
-word bigint_sub2(word x[], u32bit x_size,
- const word y[], u32bit y_size);
+word bigint_sub2(word x[], size_t x_size,
+ const word y[], size_t y_size);
/**
* x = y - x; assumes y >= x
*/
-void bigint_sub2_rev(word x[], const word y[], u32bit y_size);
+void bigint_sub2_rev(word x[], const word y[], size_t y_size);
word bigint_sub3(word z[],
- const word x[], u32bit x_size,
- const word y[], u32bit y_size);
+ const word x[], size_t x_size,
+ const word y[], size_t y_size);
/*
* Shift Operations
*/
-void bigint_shl1(word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift);
+void bigint_shl1(word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift);
-void bigint_shr1(word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift);
+void bigint_shr1(word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift);
-void bigint_shl2(word y[], const word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift);
+void bigint_shl2(word y[], const word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift);
-void bigint_shr2(word y[], const word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift);
+void bigint_shr2(word y[], const word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift);
/*
* Simple O(N^2) Multiplication and Squaring
*/
void bigint_simple_mul(word z[],
- const word x[], u32bit x_size,
- const word y[], u32bit y_size);
+ const word x[], size_t x_size,
+ const word y[], size_t y_size);
-void bigint_simple_sqr(word z[], const word x[], u32bit x_size);
+void bigint_simple_sqr(word z[], const word x[], size_t x_size);
/*
* Linear Multiply
*/
-void bigint_linmul2(word x[], u32bit x_size, word y);
-void bigint_linmul3(word z[], const word x[], u32bit x_size, word y);
+void bigint_linmul2(word x[], size_t x_size, word y);
+void bigint_linmul3(word z[], const word x[], size_t x_size, word y);
/*
* Montgomery Reduction
@@ -86,22 +86,22 @@ void bigint_linmul3(word z[], const word x[], u32bit x_size, word y);
* @param x_size size of x
* @param u Montgomery value
*/
-void bigint_monty_redc(word z[], u32bit z_size,
+void bigint_monty_redc(word z[], size_t z_size,
word workspace[],
- const word x[], u32bit x_size,
+ const word x[], size_t x_size,
word u);
/*
* Division operation
*/
-u32bit bigint_divcore(word q, word y2, word y1,
+size_t bigint_divcore(word q, word y2, word y1,
word x3, word x2, word x1);
/**
* Compare x and y
*/
-s32bit bigint_cmp(const word x[], u32bit x_size,
- const word y[], u32bit y_size);
+s32bit bigint_cmp(const word x[], size_t x_size,
+ const word y[], size_t y_size);
/**
* Compute ((n1<<bits) + n0) / d
@@ -132,12 +132,12 @@ void bigint_comba_sqr16(word out[64], const word in[32]);
/*
* High Level Multiplication/Squaring Interfaces
*/
-void bigint_mul(word z[], u32bit z_size, word workspace[],
- const word x[], u32bit x_size, u32bit x_sw,
- const word y[], u32bit y_size, u32bit y_sw);
+void bigint_mul(word z[], size_t z_size, word workspace[],
+ const word x[], size_t x_size, size_t x_sw,
+ const word y[], size_t y_size, size_t y_sw);
-void bigint_sqr(word z[], u32bit z_size, word workspace[],
- const word x[], u32bit x_size, u32bit x_sw);
+void bigint_sqr(word z[], size_t z_size, word workspace[],
+ const word x[], size_t x_size, size_t x_sw);
}
diff --git a/src/math/mp/mp_generic/mp_asm.h b/src/math/mp/mp_generic/mp_asm.h
index 7c18343ef..ee46e1aa9 100644
--- a/src/math/mp/mp_generic/mp_asm.h
+++ b/src/math/mp/mp_generic/mp_asm.h
@@ -14,7 +14,7 @@
#if (BOTAN_MP_WORD_BITS == 8)
typedef Botan::u16bit dword;
#elif (BOTAN_MP_WORD_BITS == 16)
- typedef Botan::u32bit dword;
+ typedef Botan::size_t dword;
#elif (BOTAN_MP_WORD_BITS == 32)
typedef Botan::u64bit dword;
#elif (BOTAN_MP_WORD_BITS == 64)
diff --git a/src/math/mp/mp_karat.cpp b/src/math/mp/mp_karat.cpp
index 1cb278367..ea0693bf1 100644
--- a/src/math/mp/mp_karat.cpp
+++ b/src/math/mp/mp_karat.cpp
@@ -16,7 +16,7 @@ namespace {
/*
* Karatsuba Multiplication Operation
*/
-void karatsuba_mul(word z[], const word x[], const word y[], u32bit N,
+void karatsuba_mul(word z[], const word x[], const word y[], size_t N,
word workspace[])
{
if(N < BOTAN_KARAT_MUL_THRESHOLD || N % 2)
@@ -31,7 +31,7 @@ void karatsuba_mul(word z[], const word x[], const word y[], u32bit N,
return bigint_simple_mul(z, x, N, y, N);
}
- const u32bit N2 = N / 2;
+ const size_t N2 = N / 2;
const word* x0 = x;
const word* x1 = x + N2;
@@ -63,28 +63,28 @@ void karatsuba_mul(word z[], const word x[], const word y[], u32bit N,
karatsuba_mul(z0, x0, y0, N2, workspace+N);
karatsuba_mul(z1, x1, y1, N2, workspace+N);
- const u32bit blocks_of_8 = N - (N % 8);
+ const size_t blocks_of_8 = N - (N % 8);
word ws_carry = 0;
- for(u32bit j = 0; j != blocks_of_8; j += 8)
+ for(size_t j = 0; j != blocks_of_8; j += 8)
ws_carry = word8_add3(workspace + N + j, z0 + j, z1 + j, ws_carry);
- for(u32bit j = blocks_of_8; j != N; ++j)
+ for(size_t j = blocks_of_8; j != N; ++j)
workspace[N + j] = word_add(z0[j], z1[j], &ws_carry);
word z_carry = 0;
- for(u32bit j = 0; j != blocks_of_8; j += 8)
+ for(size_t j = 0; j != blocks_of_8; j += 8)
z_carry = word8_add2(z + N2 + j, workspace + N + j, z_carry);
- for(u32bit j = blocks_of_8; j != N; ++j)
+ for(size_t j = blocks_of_8; j != N; ++j)
z[N2 + j] = word_add(z[N2 + j], workspace[N + j], &z_carry);
z[N + N2] = word_add(z[N + N2], ws_carry, &z_carry);
if(z_carry)
- for(u32bit j = 1; j != N2; ++j)
+ for(size_t j = 1; j != N2; ++j)
if(++z[N + N2 + j])
break;
@@ -97,7 +97,7 @@ void karatsuba_mul(word z[], const word x[], const word y[], u32bit N,
/*
* Karatsuba Squaring Operation
*/
-void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
+void karatsuba_sqr(word z[], const word x[], size_t N, word workspace[])
{
if(N < BOTAN_KARAT_SQR_THRESHOLD || N % 2)
{
@@ -111,7 +111,7 @@ void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
return bigint_simple_sqr(z, x, N);
}
- const u32bit N2 = N / 2;
+ const size_t N2 = N / 2;
const word* x0 = x;
const word* x1 = x + N2;
@@ -135,28 +135,28 @@ void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
karatsuba_sqr(z0, x0, N2, workspace+N);
karatsuba_sqr(z1, x1, N2, workspace+N);
- const u32bit blocks_of_8 = N - (N % 8);
+ const size_t blocks_of_8 = N - (N % 8);
word ws_carry = 0;
- for(u32bit j = 0; j != blocks_of_8; j += 8)
+ for(size_t j = 0; j != blocks_of_8; j += 8)
ws_carry = word8_add3(workspace + N + j, z0 + j, z1 + j, ws_carry);
- for(u32bit j = blocks_of_8; j != N; ++j)
+ for(size_t j = blocks_of_8; j != N; ++j)
workspace[N + j] = word_add(z0[j], z1[j], &ws_carry);
word z_carry = 0;
- for(u32bit j = 0; j != blocks_of_8; j += 8)
+ for(size_t j = 0; j != blocks_of_8; j += 8)
z_carry = word8_add2(z + N2 + j, workspace + N + j, z_carry);
- for(u32bit j = blocks_of_8; j != N; ++j)
+ for(size_t j = blocks_of_8; j != N; ++j)
z[N2 + j] = word_add(z[N2 + j], workspace[N + j], &z_carry);
z[N + N2] = word_add(z[N + N2], ws_carry, &z_carry);
if(z_carry)
- for(u32bit j = 1; j != N2; ++j)
+ for(size_t j = 1; j != N2; ++j)
if(++z[N + N2 + j])
break;
@@ -171,9 +171,9 @@ void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[])
/*
* Pick a good size for the Karatsuba multiply
*/
-u32bit karatsuba_size(u32bit z_size,
- u32bit x_size, u32bit x_sw,
- u32bit y_size, u32bit y_sw)
+size_t karatsuba_size(size_t z_size,
+ size_t x_size, size_t x_sw,
+ size_t y_size, size_t y_sw)
{
if(x_sw > x_size || x_sw > y_size || y_sw > x_size || y_sw > y_size)
return 0;
@@ -182,8 +182,8 @@ u32bit karatsuba_size(u32bit z_size,
((y_size == y_sw) && (y_size % 2)))
return 0;
- const u32bit start = (x_sw > y_sw) ? x_sw : y_sw;
- const u32bit end = (x_size < y_size) ? x_size : y_size;
+ const size_t start = (x_sw > y_sw) ? x_sw : y_sw;
+ const size_t end = (x_size < y_size) ? x_size : y_size;
if(start == end)
{
@@ -192,7 +192,7 @@ u32bit karatsuba_size(u32bit z_size,
return start;
}
- for(u32bit j = start; j <= end; ++j)
+ for(size_t j = start; j <= end; ++j)
{
if(j % 2)
continue;
@@ -215,7 +215,7 @@ u32bit karatsuba_size(u32bit z_size,
/*
* Pick a good size for the Karatsuba squaring
*/
-u32bit karatsuba_size(u32bit z_size, u32bit x_size, u32bit x_sw)
+size_t karatsuba_size(size_t z_size, size_t x_size, size_t x_sw)
{
if(x_sw == x_size)
{
@@ -224,7 +224,7 @@ u32bit karatsuba_size(u32bit z_size, u32bit x_size, u32bit x_sw)
return x_sw;
}
- for(u32bit j = x_sw; j <= x_size; ++j)
+ for(size_t j = x_sw; j <= x_size; ++j)
{
if(j % 2)
continue;
@@ -245,9 +245,9 @@ u32bit karatsuba_size(u32bit z_size, u32bit x_size, u32bit x_sw)
/*
* Multiplication Algorithm Dispatcher
*/
-void bigint_mul(word z[], u32bit z_size, word workspace[],
- const word x[], u32bit x_size, u32bit x_sw,
- const word y[], u32bit y_size, u32bit y_sw)
+void bigint_mul(word z[], size_t z_size, word workspace[],
+ const word x[], size_t x_size, size_t x_sw,
+ const word y[], size_t y_size, size_t y_sw)
{
if(x_sw == 1)
{
@@ -285,7 +285,7 @@ void bigint_mul(word z[], u32bit z_size, word workspace[],
}
else
{
- const u32bit N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw);
+ const size_t N = karatsuba_size(z_size, x_size, x_sw, y_size, y_sw);
if(N)
{
@@ -300,8 +300,8 @@ void bigint_mul(word z[], u32bit z_size, word workspace[],
/*
* Squaring Algorithm Dispatcher
*/
-void bigint_sqr(word z[], u32bit z_size, word workspace[],
- const word x[], u32bit x_size, u32bit x_sw)
+void bigint_sqr(word z[], size_t z_size, word workspace[],
+ const word x[], size_t x_size, size_t x_sw)
{
if(x_sw == 1)
{
@@ -329,7 +329,7 @@ void bigint_sqr(word z[], u32bit z_size, word workspace[],
}
else
{
- const u32bit N = karatsuba_size(z_size, x_size, x_sw);
+ const size_t N = karatsuba_size(z_size, x_size, x_sw);
if(N)
{
diff --git a/src/math/mp/mp_misc.cpp b/src/math/mp/mp_misc.cpp
index 77b8e6f51..0232f01d6 100644
--- a/src/math/mp/mp_misc.cpp
+++ b/src/math/mp/mp_misc.cpp
@@ -15,7 +15,7 @@ extern "C" {
/*
* Core Division Operation
*/
-u32bit bigint_divcore(word q, word y2, word y1,
+size_t bigint_divcore(word q, word y2, word y1,
word x3, word x2, word x1)
{
// Compute (y2,y1) * q
@@ -38,8 +38,8 @@ u32bit bigint_divcore(word q, word y2, word y1,
/*
* Compare two MP integers
*/
-s32bit bigint_cmp(const word x[], u32bit x_size,
- const word y[], u32bit y_size)
+s32bit bigint_cmp(const word x[], size_t x_size,
+ const word y[], size_t y_size)
{
if(x_size < y_size) { return (-bigint_cmp(y, y_size, x, x_size)); }
@@ -50,7 +50,7 @@ s32bit bigint_cmp(const word x[], u32bit x_size,
x_size--;
}
- for(u32bit j = x_size; j > 0; --j)
+ for(size_t j = x_size; j > 0; --j)
{
if(x[j-1] > y[j-1])
return 1;
@@ -68,7 +68,7 @@ word bigint_divop(word n1, word n0, word d)
{
word high = n1 % d, quotient = 0;
- for(u32bit j = 0; j != MP_WORD_BITS; ++j)
+ for(size_t j = 0; j != MP_WORD_BITS; ++j)
{
word high_top_bit = (high & MP_WORD_TOP_BIT);
diff --git a/src/math/mp/mp_shift.cpp b/src/math/mp/mp_shift.cpp
index f1d609bfb..0531658ec 100644
--- a/src/math/mp/mp_shift.cpp
+++ b/src/math/mp/mp_shift.cpp
@@ -15,11 +15,11 @@ extern "C" {
/*
* Single Operand Left Shift
*/
-void bigint_shl1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
+void bigint_shl1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
{
if(word_shift)
{
- for(u32bit j = 1; j != x_size + 1; ++j)
+ for(size_t j = 1; j != x_size + 1; ++j)
x[(x_size - j) + word_shift] = x[x_size - j];
clear_mem(x, word_shift);
}
@@ -27,7 +27,7 @@ void bigint_shl1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
if(bit_shift)
{
word carry = 0;
- for(u32bit j = word_shift; j != x_size + word_shift + 1; ++j)
+ for(size_t j = word_shift; j != x_size + word_shift + 1; ++j)
{
word temp = x[j];
x[j] = (temp << bit_shift) | carry;
@@ -39,7 +39,7 @@ void bigint_shl1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
/*
* Single Operand Right Shift
*/
-void bigint_shr1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
+void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
{
if(x_size < word_shift)
{
@@ -57,7 +57,7 @@ void bigint_shr1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
{
word carry = 0;
- u32bit top = x_size - word_shift;
+ size_t top = x_size - word_shift;
while(top >= 4)
{
@@ -94,15 +94,15 @@ void bigint_shr1(word x[], u32bit x_size, u32bit word_shift, u32bit bit_shift)
/*
* Two Operand Left Shift
*/
-void bigint_shl2(word y[], const word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift)
+void bigint_shl2(word y[], const word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift)
{
- for(u32bit j = 0; j != x_size; ++j)
+ for(size_t j = 0; j != x_size; ++j)
y[j + word_shift] = x[j];
if(bit_shift)
{
word carry = 0;
- for(u32bit j = word_shift; j != x_size + word_shift + 1; ++j)
+ for(size_t j = word_shift; j != x_size + word_shift + 1; ++j)
{
word w = y[j];
y[j] = (w << bit_shift) | carry;
@@ -114,17 +114,17 @@ void bigint_shl2(word y[], const word x[], u32bit x_size,
/*
* Two Operand Right Shift
*/
-void bigint_shr2(word y[], const word x[], u32bit x_size,
- u32bit word_shift, u32bit bit_shift)
+void bigint_shr2(word y[], const word x[], size_t x_size,
+ size_t word_shift, size_t bit_shift)
{
if(x_size < word_shift) return;
- for(u32bit j = 0; j != x_size - word_shift; ++j)
+ for(size_t j = 0; j != x_size - word_shift; ++j)
y[j] = x[j + word_shift];
if(bit_shift)
{
word carry = 0;
- for(u32bit j = x_size - word_shift; j > 0; --j)
+ for(size_t j = x_size - word_shift; j > 0; --j)
{
word w = y[j-1];
y[j-1] = (w >> bit_shift) | carry;
diff --git a/src/math/mp/mp_types.h b/src/math/mp/mp_types.h
index 1648713ed..e8723b5bf 100644
--- a/src/math/mp/mp_types.h
+++ b/src/math/mp/mp_types.h
@@ -17,7 +17,7 @@ namespace Botan {
#elif (BOTAN_MP_WORD_BITS == 16)
typedef u16bit word;
#elif (BOTAN_MP_WORD_BITS == 32)
- typedef u32bit word;
+ typedef size_t word;
#elif (BOTAN_MP_WORD_BITS == 64)
typedef u64bit word;
#else
diff --git a/src/math/mp/mulop_generic/mp_mulop.cpp b/src/math/mp/mulop_generic/mp_mulop.cpp
index b6966ada7..e6a8ba891 100644
--- a/src/math/mp/mulop_generic/mp_mulop.cpp
+++ b/src/math/mp/mulop_generic/mp_mulop.cpp
@@ -17,23 +17,23 @@ extern "C" {
/*
* Simple O(N^2) Multiplication
*/
-void bigint_simple_mul(word z[], const word x[], u32bit x_size,
- const word y[], u32bit y_size)
+void bigint_simple_mul(word z[], const word x[], size_t x_size,
+ const word y[], size_t y_size)
{
- const u32bit x_size_8 = x_size - (x_size % 8);
+ const size_t x_size_8 = x_size - (x_size % 8);
clear_mem(z, x_size + y_size);
- for(u32bit i = 0; i != y_size; ++i)
+ for(size_t i = 0; i != y_size; ++i)
{
const word y_i = y[i];
word carry = 0;
- for(u32bit j = 0; j != x_size_8; j += 8)
+ for(size_t j = 0; j != x_size_8; j += 8)
carry = word8_madd3(z + i + j, x + j, y_i, carry);
- for(u32bit j = x_size_8; j != x_size; ++j)
+ for(size_t j = x_size_8; j != x_size; ++j)
z[i+j] = word_madd3(x[j], y_i, z[i+j], &carry);
z[x_size+i] = carry;
@@ -51,21 +51,21 @@ void bigint_simple_mul(word z[], const word x[], u32bit x_size,
* Applied Cryptography, chapter 14
*
*/
-void bigint_simple_sqr(word z[], const word x[], u32bit x_size)
+void bigint_simple_sqr(word z[], const word x[], size_t x_size)
{
- const u32bit x_size_8 = x_size - (x_size % 8);
+ const size_t x_size_8 = x_size - (x_size % 8);
clear_mem(z, 2*x_size);
- for(u32bit i = 0; i != x_size; ++i)
+ for(size_t i = 0; i != x_size; ++i)
{
const word x_i = x[i];
word carry = 0;
- for(u32bit j = 0; j != x_size_8; j += 8)
+ for(size_t j = 0; j != x_size_8; j += 8)
carry = word8_madd3(z + i + j, x + j, x_i, carry);
- for(u32bit j = x_size_8; j != x_size; ++j)
+ for(size_t j = x_size_8; j != x_size; ++j)
z[i+j] = word_madd3(x[j], x_i, z[i+j], &carry);
z[x_size+i] = carry;