Introduction to fundamentals of cryptography: a case example for UEFI environment

Introduction to fundamentals of cryptography: a case example for UEFI environment

1. Introduction

In a world where digital communication is ubiquitous and information security is an absolute priority, encryption plays a fundamental role in protecting sensitive data from unauthorized access. Another important aspect is the hashing method, which plays a crucial role in verifying data integrity and protecting against fraud.

By understanding the fundamentals and applications of encryption, the computational systems are prepared to protect their data and ensure the security of their communications in an increasingly complex and interconnected digital environment.

This article aims to explore the principles, methods, and applications of cryptography, covering both theoretical and practical aspects, considering an example case in pre-operating system environment, so-called UEFI.

2. What is cryptography?

Cryptography is the process of transforming readable information into ciphertext, that is, to make a text incomprehensible to prevent third parties from having access to sensitive information. Encryption goes far beyond protecting your confidentiality and ensuring integrity and authenticity during the transmission and storage of this data, which are considered pillars of Information Security [1].

An encryption operation involves transforming a plaintext message into encrypted message to ensure its confidentiality. This process begins with the selection of a cryptographic algorithm and the generation of a cryptographic key (See Figure 1). The plaintext message, representing the original content, is then encrypted using the chosen algorithm and key. This encryption process scrambles the plaintext into ciphertext, rendering it unreadable without the corresponding decryption key [2].

The resulting ciphertext appears as a series of seemingly random characters, as shown in Figure 1 at encrypted message block, disguising the original message. Only parties possessing the correct decryption key can reverse the encryption process to recover the original plaintext message [5]. This encryption process plays a crucial role in securing sensitive information, such as personal messages or confidential data, from unauthorized access or interception during communication over networks or storage in databases.

Figure 1

3. Types of Cryptografy

In the encryption operation, several types of encryptions can be addressed. The three main types of encryptions are Symmetric Encryption, Asymmetric Encryption, and Hashing. Each of the types has its own characteristics and specific uses, as well as security levels [2]. In the sequence of the text, they are explained.

a. Symmetric Encryption

This type of encryption uses only a single key (a random value that is used to control the data encryption and decryption process), which is used to encrypt and decrypt the message. It is necessary to share this key securely, as the key for encryption is the same as the key for decryption, as presented in Figure 2.

Figure 2

Symmetric encryption algorithms have two main types, block encryption algorithms that encrypts data in fixed blocks of specific size and stream encryption which are the algorithm that encrypts and decrypt data one element at a time as opposed to block encryption, which encrypts a fixed block of data [2].

i. AES (Advanced Encryption Standard)

At the forefront of symmetric encryption stands AES, a block cipher renowned for its robust security measures. With a fixed block size of 128 bits, AES supports key sizes of 128, 192, or 256 bits [3].

AES encryption employs two modes, ECB (Electronic Codebook) and CBC (Cypher Block Chaining) mode. ECB mode is the simplest encryption method, which the message is divided into blocks and each block is encrypted separately. The disadvantage of this method is that identical blocks of plaintext are encrypted into identical blocks of ciphertext, resulting that it does not hide data patterns. In addition, it does not provide perfect message confidentiality, and is not recommended for use in cryptographic protocols in general [4, 11]. The Figure 3 shows an original image at left and the respective encrypted image as an example using ECB mode.

Figure 3

It can be seen from Figure 3 that parts of the image that are similar are encoded in the same way, confirming that patterns are easy to identify in this encryption method.

On the other hand, in CBC encryption mode, each plaintext block is XORed along with the previous ciphered block before the text is encrypted. In this way, each cipher block is dependent on all the plaintext blocks processed up to this moment. Furthermore, for each message to be unique, even from the same original text, a unique initialization vector must be used in the first block, preferably randomly generated [15]. Repeating the original image presented in Figure 3, the Figure 4 shows the result of applying the CBC encryption method, where it is no longer possible to identify patterns in the encrypted message.

Figure 4?

There is another algorithm for AES encryption, called AES-GCM 256, short for Advanced Encryption Standard with Galois/Counter Mode, which stands as a robust encryption algorithm offering both confidentiality and authentication features. This encryption scheme provides a way to encrypt data securely while also ensuring the integrity and authenticity of the transmitted information.

In the process of authenticated encryption using AES-GCM 256, four key inputs are required: the secret key, initialization vector (IV), also referred as nonce, the plaintext message itself, and optional additional authentication data (AAD). These components work together seamlessly to provide a secure encryption process. One notable aspect of AES-GCM 256 is its fixed requirements for the nonce and the authentication tag. The nonce must be precisely 12 bytes (96 bits) in length, and the authentication tag is fixed at 16 bytes (128 bits). These fixed lengths ensure consistency and reliability in the encryption process [10, 11].

ii. DES (Data Encryption Standard)

DES, a cornerstone cryptographic algorithm, enforces a strict key length of 56 bits, albeit exhibiting vulnerabilities due to its relatively short key size [16].

iii. 3DES (Triple Data Encryption Standard)

3DES, an evolution of DES, fortifies encryption by employing three consecutive DES algorithms with distinct keys, bolstering security against potential vulnerabilities [16].

In summary, symmetric encryption methods like AES, AES-GCM, DES, and 3DES offer powerful tools for safeguarding sensitive information. Understanding their aspects and implementations is essential for constructing robust data security frameworks.

b. Asymmetric Encryption

Asymmetric encryption, unlike symmetric encryption, has two keys, one to encrypt and the other to decrypt the message, which the key for encryption is called the Public Key and the key for decryption is called the Private Key, as shown in Figure 5. This means that the public key can be shared, but the private key must only be kept secret. This type of encryption can be used for authentication, digital signatures, among other documents that may contain sensitive data [8]. For example, to generate a digital signature it is necessary to first generate a fixed-length identifier for the content to be signed and this is done through a hash function. Subsequently, the digital signature is generated using the private key on this identifier and then a signed package is created with the document, signature, and digital certificate of the signatory.

Figure 5

To verify the integrity and authenticity of this document, the recipient will use the public key contained in the digital certificate to decrypt the signature and thus obtain the hash that was signed. With this, the recipient will calculate the hash again and compare it with the received hash and if both matches, it will be proven that it is a valid signature and there has been no change in the document [9].

i. RSA

RSA operates on the principle of utilizing a pair of keys, a public key and a private key. The public key is used to encrypt data, while the private key decrypts it. Derived from two large prime numbers, the keys ensure robust security, as it’s exceedingly challenging to deduce the original primes from the generated key. In the RSA algorithm, the input consists of the public key, generated from the multiplication of two large primes, and the plaintext, which represents the original text to be encrypted. The output, in turn, yields the ciphertext, representing the result of the encryption operation applied to the plaintext [9].

ii. ElGamal

Operating on the discrete logarithm problem, ElGamal encryption is often employed for digital signatures, offering robust security features. Its input parameters include the public key, generated using specific parameters like large prime numbers, a primitive root of, and a randomly chosen secret integer. The plaintext, representing the original text, completes the input [17]. The resulting ciphertext represents the encrypted form of the plaintext message.

iii. Diffie-Hellman

Unlike ElGamal, the Diffie-Hellman algorithm isn’t directly used for message encryption. Instead, it facilitates secure communication, digital signatures, and key exchange over insecure channels. Its input parameters include public keys generated from agreed-upon configuration parameters (and), along with private keys chosen by the sender and recipient. The plaintext, indicative of the original message, serves as another input. The output yields a shared key, which can be utilized for symmetric encryption, ensuring secure communication [18].

iv. ECC (Elliptic Curve Cryptography)

Harnessing the mathematical properties of elliptic curves, ECC offers enhanced security with smaller key sizes compared to traditional methods. Its input parameters define the elliptic curve, including coefficients, a generating point, and the order of the generating point. Additionally, the receiver’s public key, representing a point on the elliptic curve, and the plaintext, means the input. The output includes a shared key, derived from computations involving the sender’s private key and the receiver’s public key, along with the ciphertext, representing the encrypted form of the plaintext message, and potentially a digital signature for message authentication [19].

c. Hashing

This is a technique that does not use keys, it basically converts an input (plaintext or data) into a fixed and unique hash value (hashed text) through a hash function, and any change to the input data will result in a completely different hashed result. This mode is used to ensure the integrity of the sent message and the Figure 6 shows the basic scheme addressed to this method.

Figure 6

The hash values are deterministic, meaning that the same input will always produce the same hash value, and they are designed to be irreversible, making it computationally infeasible to derive the original input from the hash value. The hash function, as shown in Figure 6 is the core component of a hashing algorithm once it defines the rules and operations used to transform the input data into a fixed-size hash value. Hash functions typically include operations like bitwise manipulation, modular arithmetic, and mixing functions to ensure that small changes in the input result in significantly different hash values.

A practical application of hashing is in storing passwords in a database. When a user creates an account on a system, their password is passed through a hash function before being stored in the database. For example, if the user chooses the password “mypassword123”, it will be transformed into a seemingly random string of characters through a hash function. Only the hashed version of that password is then stored in the database.

The different types of hash functions lead to the different types of hashing algorithms as presented below. Each one of these algorithms is described only with simple technical aspects, and for more information, please consider consulting its respective references.

i. SHA-2 (Secure Hash Algorithm 2)

The algorithm SHA-2 comprises a family of several algorithms, including SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224, and SHA-512/256. Ranging from 224 bits (28 bytes) to 512 bits (64 bytes), the varying bit lengths directly correlate with the algorithm’s resistance to cryptographic attacks [20]. The SHA-2 hash function operates with a straightforward input-output structure, which the plaintext message serves as the input, while the output yields a hash digest, a sequence of hexadecimal digits.

ii. SHA-3 (Secure Hash Algorithm 3)

Offering enhanced efficiency and security compared to SHA-2, SHA-3 allows for the variation of both input and output sizes. It offers four output sizes: 224, 256, 384, and 512 bits. This algorithm provides flexibility while maintaining robust security measures [21]. Like SHA-2, SHA-3 operates with a single input and output, which the plaintext message is inputted, and the resulting output is a hash digest represented by a sequence of hexadecimal digits.

iii. MD5 (Message Digest Algorithm 5)

MD5 is known for its fixed output size, a 128-bit hash value, accommodating input messages of arbitrary sizes. Despite its widespread use in the past, MD5 has become susceptible to vulnerabilities and is now considered less secure compared to the modern alternatives. The MD5 function follows a simple input-output pattern [22]. The plaintext message serves as input, while the output yields a hash digest, a sequence of hexadecimal digits.

iv. Scrypt

Scrypt introduces a unique approach by transforming a password and a salt (a random value) into a cryptographic key. This technique enhances security against dictionary attacks and hardware-based threats by incorporating factors such as iteration, block size, and parallelism. Then the Scrypt function boasts multiple inputs, including:

  • Passphrase (input text), the original password, which is usually provided by the user and needs to be protected.
  • Salt, a unique random value that is used to make each key derivation operation unique, even if the same password is used. This is essential to increase security against dictionary attacks.
  • Iteration factor (N), number of iterations that the function must execute. A higher value increases security, but also increases computational cost.
  • Block factor (r), size of the memory block used in the computation. It is important to make hardware-based attacks more difficult.
  • Parallelism factor (p), which determine the parallelism of the function, that is, how many independent operations can be executed simultaneously. This is also a protective measure against hardware attacks.
  • Output key size (dkLen), the length, in bytes, of the derived key that the Scrypt function should generate.

The output of the method is the derived key, which stands for the cryptographic key resulted after applying the Scrypt function with the given inputs. Then, this key is used for authentication, encryption, or other security operations [12, 13].

i. HMAC?SHA3–512

The HMAC SHA3–512, a hash-based message authentication algorithm, utilizes SHA-3–512 as its underlying hash function. As with any MAC, HMAC can be used to simultaneously verify data integrity and the authenticity of a message. Before starting the process, a secret key is used to generate two keys, one for internal use and one for external use and, subsequently, it performs two hash calculation steps. The first step generates an internal hash from the input message and the internal key. In the second step, the final HMAC code is produced from the result of the internal hash and the external key. By incorporating these steps, the algorithm enhances security against length extension attacks. Therefore, the input for HMAC SHA3–512 includes a secret key and the message to be authenticated, whereas the output yields HMAC, the hash-based message authentication code, represented by a sequence of bytes, ensuring the integrity and authenticity of the message based on the provided key [14].

4. UEFI Environment

UEFI is a specification that defines a software interface between the operating system and the platform’s firmware. UEFI is intended to replace the Basic Input/Output System (BIOS) firmware interface present on all IBM PC-compatible personal computers. In practice, most UEFI images provide legacy support for BIOS services, and it can support remote hardware diagnostics and repair of computers even without another operating system installed [6, 7].

UEFI is launched during the system boot process and is responsible for initializing the hardware, configuring the environment for the operating system, and starting the operating system. This occurs shortly after the computer is turned on.

a. Encryption case for UEFI Environment

Currently, when discussing encryption in embedded software such as UEFI, it still remains a relatively unexplored subject. However, the use of cryptography in systems like these is important, particularly when data generated by a diagnosis, for example, may contain sensitive information. Furthermore, in cases where this kind of application may have functionality such that the generated data is transferred to a server and potential interception can occur during the transmission of this data, it can lead to significant issues.

Considering a hardware diagnostics application in UEFI environment, it is required to transfer to a server a set of data composed of execution log files, which is a large volume of information that is desired to protect through cryptography. To apply encryption in this UEFI application, it is possible to use both symmetric and asymmetric encryption, as presented earlier in this article.

Then, the proposal was to use AES-GCM 256 method to encrypt the data once it has a larger key size compared to AES-CBC, which turn it more secure. On the other hand, RSA encryption was used to encrypt the AES-GCM key. The reason for not using only the RSA method is that it has a limitation on the size of the input message to be encrypted, that is, the size of the message cannot be greater than the size of the RSA key. Therefore, a combination of both methods was explored to increase the security level of the cryptography process.

To exemplify the entire encryption process applied to the data generated by an application, a flowchart can be seen in Figure 7.

Figure 7

After starting the encryption process, the first step is to create the input parameters: a single key, the initialization vector (IV) and additional authentication data value (AAD). Once the input parameters of the AES-GCM algorithm are created, move on to encrypting the data that will be protect and sent to a server, in this example the execution logs stored as txt/JSON files.

After data encryption, the RSA method is applied. In this step, the generated AES input vector (Key, IV and AAD) is encrypted by RSA using the public key, which, after being attached to the message encrypted in the previous step, is sent to the server. Therefore, the encryption process ends with the server receiving a completely encrypted message, where the protected data was encrypted by the symmetric AES-GCM method, and the input parameters of the respective method were protected by the asymmetric RSA method.

Therefore, for the server to access the original data, it can simply use the RSA private key to obtain the AES-GCM single key and use it to decrypt the original data. This is an example of a combination different cryptography methods that can be applied to an embedded system that needs to connect to a server and transfer information securely.

5. Conclusion

This article covered the initial fundamentals of encryption, covering the main types and methods used in data protection today. Among the types presented are symmetric and asymmetric algorithms and hashing algorithms. Symmetric encryption, exemplified by algorithms like AES, boasts efficiency and speed, making it ideal for encrypting large volumes of data. However, its reliance on a shared encryption key necessitates robust security measures for key distribution, as compromising the key can lead to the decryption of all encrypted data, posing a significant security risk. On the other hand, asymmetric encryption methods, such as RSA or ECC, provide a secure key exchange and digital signatures without the need for pre-shared keys. This capability is particularly advantageous for secure communication between unknown parties over insecure channels. However, the computational intensity and slower processing speeds of asymmetric encryption may limit its practicality for scenarios requiring real-time data encryption. Concerning the hashing methods, such as SHA-256 or MD5, they stand out as efficiently verifying data integrity, offering a quick and deterministic way to ensure the integrity of data. Nonetheless, they are susceptible to collision attacks, where two different inputs produce the same hash value, potentially compromising data integrity. Moreover, while hashing methods securely store passwords without exposing them in plaintext form, they do not provide encryption or confidentiality, leaving data vulnerable to unauthorized access or disclosure.

In addition, a case was presented in which it is possible to combine different encryption methods to overcome problems such as messages of relevant size that need to be transferred to a server while maintaining a satisfactory level of security. Therefore, it is possible to use a symmetric method that allows the encryption of large volumes of data in combination with an asymmetric method that offers a higher level of security.

In summary, each cryptographic method has its unique strengths and weaknesses, catering to different security requirements and use cases. Understanding these nuances is crucial for selecting the most appropriate cryptographic techniques to ensure robust security measures are in place.

6. Acknowledgement

This research was partially funded by Lenovo, as part of its R&D investment under Brazilian Informatics Law, and by the FIT?—?Flextronics Institute of Technology with all further resources needed to perform this work.

Article written by:

Camila Martins, Software Development Analyst at FIT, Sorocaba, S?o Paulo. Graduated in Computer Engineering, Digital Games Technology and MBA in Project and Business Management from FACENS.

7. References

[1] Introdu??o a criptografia, Aug 29, 2017. Available in: < https://medium.com/@m0blabs/introdu%C3%A7%C3%A3o-a-criptografia-820206eda5a9>. Access at: Jul 20, 2023.

[2] SOUZA, Fernando. Conceitos básicos de criptografia, Mar 11, 2020. Available in: < https://medium.com/prognosys/conceitos-b%C3%A1sicos-de-criptografia-624eb6ec3171>. Access at: Jul 20, 2023.

[3] SOUZA, Fernando. Criptografia simétrica, Apr 3, 2020. Available in: <https://medium.com/prognosys/criptografia-sim%C3%A9trica-6b4271ff697c>. Access at: Jul 20, 2023.

[4] OLIVEIRA, Ronielton Rezende. Criptografia simétrica e assimétrica: os principais algoritmos de cifragem. Available in: <https://uab.ifsul.edu.br/tsiad/conteudo/modulo5/src/biblioteca/1_Leitura_Complementar_Algoritmos_de_Criptografia.pdf.pdf>. Access at: Aug 22, 2023.

[5] O que é uma chave criptográfica?. Available in: < https://www.cloudflare.com/pt-br/learning/ssl/what-is-a-cryptographic-key/>. Access at: Sep 19, 2023.

[6] Unified Extensible Firmware Interface, Jun, 2021. Available in: <https://pt.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface>. Access at: Sep 20, 2023.

[7] O que é UEFI e Como Posso Usá-lo no Windows? [Guia Completo], Mar 20, 2023. Available in: <https://br.easeus.com/diskmanager/o-que-e-uefi.html>. Access at: Sep 20, 2023.

[8] Criptografia Assimétrica: Saiba O Que é, Como Funciona E Vantagens., Oct 20, 2022. Available in: <https://www.bry.com.br/blog/criptografia/>. Access at: Oct 04, 2023.

[9] GODINHO, Rafael. Criptografia: como é aplicada na assinatura digital, Sep 24, 2021. Available in: <https://whom.com.br/blog/criptografia-assimetrica-o-que-como-funciona-e-vantagens/#:~:text=Normalmente%2C%20a%20criptografia%20assim%C3%A9trica%20%C3%A9,chave%20foi%20compartilhada%20s%C3%A3o%20menores.> Access at: Oct 04, 2023.

[10] AES-GCM authenticated encryption, Jan 01, 2023. Available in: <https://www.cryptosys.net/pki/manpki/pki_aesgcmauthencryption.html>. Access at: Nov 06, 2023.

[11] AES?—?Padr?o de criptografia avan?ado: o que é e como funciona, May 13, 2021. Available in: <https://cryptoid.com.br/criptografia/aes-padrao-de-criptografia-avancado-o-que-e-e-como-funciona/>. Access at: Nov 06, 2023.

[12] Scrypt. Available in: <https://www.openssl.org/docs/man1.1.1/man7/scrypt.html>. Access at: Nov 06, 2023.

[13] Scrypt. Available in: <https://pt.wikipedia.org/wiki/Scrypt>. Access at: Nov 06, 2023.

[14] HMAC. Available in: <https://pt.wikipedia.org/wiki/HMAC>. Access at: Nov 06. 2023.

[15] MORAIS, José. Seguran?a da Informa??o?—?Criptografia AES, Nov 08, 2017. Available in: < https://embarcados.com.br/criptografia-aes/>. Access at: Jan 22, 2024.

[16] SOUTO, Rodrigo Fontes; RORIZ, Vasco; LIMA, Elias Bechepeche Feliciano de. Implementa??o do 3DES em Sistemas Embarcados para Terminais de Ponto de Venda. Available in: < https://www.aedb.br/seget/arquivos/artigos07/1131_DES_Seget.pdf>. Access at: Jan 22, 2024.

[17] JNR, Paul K. Arhin. A Comparative Study of RSA and ELGAMAL Cryptosystems, May 29, 2023. Available in: <https://www.carijournals.org/journals/index.php/IJCE/article/download/1291/1490>. Access at: Jan 22, 2024.

[18] Troca de chaves de Diffie–Hellman. Available in: <https://pt.wikipedia.org/wiki/Troca_de_chaves_de_Diffie%E2%80%93Hellman>. Access at: Jan 22, 2024.

[19] MADEIRA, Fernando Lima. Aplica??o Prática de Criptografia de Curvas Elípticas (ECC), 2021. Available in: <https://bdm.unb.br/bitstream/10483/31187/1/2021_FernandoLimaMadeira_tcc.pdf>. Access at: Jan 22, 2024.

[20] SHA2. Available in: <https://pt.frwiki.wiki/wiki/SHA-2>. Access at: Jan 22, 2024.

[21] SHA3. Available in: <https://pt.frwiki.wiki/wiki/SHA-3>. Access at: Jan 22, 2024.

[22] MD5. Available in: <https://pt.frwiki.wiki/wiki/MD5>. Access at: Jan 22, 2024.


Sidarta Martins

Consultant in Synergy Marketing and Human Resourses

3 个月

An important text for both, people who want to know about the subject and people that are in the field and need to improve their knowledge. Congratulations to the Author and to FIT. Professor and Brasilian Poet Sidarta Martins.

回复
Rafael M.

Software Security Architect / Cyber Security Researcher

9 个月

Trabalho incrível Camila Martins. Parabéns!

Marcelo Scandiuzzi

Software Development Coordinator at FIT | PSM I | Agile Product Management

9 个月

Parabéns pelo artigo Camila! Muito bom????????

Felipe de Oliveira Marchioli

Analista de Sistemas III (L4) na GFT

9 个月

Parabéns Cá! ótimo artigo! ??

Bruno Oliveira

Analista de Desenvolvimento de Software II na FIT - Instituto de Tecnologia

9 个月

Muito boom, Camila Martins. Parabéns pelo artigo

要查看或添加评论,请登录

FIT - Instituto de Tecnologia的更多文章

社区洞察

其他会员也浏览了