This shows you the differences between two versions of the page.
ic:labs:09 [2021/01/25 11:13] razvan.smadu |
ic:labs:09 [2023/10/09 23:23] (current) razvan.smadu |
||
---|---|---|---|
Line 1: | Line 1: | ||
===== Laboratorul 09 - OpenSSL MACs, Hashes and AEAD ===== | ===== Laboratorul 09 - OpenSSL MACs, Hashes and AEAD ===== | ||
- | The powerpoint presentation for this lab can be found [[https://drive.google.com/file/d/19Q9ECzdrlRsT3UswP4Pwa91zSNcE1T94/view?usp=sharing|here]]. | + | Prezentarea PowerPoint pentru acest laborator o puteți găsi [[https://drive.google.com/file/d/19Q9ECzdrlRsT3UswP4Pwa91zSNcE1T94/view?usp=sharing|aici]]. Puteți lucra acest laborator folosind platforma Google Colab, accesând [[https://colab.research.google.com/github/ACS-IC-labs/IC-labs/blob/main/labs/lab09/lab9.ipynb|acest]] link. |
- | ==== Exercise 1 ==== | + | <hidden> |
- | In this exercise we'll use the command line to compute an HMAC, with SHA-1 as the hashing algorithm. | + | ==== Exercițiul 1 ==== |
- | Recall from the lecture that for HMAC to be secure, we need to sample a random key $k \gets \mathcal{K}$. | + | În acest exercițiu vom folosi CLI pentru a calcula un HMAC, cu SHA-1 pentru algoritmul de hash. |
- | We can generate random bytes using ''openssl rand''. To compute HMACs, check the documentation for ''openssl dgst''. | + | Aduceți-vă aminte de la curs că pentru ca un HMAC să fie sigur, trebuie să generăm o cheie aleatoare $k \gets \mathcal{K}$. |
- | For this exercise, use OpenSSL commands to: | + | Putem folosi octeți aleatori folosind ''openssl rand''. Modul în care se generează HMAC-uri îl puteți găsi în documentația pentru ''openssl dgst''. |
- | - generate a 16 byte random key; | + | |
- | - use the key to compute the SHA-1 HMAC of the following message: "Laborator IC"; | + | |
- | - use the same key to compute the SHA-1 HMAC of the following message: "Laborator IC!". Notice the difference between the messages - a single character (e.g "!"). Observe that the message authentication codes are completely different. | + | |
+ | Pentru acest exercițiu, folosiți comenzi OpenSSL pentru îndeplinirea următoarelor task-uri: | ||
+ | - generați o cheie aleatoare de 16 octeți; | ||
+ | - folosiți cheia pentru a calcula un HMAC SHA-1 al mesajului: "Laborator IC"; | ||
+ | - folosiți aceeași cheie pentru a calcula un HMAC SHA-1 al mesajului "Laborator IC!". Observați diferența dintre mesaje - un singur caracter (adăugarea "!") modifică complet codul HMAC. | ||
- | ==== Exercise 2 ==== | + | ==== Exercițiul 2 ==== |
- | Before you start solving the exercises below, download the {{:ic:laboratoare:aesgcm.zip|lab archive from here}}. | + | Înainte de a începe următorul exercițiu, descărcați {{:ic:laboratoare:aesgcm.zip|arhiva laboratorului de aici}}. |
- | The archive contains the source code for Exercise 3, but sadly it is encrypted. Luckily, we forgot to remove the password file from the archive. | + | Arhiva conține codul sursă pentru Exercițiul 3, dar din păcate este criptat. Aveți noroc că am uitat să scoatem fișierul cu parola din arhivă. |
- | Use ''openssl'' commands to decrypt the source file. | + | Folosiți comenzi ''openssl'' pentru a decripta fișierul cu codul sursă. |
<note hint> | <note hint> | ||
- | The file is encrypted using AES-256 in CBC mode. | + | Fișierul este criptat folosind AES-256 în mod CBC. |
</note> | </note> | ||
==== Exercise 3 ==== | ==== Exercise 3 ==== | ||
- | <hidden> | ||
<note hint> | <note hint> | ||
- | The problem has been fixed, so no more code for students! | + | Problema a fost rezolvată, nu mai e nevoie de cod pentru studenți! |
</note> | </note> | ||
- | In case you didn't manage to solve Exercise 3 (more recent versions of openssl are not compatible with respect to the encryption/decryption using password), here is the lab starting code: | + | În caz că nu ați reușit să rezolvați Exercițiul 2 (versiuni mai recente de openssl nu sunt compatibile cu criptarea/decriptarea folosind parola), aveți aici codul sursă: |
<code> | <code> | ||
Line 143: | Line 143: | ||
</code> | </code> | ||
- | </hidden> | + | În acest exercițiu vom folosi OpenSSL ca să criptăm și să decriptăm cu AES-256-GCM. Din păcate, AES-GCM nu poate fi folosit prin comenzile din CLI de OpenSSL, așa că va trebui să îl implementăm noi. |
- | + | ||
- | In this exercise we'll use OpenSSL to encrypt and decrypt with AES-256-GCM. Unfortunately, AES-GCM is not supported by the command line utilities of OpenSSL so we'll have to implement it ourselves. | + | |
- | + | ||
- | Open the file you decrypted in the previous exercise and inspect the code. There are two functions that need to be implemented: ''aes_gcm_encrypt'' and ''aes_gcm_decrypt''. We have included hints to guide you through the code. | + | |
- | The main program initializes a dummy key and a dummy IV; a long message is then encrypted and decrypted. The encryption should automatically include the authentication tag at the end, and the decryption should return an error if the verification of the tag fails. | + | Deschideți fișierul pe care l-ați decriptat la exercițiul anterior și analizați codul. Sunt două funcții care trebuie implementate: ''aes_gcm_encrypt'' și ''aes_gcm_decrypt''. Am pus comentarii în cod care să vă îndrume în implementare. |
- | If you do not change keys and the implementation is ok, the ciphertext you obtain should be equal to our own. Otherwise, some of the tests will fail. | + | Funcția main inițializează o cheie dummy și un IV dummy; un mesaj lung este criptat și apoi decriptat. Mesajul criptat ar trebui să includă automat la finalul ei tag-ul de autentificare, iar decriptarea ar trebui să întoarcă o eroare dacă verificarea tag-ului eșuează. |
+ | Dacă nu schimbați cheile și implementarea este corectă, textul criptat pe care îl obțineți ar trebui să fie același cu al nostru. În caz contrar, unele teste vor pica. | ||
- | Below we have included an example of encryption with RC2 (taken from the OpenSSL man pages). The AES-GCM encryption implementation is quite similar - the authentication tag is automatically appended when finalizing the encryption context. | + | Aveți mai jos inclus un exemplu de criptare cu RC2 (luat din paginile de manual ale OpenSSL). Criptarea AES-GCM este similară ca implementare - tag-ul de autentificare este automat adăugat când finalizăm contextul criptării. |
<code C> | <code C> | ||
Line 196: | Line 193: | ||
<note hint> | <note hint> | ||
- | You may need to change the the LDFLAGS in Makefile: | + | S-ar putea să fie nevoie să schimbați LDFLAGS din Makefile: |
LDFLAGS=-lcrypto -ldl | LDFLAGS=-lcrypto -ldl | ||
</note> | </note> | ||
<note tip> | <note tip> | ||
- | See the open ssl manual [[https://www.openssl.org/docs/man1.1.0/crypto/EVP_aes_256_gcm.html|here]] page for EVP encrypt to see the usage of the EVP functions and an example similar to the one above. | + | Vedeți pagina de criptare EVP din manualul OpenSSL [[https://www.openssl.org/docs/man1.1.1/man3/EVP_aes_256_gcm.html|aici]] pentru informații legate de cum se folosesc funcțiile EVP și un exemplu similar cu cel de mai sus. |
</note> | </note> | ||
+ | </hidden> | ||
+ |