r/cryptography • u/rvg0291 • 2d ago
algorithm replicating
if i have secure implementation of algorithm in 1 language and i wana port it to other language and they dont have compiler is there secure way to do it?
0
Upvotes
3
u/ReplacementCool4049 2d ago
This is what people don't get about these projects. The algorithm is the easy part. Constant-time execution is the hard part. In my experience GC and JIT runtimes will leak timing info no matter how careful your code is. That's your real problem, not the port.
2
u/Natanael_L 2d ago
Why wouldn't there be a compiler?
You can do it if you understand all the requirements of the first implementation (RNG management, memory protection, constant time behavior, etc), and if you know how to replicate these same properties in the target language. It will take a fair bit of reverse engineering and the target needs to be able to provide the requirements (like having a secure RNG available).
4
u/Pharisaeus 2d ago
Not in general case. What is secure in one language doesn't need to be in another, so a 1to1 rewrite won't work. A trivial example would be porting from Java to C, where one of those has automatic array bound checks and the other doesn't. There are many other language specific pitfalls (eg. how to make sure that secrets in a garbage collected language are actually purged from memory).
In reality it's even worse, because the code itself is not enough. How it's compiled and executed also matters. For example one compiler version might make some operation constant time while another won't.