diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-02-17 18:09:56 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1999-02-17 18:09:56 +0000 |
commit | e87bd06433c9c3ed129321f904d555057fddd0ef (patch) | |
tree | 39cd8e7e263fc380b66f1b7497c7afc0de6d0d2c /sys/netinet/ip_cast.c | |
parent | 659730a173a6780111b95325c95a113297ad8dcc (diff) |
indent; remove local types
Diffstat (limited to 'sys/netinet/ip_cast.c')
-rw-r--r-- | sys/netinet/ip_cast.c | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/sys/netinet/ip_cast.c b/sys/netinet/ip_cast.c index af565c5041c..ed4fe63a1b7 100644 --- a/sys/netinet/ip_cast.c +++ b/sys/netinet/ip_cast.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_cast.c,v 1.2 1998/11/24 10:04:06 niklas Exp $ */ +/* $OpenBSD: ip_cast.c,v 1.3 1999/02/17 18:09:55 deraadt Exp $ */ /* * CAST-128 in C * Written by Steve Reid <sreid@sea-to-sky.net> @@ -11,10 +11,10 @@ #include <netinet/ip_castsb.h> /* Macros to access 8-bit bytes out of a 32-bit word */ -#define U8a(x) ( (u8) (x>>24) ) -#define U8b(x) ( (u8) ((x>>16)&255) ) -#define U8c(x) ( (u8) ((x>>8)&255) ) -#define U8d(x) ( (u8) ((x)&255) ) +#define U_INT8_Ta(x) ( (u_int8_t) (x>>24) ) +#define U_INT8_Tb(x) ( (u_int8_t) ((x>>16)&255) ) +#define U_INT8_Tc(x) ( (u_int8_t) ((x>>8)&255) ) +#define U_INT8_Td(x) ( (u_int8_t) ((x)&255) ) /* Circular left shift */ #define ROL(x, n) ( ((x)<<(n)) | ((x)>>(32-(n))) ) @@ -22,29 +22,29 @@ /* CAST-128 uses three different round functions */ #define F1(l, r, i) \ t = ROL(key->xkey[i] + r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] ^ cast_sbox2[U8b(t)]) - \ - cast_sbox3[U8c(t)]) + cast_sbox4[U8d(t)]; + l ^= ((cast_sbox1[U_INT8_Ta(t)] ^ cast_sbox2[U_INT8_Tb(t)]) - \ + cast_sbox3[U_INT8_Tc(t)]) + cast_sbox4[U_INT8_Td(t)]; #define F2(l, r, i) \ t = ROL(key->xkey[i] ^ r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] - cast_sbox2[U8b(t)]) + \ - cast_sbox3[U8c(t)]) ^ cast_sbox4[U8d(t)]; + l ^= ((cast_sbox1[U_INT8_Ta(t)] - cast_sbox2[U_INT8_Tb(t)]) + \ + cast_sbox3[U_INT8_Tc(t)]) ^ cast_sbox4[U_INT8_Td(t)]; #define F3(l, r, i) \ t = ROL(key->xkey[i] - r, key->xkey[i+16]); \ - l ^= ((cast_sbox1[U8a(t)] + cast_sbox2[U8b(t)]) ^ \ - cast_sbox3[U8c(t)]) - cast_sbox4[U8d(t)]; + l ^= ((cast_sbox1[U_INT8_Ta(t)] + cast_sbox2[U_INT8_Tb(t)]) ^ \ + cast_sbox3[U_INT8_Tc(t)]) - cast_sbox4[U_INT8_Td(t)]; /***** Encryption Function *****/ -void cast_encrypt(cast_key* key, u8* inblock, u8* outblock) +void cast_encrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) { -u32 t, l, r; +u_int32_t t, l, r; /* Get inblock into l,r */ - l = ((u32)inblock[0] << 24) | ((u32)inblock[1] << 16) | - ((u32)inblock[2] << 8) | (u32)inblock[3]; - r = ((u32)inblock[4] << 24) | ((u32)inblock[5] << 16) | - ((u32)inblock[6] << 8) | (u32)inblock[7]; + l = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | + ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; + r = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | + ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; /* Do the work */ F1(l, r, 0); F2(r, l, 1); @@ -66,14 +66,14 @@ u32 t, l, r; F1(r, l, 15); } /* Put l,r into outblock */ - outblock[0] = U8a(r); - outblock[1] = U8b(r); - outblock[2] = U8c(r); - outblock[3] = U8d(r); - outblock[4] = U8a(l); - outblock[5] = U8b(l); - outblock[6] = U8c(l); - outblock[7] = U8d(l); + outblock[0] = U_INT8_Ta(r); + outblock[1] = U_INT8_Tb(r); + outblock[2] = U_INT8_Tc(r); + outblock[3] = U_INT8_Td(r); + outblock[4] = U_INT8_Ta(l); + outblock[5] = U_INT8_Tb(l); + outblock[6] = U_INT8_Tc(l); + outblock[7] = U_INT8_Td(l); /* Wipe clean */ t = l = r = 0; } @@ -81,15 +81,15 @@ u32 t, l, r; /***** Decryption Function *****/ -void cast_decrypt(cast_key* key, u8* inblock, u8* outblock) +void cast_decrypt(cast_key* key, u_int8_t* inblock, u_int8_t* outblock) { -u32 t, l, r; +u_int32_t t, l, r; /* Get inblock into l,r */ - r = ((u32)inblock[0] << 24) | ((u32)inblock[1] << 16) | - ((u32)inblock[2] << 8) | (u32)inblock[3]; - l = ((u32)inblock[4] << 24) | ((u32)inblock[5] << 16) | - ((u32)inblock[6] << 8) | (u32)inblock[7]; + r = ((u_int32_t)inblock[0] << 24) | ((u_int32_t)inblock[1] << 16) | + ((u_int32_t)inblock[2] << 8) | (u_int32_t)inblock[3]; + l = ((u_int32_t)inblock[4] << 24) | ((u_int32_t)inblock[5] << 16) | + ((u_int32_t)inblock[6] << 8) | (u_int32_t)inblock[7]; /* Do the work */ /* Only do full 16 rounds if key length > 80 bits */ if (key->rounds > 12) { @@ -111,14 +111,14 @@ u32 t, l, r; F2(r, l, 1); F1(l, r, 0); /* Put l,r into outblock */ - outblock[0] = U8a(l); - outblock[1] = U8b(l); - outblock[2] = U8c(l); - outblock[3] = U8d(l); - outblock[4] = U8a(r); - outblock[5] = U8b(r); - outblock[6] = U8c(r); - outblock[7] = U8d(r); + outblock[0] = U_INT8_Ta(l); + outblock[1] = U_INT8_Tb(l); + outblock[2] = U_INT8_Tc(l); + outblock[3] = U_INT8_Td(l); + outblock[4] = U_INT8_Ta(r); + outblock[5] = U_INT8_Tb(r); + outblock[6] = U_INT8_Tc(r); + outblock[7] = U_INT8_Td(r); /* Wipe clean */ t = l = r = 0; } @@ -126,9 +126,9 @@ u32 t, l, r; /***** Key Schedual *****/ -void cast_setkey(cast_key* key, u8* rawkey, int keybytes) +void cast_setkey(cast_key* key, u_int8_t* rawkey, int keybytes) { -u32 t[4], z[4], x[4]; +u_int32_t t[4], z[4], x[4]; int i; /* Set number of rounds to 12 or 16, depending on key length */ @@ -137,91 +137,91 @@ int i; /* Copy key to workspace x */ for (i = 0; i < 4; i++) { x[i] = 0; - if ((i*4+0) < keybytes) x[i] = (u32)rawkey[i*4+0] << 24; - if ((i*4+1) < keybytes) x[i] |= (u32)rawkey[i*4+1] << 16; - if ((i*4+2) < keybytes) x[i] |= (u32)rawkey[i*4+2] << 8; - if ((i*4+3) < keybytes) x[i] |= (u32)rawkey[i*4+3]; + if ((i*4+0) < keybytes) x[i] = (u_int32_t)rawkey[i*4+0] << 24; + if ((i*4+1) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+1] << 16; + if ((i*4+2) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+2] << 8; + if ((i*4+3) < keybytes) x[i] |= (u_int32_t)rawkey[i*4+3]; } /* Generate 32 subkeys, four at a time */ for (i = 0; i < 32; i+=4) { switch (i & 4) { case 0: - t[0] = z[0] = x[0] ^ cast_sbox5[U8b(x[3])] ^ - cast_sbox6[U8d(x[3])] ^ cast_sbox7[U8a(x[3])] ^ - cast_sbox8[U8c(x[3])] ^ cast_sbox7[U8a(x[2])]; - t[1] = z[1] = x[2] ^ cast_sbox5[U8a(z[0])] ^ - cast_sbox6[U8c(z[0])] ^ cast_sbox7[U8b(z[0])] ^ - cast_sbox8[U8d(z[0])] ^ cast_sbox8[U8c(x[2])]; - t[2] = z[2] = x[3] ^ cast_sbox5[U8d(z[1])] ^ - cast_sbox6[U8c(z[1])] ^ cast_sbox7[U8b(z[1])] ^ - cast_sbox8[U8a(z[1])] ^ cast_sbox5[U8b(x[2])]; - t[3] = z[3] = x[1] ^ cast_sbox5[U8c(z[2])] ^ - cast_sbox6[U8b(z[2])] ^ cast_sbox7[U8d(z[2])] ^ - cast_sbox8[U8a(z[2])] ^ cast_sbox6[U8d(x[2])]; + t[0] = z[0] = x[0] ^ cast_sbox5[U_INT8_Tb(x[3])] ^ + cast_sbox6[U_INT8_Td(x[3])] ^ cast_sbox7[U_INT8_Ta(x[3])] ^ + cast_sbox8[U_INT8_Tc(x[3])] ^ cast_sbox7[U_INT8_Ta(x[2])]; + t[1] = z[1] = x[2] ^ cast_sbox5[U_INT8_Ta(z[0])] ^ + cast_sbox6[U_INT8_Tc(z[0])] ^ cast_sbox7[U_INT8_Tb(z[0])] ^ + cast_sbox8[U_INT8_Td(z[0])] ^ cast_sbox8[U_INT8_Tc(x[2])]; + t[2] = z[2] = x[3] ^ cast_sbox5[U_INT8_Td(z[1])] ^ + cast_sbox6[U_INT8_Tc(z[1])] ^ cast_sbox7[U_INT8_Tb(z[1])] ^ + cast_sbox8[U_INT8_Ta(z[1])] ^ cast_sbox5[U_INT8_Tb(x[2])]; + t[3] = z[3] = x[1] ^ cast_sbox5[U_INT8_Tc(z[2])] ^ + cast_sbox6[U_INT8_Tb(z[2])] ^ cast_sbox7[U_INT8_Td(z[2])] ^ + cast_sbox8[U_INT8_Ta(z[2])] ^ cast_sbox6[U_INT8_Td(x[2])]; break; case 4: - t[0] = x[0] = z[2] ^ cast_sbox5[U8b(z[1])] ^ - cast_sbox6[U8d(z[1])] ^ cast_sbox7[U8a(z[1])] ^ - cast_sbox8[U8c(z[1])] ^ cast_sbox7[U8a(z[0])]; - t[1] = x[1] = z[0] ^ cast_sbox5[U8a(x[0])] ^ - cast_sbox6[U8c(x[0])] ^ cast_sbox7[U8b(x[0])] ^ - cast_sbox8[U8d(x[0])] ^ cast_sbox8[U8c(z[0])]; - t[2] = x[2] = z[1] ^ cast_sbox5[U8d(x[1])] ^ - cast_sbox6[U8c(x[1])] ^ cast_sbox7[U8b(x[1])] ^ - cast_sbox8[U8a(x[1])] ^ cast_sbox5[U8b(z[0])]; - t[3] = x[3] = z[3] ^ cast_sbox5[U8c(x[2])] ^ - cast_sbox6[U8b(x[2])] ^ cast_sbox7[U8d(x[2])] ^ - cast_sbox8[U8a(x[2])] ^ cast_sbox6[U8d(z[0])]; + t[0] = x[0] = z[2] ^ cast_sbox5[U_INT8_Tb(z[1])] ^ + cast_sbox6[U_INT8_Td(z[1])] ^ cast_sbox7[U_INT8_Ta(z[1])] ^ + cast_sbox8[U_INT8_Tc(z[1])] ^ cast_sbox7[U_INT8_Ta(z[0])]; + t[1] = x[1] = z[0] ^ cast_sbox5[U_INT8_Ta(x[0])] ^ + cast_sbox6[U_INT8_Tc(x[0])] ^ cast_sbox7[U_INT8_Tb(x[0])] ^ + cast_sbox8[U_INT8_Td(x[0])] ^ cast_sbox8[U_INT8_Tc(z[0])]; + t[2] = x[2] = z[1] ^ cast_sbox5[U_INT8_Td(x[1])] ^ + cast_sbox6[U_INT8_Tc(x[1])] ^ cast_sbox7[U_INT8_Tb(x[1])] ^ + cast_sbox8[U_INT8_Ta(x[1])] ^ cast_sbox5[U_INT8_Tb(z[0])]; + t[3] = x[3] = z[3] ^ cast_sbox5[U_INT8_Tc(x[2])] ^ + cast_sbox6[U_INT8_Tb(x[2])] ^ cast_sbox7[U_INT8_Td(x[2])] ^ + cast_sbox8[U_INT8_Ta(x[2])] ^ cast_sbox6[U_INT8_Td(z[0])]; break; } switch (i & 12) { case 0: case 12: - key->xkey[i+0] = cast_sbox5[U8a(t[2])] ^ cast_sbox6[U8b(t[2])] ^ - cast_sbox7[U8d(t[1])] ^ cast_sbox8[U8c(t[1])]; - key->xkey[i+1] = cast_sbox5[U8c(t[2])] ^ cast_sbox6[U8d(t[2])] ^ - cast_sbox7[U8b(t[1])] ^ cast_sbox8[U8a(t[1])]; - key->xkey[i+2] = cast_sbox5[U8a(t[3])] ^ cast_sbox6[U8b(t[3])] ^ - cast_sbox7[U8d(t[0])] ^ cast_sbox8[U8c(t[0])]; - key->xkey[i+3] = cast_sbox5[U8c(t[3])] ^ cast_sbox6[U8d(t[3])] ^ - cast_sbox7[U8b(t[0])] ^ cast_sbox8[U8a(t[0])]; + key->xkey[i+0] = cast_sbox5[U_INT8_Ta(t[2])] ^ cast_sbox6[U_INT8_Tb(t[2])] ^ + cast_sbox7[U_INT8_Td(t[1])] ^ cast_sbox8[U_INT8_Tc(t[1])]; + key->xkey[i+1] = cast_sbox5[U_INT8_Tc(t[2])] ^ cast_sbox6[U_INT8_Td(t[2])] ^ + cast_sbox7[U_INT8_Tb(t[1])] ^ cast_sbox8[U_INT8_Ta(t[1])]; + key->xkey[i+2] = cast_sbox5[U_INT8_Ta(t[3])] ^ cast_sbox6[U_INT8_Tb(t[3])] ^ + cast_sbox7[U_INT8_Td(t[0])] ^ cast_sbox8[U_INT8_Tc(t[0])]; + key->xkey[i+3] = cast_sbox5[U_INT8_Tc(t[3])] ^ cast_sbox6[U_INT8_Td(t[3])] ^ + cast_sbox7[U_INT8_Tb(t[0])] ^ cast_sbox8[U_INT8_Ta(t[0])]; break; case 4: case 8: - key->xkey[i+0] = cast_sbox5[U8d(t[0])] ^ cast_sbox6[U8c(t[0])] ^ - cast_sbox7[U8a(t[3])] ^ cast_sbox8[U8b(t[3])]; - key->xkey[i+1] = cast_sbox5[U8b(t[0])] ^ cast_sbox6[U8a(t[0])] ^ - cast_sbox7[U8c(t[3])] ^ cast_sbox8[U8d(t[3])]; - key->xkey[i+2] = cast_sbox5[U8d(t[1])] ^ cast_sbox6[U8c(t[1])] ^ - cast_sbox7[U8a(t[2])] ^ cast_sbox8[U8b(t[2])]; - key->xkey[i+3] = cast_sbox5[U8b(t[1])] ^ cast_sbox6[U8a(t[1])] ^ - cast_sbox7[U8c(t[2])] ^ cast_sbox8[U8d(t[2])]; + key->xkey[i+0] = cast_sbox5[U_INT8_Td(t[0])] ^ cast_sbox6[U_INT8_Tc(t[0])] ^ + cast_sbox7[U_INT8_Ta(t[3])] ^ cast_sbox8[U_INT8_Tb(t[3])]; + key->xkey[i+1] = cast_sbox5[U_INT8_Tb(t[0])] ^ cast_sbox6[U_INT8_Ta(t[0])] ^ + cast_sbox7[U_INT8_Tc(t[3])] ^ cast_sbox8[U_INT8_Td(t[3])]; + key->xkey[i+2] = cast_sbox5[U_INT8_Td(t[1])] ^ cast_sbox6[U_INT8_Tc(t[1])] ^ + cast_sbox7[U_INT8_Ta(t[2])] ^ cast_sbox8[U_INT8_Tb(t[2])]; + key->xkey[i+3] = cast_sbox5[U_INT8_Tb(t[1])] ^ cast_sbox6[U_INT8_Ta(t[1])] ^ + cast_sbox7[U_INT8_Tc(t[2])] ^ cast_sbox8[U_INT8_Td(t[2])]; break; } switch (i & 12) { case 0: - key->xkey[i+0] ^= cast_sbox5[U8c(z[0])]; - key->xkey[i+1] ^= cast_sbox6[U8c(z[1])]; - key->xkey[i+2] ^= cast_sbox7[U8b(z[2])]; - key->xkey[i+3] ^= cast_sbox8[U8a(z[3])]; + key->xkey[i+0] ^= cast_sbox5[U_INT8_Tc(z[0])]; + key->xkey[i+1] ^= cast_sbox6[U_INT8_Tc(z[1])]; + key->xkey[i+2] ^= cast_sbox7[U_INT8_Tb(z[2])]; + key->xkey[i+3] ^= cast_sbox8[U_INT8_Ta(z[3])]; break; case 4: - key->xkey[i+0] ^= cast_sbox5[U8a(x[2])]; - key->xkey[i+1] ^= cast_sbox6[U8b(x[3])]; - key->xkey[i+2] ^= cast_sbox7[U8d(x[0])]; - key->xkey[i+3] ^= cast_sbox8[U8d(x[1])]; + key->xkey[i+0] ^= cast_sbox5[U_INT8_Ta(x[2])]; + key->xkey[i+1] ^= cast_sbox6[U_INT8_Tb(x[3])]; + key->xkey[i+2] ^= cast_sbox7[U_INT8_Td(x[0])]; + key->xkey[i+3] ^= cast_sbox8[U_INT8_Td(x[1])]; break; case 8: - key->xkey[i+0] ^= cast_sbox5[U8b(z[2])]; - key->xkey[i+1] ^= cast_sbox6[U8a(z[3])]; - key->xkey[i+2] ^= cast_sbox7[U8c(z[0])]; - key->xkey[i+3] ^= cast_sbox8[U8c(z[1])]; + key->xkey[i+0] ^= cast_sbox5[U_INT8_Tb(z[2])]; + key->xkey[i+1] ^= cast_sbox6[U_INT8_Ta(z[3])]; + key->xkey[i+2] ^= cast_sbox7[U_INT8_Tc(z[0])]; + key->xkey[i+3] ^= cast_sbox8[U_INT8_Tc(z[1])]; break; case 12: - key->xkey[i+0] ^= cast_sbox5[U8d(x[0])]; - key->xkey[i+1] ^= cast_sbox6[U8d(x[1])]; - key->xkey[i+2] ^= cast_sbox7[U8a(x[2])]; - key->xkey[i+3] ^= cast_sbox8[U8b(x[3])]; + key->xkey[i+0] ^= cast_sbox5[U_INT8_Td(x[0])]; + key->xkey[i+1] ^= cast_sbox6[U_INT8_Td(x[1])]; + key->xkey[i+2] ^= cast_sbox7[U_INT8_Ta(x[2])]; + key->xkey[i+3] ^= cast_sbox8[U_INT8_Tb(x[3])]; break; } if (i >= 16) { |