refactor code and implement unit tests

This commit is contained in:
2024-05-29 07:18:30 -05:00
parent 4f3b37642f
commit 4fd3e6cc5a
16 changed files with 540 additions and 601 deletions

0
test/__init__.py Normal file
View File

View File

@@ -0,0 +1,10 @@
{
"OuterClientShuffleEphemeralKey": [[1,4,2,9,5,7,8,3,0,6]],
"OuterClientShuffleFunctionEphemeralKey": [[4,3,2,5,1,6,7,8,0,9]],
"ClientEphemeralKey": [[21,149,75,73,228,81,79],[41,189,80,209,45,101,53],[139,238,141,159,30,79,214],[239,234,72,75,80,190,124],[203,225,246,200,205,195,92],[201,185,113,101,176,216,106],[14,210,125,70,53,128,57],[115,27,97,39,199,26,104],[29,4,55,5,13,57,19],[158,184,137,0,221,12,217]],
"ClientShuffleEphemeralKeyA": [[5,0,4,3,2,6,1],[0,6,2,1,5,3,4],[1,2,0,3,5,4,6],[0,2,6,3,4,5,1],[5,1,2,0,3,4,6],[1,0,3,4,5,6,2],[3,0,5,2,6,4,1],[6,4,5,3,0,2,1],[2,4,6,0,3,5,1],[4,6,2,3,5,1,0]],
"OuterClientShuffleMediumEphemeralKey": [[2,3,9,6,5,7,4,1,0,8]],
"OuterClientShuffleFunctionMediumEphemeralKey": [[0,1,6,3,4,5,7,9,2,8]],
"ClientShuffleMediumEphemeralKeyA": [[2,4,1,6,3,0,5],[5,1,6,4,0,2,3],[3,6,5,1,4,0,2],[6,4,5,2,3,1,0],[6,0,3,5,1,2,4],[6,0,3,1,4,2,5],[4,1,3,0,2,5,6],[5,0,2,1,6,4,3],[3,2,4,5,6,0,1],[1,5,0,2,3,6,4]],
"ClientMediumEphemeralKey": [[196,239,0,227,191,41,36],[99,212,122,236,132,38,217],[196,175,206,246,149,100,83],[18,216,7,225,159,221,59],[56,200,125,86,197,39,108],[214,128,152,217,7,138,12],[47,165,141,81,99,208,85],[71,79,10,15,36,139,177],[68,22,52,200,132,0,125],[205,198,219,188,190,238,23]]
}

View File

@@ -0,0 +1,30 @@
{
"OuterFunctionKey": [[9, 7, 4, 2, 5, 3, 0, 6, 1, 8]],
"OuterFunctionFunctionKey": [[8, 1, 4, 5, 2, 3, 7, 6, 0, 9]],
"OuterServerShuffleFunctionKey": [[3, 9, 2, 5, 0, 7, 6, 8, 1, 4]],
"MutualKey": [[197, 126, 66, 64, 226, 18, 153], [28, 15, 172, 73, 132, 222, 220], [110, 115, 107, 210, 52, 23, 116], [178, 122, 168, 93, 146, 206, 80], [22, 191, 165, 251, 58, 135, 166], [137, 78, 235, 223, 179, 194, 64], [134, 130, 154, 214, 225, 215, 97], [60, 41, 193, 9, 197, 108, 87], [198, 134, 72, 146, 247, 223, 166], [104, 81, 159, 34, 29, 200, 196]],
"FunctionKey": [[1, 5, 0, 2, 3, 6, 4], [5, 2, 6, 4, 1, 3, 0], [4, 2, 3, 5, 6, 1, 0], [0, 3, 1, 6, 5, 2, 4], [4, 1, 3, 0, 6, 5, 2], [6, 3, 4, 2, 5, 1, 0], [2, 3, 0, 4, 1, 6, 5], [4, 0, 6, 5, 2, 3, 1], [3, 2, 4, 1, 0, 5, 6], [2, 3, 4, 1, 5, 0, 6]],
"ClientShuffleKeyX": [[6, 3, 1, 4, 5, 0, 2], [6, 5, 0, 2, 3, 4, 1], [1, 4, 0, 6, 3, 2, 5], [6, 1, 4, 5, 3, 2, 0], [2, 0, 1, 4, 3, 5, 6], [3, 0, 6, 2, 1, 4, 5], [3, 2, 0, 1, 6, 4, 5], [6, 2, 3, 0, 1, 5, 4], [3, 0, 6, 5, 4, 1, 2], [3, 2, 5, 0, 4, 1, 6]],
"MutualMediumKey": [[134, 55, 223, 228, 216, 192, 220], [84, 232, 155, 47, 216, 122, 96], [238, 56, 234, 113, 178, 232, 59], [159, 126, 156, 186, 176, 95, 207], [55, 49, 8, 218, 248, 232, 26], [244, 128, 254, 159, 227, 164, 88], [86, 49, 163, 158, 91, 29, 85], [224, 29, 111, 130, 45, 64, 242], [233, 36, 69, 153, 173, 187, 85], [190, 180, 204, 92, 117, 118, 208]],
"OuterFunctionMediumKey": [[1, 6, 0, 2, 9, 5, 8, 4, 7, 3]],
"OuterFunctionFunctionMediumKey": [[4, 1, 7, 8, 9, 6, 0, 2, 3, 5]],
"OuterServerShuffleFunctionMediumKey": [[4, 0, 5, 9, 3, 1, 7, 8, 6, 2]],
"FunctionMediumKey": [[0, 2, 5, 3, 6, 4, 1], [0, 6, 4, 3, 1, 2, 5], [1, 6, 2, 0, 4, 5, 3], [0, 3, 1, 5, 6, 2, 4], [3, 2, 0, 6, 5, 1, 4], [1, 3, 6, 4, 5, 0, 2], [5, 0, 6, 3, 1, 2, 4], [6, 4, 3, 5, 0, 1, 2], [5, 2, 3, 6, 1, 0, 4], [3, 6, 1, 0, 2, 5, 4]],
"ClientShuffleMediumKeyX": [[2, 1, 6, 0, 5, 4, 3], [3, 0, 5, 2, 6, 4, 1], [5, 3, 0, 1, 2, 6, 4], [3, 5, 4, 1, 0, 6, 2], [0, 5, 2, 4, 1, 3, 6], [5, 2, 3, 1, 4, 6, 0], [2, 1, 5, 6, 3, 0, 4], [4, 6, 0, 3, 5, 1, 2], [1, 3, 2, 0, 4, 5, 6], [3, 6, 5, 1, 0, 4, 2]],
"OuterPositionShuffleMediumKey": [[7, 5, 4, 8, 6, 3, 0, 1, 9, 2]],
"OuterPositionShuffleFunctionMediumKey": [[9, 2, 5, 0, 1, 6, 8, 4, 3, 7]],
"OuterPositionFunctionMediumKey": [[7, 2, 0, 8, 1, 6, 3, 5, 9, 4]],
"PositionFunctionMediumKey": [[1, 5, 4, 0, 6, 2, 3], [2, 4, 0, 5, 3, 6, 1], [1, 4, 0, 2, 5, 6, 3], [4, 1, 0, 3, 2, 6, 5], [4, 0, 2, 3, 5, 6, 1], [1, 0, 2, 3, 4, 6, 5], [2, 3, 1, 5, 0, 6, 4], [1, 0, 3, 2, 4, 5, 6], [4, 0, 1, 5, 2, 6, 3], [2, 1, 0, 3, 6, 5, 4]],
"PositionShuffleMediumKey": [[5, 4, 3, 1, 2, 0, 6], [0, 2, 5, 4, 6, 1, 3], [6, 3, 1, 2, 5, 0, 4], [0, 1, 6, 5, 4, 3, 2], [1, 2, 6, 0, 5, 3, 4], [2, 1, 5, 6, 0, 3, 4], [5, 3, 0, 4, 1, 2, 6], [2, 1, 4, 5, 3, 0, 6], [0, 1, 6, 2, 4, 5, 3], [3, 6, 4, 2, 5, 1, 0]],
"ClientKey": [[148, 232, 147, 96, 20, 201, 150], [120, 0, 158, 250, 176, 223, 82], [12, 81, 193, 212, 247, 100, 1], [127, 211, 164, 202, 25, 149, 34], [214, 38, 10, 197, 195, 97, 193], [177, 120, 199, 180, 206, 184, 155], [154, 146, 186, 205, 190, 47, 169], [164, 80, 233, 207, 214, 91, 108], [123, 101, 231, 244, 92, 88, 12], [222, 193, 85, 98, 224, 145, 0]],
"ClientShuffleKeyA": [[6, 0, 3, 5, 2, 1, 4], [4, 3, 2, 5, 0, 1, 6], [5, 4, 1, 0, 2, 3, 6], [3, 6, 1, 4, 5, 2, 0], [3, 5, 4, 2, 0, 1, 6], [6, 1, 5, 4, 2, 3, 0], [0, 4, 6, 3, 5, 1, 2], [0, 6, 4, 3, 1, 2, 5], [5, 0, 6, 3, 4, 1, 2], [3, 2, 0, 4, 1, 6, 5]],
"OuterClientShuffleKey": [[6, 4, 7, 8, 0, 2, 1, 9, 5, 3]],
"OuterClientShuffleFunctionKey": [[4, 2, 1, 0, 5, 7, 8, 9, 3, 6]],
"OuterClientShuffleMediumKey": [[6, 7, 0, 4, 1, 8, 2, 5, 3, 9]],
"OuterClientShuffleFunctionMediumKey": [[3, 2, 9, 5, 4, 7, 0, 6, 8, 1]],
"ClientShuffleMediumKeyA": [[5, 4, 0, 6, 1, 2, 3], [6, 0, 5, 3, 4, 1, 2], [5, 2, 0, 6, 3, 1, 4], [5, 4, 6, 1, 3, 2, 0], [0, 2, 3, 1, 4, 5, 6], [1, 3, 6, 4, 0, 5, 2], [2, 6, 4, 5, 1, 3, 0], [6, 3, 0, 2, 5, 4, 1], [5, 4, 1, 6, 0, 3, 2], [6, 2, 0, 4, 1, 3, 5]],
"ClientMediumKey": [[16, 193, 15, 233, 117, 250, 34], [246, 77, 93, 136, 102, 250, 63], [214, 203, 45, 87, 239, 246, 207], [97, 24, 129, 224, 42, 111, 39], [46, 178, 119, 116, 89, 226, 216], [212, 133, 56, 244, 233, 251, 117], [139, 72, 193, 199, 141, 188, 200], [60, 229, 239, 108, 154, 254, 241], [189, 192, 168, 92, 5, 121, 18], [160, 69, 107, 197, 130, 150, 168]]
}

View File

@@ -0,0 +1,680 @@
{
"MutualEphemeralKey": [
[
106,
113,
9,
54,
49,
4,
207
],
[
184,
3,
232,
179,
15,
113,
142
],
[
129,
44,
164,
54,
1,
32,
201
],
[
106,
50,
246,
140,
149,
179,
109
],
[
210,
11,
69,
193,
77,
245,
62
],
[
37,
76,
137,
24,
220,
30,
165
],
[
40,
57,
147,
225,
24,
176,
103
],
[
37,
212,
189,
203,
218,
138,
168
],
[
73,
227,
38,
164,
20,
239,
24
],
[
7,
194,
254,
76,
0,
244,
215
]
],
"FunctionEphemeralKey": [
[
6,
0,
1,
4,
2,
3,
5
],
[
2,
3,
6,
4,
0,
1,
5
],
[
2,
4,
0,
3,
6,
1,
5
],
[
0,
4,
2,
3,
1,
5,
6
],
[
6,
4,
2,
5,
1,
0,
3
],
[
5,
1,
0,
6,
4,
2,
3
],
[
1,
2,
4,
3,
6,
0,
5
],
[
6,
1,
4,
0,
5,
3,
2
],
[
2,
3,
5,
4,
6,
0,
1
],
[
1,
6,
4,
3,
5,
2,
0
]
],
"OuterFunctionEphemeralKey": [
[
0,
9,
6,
2,
1,
5,
3,
8,
7,
4
]
],
"OuterFunctionFunctionEphemeralKey": [
[
2,
3,
9,
7,
6,
0,
1,
4,
8,
5
]
],
"OuterServerShuffleFunctionEphemeralKey": [
[
0,
8,
5,
9,
7,
3,
1,
4,
6,
2
]
],
"MutualMediumEphemeralKey": [
[
106,
113,
9,
54,
49,
4,
207
],
[
184,
3,
232,
179,
15,
113,
142
],
[
129,
44,
164,
54,
1,
32,
201
],
[
106,
50,
246,
140,
149,
179,
109
],
[
210,
11,
69,
193,
77,
245,
62
],
[
37,
76,
137,
24,
220,
30,
165
],
[
40,
57,
147,
225,
24,
176,
103
],
[
37,
212,
189,
203,
218,
138,
168
],
[
73,
227,
38,
164,
20,
239,
24
],
[
7,
194,
254,
76,
0,
244,
215
]
],
"FunctionMediumEphemeralKey": [
[
1,
0,
5,
6,
4,
3,
2
],
[
4,
0,
1,
5,
3,
2,
6
],
[
6,
4,
0,
3,
1,
5,
2
],
[
6,
3,
4,
1,
2,
5,
0
],
[
4,
5,
2,
3,
1,
6,
0
],
[
4,
6,
1,
0,
3,
2,
5
],
[
5,
0,
6,
4,
2,
1,
3
],
[
3,
5,
2,
6,
0,
1,
4
],
[
0,
1,
3,
6,
2,
4,
5
],
[
6,
3,
4,
2,
5,
0,
1
]
],
"PositionFunctionMediumEphemeralKey": [
[
1,
2,
3,
4,
0,
6,
5
],
[
5,
2,
1,
3,
6,
0,
4
],
[
2,
1,
0,
4,
5,
6,
3
],
[
3,
6,
4,
1,
5,
0,
2
],
[
0,
4,
6,
3,
2,
1,
5
],
[
4,
5,
3,
2,
6,
0,
1
],
[
3,
5,
0,
6,
2,
1,
4
],
[
3,
5,
1,
6,
2,
0,
4
],
[
3,
0,
5,
2,
1,
4,
6
],
[
5,
4,
2,
6,
3,
0,
1
]
],
"OuterFunctionMediumEphemeralKey": [
[
5,
0,
3,
8,
9,
7,
6,
4,
2,
1
]
],
"OuterFunctionFunctionMediumEphemeralKey": [
[
6,
9,
7,
1,
2,
8,
3,
5,
4,
0
]
],
"OuterPositionFunctionMediumEphemeralKey": [
[
6,
8,
2,
1,
0,
5,
7,
9,
3,
4
]
],
"OuterServerShuffleFunctionMediumEphemeralKey": [
[
8,
0,
9,
6,
7,
4,
2,
1,
3,
5
]
],
"OuterPositionShuffleFunctionMediumEphemeralKey": [
[
7,
1,
9,
2,
6,
4,
0,
3,
5,
8
]
],
"PositionShuffleMediumEphemeralKey": [
[
0,
1,
5,
2,
4,
3,
6
],
[
1,
3,
5,
2,
6,
4,
0
],
[
3,
6,
0,
2,
5,
4,
1
],
[
3,
6,
2,
0,
5,
1,
4
],
[
2,
6,
4,
1,
0,
5,
3
],
[
6,
2,
0,
3,
1,
4,
5
],
[
5,
2,
1,
3,
4,
6,
0
],
[
3,
2,
0,
5,
1,
4,
6
],
[
4,
2,
6,
1,
0,
3,
5
],
[
3,
1,
5,
0,
6,
2,
4
]
],
"OuterPositionShuffleMediumEphemeralKey": [
[
1,
9,
6,
4,
0,
5,
7,
2,
8,
3
]
]
}

View File

@@ -0,0 +1,7 @@
{
"OuterServerShuffleEphemeralKey": [[7,5,2,1,8,4,3,6,9,0]],
"ServerEphemeralKey": [[206,101,8,204,115,100,89],[108,247,32,6,2,165,114],[52,169,117,54,230,48,109],[179,218,87,113,86,50,182],[248,53,202,160,133,191,208],[220,64,196,172,113,159,71],[129,99,201,133,213,131,195],[75,151,222,237,193,169,122],[131,125,69,154,243,214,89],[245,65,225,44,226,68,216]],
"ServerShuffleEphemeralKey": [[6,1,3,0,4,2,5],[3,2,1,0,4,5,6],[2,4,3,5,0,6,1],[4,1,3,6,0,2,5],[1,4,2,3,0,5,6],[6,4,5,0,2,3,1],[0,4,2,3,1,5,6],[0,6,3,5,1,2,4],[2,6,3,1,4,5,0],[5,0,4,1,6,3,2]],
"ServerMediumEphemeralKey": [[122,2,181,28,253,157,228],[209,94,236,250,2,133,44],[16,40,112,171,92,121,235],[242,194,137,155,217,175,61],[22,152,73,65,106,43,186],[101,77,107,181,210,24,204],[16,22,46,83,188,106,117],[31,144,220,193,98,30,81],[227,29,136,169,69,9,25],[79,106,14,23,137,61,59]],
"Alphabet": [[253, 144, 217, 190, 1, 49, 154], [103, 69, 139, 148, 17, 244, 36], [84, 171, 243, 99, 236, 46, 251], [128, 123, 182, 14, 176, 65, 31], [92, 241, 32, 224, 48, 223, 145], [222, 39, 131, 33, 233, 127, 73], [156, 101, 208, 162, 105, 169, 107], [80, 0, 83, 61, 125, 177, 164], [134, 64, 212, 111, 172, 26, 60], [242, 78, 245, 137, 115, 120, 149]]
}

View File

@@ -0,0 +1,26 @@
{
"OuterFunctionKey": [[9, 7, 4, 2, 5, 3, 0, 6, 1, 8]],
"OuterFunctionFunctionKey": [[8, 1, 4, 5, 2, 3, 7, 6, 0, 9]],
"OuterServerShuffleFunctionKey": [[3, 9, 2, 5, 0, 7, 6, 8, 1, 4]],
"MutualKey": [[197, 126, 66, 64, 226, 18, 153], [28, 15, 172, 73, 132, 222, 220], [110, 115, 107, 210, 52, 23, 116], [178, 122, 168, 93, 146, 206, 80], [22, 191, 165, 251, 58, 135, 166], [137, 78, 235, 223, 179, 194, 64], [134, 130, 154, 214, 225, 215, 97], [60, 41, 193, 9, 197, 108, 87], [198, 134, 72, 146, 247, 223, 166], [104, 81, 159, 34, 29, 200, 196]],
"FunctionKey": [[1, 5, 0, 2, 3, 6, 4], [5, 2, 6, 4, 1, 3, 0], [4, 2, 3, 5, 6, 1, 0], [0, 3, 1, 6, 5, 2, 4], [4, 1, 3, 0, 6, 5, 2], [6, 3, 4, 2, 5, 1, 0], [2, 3, 0, 4, 1, 6, 5], [4, 0, 6, 5, 2, 3, 1], [3, 2, 4, 1, 0, 5, 6], [2, 3, 4, 1, 5, 0, 6]],
"ClientShuffleKeyX": [[6, 3, 1, 4, 5, 0, 2], [6, 5, 0, 2, 3, 4, 1], [1, 4, 0, 6, 3, 2, 5], [6, 1, 4, 5, 3, 2, 0], [2, 0, 1, 4, 3, 5, 6], [3, 0, 6, 2, 1, 4, 5], [3, 2, 0, 1, 6, 4, 5], [6, 2, 3, 0, 1, 5, 4], [3, 0, 6, 5, 4, 1, 2], [3, 2, 5, 0, 4, 1, 6]],
"MutualMediumKey": [[134, 55, 223, 228, 216, 192, 220], [84, 232, 155, 47, 216, 122, 96], [238, 56, 234, 113, 178, 232, 59], [159, 126, 156, 186, 176, 95, 207], [55, 49, 8, 218, 248, 232, 26], [244, 128, 254, 159, 227, 164, 88], [86, 49, 163, 158, 91, 29, 85], [224, 29, 111, 130, 45, 64, 242], [233, 36, 69, 153, 173, 187, 85], [190, 180, 204, 92, 117, 118, 208]],
"OuterFunctionMediumKey": [[1, 6, 0, 2, 9, 5, 8, 4, 7, 3]],
"OuterFunctionFunctionMediumKey": [[4, 1, 7, 8, 9, 6, 0, 2, 3, 5]],
"OuterServerShuffleFunctionMediumKey": [[4, 0, 5, 9, 3, 1, 7, 8, 6, 2]],
"FunctionMediumKey": [[0, 2, 5, 3, 6, 4, 1], [0, 6, 4, 3, 1, 2, 5], [1, 6, 2, 0, 4, 5, 3], [0, 3, 1, 5, 6, 2, 4], [3, 2, 0, 6, 5, 1, 4], [1, 3, 6, 4, 5, 0, 2], [5, 0, 6, 3, 1, 2, 4], [6, 4, 3, 5, 0, 1, 2], [5, 2, 3, 6, 1, 0, 4], [3, 6, 1, 0, 2, 5, 4]],
"ClientShuffleMediumKeyX": [[2, 1, 6, 0, 5, 4, 3], [3, 0, 5, 2, 6, 4, 1], [5, 3, 0, 1, 2, 6, 4], [3, 5, 4, 1, 0, 6, 2], [0, 5, 2, 4, 1, 3, 6], [5, 2, 3, 1, 4, 6, 0], [2, 1, 5, 6, 3, 0, 4], [4, 6, 0, 3, 5, 1, 2], [1, 3, 2, 0, 4, 5, 6], [3, 6, 5, 1, 0, 4, 2]],
"OuterPositionShuffleMediumKey": [[7, 5, 4, 8, 6, 3, 0, 1, 9, 2]],
"OuterPositionShuffleFunctionMediumKey": [[9, 2, 5, 0, 1, 6, 8, 4, 3, 7]],
"OuterPositionFunctionMediumKey": [[7, 2, 0, 8, 1, 6, 3, 5, 9, 4]],
"PositionFunctionMediumKey": [[1, 5, 4, 0, 6, 2, 3], [2, 4, 0, 5, 3, 6, 1], [1, 4, 0, 2, 5, 6, 3], [4, 1, 0, 3, 2, 6, 5], [4, 0, 2, 3, 5, 6, 1], [1, 0, 2, 3, 4, 6, 5], [2, 3, 1, 5, 0, 6, 4], [1, 0, 3, 2, 4, 5, 6], [4, 0, 1, 5, 2, 6, 3], [2, 1, 0, 3, 6, 5, 4]],
"PositionShuffleMediumKey": [[5, 4, 3, 1, 2, 0, 6], [0, 2, 5, 4, 6, 1, 3], [6, 3, 1, 2, 5, 0, 4], [0, 1, 6, 5, 4, 3, 2], [1, 2, 6, 0, 5, 3, 4], [2, 1, 5, 6, 0, 3, 4], [5, 3, 0, 4, 1, 2, 6], [2, 1, 4, 5, 3, 0, 6], [0, 1, 6, 2, 4, 5, 3], [3, 6, 4, 2, 5, 1, 0]],
"OuterServerShuffleKey": [[4, 9, 6, 0, 7, 5, 3, 1, 2, 8]],
"ServerKey": [[242, 97, 234, 194, 76, 104, 44], [232, 187, 4, 235, 28, 253, 239], [135, 213, 186, 200, 121, 14, 36], [16, 119, 58, 129, 53, 73, 8], [190, 27, 252, 176, 97, 8, 138], [116, 158, 97, 219, 187, 13, 179], [101, 112, 112, 80, 213, 35, 178], [196, 171, 60, 254, 251, 236, 206], [210, 226, 52, 138, 164, 63, 170], [146, 143, 69, 69, 141, 151, 174]],
"ServerShuffleKey": [[5, 2, 3, 0, 6, 4, 1], [5, 2, 6, 3, 0, 1, 4], [1, 3, 5, 0, 2, 6, 4], [6, 2, 1, 4, 5, 0, 3], [2, 3, 4, 1, 5, 6, 0], [3, 2, 0, 1, 5, 4, 6], [2, 6, 0, 3, 4, 1, 5], [3, 0, 4, 6, 2, 5, 1], [5, 3, 2, 0, 6, 4, 1], [1, 4, 5, 3, 2, 6, 0]],
"ServerMediumKey": [[112, 102, 52, 70, 128, 146, 63], [237, 152, 85, 249, 104, 196, 236], [102, 8, 226, 21, 208, 141, 226], [156, 142, 127, 216, 244, 176, 108], [180, 69, 102, 8, 144, 57, 116], [71, 231, 161, 63, 102, 253, 15], [124, 217, 105, 12, 79, 35, 60], [255, 142, 198, 151, 250, 242, 195], [207, 75, 238, 78, 51, 122, 150], [253, 208, 32, 232, 53, 47, 22]]
}

132
test/get_hard_coded_json.py Normal file
View File

@@ -0,0 +1,132 @@
import json
from src.models import MutualEphemeralDataKeys, MutualEphemeralMediumKeys, MutualEphemeralKeys, \
MutualPersistentMediumKeys, MutualPersistentDataKeys, MutualPersistentKeys, MutualKeys, ServerEphemeralMediumKeys, \
ServerEphemeralDataKeys, ServerEphemeralKeys, ServerPersistentMediumKeys, ServerPersistentDataKeys, ServerKeys, \
ServerPersistentKeys, ClientEphemeralMediumKeys, ClientEphemeralDataKeys, ClientEphemeralKeys, \
ClientPersistentMediumKeys, ClientKeys, ClientPersistentKeys, ClientPersistentDataKeys, AlphabetKey
def keys():
with open("darc_key_json/client_persistent_keys.json") as fp:
client_persistent_keys = json.load(fp)
with open("darc_key_json/client_ephemeral_keys.json") as fp:
client_ephemeral_keys = json.load(fp)
with open("darc_key_json/server_persistent_keys.json") as fp:
server_persistent_keys = json.load(fp)
with open("darc_key_json/server_ephemeral_keys.json") as fp:
server_ephemeral_keys = json.load(fp)
with open("darc_key_json/mutual_ephemeral_keys.json") as fp:
mutual_ephemeral_keys = json.load(fp)
client_persistent_keys = {k: {"matrix": v} for k, v in client_persistent_keys.items()}
client_ephemeral_keys = {k: {"matrix": v} for k, v in client_ephemeral_keys.items()}
server_persistent_keys = {k: {"matrix": v} for k, v in server_persistent_keys.items()}
server_ephemeral_keys = {k: {"matrix": v} for k, v in server_ephemeral_keys.items()}
mutual_ephemeral_keys = {k: {"matrix": v} for k, v in mutual_ephemeral_keys.items()}
client_keys = ClientKeys(
persistent=ClientPersistentKeys(
data=ClientPersistentDataKeys(
outer_key_1=client_persistent_keys["outer_key_1"],
outer_key_2=client_persistent_keys["outer_key_2"],
alpha_key=client_persistent_keys["alpha_key"],
inner_key_4=client_persistent_keys["inner_key_4"]
),
medium_phase2=ClientPersistentMediumKeys(
outer_key_1=client_persistent_keys["outer_key_1"],
outer_key_2=client_persistent_keys["outer_key_2"],
inner_key_4=client_persistent_keys["inner_key_4"],
alpha_key=client_persistent_keys["alpha_key"]
)
),
ephemeral=ClientEphemeralKeys(
data=ClientEphemeralDataKeys(
outer_key_1=client_ephemeral_keys["outer_key_1"],
outer_key_2=client_ephemeral_keys["outer_key_2"],
alpha_key=client_ephemeral_keys["alpha_key"],
inner_key_4=client_ephemeral_keys["inner_key_4"]
),
medium_phase2=ClientEphemeralMediumKeys(
outer_key_1=client_ephemeral_keys["outer_key_1"],
outer_key_2=client_ephemeral_keys["outer_key_2"],
inner_key_4=client_ephemeral_keys["inner_key_4"],
alpha_key=client_ephemeral_keys["alpha_key"]
)
)
)
server_keys = ServerKeys(
persistent=ServerPersistentKeys(
data=ServerPersistentDataKeys(
outer_key_1=server_persistent_keys["outer_key_1"],
alpha_key=server_persistent_keys["alpha_key"],
inner_key_4=server_persistent_keys["inner_key_4"]
),
medium_phase2=ServerPersistentMediumKeys(
alpha_key=server_persistent_keys["alpha_key"],
)
),
ephemeral=ServerEphemeralKeys(
data=ServerEphemeralDataKeys(
outer_key_1=server_ephemeral_keys["outer_key_1"],
alpha_key=server_ephemeral_keys["alpha_key"],
inner_key_4=server_ephemeral_keys["inner_key_4"]
),
medium_phase2=ServerEphemeralMediumKeys(
alpha_key=server_ephemeral_keys["alpha_key"],
)
)
)
mutual_keys = MutualKeys(
persistent=MutualPersistentKeys(
data=MutualPersistentDataKeys(
outer_key_1=server_persistent_keys["outer_key_1"],
outer_key_2=server_persistent_keys["outer_key_2"],
outer_key_6=server_persistent_keys["outer_key_6"],
alpha_key=server_persistent_keys["alpha_key"],
inner_key_4=server_persistent_keys["FunctionKey"],
inner_key_1=server_persistent_keys["inner_key_1"],
),
medium_phase2=MutualPersistentMediumKeys(
alpha_key=server_persistent_keys["alpha_key"],
outer_key_1=server_persistent_keys["outer_key_1"],
outer_key_2=server_persistent_keys["outer_key_2"],
outer_key_6=server_persistent_keys["outer_key_6"],
inner_key_4=server_persistent_keys["inner_key_4"],
inner_key_1=server_persistent_keys["inner_key_1"],
outer_key_3=server_persistent_keys["outer_key_3"],
outer_key_5=server_persistent_keys["outer_key_5"],
outer_key_4=server_persistent_keys["outer_key_4"],
inner_key_3=server_persistent_keys["inner_key_3"],
)
),
ephemeral=MutualEphemeralKeys(
data=MutualEphemeralDataKeys(
alpha_key=mutual_ephemeral_keys["MutualEphemeralKey"],
inner_key_4=mutual_ephemeral_keys["FunctionEphemeralKey"],
outer_key_1=mutual_ephemeral_keys["OuterFunctionEphemeralKey"],
outer_key_2=mutual_ephemeral_keys["OuterFunctionFunctionEphemeralKey"],
outer_key_6=mutual_ephemeral_keys["OuterServerShuffleFunctionEphemeralKey"]
),
medium_phase2=MutualEphemeralMediumKeys(
alpha_key=mutual_ephemeral_keys["MutualMediumEphemeralKey"],
inner_key_4=mutual_ephemeral_keys["FunctionMediumEphemeralKey"],
inner_key_3=mutual_ephemeral_keys["inner_key_3"],
outer_key_1=mutual_ephemeral_keys["outer_key_1"],
outer_key_2=mutual_ephemeral_keys["outer_key_2"],
outer_key_6=mutual_ephemeral_keys["outer_key_6"],
outer_key_3=mutual_ephemeral_keys["outer_key_3"],
outer_key_5=mutual_ephemeral_keys["outer_key_5"],
outer_key_4=mutual_ephemeral_keys["outer_key_4"]
)
)
)
darc_phase2 = AlphabetKey(**server_ephemeral_keys["Alphabet"])

1030
test/mimick_excel.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,487 @@
from src.models import DarcKey, DarcKeyTypes
if __name__ == "__main__":
height = 10
width = 7
# B_o_m
# 2 Outer (Mutual) (Substitution) Function Key
outer_mutual_substitution_function_key = DarcKey(matrix=[['9', '7', '4', '2', '5', '3', '0', '6', '1', '8']], key_type=DarcKeyTypes.outer_shuffle)
# 3 Outer (Mutual) (Substitution) Function Function Key
outer_mutual_substitution_function_function_key = DarcKey(matrix=[['8', '1', '4', '5', '2', '3', '7', '6', '0', '9']], key_type=DarcKeyTypes.outer_shuffle)
# 4 Outer Server (Mutual) Shuffle (Permutation) Function Key
outer_mutual_shuffle_permutation_function_key = DarcKey(matrix=[['3', '9', '2', '5', '0', '7', '6', '8', '1', '4']], key_type=DarcKeyTypes.outer_shuffle)
# 5 Outer Client Shuffle (Permutation) Key
outer_client_shuffle_permutation_key = DarcKey(matrix=[['6', '4', '7', '8', '0', '2', '1', '9', '5', '3']], key_type=DarcKeyTypes.outer_shuffle)
# 6 Outer Client Shuffle (Permutation) Function Key
outer_client_shuffle_permutation_function_key = DarcKey(matrix=[['4', '2', '1', '0', '5', '7', '8', '9', '3', '6']], key_type=DarcKeyTypes.outer_shuffle)
# 7 Outer Server Shuffle (Permutation) Key
outer_server_shuffle_permutation_key = DarcKey(matrix=[['4', '9', '6', '0', '7', '5', '3', '1', '2', '8']], key_type=DarcKeyTypes.outer_shuffle)
# 15 Outer (Mutual) (Substitution) Function ephemeral Key
outer_mutual_substitution_function_ephemeral_key = DarcKey(matrix=[
['0', '9', '6', '2', '1', '5', '3', '8', '7', '4']
], key_type=DarcKeyTypes.outer_shuffle)
# 16 Outer (Mutual) (Substitution) Function Function ephemeral Key
outer_mutual_substitution_function_function_ephemeral_key = DarcKey(matrix=[
['2', '3', '9', '7', '6', '0', '1', '4', '8', '5']
], key_type=DarcKeyTypes.outer_shuffle)
# 17 Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key
outer_server_mutual_shuffle_permutation_function_ephemeral_key = DarcKey(matrix=[
['0', '8', '5', '9', '7', '3', '1', '4', '6', '2']
], key_type=DarcKeyTypes.outer_shuffle)
# 18 Outer Client Shuffle (Permutation) ephemeral Key
outer_client_shuffle_permutation_ephemeral_key = DarcKey(matrix=[
['1', '4', '2', '9', '5', '7', '8', '3', '0', '6']
], key_type=DarcKeyTypes.outer_shuffle)
# 19 Outer Client Shuffle (Permutation) Function ephemeral Key
outer_client_shuffle_permutation_function_ephemeral_key = DarcKey(matrix=[
['4', '3', '2', '5', '1', '6', '7', '8', '0', '9']
], key_type=DarcKeyTypes.outer_shuffle)
# 20 Outer Server Shuffle (Permutation) ephemeral Key
outer_server_shuffle_permutation_ephemeral_key = DarcKey(matrix=[
['7', '5', '2', '1', '8', '4', '3', '6', '9', '0']
], key_type=DarcKeyTypes.outer_shuffle)
# 29 Alphabet Input Sequence the message
alphabet_input_sequence = DarcKey(matrix=[
['0', '2', '4', '6', '8', '1', '3', '5', '7', '9']
], key_type=DarcKeyTypes.outer_shuffle)
# 1 Alphabet Values
alphabet_values = DarcKey(matrix=[
['10', '28', '38', '41', '51', '64', '70'],
['15', '25', '33', '48', '56', '69', '71'],
['13', '22', '36', '47', '54', '60', '72'],
['12', '24', '31', '43', '58', '63', '73'],
['11', '21', '39', '49', '53', '65', '74'],
['18', '20', '32', '45', '52', '61', '75'],
['14', '29', '37', '44', '57', '68', '76'],
['19', '23', '34', '40', '59', '62', '77'],
['17', '27', '35', '42', '55', '67', '78'],
['16', '26', '30', '46', '50', '66', '79']
], key_type=DarcKeyTypes.alphabet)
# 8 (Mutual) (Substitution) Function Key
mutual_substitution_function_key = DarcKey(matrix=[
['1', '5', '0', '2', '3', '6', '4'],
['5', '2', '6', '4', '1', '3', '0'],
['4', '2', '3', '5', '6', '1', '0'],
['0', '3', '1', '6', '5', '2', '4'],
['4', '1', '3', '0', '6', '5', '2'],
['6', '3', '4', '2', '5', '1', '0'],
['2', '3', '0', '4', '1', '6', '5'],
['4', '0', '6', '5', '2', '3', '1'],
['3', '2', '4', '1', '0', '5', '6'],
['2', '3', '4', '1', '5', '0', '6']
], key_type=DarcKeyTypes.inner_shuffle)
# 9 Client Shuffle (Permutation) Key X
client_shuffle_permutation_key_x = DarcKey(matrix=[
['6', '3', '1', '4', '5', '0', '2'],
['6', '5', '0', '2', '3', '4', '1'],
['1', '4', '0', '6', '3', '2', '5'],
['6', '1', '4', '5', '3', '2', '0'],
['2', '0', '1', '4', '3', '5', '6'],
['3', '0', '6', '2', '1', '4', '5'],
['3', '2', '0', '1', '6', '4', '5'],
['6', '2', '3', '0', '1', '5', '4'],
['3', '0', '6', '5', '4', '1', '2'],
['3', '2', '5', '0', '4', '1', '6']
], key_type=DarcKeyTypes.inner_shuffle)
# 10 Client Shuffle (Permutation) Key A (remove A)
client_shuffle_permutation_key_a = DarcKey(matrix=[
['6', '0', '3', '5', '2', '1', '4'],
['4', '3', '2', '5', '0', '1', '6'],
['5', '4', '1', '0', '2', '3', '6'],
['3', '6', '1', '4', '5', '2', '0'],
['3', '5', '4', '2', '0', '1', '6'],
['6', '1', '5', '4', '2', '3', '0'],
['0', '4', '6', '3', '5', '1', '2'],
['0', '6', '4', '3', '1', '2', '5'],
['5', '0', '6', '3', '4', '1', '2'],
['3', '2', '0', '4', '1', '6', '5']
], key_type=DarcKeyTypes.inner_shuffle)
# 11 Server Shuffle (Permutation) Key
server_shuffle_permutation_key = DarcKey(matrix=[
['5', '2', '3', '0', '6', '4', '1'],
['5', '2', '6', '3', '0', '1', '4'],
['1', '3', '5', '0', '2', '6', '4'],
['6', '2', '1', '4', '5', '0', '3'],
['2', '3', '4', '1', '5', '6', '0'],
['3', '2', '0', '1', '5', '4', '6'],
['2', '6', '0', '3', '4', '1', '5'],
['3', '0', '4', '6', '2', '5', '1'],
['5', '3', '2', '0', '6', '4', '1'],
['1', '4', '5', '3', '2', '6', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 21 (Mutual) (Substitution) Function ephemeral Key
mutual_substitution_function_ephemeral_key = DarcKey(matrix=[
['6', '0', '1', '4', '2', '3', '5'],
['2', '3', '6', '4', '0', '1', '5'],
['2', '4', '0', '3', '6', '1', '5'],
['0', '4', '2', '3', '1', '5', '6'],
['6', '4', '2', '5', '1', '0', '3'],
['5', '1', '0', '6', '4', '2', '3'],
['1', '2', '4', '3', '6', '0', '5'],
['6', '1', '4', '0', '5', '3', '2'],
['2', '3', '5', '4', '6', '0', '1'],
['1', '6', '4', '3', '5', '2', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 22 Client Shuffle (Permutation) ephemeral Key A (remove A)
client_shuffle_permutation_ephemeral_key_a = DarcKey(matrix=[
['5', '0', '4', '3', '2', '6', '1'],
['0', '6', '2', '1', '5', '3', '4'],
['1', '2', '0', '3', '5', '4', '6'],
['0', '2', '6', '3', '4', '5', '1'],
['5', '1', '2', '0', '3', '4', '6'],
['1', '0', '3', '4', '5', '6', '2'],
['3', '0', '5', '2', '6', '4', '1'],
['6', '4', '5', '3', '0', '2', '1'],
['2', '4', '6', '0', '3', '5', '1'],
['4', '6', '2', '3', '5', '1', '0']
], key_type=DarcKeyTypes.inner_shuffle)
# 23 Server Shuffle (Permutation) ephemeral Key 1 (remove 1)
server_shuffle_permutation_ephemeral_key_1 = DarcKey(matrix=[
['6', '1', '3', '0', '4', '2', '5'],
['3', '2', '1', '0', '4', '5', '6'],
['2', '4', '3', '5', '0', '6', '1'],
['4', '1', '3', '6', '0', '2', '5'],
['1', '4', '2', '3', '0', '5', '6'],
['6', '4', '5', '0', '2', '3', '1'],
['0', '4', '2', '3', '1', '5', '6'],
['0', '6', '3', '5', '1', '2', '4'],
['2', '6', '3', '1', '4', '5', '0'],
['5', '0', '4', '1', '6', '3', '2']
], key_type=DarcKeyTypes.inner_shuffle)
# 12 Shared (Mutual) (Substitution) Component 1
shared_mutual_substitution_component_1 = DarcKey(matrix=[
['81', '150', '209', '32', '246', '219', '15'],
['100', '15', '50', '179', '52', '1', '142'],
['98', '34', '170', '6', '195', '115', '117'],
['205', '169', '12', '151', '139', '91', '114'],
['192', '153', '175', '62', '249', '230', '103'],
['56', '54', '44', '107', '125', '122', '219'],
['28', '16', '32', '27', '95', '248', '200'],
['152', '121', '40', '198', '19', '55', '59'],
['189', '227', '175', '102', '171', '135', '170'],
['182', '144', '202', '64', '253', '89', '196']
], key_type=DarcKeyTypes.alphabet)
# 13 Client (Substitution) Key
client_substitution_key = DarcKey(matrix=[
['148', '232', '147', '96', '20', '201', '150'],
['120', '0', '158', '250', '176', '223', '82'],
['12', '81', '193', '212', '247', '100', '1'],
['127', '211', '164', '202', '25', '149', '34'],
['214', '38', '10', '197', '195', '97', '193'],
['177', '120', '199', '180', '206', '184', '155'],
['154', '146', '186', '205', '190', '47', '169'],
['164', '80', '233', '207', '214', '91', '108'],
['123', '101', '231', '244', '92', '88', '12'],
['222', '193', '85', '98', '224', '145', '0']
], key_type=DarcKeyTypes.alphabet)
# 14 Server (Substitution) Key
server_substitution_key = DarcKey(matrix=[
['163', '247', '59', '226', '186', '179', '35'],
['140', '180', '54', '88', '40', '252', '97'],
['229', '247', '16', '206', '186', '125', '81'],
['221', '222', '54', '22', '190', '18', '122'],
['126', '130', '83', '142', '152', '238', '237'],
['76', '168', '77', '176', '198', '119', '104'],
['121', '96', '80', '75', '138', '219', '122'],
['92', '210', '20', '56', '232', '219', '245'],
['111', '1', '155', '236', '15', '184', '0'],
['36', '31', '143', '5', '112', '206', '106']
],
key_type=DarcKeyTypes.alphabet
)
# 24 Server (Substitution) ephemeral Unique Component Function
server_substitution_ephemeral_unique_component_function = 5
# 25 Shared (Mutual) (Substitution) ephemeral Key
shared_mutual_substitution_ephemeral_key = DarcKey(matrix=[
['106', '113', '9', '54', '49', '4', '207'],
['184', '3', '232', '179', '15', '113', '142'],
['129', '44', '164', '54', '1', '32', '201'],
['106', '50', '246', '140', '149', '179', '109'],
['210', '11', '69', '193', '77', '245', '62'],
['37', '76', '137', '24', '220', '30', '165'],
['40', '57', '147', '225', '24', '176', '103'],
['37', '212', '189', '203', '218', '138', '168'],
['73', '227', '38', '164', '20', '239', '24'],
['7', '194', '254', '76', '0', '244', '215']
], key_type=DarcKeyTypes.alphabet)
# 26 Client (Substitution) ephemeral Key
client_substitution_ephemeral_key = DarcKey(matrix=[
['21', '149', '75', '73', '228', '81', '79'],
['41', '189', '80', '209', '45', '101', '53'],
['139', '238', '141', '159', '30', '79', '214'],
['239', '234', '72', '75', '80', '190', '124'],
['203', '225', '246', '200', '205', '195', '92'],
['201', '185', '113', '101', '176', '216', '106'],
['14', '210', '125', '70', '53', '128', '57'],
['115', '27', '97', '39', '199', '26', '104'],
['29', '4', '55', '5', '13', '57', '19'],
['158', '184', '137', '0', '221', '12', '217']
], key_type=DarcKeyTypes.alphabet)
# 27 Server (Substitution) ephemeral Random Component
server_substitution_ephemeral_random_component = DarcKey(matrix=[
['191', '50', '229', '60', '201', '64', '45'],
['31', '88', '90', '8', '153', '6', '228'],
['117', '63', '38', '90', '236', '207', '254'],
['64', '219', '36', '3', '119', '205', '171'],
['172', '138', '153', '52', '161', '137', '216'],
['49', '150', '210', '129', '174', '190', '54'],
['81', '230', '135', '200', '218', '31', '52'],
['128', '253', '177', '220', '1', '83', '3'],
['204', '199', '43', '50', '148', '215', '6'],
['79', '124', '128', '30', '74', '242', '85']
], key_type=DarcKeyTypes.alphabet)
# 28 Server (Substitution) ephemeral Unique Component
server_substitution_ephemeral_unique_component = DarcKey(matrix=[
['7', '190', '58', '75', '135', '15', '214', '149', '244', '224']
], key_type=DarcKeyTypes.alphabet)
# 30 Shared (Mutual) (Substitution) Key
shared_mutual_substitution_key = shared_mutual_substitution_component_1 ^ client_substitution_key
# 31 Outer (Mutual) Function Function ephemeral Key Applied = Outer (Mutual) (Substitution) Function Function Key << Outer (Mutual) (Substitution) Function Function ephemeral Key
outer_mutual_function_function_ephemeral_key_applied = outer_mutual_substitution_function_function_key << outer_mutual_substitution_function_function_ephemeral_key
# 32 Inner (Mutual) Function Applied Key = (Mutual) (Substitution) Function Key << (Mutual) (Substitution) Function ephemeral Key
inner_mutual_function_applied_key = mutual_substitution_function_key << mutual_substitution_function_ephemeral_key
# 33 Inner (Mutual) Function Key Scratch = Inner (Mutual) Function Applied Key << Outer (Mutual) Function Function ephemeral Key Applied
inner_mutual_function_key_scratch = inner_mutual_function_applied_key < outer_mutual_function_function_ephemeral_key_applied
# 34 Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied = Outer Server (Mutual) Shuffle (Permutation) Function Key << Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key
outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied = outer_mutual_shuffle_permutation_function_key << outer_server_mutual_shuffle_permutation_function_ephemeral_key
# 35 Client Shuffle (Permutation) Key X Scratch = Client Shuffle (Permutation) Key X < Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied
client_shuffle_permutation_key_x_scratch = client_shuffle_permutation_key_x < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 36 Inner Function Key Scratch 2 = Inner (Mutual) Function Key Scratch << Client Shuffle (Permutation) Key X Scratch
inner_function_key_scratch_2 = inner_mutual_function_key_scratch << client_shuffle_permutation_key_x_scratch
# 37 Outer (Mutual) Function ephemeral Key Applied = Outer (Mutual) (Substitution) Function Key < Outer (Mutual) (Substitution) Function ephemeral Key
outer_mutual_function_ephemeral_key_applied = outer_mutual_substitution_function_key << outer_mutual_substitution_function_ephemeral_key
# 38 Server (Substitution) Key Scratch = Server (Substitution) Key < Outer (Mutual) Function ephemeral Key Applied
server_substitution_key_scratch = server_substitution_key < outer_mutual_function_ephemeral_key_applied
# 39 Shared (Mutual) (Substitution) Key Scratch = Shared (Mutual) (Substitution) Key < Outer (Mutual) Function ephemeral Key Applied
shared_mutual_substitution_key_scratch = shared_mutual_substitution_key < outer_mutual_function_ephemeral_key_applied
# 40 Shared (Mutual) (Substitution) ephemeral Key Server Scratch = Shared (Mutual) (Substitution) ephemeral Key < Outer (Mutual) Function ephemeral Key Applied
shared_mutual_substitution_ephemeral_key_server_scratch = shared_mutual_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# line 78
# 41 Server Client Shuffle (Permutation) = Server Shuffle (Permutation) Key << Client Shuffle (Permutation) Key X
server_client_shuffle_permutation = server_shuffle_permutation_key << client_shuffle_permutation_key_x
# 42 Server Client Shuffle (Permutation) Inverse
server_client_shuffle_permutation_inverse = ~server_client_shuffle_permutation
# 43 Server Shuffle (Permutation) ephemeral Key 1 Inverse (remove 1) = ~(Server Shuffle (Permutation) ephemeral Key 1 (remove 1))
server_shuffle_permutation_ephemeral_key_1_inverse = ~server_shuffle_permutation_ephemeral_key_1
# 44 Server Shuffle (Permutation) ephemeral Key Applied = Server Client Shuffle (Permutation) Inverse < Server Shuffle (Permutation) ephemeral Key 1 Inverse (remove 1)
server_shuffle_permutation_ephemeral_key_applied = server_client_shuffle_permutation_inverse << server_shuffle_permutation_ephemeral_key_1_inverse
# line 82
# 45 Server Shuffle (Permutation) ephemeral Key Applied Scratch = Server Shuffle (Permutation) ephemeral Key Applied < Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied
server_shuffle_permutation_ephemeral_key_applied_scratch = server_shuffle_permutation_ephemeral_key_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 46 Server Shuffle (Permutation) ephemeral Key Applied Scratch Inverse = ~Server Shuffle (Permutation) ephemeral Key Applied Scratch
server_shuffle_permutation_ephemeral_key_applied_scratch_inverse = ~server_shuffle_permutation_ephemeral_key_applied_scratch
# 47 Outer Server Shuffle (Permutation) ephemeral Key Applied = Outer Server Shuffle (Permutation) Key < Outer Server Shuffle (Permutation) ephemeral Key
outer_server_shuffle_permutation_ephemeral_key_applied = outer_server_shuffle_permutation_key << outer_server_shuffle_permutation_ephemeral_key
# 48 Alphabet Scratch 1 = Alphabet Values < Outer Server Shuffle (Permutation) ephemeral Key Applied
alphabet_scratch_1 = alphabet_values < outer_server_shuffle_permutation_ephemeral_key_applied
# 49 Alphabet Scratch 2 = Alphabet Scratch 1 << Server Shuffle (Permutation) ephemeral Key Applied Scratch Inverse
alphabet_scratch_2 = alphabet_scratch_1 << server_shuffle_permutation_ephemeral_key_applied_scratch_inverse
# 50 Server (Substitution) ephemeral Component Scratch 1 = Server (Substitution) ephemeral Random Component.column_substitution( Server (Substitution) ephemeral Unique Component Function ,Server (Substitution) ephemeral Unique Component)
server_substitution_ephemeral_component_scratch_1 = server_substitution_ephemeral_random_component.column_substitution(
server_substitution_ephemeral_unique_component_function,
server_substitution_ephemeral_unique_component.matrix[0]
)
# 51 Server (Substitution) ephemeral Component Scratch 2 = Server (Substitution) ephemeral Component Scratch 1 < Outer (Mutual) Function ephemeral Key Applied
server_substitution_ephemeral_component_scratch_2 = server_substitution_ephemeral_component_scratch_1 < outer_mutual_function_ephemeral_key_applied
# 52 Server (Substitution) ephemeral Component Scratch 3 = Alphabet Scratch 2 ^ (Server (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Server (Substitution) ephemeral Component Scratch 2 << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) ephemeral Key Server Scratch << Inner Function Key Scratch 2)
server_substitution_ephemeral_component_scratch_3 = alphabet_scratch_2 ^ (server_substitution_key_scratch << inner_function_key_scratch_2) ^ (server_substitution_ephemeral_component_scratch_2 << inner_function_key_scratch_2) ^ (shared_mutual_substitution_key_scratch << inner_function_key_scratch_2) ^ (shared_mutual_substitution_ephemeral_key_server_scratch << inner_function_key_scratch_2)
# 52 Inner Function Key Scratch 2 Inverse = ~Inner Function Key Scratch 2
inner_function_key_scratch_2_inverse = ~inner_function_key_scratch_2
# 54 Server (Substitution) ephemeral Key Scratch = Server (Substitution) ephemeral Component Scratch 3 << Inner Function Key Scratch 2 Inverse
server_substitution_ephemeral_key_scratch = server_substitution_ephemeral_component_scratch_3 << inner_function_key_scratch_2_inverse
# 55 Outer (Mutual) Function ephemeral Key Applied Inverse = ~Outer (Mutual) Function ephemeral Key Applied
outer_mutual_function_ephemeral_key_applied_inverse = ~outer_mutual_function_ephemeral_key_applied
# 56 Server (Substitution) ephemeral Key = Server (Substitution) ephemeral Key Scratch < Outer (Mutual) Function ephemeral Key Applied Inverse
server_substitution_ephemeral_key = server_substitution_ephemeral_key_scratch < outer_mutual_function_ephemeral_key_applied_inverse
# line 94
""" Server Tx (Phase 1) """
# 57 Inner Server Shuffle (Permutation) Key Applied = Server Shuffle (Permutation) ephemeral Key 1 (remove 1) << Server Shuffle (Permutation) Key
inner_server_shuffle_permutation_key_applied = server_shuffle_permutation_ephemeral_key_1 << server_shuffle_permutation_key
# 58 Outer Server Shuffle (Permutation) Key Applied = Inner Server Shuffle (Permutation) Key Applied < Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied
outer_server_shuffle_permutation_key_applied = inner_server_shuffle_permutation_key_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 59 Server (Substitution) ephemeral Key Scratch = Server (Substitution) ephemeral Key < Outer (Mutual) Function ephemeral Key Applied
server_substitution_ephemeral_key_scratch = server_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# 86 Outer Shuffle (Permutation) = Alphabet Values << Outer Server Shuffle (Permutation) ephemeral Key Applied
#outer_shuffle_permutation = alphabet_values < outer_server_shuffle_permutation_ephemeral_key_applied
## 87 Inner Shuffle (Permutation) = Outer Shuffle (Permutation) << Outer Server Shuffle (Permutation) Key Applied
#inner_shuffle_permutation = outer_shuffle_permutation << outer_server_shuffle_permutation_key_applied
## 88 Translation (Substitution) = Inner Shuffle (Permutation) ^ (Server (Substitution) ephemeral Key Scratch << Inner (Mutual) Function Key Scratch) ^ (Server (Substitution) Key Scratch << Inner (Mutual) Function Key Scratch)
#translation_substitution = inner_shuffle_permutation ^ (
# server_substitution_ephemeral_key_scratch << inner_mutual_function_key_scratch) ^ (
# server_substitution_key_scratch << inner_mutual_function_key_scratch)
# line 108
""" Client Rx (Phase 2) """
# 62 Client (Substitution) Key A Scratch = Client (Substitution) Key < Outer (Mutual) Function ephemeral Key Applied
client_substitution_key_a_scratch = client_substitution_key < outer_mutual_function_ephemeral_key_applied
# 63 Client (Substitution) ephemeral Key A Scratch = Client (Substitution) ephemeral Key < Outer (Mutual) Function ephemeral Key Applied
client_substitution_ephemeral_key_a_scratch = client_substitution_ephemeral_key < outer_mutual_function_ephemeral_key_applied
# 64 Client Shuffle (Permutation) Key A Applied (remove A) = Client Shuffle (Permutation) Key A Applied (remove A) << Client Shuffle (Permutation) ephemeral Key A (remove A)
client_shuffle_permutation_key_a_applied = client_shuffle_permutation_key_a << client_shuffle_permutation_ephemeral_key_a
# 65 Client Shuffle (Permutation) Key A Scratch (remove A) = Client Shuffle (Permutation) Key A Applied (remove A) < Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied
client_shuffle_permutation_key_a_scratch = client_shuffle_permutation_key_a_applied < outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied
# 66 Outer Client Shuffle (Permutation) ephemeral Key Applied = Outer Client Shuffle (Permutation) Key << Outer Client Shuffle (Permutation) ephemeral Key
outer_client_shuffle_permutation_ephemeral_key_applied = outer_client_shuffle_permutation_key << outer_client_shuffle_permutation_ephemeral_key
# 67 Outer Client Shuffle (Permutation) Function ephemeral Key Applied = Outer Client Shuffle (Permutation) Function Key << Outer Client Shuffle (Permutation) Function ephemeral Key
outer_client_shuffle_permutation_function_ephemeral_key_applied = outer_client_shuffle_permutation_function_key << outer_client_shuffle_permutation_function_ephemeral_key
# 68 Outer Client Shuffle (Permutation) Function Key Applied = Outer Client Shuffle (Permutation) ephemeral Key Applied << Outer Client Shuffle (Permutation) Function ephemeral Key Applied
outer_client_shuffle_permutation_function_key_applied = outer_client_shuffle_permutation_ephemeral_key_applied << outer_client_shuffle_permutation_function_ephemeral_key_applied
# 69 Outer Client Shuffle (Permutation) Function Key Applied Inverse = ~Outer Client Shuffle (Permutation) Function Key Applied
outer_client_shuffle_permutation_function_key_applied_inverse = ~outer_client_shuffle_permutation_function_key_applied
# 70 Alphabet Input Sequence Scratch = Outer Client Shuffle (Permutation) Function Key Applied Inverse << Alphabet Input Sequence
alphabet_input_sequence_scratch = outer_client_shuffle_permutation_function_key_applied_inverse << alphabet_input_sequence
# 89 Translation (Substitution) - Client Data = Translation (Substitution) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner (Mutual) Function Key Scratch) ^ (Client (Substitution) Key A Scratch << Inner (Mutual) Function Key Scratch) ^ (Client (Substitution) ephemeral Key A Scratch << Inner (Mutual) Function Key Scratch)
#translation_substitution_client_data = translation_substitution ^ (
# shared_mutual_substitution_key_scratch << inner_mutual_function_key_scratch) ^ (
# client_substitution_key_a_scratch << inner_mutual_function_key_scratch) ^ (
# client_substitution_ephemeral_key_a_scratch << inner_mutual_function_key_scratch)
## 90 Inner Shuffle (Permutation) - CSKA+CSEKA = Translation (Substitution) - Client Data << Client Shuffle (Permutation) Key A Scratch (remove A)
#inner_shuffle_permutation_cska_cseka = translation_substitution_client_data << client_shuffle_permutation_key_a_scratch
## 91 Outer Shuffle (Permutation) - Client Rest = Inner Shuffle (Permutation) - CSKA+CSEKA << Outer Client Shuffle (Permutation) Function Key Applied
#outer_shuffle_permutation_client_rest = inner_shuffle_permutation_cska_cseka < outer_client_shuffle_permutation_function_key_applied
# line 130
""" Client Tx (Phase 3) """
# 71 Client Shuffle (Permutation) Key A Inverse (remove A) = ~Client Shuffle (Permutation) Key A (remove A)
client_shuffle_permutation_key_a_inverse = ~client_shuffle_permutation_key_a
# 72 Client Shuffle (Permutation) Key B (remove B) = Client Shuffle (Permutation) Key A Inverse (remove A) << Client Shuffle (Permutation) Key X
client_shuffle_permutation_key_b = client_shuffle_permutation_key_a_inverse << client_shuffle_permutation_key_x
# 73 Client Shuffle (Permutation) ephemeral Key A (remove A) Inverse = ~Client Shuffle (Permutation) ephemeral Key A (remove A)
client_shuffle_permutation_ephemeral_key_a_inverse = ~client_shuffle_permutation_ephemeral_key_a
# 74 Client Shuffle (Permutation) Key B Applied = Client Shuffle (Permutation) ephemeral Key B << Client Shuffle (Permutation) Key B (remove B)
client_shuffle_permutation_key_b_applied = client_shuffle_permutation_ephemeral_key_a_inverse << client_shuffle_permutation_key_b
# 75 Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch = Outer Server (Mutual) Shuffle (Permutation) Function ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_server_mutual_shuffle_permutation_function_key_scratch = outer_server_mutual_shuffle_permutation_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 76 Client Shuffle (Permutation) Key B Scratch = Client Shuffle (Permutation) Key B Applied < Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch
client_shuffle_permutation_key_b_scratch = client_shuffle_permutation_key_b_applied < outer_server_mutual_shuffle_permutation_function_key_scratch
# 77 Client Shuffle (Permutation) Key X Scratch 2 = Client Shuffle (Permutation) Key X < Outer Server (Mutual) Shuffle (Permutation) Function Key Scratch
client_shuffle_permutation_key_x_scratch_2 = client_shuffle_permutation_key_x < outer_server_mutual_shuffle_permutation_function_key_scratch
# line 144
# 78 Outer Function Function Key Scratch = Outer (Mutual) Function Function ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_function_function_key_scratch = outer_mutual_function_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 79 Inner (Mutual) Function Key Client Scratch = Inner (Mutual) Function Applied Key < Outer Function Function Key Scratch
inner_mutual_function_key_client_scratch = inner_mutual_function_applied_key < outer_function_function_key_scratch
# line 147
# 80 (Mutual) Function Key Scratch 2 = Inner (Mutual) Function Key Client Scratch << client_shuffle_permutation_key_x_scratch_2
mutual_function_key_scratch_2 = inner_mutual_function_key_client_scratch << client_shuffle_permutation_key_x_scratch_2
# 81 Outer (Mutual) Function Key Scratch = Outer (Mutual) Function ephemeral Key Applied << Outer Client Shuffle (Permutation) Function Key Applied
outer_mutual_function_key_scratch = outer_mutual_function_ephemeral_key_applied << outer_client_shuffle_permutation_function_key_applied
# 82 Client (Substitution) Key B Scratch = Client (Substitution) Key < Outer (Mutual) Function Key Scratch
client_substitution_key_b_scratch = client_substitution_key < outer_mutual_function_key_scratch
# 83 Client (Substitution) ephemeral Key B Scratch = Client (Substitution) ephemeral Key < Outer (Mutual) Function Key Scratch
client_substitution_ephemeral_key_b_scratch = client_substitution_ephemeral_key < outer_mutual_function_key_scratch
# 84 Shared (Mutual) (Substitution) ephemeral Key Client Scratch = Shared (Mutual) (Substitution) ephemeral Key < Outer (Mutual) Function Key Scratch
shared_mutual_substitution_ephemeral_key_client_scratch = shared_mutual_substitution_ephemeral_key < outer_mutual_function_key_scratch
# 92 Inner Shuffle (Permutation) - CSEKB +CSKB = Outer Shuffle (Permutation) - Client Rest << Client Shuffle (Permutation) Key B Scratch
#inner_shuffle_permutation_csekb_cskb = outer_shuffle_permutation_client_rest << client_shuffle_permutation_key_b_scratch
## 93 Translation (Substitution) DARC Data = Inner Shuffle (Permutation) - CSEKB +CSKB ^ (Client (Substitution) Key B Scratch << (Mutual) Function Key Scratch 2) ^ (Client (Substitution) ephemeral Key B Scratch << (Mutual) Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) ephemeral Key Client Scratch << (Mutual) Function Key Scratch 2)
#translation_substitution_darc_data = inner_shuffle_permutation_csekb_cskb ^ (
# client_substitution_key_b_scratch << mutual_function_key_scratch_2) ^ (
# client_substitution_ephemeral_key_b_scratch << mutual_function_key_scratch_2) ^ (
# shared_mutual_substitution_ephemeral_key_client_scratch << mutual_function_key_scratch_2)
# line 175
""" Server Rx (Phase 4) """
# 85 Translation (Substitution) = Alphabet Scratch 2 ^ (Server (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Server (Substitution) ephemeral Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) Key Scratch << Inner Function Key Scratch 2) ^ (Shared (Mutual) (Substitution) ephemeral Key Server Scratch << Inner Function Key Scratch 2)
translation_substitution = (
alphabet_scratch_2 ^
(server_substitution_key_scratch << inner_function_key_scratch_2) ^
(server_substitution_ephemeral_key_scratch << inner_function_key_scratch_2) ^
(shared_mutual_substitution_key_scratch << inner_function_key_scratch_2) ^
(shared_mutual_substitution_ephemeral_key_server_scratch << inner_function_key_scratch_2)
)
a = 1

55
test/test_darc.py Normal file
View File

@@ -0,0 +1,55 @@
from src.client_darc_noclient import merge_message_no_client, darc_phase_2_3
from src.client_darc import merge_message, darc_phase2, darc_phase3
from src.models import (AlphabetKey, OuterKey, ClientKeys, ServerKeys,
MutualKeys)
from src.server_darc import darc_phase1, darc_phase_4
import pytest
@pytest.mark.parametrize("height, width", [(256, 10), (100, 70), (40, 50)])
def test_darc(height, width):
server_keys = ServerKeys.random_init(height, width)
mutual_keys = MutualKeys.random_init(height, width)
client_keys = ClientKeys.random_init(height, width)
alphabet = AlphabetKey.init_matrix(width, height, 255)
server_keys.persistent.data.alpha_key = server_keys.persistent.data.alpha_key ^ mutual_keys.persistent.data.alpha_key
server_keys.persistent.medium.alpha_key = server_keys.persistent.medium.alpha_key ^ mutual_keys.persistent.medium.alpha_key
mutual_keys.persistent.data.alpha_key = mutual_keys.persistent.data.alpha_key ^ client_keys.persistent.data.alpha_key
mutual_keys.persistent.medium.alpha_key = mutual_keys.persistent.medium.alpha_key ^ client_keys.persistent.medium.alpha_key
original_message = OuterKey.init_matrix(height).matrix[0]
(alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys)
(alphabet_phase2, medium_phase2) = darc_phase2(alphabet_phase1, medium_phase1, client_keys, mutual_keys)
(phase3_alphabet, phase3_medium) = darc_phase3(alphabet_phase2, medium_phase2, client_keys, mutual_keys)
darc_message = merge_message(phase3_alphabet, phase3_medium, client_keys, mutual_keys, original_message)
message = darc_phase_4(alphabet, darc_message, server_keys, mutual_keys)
assert original_message == message
@pytest.mark.parametrize("height, width", [(256, 10), (100, 70), (40, 50)])
def test_darc_no_client(height, width):
server_keys = ServerKeys.random_init(height, width)
mutual_keys = MutualKeys.random_init(height, width)
client_keys = ClientKeys.random_init(height, width)
alphabet = AlphabetKey.init_matrix(width, height, 255)
server_keys.persistent.data.alpha_key = server_keys.persistent.data.alpha_key ^ mutual_keys.persistent.data.alpha_key
server_keys.persistent.medium.alpha_key = server_keys.persistent.medium.alpha_key ^ mutual_keys.persistent.medium.alpha_key
mutual_keys.persistent.data.alpha_key = mutual_keys.persistent.data.alpha_key ^ client_keys.persistent.data.alpha_key
mutual_keys.persistent.medium.alpha_key = mutual_keys.persistent.medium.alpha_key ^ client_keys.persistent.medium.alpha_key
original_message = OuterKey.init_matrix(height).matrix[0]
(alphabet_phase1, medium_phase1) = darc_phase1(alphabet, server_keys, mutual_keys)
(phase3_alphabet, phase3_medium) = darc_phase_2_3(alphabet_phase1, medium_phase1, mutual_keys)
darc_message = merge_message_no_client(phase3_alphabet, phase3_medium, mutual_keys, original_message)
message = darc_phase_4(alphabet, darc_message, server_keys, mutual_keys)
assert original_message == message