Convert AES-128-CTR to pre-parsed C++ circuit#171
Convert AES-128-CTR to pre-parsed C++ circuit#171kdrag0n wants to merge 2 commits intoemp-toolkit:masterfrom
Conversation
kdrag0n
commented
Jul 22, 2022
- Add support for loading and generating pre-parsed C++ code for BristolFashion circuits (mostly copied from BristolFormat)
- Use a pre-parsed AES-128 circuit for AES_128_CTR_Calculator in order to improve initialization time, especially in environments where sscanf is relatively slow (45 -> 35 ms in a program that uses the AES_128_CTR_Calculator)
Mostly copied from the BristolFormat implementation.
This provides a considerable improvement in AES_128_CTR_Calculator's initialization time, especially in environments where sscanf is relatively slow. Time in a program that uses AES_128_CTR_Calculator has decreased from ~45 to 35 ms.
|
Thanks for your contribution. However, I'm not sure if it is a good idea to put aes_128.cpp as the source since it is essentially duplicated information with aes_128.txt. There is a pre-parsed AES from https://github.com/emp-toolkit/emp-tool/blob/master/CMakeLists.txt#L17 already. What's the difference? |
I agree that the duplication isn't ideal, but I'm not sure what the alternative is. The txt.cpp file can be generated at compile-time with shell commands, but generating this is a bit more complicated and requires calling
The txt.cpp + fmemopen approach is certainly faster than reading from a file, but in my testing, it's still considerably slower than this because the textual data is parsed with sscanf (character-by-character) every time AES_128_CTR_Calculator is initialized. This pre-parsed circuit already has all the text parsed into numbers that are compiled into the library as constant data (similar to the output of Benchmarks of a program that uses AES_128_CTR_Calculator, before and after this change: Host: 45 -> 35 ms |
|
The |
|
The txt.cpp file looks like this: It's compiled into the binary, but the embedded data is the content of aes_128.txt — still in textual form. fmemopen is used to open a virtual FILE pointing to this data so the text can be parsed with fscanf: emp-tool/emp-tool/circuits/aes_128_ctr.h Line 108 in f1f46ff emp-tool/emp-tool/circuits/circuit_file.h Line 166 in 1345a14 |
|
I see you are right! I think the best way is to modify the existing code so that the generated array in the current code base does not need parsing anymore, right? |