MCPcopy Create free account
hub / github.com/Hydr8gon/3Beans / cryptBlock

Method cryptBlock

src/core/convert/aes.cpp:117–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115}
116
117template <bool decrypt> void Aes::cryptBlock(uint32_t *src, uint32_t *dst) {
118 // Set initial values for encryption/decryption
119 uint32_t y0 = rKey[0] ^ src[0];
120 uint32_t y1 = rKey[1] ^ src[1];
121 uint32_t y2 = rKey[2] ^ src[2];
122 uint32_t y3 = rKey[3] ^ src[3];
123
124 // Encrypt/decrypt a block of data
125 for (int i = 4; i < 40; i += 4) {
126 uint32_t x0 = rKey[i + 0] ^ (decrypt ? scatter32(rTable, y3, y2, y1, y0) : scatter32(fTable, y1, y2, y3, y0));
127 uint32_t x1 = rKey[i + 1] ^ (decrypt ? scatter32(rTable, y0, y3, y2, y1) : scatter32(fTable, y2, y3, y0, y1));
128 uint32_t x2 = rKey[i + 2] ^ (decrypt ? scatter32(rTable, y1, y0, y3, y2) : scatter32(fTable, y3, y0, y1, y2));
129 uint32_t x3 = rKey[i + 3] ^ (decrypt ? scatter32(rTable, y2, y1, y0, y3) : scatter32(fTable, y0, y1, y2, y3));
130 y0 = x0; y1 = x1; y2 = x2; y3 = x3;
131 }
132
133 // Output the final encrypted/decrypted values
134 dst[0] = rKey[40] ^ (decrypt ? scatter8(rsBox, y3, y2, y1, y0) : scatter8(fsBox, y1, y2, y3, y0));
135 dst[1] = rKey[41] ^ (decrypt ? scatter8(rsBox, y0, y3, y2, y1) : scatter8(fsBox, y2, y3, y0, y1));
136 dst[2] = rKey[42] ^ (decrypt ? scatter8(rsBox, y1, y0, y3, y2) : scatter8(fsBox, y3, y0, y1, y2));
137 dst[3] = rKey[43] ^ (decrypt ? scatter8(rsBox, y2, y1, y0, y3) : scatter8(fsBox, y0, y1, y2, y3));
138}
139
140void Aes::autoBoot() {
141 // Enable the auto-boot hack for the next 2 processed icons

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected