Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor fe_isnonzero to fe_isnonzero_vartime #1893

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ include = [
"include/ring-core/asm_base.h",
"include/ring-core/base.h",
"include/ring-core/check.h",
"include/ring-core/mem.h",
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
"include/ring-core/poly1305.h",
"include/ring-core/target.h",
"include/ring-core/type_check.h",
Expand Down
17 changes: 10 additions & 7 deletions crypto/curve25519/curve25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
//
// The field functions are shared by Ed25519 and X25519 where possible.

#include <ring-core/mem.h>

#include "internal.h"
#include "../internal.h"

Expand Down Expand Up @@ -397,14 +395,19 @@ static void fe_invert(fe *out, const fe *z) {

// return 0 if f == 0
// return 1 if f != 0
static int fe_isnonzero(const fe_loose *f) {
static int fe_isnonzero_vartime(const fe_loose *f) {
fe tight;
fe_carry(&tight, f);
uint8_t s[32];
fe_tobytes(s, &tight);

static const uint8_t zero[32] = {0};
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
for (size_t i = 0; i < sizeof(s); i++) {
if (s[i] != 0) {
return 1;
}
}

return 0;
}

// return 1 if f is in {1,3,5,...,q-2}
Expand Down Expand Up @@ -507,9 +510,9 @@ int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]) {
fe_sq_tt(&vxx, &h->X);
fe_mul_ttl(&vxx, &vxx, &v);
fe_sub(&check, &vxx, &u);
if (fe_isnonzero(&check)) {
if (fe_isnonzero_vartime(&check)) {
fe_add(&check, &vxx, &u);
if (fe_isnonzero(&check)) {
if (fe_isnonzero_vartime(&check)) {
return 0;
}
fe_mul_ttt(&h->X, &h->X, &sqrtm1);
Expand Down
1 change: 0 additions & 1 deletion crypto/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
* copied and put under another distribution licence
* [including the GNU Public Licence.] */

#include <ring-core/mem.h>
tisonkun marked this conversation as resolved.
Show resolved Hide resolved
#include "internal.h"

int CRYPTO_memcmp(const void *in_a, const void *in_b, size_t len) {
Expand Down
69 changes: 0 additions & 69 deletions include/ring-core/mem.h

This file was deleted.

Loading