From 70db176e715f4fc143ccd1ff75984fdf7c0845cd Mon Sep 17 00:00:00 2001 From: lloyd Date: Sat, 19 Aug 2006 12:42:23 +0000 Subject: Move bigint_simple_mul into mp_mul.cpp, since that is the only place it was used. Make a variant of bigint_simple_mul, bigint_simple_sqr, for mp_sqr.cpp --- include/mp_core.h | 2 -- src/mp_asm.cpp | 12 ------------ src/mp_mul.cpp | 12 ++++++++++++ src/mp_sqr.cpp | 17 ++++++++++++++--- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/include/mp_core.h b/include/mp_core.h index d5e9cbe1b..8062ba845 100644 --- a/include/mp_core.h +++ b/include/mp_core.h @@ -44,8 +44,6 @@ word bigint_mul_add_words(word[], const word[], u32bit, word); void bigint_linmul2(word[], u32bit, word); void bigint_linmul3(word[], const word[], u32bit, word); - -void bigint_simple_mul(word[], const word[], u32bit, const word[], u32bit); void bigint_linmul_add(word[], u32bit, const word[], u32bit, word); /************************************************* diff --git a/src/mp_asm.cpp b/src/mp_asm.cpp index 88cc8b6e1..64605bb48 100644 --- a/src/mp_asm.cpp +++ b/src/mp_asm.cpp @@ -171,18 +171,6 @@ void bigint_linmul3(word z[], const word x[], u32bit x_size, word y) z[x_size] = carry; } -/************************************************* -* Simple O(N^2) Multiplication * -*************************************************/ -void bigint_simple_mul(word z[], const word x[], u32bit x_size, - const word y[], u32bit y_size) - { - clear_mem(z, x_size + y_size); - - for(u32bit j = 0; j != x_size; ++j) - z[j+y_size] = bigint_mul_add_words(z + j, y, y_size, x[j]); - } - /************************************************* * Montgomery Reduction Algorithm * *************************************************/ diff --git a/src/mp_mul.cpp b/src/mp_mul.cpp index ecebf823a..2870846fb 100644 --- a/src/mp_mul.cpp +++ b/src/mp_mul.cpp @@ -10,6 +10,18 @@ namespace Botan { namespace { +/************************************************* +* Simple O(N^2) Multiplication * +*************************************************/ +void bigint_simple_mul(word z[], const word x[], u32bit x_size, + const word y[], u32bit y_size) + { + clear_mem(z, x_size + y_size); + + for(u32bit j = 0; j != x_size; ++j) + z[j+y_size] = bigint_mul_add_words(z + j, y, y_size, x[j]); + } + /************************************************* * Karatsuba Multiplication Operation * *************************************************/ diff --git a/src/mp_sqr.cpp b/src/mp_sqr.cpp index 934a90c5a..57b4695ee 100644 --- a/src/mp_sqr.cpp +++ b/src/mp_sqr.cpp @@ -10,6 +10,17 @@ namespace Botan { namespace { +/************************************************* +* Simple O(N^2) Squaring * +*************************************************/ +void bigint_simple_sqr(word z[], const word x[], u32bit x_size) + { + clear_mem(z, 2*x_size); + + for(u32bit j = 0; j != x_size; ++j) + z[j+x_size] = bigint_mul_add_words(z + j, x, x_size, x[j]); + } + /************************************************* * Karatsuba Squaring Operation * *************************************************/ @@ -22,7 +33,7 @@ void karatsuba_sqr(word z[], const word x[], u32bit N, word workspace[]) else if(N == 8) bigint_comba_sqr8(z, x); else if(N < KARATSUBA_SQR_LOWER_SIZE || N % 2) - bigint_simple_mul(z, x, N, x, N); + bigint_simple_sqr(z, x, N); else { const u32bit N2 = N / 2; @@ -103,7 +114,7 @@ void handle_small_sqr(word z[], u32bit z_size, else if(x_sw <= 8 && x_size >= 8 && z_size >= 16) bigint_comba_sqr8(z, x); else - bigint_simple_mul(z, x, x_sw, x, x_sw); + bigint_simple_sqr(z, x, x_sw); } } @@ -128,7 +139,7 @@ void bigint_sqr(word z[], u32bit z_size, word workspace[], karatsuba_sqr(z, x, N, workspace); } else - bigint_simple_mul(z, x, x_sw, x, x_sw); + bigint_simple_sqr(z, x, x_sw); } } -- cgit v1.2.3