-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert AES-128-CTR to pre-parsed C++ circuit #171
base: master
Are you sure you want to change the base?
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? |