summaryrefslogtreecommitdiff
path: root/src/util/test_crypto_ecc_dlog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/test_crypto_ecc_dlog.c')
-rw-r--r--src/util/test_crypto_ecc_dlog.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/util/test_crypto_ecc_dlog.c b/src/util/test_crypto_ecc_dlog.c
index a2c02a94e..2b0c7433c 100644
--- a/src/util/test_crypto_ecc_dlog.c
+++ b/src/util/test_crypto_ecc_dlog.c
@@ -44,7 +44,7 @@
/**
* Maximum memory to use, sqrt(MAX_FACT) is a good choice.
*/
-#define MAX_MEM 10
+#define MAX_MEM 100
/**
* How many values do we test?
@@ -65,38 +65,38 @@
static void
test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc)
{
- gcry_mpi_t fact;
- gcry_mpi_t n;
- gcry_ctx_t ctx;
- gcry_mpi_point_t q;
- gcry_mpi_point_t g;
+ struct GNUNET_CRYPTO_EccScalar* fact;
+ struct GNUNET_CRYPTO_EccScalar* n;
+ struct GNUNET_CRYPTO_EccPoint* q;
unsigned int i;
int x;
int iret;
- GNUNET_assert (0 == gcry_mpi_ec_new (&ctx, NULL, CURVE));
- g = gcry_mpi_ec_get_point ("g", ctx, 0);
- GNUNET_assert (NULL != g);
- n = gcry_mpi_ec_get_mpi ("n", ctx, 0);
- q = gcry_mpi_point_new (0);
- fact = gcry_mpi_new (0);
for (i = 0; i < TEST_ITER; i++)
{
fprintf (stderr, ".");
x = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
MAX_FACT);
+ n = GNUNET_new (struct GNUNET_CRYPTO_EccScalar);
+ for (i = 0; i < x; i++)
+ sodium_increment (n->v, sizeof (n->v));
+ //memcpy (n->v, &x, sizeof (x));
if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
2))
{
- gcry_mpi_set_ui (fact, x);
- gcry_mpi_sub (fact, n, fact);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Trying negative %d\n", -x);
+ fact = GNUNET_new (struct GNUNET_CRYPTO_EccScalar);
+ crypto_core_ed25519_scalar_negate (fact->v, n->v);
x = -x;
+ GNUNET_free (n);
}
else
{
- gcry_mpi_set_ui (fact, x);
+ fact = n;
}
- gcry_mpi_ec_mul (q, fact, g, ctx);
+ q = GNUNET_new (struct GNUNET_CRYPTO_EccPoint);
+ crypto_scalarmult_ed25519_base_noclamp (q->v, fact->v);
if (x !=
(iret = GNUNET_CRYPTO_ecc_dlog (edc,
q)))
@@ -108,11 +108,8 @@ test_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc)
GNUNET_assert (0);
}
}
- gcry_mpi_release (fact);
- gcry_mpi_release (n);
- gcry_mpi_point_release (g);
- gcry_mpi_point_release (q);
- gcry_ctx_release (ctx);
+ GNUNET_free (fact);
+ GNUNET_free (q);
fprintf (stderr, "\n");
}
@@ -127,13 +124,13 @@ test_math (struct GNUNET_CRYPTO_EccDlogContext *edc)
{
int i;
int j;
- gcry_mpi_point_t ip;
- gcry_mpi_point_t jp;
- gcry_mpi_point_t r;
- gcry_mpi_point_t ir;
- gcry_mpi_point_t irj;
- gcry_mpi_point_t r_inv;
- gcry_mpi_point_t sum;
+ struct GNUNET_CRYPTO_EccPoint* ip;
+ struct GNUNET_CRYPTO_EccPoint* jp;
+ struct GNUNET_CRYPTO_EccPoint* r;
+ struct GNUNET_CRYPTO_EccPoint* ir;
+ struct GNUNET_CRYPTO_EccPoint* irj;
+ struct GNUNET_CRYPTO_EccPoint* r_inv;
+ struct GNUNET_CRYPTO_EccPoint* sum;
for (i = -MATH_MAX; i < MATH_MAX; i++)
{
@@ -141,6 +138,8 @@ test_math (struct GNUNET_CRYPTO_EccDlogContext *edc)
for (j = -MATH_MAX; j < MATH_MAX; j++)
{
fprintf (stderr, ".");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%d + %d\n", i, j);
jp = GNUNET_CRYPTO_ecc_dexp (edc, j);
GNUNET_CRYPTO_ecc_rnd (edc,
&r,
@@ -148,9 +147,13 @@ test_math (struct GNUNET_CRYPTO_EccDlogContext *edc)
ir = GNUNET_CRYPTO_ecc_add (edc, ip, r);
irj = GNUNET_CRYPTO_ecc_add (edc, ir, jp);
sum = GNUNET_CRYPTO_ecc_add (edc, irj, r_inv);
- GNUNET_assert (i + j ==
- GNUNET_CRYPTO_ecc_dlog (edc,
- sum));
+ int res = GNUNET_CRYPTO_ecc_dlog (edc, sum);
+ if (i + j != res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Got %d, expected %d\n", res, i+j);
+ GNUNET_assert (0);
+ }
GNUNET_CRYPTO_ecc_free (jp);
GNUNET_CRYPTO_ecc_free (ir);
GNUNET_CRYPTO_ecc_free (irj);