fix bn.c
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
2014-03-19 Niibe Yutaka <gniibe@fsij.org>
|
2014-03-19 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* src/bn.c (bn256_add): Fix for X == B.
|
||||||
|
(bn256_sub): Likewise.
|
||||||
|
|
||||||
* src/ecc-edwards.c: New.
|
* src/ecc-edwards.c: New.
|
||||||
|
|
||||||
2014-03-18 Niibe Yutaka <gniibe@fsij.org>
|
2014-03-18 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|||||||
10
src/bn.c
10
src/bn.c
@@ -30,6 +30,7 @@ uint32_t
|
|||||||
bn256_add (bn256 *X, const bn256 *A, const bn256 *B)
|
bn256_add (bn256 *X, const bn256 *A, const bn256 *B)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
uint32_t v;
|
||||||
uint32_t carry = 0;
|
uint32_t carry = 0;
|
||||||
uint32_t *px;
|
uint32_t *px;
|
||||||
const uint32_t *pa, *pb;
|
const uint32_t *pa, *pb;
|
||||||
@@ -40,9 +41,10 @@ bn256_add (bn256 *X, const bn256 *A, const bn256 *B)
|
|||||||
|
|
||||||
for (i = 0; i < BN256_WORDS; i++)
|
for (i = 0; i < BN256_WORDS; i++)
|
||||||
{
|
{
|
||||||
|
v = *pb;
|
||||||
*px = *pa + carry;
|
*px = *pa + carry;
|
||||||
carry = (*px < carry);
|
carry = (*px < carry);
|
||||||
*px += *pb;
|
*px += v;
|
||||||
carry += (*px < *pb);
|
carry += (*px < *pb);
|
||||||
px++;
|
px++;
|
||||||
pa++;
|
pa++;
|
||||||
@@ -56,6 +58,7 @@ uint32_t
|
|||||||
bn256_sub (bn256 *X, const bn256 *A, const bn256 *B)
|
bn256_sub (bn256 *X, const bn256 *A, const bn256 *B)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
uint32_t v;
|
||||||
uint32_t borrow = 0;
|
uint32_t borrow = 0;
|
||||||
uint32_t *px;
|
uint32_t *px;
|
||||||
const uint32_t *pa, *pb;
|
const uint32_t *pa, *pb;
|
||||||
@@ -68,9 +71,10 @@ bn256_sub (bn256 *X, const bn256 *A, const bn256 *B)
|
|||||||
{
|
{
|
||||||
uint32_t borrow0 = (*pa < borrow);
|
uint32_t borrow0 = (*pa < borrow);
|
||||||
|
|
||||||
|
v = *pb;
|
||||||
*px = *pa - borrow;
|
*px = *pa - borrow;
|
||||||
borrow = (*px < *pb) + borrow0;
|
borrow = (*px < v) + borrow0;
|
||||||
*px -= *pb;
|
*px -= v;
|
||||||
px++;
|
px++;
|
||||||
pa++;
|
pa++;
|
||||||
pb++;
|
pb++;
|
||||||
|
|||||||
Reference in New Issue
Block a user