Fix carry bug in sum/diff
This commit is contained in:
parent
c621355d8d
commit
ff98558c4b
|
@ -356,7 +356,7 @@ func sum*(r: BigIntViewMut, a, b: distinct BigIntViewAny): CTBool[Word] =
|
|||
|
||||
for i in 0 ..< a.numLimbs():
|
||||
r[i] = a[i] + b[i] + Word(result)
|
||||
result = a[i].isMsbSet()
|
||||
result = r[i].isMsbSet()
|
||||
r[i] = r[i].mask()
|
||||
|
||||
func diff*(r: BigIntViewMut, a, b: distinct BigIntViewAny): CTBool[Word] =
|
||||
|
@ -370,7 +370,7 @@ func diff*(r: BigIntViewMut, a, b: distinct BigIntViewAny): CTBool[Word] =
|
|||
|
||||
for i in 0 ..< a.numLimbs():
|
||||
r[i] = a[i] - b[i] - Word(result)
|
||||
result = a[i].isMsbSet()
|
||||
result = r[i].isMsbSet()
|
||||
r[i] = r[i].mask()
|
||||
|
||||
# ############################################################
|
||||
|
|
|
@ -278,16 +278,16 @@ proc mainAdd() =
|
|||
# echo "rGMP: ", rGMP.toHex()
|
||||
# echo "rConstantine: ", rConstantine.toHex()
|
||||
|
||||
# doAssert rGMP == rConstantine, block:
|
||||
# # Reexport as bigEndian for debugging
|
||||
# discard mpz_export(aBuf[0].addr, aW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, a)
|
||||
# discard mpz_export(bBuf[0].addr, bW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, b)
|
||||
# "\nModular Addition on curve " & $curve & " with operands\n" &
|
||||
# " a: " & aBuf.toHex & "\n" &
|
||||
# " b: " & bBuf.toHex & "\n" &
|
||||
# "failed:" & "\n" &
|
||||
# " GMP: " & rGMP.toHex() & "\n" &
|
||||
# " Constantine: " & rConstantine.toHex()
|
||||
doAssert rGMP == rConstantine, block:
|
||||
# Reexport as bigEndian for debugging
|
||||
discard mpz_export(aBuf[0].addr, aW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, a)
|
||||
discard mpz_export(bBuf[0].addr, bW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, b)
|
||||
"\nModular Addition on curve " & $curve & " with operands\n" &
|
||||
" a: " & aBuf.toHex & "\n" &
|
||||
" b: " & bBuf.toHex & "\n" &
|
||||
"failed:" & "\n" &
|
||||
" GMP: " & rGMP.toHex() & "\n" &
|
||||
" Constantine: " & rConstantine.toHex()
|
||||
|
||||
doAssert rGMP == r2Constantine, block:
|
||||
# Reexport as bigEndian for debugging
|
||||
|
@ -375,16 +375,16 @@ proc mainSub() =
|
|||
# echo "rGMP: ", rGMP.toHex()
|
||||
# echo "rConstantine: ", rConstantine.toHex()
|
||||
|
||||
# doAssert rGMP == rConstantine, block:
|
||||
# # Reexport as bigEndian for debugging
|
||||
# discard mpz_export(aBuf[0].addr, aW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, a)
|
||||
# discard mpz_export(bBuf[0].addr, bW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, b)
|
||||
# "\nModular Substraction on curve " & $curve & " with operands\n" &
|
||||
# " a: " & aBuf.toHex & "\n" &
|
||||
# " b: " & bBuf.toHex & "\n" &
|
||||
# "failed:" & "\n" &
|
||||
# " GMP: " & rGMP.toHex() & "\n" &
|
||||
# " Constantine: " & rConstantine.toHex()
|
||||
doAssert rGMP == rConstantine, block:
|
||||
# Reexport as bigEndian for debugging
|
||||
discard mpz_export(aBuf[0].addr, aW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, a)
|
||||
discard mpz_export(bBuf[0].addr, bW.addr, GMP_MostSignificantWordFirst, 1, GMP_WordNativeEndian, 0, b)
|
||||
"\nModular Substraction on curve " & $curve & " with operands\n" &
|
||||
" a: " & aBuf.toHex & "\n" &
|
||||
" b: " & bBuf.toHex & "\n" &
|
||||
"failed:" & "\n" &
|
||||
" GMP: " & rGMP.toHex() & "\n" &
|
||||
" Constantine: " & rConstantine.toHex()
|
||||
|
||||
doAssert rGMP == r2Constantine, block:
|
||||
# Reexport as bigEndian for debugging
|
||||
|
|
Loading…
Reference in New Issue