Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
namespace_asm.py
Go to the documentation of this file.
1import re
2from typing import Set
3
4FNAME_REGEX = re.compile(r"""
5 ((.global|call)\s+(?P<name>(\w|\d)+))|
6 (^(?P<label>(\d|\w)+):)
7 """, re.VERBOSE)
8
9
10def get_functionnames(filecontent: str) -> Set[str]:
11 found = set()
12 for line in filecontent.splitlines():
13 if (match := FNAME_REGEX.search(line)) is not None:
14 name = match.group("name") or match.group("label")
15 if "secsidh_csidh_internal" in name or "secsidh_ctidh_internal" in name or name == "randombytes":
16 continue
17 found.add(name)
18 return found
19
20
21if __name__ == "__main__":
22 import sys
23 if len(sys.argv) != 3:
24 print(f"Usage: {sys.argv[0]} prime file.s", file=sys.stderr)
25 exit(1)
26 prime = sys.argv[1]
27 inputfilename = sys.argv[2]
28
29 assert prime in ("512", "2047k221", "4095k256", "5119k234", "6143k256", "8191k332", "9215k384")
30
31 with open(inputfilename, "r") as fh:
32 contents = fh.read()
33
34 functionnames = get_functionnames(contents)
35
36 for name in functionnames:
37 contents = re.sub(fr"\b{name}\b", f"secsidh_csidh_internal_{prime}_{name}", contents)
38
39 assert len(get_functionnames(contents)) == 0, f"missed {get_functionnames(contents)}"
40
41 with open(inputfilename, "w") as fh:
42 fh.write(contents)
Set[str] get_functionnames(str filecontent)