Skip to content

Commit

Permalink
Merge pull request #24 from LedgerHQ/develop
Browse files Browse the repository at this point in the history
merge to master
  • Loading branch information
cedelavergne-ledger authored Dec 20, 2024
2 parents 99d5802 + a2f2e10 commit a1bdd35
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GIT_DESCRIBE=$(shell git describe --tags --abbrev=8 --always --long --dirty 2>/d
VERSION_TAG=$(shell echo $(GIT_DESCRIBE) | sed 's/^v//g')
APPVERSION_M=1
APPVERSION_N=2
APPVERSION_P=0
APPVERSION_P=1
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
APPNAME = "Mina"

Expand Down
11 changes: 11 additions & 0 deletions src/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "globals.h"
#include "random_oracle_input.h"

#define HEARTBEAT_INTERVAL 20

// Base field Fp
static const Field FIELD_MODULUS = {
0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -402,7 +404,12 @@ void group_scalar_mul(Group *q, const Scalar k, const Group *p)
}

Group t0;
uint8_t heartbeat_counter = 0;
for (size_t i = 0; i < SCALAR_BITS; i++) {
if (++heartbeat_counter >= HEARTBEAT_INTERVAL) {
io_seproxyhal_io_heartbeat();
heartbeat_counter = 0;
}
uint8_t di = (k[i / 8] >> (7 - (i % 8))) & 0x01;

// q = 2q
Expand Down Expand Up @@ -489,7 +496,9 @@ void affine_scalar_mul(Affine *q, const Scalar k, const Affine *p)
{
Group pp, pq;
affine_to_group(&pp, p);
io_seproxyhal_io_heartbeat();
group_scalar_mul(&pq, k, &pp);
io_seproxyhal_io_heartbeat();
affine_from_group(q, &pq);
}

Expand Down Expand Up @@ -625,6 +634,8 @@ bool message_derive(Scalar out, const Keypair *kp, const ROInput *input, const u
return false;
}

io_seproxyhal_io_heartbeat();

// blake2b hash
cx_blake2b_t ctx;
if(CX_OK != cx_blake2b_init_no_throw(&ctx, 256)){
Expand Down
14 changes: 13 additions & 1 deletion src/poseidon.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@

#include <os.h>
#include <string.h>
#include <os_io_seproxyhal.h>

#include "crypto.h"
#include "poseidon.h"

#define HEARTBEAT_INTERVAL 20

// Round constants Pasta Fp (first 64)
static const Field round_keys[ROUNDS][SPONGE_SIZE] = {
{
Expand Down Expand Up @@ -1466,9 +1469,13 @@ void sbox(Field xa, const Field x) // 09179b
void poseidon_permutation(State s)
{
Field tmp;

uint8_t heartbeat_counter = 0;
// Full rounds
for (size_t r = 0; r < FULL_ROUNDS; r++) {
if (++heartbeat_counter >= HEARTBEAT_INTERVAL) {
io_seproxyhal_io_heartbeat();
heartbeat_counter = 0;
}
// ark
for (size_t i = 0; i < SPONGE_SIZE; i++) {
field_copy(tmp, s[i]);
Expand Down Expand Up @@ -1509,8 +1516,13 @@ void poseidon_update(State s, const Field *input, const size_t len)
{
Field tmp;
size_t pairs = len / 2;
uint8_t heartbeat_counter = 0;

for (size_t i = 0; i < pairs; ++i) {
if (++heartbeat_counter >= HEARTBEAT_INTERVAL) {
io_seproxyhal_io_heartbeat();
heartbeat_counter = 0;
}
field_copy(tmp, s[0]);
field_add(s[0], tmp, input[2*i]);

Expand Down

0 comments on commit a1bdd35

Please sign in to comment.