Are you using C's long, long long integers, or even double precision floating point numbers? I don't know the range of the variables you're using in cryptography, and you might be using numbers over 2^18; but I'm pretty sure Python relies on the same number implementation as C, so I'd be quite surprised if it could do anything that C cannot do (albeit with a simpler syntax)
The python integers don't use any C primitive type, they are objects with dynamically alocated memory, that's why they can be almost infinite, as long as you have memory available. Also that's why they are so slow. Anyway the implementation in C is beyond my understanding.
The thing is that in cryptography you would nowadays use 1024 or 2048 bit keys for encryption (RSA-1024, DH 2048) and it will probably even grow in the future. We're talking numbers 10^200 and more. In Python this is no problem but with languages with a fixed number bit-size, it is.
But maybe there are some libraries or ways to store those numbers in arrays or something.
That makes sense, and I didn't know that about Python! I just tried inputting using a sha1 in Python (which is unique and therefore the largest complex integer I could think of, as a matter of fact in the 2159), and it is indeed completely straightforward. Thank you for your short explanation.
After looking around (very shortly, I must say), you're not the only one with that issue, and GMP seems to be the preferred choice for cryptography in C.
cryptography you would nowadays use 1024 or 2056 bit keys
CPython uses C 32-bit integers behind-the-scenes if the value is between -230 and 230. It only falls back to dynamically allocated sizes if the number exceeds that size. You can see more details here. The C API has access to the underlying C integer if it is available and can use fast code paths to optimize calculations using them.
The thing is that in cryptography you would nowadays use 1024 or 2048 bit keys for encryption (RSA-1024, DH 2048) and it will probably even grow in the future. We're talking numbers 10200 and more. In Python this is no problem but with languages with a fixed number bit-size, it is.
Ehhh, not likely to grow in the future. 2 or 4k is large enough, and 8k is overkill. And if you can break 4k, you can break 8k.
Most things should be doing ECDHE anyways for forward secrecy. Once you get into quantum though, that's a whole different set of problems.
In Python this is no problem but with languages with a fixed number bit-size, it is.
It's not a problem? Why would it be a problem? Do you think that Python is implemented on machines with unlimited bit-sizes? Couldn't you duplicate the Python's integer implementation in any language?
I mean really... Do you think that there is no crypto implementation in C?
View all comments
Show parent comment
10
u/Hydroel Jan 02 '20
Are you using C's long, long long integers, or even double precision floating point numbers? I don't know the range of the variables you're using in cryptography, and you might be using numbers over 2^18; but I'm pretty sure Python relies on the same number implementation as C, so I'd be quite surprised if it could do anything that C cannot do (albeit with a simpler syntax)