3. 34/16/2019
Public Key Cryptography…Very Brief Intro
Basic RSA Signature Operations with OpenSSL
RSA Math
Signature Verification with Python to Demonstrate
Math
Trust
Topics
4. 44/16/2019
Symmetric vs. Asymmetric
Public/Private Keys
−Sign with Private key; Verify with Public key
(Everyone can verify, 1 can sign)
−Encrypt with Public key; Decrypt with Private key
(Everyone can encrypt, 1 can decrypt)
−Best Practice: Don’t use same keypair for both
encrypting and signing
Public Key (Asymmetric) Cryptography
9. 94/16/2019
p, q, n, e, d
p, q are chosen large prime numbers
modulus n=p*q
public exponent e is chosen (3 and 65537 are commonly
used)
private exponent d is derived from p, q, and e
“Modular Exponentiation”
signature(encrypt) = 𝑑𝑎𝑡𝑎d mod n
verify(decrypt) = signaturee mod n
RSA Math
10. 104/16/2019
Show p, q, n, e, d
openssl rsa -in privateKey.pem -text -noout
Private-Key: (2048 bit)
Modulus: 00:df:a3:ab:f4... <-n
publicExponent: 65537 (0x10001) <-e
privateExponent: ... <-d
prime1: ... <-p
prime2: ... <-q
Examine Parts of Key
12. 124/16/2019
Need 3 values: n, e, and signature
− n (modulus)
openssl rsa -noout -in privateKey.pem -modulus
mod =
int("DFA3ABF46D3814551238A931A0B0561D583D436FAAFDD691C83C57008A347B24B16BB0CC816C7DD0EC167E0F5EDDE4F8196CCE6A1CBD3EB500
D0D84D6E7E0939C6C3B2BC17718854AB4B1C6EE9A80536AE9D21F0FD591512C1A4EA36E1709273AD47AD3C5EE14493774967FEE666767C7A790587F
79E5D342D79F25F2F0571FD2486A03E89A9B02EF57DF060EE7D9246D1BF89924F015FE33060CAF9790AB7A162AD159ADA3289CCF15EE2ECD188352B
41269493139333F0CB44C47FDC9E2D4EDE84206E6C94EEB223BD556CBE14376047C7B9BF96413CA153452A6C66D397500AA30538ADD6C3DB590C70F
0D1B426F64D97636BBF6AE84AEF894280B38E1B6B",16)
− e (public exponent)
0x10001 (65537)
exp = int("10001",16)
− signature
xxd -l 256 -ps -c 256 helloSig.bin
sig =
int("53BEE3B3926E0011BFEEBD97D76564A2E3157A5C9984FD18099EBE014112491867BF08850643F7EFC5495B082C741E43C38B6BA090372B7F48
03AB27E4A5BC1266EA4F4D70738E372F58C399742FE42B5A28E1C0A6A5FE788CFE16426E5EC2C8CFFBD23BC27F1E49D93BBEF3CD0F921C3F8EAE021
8F392FA822C40D42130052C6E2DF749D6D74E5E5C79A758A91DC5A13B5BD17A67ECA508C3008C9B32DCA0BBD92BB881156AB354FCE916721143539B
51AF77D402E13E8845808E3FD9751C3C3352FF5D3E3CA80DA3ECDFF585F30EE2D0705CF5612E27C88DEF944C16F2C051762149A00FDE2C3BFF48532
0279884A6560F3CE85EF8DCD2C625A4BAC8F3E46D",16)
Signature Verification with Python
13. 134/16/2019
Modular exponentiation
ver = pow(sig,exp,mod)
Print the result!
print hex(ver)
0x1ffff...003031300d0609608648016503040201050004205891b5b522d5df086d0ff0b110fbd9d21bb4fc
7163af34d08286a2e846f6be03
WHAT IS THAT?
Signature Verification with Python
14. 144/16/2019
Break it into parts
0x1ffffffffffffffff...003031300d0609608648016503040201050004205891b5b522d5df086d0ff0b110fbd
9d21bb4fc7163af34d08286a2e846f6be03L
Third part:
openssl dgst -sha256 hello.txt
First part:
− padding
Second part:
− encoding for hash algorithm identifier
Signature Verification with Python
16. 164/16/2019
What did we just prove?
We proved that the private key corresponding to
publicKey.pem signed hello.txt resulting in the signature file
helloSig.bin
The decrypted signature proves the private key. The hash
proves the file.
So did we prove that Bob signed it?
− No
− We don’t know who that private key belongs to
But if Bob gives us a certificate signed by someone we trust,
and that certificate contains the public key we used to verify
the signature, THEN we can trust that Bob signed the file.
Trust