-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimu_aeshpc_32bit.cpp
More file actions
71 lines (58 loc) · 1.55 KB
/
simu_aeshpc_32bit.cpp
File metadata and controls
71 lines (58 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "verime_lib.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stddef.h>
#ifndef D
#define D GENERIC_D
#endif
#define SEED_PRNG_BYTES 80/8
struct Prober;
int save_state(Prober *p);
void run_simu(
SimModel *sm,
Prober *p,
char* data,
size_t data_size
) {
// Data input organised as
// 1) SEED_PRNG_BYTES bytes of seed
// 2) 16 bytes of umsk plaintext
// 3) 16*D bytes of msk key
// Initialise control signal at the top level
sm->vtop->in_valid=0;
sm->vtop->in_seed_valid=0;
// Reset the AES core
sm->vtop->rst = 1;
sim_clock_cycle(sm);
sm->vtop->rst = 0;
sim_clock_cycle(sm);
// Feed the seed
memcpy(&sm->vtop->in_seed,data,SEED_PRNG_BYTES);
sm->vtop->in_seed_valid = 1;
sm->vtop->eval();
while(sm->vtop->in_seed_ready!=1){
sim_clock_cycle(sm);
}
sim_clock_cycle(sm);
sm->vtop->in_seed_ready = 0;
// Prepare the run with input data
// Assign the plaintext with constant sharing
memcpy(&sm->vtop->in_shares_plaintext,data+SEED_PRNG_BYTES,16*D);
// Assign the key
memcpy(&sm->vtop->in_shares_key,data+SEED_PRNG_BYTES+16*D,16*D);
// Start the run
sm->vtop->in_valid = 1;
sm->vtop->eval();
while(sm->vtop->in_ready!=1){
sim_clock_cycle(sm);
}
sim_clock_cycle(sm);
sm->vtop->in_valid = 0;
sm->vtop->eval();
// Run until the end of the computation
while(sm->vtop->out_valid!=1){
save_state(p);
sim_clock_cycle(sm);
}
save_state(p);
}