minor fixes.

This commit is contained in:
NIIBE Yutaka
2014-04-14 18:37:25 +09:00
parent 53aa3de9b4
commit 4d6f59079a
5 changed files with 17 additions and 8 deletions

View File

@@ -1,3 +1,11 @@
2014-04-14 Niibe Yutaka <gniibe@fsij.org>
* src/jpc.c (jpc_to_ac): Error check before mod_inv.
* src/mod.c (mod_inv): No return value (if N==0 returns ZERO).
* src/bn.c [BN256_NO_RANDOM]: Only include "random.h" if needed.
2014-04-08 Niibe Yutaka <gniibe@fsij.org>
* src/mod.c (mod_inv): Use MAX_GCD_STEPS_BN256.

View File

@@ -23,7 +23,9 @@
#include <stdint.h>
#include <string.h>
#ifndef BN256_NO_RANDOM
#include "random.h"
#endif
#include "bn.h"
uint32_t

View File

@@ -185,9 +185,11 @@ FUNC(jpc_to_ac) (ac *X, const jpc *A)
{
bn256 z_inv[1], z_inv_sqr[1];
if (mod_inv (z_inv, A->z, CONST_P256) < 0)
if (bn256_is_zero (A->z))
return -1;
mod_inv (z_inv, A->z, CONST_P256);
MFNC(sqr) (z_inv_sqr, z_inv);
MFNC(mul) (z_inv, z_inv, z_inv_sqr);

View File

@@ -147,8 +147,10 @@ mod_reduce (bn256 *X, const bn512 *A, const bn256 *B, const bn256 *MU_lower)
* @brief C = X^(-1) mod N
*
* Assume X and N are co-prime (or N is prime).
* If N==0, return 0.
*
*/
int
void
mod_inv (bn256 *C, const bn256 *X, const bn256 *N)
{
bn256 u[1], v[1], tmp[1];
@@ -157,9 +159,6 @@ mod_inv (bn256 *C, const bn256 *X, const bn256 *N)
#define borrow carry
int n = MAX_GCD_STEPS_BN256;
if (bn256_is_zero (X))
return -1;
memset (C, 0, sizeof (bn256));
memcpy (u, X, sizeof (bn256));
memcpy (v, N, sizeof (bn256));
@@ -352,6 +351,4 @@ mod_inv (bn256 *C, const bn256 *X, const bn256 *N)
}
}
#undef borrow
return 0;
}

View File

@@ -1,3 +1,3 @@
void mod_reduce (bn256 *X, const bn512 *A, const bn256 *B,
const bn256 *MU_lower);
int mod_inv (bn256 *X, const bn256 *A, const bn256 *N);
void mod_inv (bn256 *X, const bn256 *A, const bn256 *N);