mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-18 09:41:10 +00:00
Rework t_compare_mpi() to improve diagnostics.
This commit is contained in:
parent
42f68fb348
commit
ae7f1e909e
1 changed files with 31 additions and 7 deletions
38
t/t_mpi.c
38
t/t_mpi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014 Dag-Erling Smørgrav
|
* Copyright (c) 2014-2017 Dag-Erling Smørgrav
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -73,7 +73,7 @@ static uint32_t large_e[LARGE_E_SIZE];
|
||||||
* Verify that an MPI has never grown.
|
* Verify that an MPI has never grown.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
t_mpi_not_grown(cryb_mpi *x)
|
t_mpi_not_grown(const cryb_mpi *x)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ t_mpi_grown(cryb_mpi *x)
|
||||||
* Verify that an MPI is zero.
|
* Verify that an MPI is zero.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
t_mpi_is_zero(cryb_mpi *x)
|
t_mpi_is_zero(const cryb_mpi *x)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
|
@ -117,11 +117,24 @@ t_mpi_is_zero(cryb_mpi *x)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print an MPI in semi-human-readable form
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
t_verbose_mpi(const cryb_mpi *x)
|
||||||
|
{
|
||||||
|
|
||||||
|
t_verbose("%c", x->neg ? '-' : '+');
|
||||||
|
t_verbose("%08x", x->msb == 0 ? 0 : x->words[0]);
|
||||||
|
for (unsigned int i = 1; i < (x->msb + 31) / 32; ++i)
|
||||||
|
t_verbose(" %08x", x->words[i]);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Verify that an MPI has the expected value
|
* Verify that an MPI has the expected value
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
t_compare_mpi(cryb_mpi *e, cryb_mpi *x)
|
t_compare_mpi(const cryb_mpi *e, const cryb_mpi *x)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
|
@ -129,9 +142,20 @@ t_compare_mpi(cryb_mpi *e, cryb_mpi *x)
|
||||||
return (1);
|
return (1);
|
||||||
if (e == NULL || x == NULL)
|
if (e == NULL || x == NULL)
|
||||||
return (0);
|
return (0);
|
||||||
ret &= t_compare_u(e->msb, x->msb);
|
if (x->words == NULL) {
|
||||||
ret &= t_compare_i(e->neg, x->neg);
|
t_verbose("uninitialized MPI\n");
|
||||||
ret &= t_compare_mem(e->words, x->words, (e->msb + 7) / 8);
|
return (0);
|
||||||
|
}
|
||||||
|
if (e->neg != x->neg || e->msb != x->msb ||
|
||||||
|
memcmp(e->words, x->words, (e->msb + 7) / 8) != 0) {
|
||||||
|
t_verbose("expected ");
|
||||||
|
t_verbose_mpi(e);
|
||||||
|
t_verbose("\n");
|
||||||
|
t_verbose("received ");
|
||||||
|
t_verbose_mpi(x);
|
||||||
|
t_verbose("\n");
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue