This shows you the differences between two versions of the page.
|
ic:laboratoare:11 [2018/12/07 22:14] george.pirtoaca |
ic:laboratoare:11 [2020/11/05 17:53] (current) acosmin.maria |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Laboratorul 11 - Public key encryption ===== | + | ===== Laboratorul 10 - Public key encryption ===== |
| In this lab we'll do some cool exercises using public key encryption methods for key exchange and data encryption. | In this lab we'll do some cool exercises using public key encryption methods for key exchange and data encryption. | ||
| - | |||
| - | Before starting the labs, download openssl 1.1.0 from [[https://www.openssl.org/source/openssl-1.1.0c.tar.gz|here]]. | ||
| - | Save the file to some local folder accessible by you, then compile it and install it to some folder. | ||
| - | Open the unpacked folder from bash, and run the following commands: | ||
| - | <code bash> | ||
| - | linux$ ./config --prefix=/home/student/local --openssldir=/home/student/local/openssl | ||
| - | linux$ make | ||
| - | linux$ make test | ||
| - | linux$ make install | ||
| - | </code> | ||
| - | (in case of trouble, check also the instructions at the end of [[http://ocw.cs.pub.ro/courses/ic/laboratoare/09|lab 9]]). | ||
| - | |||
| - | While the tools are building/compiling you may start working on some of the exercises. | ||
| Line 26: | Line 13: | ||
| Download the lab code from {{:ic:laboratoare:lab11.zip|here}}. After unzipping, you'll find the source code | Download the lab code from {{:ic:laboratoare:lab11.zip|here}}. After unzipping, you'll find the source code | ||
| for a client (dhe.c) and a server (dhe_server.c), along with a Makefile and fixed Diffie-Hellman p and g params in the files dhparam.pem. | for a client (dhe.c) and a server (dhe_server.c), along with a Makefile and fixed Diffie-Hellman p and g params in the files dhparam.pem. | ||
| - | |||
| - | <note> | ||
| - | Update the Makefile with the paths relevant to your installation folders | ||
| - | </note> | ||
| The client and server have a similar structure. Each of them should build a public key, then send it to the other party, receive the public key from the other party and finally compute the secret key. Your task is to complete the missing parts. For this, consult the openssl documentation [[https://www.openssl.org/docs/man1.1.0/crypto/|here]]. Since they are similar, focus only on one of them and then do similarly on the other one. | The client and server have a similar structure. Each of them should build a public key, then send it to the other party, receive the public key from the other party and finally compute the secret key. Your task is to complete the missing parts. For this, consult the openssl documentation [[https://www.openssl.org/docs/man1.1.0/crypto/|here]]. Since they are similar, focus only on one of them and then do similarly on the other one. | ||
| Line 39: | Line 22: | ||
| If all goes well, you should see the same secret key on both client and server. | If all goes well, you should see the same secret key on both client and server. | ||
| - | <hidden> | + | Before starting this task, check that you have openSSL installed (in this lab we'll use openSSL 1.1.0): |
| - | The solution is {{:ic:laboratoare:lab_dhe_solved.zip|here}}. | + | <code> |
| - | </hidden> | + | #openssl version |
| + | </code> | ||
| + | |||
| + | Also, make sure that you have "libssl-dev" installed (ask your lab supervisor to help you if this is missing, e.g. if you cannot find header files during compilation). | ||
| + | |||
| + | <note> | ||
| + | If you need to install openSSL on your own machine, download openssl 1.1.0 from [[https://www.openssl.org/source/openssl-1.1.0c.tar.gz|here]]. | ||
| + | Save the file to some local folder accessible by you, then compile it and install it to some folder. | ||
| + | Open the unpacked folder from bash, and run the following commands: | ||
| + | <code bash> | ||
| + | linux$ ./config --prefix=/home/student/local --openssldir=/home/student/local/openssl | ||
| + | linux$ make | ||
| + | linux$ make test | ||
| + | linux$ make install | ||
| + | </code> | ||
| + | (in case of trouble, check also the instructions at the end of [[http://ocw.cs.pub.ro/courses/ic/laboratoare/09|lab 9]]). | ||
| + | |||
| + | Make sure to update the Makefile with the paths relevant to your installation folders if you do your own install. | ||
| + | |||
| + | While the tools are building/compiling you may start working on the other exercises. | ||
| + | </note> | ||
| + | |||
| + | <note tip> | ||
| + | For some distributions (e.g. ubuntu), you might need to put the "-lcrypto" flag for compilation at the end. | ||
| + | That is, having the compile lines in the Makefile like this: | ||
| + | <code> | ||
| + | #gcc -L/usr/local/lib dhe.c -o dhe -lcrypto | ||
| + | </code> | ||
| + | </note> | ||
| + | |||
| === Bonus 1 === | === Bonus 1 === | ||
| Line 53: | Line 66: | ||
| ==== Exercise 2: RSA parity oracle (4p) ==== | ==== Exercise 2: RSA parity oracle (4p) ==== | ||
| - | Generate a 1024 bit RSA key pair. | + | Generate a 1024 bit RSA key pair using the Python's Crypto module. |
| Write an oracle function that uses the private key to answer the question "is the plaintext of this message even or odd" (is the last bit of the message 0 or 1). Imagine for instance a server that accepted RSA-encrypted messages and checked the parity of their decryption to validate them, and spat out an error if they were of the wrong parity. | Write an oracle function that uses the private key to answer the question "is the plaintext of this message even or odd" (is the last bit of the message 0 or 1). Imagine for instance a server that accepted RSA-encrypted messages and checked the parity of their decryption to validate them, and spat out an error if they were of the wrong parity. | ||
| Line 68: | Line 81: | ||
| Here's why: | Here's why: | ||
| * RSA ciphertexts are just numbers. You can do trivial math on them. You can for instance multiply a ciphertext by the RSA-encryption of another number; the corresponding plaintext will be the product of those two numbers. | * RSA ciphertexts are just numbers. You can do trivial math on them. You can for instance multiply a ciphertext by the RSA-encryption of another number; the corresponding plaintext will be the product of those two numbers. | ||
| - | * If you double a ciphertext (multiply it by (2**e)%n), the resulting plaintext will (obviously) be either even or odd. | + | * If you double the original plaintext multiply the ciphertext by (2**e)%n). |
| * If the plaintext after doubling is even, doubling the plaintext didn't wrap the modulus --- the modulus is a prime number. | * If the plaintext after doubling is even, doubling the plaintext didn't wrap the modulus --- the modulus is a prime number. | ||
| Line 80: | Line 93: | ||
| After log2(n) iterations, you have the decryption of the message. | After log2(n) iterations, you have the decryption of the message. | ||
| - | |||
| - | Print the upper bound of the message as a string at each iteration; you'll see the message decrypt "hollywood style". | ||
| Decrypt the string (after encrypting it to a hidden private key) above. | Decrypt the string (after encrypting it to a hidden private key) above. | ||
| Line 90: | Line 101: | ||
| Alice wants to share a secret with Bob, but she knows that if she explicitly tells it to Bob, Eve somehow will find out (she hears everything). So she and Bob establish a small game which helps them think about the same secret, without saying it. The game goes like this: | Alice wants to share a secret with Bob, but she knows that if she explicitly tells it to Bob, Eve somehow will find out (she hears everything). So she and Bob establish a small game which helps them think about the same secret, without saying it. The game goes like this: | ||
| - | * Alice sends to Bot a list of puzzles. A puzzle looks like this: | + | * Alice sends to Bob a list of puzzles. A puzzle looks like this: |
| $\mathsf{Puzzle}_i = \mathsf{AES}(\mathsf{key} = 0^{14} \| i, \mathsf{plaintext = Puzzle} \| i \| secret_i)$ | $\mathsf{Puzzle}_i = \mathsf{AES}(\mathsf{key} = 0^{14} \| i, \mathsf{plaintext = Puzzle} \| i \| secret_i)$ | ||
| Line 174: | Line 185: | ||
| </file> | </file> | ||
| - | |||
| - | <hidden> | ||
| - | The solution is {{:ic:laboratoare:lab11_sol.zip|here}}. | ||
| - | </hidden> | ||