r/Python • • Jan 01 '20

"The rules of perf" at Dropbox

Post image
1.6k Upvotes

162 comments sorted by

View all comments

Show parent comments

6

u/geeshta Jan 02 '20

Nice reply, thank you! I want to ask how would you do crypto in C? The problem I'm having is that with Python you have (almost) infinite integers and in cryptogryphy, numbers of tens to hundreds of digits (in base 10) are used. I alway wanted to rewrite my factorization/encryption/decryption libraries that I wrote in Python to C to see the performance increase but always struggled with C's MAX values for integers.

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)

17

u/geeshta Jan 02 '20 edited Jan 02 '20

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.

0

u/DiggV4Sucks Jan 02 '20

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?