-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathparse_chacha_tv.py
More file actions
48 lines (43 loc) · 1.33 KB
/
parse_chacha_tv.py
File metadata and controls
48 lines (43 loc) · 1.33 KB
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
# Copyright 2018 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import re
import paths
import parsetv
class ParseChacha20(parsetv.ParseTv):
def _finish_tvkv(self):
if self._tvvalue:
m = re.fullmatch(r"Keystream block (\d+)", self._tvkey)
if m:
self._tvstreamlist.append({
"block": int(m.group(1)),
"value": self._tvvalue,
})
else:
self._tvdict[self._tvkey] = self._tvvalue
self._tvkey = None
self._tvvalue = None
def _handle_line(self, l):
l = l.strip()
if l.startswith("Test vectors"):
pass
elif len(l) == 0:
self._finish_tvkv()
elif l[0] in "=-":
pass
elif l.startswith("TC"):
self._start_tvset({"setintro": l})
elif ":" in l:
k, v = l.split(":", 1)
if k == "Key":
self._start_tv({})
self._start_tvkv(k.strip())
self._vappend(v.strip())
else:
self._vappend(l)
def test_vectors():
p = ParseChacha20()
p.parse_file(paths.top / "test_vectors" / "other" / "chacha_testvectors.txt")
return p.get()