# Analysis of Cryptographic Algorithms to Improve Cybersecurity in the Industrial Electrical Sector
## 4 Digital Security Methodologies outside Those Proposed by IEC62351  
ChaCha20 is a stream cipher used to ensure confidentiality, while Poly1305 is a MAC algorithm to ensure the integrity and authenticity of messages. Both algorithms can be used together to form an AEAD (Authenticated Encryption with Associated Data), which verifies both the integrity and authenticity of the ciphertext, as well as the integrity of some extra information. ChaCha20 is an ARX (add, rotate, mixing columns) of the matrix or smart division of polynomials. AES relies on the fact that modern CPUs have Galois field arithmetic built in as real instructions, while ChaCha20 does not need any of that, which makes it especially useful for low-end electronic devices or those that need great speed [25]. On the other hand, the Poly1305 algorithm is used for the integrity and authenticity of the message. Poly1305 takes a 256-bit key, a message of arbitrary length, and generates a 128-bit (16-byte) output known as a TAG or MAC. ChaCha20 and Poly1305 are defined in RFC8439 [26]. The combination of both protocols is part of the new TLS 1.3 version, one of the strongest competitors to AES-GCM [27]. RFC8439 provides the series of steps to follow the Poly1305 algorithm, which is detailed in Algorithm 1. As mentioned above, it is possible to build an AEAD algorithm using ChaCha20 and Poly1305 together, which is why AEAD was given greater emphasis than the use of ChaCha20 and Poly1305 separately, as will be seen below. The algorithm, to perform the Poly1305 MAC TAG, uses the additional text to be authenticated (AAD) and the ciphertext. The AEAD algorithm encrypts the APDU using ChaCha20, and then this text and the additional text are used to calculate the MAC value using Poly1305. To calculate the Poly1305 MAC, a key is generated using a ChaCha20 block with the 32-bit counter block being zero. This MAC value is appended to the \"extension\" field of the secure GOOSE frame. The length of the \"extension\" field is reflected in the second byte of the Reserved1 field. The order in which to perform this is detailed in Algorithm 2. Figure 4 shows the process graphically. \begin{table}
\begin{tabular}{l l l l} \hline \hline
**MAC Algorithm** & **Hash Function** & **MAC Value Size in Bytes** \\ \hline HMAC-SHA256-80 & SHA256 & 10 \\ HMAC-SHA256-256 & SHA256 & 16 \\ HMAC-SHA256-256 & SHA256 & 32 \\ AES-GMAC-64 & 8 \\ AES-GMAC-128 & 16 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: MAC algorithms proposed by IEC62351-6:2020. \begin{table}
\begin{tabular}{l l l l l l} \hline \hline
**Algorithm** & \begin{tabular}{l} **Total GOOSE Message** \\ **Size (bytes)** \\ \end{tabular} & \begin{tabular}{l} **Publisher Computing** \\ **Time (ms)** \\ \end{tabular} & \begin{tabular}{l} **Subscriber Computing** \\ **Time (ms)** \\ \end{tabular} & \
\begin{tabular}{l} **Communication** \\ **Delay (ms)** \\ \end{tabular} &
\begin{tabular}{l} **End-to-End Delay (ms)** \\ \end{tabular} \\ \hline Without security & 159 & 0 & 0 & 0.0664 & 0.0664 \\ HMAC-SHA256-80 & 193 & 0.0127 & 0.0141 & 0.0709 & 0.0977 \\ HMAC-SHA256-128 & 199 & 0.0127 & 0.0142 & 0.0722 & 0.0991 \\ HMAC256-256 & 215 & 0.0127 & 0.0143 & 0.0757 & 0.1027 \\ AES-GMAC-64 & 205 & 0.0054 & 0.0066 & 0.0730 & 0.0850 \\ AES-GMAC-128 & 213 & 0.0055 & 0.0069 & 0.0749 & 0.0873 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Times in secure GOOSE messaging exchanges under the different MAC algorithms recommended by IEC62351-6:2020. ```
1. Split the key in two. 2. Perform the \"clamp\" process to the \"r\" part of the 256-bit key. 3. Set the prime number \"P\" to (2130-5). 4. Set the \"accumulator\" variable (Acc) to zero. 5. Divide the message into 16-byte blocks, the last block will most likely be shorter. 6. Read the block as a number in little-endian order. 7. Add a bit after the number of octets, for 16-byte blocks, this would be adding 2128, for the smallest block, adding some power divisible by 8, for example, 2120, 2112 up to 28. 8.