aboutsummaryrefslogtreecommitdiff
path: root/src/model/c/src/montgomery_array.c
diff options
context:
space:
mode:
authorJoachim StroĢˆmbergson <joachim@secworks.se>2015-04-27 11:17:08 +0200
committerJoachim StroĢˆmbergson <joachim@secworks.se>2015-04-27 11:17:08 +0200
commita315223f98fa6f1fdea2b1080c5f3e33352ebb13 (patch)
tree0fb3f6c458df78f58017e9475ff3b0c5cb3b52d0 /src/model/c/src/montgomery_array.c
parent502f0f429a261628fe5e43582280012541c40804 (diff)
Updating modexp core to v 0.50. This version contains a working core that can perform sign and verify with big keys/values. The core builds ok in Altera and Xilinx FPGA tools. This commit also includes a new testgenerator capable of generating testbench for modexp with autgenerated test data of different lengths. The README has been updated with status and implementation results in for different FPGA devices.
Diffstat (limited to 'src/model/c/src/montgomery_array.c')
-rw-r--r--src/model/c/src/montgomery_array.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/model/c/src/montgomery_array.c b/src/model/c/src/montgomery_array.c
index 0ddc742..c3579a9 100644
--- a/src/model/c/src/montgomery_array.c
+++ b/src/model/c/src/montgomery_array.c
@@ -3,22 +3,15 @@
#include "bignum_uint32_t.h"
#include "montgomery_array.h"
-void mont_prod_array(uint32_t length, uint32_t *A, uint32_t *B, uint32_t *M,
- uint32_t *temp, uint32_t *s) {
+void mont_prod_array(uint32_t length, uint32_t *A, uint32_t *B, uint32_t *M, uint32_t *s) {
zero_array(length, s);
for (int32_t wordIndex = ((int32_t) length) - 1; wordIndex >= 0; wordIndex--) {
for (int i = 0; i < 32; i++) {
- int b = (B[wordIndex] >> i) & 1;
+ uint32_t b = (B[wordIndex] >> i) & 1;
//q = (s - b * A) & 1;
- sub_array(length, s, A, temp);
- int q;
- if (b == 1) {
- q = temp[length - 1] & 1;
- } else {
- q = s[length - 1] & 1;
- }
+ uint32_t q = (s[length-1] ^ (A[length-1] & b)) & 1; // int q = (s - b * A) & 1;
// s = (s + q*M + b*A) >>> 1;
if (q == 1) {
@@ -77,11 +70,11 @@ void mont_exp_array(uint32_t length, uint32_t *X, uint32_t *E, uint32_t *M,
// 2. Z0 := MontProd( 1, Nr, M )
zero_array(length, ONE);
ONE[length - 1] = 1;
- mont_prod_array(length, ONE, Nr, M, temp, Z);
+ mont_prod_array(length, ONE, Nr, M, Z);
//debugArray("Z0", length, Z);
// 3. P0 := MontProd( X, Nr, M );
- mont_prod_array(length, X, Nr, M, temp, P);
+ mont_prod_array(length, X, Nr, M, P);
//debugArray("P0", length, P);
// 4. for i = 0 to n-1 loop
@@ -91,18 +84,18 @@ void mont_exp_array(uint32_t length, uint32_t *X, uint32_t *E, uint32_t *M,
uint32_t ei = (ei_ >> (i % 32)) & 1;
// 6. if (ei = 1) then Zi+1 := MontProd ( Zi, Pi, M) else Zi+1 := Zi
if (ei == 1) {
- mont_prod_array(length, Z, P, M, temp, temp2);
+ mont_prod_array(length, Z, P, M, temp2);
copy_array(length, temp2, Z);
//debugArray("Z ", length, Z);
}
// 5. Pi+1 := MontProd( Pi, Pi, M );
- mont_prod_array(length, P, P, M, temp, temp2);
+ mont_prod_array(length, P, P, M, temp2);
copy_array(length, temp2, P);
//debugArray("P ", length, P);
// 7. end for
}
// 8. Zn := MontProd( 1, Zn, M );
- mont_prod_array(length, ONE, Z, M, temp, temp2);
+ mont_prod_array(length, ONE, Z, M, temp2);
copy_array(length, temp2, Z);
//debugArray("Z ", length, Z);
// 9. RETURN Zn