def run_sign(d, k, msg): """Runs the sign primitive to perform an ecdsa sign""" global dmem global inst_cnt global cycle_cnt global ctx global stats load_pointer() machine = Machine(dmem.copy(), ins_objects, P256INIT_START_ADDR, P256INIT_STOP_ADDR, ctx=ctx) cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_msg(msg) load_d(d) load_k(k) machine.dmem = dmem.copy() machine.pc = P256SIGN_START_ADDR machine.stop_addr = P256SIGN_STOP_ADDR machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() return dmem[pR], dmem[pS]
def run_scalarmult(x, y, k): """Runs the scalarmult primitive to multiply a curve point with a scalar""" global dmem global inst_cnt global cycle_cnt global ctx load_pointer() machine = Machine(dmem.copy(), ins_objects, P256INIT_START_ADDR, P256INIT_STOP_ADDR, ctx=ctx) cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) load_k(k) machine.dmem = dmem.copy() machine.pc = P256SCALARMULT_START_ADDR machine.stop_addr = P256SCALARMULT_STOP_ADDR cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() return dmem[pX], dmem[pY]
def run_verify(x, y, r, s, msg): """Runs the sign primitive to perform an ecdsa sign""" global dmem global inst_cnt global cycle_cnt global ctx load_pointer() machine = Machine(dmem.copy(), ins_objects, P256INIT_START_ADDR, P256INIT_STOP_ADDR, ctx=ctx) cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) load_r(r) load_s(s) load_msg(msg) machine.dmem = dmem.copy() machine.pc = P256VERIFY_START_ADDR machine.stop_addr = P256VERIFY_STOP_ADDR cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() # Verification successful if r == rnd return dmem[pR] == dmem[pRnd]
def run_isoncurve(x, y): """Runs the isoncurve primitive to check if a point is a valid curve point""" global dmem global inst_cnt global cycle_cnt global ctx load_pointer() machine = Machine(dmem.copy(), ins_objects, P256INIT_START_ADDR, P256INIT_STOP_ADDR, ctx=ctx) cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) machine.dmem = dmem.copy() machine.pc = P256ISONCURVE_START_ADDR machine.stop_addr = P256ISONCURVE_STOP_ADDR cont = True while cont: cont, trace_str, cycles = machine.step() print(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() # point is on curve if r and s are equal on_curve = (dmem[pS] == dmem[pR]) return on_curve
def run_verify(x, y, r, s, msg): """Runs the sign primitive to perform an ecdsa sign""" global dmem global inst_cnt global cycle_cnt global ctx global stats global breakpoints load_pointer() machine = Machine(dmem.copy(), ins_objects, start_addr_dict['p256init'], stop_addr_dict['p256init'], ctx=ctx, breakpoints=breakpoints) machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) load_r(r) load_s(s) load_msg(msg) machine.dmem = dmem.copy() machine.pc = start_addr_dict['p256verify'] machine.stop_addr = stop_addr_dict['p256verify'] machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() # Verification successful if r == rnd return dmem[pR] == dmem[pRnd]
def run_scalarmult(x, y, k): """Runs the scalarmult primitive to multiply a curve point with a scalar""" global dmem global inst_cnt global cycle_cnt global ctx global stats global breakpoints load_pointer() machine = Machine(dmem.copy(), ins_objects, start_addr_dict['p256init'], stop_addr_dict['p256init'], ctx=ctx, breakpoints=breakpoints) machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) load_k(k) machine.dmem = dmem.copy() machine.pc = start_addr_dict['p256scalarmult'] machine.stop_addr = stop_addr_dict['p256scalarmult'] machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() return dmem[pX], dmem[pY]
def run_sign(d, k, msg): """Runs the sign primitive to perform an ecdsa sign""" global dmem global inst_cnt global cycle_cnt global ctx global stats global breakpoints load_pointer() machine = Machine(dmem.copy(), ins_objects, start_addr_dict['p256init'], stop_addr_dict['p256init'], ctx=ctx, breakpoints=breakpoints) cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_msg(msg) load_d(d) load_k(k) machine.dmem = dmem.copy() machine.pc = start_addr_dict['p256sign'] machine.stop_addr = stop_addr_dict['p256sign'] machine.stats = stats cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() return dmem[pR], dmem[pS]
def run_isoncurve(x, y): """Runs the isoncurve primitive to check if a point is a valid curve point""" global dmem global inst_cnt global cycle_cnt global ctx global stats load_pointer() machine = Machine(dmem.copy(), ins_objects, start_addr_dict['p256init'], stop_addr_dict['p256init'], ctx=ctx, breakpoints=breakpoints) cont = True while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() load_x(x) load_y(y) machine.dmem = dmem.copy() machine.pc = start_addr_dict['p256isoncurve'] machine.stop_addr = stop_addr_dict['p256isoncurve'] cont = True machine.stats = stats while cont: cont, trace_str, cycles = machine.step() dump_trace_str(trace_str) inst_cnt += 1 cycle_cnt += cycles dmem = machine.dmem.copy() # point is on curve if r and s are equal on_curve = (dmem[pS] == dmem[pR]) return on_curve