Browse Source

fix detection of external random seed and adopt it in dp3t zencode

master
Jaromil 3 years ago
parent
commit
944da69be0
  1. 2
      src/zen_random.c
  2. 7
      src/zenroom.c
  3. 1
      src/zenroom.h
  4. 12
      test/zencode_dp3t/run.sh

2
src/zen_random.c

@ -68,7 +68,7 @@ void* rng_alloc() {
return NULL; }
// random seed provided externally
if(Z->random_seed[0]) {
if(Z->random_external) {
act(Z->lua,"Random seed is external, deterministic execution");
#ifndef ARCH_CORTEX
} else {

7
src/zenroom.c

@ -161,13 +161,12 @@ zenroom_t *zen_init(const char *conf, char *keys, char *data) {
Z->userdata = NULL;
Z->errorlevel = get_debug();
Z->random_generator = NULL;
Z->random_seed[0] = 0x0; // flag for external rngseed
Z->random_external = 0;
// use RNGseed from configuration if present (deterministic mode)
if(zconf_rngseed[0] != 0x0) {
// short p = 0;
// if(zconf_rngseed[0] == '0' && zconf_rngseed[1] == 'x') p += 2;
// hex2buf(Z->random_seed, &zconf_rngseed[p]);
Z->random_external = 1;
memset(Z->random_seed, 0x0, 256);
hex2buf(Z->random_seed, zconf_rngseed);
}
// initialize the random generator

1
src/zenroom.h

@ -70,6 +70,7 @@ typedef struct {
void *random_generator; // cast to RNG
char random_seed[RANDOM_SEED_LEN];
int random_external; // signal when rngseed is external
int errorlevel;
void *userdata; // anything passed at init (reserved for caller)

12
test/zencode_dp3t/run.sh

@ -2,6 +2,8 @@
# https://github.com/DP-3T/documents
RNGSEED=hex:00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
####################
# common script init
if ! test -r ../utils.sh; then
@ -46,8 +48,8 @@ Then print the 'ephemeral ids'
EOF
# now generate a test with 40.000 infected SK
cat <<EOF | $Z -z > SK_infected_40k.json
# now generate a test with 20.000 infected SK
cat <<EOF | $Z -z > SK_infected_20k.json
rule check version 1.0.0
rule input encoding hex
rule output encoding hex
@ -58,7 +60,7 @@ Then print the 'list of infected'
EOF
# extract a few random infected ephemeral ids to simulate proximity
cat <<EOF | $Z -z -a SK_infected_40k.json | tee EphID_infected.json
cat <<EOF | $Z -z -a SK_infected_20k.json | tee EphID_infected.json
scenario 'dp3t'
rule check version 1.0.0
rule input encoding hex
@ -74,7 +76,7 @@ Then print the 'ephemeral ids'
EOF
# given a list of infected and a list of ephemeral ids
cat <<EOF | tee dp3t_check.zen | $Z -z -a SK_infected_40k.json -k EphID_infected.json
cat <<EOF | tee dp3t_check.zen | $Z -z -a SK_infected_20k.json -k EphID_infected.json
scenario 'dp3t'
rule check version 1.0.0
rule input encoding hex
@ -88,7 +90,7 @@ Then print the 'proximity tracing'
EOF
# given a list of infected and a list of ephemeral ids
# cat <<EOF | $Z -c memmanager=sys -z -a $D/SK_infected_40k.json -k $D/EphID_2.json
# cat <<EOF | $Z -c memmanager=sys -z -a $D/SK_infected_20k.json -k $D/EphID_2.json
# scenario 'dp3t'
# rule check version 1.0.0
# rule input encoding hex

Loading…
Cancel
Save