-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.zok
177 lines (148 loc) · 14.7 KB
/
test.zok
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
from "./root.zok" import u32sToU8s, flattenedToBytes, checkMask, maskString, substringAt, hasSubstringAt, checkAud, hasMaskedString, checkJwt;
import "hashes/sha256/sha256" as sha256;
def testCheckMask() -> bool {
// Valid mask with 1s followed by 0s followed by 1s
assert(checkMask([255, 0, 255]));
// Valid mask with 1s followed by 0s followed by 1s
assert(checkMask([255, 255, 255, 0, 255]));
// Valid mask with 1s followed by 0s followed by 1s
assert(checkMask([255, 255, 255, 0, 0, 0, 0, 255, 255]));
// Valid masks with 1s followed by 0s
assert(checkMask([1,0]));
assert(checkMask([1,1,0]));
assert(checkMask([1,0,0]));
/* Should these b valid? I don't c ynot nor do i c y */
// Valid mask with 0s followed by 1s followed by 0s
assert(checkMask([0, 255, 0, 0]));
// Valid masks with 0s followed by 1s
assert(checkMask([0,1]));
assert(checkMask([0,0,1]));
assert(checkMask([0,1,1]));
/*These are now valid:
// invalid mask with all 1s
assert(!checkMask([255, 255, 255, 255, 255, 255]));
// invalid mask with all 0s
assert(!checkMask([0, 0, 0, 0, 0, 0]));
*/
// Invalid mask with bytes that neither 255 nor 0
assert(!checkMask([0,1,2,3,6]));
// Invalid mask with too many flips between 0s and 255s
assert(!checkMask([0, 0, 255, 255, 0, 255]));
return true;
}
def testMaskString() -> bool {
assert(maskString([1,2,3],[0,0,0]) == [0,0,0]);
assert(maskString([0,0,0],[1,0,1]) == [0,0,0]);
assert(maskString([1,2,3],[255,255,255]) == [1,2,3]);
assert(maskString([1,2,3],[255,0,255]) == [1,0,3]);
return true;
}
def testSubstringAt()-> bool {
assert(substringAt::<3,2>([30,42,69], 1) == [42,69]);
assert(substringAt::<4,4>([30,42,69,255], 0) == [30,42,69,255]);
assert(substringAt::<4,2>([30,42,69,255], 0) == [30,42]);
assert(substringAt::<2,1>([67,69], 1) == [69]);
assert(substringAt::<1,1>([42], 0) == [42]);
return true;
}
def testHasSubstringAt()-> bool {
assert(hasSubstringAt([30,42,69], [42,69], 1));
assert(!hasSubstringAt([30,40,69], [42,69], 1));
assert(hasSubstringAt([42], [42], 0));
assert(hasSubstringAt([42,69], [42], 0));
assert(!hasSubstringAt([42,69], [67], 1));
assert(!hasSubstringAt([42], [43], 0));
return true;
}
def testFlatten()-> bool {
assert(flattenedToBytes::<1,128>([[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]) == [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);
assert(!(flattenedToBytes::<1,128>([[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]) == [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0]);
return true;
}
def testU32ToU8s()-> bool {
assert(u32sToU8s::<2,8>([2,0]) == [0,0,0,2,0,0,0,0]);
return true;
}
def testCheckAud()-> bool {
assert( checkAud([69,12,144,6,140,1,0,9,12], [144,6,140], 2));
assert(!checkAud([69,12,169,6,140,1,0,9,12], [144,6,140], 2));
assert(!checkAud([69,12,169,6,140,1,0,9,12], [169,6,140], 1));
assert( checkAud([69,12,169,6,140,1,0,9,12], [169,6,140], 2));
return true;
}
def testHasMaskedString()-> bool {
assert( hasMaskedString([69,42,0,0,69,42,7,69,69,69,69,1], [255,255,255,255,0,0,0], [42,7,69,69,0,0,0], 5));
assert(!hasMaskedString([69,42,0,0,69,42,7,69,79,69,69,1], [255,255,255,255,0,0,0], [42,7,69,69,0,0,0], 5));
assert(!hasMaskedString([69,42,0,0,69,42,7,69,69,69,69,1], [255,255,255,0 ,0,0,0], [42,7,69,69,0,0,0], 5));
assert(!hasMaskedString([69,42,0,0,69,42,7,69,69,69,69,1], [255,255,255,255,0,0,0], [42,7,69, 0,0,0,0], 5));
assert(!hasMaskedString([69,42,0,0,69,42,7,69,69,69,69,1], [255,255,255,255,0,0,0], [42,7,69,69,0,0,0], 4));
return true;
}
/* Deprecated; using testHasMasked instead now because exp is in base64 not uint */
// def testCheckExp()-> bool {
// assert(checkExp([[0,1,2,5,8,69,103032949,1655252511,8000,3,9,1,69,10,3, 69]], 1655252510, [0,7]));
// assert(!checkExp([[0,1,2,5,8,69,103032949,1655252511,8000,3,9,1,69,10,3, 69]], 1655252512, [0,7]));
// assert(!checkExp([[0,1,2,5,8,69,103032949,1655252511,8000,3,9,1,69,10,3, 69]], 1655252510, [0,6]));
// assert(!checkExp([[0,1,2,5,8,69,103032949,1655252511,8000,3,9,1,69,10,3, 69], [0,1,2,5,8,69,103032949,1655252509,8000,3,9,1,69,10,3, 69]], 1655252510, [1,7]));
// assert(checkExp([[0,1,2,5,8,69,103032949,1655252511,8000,3,9,1,69,10,3, 69], [0,1,2,5,8,69,103032949,1655252590,8000,3,9,1,69,10,3, 69]], 1655252510, [1,7]));
// return true;
def testCheckJwt512x3()-> bool {
// u32[8][16] googlePaddedPreimage = [[1702447730,1633112425,1332300407,1668102507,1683443248,1633106293,1280784761,1496476779,1280784761,1517891635,1632064116,1514688051,1498958454,1664246650,1513254961,1634547764],[1498899507,1682392630,1513256055,1297561969,1668893043,1231898227,1517898038,1231833684,1298814258,1231958062,1702447720,1682323823,1498959471,1231712105,1648834924,1330071153],[1298810480,1415071098,1297499758,1446071877,1331186296,1517898099,1231898161,1514359094,1231767121,1430466894,1430616138,1296390738,1433163351,1382766156,1414949977,1231648617],[1664308841,1231712105,1296318839,1296248951,1296318841,1280592250,1296328564,1330926968,1316571507,1231898161,1682401382,1682402420,1515407670,1297373489,1297369395,1316637048],[1329821545,1633177210,1231712105,1632129584,1665682742,1480800611,1278359929,1496476779,1282226553,1517898099,1231902260,1665354038,1297373489,1297370419,1314154362,1299806057],[1513253938,1515664742,1651328628,1515407670,1231762792,1651328626,1229272432,1632061043,1231648617,1633109552,1231712120,1315591544,1298818869,1313099130,1279478389,1647457642],[1515407670,1231971439,1498960492,1684887161,1231648617,1517110900,1633122357,1479685480,1649890665,1332300364,1632061043,1664238953,1279478385,1682402153,1332300081,1500333431],[1498704760,1313026411,1314347384,1280594226,1316640116,1330071861,1297297772,1298819959,1516921648,1330923827,1514426729,1716617216,0,0,0,3952]];
// u32[8] googleHash = [1430026552,2342630845,2007623219,2509188588,218435145,3526213489,2255769372,843489774];
u32[3][16] preimg = [[1702447730,1633112425,1332300406,1498899546,1231958062,1702447722,1668109931,1668892982,1231831673,1647530614,1496463731,1446204013,1231648617,1498961515,1231712105,1513239926],[1664248954,1231648617,1668105845,1514359094,1231834490,1395738931,1464300646,1433101107,1378907202,1500272200,1362250345,1313362228,1634495537,1433102412,1450012782,1664108116],[1699109239,1296382330,1496405353,1279478380,1699234153,1332300152,1315591544,1299863857,1298814330,1231958144,0,0,0,0,0,1336]];
// u8[192] flattened = [101,121,74,114,97,87,81,105,79,105,74,118,89,87,100,90,73,110,48,46,101,121,74,106,99,109,86,107,99,121,73,54,73,108,66,121,98,51,82,118,89,50,57,115,86,51,82,109,73,105,119,105,89,88,86,107,73,106,111,105,90,50,53,118,99,50,108,122,73,105,119,105,99,109,70,117,90,67,73,54,73,108,77,122,83,49,73,51,87,71,116,102,85,107,99,51,82,48,116,66,89,108,86,72,81,50,74,105,78,72,81,52,97,108,108,49,85,107,104,76,86,109,112,110,99,48,70,84,101,70,89,119,77,69,57,122,89,49,85,105,76,67,74,108,101,72,65,105,79,105,73,120,78,106,85,120,77,122,89,49,77,106,85,122,73,110,48,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,56];
// u8[384] flattened = flattenedToBytes::<3,384>(preimg);
u32[8] hash = [3061472856,343516747,3538476305,3326575927,2228721217,2069433080,3190598334,2108440221];
assert(sha256(preimg) == hash);
u8[24] audMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0];
u8[24] audMasked = [73,105,119,105,89,88,86,107,73,106,111,105,90,50,53,118,99,50,108,122,0,0,0,0];
u32 audIdx = 48;
u8[48] subMasked = [101,121,74,106,99,109,86,107,99,121,73,54,73,108,66,121,98,51,82,118,89,50,57,115,86,51,82,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
u8[48] subMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
u32 subIdx = 20;
u8[24] expMasked = [76,67,74,108,101,72,65,105,79,105,73,120,78,106,85,120,77,122,89,49,77,106,85,122];
u8[24] expMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
u32 expIdx = 140;
// assert(hasMaskedString(flattened, audMask, audMasked, audIdx));
// assert(hasMaskedString(flattened, subMask, subMasked, subIdx));
// assert(hasMaskedString(flattened, expMask, expMasked, expIdx));
bool success = checkJwt(preimg, hash, audMask, audMasked, audIdx, subMask, subMasked, subIdx, expMask, expMasked, expIdx);
assert(success);
return true;
}
def testCheckJwt512x14()-> bool {
u32[14][16] preimg = [[1702447720,1648845673,1332300371,1434077489,1315522931,1231910000,1514359094,1231710002,1297373488,1331123504,1314144634,1297372538,1329876589,1315785013,1514427768,1296517427],[1496469808,1515481977,1298815594,1295142507,1329882985,1279478320,1700282729,1332300363,1446072681,1716596325,2034921571,860711247,1766484057,844002916,1463103587,2033544802],[842624610,1196782937,842626121,1769433433,1483765577,1785686349,1783967823,1416048718,1413576526,1415131724,1414428769,1481453902,1194423898,1834380878,1465281378,845441124],[1466988899,1147697497,1784969049,1849767267,1481798988,1833334627,1213035866,842626650,846752868,1481534563,1833858658,1850895458,1850832217,842626121,1769433433,1482058569],[1785686349,1783967823,1416048718,1413576526,1415131724,1414428769,1481453902,1194423898,1834380878,1465281378,845441124,1466988899,1147697497,1784969049,1849767267,1481798988],[1833334627,1213035866,842626650,846752868,1481534563,1833858658,1850895458,1850832217,842626121,1769433443,861301065,1785686349,1413576526,2053583695,1146171470,1147370061],[1415805261,1785410638,1414625865,1769433434,1462855777,1467443535,1766487385,1463117921,842362977,1195799377,1197765721,1466725196,1833858658,1397322569,1834382425,1466725208],[861564003,1835822433,1465281353,1785737315,1851157580,1128949860,1178169177,1481535305,1785686372,1146777942,1815691866,809924948,1198552396,1481004627,1817064802,1433956186],[2034856777,1832216674,1465215311,1766477657,1463117921,2034388833,1466460258,1128418401,1195799395,843409740,1128953697,1464741988,1481272393,1785686369,1213345891,1213019724],[2033808225,1145927002,842626650,846752868,1481534563,1833858658,1850895458,1850832217,842626124,843413073,1430672727,1162234724,2052222541,1447113557,1180325203,844781397],[1429302372,1180988501,1449621585,1817081431,1785483351,1414682197,1467239523,1784968020,1146173795,2053845580,1464691020,1128951393,1482320994,1815704921,1462856777,1785686356],[1833334105,1467180884,1835822937,1467443532,1128951129,1462857826,1215063650,1833333850,1397306953,1802792793,1467513433,1397322569,1836611161,843477850,1397306953,1834382665],[1769433441,1464217673,1785690190,1783986253,2052142413,1784904268,1128950885,1212246351,1782919758,1413839438,1414083662,2051896137,1836068961,1397306953,1782657870,1414870095],[1147432015,1414083405,2051092826,1415131225,843396173,1465280589,2051355481,1784248410,1196521561,1464494670,1464232282,1785162086,1367343104,0,0,7048]];
u32[8] hash = [594231611,4059076825,2888452636,2914781367,3635075950,3225969771,649882671,19203446];
assert(sha256(preimg) == hash);
u8[108] audMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
u8[108] audMasked = [73,105,119,105,89,88,86,107,73,106,111,105,77,106,85,48,79,84,103,48,78,84,65,119,78,84,89,50,76,84,78,120,97,88,77,49,78,71,49,118,90,109,86,110,78,87,86,107,98,50,100,104,100,87,112,121,99,68,104,121,89,106,100,119,89,110,65,53,99,88,82,117,76,109,70,119,99,72,77,117,90,50,57,118,90,50,120,108,100,88,78,108,99,109,78,118,98,110,82,108,98,110,81,117,89,50,57,116]; // u32 audIdx = 48
u32 audIdx = 247;
u8[48] subMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0];
u8[48] subMasked = [73,105,119,105,99,51,86,105,73,106,111,105,77,84,65,119,78,122,103,51,79,68,81,48,78,68,99,122,77,84,99,121,77,106,107,52,78,84,81,122,0,0,0,0,0,0,0,0];
u32 subIdx = 355;
u8[24] expMask = [255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255];
u8[24] expMasked = [76,67,74,108,101,72,65,105,79,106,69,50,78,84,69,122,78,84,73,52,78,122,77,115];
u32 expIdx = 791;
// assert(hasMaskedString(flattened, audMask, audMasked, audIdx));
// assert(hasMaskedString(flattened, subMask, subMasked, subIdx));
// assert(hasMaskedString(flattened, expMask, expMasked, expIdx));
bool success = checkJwt(preimg, hash, audMask, audMasked, audIdx, subMask, subMasked, subIdx, expMask, expMasked, expIdx);
assert(success);
return true;
}
def main() {
bool z = testCheckMask();
bool x = testMaskString();
bool c = testSubstringAt();
bool v = testHasSubstringAt();
bool b = testCheckAud();
bool n = testHasMaskedString();
// bool m = testCheckExp();
bool s = testU32ToU8s();
bool a = testFlatten();
bool integration3 = testCheckJwt512x3();
bool integration14 = testCheckJwt512x14();
return;
}