Files
kunlun/rom/riscv2/crypto/mbedtls-2.4.0/library/ed25519/ref10/fe_isnonzero.c
2024-09-28 14:24:04 +08:00

54 lines
662 B
C

#include "fe.h"
/*
return 1 if f == 0
return 0 if f != 0
Preconditions:
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
*/
int fe_isnonzero(const fe f) {
unsigned char s[32];
unsigned char r;
fe_tobytes(s, f);
r = s[0];
#define F(i) r |= s[i]
F(1);
F(2);
F(3);
F(4);
F(5);
F(6);
F(7);
F(8);
F(9);
F(10);
F(11);
F(12);
F(13);
F(14);
F(15);
F(16);
F(17);
F(18);
F(19);
F(20);
F(21);
F(22);
F(23);
F(24);
F(25);
F(26);
F(27);
F(28);
F(29);
F(30);
F(31);
#undef F
return r != 0;
}