summaryrefslogtreecommitdiff
path: root/lib/rijndael-alg-fst.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2009-12-10 20:28:30 +0100
committerBruno Haible <bruno@clisp.org>2009-12-10 20:28:30 +0100
commit441aa3044f43e5572f58c354f01e6bc070acd5c7 (patch)
treebef236e8058dd3469da28ffcd5a6a287222a4c50 /lib/rijndael-alg-fst.c
parent039ae97b8ae35a2446c5d62d72b21689c97da7e2 (diff)
downloadgnulib-441aa3044f43e5572f58c354f01e6bc070acd5c7.tar.gz
Use spaces for indentation, not tabs.
Diffstat (limited to 'lib/rijndael-alg-fst.c')
-rw-r--r--lib/rijndael-alg-fst.c284
1 files changed, 142 insertions, 142 deletions
diff --git a/lib/rijndael-alg-fst.c b/lib/rijndael-alg-fst.c
index dcd812c44e..c00528b361 100644
--- a/lib/rijndael-alg-fst.c
+++ b/lib/rijndael-alg-fst.c
@@ -737,23 +737,23 @@ static const uint32_t rcon[] = {
};
#define GETU32(pt) (((uint32_t)((pt)[0] & 0xFF) << 24) ^ \
- ((uint32_t)((pt)[1] & 0xFF) << 16) ^ \
- ((uint32_t)((pt)[2] & 0xFF) << 8) ^ \
- ((uint32_t)((pt)[3] & 0xFF)))
-#define PUTU32(ct, st) { \
- (ct)[0] = (char)((st) >> 24); \
- (ct)[1] = (char)((st) >> 16); \
- (ct)[2] = (char)((st) >> 8); \
+ ((uint32_t)((pt)[1] & 0xFF) << 16) ^ \
+ ((uint32_t)((pt)[2] & 0xFF) << 8) ^ \
+ ((uint32_t)((pt)[3] & 0xFF)))
+#define PUTU32(ct, st) { \
+ (ct)[0] = (char)((st) >> 24); \
+ (ct)[1] = (char)((st) >> 16); \
+ (ct)[2] = (char)((st) >> 8); \
(ct)[3] = (char)(st); }
/**
* Expand the cipher key into the encryption key schedule.
*
- * @return the number of rounds for the given cipher key size.
+ * @return the number of rounds for the given cipher key size.
*/
int
rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits)
+ const char cipherKey[], size_t keyBits)
{
size_t i = 0;
uint32_t temp;
@@ -765,78 +765,78 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
if (keyBits == 128)
{
for (;;)
- {
- temp = rk[3];
- rk[4] = rk[0] ^
- (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
- (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
- (Te4[(temp) & 0xff] & 0x0000ff00) ^
- (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
- rk[5] = rk[1] ^ rk[4];
- rk[6] = rk[2] ^ rk[5];
- rk[7] = rk[3] ^ rk[6];
- if (++i == 10)
- {
- return 10;
- }
- rk += 4;
- }
+ {
+ temp = rk[3];
+ rk[4] = rk[0] ^
+ (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
+ (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
+ (Te4[(temp) & 0xff] & 0x0000ff00) ^
+ (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
+ rk[5] = rk[1] ^ rk[4];
+ rk[6] = rk[2] ^ rk[5];
+ rk[7] = rk[3] ^ rk[6];
+ if (++i == 10)
+ {
+ return 10;
+ }
+ rk += 4;
+ }
}
rk[4] = GETU32 (cipherKey + 16);
rk[5] = GETU32 (cipherKey + 20);
if (keyBits == 192)
{
for (;;)
- {
- temp = rk[5];
- rk[6] = rk[0] ^
- (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
- (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
- (Te4[(temp) & 0xff] & 0x0000ff00) ^
- (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
- rk[7] = rk[1] ^ rk[6];
- rk[8] = rk[2] ^ rk[7];
- rk[9] = rk[3] ^ rk[8];
- if (++i == 8)
- {
- return 12;
- }
- rk[10] = rk[4] ^ rk[9];
- rk[11] = rk[5] ^ rk[10];
- rk += 6;
- }
+ {
+ temp = rk[5];
+ rk[6] = rk[0] ^
+ (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
+ (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
+ (Te4[(temp) & 0xff] & 0x0000ff00) ^
+ (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
+ rk[7] = rk[1] ^ rk[6];
+ rk[8] = rk[2] ^ rk[7];
+ rk[9] = rk[3] ^ rk[8];
+ if (++i == 8)
+ {
+ return 12;
+ }
+ rk[10] = rk[4] ^ rk[9];
+ rk[11] = rk[5] ^ rk[10];
+ rk += 6;
+ }
}
rk[6] = GETU32 (cipherKey + 24);
rk[7] = GETU32 (cipherKey + 28);
if (keyBits == 256)
{
for (;;)
- {
- temp = rk[7];
- rk[8] = rk[0] ^
- (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
- (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
- (Te4[(temp) & 0xff] & 0x0000ff00) ^
- (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
- rk[9] = rk[1] ^ rk[8];
- rk[10] = rk[2] ^ rk[9];
- rk[11] = rk[3] ^ rk[10];
- if (++i == 7)
- {
- return 14;
- }
- temp = rk[11];
- rk[12] = rk[4] ^
- (Te4[(temp >> 24)] & 0xff000000) ^
- (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
- (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
- (Te4[(temp) & 0xff] & 0x000000ff);
- rk[13] = rk[5] ^ rk[12];
- rk[14] = rk[6] ^ rk[13];
- rk[15] = rk[7] ^ rk[14];
+ {
+ temp = rk[7];
+ rk[8] = rk[0] ^
+ (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
+ (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
+ (Te4[(temp) & 0xff] & 0x0000ff00) ^
+ (Te4[(temp >> 24)] & 0x000000ff) ^ rcon[i];
+ rk[9] = rk[1] ^ rk[8];
+ rk[10] = rk[2] ^ rk[9];
+ rk[11] = rk[3] ^ rk[10];
+ if (++i == 7)
+ {
+ return 14;
+ }
+ temp = rk[11];
+ rk[12] = rk[4] ^
+ (Te4[(temp >> 24)] & 0xff000000) ^
+ (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
+ (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
+ (Te4[(temp) & 0xff] & 0x000000ff);
+ rk[13] = rk[5] ^ rk[12];
+ rk[14] = rk[6] ^ rk[13];
+ rk[15] = rk[7] ^ rk[14];
- rk += 8;
- }
+ rk += 8;
+ }
}
return 0;
}
@@ -844,11 +844,11 @@ rijndaelKeySetupEnc (uint32_t rk[ /*4*(Nr + 1) */ ],
/**
* Expand the cipher key into the decryption key schedule.
*
- * @return the number of rounds for the given cipher key size.
+ * @return the number of rounds for the given cipher key size.
*/
int
rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ],
- const char cipherKey[], size_t keyBits)
+ const char cipherKey[], size_t keyBits)
{
size_t Nr, i, j;
uint32_t temp;
@@ -877,32 +877,32 @@ rijndaelKeySetupDec (uint32_t rk[ /*4*(Nr + 1) */ ],
{
rk += 4;
rk[0] =
- Td0[Te4[(rk[0] >> 24)] & 0xff] ^
- Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
- Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
- Td3[Te4[(rk[0]) & 0xff] & 0xff];
+ Td0[Te4[(rk[0] >> 24)] & 0xff] ^
+ Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
+ Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
+ Td3[Te4[(rk[0]) & 0xff] & 0xff];
rk[1] =
- Td0[Te4[(rk[1] >> 24)] & 0xff] ^
- Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
- Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
- Td3[Te4[(rk[1]) & 0xff] & 0xff];
+ Td0[Te4[(rk[1] >> 24)] & 0xff] ^
+ Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
+ Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
+ Td3[Te4[(rk[1]) & 0xff] & 0xff];
rk[2] =
- Td0[Te4[(rk[2] >> 24)] & 0xff] ^
- Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
- Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
- Td3[Te4[(rk[2]) & 0xff] & 0xff];
+ Td0[Te4[(rk[2] >> 24)] & 0xff] ^
+ Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
+ Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
+ Td3[Te4[(rk[2]) & 0xff] & 0xff];
rk[3] =
- Td0[Te4[(rk[3] >> 24)] & 0xff] ^
- Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
- Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
- Td3[Te4[(rk[3]) & 0xff] & 0xff];
+ Td0[Te4[(rk[3] >> 24)] & 0xff] ^
+ Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
+ Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
+ Td3[Te4[(rk[3]) & 0xff] & 0xff];
}
return Nr;
}
void
rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char pt[16], char ct[16])
+ const char pt[16], char ct[16])
{
uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
size_t r;
@@ -922,44 +922,44 @@ rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
for (;;)
{
t0 =
- Te0[(s0 >> 24)] ^
- Te1[(s1 >> 16) & 0xff] ^
- Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4];
+ Te0[(s0 >> 24)] ^
+ Te1[(s1 >> 16) & 0xff] ^
+ Te2[(s2 >> 8) & 0xff] ^ Te3[(s3) & 0xff] ^ rk[4];
t1 =
- Te0[(s1 >> 24)] ^
- Te1[(s2 >> 16) & 0xff] ^
- Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5];
+ Te0[(s1 >> 24)] ^
+ Te1[(s2 >> 16) & 0xff] ^
+ Te2[(s3 >> 8) & 0xff] ^ Te3[(s0) & 0xff] ^ rk[5];
t2 =
- Te0[(s2 >> 24)] ^
- Te1[(s3 >> 16) & 0xff] ^
- Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6];
+ Te0[(s2 >> 24)] ^
+ Te1[(s3 >> 16) & 0xff] ^
+ Te2[(s0 >> 8) & 0xff] ^ Te3[(s1) & 0xff] ^ rk[6];
t3 =
- Te0[(s3 >> 24)] ^
- Te1[(s0 >> 16) & 0xff] ^
- Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7];
+ Te0[(s3 >> 24)] ^
+ Te1[(s0 >> 16) & 0xff] ^
+ Te2[(s1 >> 8) & 0xff] ^ Te3[(s2) & 0xff] ^ rk[7];
rk += 8;
if (--r == 0)
- {
- break;
- }
+ {
+ break;
+ }
s0 =
- Te0[(t0 >> 24)] ^
- Te1[(t1 >> 16) & 0xff] ^
- Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0];
+ Te0[(t0 >> 24)] ^
+ Te1[(t1 >> 16) & 0xff] ^
+ Te2[(t2 >> 8) & 0xff] ^ Te3[(t3) & 0xff] ^ rk[0];
s1 =
- Te0[(t1 >> 24)] ^
- Te1[(t2 >> 16) & 0xff] ^
- Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1];
+ Te0[(t1 >> 24)] ^
+ Te1[(t2 >> 16) & 0xff] ^
+ Te2[(t3 >> 8) & 0xff] ^ Te3[(t0) & 0xff] ^ rk[1];
s2 =
- Te0[(t2 >> 24)] ^
- Te1[(t3 >> 16) & 0xff] ^
- Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2];
+ Te0[(t2 >> 24)] ^
+ Te1[(t3 >> 16) & 0xff] ^
+ Te2[(t0 >> 8) & 0xff] ^ Te3[(t1) & 0xff] ^ rk[2];
s3 =
- Te0[(t3 >> 24)] ^
- Te1[(t0 >> 16) & 0xff] ^
- Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3];
+ Te0[(t3 >> 24)] ^
+ Te1[(t0 >> 16) & 0xff] ^
+ Te2[(t1 >> 8) & 0xff] ^ Te3[(t2) & 0xff] ^ rk[3];
}
/*
* apply last round and
@@ -993,7 +993,7 @@ rijndaelEncrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
void
rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
- const char ct[16], char pt[16])
+ const char ct[16], char pt[16])
{
uint32_t s0, s1, s2, s3, t0, t1, t2, t3;
size_t r;
@@ -1013,44 +1013,44 @@ rijndaelDecrypt (const uint32_t rk[ /*4*(Nr + 1) */ ], size_t Nr,
for (;;)
{
t0 =
- Td0[(s0 >> 24)] ^
- Td1[(s3 >> 16) & 0xff] ^
- Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4];
+ Td0[(s0 >> 24)] ^
+ Td1[(s3 >> 16) & 0xff] ^
+ Td2[(s2 >> 8) & 0xff] ^ Td3[(s1) & 0xff] ^ rk[4];
t1 =
- Td0[(s1 >> 24)] ^
- Td1[(s0 >> 16) & 0xff] ^
- Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5];
+ Td0[(s1 >> 24)] ^
+ Td1[(s0 >> 16) & 0xff] ^
+ Td2[(s3 >> 8) & 0xff] ^ Td3[(s2) & 0xff] ^ rk[5];
t2 =
- Td0[(s2 >> 24)] ^
- Td1[(s1 >> 16) & 0xff] ^
- Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6];
+ Td0[(s2 >> 24)] ^
+ Td1[(s1 >> 16) & 0xff] ^
+ Td2[(s0 >> 8) & 0xff] ^ Td3[(s3) & 0xff] ^ rk[6];
t3 =
- Td0[(s3 >> 24)] ^
- Td1[(s2 >> 16) & 0xff] ^
- Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7];
+ Td0[(s3 >> 24)] ^
+ Td1[(s2 >> 16) & 0xff] ^
+ Td2[(s1 >> 8) & 0xff] ^ Td3[(s0) & 0xff] ^ rk[7];
rk += 8;
if (--r == 0)
- {
- break;
- }
+ {
+ break;
+ }
s0 =
- Td0[(t0 >> 24)] ^
- Td1[(t3 >> 16) & 0xff] ^
- Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0];
+ Td0[(t0 >> 24)] ^
+ Td1[(t3 >> 16) & 0xff] ^
+ Td2[(t2 >> 8) & 0xff] ^ Td3[(t1) & 0xff] ^ rk[0];
s1 =
- Td0[(t1 >> 24)] ^
- Td1[(t0 >> 16) & 0xff] ^
- Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1];
+ Td0[(t1 >> 24)] ^
+ Td1[(t0 >> 16) & 0xff] ^
+ Td2[(t3 >> 8) & 0xff] ^ Td3[(t2) & 0xff] ^ rk[1];
s2 =
- Td0[(t2 >> 24)] ^
- Td1[(t1 >> 16) & 0xff] ^
- Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2];
+ Td0[(t2 >> 24)] ^
+ Td1[(t1 >> 16) & 0xff] ^
+ Td2[(t0 >> 8) & 0xff] ^ Td3[(t3) & 0xff] ^ rk[2];
s3 =
- Td0[(t3 >> 24)] ^
- Td1[(t2 >> 16) & 0xff] ^
- Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3];
+ Td0[(t3 >> 24)] ^
+ Td1[(t2 >> 16) & 0xff] ^
+ Td2[(t1 >> 8) & 0xff] ^ Td3[(t0) & 0xff] ^ rk[3];
}
/*
* apply last round and