r/cryptography • u/rvg0291 • 1d 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?
2
u/Natanael_L 1d 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).
1
u/rvg0291 1d ago
what if source language uses syscalls wich target doesnt have
1
u/Natanael_L 19h ago
What kind of syscalls? You'd have to model what the calls do and figure out if they're necessary and if they can be replicated.
For cryptographic algorithms, the only common syscalls are memory access and RNG calls. If you don't have an RNG available you've got problems, unless the algorithm is deterministic.
1
u/rvg0291 18h ago
thats hard to replace syscalls i know that they dont need syscalls but some librarys still have them including console syscalls to make cli,lib loading syscalls,rng syscalls and its hard top replicate them also i need final algorithm to have finite memory and time wich starting algorithms dont cus they have unbounded/conditonal while loops
4
u/Pharisaeus 1d 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.
3
u/ReplacementCool4049 1d 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.