-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsecCompMultiParty.h
142 lines (123 loc) · 3.57 KB
/
secCompMultiParty.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* secCompMultiParty.h
*
* Created on: Mar 31, 2015
* Author: froike
*/
#ifndef SECCOMPMULTIPARTY_H_
#define SECCOMPMULTIPARTY_H_
/*
* define section (pre-compilation values)
* STRING_BUFFER_SIZE will describes the maximum buffer length.
*/
#define STRING_BUFFER_SIZE 256
#define true 1
#define false 0
#define flagXor 1
#define flagXnor 2
#define flagNone 0
#define dispXor "Xor"
#define dispXnor "Xnor"
#define dispNone "None"
/*
* This struct present one player and array of his inputs bit serials.
*/
typedef struct player{
unsigned int playerBitAmount;
unsigned int * playerBitArray;
} Player;
/*
* This struct present one gate with two inputs bit, one output bit and a Truth table.
*
*/
typedef struct truthTable{
unsigned int FF : 1;
unsigned int FT : 1;
unsigned int TF : 1;
unsigned int TT : 1;
unsigned int Y1 : 1;
unsigned int Y2 : 1;
unsigned int Y3 : 1;
unsigned int Y4 : 1;
} TruthTable;
typedef struct gate{
unsigned int inputBit1;
unsigned int inputBit2;
unsigned int outputBit;
TruthTable truthTable ;
unsigned int flags : 2; //limited for 2 bits
} Gate;
typedef struct cycle{
unsigned int amountOfPlayers;
unsigned int amountOfGates;
Gate ** specialGates;
Player outputbits;
Gate * gateArray;
Player ** playerArray;
} Cycle;
/*
* This function got path fo file that present an circle (format instructions below).
* if it success to create circle then This function return an Circle struct.
* else it will return NULL pointer and print the reason for failing.
*
* Circle file format will start with "<amount of Gates> <amount of Players>" as to numbers split with one space.
*
* Next lines will contains the player ID and the amount of input bits he need. after that, line by line, one line for each bit serial.
* Exemple:
* P<player ID> <amount of player inputs bit>
* <first input bit serial>
* <second input bit serial>
* .
* .
*
* in this way it collect player after player until it collect many players as described in <amount of Players>...
*
* then will need to come the gates describes lines. each line for gate in this format:
* <first input bit> <sec input bit> <output bit> <truth Table> <flags>
* the truth Table will be in format of 4 digit length contains just 1 or 0 digits.
* flags is optional.
*
* Exmple for valid file:
* # if you have notes you can write it start with '#'... and we just ignore that lines.
* 4 3
* # Players:
* P0 3
* 0
* 1
* 2
* P1 3
* 3
* 4
* 5
* P2 3
* 6
* 7
* 8
* # Gates:
* 0 1 9 1010
* 2 3 10 1101 freeXor
* 4 5 11 0010
* 6 7 12 0101
*
*/
extern Cycle * readCycleFromFile(char path[]);
/*
* private function that crate gates structs. it used in readCycleFromFile function.
*/
Gate GateCreator(const unsigned int inputBit1, const unsigned int inputBit2, const unsigned int outputBit, const TruthTable TTable, const unsigned int flags);
/*
* this function print full given Cycle it cycle file format.
* (the format explanation can be found in this h file at readCycleFromFile function documentation.)
*/
extern void printCycle(const Cycle * C);
/*
* this function remove all spaces from the string it get.
*/
void removeSpacesAndTubs(char* source);
/*
* This function react as destroyer for Circles. it will free all the dynamic memory it use.
* Attention: if you forget use this function after done with circle, parts of it will remain in the memory until your program will terminated.
*/
void freeCircle(Cycle * c);
Gate ** specialGatesCollector(Gate * GatesArray, const unsigned int arraySize, const unsigned int specialAmount);
#endif /* SECCOMPMULTIPARTY_H_ */