Skip to content

Commit

Permalink
Example 1 - avoid optimizing out stack variable clearing by using an …
Browse files Browse the repository at this point in the history
…__attribute__
  • Loading branch information
isle2983 committed Jan 29, 2017
1 parent 9d560f9 commit 72c0ebb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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
9 changes: 9 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,14 @@ static void secp256k1_ge_clear(secp256k1_ge *r) {
secp256k1_fe_clear(&r->y);
}

static void __attribute__((optimize("O0"))) secp256k1_secure_clear(void *s, size_t n) {
(void) 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

0 comments on commit 72c0ebb

Please sign in to comment.