cleanup
This commit is contained in:
parent
513a004f9f
commit
a5305627d2
|
@ -54,8 +54,6 @@ Show parameters of the private key
|
||||||
openssl rsa -in $PRIVATE_KEY -text -noout
|
openssl rsa -in $PRIVATE_KEY -text -noout
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Create RSA Key
|
### Create RSA Key
|
||||||
|
|
||||||
Generate an OpenSSL RSA key via
|
Generate an OpenSSL RSA key via
|
||||||
|
@ -97,14 +95,16 @@ openssl rsautl -decrypt -in $CIPHER -out $PLAIN_TEXT -inkey $PRIVATE_KEY
|
||||||
|
|
||||||
### Read Parameters of a DH Keys
|
### Read Parameters of a DH Keys
|
||||||
|
|
||||||
* Output of a DH key is done the following way
|
Output of a DH key is done the following way
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl dhparam -in $PRIVATE_KEY -text -noout
|
openssl dhparam -in $PRIVATE_KEY -text -noout
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create DH Key
|
### Create DH Key
|
||||||
|
|
||||||
* A Diffie-Hellman key can be created via
|
A Diffie-Hellman key can be created via
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl dhparam -out $PRIVATE_KEY 4096
|
openssl dhparam -out $PRIVATE_KEY 4096
|
||||||
```
|
```
|
||||||
|
@ -113,7 +113,7 @@ openssl dhparam -out $PRIVATE_KEY 4096
|
||||||
|
|
||||||
### Encrypt AES
|
### Encrypt AES
|
||||||
|
|
||||||
* Encrypt AES
|
Encrypt AES
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl aes-256-cbc -e -in $PLAIN_TEXT -out $CIPHER
|
openssl aes-256-cbc -e -in $PLAIN_TEXT -out $CIPHER
|
||||||
|
@ -121,7 +121,8 @@ openssl aes-256-cbc -e -in $PLAIN_TEXT -out $CIPHER
|
||||||
|
|
||||||
### Decrypt AES
|
### Decrypt AES
|
||||||
|
|
||||||
* Decrypt AES
|
Decrypt AES
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl aes-256-cbc -d -in $CIPHER -out $PLAIN_TEXT
|
openssl aes-256-cbc -d -in $CIPHER -out $PLAIN_TEXT
|
||||||
```
|
```
|
||||||
|
@ -130,14 +131,16 @@ openssl aes-256-cbc -d -in $CIPHER -out $PLAIN_TEXT
|
||||||
|
|
||||||
### Encrypt PBKDF2
|
### Encrypt PBKDF2
|
||||||
|
|
||||||
* Encrypt file via PBKDF2 with 128000 iterations
|
Encrypt file via PBKDF2 with 128000 iterations
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl aes-256-cbc -pbkdf2 -iter 128000 -e -in $PLAIN_TEXT -out $CIPHER
|
openssl aes-256-cbc -pbkdf2 -iter 128000 -e -in $PLAIN_TEXT -out $CIPHER
|
||||||
```
|
```
|
||||||
|
|
||||||
### Decrypt PBKDF2
|
### Decrypt PBKDF2
|
||||||
|
|
||||||
* Decrypt file via PBKDF2 with an iteration of 128000
|
Decrypt file via PBKDF2 with an iteration of 128000
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
openssl aes-256-cbc -pbkdf2 -iter 128000 -d -in $CIPHER -out $PLAIN_TEXT
|
openssl aes-256-cbc -pbkdf2 -iter 128000 -d -in $CIPHER -out $PLAIN_TEXT
|
||||||
```
|
```
|
||||||
|
@ -151,4 +154,3 @@ openssl aes-256-cbc -pbkdf2 -iter 128000 -d -in $CIPHER -out $PLAIN_TEXT
|
||||||
```sh
|
```sh
|
||||||
openssl ec -pubin -in publickey.pem -noout -text
|
openssl ec -pubin -in publickey.pem -noout -text
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
# RSA
|
# RSA
|
||||||
|
|
||||||
* `p * q = n`
|
What is interesting about an RSA key:
|
||||||
* Coprime Phi is calculated either by [Euler Totient](https://en.wikipedia.org/wiki/Euler's_totient_function) or [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) via [euclidean algorithm](https://crypto.stanford.edu/pbc/notes/numbertheory/euclid.html)
|
|
||||||
|
`e` is a constant, often it is 65537
|
||||||
|
|
||||||
|
`n` is the modulus, `p * q = n` through factorization
|
||||||
|
|
||||||
|
Coprime `phi` is calculated either by [Euler
|
||||||
|
Totient](https://en.wikipedia.org/wiki/Euler's_totient_function) or [greatest
|
||||||
|
common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor) via
|
||||||
|
[euclidean
|
||||||
|
algorithm](https://crypto.stanford.edu/pbc/notes/numbertheory/euclid.html)
|
||||||
|
|
||||||
|
`d` is the modular inverse of e and phi
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
$$
|
$$
|
||||||
1 < \phi < n
|
1 < \phi < n
|
||||||
|
@ -10,7 +23,7 @@ $$
|
||||||
There is also
|
There is also
|
||||||
$$
|
$$
|
||||||
\phi = (p-1) * (q-1)
|
\phi = (p-1) * (q-1)
|
||||||
$$$
|
$$
|
||||||
|
|
||||||
Encryption, public key `e` is a prime between 2 and phi
|
Encryption, public key `e` is a prime between 2 and phi
|
||||||
$$
|
$$
|
||||||
|
@ -36,8 +49,13 @@ for i in range (phi + 1, phi + foo):
|
||||||
possible_d.append()
|
possible_d.append()
|
||||||
```
|
```
|
||||||
|
|
||||||
* \\( Cipher = msg ** d mod $\phi$ \\)
|
$$
|
||||||
* \\( Cleartext = cipher ** e mod $\phi$ )
|
Cipher = msg ** d mod $\phi$
|
||||||
|
$$
|
||||||
|
|
||||||
|
$$
|
||||||
|
Cleartext = cipher ** e mod $\phi$
|
||||||
|
$$
|
||||||
|
|
||||||
## Euklid
|
## Euklid
|
||||||
|
|
||||||
|
@ -179,6 +197,7 @@ def isqrt(n):
|
||||||
x=y
|
x=y
|
||||||
y=(x+n//x)//2
|
y=(x+n//x)//2
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def fermat(n):
|
def fermat(n):
|
||||||
t0=isqrt(n)+1
|
t0=isqrt(n)+1
|
||||||
counter=0
|
counter=0
|
||||||
|
@ -214,6 +233,7 @@ def isqrt(n):
|
||||||
x=y
|
x=y
|
||||||
y=(x+n//x)//2
|
y=(x+n//x)//2
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def fermat(n):
|
def fermat(n):
|
||||||
t0=isqrt(n)+1
|
t0=isqrt(n)+1
|
||||||
counter=0
|
counter=0
|
||||||
|
|
Loading…
Reference in New Issue