aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ecdsa_fpga_curve_microcode.cpp28
-rw-r--r--ecdsa_fpga_model.cpp2
-rw-r--r--ecdsa_fpga_model.h4
-rw-r--r--ecdsa_microcode_parser.py37
4 files changed, 10 insertions, 61 deletions
diff --git a/ecdsa_fpga_curve_microcode.cpp b/ecdsa_fpga_curve_microcode.cpp
index 128e087..84083f6 100644
--- a/ecdsa_fpga_curve_microcode.cpp
+++ b/ecdsa_fpga_curve_microcode.cpp
@@ -398,34 +398,14 @@ void fpga_curve_base_scalar_multiply_microcode(const FPGA_BUFFER *k, FPGA_BUFFER
/* BEGIN_MICROCODE: CONVERT */
- uop_calc(MUL, BANK_HI, INVERT_A2, CYCLE_R0X, BANK_LO, CYCLE_SX);
- uop_calc(MUL, BANK_HI, INVERT_A3, CYCLE_R0Y, BANK_LO, CYCLE_SY);
- uop_cmpz(BANK_LO, CYCLE_R0Z);
+ uop_calc(MUL, BANK_HI, INVERT_A2, CYCLE_R0X, BANK_LO, CYCLE_R1X);
+ uop_calc(MUL, BANK_HI, INVERT_A3, CYCLE_R0Y, BANK_LO, CYCLE_R1Y);
/* END_MICROCODE */
- if (uop_flagz_r0z)
- {
- /* BEGIN_MICROCODE: CONVERT_AT_INFINITY */
-
- uop_move(BANK_LO, CONST_ZERO, BANK_HI, CYCLE_R0X);
- uop_move(BANK_LO, CONST_ZERO, BANK_HI, CYCLE_R0Y);
-
- /* END_MICROCODE */
- }
- else
- {
- /* BEGIN_MICROCODE: CONVERT_REGULAR */
-
- uop_move(BANK_LO, CYCLE_SX, BANK_HI, CYCLE_R0X);
- uop_move(BANK_LO, CYCLE_SY, BANK_HI, CYCLE_R0Y);
-
- /* END_MICROCODE */
- }
-
// return
- uop_stor(BANK_HI, CYCLE_R0X, qx);
- uop_stor(BANK_HI, CYCLE_R0Y, qy);
+ uop_stor(BANK_LO, CYCLE_R1X, qx);
+ uop_stor(BANK_LO, CYCLE_R1Y, qy);
}
#endif USE_MICROCODE
diff --git a/ecdsa_fpga_model.cpp b/ecdsa_fpga_model.cpp
index 13ba3f9..367d483 100644
--- a/ecdsa_fpga_model.cpp
+++ b/ecdsa_fpga_model.cpp
@@ -476,7 +476,7 @@ bool abuse_internal_point_adder()
{
// in fact we only need to swap P and Q
printf("Trying to add the base point to something at infinity...\n\n");
- //fpga_curve_add_jacobian_2(&qx, &qy, &qz, &px, &py, &pz, &rx, &ry, &rz);
+ fpga_curve_add_jacobian_2_shim(&qx, &qy, &qz, &px, &py, &pz, &rx, &ry, &rz);
// handle result
ok = compare_fpga_buffers(&ECDSA_GX, &ECDSA_GY, &ECDSA_ONE, &rx, &ry, &rz);
diff --git a/ecdsa_fpga_model.h b/ecdsa_fpga_model.h
index 5228b9c..7b6a7e3 100644
--- a/ecdsa_fpga_model.h
+++ b/ecdsa_fpga_model.h
@@ -77,8 +77,8 @@
// Debugging Output Control
//------------------------------------------------------------------------------
/**
-define DUMP_CYCLE_STATES // dump R0, R1, S, T after every cycle
-/**/
+#define DUMP_CYCLE_STATES // dump R0, R1, S, T after every cycle
+**/
/**
#define DUMP_UOP_OUTPUTS // dump every micro-operation output (lots of text!)
**/
diff --git a/ecdsa_microcode_parser.py b/ecdsa_microcode_parser.py
index 293e8a6..ec233d9 100644
--- a/ecdsa_microcode_parser.py
+++ b/ecdsa_microcode_parser.py
@@ -63,11 +63,8 @@ class MICROCODE_PARSER:
CONVERT = 9
- CONVERT_AT_INFINITY = 10
- CONVERT_REGULAR = 11
-
- INVERT_P256 = 12
- INVERT_P384 = 13
+ INVERT_P256 = 10
+ INVERT_P384 = 11
# magic pair of begin/end markers
@@ -163,10 +160,7 @@ class MICROCODE_PARSER:
"INVERT_P256": MICROCODE_PIECE_ENUM.INVERT_P256,
"INVERT_P384": MICROCODE_PIECE_ENUM.INVERT_P384,
- "CONVERT": MICROCODE_PIECE_ENUM.CONVERT,
-
- "CONVERT_AT_INFINITY": MICROCODE_PIECE_ENUM.CONVERT_AT_INFINITY,
- "CONVERT_REGULAR": MICROCODE_PIECE_ENUM.CONVERT_REGULAR}
+ "CONVERT": MICROCODE_PIECE_ENUM.CONVERT}
# map C bank names to Verilog bank names
@@ -204,9 +198,6 @@ class MICROCODE_PARSER:
MICROCODE_LINES_CONVERT = []
- MICROCODE_LINES_CONVERT_AT_INFINITY = []
- MICROCODE_LINES_CONVERT_REGULAR = []
-
MICROCODE_LINE_STOP = "{%s, %s, %s, %s, %s}" % ( MICROCODE_V_NAME_OPCODE_STOP,
MICROCODE_V_NAME_BANKS_DUMMY,
MICROCODE_V_NAME_OPERAND_DONTCARE,
@@ -267,9 +258,6 @@ class MICROCODE_PARSER:
if len(self.MICROCODE_LINES_CONVERT) == 0: sys.exit("sys.exit(): Empty CONVERT piece!")
- if len(self.MICROCODE_LINES_CONVERT_AT_INFINITY) == 0: sys.exit("sys.exit(): Empty CONVERT_AT_INFINITY piece!")
- if len(self.MICROCODE_LINES_CONVERT_REGULAR) == 0: sys.exit("sys.exit(): Empty CONVERT_REGULAR piece!")
-
length = 0
length += len(self.MICROCODE_LINES_PREPARE)
@@ -285,9 +273,6 @@ class MICROCODE_PARSER:
length += len(self.MICROCODE_LINES_CYCLE_K1)
length += len(self.MICROCODE_LINES_CONVERT)
-
- length += len(self.MICROCODE_LINES_CONVERT_AT_INFINITY)
- length += len(self.MICROCODE_LINES_CONVERT_REGULAR)
if mode == 1: length += len(self.MICROCODE_LINES_INVERT_P256)
if mode == 2: length += len(self.MICROCODE_LINES_INVERT_P384)
@@ -363,18 +348,6 @@ class MICROCODE_PARSER:
num_mul_cycle += self.__format_line(line)
self.__format_line(self.MICROCODE_LINE_STOP)
- offset_convert_at_infinity = self.__addr;
- print("// CONVERT_AT_INFINITY");
- for line in self.MICROCODE_LINES_CONVERT_AT_INFINITY:
- self.__format_line(line)
- self.__format_line(self.MICROCODE_LINE_STOP)
-
- offset_convert_regular = self.__addr;
- print("// CONVERT_REGULAR");
- for line in self.MICROCODE_LINES_CONVERT_REGULAR:
- num_mul_cycle += self.__format_line(line)
- self.__format_line(self.MICROCODE_LINE_STOP)
-
if mode == 1:
offset_invert_p256 = self.__addr;
print("// INVERT_P256");
@@ -400,8 +373,6 @@ class MICROCODE_PARSER:
self.__format_offset("UOP_OFFSET_CYCLE_K0 ", offset_cycle_k0)
self.__format_offset("UOP_OFFSET_CYCLE_K1 ", offset_cycle_k1)
self.__format_offset("UOP_OFFSET_CONVERT ", offset_convert)
- self.__format_offset("UOP_OFFSET_CONVERT_AT_INFINITY ", offset_convert_at_infinity)
- self.__format_offset("UOP_OFFSET_CONVERT_REGULAR ", offset_convert_regular)
if mode == 1: self.__format_offset("UOP_OFFSET_INVERT_P256 ", offset_invert_p256)
if mode == 2: self.__format_offset("UOP_OFFSET_INVERT_P384 ", offset_invert_p384)
@@ -665,8 +636,6 @@ class MICROCODE_PARSER:
elif self.__current_piece == self.MICROCODE_PIECE_ENUM.INVERT_P256: self.MICROCODE_LINES_INVERT_P256.append(data)
elif self.__current_piece == self.MICROCODE_PIECE_ENUM.INVERT_P384: self.MICROCODE_LINES_INVERT_P384.append(data)
elif self.__current_piece == self.MICROCODE_PIECE_ENUM.CONVERT: self.MICROCODE_LINES_CONVERT.append(data)
- elif self.__current_piece == self.MICROCODE_PIECE_ENUM.CONVERT_AT_INFINITY: self.MICROCODE_LINES_CONVERT_AT_INFINITY.append(data)
- elif self.__current_piece == self.MICROCODE_PIECE_ENUM.CONVERT_REGULAR: self.MICROCODE_LINES_CONVERT_REGULAR.append(data)
def __print_parse_error(self, msg):
print("PARSE ERROR: %s" % (msg))