Differences

This shows you the differences between two versions of the page.

Link to this comparison view

ic:labs:09 [2020/12/01 15:17]
philip.dumitru [Exercise 3]
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 =====
  
-==== Exercise 1 ====+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.
  
-In this exercise we'll use the command line to compute an HMAC, with SHA-1 as the hashing algorithm.+<​hidden>​
  
-Recall from the lecture that for HMAC to be secure, we need to sample a random key $k \gets \mathcal{K}$.+==== Exercițiul 1 ====
  
-We can generate random bytes using ''​openssl rand''​. To compute HMACscheck the documentation for ''​openssl dgst''​.+În acest exercițiu vom folosi CLI pentru a calcula un HMACcu SHA-1 pentru algoritmul de hash.
  
-For this exercise, use OpenSSL commands to: +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}$.
-  ​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.+
  
 +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''​.
  
-==== Exercise 2 ====+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.
  
-In this exercise you will implement the Birthday attack on SHA-1 from the previous lab using OpenSSL. The goal is to obtain a collision in the first four bytes of the hash. 
  
-In contrast to previous labs, this time we'll use C. You can implement the attack from scratch, or start from our {{:​sasc:​laboratoare:​birthday.tar.gz|archive here}}.+==== Exercițiul 2 ====
  
-To compute ​digestyou might find the code below useful:+Înainte de începe următorul exercițiudescărcați {{:ic:​laboratoare:​aesgcm.zip|arhiva laboratorului de aici}}.
  
-<code C> +Arhiva conține codul sursă pentru Exercițiul 3dar din păcate este criptat. Aveți noroc că am uitat să scoatem fișierul cu parola din arhivă.
-    SHA_CTX context; +
-    SHA1_Init(&​context);​ +
-    SHA1_Update(&​contextbuffer, length); +
-    SHA1_Final(md,​ &​context);​ /* md must point to at least 20 bytes of valid memory */ +
-</​code>​+
  
-<note important>​ +Folosiți comenzi ​''​openssl'' ​pentru a decripta fișierul cu codul sursă.
-You may compile and install OpenSSL from sources. +
- +
-Download the library from [[https://​www.openssl.org/​source/​openssl-1.1.1d.tar.gz]],​ and unpack it. +
- +
-Open the unpacked folder from bash, and run the following commands: +
-<code bash> +
-$ ./config --prefix=your_working_dir --openssldir=your_working_dir/​openssl +
-$ make +
-$ make install_sw +
-</​code>​ +
- +
-To fix the makefile using the new paths, change the variables at the start with the ones below: +
-<code makefile>​ +
-LDFLAGS=-Lyour_working_dir/​lib -lcrypto +
-CFLAGS=-Wall -g -Iyour_working_dir/​include +
-</​code>​ +
-</​note>​ +
- +
- +
- +
-==== Exercise 2 ==== +
- +
-Before you start solving the exercises below, download the {{:​ic:​laboratoare:​aesgcm.zip|lab archive from here}}. +
- +
-The archive contains the source code for Exercise 4, but sadly it is encrypted. Luckily, we forgot to remove the password file from the archive. +
- +
-Use ''​openssl'' ​commands to decrypt the source file.+
  
 <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 ​====+==== Exercise ​====
  
-<​hidden>​ 
  
 <note hint> <note hint>
-The problem has been fixedso 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 176: 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-128-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 ​dummy key and a dummy IV; a long message is then encrypted and decryptedThe 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 ownOtherwisesome of the tests will fail.+Funcția main inițializează o cheie dummy și un IV dummy; un mesaj lung este criptat și apoi decriptatMesajul criptat ar trebui să includă automat la finalul ei tag-ul de autentificareiar 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 229: 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>​
 +
ic/labs/09.1606828668.txt.gz · Last modified: 2020/12/01 15:17 by philip.dumitru
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0