mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-01-03 02:11:10 +00:00
Add mpi_eq_abs() and mpi_eq() predicates.
This commit is contained in:
parent
b6368af502
commit
c5b962387c
2 changed files with 26 additions and 1 deletions
|
@ -58,5 +58,7 @@ int mpi_add_abs(cryb_mpi *, cryb_mpi *, cryb_mpi *);
|
||||||
int mpi_sub_abs(cryb_mpi *, cryb_mpi *, cryb_mpi *);
|
int mpi_sub_abs(cryb_mpi *, cryb_mpi *, cryb_mpi *);
|
||||||
int mpi_cmp_abs(cryb_mpi *, cryb_mpi *);
|
int mpi_cmp_abs(cryb_mpi *, cryb_mpi *);
|
||||||
int mpi_cmp(cryb_mpi *, cryb_mpi *);
|
int mpi_cmp(cryb_mpi *, cryb_mpi *);
|
||||||
|
int mpi_eq_abs(cryb_mpi *, cryb_mpi *);
|
||||||
|
int mpi_eq(cryb_mpi *, cryb_mpi *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <cryb/mpi.h>
|
#include <cryb/mpi.h>
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ mpi_cmp_abs(cryb_mpi *X, cryb_mpi *Y)
|
||||||
if (X->msb < Y->msb)
|
if (X->msb < Y->msb)
|
||||||
return (-1);
|
return (-1);
|
||||||
/* no luck, compare word by word */
|
/* no luck, compare word by word */
|
||||||
for (i = X->msb / 32; i >= 0; --i) {
|
for (i = (X->msb + 31) / 32; i >= 0; --i) {
|
||||||
if (X->words[i] > Y->words[i])
|
if (X->words[i] > Y->words[i])
|
||||||
return (1);
|
return (1);
|
||||||
if (X->words[i] < Y->words[i])
|
if (X->words[i] < Y->words[i])
|
||||||
|
@ -79,3 +80,25 @@ mpi_cmp(cryb_mpi *X, cryb_mpi *Y)
|
||||||
return (mpi_cmp_abs(X, Y));
|
return (mpi_cmp_abs(X, Y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare for equality
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
mpi_eq_abs(cryb_mpi *A, cryb_mpi *B)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (A->msb == B->msb &&
|
||||||
|
memcmp(A->words, B->words, (A->msb + 31) / 32) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare for equality
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
mpi_eq(cryb_mpi *A, cryb_mpi *B)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (A->neg == B->neg && A->msb != B->msb &&
|
||||||
|
memcmp(A->words, B->words, (A->msb + 31) / 32) == 0);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue