{"id":21766358,"url":"https://github.com/drilonaliu/parallel-s_aes-ccm-xts","last_synced_at":"2025-03-21T05:24:17.659Z","repository":{"id":254494979,"uuid":"846692758","full_name":"drilonaliu/Parallel-S_AES-CCM-XTS","owner":"drilonaliu","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-26T18:28:33.000Z","size":1069,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T02:18:27.406Z","etag":null,"topics":["aes","cryptography","cuda","gpu","parallel-programming","saes"],"latest_commit_sha":null,"homepage":"","language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drilonaliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-23T18:44:34.000Z","updated_at":"2024-10-10T22:13:43.000Z","dependencies_parsed_at":"2024-08-23T21:15:25.975Z","dependency_job_id":"17d9f5b5-c981-452e-a1f1-f6074fcce329","html_url":"https://github.com/drilonaliu/Parallel-S_AES-CCM-XTS","commit_stats":null,"previous_names":["drilonaliu/parallel-s_aes-ccm-xts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-S_AES-CCM-XTS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-S_AES-CCM-XTS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-S_AES-CCM-XTS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-S_AES-CCM-XTS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drilonaliu","download_url":"https://codeload.github.com/drilonaliu/Parallel-S_AES-CCM-XTS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244741988,"owners_count":20502387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aes","cryptography","cuda","gpu","parallel-programming","saes"],"created_at":"2024-11-26T13:16:56.158Z","updated_at":"2025-03-21T05:24:17.635Z","avatar_url":"https://github.com/drilonaliu.png","language":"Cuda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parallel-S_AES-Implementations\n \nSimplified AES (S-AES) works the same way as the AES algorithm, with the difference being that S-AES uses 16 bit key for encryption instead of AES that normally uses 256. To achieve parallelization, S-AES uses 16 threads for parallel encryption/decryption of 16 bits. The text is converted to binary from CPU and then this array of bits is send to GPU for encryption. In addition to parallelization of S-AES, two modes that use SAES for encryption/decryption are also parallelized; CCM and XTS.\n\n## CCM \n\nCCM - Counter with Cipher-Block Chaining Message Authentication is an authenticated encryption, which means that simultaneosly protects confidentiallity and authenticity (integrety) of communications. \n\nThe algorithm for CCM encryption is given below.\n\n\u003cdiv\u003e\n  \u003cp\u003e\n    \u003cimg src=\"images/CCM_1.png\"\u003e\n    \u003cimg src=\"images/CCM_2.png\"\u003e\n     \u003cimg src=\"images/CCM_3.png\"\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## XTS\n \nThe XTS-AES is a block cipher mode of operation, approved by NIST in 2010. The XTS-AES algorithm uses the AES algorithm twice and uses two keys. The following parametres are associated with the algorithm.\n * Key - 256 or 512 bit XTS-AES key; this is parsed as a concatination of two fields of equal size Key1 and Key2, such that Key = Key1 || Key2. For SAES Key has a length of 32 bits, Key1 and Key2 being both 16 bits.\n * Pj - The jth block of the plaintext. All blocks except possibly the final block have a length of 128 bits (for SAES 16 bits). A plaintext data unit, typically a disk sector, conssits of the sequence P1,P2,,...Pm.\n * Cj - The jth block of cipher text. All blocks except possibly the final block have a length of 128 bits (for -AES 16 bits).\n * j - The sequential number of the 128-bit block inside the data unit.\n * i - The value of the 128-bit tweak. Each data unit (sector) is assigned a tweak value that is a nonnegative integer. The tweak values are assigned consecuitevely, starting from an arbritary nonnegative integer.\n * a - A primitive element of GF(2^128) that corresponds to the polynomial x ( 0000...10). (for S-AES we have GF(2^16).\n * a^j - a multiplied by itself j times, in GF(2^128) (for S-AES, GF*2^16).\n\nThe XTS-AES operation on Single block is given on the scheme below. \n\n\u003cdiv\u003e\n  \u003cp\u003e\n    \u003cimg src=\"images/XTS_1.png\"\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\nThe full XTS-AES mode is given with the scheme below. \n\n\u003cdiv\u003e\n  \u003cp\u003e\n    \u003cimg src=\"images/XTS_2.png\"\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## Simplified AES\n\nSimplified AES algorithm, has as input the block of length 16 bits, the key\n16-bit length as well as the 16-bit block output. The algorithm has the actions SBOX, ShiftRows,\nMixColums, AddRoundKey and their inverses InvSBOX, InvShiftRows, InvMixColums (\nanalogous to the AES algorithm).\n\n### Encryption \n\nIt has three rounds, where two firs rounds are identical and the third round does not have MixColoumns. Let $P$ be plain text and $K_0$ be the key.  \n\n$$ \nA =\n\\begin{vmatrix}\nA_0 \u0026 A_1 \\\\\nA_2 \u0026 A_3  \\\\\n\\end{vmatrix}\n$$\n\n$$ \nK_0 =\n\\begin{vmatrix}\nK_0 \u0026 K_1 \\\\\nK_2 \u0026 K_3  \\\\\n\\end{vmatrix}\n$$\n\n, where $A_i$ and $K_j$ are 4 bits in a hexadecimal form so $A_i,k_j \\in \\set {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}$\n\n$$ \nP \\oplus{K_0 =\n\\begin{vmatrix}\nA_0 \u0026 A_1 \\\\\nA_2 \u0026 A_3  \\\\\n\\end{vmatrix}}\n\\oplus{\n\\begin{vmatrix}\nK_0 \u0026 K_1 \\\\\nK_2 \u0026 K_3  \\\\\n\\end{vmatrix}} =\n\\begin{vmatrix}\nB_0 \u0026 B_1 \\\\\nB_2 \u0026 B_3  \\\\\n\\end{vmatrix} = \nB\n$$\n\nThen B enters in the below structure (Three rounds). First SBOX substitution is made, given with the\n\n$$\nSBOX = \n\\begin{vmatrix}\n6_{16} \u0026 B_{16} \u0026 0_{16} \u0026 4_{16} \\\\\n7_{16} \u0026 E_{16} \u0026 2_{16} \u0026 F_{16} \\\\\n9_{16} \u0026 8_{16} \u0026 A_{16} \u0026 C_{16} \\\\\n3_{16} \u0026 1_{16} \u0026 5_{16} \u0026 D_{16} \\\\\n\\end{vmatrix}\n$$\n\nThis SBOX is built within the Galois Field $GF(2^4)$ with the irreducible polynom $x^4+x+1$. The substitution is made such that the first two bits of $B_i$ tell the row and the last two bits indicate the coloumn of the SBOX. Then $B_i$ gets subsituted with the SBOX value where the coloumn and the row intersect. \n\n$$\nSBOX(\n\\begin{vmatrix}\nB_0 \u0026 B_2 \\\\\nB_1 \u0026 B_3  \\\\\n\\end{vmatrix}) =\n\\begin{vmatrix}\nC_0 \u0026 C_1 \\\\\nC_2 \u0026 C_3 \\\\\n\\end{vmatrix}\n$$\n \n$$\nShiftRows(\n\\begin{vmatrix}\nC_0 \u0026 C_2 \\\\\nB_1 \u0026 C_3  \\\\\n\\end{vmatrix}) =\n\\begin{vmatrix}\nC_0 \u0026 C_2 \\\\\nC_3 \u0026 C_1 \\\\\n\\end{vmatrix}\n$$\n\nThen comes the MixColoumns operation, where the multiplication with Maximal Distance Separabile matrix) and the result from ShiftRows operation. The MDS matrix for MixColoumnns is \n\n$$\n\\begin{vmatrix} \n1_{16} \u0026 1_{16} \\\\\n1_{16} \u0026 2_{16} \\\\\n\\end {vmatrix}\n\\begin{vmatrix} \nC_{0} \u0026 C_{2} \\\\\nC_{3} \u0026 C_{1} \\\\\n\\end {vmatrix} = \n\\begin{vmatrix} \n1_{16} *C_0+1_{16}*C_3  \u0026 1_{16} *C_2+1_{16}*C_1 \\\\\n1_{16} *C_0+2_{16}*C_3  \u0026 1_{16} *C_2+2_{16}*C_1 \\\\ \n\\end {vmatrix} =\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_1 \u0026 D_3 \\\\\n\\end{vmatrix}\n$$\n\nwhere multiplication and addition is performed within the Galuois Field $GF(2^4)/x^4+x+1$\n\n\nIn AddRoundKey, the obtained matrix XOR-s with the KEY from the first round $K_1$ which is generated(similiarly with $K_2$ and $K_3$).\n\n$$\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_1 \u0026 D_3 \\\\\n\\end{vmatrix}\n\\oplus{K_1}=\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_1 \u0026 D_3 \\\\\n\\end{vmatrix}\n\\oplus{\\begin{vmatrix}\nk_0 \u0026 k_2 \\\\\nk_1 \u0026 k_3 \\\\\n\\end{vmatrix}} =\n\\begin{vmatrix}\nE_0 \u0026 E_2 \\\\\nE_1 \u0026 E_3 \\\\\n\\end{vmatrix}\n$$\n\nThis matrix goes in again in the second round with the same repetition of operations and then again in round 3.\n\nBelow is given the encryption scheme for simplified AES.\n\n![sAES scheme](https://user-images.githubusercontent.com/84543584/201967408-6d6579d6-f09d-4faf-bcfc-4a5e94baa189.png)\n\n## Decryption\n\nIt has three rounds, where the first round does not have InvMixColoumns and two last rounds are identical(second and the third round).\n\nGiven the encrypted text $C$ and generated Key $K_3$ where $A_i$ and $k_j$ are each 4 bit in a hexadecimal form so $A_i, k_j \\in{0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}$.\n\n$$ \nC = \n\\begin{vmatrix}\nA_0 \u0026 A_2 \\\\\nA_1 \u0026 A_3 \\\\\n\\end{vmatrix} \n$$\n\n$$ \nK_3 = \n\\begin{vmatrix}\nk_{12} \u0026 k_{14} \\\\\nk_{13} \u0026 k_{15} \\\\\n\\end{vmatrix} \n$$\n\nIn the first round the first operation is AddRound Key, so it is calculated\n\n$$\nP \\oplus{K_3} = \n\\begin{vmatrix}\nA_0 \u0026 A_2 \\\\\nA_1 \u0026 A_3 \\\\\n\\end{vmatrix}\n\\oplus{\n\\begin{vmatrix}\nk_{12} \u0026 k_{14} \\\\\nk_{13} \u0026 k_{15} \\\\\n\\end{vmatrix}} =\n\\begin{vmatrix}\nA_0 \\oplus {k_{12}} \u0026 A_2 \\oplus {k_{14}} \\\\\nA_1 \\oplus {k_{13}} \u0026 A_3 \\oplus {k_{15}} \\\\\n\\end{vmatrix} = \n\\begin{vmatrix}\nB_0 \u0026 B_2 \\\\\nB_1 \u0026 B_3 \\\\\n\\end{vmatrix}\n$$\n\nAfter AddRoundKey, comes InvShiftRows, where the second row is shifted right for four bits.\n\n$$\nInvShiftRows(\n\\begin{vmatrix}\nB_0 \u0026 B_2 \\\\\nB_1 \u0026 B_3 \\\\\n\\end{vmatrix}) =\n\\begin{vmatrix}\nB_0 \u0026 B_2 \\\\\nB_3 \u0026 B_1 \\\\\n\\end{vmatrix}\n$$\n\nThen the substitution is done with the InvSBOX given with the matrix\\table:\n\n$$\nInvSBOX = \n\\begin{vmatrix}\n2_{16} \u0026 D_{16} \u0026 6_{16} \u0026 C_{16} \\\\\n3_{16} \u0026 E_{16} \u0026 0_{16} \u0026 4_{16} \\\\\n9_{16} \u0026 8_{16} \u0026 A_{16} \u0026 1_{16} \\\\\nB_{16} \u0026 F_{16} \u0026 5_{16} \u0026 7_{16} \\\\\n\\end{vmatrix}\n$$\n\nThis InvSBOX is built within the Galois Field $GF(2^16)$ with the irreducible polynomial $x^4+x+1$. The substitution is done in such way that the first two bits of $B_i$ represent the row of the InvSBOX-it and the last two bits represent the coloumn of the InvSBOX. Then $B_i$ gets subsituted with the SBOX value where the row and the coloumn intersect. \n\n$$\nInvSBOX(\n\\begin{vmatrix}\nB_0 \u0026 B_2 \\\\\nB_3 \u0026 B_1 \\\\\n\\end{vmatrix}) =\n\\begin{vmatrix}\nC_0 \u0026 C_2 \\\\\nC_1 \u0026 C_3 \\\\\n\\end{vmatrix}\n$$\n\nAfter InvSBOX the first round ends and then the two last rounds begin. \n\nIn the second round, AddRoundKey is performed first, where the obtained value  XOR-s the second round key $K_2$ which is also generated just like ($K_1$ and $K_0$).\n\n$$\n\\begin{vmatrix}\nC_0 \u0026 C_2 \\\\ \nC_1 \u0026 C_3 \\\\\n\\end{vmatrix}\n\\oplus{K_2} =\n\\begin{vmatrix}\nC_0 \u0026 C_2 \\\\ \nC_1 \u0026 C_3 \\\\\n\\end{vmatrix}\n\\oplus{\n\\begin{vmatrix}\nk_8 \u0026 k_{10} \\\\ \nk_9 \u0026 k_{11} \\\\\n\\end{vmatrix}} =\n\\begin{vmatrix}\nT_0 \u0026 T_2 \\\\\nT_1 \u0026 T_3 \\\\\n\\end{vmatrix}\n$$\n\nThen comes the MixColoumns operation, where the multiplication with Maximal Distance Separabile matrix) and the result from InvShiftRows operation. The MDS matrix for InvMixColoumnns is \n\n$$\n\\begin{vmatrix} \nF_{16} \u0026 E_{16} \\\\\nE_{16} \u0026 E_{16} \\\\\n\\end {vmatrix}\n\\begin{vmatrix} \nT_{0} \u0026 T_{2} \\\\\nT_{3} \u0026 T_{1} \\\\\n\\end {vmatrix} = \n\\begin{vmatrix} \nF_{16} *T_0+E_{16}*T_3  \u0026 F_{16} *T_2+E_{16}*T_1 \\\\\nE_{16} *T_0+E_{16}*T_3  \u0026 E_{16} *T_2+E_{16}*T_1 \\\\ \n\\end {vmatrix} =\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_1 \u0026 D_3 \\\\\n\\end{vmatrix}\n$$\n\nwhere multiplication and addition is done within Galois Field $GF(2^16)/x^4+x+1$.\n\nThen after InvMixColoumns comes InvShiftRows, where the second row is shifted right for four bits. \n\n$$\nInvShiftRows(\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_1 \u0026 D_3 \\\\\n\\end{vmatrix}) =  \n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_3 \u0026 D_1 \\\\\n\\end{vmatrix})\n$$\n\nThen the substitution happens with the InvSBOX(inverse of SBOX)\n\n$$\nInvShiftRows(\n\\begin{vmatrix}\nD_0 \u0026 D_2 \\\\\nD_3 \u0026 D_1 \\\\\n\\end{vmatrix}) =  \n\\begin{vmatrix}\nP_0 \u0026 P_2 \\\\\nP_1 \u0026 P_3 \\\\\n\\end{vmatrix})\n$$\n\nThis matrix goes back again in the third round with the repetition of the operations and finally in the end it XOR-s with the key $K_0$. \n\n$$\nR \\oplus{K_0} = \n\\begin{vmatrix}\nR_0 \u0026 R_2 \\\\ \nR_1 \u0026 R_3 \\\\\n\\end{vmatrix}\n\\oplus{\n\\begin{vmatrix}\nk_0 \u0026 k_2 \\\\ \nk_1 \u0026 k_3 \\\\\n\\end{vmatrix}}= \n\\begin{vmatrix}\nR_0 \\oplus {k_{0}} \u0026 R_2 \\oplus {k_{2}} \\\\\nR_1 \\oplus {k_{1}} \u0026 R_3 \\oplus {k_{3}} \\\\\n\\end{vmatrix} =\n\\begin{vmatrix}\nL_0 \u0026 L_2 \\\\\nL_1 \u0026 L_3 \\\\\n\\end{vmatrix}\n$$\n\n\nBelow is given the Simplified AES decryption scheme: \n![decryption SAES](https://user-images.githubusercontent.com/84543584/201981715-eab3a744-5803-4a85-ac3f-84cfbe7a0ca2.png)\n\n## Key round generation \n\nThree keys are generated for both encryption and decryption for SAES. Below is given the scheme: \n\n![keyAES](https://user-images.githubusercontent.com/84543584/201982414-84b63d2e-3915-44a8-ae1d-1db0b336dc62.png)\n\n## References \n\nWilliam Stallings - Cryptograph and Network Security, Principles and Practice\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-s_aes-ccm-xts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrilonaliu%2Fparallel-s_aes-ccm-xts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-s_aes-ccm-xts/lists"}