workshops/slides/rsa/rsa.md

241 lines
4.8 KiB
Markdown
Raw Permalink Normal View History

2023-05-16 11:33:10 +00:00
---
title:
- RSA - Asimetricna kriptografija i primena
author:
- Aleksej Jocic
theme:
- Warsaw
colortheme:
- orchid
---
# Uvod
- Simetricna kriptografija
2023-06-05 01:54:48 +00:00
Isti kljuc za sifrovanje i desifrovanje
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
$10101 \oplus 11001 = 01100$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
$(m \oplus k) \oplus k =m \oplus (k \oplus k)= m \oplus 0= m$
2023-05-16 11:50:30 +00:00
- Problem bezbedne razmene kljuceva
2023-05-16 11:33:10 +00:00
- Problem autenticnosti
# Uvod
- Asiemtricna kriptografija
2023-05-16 11:50:30 +00:00
- Razliciti kljucevi za sifrovanje i desifrovanje
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $f(m,k1)=c$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $f(c,k2)=m$
2023-05-16 11:50:30 +00:00
- Kljuc za sifrovanje je javno dostupan, (svi znaju $k1$)
- Sifrovanje privatnim kljucem korisceno kao digitalni potpis
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $f(m,k2)=c$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $f(c,k1)=m$
2023-05-16 11:33:10 +00:00
# RSA
- RSA
2023-05-16 11:50:30 +00:00
- 1977\. Ron Rivest, Adi Shamir, Leonard Adleman
- 1976\. DiffieHellman razmena kljuceva
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $g^a \equiv A \mod p$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $g^b \equiv B \mod p$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- $A^b \equiv (g^a)^b$$\equiv (g^b)^a$$\equiv B^a$$\mod p$
2023-05-16 11:33:10 +00:00
# RSA
<div>
2023-05-16 11:50:30 +00:00
![DiffieHellman](slides/rsa/dhke.png)
2023-05-16 11:33:10 +00:00
</div>
# RSA
## Mala Fermaova teorema
Ako je $p$ prost broj, za svako $a$ vazi:
$a^{p-1} \equiv 1 \mod p$
2023-05-16 11:50:30 +00:00
2023-05-16 11:33:10 +00:00
## Posledica
Ako su $p$ i $q$ prosti brojevi, za svako $a$ vazi:
2023-05-16 11:50:30 +00:00
$a^{(p-1)(q-1)}$$\equiv ({a^{p-1}})^{q-1}$$\equiv 1 \mod q$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$a^{(p-1)(q-1)}$$\equiv ({a^{q-1}})^{p-1}$$\equiv 1 \mod p$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$(a^{(p-1)(q-1)}-1)$ je deljivo i sa $p$ i $q$.
2023-05-16 11:33:10 +00:00
$p$ i $q$ su prosti, pa mora da je deljivo i sa $p \cdot q$.
# RSA
2023-06-05 01:54:48 +00:00
## Posledica
2023-05-16 11:50:30 +00:00
$a^{(p-1)(q-1)} \equiv 1 \mod pq$
2023-05-16 11:33:10 +00:00
Takodje:
2023-06-05 01:54:48 +00:00
2023-05-16 11:50:30 +00:00
$a^{x(p-1)(q-1)}$$\equiv ({a^x})^{(p-1)(q-1)}$$\equiv 1 \mod pq$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$a^{x(p-1)(q-1)+1} \equiv a \mod pq$
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
\pause
2023-05-16 11:33:10 +00:00
## Trazimo
$e$ i $d$ tako da:
2023-05-16 11:50:30 +00:00
$({a^e})^d \equiv a^{ed} \equiv a^{x(p-1)(q-1)+1} \mod pq$
2023-05-16 11:33:10 +00:00
Odnosno:
2023-06-05 01:54:48 +00:00
2023-05-16 11:50:30 +00:00
$ed \equiv 1 \mod (p-1)(q-1)$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$d$ je modularni inverz od $e$ pod modulom $(p-1)(q-1)$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
Mozemo koristiti `Produzeni Euklidov algoritam`.
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
U buduce cemo oznacavati $n=pq$, a $\varphi(n)=(p-1)(q-1)$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$a^{\varphi(n)} \equiv 1 \mod n$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
$a^{ed} \equiv a^{x\varphi(n)+1}$$\equiv a \mod n$
2023-05-16 11:33:10 +00:00
# RSA
2023-05-16 11:50:30 +00:00
- Problem faktorisanja $n=pq$
- $\varphi(n)=(p-1)(q-1)$ nije poznato bez $p$ i $q$
- $d$ kao modularni inverz od $e$ nije poznat bez $\varphi(n)$
- $d$ mozemo da cuvamo tajnim cak i ako objavimo $e$ i $n$ javno
2023-05-16 11:33:10 +00:00
# RSA
- Generisanje kljuceva
2023-05-16 11:50:30 +00:00
- Nadjimo velike proste brojeve $p$ i $q$
2023-05-16 11:33:10 +00:00
2023-05-16 11:50:30 +00:00
Testovi prostosti brojeva (Fermaov test)
- Generisemo $n=pq$
- Nadjimo $e$ koji je uzajamno prost sa $(p-1)(q-1)$
- Nadjimo $d$ koriscenjem Produzenog Euklidovog algoritma
2023-06-05 01:54:48 +00:00
- Mozemo zaboraviti $p$ i $q$, jer nam vise ne trebaju
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
# Sifrovanje i potpisivanje
2023-05-16 11:33:10 +00:00
2023-06-05 01:54:48 +00:00
- Javni kljuc se sastoji od brojeva $e$ i $n$
2023-05-16 11:50:30 +00:00
2023-06-05 01:54:48 +00:00
$m^e \equiv C \mod n$
2023-05-16 11:33:10 +00:00
- Privatni kljuc se sastoji od brojeva $d$ i $n$
$C^d \equiv m \mod n$
- Digitalni potpis se postize sifrovanjem sa privatim kljucem
2023-05-16 11:50:30 +00:00
$m^d \equiv S \mod n$
2023-05-16 11:33:10 +00:00
- Provera digitalnog potpisa:
2023-06-05 01:54:48 +00:00
2023-05-16 11:33:10 +00:00
$S^e \equiv m \mod n$
# Prodruzeni Euklidov algoritam
```
def egcd(a, b):
if a == 0:
return (b, 0, 1)
g, y, x = egcd(b%a,a)
return (g, x - (b//a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
if g != 1:
raise Exception('No modular inverse')
return x%m
```
# Napadi na RSA
- Napadi na RSA
2023-05-16 11:50:30 +00:00
- Pogadjanje poruke, potrebno dopunjavanje poruke random podacima (padding)
- Premali eksponent $e$, korenovanje sifrovanog teksta za male poruke (veliko $e$)
- Koriscenje istog eksponenta za vise kljuceva, napad koriscenjem Kineske teoreme o ostatku (random izabrano $e$)
2023-05-16 11:33:10 +00:00
- Desifrovanje sumnjivog teksta, $(x^e \cdot C)^d \equiv (x^e)^d \cdot C^d \equiv x \cdot m \mod n$
# Primena
## GNU Privacy Guard
2023-05-16 11:50:30 +00:00
- 1999\. Werner Koch
- Generisanje kljuca: `gpg --gen-key`
- Lista javnih kljuceva: `gpg --list-keys`
- Export privatnih kljuceva: `gpg --export-secret-keys --output backup.gpg`
- Upload kljuceva: `gpg --send-key [KEYID]`
- Sifrovanje poruke: `gpg -e file.txt`
- Desifrovanje: `gpg -d file.txt`
- Potpisivanje poruke ili fajla: `gpg -s file.exe`
- Potpisivanje kljuca: `gpg --sign-key [KEYID]`
- ASCII output: `gpg --armor -se file.txt`
2023-05-16 11:33:10 +00:00
- GPG password manager: `gpg --armor -c passwords.txt`
# Primena
## Git
2023-05-16 11:50:30 +00:00
- Podesavanje kljuca: `git config --global user.signingkey [KEYID]`
- Potpisivanje komita: `git commit -S`
2023-05-16 11:33:10 +00:00
<div>
2023-05-16 11:50:30 +00:00
![Github signed commits](slides/rsa/github-verified.png)
2023-05-16 11:33:10 +00:00
</div>
# Primena
## SSH
2023-05-16 11:50:30 +00:00
- Generisanje kljuca: `ssh-keygen [-f filename]`
- Dodavanje kljuca na remote masinu: `ssh-copy-id [-i filename] user@hostname`
2023-05-16 11:33:10 +00:00
- `~/.ssh/authorized_keys`
# The Onion Router
## Tor
2023-05-16 11:50:30 +00:00
- 1990\.-te United States Naval Research Laboratory (Paul Syverson,Michael G. Reed,David Goldschlag)
2023-05-16 11:33:10 +00:00
- 20.9.2002. prva verzija Tor-a (javni projekat, anonimnosti u masi)
# The Onion Router
<div>
2023-05-16 11:50:30 +00:00
![How Tor works](slides/rsa/tor.png)
2023-05-16 11:33:10 +00:00
</div>
# Onion hidden services
<div>
2023-05-16 11:50:30 +00:00
![How hidden services works](slides/rsa/tor-onion-services.png)
2023-05-16 11:33:10 +00:00
</div>
# The Onion Router
- Napadi na Tor
2023-05-16 11:50:30 +00:00
- Tor ne stiti od vremenske korelacije (pristup sa obe strane veze)
- Slabosti u aplikacijama koje koriste Tor
- Pogresno konfigurisane aplikacije
2023-05-16 11:33:10 +00:00
- DNS Leak
# Hvala
Hvala na paznji!