Skip to content

[trivial] clear stack variable by function #438

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/ecmult_gen_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
secp256k1_ge_from_storage(&add, &adds);
secp256k1_gej_add_ge(r, r, &add);
}
bits = 0;
secp256k1_int_clear(&bits);
secp256k1_ge_clear(&add);
secp256k1_scalar_clear(&gnb);
}
Expand Down
14 changes: 14 additions & 0 deletions src/group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef _SECP256K1_GROUP_IMPL_H_
#define _SECP256K1_GROUP_IMPL_H_

#include <string.h>
#include "num.h"
#include "field.h"
#include "group.h"
Expand Down Expand Up @@ -213,6 +214,19 @@ static void secp256k1_ge_clear(secp256k1_ge *r) {
secp256k1_fe_clear(&r->y);
}

typedef void *(*memset_t)(void *, int, size_t);

static volatile memset_t secure_memset = memset;

static void secp256k1_secure_clear(void *s, size_t n) {
(void) secure_memset(s, 0, n);

}

static void secp256k1_int_clear(int *r) {
secp256k1_secure_clear(r, sizeof(*r));
}

static int secp256k1_ge_set_xquad(secp256k1_ge *r, const secp256k1_fe *x) {
secp256k1_fe x2, x3, c;
r->x = *x;
Expand Down