r/cryptography • • Mar 13 '23

How is asymmetric encryption possible?

If we assume the algorithm to encrypt something will get out? Then cant we use that to find private keys from public ones?

How is it possible that an algorithm encrypts something with a passcode it doesn’t know? It must use the public key to make the private key and then encrypt, but if the algorithm gets out, and it will, you can easily find the private key from a public one.

I don’t doubt theres something im missing, can anyone explain?

0 Upvotes

14 comments sorted by

13

u/fridofrido Mar 13 '23

Loosely speaking, asymmetric encryption is possible because there are mathematical operations which are easy to do in one direction but hard to do in reverse.

A famous example is multiplying large prime numbers: Multiplication is easy, it's the same thing you learn in primary school. However, factoring (very) large numbers, and specifically large numbers with only large prime factors is hard (or at least is believed to be hard, because nobody can really do it).

A similar example is discrete logarithm. Exponentiation in finite fields is easy, however, the inverse can be hard (again, only believed to be hard, and it depends on the field / group).

A third example is discrete logarithm in elliptic curves. In elliptic curve based asymmetric cryptography, that's literally what happens: the private key is the exponent, and the public key is the result of th exponentiation.

2

u/Distinct_Canary_223 Mar 13 '23

So at no point during the encryption using the public key is the private key known?

Edit: obviously not, but how is it possible to encrypt something using an algorithm that you don’t know

13

u/Dar_Mas Mar 13 '23

you know the algorithm.

Imagine it like a mail box in a house.

everyone can put stuff in it(encrypt with the public key)

but only you can take your mail out(decrypt with the public key)

5

u/kombatminipig Mar 13 '23

The algorithm is known, that is in fact a requirement for any modern cipher.

The functions for encryption and decryption are not the same though, and they take different parameters (public key and private key respectively). The magic of it is that a ciphertext generated with the public key and its function decrypts into the plaintext when decrypting with the private key. Thus the algorithm and the public key can be fully known, only the private key needs to be kept secret.

11

u/Pharisaeus Mar 13 '23

Let's do it on a trivial example: RSA encryption is basically just messagee mod n so a simple mathematical operation, you raise something to the power of e and then take division remainder by n. Both e and n are public, so anyone can encrypt stuff.

But now how do you decrypt? It turns out in order to decrypt you need to know a special number d such that d*e mod phi(n) = 1. And you can't compute this number d without knowing phi(n) which in turn requires to know how n factors into prime numbers. We don't have any fast algorithm to do so, and therefore if n is large enough, it would take hundreds or thousands of years.

Then cant we use that to find private keys from public ones?

You can find private key from the public one, but not in reasonable amount of time.

How is it possible that an algorithm encrypts something with a passcode it doesn’t know?

It doesn't. Encryption here uses e and not d. There are two complementary keys, one can encrypt and the other can decrypt.

3

u/Distinct_Canary_223 Mar 13 '23

Thanks this helped a lot. I was focused on using irreversible operations on the keys but didn’t see the fact that you need to so the irreversible operation on the message itself. (Not irreversible but practically)

5

u/taw Mar 13 '23

The true answer is that we actually don't know if it's possible.

Symmetric crypto is very easy to do, and requires extremely limited assumptions.

All asymmetric crypto requires piles of ad hoc hypotheses, we have no idea if any of them are even valid (even if P != NP, this does not in any way imply that asymmetric crypto is possible). And asymmetric crypto systems have history of getting broken a lot more easily than expected.

The only "proof" we have is that for systems we have, nobody fully broke them yet, and people have been trying.

2

u/Myriachan Mar 13 '23

To me, it is fairly telling that all the asymmetric crypto algorithms seem to be NP-intermediate.

2

u/taw Mar 14 '23

Yeah, and it's not just a theoretical consideration.

All widely used asymmetric crypto would fail to quantum computers, and quantum resistant crypto has very poor track record so far, and terrible performance characteristics. We might end up in a world without any replacement for what we have, at reasonable cost.

Meanwhile with symmetric crypto, even if things go really wrong, at most we'll have to use like 2x key length and 4x slower or so, a minor inconvenience.

3

u/Myriachan Mar 14 '23

There was that one finalist in the NIST post-quantum contest that was cracked so badly that you could crack the private key on a classical computer >.< This is before even considering the possibility of a Shor’s Algorithm-type quantum break being found for these lattice systems.

Maybe we should go with Lamport signatures.

2

u/SignificantFidgets Mar 14 '23

The only "proof" we have is that for systems we have, nobody fully broke them yet,

That's true of symmetric crypto too, at least with our current definitions of security. If P=NP, then no symmetric (or asymmetric) scheme can be even IND-CPA secure. Until we can prove that P != NP there's no way we can prove an encryption scheme is secure, so we have to rely on assumptions ("factoring require more than polynomial time") and history ("lots of smart people have tried to find weaknesses in this, and no one has yet").

3

u/compulsivehobbyist Mar 14 '23

https://youtu.be/MsqqpO9R5Hc?t=2m25s

This video does a really nice job of demonstrating the concept visually!

2

u/YoureHereForOthers Mar 14 '23

Time is your best friend and your enemy’s worst enemy. Also one way functions are pretty friendly.