Symmetric encryption is a type of encryption where you use a password (also known as a "key") to encrypt your data, and then the same password to decrypt the data.
For example, this is the type of encryption that is used for encrypting the data in our smartphones and laptops with disk encryption.
This way, if your laptop gets stolen, the thief is not able to see your private photos without knowing your password, even though they are able to read every byte of your disk.
The downside is that that you have to type your password every time you want to login. This leads people to want to use shorter passwords, which in turn are more prone to password cracking.
The other main type of encryption is public-key cryptography.
The advantage of public-key cryptography is that it allows you to send secret messages to other people even an the attacker is able to capture the encrypted messages. This is for example what you want to do when sending a personal message to a friend over the Internet. Such encryption is especially crucial when using wireless communication such as Wi-Fi, where anyone nearby can capture the signals you send and receive, and would be able to read all your data if it weren't encrypted.
Easily sending encrypted messages over the Internet is not possible with symmetric encryption because for your friend to decrypt the message in that system, you'd need to send them the password, which the attacker would also be able to eavesdrop and then decrypt the message that follows using it. The problem of sharing a password with another person online is called key exchange.
Advanced Encryption Standard (AES) is one of the most popular families of symmetric encryption algorithms.
OpenSSL is a popular open source implementation of symmetric and public-key cryptography. A simple example of using OpenSSL for symmetric encryption from the command-line is:This asks for a password, which we set as contains:Then to decrypt:once again asks for your password and given the correct password produces a file This was tested on Ubuntu 24.04, OpenSSL 3.0.13. See also: How to use OpenSSL to encrypt/decrypt files? on Stack Overflow.
echo 'Hello World!' > message.txt
openssl aes-256-cbc -a -salt -pbkdf2 -in message.txt -out message.txt.enc
asdfqwer
, and then produces a file message.txt.enc
containing garbled text such that:hd message.txt.enc
00000000 55 32 46 73 64 47 56 6b 58 31 38 58 48 65 2f 30 |U2FsdGVkX18XHe/0|
00000010 70 56 42 2b 70 45 6c 55 59 38 2b 54 38 7a 4e 34 |pVB+pElUY8+T8zN4|
00000020 4e 37 6d 52 2f 73 6d 4d 62 64 30 3d 0a |N7mR/smMbd0=.|
0000002d
openssl aes-256-cbc -d -a -pbkdf2 -in message.txt.enc -out message.new.txt
message.new.txt
containing the original message:Hello World!
There is no provably secure symmetric-key algorithm besides the one-time pad, which has the serious drawback of requiring the key to be as long as the message. This means that we believe that most encryption algorithms are secure because it is a hugely valuable target and no one has managed to crack them yet. But we don't have a mathematical proof that they are actually secure, so they could in theory be broken by new algorithms one day.
There aren't any 2020, except in the trivial one-time pad case where the key is as large as the message: crypto.stackexchange.com/questions/10815/how-do-we-prove-that-aes-des-etc-are-secure
The only perfect cryptosystem!
The problem is that you need a shared key as large as the message.
Systems like advanced Encryption Standard allow us to encrypt things larger than the key, but the tradeoff is that they could be possibly broken, as don't have any provably secure symmetric-key algorithms as of 2020.
Symmetric-key algorithm is al algorithm implementing symmetric encryption.
2020-so-far yes, Grover's algorithm would only effectively reduce key sizes by half:but there isn't a mathematical proof either.
It allows you to do two things:
One notable application: cryptocurrency, see e.g. how Bitcoin works.
Used for example:
- by Monero to hide the input of a transaction
- anonymous electronic voting
Based on the fact that we don't have a P algorithm for integer factorization as of 2020. But nor proof that one does not exist!
The private key is made of two randomly generated prime numbers: and . How such large primes are found: how large primes are found for RSA.
The public key is made of:
n = p*q
- a randomly chosen integer exponent between
1
ande_max = lcm(p -1, q -1)
, wherelcm
is the Least common multiple
Given a plaintext message This operation is called modular exponentiation can be calculated efficiently with the Extended Euclidean algorithm.
m
, the encrypted ciphertext version is:c = m^e mod n
The inverse operation of finding the private
m
from the public c
, e
and is however believed to be a hard problem without knowing the factors of n
.However, if we know the private
p
and q
, we can solve the problem. As follows.First we calculate the modular multiplicative inverse. TODO continue.
Bibliography:
- www.comparitech.com/blog/information-security/rsa-encryption/ has a numeric example
Answers suggest hat you basically pick a random large odd number, and add 2 to it until your selected primality test passes.
The prime number theorem tells us that the probability that a number between 1 and is a prime number is .
Therefore, for an N-bit integer, we only have to run the test N times on average to find a prime.
Since say, A 512-bit integer is already humongous and sufficiently large, we would only need to search 512 times on average even for such sizes, and therefore the procedure scales well.
RSA vs Diffie-Hellman key exchange are the dominant public-key cryptography systems as of 2020, so it is natural to ask how they compare:
- security.stackexchange.com/questions/35471/is-there-any-particular-reason-to-use-diffie-hellman-over-rsa-for-key-exchange
- crypto.stackexchange.com/questions/2867/whats-the-fundamental-difference-between-diffie-hellman-and-rsa
- crypto.stackexchange.com/questions/797/is-diffie-hellman-mathematically-the-same-as-rsa
As its name indicates, Diffie-Hellman key exchange is a key exchange algorithm. TODO verify: this means that in order to transmit a message, both parties must first send data to one another to reach a shared secret key. For RSA on the other hand, you can just take the public key of the other party and send encrypted data to them, the receiver does not need to send you any data at any point.
Based on the fact that we don't have a P algorithm for the discrete logarithm of the cyclic group as of 2020, but we do have an efficient algorithm for modular exponentiation. But nor do we have proof that one does not exist! Living on the edge as usual for public-key cryptography.
The algorithm is completely analogous to Diffie-Hellman key exchange in that you efficiently raise a number to a power times and send the result over while keeping as private key.
The only difference is that a different group is used: instead of using the cyclic group, we use the elliptic curve group of an elliptic curve over a finite field.
Variant of Diffie-Hellman key exchange based on elliptic curve cryptography.
ECDH has smaller keys. youtu.be/gAtBM06xwaw?t=634 mentions some interesting downsides:
- bad curves exist, while in modular, any number seems to work well. TODO why?
- TODO can't find this mentioned anywher else: Diffie-Hellman key exchange has a proof that there is no algorithm, ECDH doesn't. Which proof?
Ciro Santilli has a hard time understanding why this is possible, e.g. many people use short 4 digit pins, or a short swipe pattern. Why can't this be cracked easily offline?
Can we do better than "wrong password implies random bytes"?
Can the last disk access times be checked via forensic methods?
Generate public private key, test encrypt and test decrypt:
# Create your pubkey.
gpg --gen-key
gpg --armor --output pubkey.gpg --export <myemail>
# Encrypt using someone's pubkey.
gpg --import pubkey2.gpg
echo 'hello world' > hello.txt
gpg --output hello.txt.gpg --encrypt --recipient <other-email> hello.txt
# Double check it is not plaintext in the encrypted message.
grep hello hello.txt.gpg
# Decrypt.
gpg --output hello.decrypt.txt --decrypt --recipient <myemail> hello.txt.gpg
diff -u hello.decrypt.txt hello.txt
This is a way to host a server that actually hide the IP of the server from the client, just like Tor hides the IP of the client from the server. Amazing tecnology!
This is why it enables hosting illegal things like the Silk Road: law enforcement is not able find where the server is hosted, and take it down or identify the owner.
This is where "fun" stuff is likely to be.
Live January 2024.
Bibliography:
In the context of cryptography, authentication means "ensuring that the message you got comes from who you think it did".
Authentication is how we prevent the man-in-the-middle attack.
Authentication is one of the hardest parts of cryptography, because the only truly secure way to do it is by driving to the other party yourself to establish a pre-shared key so you can do message authentication code. Or to share your public key with them if you are satisfied with the safety of post-quantum cryptography.