fix modexp bug

This commit is contained in:
jangko 2023-08-03 12:10:38 +07:00
parent d3d172edee
commit b6337e9b66
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 3 additions and 3 deletions

View File

@ -186,9 +186,6 @@ proc modExp*(b, e, m: openArray[byte]): seq[byte] =
if m.len == 0: if m.len == 0:
return @[0.byte] return @[0.byte]
if e.len == 0:
return @[1.byte]
if mp_init_multi(base, exp.addr, modulo.addr, nil) != MP_OKAY: if mp_init_multi(base, exp.addr, modulo.addr, nil) != MP_OKAY:
return return
@ -209,6 +206,9 @@ proc modExp*(b, e, m: openArray[byte]): seq[byte] =
# For all x != 0, x^0 == 1 as well # For all x != 0, x^0 == 1 as well
mp_clear_multi(base, exp.addr, modulo.addr, nil) mp_clear_multi(base, exp.addr, modulo.addr, nil)
return @[1.byte] return @[1.byte]
else:
mp_clear_multi(base, exp.addr, modulo.addr, nil)
return @[1.byte]
if b.len > 0: if b.len > 0:
discard mp_from_ubin(base, b[0].getPtr, b.len.csize_t) discard mp_from_ubin(base, b[0].getPtr, b.len.csize_t)