r/cryptography • • 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?

0 Upvotes

11 comments sorted by

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.

1

u/rvg0291 18h ago

what if algorithm dont needs to be time leak prof? will just rewriting it line by line be enough?

1

u/Natanael_L 16h ago

Do you only need to import data and successfully decrypt, or do you need to actually deploy something secure and interactive? If the former then maybe, if the latter then no it's not enough

1

u/rvg0291 7h ago

i wana use same library for all cryptocryptography since i think its easyer to fix single lib for all languages and more portable but most implementations isint portable enough and also i need to use it in sat solver so i need it to work in language wich can be easyly converted into sat solvable format with lib itself turning into sat solvable format too

1

u/Natanael_L 7h ago

You're going the wrong direction then. You should pick implementations that fit a SAT solver (because those aren't practical unless constraints and properties are very well defined) and then port them to whatever your target system is.

1

u/rvg0291 6h ago

i tryed finding but its realy hard to find them

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.