-
Notifications
You must be signed in to change notification settings - Fork 9
/
runner.cpp
75 lines (60 loc) · 1.58 KB
/
runner.cpp
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
71
72
73
74
75
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <bndiff/config.h>
#include <bndiff/operation.h>
#include <bndiff/module.h>
#include "runner.h"
#include "multi.h"
bool Runner::run(void) {
uint8_t numbers[NUM_BIGNUMS][BNSTR_LEN];
bool ret = false;
bool compare = true;
size_t loops = 0;
if ( input->extract((uint8_t*)numbers, sizeof(numbers)) == false ) {
return false;
}
if ( multi->initialize() == false ) {
goto end;
}
for (size_t i = 0; i < NUM_BIGNUMS; i++) {
multi->bignum_from_bin(numbers[i], BNSTR_LEN, i);
}
operation_t operation;
while ( input->extract(&operation, sizeof(operation)) == true ) {
loops++;
uint8_t opt;
if ( input->extract(&opt, sizeof(opt)) != true ) {
break;
}
if ( multi->exec_operation(operation, opt) == false ) {
compare = false;
break;
}
if ( multi->compare() == false ) {
abort();
}
/* Swap two arbitrary bignums */
uint8_t swap_a, swap_b;
if ( input->extract(&swap_a, sizeof(swap_a)) != true ) {
break;
}
if ( input->extract(&swap_b, sizeof(swap_b)) != true ) {
break;
}
swap_a %= NUM_BIGNUMS;
swap_b %= NUM_BIGNUMS;
multi->swap_bignum(swap_a, swap_b);
if ( loops == 2 ) {
break;
}
}
if ( compare == true ) {
if ( multi->compare() == false ) {
abort();
}
}
end:
multi->shutdown();
return ret;
}