diff -u -r -x CVS -N grub2/ChangeLog grub2-new/ChangeLog --- grub2/ChangeLog 2007-08-29 12:39:41.000000000 +0200 +++ grub2-new/ChangeLog 2007-09-03 20:39:28.000000000 +0200 @@ -1,3 +1,14 @@ +2007-09-03 Simon Peter
+ * disk/devmapper.c: New file. + * include/grub/crypto.h: New file. + * conf/common.rmk: Add devmapper.mod and dependency + declaratins. Add crypto.mod, aes.mod and rmd160.mod and dependency + declarations. + * include/grub/disk.h: Add GRUB_DISK_DEVICE_CRYPTO_ID. + * crypto/aes.c: New file. + * crypto/crypto.c: New file. + * crypto/rmd160.c: New file. + 2007-08-29 Robert Millan Patch from Simon Peter : diff -u -r -x CVS -N grub2/crypto/aes.c grub2-new/crypto/aes.c --- grub2/crypto/aes.c 2007-09-03 20:40:37.000000000 +0200 +++ grub2-new/crypto/aes.c 2007-09-03 20:25:06.000000000 +0200 @@ -42,9 +42,9 @@ */ typedef struct { - unsigned long erk[64]; /*!< encryption round keys */ - unsigned long drk[64]; /*!< decryption round keys */ - int nr; /*!< number of rounds */ + unsigned long erk[64]; /*!< encryption round keys */ + unsigned long drk[64]; /*!< decryption round keys */ + int nr; /*!< number of rounds */ } aes_context; @@ -90,16 +90,16 @@ /* * Forward S-box & tables */ -static uint8 FSb[256]; -static uint32 FT0[256]; -static uint32 FT1[256]; -static uint32 FT2[256]; -static uint32 FT3[256]; +static uint8 FSb[256]; +static uint32 FT0[256]; +static uint32 FT1[256]; +static uint32 FT2[256]; +static uint32 FT3[256]; /* * Reverse S-box & tables */ -static uint8 RSb[256]; +static uint8 RSb[256]; static uint32 RT0[256]; static uint32 RT1[256]; static uint32 RT2[256]; @@ -118,80 +118,83 @@ #define XTIME(x) ( ( x << 1 ) ^ ( ( x & 0x80 ) ? 0x1B : 0x00 ) ) #define MUL(x,y) ( ( x && y ) ? pow[(log[x] + log[y]) % 255] : 0 ) -static void aes_gen_tables( void ) +static void +aes_gen_tables (void) { - int i; - uint8 x, y; - uint8 pow[256]; - uint8 log[256]; - - /* - * compute pow and log tables over GF(2^8) - */ - for( i = 0, x = 1; i < 256; i++, x ^= XTIME( x ) ) + int i; + uint8 x, y; + uint8 pow[256]; + uint8 log[256]; + + /* + * compute pow and log tables over GF(2^8) + */ + for (i = 0, x = 1; i < 256; i++, x ^= XTIME (x)) { - pow[i] = x; - log[x] = i; + pow[i] = x; + log[x] = i; } - /* - * calculate the round constants - */ - for( i = 0, x = 1; i < 10; i++, x = XTIME( x ) ) + /* + * calculate the round constants + */ + for (i = 0, x = 1; i < 10; i++, x = XTIME (x)) { - RCON[i] = (uint32) x << 24; + RCON[i] = (uint32) x << 24; } - /* - * generate the forward and reverse S-boxes - */ - FSb[0x00] = 0x63; - RSb[0x63] = 0x00; + /* + * generate the forward and reverse S-boxes + */ + FSb[0x00] = 0x63; + RSb[0x63] = 0x00; - for( i = 1; i < 256; i++ ) + for (i = 1; i < 256; i++) { - x = pow[255 - log[i]]; + x = pow[255 - log[i]]; - y = x; y = ( y << 1 ) | ( y >> 7 ); - x ^= y; y = ( y << 1 ) | ( y >> 7 ); - x ^= y; y = ( y << 1 ) | ( y >> 7 ); - x ^= y; y = ( y << 1 ) | ( y >> 7 ); - x ^= y ^ 0x63; + y = x; + y = (y << 1) | (y >> 7); + x ^= y; + y = (y << 1) | (y >> 7); + x ^= y; + y = (y << 1) | (y >> 7); + x ^= y; + y = (y << 1) | (y >> 7); + x ^= y ^ 0x63; - FSb[i] = x; - RSb[x] = i; + FSb[i] = x; + RSb[x] = i; } - /* - * generate the forward and reverse tables - */ - for( i = 0; i < 256; i++ ) + /* + * generate the forward and reverse tables + */ + for (i = 0; i < 256; i++) { - x = FSb[i]; y = XTIME( x ); + x = FSb[i]; + y = XTIME (x); - FT0[i] = (uint32) ( x ^ y ) ^ - ( (uint32) x << 8 ) ^ - ( (uint32) x << 16 ) ^ - ( (uint32) y << 24 ); + FT0[i] = (uint32) (x ^ y) ^ + ((uint32) x << 8) ^ ((uint32) x << 16) ^ ((uint32) y << 24); - FT0[i] &= 0xFFFFFFFF; + FT0[i] &= 0xFFFFFFFF; - FT1[i] = ROTR8( FT0[i] ); - FT2[i] = ROTR8( FT1[i] ); - FT3[i] = ROTR8( FT2[i] ); + FT1[i] = ROTR8 (FT0[i]); + FT2[i] = ROTR8 (FT1[i]); + FT3[i] = ROTR8 (FT2[i]); - y = RSb[i]; + y = RSb[i]; - RT0[i] = ( (uint32) MUL( 0x0B, y ) ) ^ - ( (uint32) MUL( 0x0D, y ) << 8 ) ^ - ( (uint32) MUL( 0x09, y ) << 16 ) ^ - ( (uint32) MUL( 0x0E, y ) << 24 ); + RT0[i] = ((uint32) MUL (0x0B, y)) ^ + ((uint32) MUL (0x0D, y) << 8) ^ + ((uint32) MUL (0x09, y) << 16) ^ ((uint32) MUL (0x0E, y) << 24); - RT0[i] &= 0xFFFFFFFF; + RT0[i] &= 0xFFFFFFFF; - RT1[i] = ROTR8( RT0[i] ); - RT2[i] = ROTR8( RT1[i] ); - RT3[i] = ROTR8( RT2[i] ); + RT1[i] = ROTR8 (RT0[i]); + RT2[i] = ROTR8 (RT1[i]); + RT3[i] = ROTR8 (RT2[i]); } } @@ -199,45 +202,51 @@ /* * Forward S-box + * + * See Figure 7 of FIPS PUB 197. This array is generated by + * the algorithm described in Section 5.1.1 of FIPS PUB 197. */ -static const uint8 FSb[256] = -{ - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 +static const uint8 FSb[256] = { + 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, + 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, + 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, + 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, + 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, + 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, + 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, + 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, + 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, + 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, + 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, + 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, + 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, + 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, + 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, + 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, + 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, + 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, + 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, + 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, + 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, + 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, + 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, + 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, + 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, + 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, + 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, + 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, + 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, + 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, + 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, + 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 }; /* * Forward tables + * + * These are optimization tables, as described for example in: + * http://en.wikipedia.org/wiki/Advanced_Encryption_Standard + * Section "Optimization of the Cipher". */ #define FT \ \ @@ -308,63 +317,73 @@ #define V(a,b,c,d) 0x##a##b##c##d static const uint32 FT0[256] = { FT }; + #undef V #define V(a,b,c,d) 0x##d##a##b##c static const uint32 FT1[256] = { FT }; + #undef V #define V(a,b,c,d) 0x##c##d##a##b static const uint32 FT2[256] = { FT }; + #undef V #define V(a,b,c,d) 0x##b##c##d##a static const uint32 FT3[256] = { FT }; + #undef V #undef FT /* * Reverse S-box + * + * See Figure 14 of FIPS PUB 197. This array is generated by + * the algorithm described in Section 5.3.2 of FIPS PUB 197. */ -static const uint8 RSb[256] = -{ - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D +static const uint8 RSb[256] = { + 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, + 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, + 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, + 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, + 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, + 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, + 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, + 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, + 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, + 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, + 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, + 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, + 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, + 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, + 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, + 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, + 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, + 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, + 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, + 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, + 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, + 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, + 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, + 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, + 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, + 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, + 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, + 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, + 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, + 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, + 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, + 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D }; /* * Reverse tables + * + * These are optimization tables, as described for example in: + * http://en.wikipedia.org/wiki/Advanced_Encryption_Standard + * Section "Optimization of the Cipher". */ #define RT \ \ @@ -435,18 +454,22 @@ #define V(a,b,c,d) 0x##a##b##c##d static const uint32 RT0[256] = { RT }; + #undef V #define V(a,b,c,d) 0x##d##a##b##c static const uint32 RT1[256] = { RT }; + #undef V #define V(a,b,c,d) 0x##c##d##a##b static const uint32 RT2[256] = { RT }; + #undef V #define V(a,b,c,d) 0x##b##c##d##a static const uint32 RT3[256] = { RT }; + #undef V #undef RT @@ -454,14 +477,16 @@ /* * Round constants */ -static const uint32 RCON[10] = -{ - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x1B000000, 0x36000000 +static const uint32 RCON[10] = { + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1B000000, 0x36000000 }; -static void aes_gen_tables( void ) {} +static void +aes_gen_tables (void) +{ +} #endif @@ -476,176 +501,184 @@ /* * AES key schedule */ -static void aes_set_key( aes_context *ctx, const uint8 *key, int keysize ) +static void +aes_set_key (aes_context * ctx, const uint8 * key, int keysize) { - int i; - uint32 *RK, *SK; - static int ft_init = 0; - static int kt_init = 0; + int i; + uint32 *RK, *SK; + static int ft_init = 0; + static int kt_init = 0; - if( ft_init == 0 ) + if (ft_init == 0) { - aes_gen_tables(); + aes_gen_tables (); - ft_init = 1; + ft_init = 1; } - switch( keysize ) + switch (keysize) { - case 128: ctx->nr = 10; break; - case 192: ctx->nr = 12; break; - case 256: ctx->nr = 14; break; - default : return; + case 128: + ctx->nr = 10; + break; + case 192: + ctx->nr = 12; + break; + case 256: + ctx->nr = 14; + break; + default: + return; } - RK = ctx->erk; + RK = ctx->erk; - for( i = 0; i < (keysize >> 5); i++ ) + for (i = 0; i < (keysize >> 5); i++) { - GET_UINT32_BE( RK[i], key, i << 2 ); + GET_UINT32_BE (RK[i], key, i << 2); } - /* - * setup encryption round keys - */ - switch( ctx->nr ) + /* + * setup encryption round keys + */ + switch (ctx->nr) { case 10: - for( i = 0; i < 10; i++, RK += 4 ) - { - RK[4] = RK[0] ^ RCON[i] ^ - ( FSb[ (uint8) ( RK[3] >> 16 ) ] << 24 ) ^ - ( FSb[ (uint8) ( RK[3] >> 8 ) ] << 16 ) ^ - ( FSb[ (uint8) ( RK[3] ) ] << 8 ) ^ - ( FSb[ (uint8) ( RK[3] >> 24 ) ] ); - - RK[5] = RK[1] ^ RK[4]; - RK[6] = RK[2] ^ RK[5]; - RK[7] = RK[3] ^ RK[6]; - } - break; + for (i = 0; i < 10; i++, RK += 4) + { + RK[4] = RK[0] ^ RCON[i] ^ + (FSb[(uint8) (RK[3] >> 16)] << 24) ^ + (FSb[(uint8) (RK[3] >> 8)] << 16) ^ + (FSb[(uint8) (RK[3])] << 8) ^ (FSb[(uint8) (RK[3] >> 24)]); + + RK[5] = RK[1] ^ RK[4]; + RK[6] = RK[2] ^ RK[5]; + RK[7] = RK[3] ^ RK[6]; + } + break; case 12: - for( i = 0; i < 8; i++, RK += 6 ) - { - RK[6] = RK[0] ^ RCON[i] ^ - ( FSb[ (uint8) ( RK[5] >> 16 ) ] << 24 ) ^ - ( FSb[ (uint8) ( RK[5] >> 8 ) ] << 16 ) ^ - ( FSb[ (uint8) ( RK[5] ) ] << 8 ) ^ - ( FSb[ (uint8) ( RK[5] >> 24 ) ] ); - - RK[7] = RK[1] ^ RK[6]; - RK[8] = RK[2] ^ RK[7]; - RK[9] = RK[3] ^ RK[8]; - RK[10] = RK[4] ^ RK[9]; - RK[11] = RK[5] ^ RK[10]; - } - break; + for (i = 0; i < 8; i++, RK += 6) + { + RK[6] = RK[0] ^ RCON[i] ^ + (FSb[(uint8) (RK[5] >> 16)] << 24) ^ + (FSb[(uint8) (RK[5] >> 8)] << 16) ^ + (FSb[(uint8) (RK[5])] << 8) ^ (FSb[(uint8) (RK[5] >> 24)]); + + RK[7] = RK[1] ^ RK[6]; + RK[8] = RK[2] ^ RK[7]; + RK[9] = RK[3] ^ RK[8]; + RK[10] = RK[4] ^ RK[9]; + RK[11] = RK[5] ^ RK[10]; + } + break; case 14: - for( i = 0; i < 7; i++, RK += 8 ) - { - RK[8] = RK[0] ^ RCON[i] ^ - ( FSb[ (uint8) ( RK[7] >> 16 ) ] << 24 ) ^ - ( FSb[ (uint8) ( RK[7] >> 8 ) ] << 16 ) ^ - ( FSb[ (uint8) ( RK[7] ) ] << 8 ) ^ - ( FSb[ (uint8) ( RK[7] >> 24 ) ] ); - - RK[9] = RK[1] ^ RK[8]; - RK[10] = RK[2] ^ RK[9]; - RK[11] = RK[3] ^ RK[10]; - - RK[12] = RK[4] ^ - ( FSb[ (uint8) ( RK[11] >> 24 ) ] << 24 ) ^ - ( FSb[ (uint8) ( RK[11] >> 16 ) ] << 16 ) ^ - ( FSb[ (uint8) ( RK[11] >> 8 ) ] << 8 ) ^ - ( FSb[ (uint8) ( RK[11] ) ] ); - - RK[13] = RK[5] ^ RK[12]; - RK[14] = RK[6] ^ RK[13]; - RK[15] = RK[7] ^ RK[14]; - } - break; + for (i = 0; i < 7; i++, RK += 8) + { + RK[8] = RK[0] ^ RCON[i] ^ + (FSb[(uint8) (RK[7] >> 16)] << 24) ^ + (FSb[(uint8) (RK[7] >> 8)] << 16) ^ + (FSb[(uint8) (RK[7])] << 8) ^ (FSb[(uint8) (RK[7] >> 24)]); + + RK[9] = RK[1] ^ RK[8]; + RK[10] = RK[2] ^ RK[9]; + RK[11] = RK[3] ^ RK[10]; + + RK[12] = RK[4] ^ + (FSb[(uint8) (RK[11] >> 24)] << 24) ^ + (FSb[(uint8) (RK[11] >> 16)] << 16) ^ + (FSb[(uint8) (RK[11] >> 8)] << 8) ^ (FSb[(uint8) (RK[11])]); + + RK[13] = RK[5] ^ RK[12]; + RK[14] = RK[6] ^ RK[13]; + RK[15] = RK[7] ^ RK[14]; + } + break; default: - break; + break; } - /* - * setup decryption round keys - */ - if( kt_init == 0 ) + /* + * setup decryption round keys + */ + if (kt_init == 0) { - for( i = 0; i < 256; i++ ) - { - KT0[i] = RT0[ FSb[i] ]; - KT1[i] = RT1[ FSb[i] ]; - KT2[i] = RT2[ FSb[i] ]; - KT3[i] = RT3[ FSb[i] ]; - } + for (i = 0; i < 256; i++) + { + KT0[i] = RT0[FSb[i]]; + KT1[i] = RT1[FSb[i]]; + KT2[i] = RT2[FSb[i]]; + KT3[i] = RT3[FSb[i]]; + } - kt_init = 1; + kt_init = 1; } - SK = ctx->drk; + SK = ctx->drk; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; - for( i = 1; i < ctx->nr; i++ ) + for (i = 1; i < ctx->nr; i++) { - RK -= 8; - - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ - KT1[ (uint8) ( *RK >> 16 ) ] ^ - KT2[ (uint8) ( *RK >> 8 ) ] ^ - KT3[ (uint8) ( *RK ) ]; RK++; - - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ - KT1[ (uint8) ( *RK >> 16 ) ] ^ - KT2[ (uint8) ( *RK >> 8 ) ] ^ - KT3[ (uint8) ( *RK ) ]; RK++; + RK -= 8; - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ - KT1[ (uint8) ( *RK >> 16 ) ] ^ - KT2[ (uint8) ( *RK >> 8 ) ] ^ - KT3[ (uint8) ( *RK ) ]; RK++; - - *SK++ = KT0[ (uint8) ( *RK >> 24 ) ] ^ - KT1[ (uint8) ( *RK >> 16 ) ] ^ - KT2[ (uint8) ( *RK >> 8 ) ] ^ - KT3[ (uint8) ( *RK ) ]; RK++; + *SK++ = KT0[(uint8) (*RK >> 24)] ^ + KT1[(uint8) (*RK >> 16)] ^ + KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; + RK++; + + *SK++ = KT0[(uint8) (*RK >> 24)] ^ + KT1[(uint8) (*RK >> 16)] ^ + KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; + RK++; + + *SK++ = KT0[(uint8) (*RK >> 24)] ^ + KT1[(uint8) (*RK >> 16)] ^ + KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; + RK++; + + *SK++ = KT0[(uint8) (*RK >> 24)] ^ + KT1[(uint8) (*RK >> 16)] ^ + KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; + RK++; } - RK -= 8; + RK -= 8; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; + *SK++ = *RK++; } /** * AES block encryption (ECB mode) */ -static void aes_encrypt( aes_context *ctx, - unsigned char input[16], - unsigned char output[16] ) -{ - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; - - RK = ctx->erk; - - GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0]; - GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1]; - GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2]; - GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3]; +static void +aes_encrypt (aes_context * ctx, + unsigned char input[16], unsigned char output[16]) +{ + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; + + RK = ctx->erk; + + GET_UINT32_BE (X0, input, 0); + X0 ^= RK[0]; + GET_UINT32_BE (X1, input, 4); + X1 ^= RK[1]; + GET_UINT32_BE (X2, input, 8); + X2 ^= RK[2]; + GET_UINT32_BE (X3, input, 12); + X3 ^= RK[3]; #define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ { \ @@ -672,71 +705,71 @@ FT3[ (uint8) ( Y2 ) ]; \ } - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - - if( ctx->nr > 10 ) - { - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - } - - if( ctx->nr > 12 ) - { - AES_FROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_FROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - } - - RK += 4; - - X0 = RK[0] ^ ( FSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ - ( FSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ - ( FSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ - ( FSb[ (uint8) ( Y3 ) ] ); - - X1 = RK[1] ^ ( FSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ - ( FSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ - ( FSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ - ( FSb[ (uint8) ( Y0 ) ] ); - - X2 = RK[2] ^ ( FSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ - ( FSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ - ( FSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ - ( FSb[ (uint8) ( Y1 ) ] ); - - X3 = RK[3] ^ ( FSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ - ( FSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ - ( FSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ - ( FSb[ (uint8) ( Y2 ) ] ); - - PUT_UINT32_BE( X0, output, 0 ); - PUT_UINT32_BE( X1, output, 4 ); - PUT_UINT32_BE( X2, output, 8 ); - PUT_UINT32_BE( X3, output, 12 ); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + + if (ctx->nr > 10) + { + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + } + + if (ctx->nr > 12) + { + AES_FROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_FROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + } + + RK += 4; + + X0 = RK[0] ^ (FSb[(uint8) (Y0 >> 24)] << 24) ^ + (FSb[(uint8) (Y1 >> 16)] << 16) ^ + (FSb[(uint8) (Y2 >> 8)] << 8) ^ (FSb[(uint8) (Y3)]); + + X1 = RK[1] ^ (FSb[(uint8) (Y1 >> 24)] << 24) ^ + (FSb[(uint8) (Y2 >> 16)] << 16) ^ + (FSb[(uint8) (Y3 >> 8)] << 8) ^ (FSb[(uint8) (Y0)]); + + X2 = RK[2] ^ (FSb[(uint8) (Y2 >> 24)] << 24) ^ + (FSb[(uint8) (Y3 >> 16)] << 16) ^ + (FSb[(uint8) (Y0 >> 8)] << 8) ^ (FSb[(uint8) (Y1)]); + + X3 = RK[3] ^ (FSb[(uint8) (Y3 >> 24)] << 24) ^ + (FSb[(uint8) (Y0 >> 16)] << 16) ^ + (FSb[(uint8) (Y1 >> 8)] << 8) ^ (FSb[(uint8) (Y2)]); + + PUT_UINT32_BE (X0, output, 0); + PUT_UINT32_BE (X1, output, 4); + PUT_UINT32_BE (X2, output, 8); + PUT_UINT32_BE (X3, output, 12); } /* * AES block decryption (ECB mode) */ -static void aes_decrypt( aes_context *ctx, - unsigned char input[16], - unsigned char output[16] ) -{ - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; - - RK = ctx->drk; - - GET_UINT32_BE( X0, input, 0 ); X0 ^= RK[0]; - GET_UINT32_BE( X1, input, 4 ); X1 ^= RK[1]; - GET_UINT32_BE( X2, input, 8 ); X2 ^= RK[2]; - GET_UINT32_BE( X3, input, 12 ); X3 ^= RK[3]; +static void +aes_decrypt (aes_context * ctx, + unsigned char input[16], unsigned char output[16]) +{ + uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; + + RK = ctx->drk; + + GET_UINT32_BE (X0, input, 0); + X0 ^= RK[0]; + GET_UINT32_BE (X1, input, 4); + X1 ^= RK[1]; + GET_UINT32_BE (X2, input, 8); + X2 ^= RK[2]; + GET_UINT32_BE (X3, input, 12); + X3 ^= RK[3]; #define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ { \ @@ -763,106 +796,100 @@ RT3[ (uint8) ( Y0 ) ]; \ } - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - - if( ctx->nr > 10 ) - { - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - } - - if( ctx->nr > 12 ) - { - AES_RROUND( X0, X1, X2, X3, Y0, Y1, Y2, Y3 ); - AES_RROUND( Y0, Y1, Y2, Y3, X0, X1, X2, X3 ); - } - - RK += 4; - - X0 = RK[0] ^ ( RSb[ (uint8) ( Y0 >> 24 ) ] << 24 ) ^ - ( RSb[ (uint8) ( Y3 >> 16 ) ] << 16 ) ^ - ( RSb[ (uint8) ( Y2 >> 8 ) ] << 8 ) ^ - ( RSb[ (uint8) ( Y1 ) ] ); - - X1 = RK[1] ^ ( RSb[ (uint8) ( Y1 >> 24 ) ] << 24 ) ^ - ( RSb[ (uint8) ( Y0 >> 16 ) ] << 16 ) ^ - ( RSb[ (uint8) ( Y3 >> 8 ) ] << 8 ) ^ - ( RSb[ (uint8) ( Y2 ) ] ); - - X2 = RK[2] ^ ( RSb[ (uint8) ( Y2 >> 24 ) ] << 24 ) ^ - ( RSb[ (uint8) ( Y1 >> 16 ) ] << 16 ) ^ - ( RSb[ (uint8) ( Y0 >> 8 ) ] << 8 ) ^ - ( RSb[ (uint8) ( Y3 ) ] ); - - X3 = RK[3] ^ ( RSb[ (uint8) ( Y3 >> 24 ) ] << 24 ) ^ - ( RSb[ (uint8) ( Y2 >> 16 ) ] << 16 ) ^ - ( RSb[ (uint8) ( Y1 >> 8 ) ] << 8 ) ^ - ( RSb[ (uint8) ( Y0 ) ] ); - - PUT_UINT32_BE( X0, output, 0 ); - PUT_UINT32_BE( X1, output, 4 ); - PUT_UINT32_BE( X2, output, 8 ); - PUT_UINT32_BE( X3, output, 12 ); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + + if (ctx->nr > 10) + { + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + } + + if (ctx->nr > 12) + { + AES_RROUND (X0, X1, X2, X3, Y0, Y1, Y2, Y3); + AES_RROUND (Y0, Y1, Y2, Y3, X0, X1, X2, X3); + } + + RK += 4; + + X0 = RK[0] ^ (RSb[(uint8) (Y0 >> 24)] << 24) ^ + (RSb[(uint8) (Y3 >> 16)] << 16) ^ + (RSb[(uint8) (Y2 >> 8)] << 8) ^ (RSb[(uint8) (Y1)]); + + X1 = RK[1] ^ (RSb[(uint8) (Y1 >> 24)] << 24) ^ + (RSb[(uint8) (Y0 >> 16)] << 16) ^ + (RSb[(uint8) (Y3 >> 8)] << 8) ^ (RSb[(uint8) (Y2)]); + + X2 = RK[2] ^ (RSb[(uint8) (Y2 >> 24)] << 24) ^ + (RSb[(uint8) (Y1 >> 16)] << 16) ^ + (RSb[(uint8) (Y0 >> 8)] << 8) ^ (RSb[(uint8) (Y3)]); + + X3 = RK[3] ^ (RSb[(uint8) (Y3 >> 24)] << 24) ^ + (RSb[(uint8) (Y2 >> 16)] << 16) ^ + (RSb[(uint8) (Y1 >> 8)] << 8) ^ (RSb[(uint8) (Y0)]); + + PUT_UINT32_BE (X0, output, 0); + PUT_UINT32_BE (X1, output, 4); + PUT_UINT32_BE (X2, output, 8); + PUT_UINT32_BE (X3, output, 12); } /* * AES-CBC buffer encryption */ -static void aes_cbc_encrypt( aes_context *ctx, - unsigned char iv[16], - unsigned char *input, - unsigned char *output, - int len ) +static void +aes_cbc_encrypt (aes_context * ctx, + unsigned char iv[16], + unsigned char *input, unsigned char *output, int len) { - int i; + int i; - while( len > 0 ) + while (len > 0) { - for( i = 0; i < 16; i++ ) - output[i] = input[i] ^ iv[i]; + for (i = 0; i < 16; i++) + output[i] = input[i] ^ iv[i]; - aes_encrypt( ctx, output, output ); - grub_memcpy( iv, output, 16 ); + aes_encrypt (ctx, output, output); + grub_memcpy (iv, output, 16); - input += 16; - output += 16; - len -= 16; + input += 16; + output += 16; + len -= 16; } } /* * AES-CBC buffer decryption */ -static void aes_cbc_decrypt( aes_context *ctx, - unsigned char iv[16], - unsigned char *input, - unsigned char *output, - int len ) +static void +aes_cbc_decrypt (aes_context * ctx, + unsigned char iv[16], + unsigned char *input, unsigned char *output, int len) { - int i; - unsigned char temp[16]; + int i; + unsigned char temp[16]; - while( len > 0 ) + while (len > 0) { - grub_memcpy( temp, input, 16 ); - aes_decrypt( ctx, input, output ); + grub_memcpy (temp, input, 16); + aes_decrypt (ctx, input, output); - for( i = 0; i < 16; i++ ) - output[i] = output[i] ^ iv[i]; + for (i = 0; i < 16; i++) + output[i] = output[i] ^ iv[i]; - grub_memcpy( iv, temp, 16 ); + grub_memcpy (iv, temp, 16); - input += 16; - output += 16; - len -= 16; + input += 16; + output += 16; + len -= 16; } } @@ -875,80 +902,82 @@ /* * AES-ECB test vectors (source: NIST, rijndael-vals.zip) */ -static const uint8 aes_enc_test[3][16] = -{ - { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, - 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F }, - { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, - 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 }, - { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, - 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 } +static const uint8 aes_enc_test[3][16] = { + {0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73, + 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F}, + {0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11, + 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14}, + {0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D, + 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4} }; - -static const uint8 aes_dec_test[3][16] = -{ - { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, - 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 }, - { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, - 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 }, - { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, - 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE } + +static const uint8 aes_dec_test[3][16] = { + {0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58, + 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0}, + {0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2, + 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4}, + {0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D, + 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE} }; /* * Checkup routine */ -int aes_self_test( int verbose ) +int +aes_self_test (int verbose) { - int i, j, u, v; - aes_context ctx; - unsigned char buf[32]; + int i, j, u, v; + aes_context ctx; + unsigned char buf[32]; - for( i = 0; i < 6; i++ ) + for (i = 0; i < 6; i++) { - u = i >> 1; - v = i & 1; - - if( verbose != 0 ) - printf( " AES-ECB-%3d (%s): ", 128 + u * 64, - ( v == 0 ) ? "enc" : "dec" ); - - memset( buf, 0, 32 ); - aes_set_key( &ctx, buf, 128 + u * 64 ); + u = i >> 1; + v = i & 1; - for( j = 0; j < 10000; j++ ) - { - if( v == 0 ) aes_encrypt( &ctx, buf, buf ); - if( v == 1 ) aes_decrypt( &ctx, buf, buf ); - } + if (verbose != 0) + printf (" AES-ECB-%3d (%s): ", 128 + u * 64, + (v == 0) ? "enc" : "dec"); + + memset (buf, 0, 32); + aes_set_key (&ctx, buf, 128 + u * 64); + + for (j = 0; j < 10000; j++) + { + if (v == 0) + aes_encrypt (&ctx, buf, buf); + if (v == 1) + aes_decrypt (&ctx, buf, buf); + } + + if ((v == 0 && memcmp (buf, aes_enc_test[u], 16) != 0) || + (v == 1 && memcmp (buf, aes_dec_test[u], 16) != 0)) + { + if (verbose != 0) + printf ("failed\n"); - if( ( v == 0 && memcmp( buf, aes_enc_test[u], 16 ) != 0 ) || - ( v == 1 && memcmp( buf, aes_dec_test[u], 16 ) != 0 ) ) - { - if( verbose != 0 ) - printf( "failed\n" ); + return (1); + } - return( 1 ); - } - - if( verbose != 0 ) - printf( "passed\n" ); + if (verbose != 0) + printf ("passed\n"); } - if( verbose != 0 ) - printf( "\n" ); + if (verbose != 0) + printf ("\n"); - return( 0 ); + return (0); } #endif /*** GNU GRUB2 interface ***/ -static grub_err_t grub_cipher_aes_init(grub_cipher_params_t params) +static grub_err_t +grub_cipher_aes_init (grub_cipher_params_t params) { - params->private = grub_malloc(sizeof(aes_context)); + params->private = grub_malloc (sizeof (aes_context)); - if(!params->private) + if (!params->private) return grub_errno; params->keysize = 32; @@ -956,57 +985,65 @@ return 0; } -static grub_err_t grub_cipher_aes_cbc_init(grub_cipher_params_t params) +static grub_err_t +grub_cipher_aes_cbc_init (grub_cipher_params_t params) { grub_err_t err; - if((err = grub_cipher_aes_init(params))) return err; - if(!(params->u.cipher.iv = grub_malloc(16))) return grub_errno; - grub_memset(params->u.cipher.iv, 0, 16); + if ((err = grub_cipher_aes_init (params))) + return err; + if (!(params->u.cipher.iv = grub_malloc (16))) + return grub_errno; + grub_memset (params->u.cipher.iv, 0, 16); params->u.cipher.iv_length = 16; return 0; } -static void grub_cipher_aes_deinit(grub_cipher_params_t params) +static void +grub_cipher_aes_deinit (grub_cipher_params_t params) { - grub_free(params->private); + grub_free (params->private); } -static void grub_cipher_aes_cbc_deinit(grub_cipher_params_t params) +static void +grub_cipher_aes_cbc_deinit (grub_cipher_params_t params) { - grub_free(params->u.cipher.iv); - grub_cipher_aes_deinit(params); + grub_free (params->u.cipher.iv); + grub_cipher_aes_deinit (params); } -static grub_err_t grub_cipher_aes_set_key(grub_cipher_params_t params, const char *key) +static grub_err_t +grub_cipher_aes_set_key (grub_cipher_params_t params, const char *key) { - aes_set_key(params->private, (uint8 *)key, params->keysize * 8); + aes_set_key (params->private, (uint8 *) key, params->keysize * 8); return 0; } -static grub_err_t grub_cipher_aes_decrypt_inplace(grub_cipher_params_t params, - char *buf, grub_size_t size) +static grub_err_t +grub_cipher_aes_decrypt_inplace (grub_cipher_params_t params, + char *buf, grub_size_t size) { grub_size_t i; - if(size % 16 != 0) - return grub_error(GRUB_ERR_BAD_ARGUMENT, "Size must be multiple of 16"); + if (size % 16 != 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Size must be multiple of 16"); - for(i = 0; i < size; i += 16) - aes_decrypt(params->private, (unsigned char *)buf + i, - (unsigned char *)buf + i); + for (i = 0; i < size; i += 16) + aes_decrypt (params->private, (unsigned char *) buf + i, + (unsigned char *) buf + i); return 0; } -static grub_err_t grub_cipher_aes_cbc_decrypt_inplace(grub_cipher_params_t params, - char *buf, grub_size_t size) +static grub_err_t +grub_cipher_aes_cbc_decrypt_inplace (grub_cipher_params_t params, + char *buf, grub_size_t size) { - if(params->u.cipher.iv_length != 16) - return grub_error(GRUB_ERR_BAD_ARGUMENT, "IV length incorrect"); + if (params->u.cipher.iv_length != 16) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "IV length incorrect"); - aes_cbc_decrypt(params->private, params->u.cipher.iv, (unsigned char *)buf, - (unsigned char *)buf, size); + aes_cbc_decrypt (params->private, params->u.cipher.iv, + (unsigned char *) buf, (unsigned char *) buf, size); return 0; } @@ -1018,45 +1055,42 @@ .name = "aes", .type = GRUB_CIPHER_TYPE_CIPHER, .keysizes = aes_keysizes, - .keysizes_length = FIELDSOF(aes_keysizes), + .keysizes_length = FIELDSOF (aes_keysizes), .init = grub_cipher_aes_init, .deinit = grub_cipher_aes_deinit, .u.cipher = { - .set_key = grub_cipher_aes_set_key, - .encrypt = NULL, - .decrypt = NULL, - .decrypt_inplace = grub_cipher_aes_decrypt_inplace, - .encrypt_inplace = NULL - } + .set_key = grub_cipher_aes_set_key, + .encrypt = NULL, + .decrypt = NULL, + .decrypt_inplace = grub_cipher_aes_decrypt_inplace, + .encrypt_inplace = NULL} }; static struct grub_cipher grub_cipher_aes_cbc = { .name = "aes-cbc", .type = GRUB_CIPHER_TYPE_CIPHER, .keysizes = aes_keysizes, - .keysizes_length = FIELDSOF(aes_keysizes), + .keysizes_length = FIELDSOF (aes_keysizes), .init = grub_cipher_aes_cbc_init, .deinit = grub_cipher_aes_cbc_deinit, .u.cipher = { - .set_key = grub_cipher_aes_set_key, - .encrypt = NULL, - .decrypt = NULL, - .decrypt_inplace = grub_cipher_aes_cbc_decrypt_inplace, - .encrypt_inplace = NULL - } + .set_key = grub_cipher_aes_set_key, + .encrypt = NULL, + .decrypt = NULL, + .decrypt_inplace = grub_cipher_aes_cbc_decrypt_inplace, + .encrypt_inplace = NULL} }; -GRUB_MOD_INIT(aes) +GRUB_MOD_INIT (aes) { - (void)mod; /* To stop warning. */ - grub_crypto_cipher_register(&grub_cipher_aes); - grub_crypto_cipher_register(&grub_cipher_aes_cbc); + grub_crypto_cipher_register (&grub_cipher_aes); + grub_crypto_cipher_register (&grub_cipher_aes_cbc); } -GRUB_MOD_FINI(aes) +GRUB_MOD_FINI (aes) { - grub_crypto_cipher_unregister(&grub_cipher_aes); - grub_crypto_cipher_unregister(&grub_cipher_aes_cbc); + grub_crypto_cipher_unregister (&grub_cipher_aes); + grub_crypto_cipher_unregister (&grub_cipher_aes_cbc); } diff -u -r -x CVS -N grub2/crypto/crypto.c grub2-new/crypto/crypto.c --- grub2/crypto/crypto.c 2007-09-03 20:40:37.000000000 +0200 +++ grub2-new/crypto/crypto.c 2007-09-03 20:25:40.000000000 +0200 @@ -31,108 +31,116 @@ #define MAX(a, b) (a > b ? a : b) -struct cipher_list { - grub_cipher_t cipher; - struct cipher_list *next; +struct cipher_list +{ + grub_cipher_t cipher; + struct cipher_list *next; }; static struct cipher_list *cipher_list = NULL; grub_err_t -grub_crypto_hash(grub_cipher_params_t params, char *hash, const char *payload, - unsigned int size) +grub_crypto_hash (grub_cipher_params_t params, char *hash, + const char *payload, unsigned int size) { - return params->cipher->u.hash.fn(params, hash, payload, size); + return params->cipher->u.hash.fn (params, hash, payload, size); } static grub_cipher_t -get_cipher(const char *name, grub_cipher_type_t type) +get_cipher (const char *name, grub_cipher_type_t type) { struct cipher_list *i; - for(i = cipher_list; i != NULL; i = i->next) - if(!grub_strcmp(i->cipher->name, name) && i->cipher->type == type) + for (i = cipher_list; i != NULL; i = i->next) + if (!grub_strcmp (i->cipher->name, name) && i->cipher->type == type) return i->cipher; return NULL; } grub_err_t -grub_crypto_new_cipher(grub_cipher_params_t *params, const char *name, - grub_cipher_type_t type) +grub_crypto_new_cipher (grub_cipher_params_t * params, const char *name, + grub_cipher_type_t type) { - grub_cipher_t cipher = get_cipher(name, type); - grub_err_t err; - - if(cipher == NULL) { - const char *errstr = "Illegal cipher type"; + grub_cipher_t cipher = get_cipher (name, type); + grub_err_t err; - switch(type) { - case GRUB_CIPHER_TYPE_NONE: - break; - - case GRUB_CIPHER_TYPE_CIPHER: - errstr = "Unknown cipher"; - break; + if (cipher == NULL) + { + const char *errstr = "Illegal cipher type"; + + switch (type) + { + case GRUB_CIPHER_TYPE_NONE: + break; + + case GRUB_CIPHER_TYPE_CIPHER: + errstr = "Unknown cipher"; + break; + + case GRUB_CIPHER_TYPE_HASH: + errstr = "Unknown hash"; + break; + } - case GRUB_CIPHER_TYPE_HASH: - errstr = "Unknown hash"; - break; + return grub_error (GRUB_ERR_BAD_ARGUMENT, errstr); } - return grub_error(GRUB_ERR_BAD_ARGUMENT, errstr); - } - - *params = grub_malloc(sizeof(struct grub_cipher_params)); - if(*params == NULL) + *params = grub_malloc (sizeof (struct grub_cipher_params)); + if (*params == NULL) return grub_errno; - if(cipher->init) { - if((err = cipher->init(*params)) != GRUB_ERR_NONE) { - grub_free(*params); - return err; + if (cipher->init) + { + if ((err = cipher->init (*params)) != GRUB_ERR_NONE) + { + grub_free (*params); + return err; + } } - } else { - unsigned int i, keysize = 0; + else + { + unsigned int i, keysize = 0; - /* Set keysize to largest */ - for(i = 0; i < cipher->keysizes_length; i++) - keysize = MAX(keysize, cipher->keysizes[i]); + /* Set keysize to largest */ + for (i = 0; i < cipher->keysizes_length; i++) + keysize = MAX (keysize, cipher->keysizes[i]); - (*params)->keysize = keysize; - } + (*params)->keysize = keysize; + } (*params)->cipher = cipher; return GRUB_ERR_NONE; } void -grub_crypto_delete_cipher(grub_cipher_params_t params) +grub_crypto_delete_cipher (grub_cipher_params_t params) { - if(params->cipher->deinit) - params->cipher->deinit(params); + if (params->cipher->deinit) + params->cipher->deinit (params); - grub_free(params); + grub_free (params); } int -grub_crypto_cipher_iterate(grub_crypto_hook hook, void *data) +grub_crypto_cipher_iterate (grub_crypto_hook hook, void *data) { struct cipher_list *i; - for(i = cipher_list; i != NULL; i = i->next) - if(hook(i->cipher, data)) + for (i = cipher_list; i != NULL; i = i->next) + if (hook (i->cipher, data)) return 1; return 0; } void -grub_crypto_cipher_register(grub_cipher_t cipher) +grub_crypto_cipher_register (grub_cipher_t cipher) { - struct cipher_list *newcipher = grub_malloc(sizeof(struct cipher_list)); + struct cipher_list *newcipher = grub_malloc (sizeof (struct cipher_list)); - if(!newcipher) return; /* out of memory! */ + if (!newcipher) + return; /* out of memory! */ newcipher->cipher = cipher; newcipher->next = cipher_list; @@ -140,67 +148,75 @@ } void -grub_crypto_cipher_unregister(grub_cipher_t cipher) +grub_crypto_cipher_unregister (grub_cipher_t cipher) { struct cipher_list *i, **prev; - for(i = cipher_list, prev = &cipher_list; i != NULL; prev = &i->next, i = i->next) - if(!grub_strcmp(i->cipher->name, cipher->name)) + for (i = cipher_list, prev = &cipher_list; i != NULL; + prev = &i->next, i = i->next) + if (!grub_strcmp (i->cipher->name, cipher->name)) break; - if(!i) { - grub_printf("BUG: Trying to unregister a non-registered cipher!\n"); - return; - } + if (!i) + { + grub_printf ("BUG: Trying to unregister a non-registered cipher!\n"); + return; + } /* Remove cipher from list */ *prev = i->next; - grub_free(i); + grub_free (i); } grub_err_t -grub_crypto_set_key(grub_cipher_params_t params, const char *key) +grub_crypto_set_key (grub_cipher_params_t params, const char *key) { - if(params->cipher->u.cipher.set_key) - return params->cipher->u.cipher.set_key(params, key); + if (params->cipher->u.cipher.set_key) + return params->cipher->u.cipher.set_key (params, key); else return GRUB_ERR_NONE; } -grub_err_t grub_crypto_encrypt(grub_cipher_params_t params, char **out, - const char *in, grub_size_t *outsize, - grub_size_t insize) -{ - if(params->cipher->u.cipher.encrypt) - return params->cipher->u.cipher.encrypt(params, out, in, outsize, insize); +grub_err_t +grub_crypto_encrypt (grub_cipher_params_t params, char **out, + const char *in, grub_size_t * outsize, + grub_size_t insize) +{ + if (params->cipher->u.cipher.encrypt) + return params->cipher->u.cipher.encrypt (params, out, in, outsize, + insize); else return GRUB_ERR_NOT_IMPLEMENTED_YET; } -grub_err_t grub_crypto_decrypt(grub_cipher_params_t params, char **out, - const char *in, grub_size_t *outsize, - grub_size_t insize) -{ - if(params->cipher->u.cipher.decrypt) - return params->cipher->u.cipher.decrypt(params, out, in, outsize, insize); +grub_err_t +grub_crypto_decrypt (grub_cipher_params_t params, char **out, + const char *in, grub_size_t * outsize, + grub_size_t insize) +{ + if (params->cipher->u.cipher.decrypt) + return params->cipher->u.cipher.decrypt (params, out, in, outsize, + insize); else return GRUB_ERR_NOT_IMPLEMENTED_YET; } -grub_err_t grub_crypto_decrypt_inplace(grub_cipher_params_t params, char *buf, - grub_size_t size) +grub_err_t +grub_crypto_decrypt_inplace (grub_cipher_params_t params, char *buf, + grub_size_t size) { - if(params->cipher->u.cipher.decrypt_inplace) - return params->cipher->u.cipher.decrypt_inplace(params, buf, size); + if (params->cipher->u.cipher.decrypt_inplace) + return params->cipher->u.cipher.decrypt_inplace (params, buf, size); else return GRUB_ERR_NOT_IMPLEMENTED_YET; } -grub_err_t grub_crypto_encrypt_inplace(grub_cipher_params_t params, char *buf, - grub_size_t size) +grub_err_t +grub_crypto_encrypt_inplace (grub_cipher_params_t params, char *buf, + grub_size_t size) { - if(params->cipher->u.cipher.encrypt_inplace) - return params->cipher->u.cipher.encrypt_inplace(params, buf, size); + if (params->cipher->u.cipher.encrypt_inplace) + return params->cipher->u.cipher.encrypt_inplace (params, buf, size); else return GRUB_ERR_NOT_IMPLEMENTED_YET; } @@ -208,29 +224,33 @@ /***** None cipher interface ***********************************************/ static grub_err_t -cipher_none_crypt(grub_cipher_params_t unused, char **out, const char *in, grub_size_t *outsize, grub_size_t insize) +cipher_none_crypt (grub_cipher_params_t unused, char **out, const char *in, + grub_size_t * outsize, grub_size_t insize) { - (void)unused; - if(!(*out = grub_malloc(insize))) return grub_errno; - *out = grub_memcpy(*out, in, insize); + (void) unused; + if (!(*out = grub_malloc (insize))) + return grub_errno; + *out = grub_memcpy (*out, in, insize); *outsize = insize; return 0; } static grub_err_t -cipher_none_crypt_inplace(grub_cipher_params_t unused, char *buf, grub_size_t size) +cipher_none_crypt_inplace (grub_cipher_params_t unused, char *buf, + grub_size_t size) { - (void)unused; - (void)buf; - (void)size; + (void) unused; + (void) buf; + (void) size; return 0; } static grub_err_t -hash_none_fn(grub_cipher_params_t params, char *out, const char *in, grub_size_t insize) +hash_none_fn (grub_cipher_params_t params, char *out, const char *in, + grub_size_t insize) { params->keysize = insize; - grub_memcpy(out, in, insize); + grub_memcpy (out, in, insize); return 0; } @@ -240,11 +260,10 @@ .keysizes_length = 0, .u.cipher = { - .encrypt = cipher_none_crypt, - .decrypt = cipher_none_crypt, - .decrypt_inplace = cipher_none_crypt_inplace, - .encrypt_inplace = cipher_none_crypt_inplace - } + .encrypt = cipher_none_crypt, + .decrypt = cipher_none_crypt, + .decrypt_inplace = cipher_none_crypt_inplace, + .encrypt_inplace = cipher_none_crypt_inplace} }; static struct grub_cipher grub_hash_none = { @@ -256,15 +275,14 @@ /***** GRUB module (de-)initialization *************************************/ -GRUB_MOD_INIT(crypto) +GRUB_MOD_INIT (crypto) { - (void)mod; /* To stop warning. */ - grub_crypto_cipher_register(&grub_cipher_none); - grub_crypto_cipher_register(&grub_hash_none); + grub_crypto_cipher_register (&grub_cipher_none); + grub_crypto_cipher_register (&grub_hash_none); } -GRUB_MOD_FINI(crypto) +GRUB_MOD_FINI (crypto) { - grub_crypto_cipher_unregister(&grub_hash_none); - grub_crypto_cipher_unregister(&grub_cipher_none); + grub_crypto_cipher_unregister (&grub_hash_none); + grub_crypto_cipher_unregister (&grub_cipher_none); } diff -u -r -x CVS -N grub2/crypto/rmd160.c grub2-new/crypto/rmd160.c --- grub2/crypto/rmd160.c 2007-09-03 20:40:37.000000000 +0200 +++ grub2-new/crypto/rmd160.c 2007-09-03 20:25:42.000000000 +0200 @@ -50,8 +50,8 @@ /* typedef 8 and 32 bit types, resp. */ /* adapt these, if necessary, for your operating system and compiler */ -typedef unsigned char byte; -typedef unsigned long dword; +typedef unsigned char byte; +typedef unsigned long dword; /* macro definitions */ @@ -67,12 +67,12 @@ #define ROL(x, n) (((x) << (n)) | ((x) >> (32-(n)))) /* the five basic functions F(), G() and H() */ -#define F(x, y, z) ((x) ^ (y) ^ (z)) -#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define F(x, y, z) ((x) ^ (y) ^ (z)) +#define G(x, y, z) (((x) & (y)) | (~(x) & (z))) #define H(x, y, z) (((x) | ~(y)) ^ (z)) -#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define I(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define J(x, y, z) ((x) ^ ((y) | ~(z))) - + /* the ten basic operations FF() through III() */ #define FF(a, b, c, d, e, x, s) {\ (a) += F((b), (c), (d)) + (x);\ @@ -127,304 +127,311 @@ /********************************************************************/ -static void MDinit(dword *MDbuf) +static void +MDinit (dword * MDbuf) { - MDbuf[0] = 0x67452301UL; - MDbuf[1] = 0xefcdab89UL; - MDbuf[2] = 0x98badcfeUL; - MDbuf[3] = 0x10325476UL; - MDbuf[4] = 0xc3d2e1f0UL; + MDbuf[0] = 0x67452301UL; + MDbuf[1] = 0xefcdab89UL; + MDbuf[2] = 0x98badcfeUL; + MDbuf[3] = 0x10325476UL; + MDbuf[4] = 0xc3d2e1f0UL; - return; + return; } /********************************************************************/ -static void compress(dword *MDbuf, dword *X) +static void +compress (dword * MDbuf, dword * X) { - dword aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2], - dd = MDbuf[3], ee = MDbuf[4]; - dword aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2], - ddd = MDbuf[3], eee = MDbuf[4]; - - /* round 1 */ - FF(aa, bb, cc, dd, ee, X[ 0], 11); - FF(ee, aa, bb, cc, dd, X[ 1], 14); - FF(dd, ee, aa, bb, cc, X[ 2], 15); - FF(cc, dd, ee, aa, bb, X[ 3], 12); - FF(bb, cc, dd, ee, aa, X[ 4], 5); - FF(aa, bb, cc, dd, ee, X[ 5], 8); - FF(ee, aa, bb, cc, dd, X[ 6], 7); - FF(dd, ee, aa, bb, cc, X[ 7], 9); - FF(cc, dd, ee, aa, bb, X[ 8], 11); - FF(bb, cc, dd, ee, aa, X[ 9], 13); - FF(aa, bb, cc, dd, ee, X[10], 14); - FF(ee, aa, bb, cc, dd, X[11], 15); - FF(dd, ee, aa, bb, cc, X[12], 6); - FF(cc, dd, ee, aa, bb, X[13], 7); - FF(bb, cc, dd, ee, aa, X[14], 9); - FF(aa, bb, cc, dd, ee, X[15], 8); - - /* round 2 */ - GG(ee, aa, bb, cc, dd, X[ 7], 7); - GG(dd, ee, aa, bb, cc, X[ 4], 6); - GG(cc, dd, ee, aa, bb, X[13], 8); - GG(bb, cc, dd, ee, aa, X[ 1], 13); - GG(aa, bb, cc, dd, ee, X[10], 11); - GG(ee, aa, bb, cc, dd, X[ 6], 9); - GG(dd, ee, aa, bb, cc, X[15], 7); - GG(cc, dd, ee, aa, bb, X[ 3], 15); - GG(bb, cc, dd, ee, aa, X[12], 7); - GG(aa, bb, cc, dd, ee, X[ 0], 12); - GG(ee, aa, bb, cc, dd, X[ 9], 15); - GG(dd, ee, aa, bb, cc, X[ 5], 9); - GG(cc, dd, ee, aa, bb, X[ 2], 11); - GG(bb, cc, dd, ee, aa, X[14], 7); - GG(aa, bb, cc, dd, ee, X[11], 13); - GG(ee, aa, bb, cc, dd, X[ 8], 12); - - /* round 3 */ - HH(dd, ee, aa, bb, cc, X[ 3], 11); - HH(cc, dd, ee, aa, bb, X[10], 13); - HH(bb, cc, dd, ee, aa, X[14], 6); - HH(aa, bb, cc, dd, ee, X[ 4], 7); - HH(ee, aa, bb, cc, dd, X[ 9], 14); - HH(dd, ee, aa, bb, cc, X[15], 9); - HH(cc, dd, ee, aa, bb, X[ 8], 13); - HH(bb, cc, dd, ee, aa, X[ 1], 15); - HH(aa, bb, cc, dd, ee, X[ 2], 14); - HH(ee, aa, bb, cc, dd, X[ 7], 8); - HH(dd, ee, aa, bb, cc, X[ 0], 13); - HH(cc, dd, ee, aa, bb, X[ 6], 6); - HH(bb, cc, dd, ee, aa, X[13], 5); - HH(aa, bb, cc, dd, ee, X[11], 12); - HH(ee, aa, bb, cc, dd, X[ 5], 7); - HH(dd, ee, aa, bb, cc, X[12], 5); - - /* round 4 */ - II(cc, dd, ee, aa, bb, X[ 1], 11); - II(bb, cc, dd, ee, aa, X[ 9], 12); - II(aa, bb, cc, dd, ee, X[11], 14); - II(ee, aa, bb, cc, dd, X[10], 15); - II(dd, ee, aa, bb, cc, X[ 0], 14); - II(cc, dd, ee, aa, bb, X[ 8], 15); - II(bb, cc, dd, ee, aa, X[12], 9); - II(aa, bb, cc, dd, ee, X[ 4], 8); - II(ee, aa, bb, cc, dd, X[13], 9); - II(dd, ee, aa, bb, cc, X[ 3], 14); - II(cc, dd, ee, aa, bb, X[ 7], 5); - II(bb, cc, dd, ee, aa, X[15], 6); - II(aa, bb, cc, dd, ee, X[14], 8); - II(ee, aa, bb, cc, dd, X[ 5], 6); - II(dd, ee, aa, bb, cc, X[ 6], 5); - II(cc, dd, ee, aa, bb, X[ 2], 12); - - /* round 5 */ - JJ(bb, cc, dd, ee, aa, X[ 4], 9); - JJ(aa, bb, cc, dd, ee, X[ 0], 15); - JJ(ee, aa, bb, cc, dd, X[ 5], 5); - JJ(dd, ee, aa, bb, cc, X[ 9], 11); - JJ(cc, dd, ee, aa, bb, X[ 7], 6); - JJ(bb, cc, dd, ee, aa, X[12], 8); - JJ(aa, bb, cc, dd, ee, X[ 2], 13); - JJ(ee, aa, bb, cc, dd, X[10], 12); - JJ(dd, ee, aa, bb, cc, X[14], 5); - JJ(cc, dd, ee, aa, bb, X[ 1], 12); - JJ(bb, cc, dd, ee, aa, X[ 3], 13); - JJ(aa, bb, cc, dd, ee, X[ 8], 14); - JJ(ee, aa, bb, cc, dd, X[11], 11); - JJ(dd, ee, aa, bb, cc, X[ 6], 8); - JJ(cc, dd, ee, aa, bb, X[15], 5); - JJ(bb, cc, dd, ee, aa, X[13], 6); - - /* parallel round 1 */ - JJJ(aaa, bbb, ccc, ddd, eee, X[ 5], 8); - JJJ(eee, aaa, bbb, ccc, ddd, X[14], 9); - JJJ(ddd, eee, aaa, bbb, ccc, X[ 7], 9); - JJJ(ccc, ddd, eee, aaa, bbb, X[ 0], 11); - JJJ(bbb, ccc, ddd, eee, aaa, X[ 9], 13); - JJJ(aaa, bbb, ccc, ddd, eee, X[ 2], 15); - JJJ(eee, aaa, bbb, ccc, ddd, X[11], 15); - JJJ(ddd, eee, aaa, bbb, ccc, X[ 4], 5); - JJJ(ccc, ddd, eee, aaa, bbb, X[13], 7); - JJJ(bbb, ccc, ddd, eee, aaa, X[ 6], 7); - JJJ(aaa, bbb, ccc, ddd, eee, X[15], 8); - JJJ(eee, aaa, bbb, ccc, ddd, X[ 8], 11); - JJJ(ddd, eee, aaa, bbb, ccc, X[ 1], 14); - JJJ(ccc, ddd, eee, aaa, bbb, X[10], 14); - JJJ(bbb, ccc, ddd, eee, aaa, X[ 3], 12); - JJJ(aaa, bbb, ccc, ddd, eee, X[12], 6); - - /* parallel round 2 */ - III(eee, aaa, bbb, ccc, ddd, X[ 6], 9); - III(ddd, eee, aaa, bbb, ccc, X[11], 13); - III(ccc, ddd, eee, aaa, bbb, X[ 3], 15); - III(bbb, ccc, ddd, eee, aaa, X[ 7], 7); - III(aaa, bbb, ccc, ddd, eee, X[ 0], 12); - III(eee, aaa, bbb, ccc, ddd, X[13], 8); - III(ddd, eee, aaa, bbb, ccc, X[ 5], 9); - III(ccc, ddd, eee, aaa, bbb, X[10], 11); - III(bbb, ccc, ddd, eee, aaa, X[14], 7); - III(aaa, bbb, ccc, ddd, eee, X[15], 7); - III(eee, aaa, bbb, ccc, ddd, X[ 8], 12); - III(ddd, eee, aaa, bbb, ccc, X[12], 7); - III(ccc, ddd, eee, aaa, bbb, X[ 4], 6); - III(bbb, ccc, ddd, eee, aaa, X[ 9], 15); - III(aaa, bbb, ccc, ddd, eee, X[ 1], 13); - III(eee, aaa, bbb, ccc, ddd, X[ 2], 11); - - /* parallel round 3 */ - HHH(ddd, eee, aaa, bbb, ccc, X[15], 9); - HHH(ccc, ddd, eee, aaa, bbb, X[ 5], 7); - HHH(bbb, ccc, ddd, eee, aaa, X[ 1], 15); - HHH(aaa, bbb, ccc, ddd, eee, X[ 3], 11); - HHH(eee, aaa, bbb, ccc, ddd, X[ 7], 8); - HHH(ddd, eee, aaa, bbb, ccc, X[14], 6); - HHH(ccc, ddd, eee, aaa, bbb, X[ 6], 6); - HHH(bbb, ccc, ddd, eee, aaa, X[ 9], 14); - HHH(aaa, bbb, ccc, ddd, eee, X[11], 12); - HHH(eee, aaa, bbb, ccc, ddd, X[ 8], 13); - HHH(ddd, eee, aaa, bbb, ccc, X[12], 5); - HHH(ccc, ddd, eee, aaa, bbb, X[ 2], 14); - HHH(bbb, ccc, ddd, eee, aaa, X[10], 13); - HHH(aaa, bbb, ccc, ddd, eee, X[ 0], 13); - HHH(eee, aaa, bbb, ccc, ddd, X[ 4], 7); - HHH(ddd, eee, aaa, bbb, ccc, X[13], 5); - - /* parallel round 4 */ - GGG(ccc, ddd, eee, aaa, bbb, X[ 8], 15); - GGG(bbb, ccc, ddd, eee, aaa, X[ 6], 5); - GGG(aaa, bbb, ccc, ddd, eee, X[ 4], 8); - GGG(eee, aaa, bbb, ccc, ddd, X[ 1], 11); - GGG(ddd, eee, aaa, bbb, ccc, X[ 3], 14); - GGG(ccc, ddd, eee, aaa, bbb, X[11], 14); - GGG(bbb, ccc, ddd, eee, aaa, X[15], 6); - GGG(aaa, bbb, ccc, ddd, eee, X[ 0], 14); - GGG(eee, aaa, bbb, ccc, ddd, X[ 5], 6); - GGG(ddd, eee, aaa, bbb, ccc, X[12], 9); - GGG(ccc, ddd, eee, aaa, bbb, X[ 2], 12); - GGG(bbb, ccc, ddd, eee, aaa, X[13], 9); - GGG(aaa, bbb, ccc, ddd, eee, X[ 9], 12); - GGG(eee, aaa, bbb, ccc, ddd, X[ 7], 5); - GGG(ddd, eee, aaa, bbb, ccc, X[10], 15); - GGG(ccc, ddd, eee, aaa, bbb, X[14], 8); - - /* parallel round 5 */ - FFF(bbb, ccc, ddd, eee, aaa, X[12] , 8); - FFF(aaa, bbb, ccc, ddd, eee, X[15] , 5); - FFF(eee, aaa, bbb, ccc, ddd, X[10] , 12); - FFF(ddd, eee, aaa, bbb, ccc, X[ 4] , 9); - FFF(ccc, ddd, eee, aaa, bbb, X[ 1] , 12); - FFF(bbb, ccc, ddd, eee, aaa, X[ 5] , 5); - FFF(aaa, bbb, ccc, ddd, eee, X[ 8] , 14); - FFF(eee, aaa, bbb, ccc, ddd, X[ 7] , 6); - FFF(ddd, eee, aaa, bbb, ccc, X[ 6] , 8); - FFF(ccc, ddd, eee, aaa, bbb, X[ 2] , 13); - FFF(bbb, ccc, ddd, eee, aaa, X[13] , 6); - FFF(aaa, bbb, ccc, ddd, eee, X[14] , 5); - FFF(eee, aaa, bbb, ccc, ddd, X[ 0] , 15); - FFF(ddd, eee, aaa, bbb, ccc, X[ 3] , 13); - FFF(ccc, ddd, eee, aaa, bbb, X[ 9] , 11); - FFF(bbb, ccc, ddd, eee, aaa, X[11] , 11); - - /* combine results */ - ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */ - MDbuf[1] = MDbuf[2] + dd + eee; - MDbuf[2] = MDbuf[3] + ee + aaa; - MDbuf[3] = MDbuf[4] + aa + bbb; - MDbuf[4] = MDbuf[0] + bb + ccc; - MDbuf[0] = ddd; + dword aa = MDbuf[0], bb = MDbuf[1], cc = MDbuf[2], + dd = MDbuf[3], ee = MDbuf[4]; + dword aaa = MDbuf[0], bbb = MDbuf[1], ccc = MDbuf[2], + ddd = MDbuf[3], eee = MDbuf[4]; + + /* round 1 */ + FF (aa, bb, cc, dd, ee, X[0], 11); + FF (ee, aa, bb, cc, dd, X[1], 14); + FF (dd, ee, aa, bb, cc, X[2], 15); + FF (cc, dd, ee, aa, bb, X[3], 12); + FF (bb, cc, dd, ee, aa, X[4], 5); + FF (aa, bb, cc, dd, ee, X[5], 8); + FF (ee, aa, bb, cc, dd, X[6], 7); + FF (dd, ee, aa, bb, cc, X[7], 9); + FF (cc, dd, ee, aa, bb, X[8], 11); + FF (bb, cc, dd, ee, aa, X[9], 13); + FF (aa, bb, cc, dd, ee, X[10], 14); + FF (ee, aa, bb, cc, dd, X[11], 15); + FF (dd, ee, aa, bb, cc, X[12], 6); + FF (cc, dd, ee, aa, bb, X[13], 7); + FF (bb, cc, dd, ee, aa, X[14], 9); + FF (aa, bb, cc, dd, ee, X[15], 8); + + /* round 2 */ + GG (ee, aa, bb, cc, dd, X[7], 7); + GG (dd, ee, aa, bb, cc, X[4], 6); + GG (cc, dd, ee, aa, bb, X[13], 8); + GG (bb, cc, dd, ee, aa, X[1], 13); + GG (aa, bb, cc, dd, ee, X[10], 11); + GG (ee, aa, bb, cc, dd, X[6], 9); + GG (dd, ee, aa, bb, cc, X[15], 7); + GG (cc, dd, ee, aa, bb, X[3], 15); + GG (bb, cc, dd, ee, aa, X[12], 7); + GG (aa, bb, cc, dd, ee, X[0], 12); + GG (ee, aa, bb, cc, dd, X[9], 15); + GG (dd, ee, aa, bb, cc, X[5], 9); + GG (cc, dd, ee, aa, bb, X[2], 11); + GG (bb, cc, dd, ee, aa, X[14], 7); + GG (aa, bb, cc, dd, ee, X[11], 13); + GG (ee, aa, bb, cc, dd, X[8], 12); + + /* round 3 */ + HH (dd, ee, aa, bb, cc, X[3], 11); + HH (cc, dd, ee, aa, bb, X[10], 13); + HH (bb, cc, dd, ee, aa, X[14], 6); + HH (aa, bb, cc, dd, ee, X[4], 7); + HH (ee, aa, bb, cc, dd, X[9], 14); + HH (dd, ee, aa, bb, cc, X[15], 9); + HH (cc, dd, ee, aa, bb, X[8], 13); + HH (bb, cc, dd, ee, aa, X[1], 15); + HH (aa, bb, cc, dd, ee, X[2], 14); + HH (ee, aa, bb, cc, dd, X[7], 8); + HH (dd, ee, aa, bb, cc, X[0], 13); + HH (cc, dd, ee, aa, bb, X[6], 6); + HH (bb, cc, dd, ee, aa, X[13], 5); + HH (aa, bb, cc, dd, ee, X[11], 12); + HH (ee, aa, bb, cc, dd, X[5], 7); + HH (dd, ee, aa, bb, cc, X[12], 5); + + /* round 4 */ + II (cc, dd, ee, aa, bb, X[1], 11); + II (bb, cc, dd, ee, aa, X[9], 12); + II (aa, bb, cc, dd, ee, X[11], 14); + II (ee, aa, bb, cc, dd, X[10], 15); + II (dd, ee, aa, bb, cc, X[0], 14); + II (cc, dd, ee, aa, bb, X[8], 15); + II (bb, cc, dd, ee, aa, X[12], 9); + II (aa, bb, cc, dd, ee, X[4], 8); + II (ee, aa, bb, cc, dd, X[13], 9); + II (dd, ee, aa, bb, cc, X[3], 14); + II (cc, dd, ee, aa, bb, X[7], 5); + II (bb, cc, dd, ee, aa, X[15], 6); + II (aa, bb, cc, dd, ee, X[14], 8); + II (ee, aa, bb, cc, dd, X[5], 6); + II (dd, ee, aa, bb, cc, X[6], 5); + II (cc, dd, ee, aa, bb, X[2], 12); + + /* round 5 */ + JJ (bb, cc, dd, ee, aa, X[4], 9); + JJ (aa, bb, cc, dd, ee, X[0], 15); + JJ (ee, aa, bb, cc, dd, X[5], 5); + JJ (dd, ee, aa, bb, cc, X[9], 11); + JJ (cc, dd, ee, aa, bb, X[7], 6); + JJ (bb, cc, dd, ee, aa, X[12], 8); + JJ (aa, bb, cc, dd, ee, X[2], 13); + JJ (ee, aa, bb, cc, dd, X[10], 12); + JJ (dd, ee, aa, bb, cc, X[14], 5); + JJ (cc, dd, ee, aa, bb, X[1], 12); + JJ (bb, cc, dd, ee, aa, X[3], 13); + JJ (aa, bb, cc, dd, ee, X[8], 14); + JJ (ee, aa, bb, cc, dd, X[11], 11); + JJ (dd, ee, aa, bb, cc, X[6], 8); + JJ (cc, dd, ee, aa, bb, X[15], 5); + JJ (bb, cc, dd, ee, aa, X[13], 6); + + /* parallel round 1 */ + JJJ (aaa, bbb, ccc, ddd, eee, X[5], 8); + JJJ (eee, aaa, bbb, ccc, ddd, X[14], 9); + JJJ (ddd, eee, aaa, bbb, ccc, X[7], 9); + JJJ (ccc, ddd, eee, aaa, bbb, X[0], 11); + JJJ (bbb, ccc, ddd, eee, aaa, X[9], 13); + JJJ (aaa, bbb, ccc, ddd, eee, X[2], 15); + JJJ (eee, aaa, bbb, ccc, ddd, X[11], 15); + JJJ (ddd, eee, aaa, bbb, ccc, X[4], 5); + JJJ (ccc, ddd, eee, aaa, bbb, X[13], 7); + JJJ (bbb, ccc, ddd, eee, aaa, X[6], 7); + JJJ (aaa, bbb, ccc, ddd, eee, X[15], 8); + JJJ (eee, aaa, bbb, ccc, ddd, X[8], 11); + JJJ (ddd, eee, aaa, bbb, ccc, X[1], 14); + JJJ (ccc, ddd, eee, aaa, bbb, X[10], 14); + JJJ (bbb, ccc, ddd, eee, aaa, X[3], 12); + JJJ (aaa, bbb, ccc, ddd, eee, X[12], 6); + + /* parallel round 2 */ + III (eee, aaa, bbb, ccc, ddd, X[6], 9); + III (ddd, eee, aaa, bbb, ccc, X[11], 13); + III (ccc, ddd, eee, aaa, bbb, X[3], 15); + III (bbb, ccc, ddd, eee, aaa, X[7], 7); + III (aaa, bbb, ccc, ddd, eee, X[0], 12); + III (eee, aaa, bbb, ccc, ddd, X[13], 8); + III (ddd, eee, aaa, bbb, ccc, X[5], 9); + III (ccc, ddd, eee, aaa, bbb, X[10], 11); + III (bbb, ccc, ddd, eee, aaa, X[14], 7); + III (aaa, bbb, ccc, ddd, eee, X[15], 7); + III (eee, aaa, bbb, ccc, ddd, X[8], 12); + III (ddd, eee, aaa, bbb, ccc, X[12], 7); + III (ccc, ddd, eee, aaa, bbb, X[4], 6); + III (bbb, ccc, ddd, eee, aaa, X[9], 15); + III (aaa, bbb, ccc, ddd, eee, X[1], 13); + III (eee, aaa, bbb, ccc, ddd, X[2], 11); + + /* parallel round 3 */ + HHH (ddd, eee, aaa, bbb, ccc, X[15], 9); + HHH (ccc, ddd, eee, aaa, bbb, X[5], 7); + HHH (bbb, ccc, ddd, eee, aaa, X[1], 15); + HHH (aaa, bbb, ccc, ddd, eee, X[3], 11); + HHH (eee, aaa, bbb, ccc, ddd, X[7], 8); + HHH (ddd, eee, aaa, bbb, ccc, X[14], 6); + HHH (ccc, ddd, eee, aaa, bbb, X[6], 6); + HHH (bbb, ccc, ddd, eee, aaa, X[9], 14); + HHH (aaa, bbb, ccc, ddd, eee, X[11], 12); + HHH (eee, aaa, bbb, ccc, ddd, X[8], 13); + HHH (ddd, eee, aaa, bbb, ccc, X[12], 5); + HHH (ccc, ddd, eee, aaa, bbb, X[2], 14); + HHH (bbb, ccc, ddd, eee, aaa, X[10], 13); + HHH (aaa, bbb, ccc, ddd, eee, X[0], 13); + HHH (eee, aaa, bbb, ccc, ddd, X[4], 7); + HHH (ddd, eee, aaa, bbb, ccc, X[13], 5); + + /* parallel round 4 */ + GGG (ccc, ddd, eee, aaa, bbb, X[8], 15); + GGG (bbb, ccc, ddd, eee, aaa, X[6], 5); + GGG (aaa, bbb, ccc, ddd, eee, X[4], 8); + GGG (eee, aaa, bbb, ccc, ddd, X[1], 11); + GGG (ddd, eee, aaa, bbb, ccc, X[3], 14); + GGG (ccc, ddd, eee, aaa, bbb, X[11], 14); + GGG (bbb, ccc, ddd, eee, aaa, X[15], 6); + GGG (aaa, bbb, ccc, ddd, eee, X[0], 14); + GGG (eee, aaa, bbb, ccc, ddd, X[5], 6); + GGG (ddd, eee, aaa, bbb, ccc, X[12], 9); + GGG (ccc, ddd, eee, aaa, bbb, X[2], 12); + GGG (bbb, ccc, ddd, eee, aaa, X[13], 9); + GGG (aaa, bbb, ccc, ddd, eee, X[9], 12); + GGG (eee, aaa, bbb, ccc, ddd, X[7], 5); + GGG (ddd, eee, aaa, bbb, ccc, X[10], 15); + GGG (ccc, ddd, eee, aaa, bbb, X[14], 8); + + /* parallel round 5 */ + FFF (bbb, ccc, ddd, eee, aaa, X[12], 8); + FFF (aaa, bbb, ccc, ddd, eee, X[15], 5); + FFF (eee, aaa, bbb, ccc, ddd, X[10], 12); + FFF (ddd, eee, aaa, bbb, ccc, X[4], 9); + FFF (ccc, ddd, eee, aaa, bbb, X[1], 12); + FFF (bbb, ccc, ddd, eee, aaa, X[5], 5); + FFF (aaa, bbb, ccc, ddd, eee, X[8], 14); + FFF (eee, aaa, bbb, ccc, ddd, X[7], 6); + FFF (ddd, eee, aaa, bbb, ccc, X[6], 8); + FFF (ccc, ddd, eee, aaa, bbb, X[2], 13); + FFF (bbb, ccc, ddd, eee, aaa, X[13], 6); + FFF (aaa, bbb, ccc, ddd, eee, X[14], 5); + FFF (eee, aaa, bbb, ccc, ddd, X[0], 15); + FFF (ddd, eee, aaa, bbb, ccc, X[3], 13); + FFF (ccc, ddd, eee, aaa, bbb, X[9], 11); + FFF (bbb, ccc, ddd, eee, aaa, X[11], 11); + + /* combine results */ + ddd += cc + MDbuf[1]; /* final result for MDbuf[0] */ + MDbuf[1] = MDbuf[2] + dd + eee; + MDbuf[2] = MDbuf[3] + ee + aaa; + MDbuf[3] = MDbuf[4] + aa + bbb; + MDbuf[4] = MDbuf[0] + bb + ccc; + MDbuf[0] = ddd; - return; + return; } /********************************************************************/ -static void MDfinish(dword *MDbuf, const byte *strptr, dword lswlen, dword mswlen) +static void +MDfinish (dword * MDbuf, const byte * strptr, dword lswlen, dword mswlen) { - unsigned int i; /* counter */ - dword X[16]; /* message words */ + unsigned int i; /* counter */ + dword X[16]; /* message words */ - grub_memset(X, 0, 16*sizeof(dword)); + grub_memset (X, 0, 16 * sizeof (dword)); - /* put bytes from strptr into X */ - for (i=0; i<(lswlen&63); i++) { + /* put bytes from strptr into X */ + for (i = 0; i < (lswlen & 63); i++) + { /* byte i goes into word X[i div 4] at pos. 8*(i mod 4) */ - X[i>>2] ^= (dword) *strptr++ << (8 * (i&3)); - } + X[i >> 2] ^= (dword) * strptr++ << (8 * (i & 3)); + } - /* append the bit m_n == 1 */ - X[(lswlen>>2)&15] ^= (dword)1 << (8*(lswlen&3) + 7); + /* append the bit m_n == 1 */ + X[(lswlen >> 2) & 15] ^= (dword) 1 << (8 * (lswlen & 3) + 7); - if ((lswlen & 63) > 55) { + if ((lswlen & 63) > 55) + { /* length goes to next block */ - compress(MDbuf, X); - grub_memset(X, 0, 16*sizeof(dword)); - } + compress (MDbuf, X); + grub_memset (X, 0, 16 * sizeof (dword)); + } + + /* append length in bits */ + X[14] = lswlen << 3; + X[15] = (lswlen >> 29) | (mswlen << 3); + compress (MDbuf, X); - /* append length in bits*/ - X[14] = lswlen << 3; - X[15] = (lswlen >> 29) | (mswlen << 3); - compress(MDbuf, X); - - return; + return; } /*** GNU GRUB2 interface ***/ #define RMDsize 160 -static grub_err_t grub_hash_rmd160_fn(grub_cipher_params_t params, char *out, - const char *in, grub_size_t insize) +static grub_err_t +grub_hash_rmd160_fn (grub_cipher_params_t params, char *out, + const char *in, grub_size_t insize) { - dword MDbuf[RMDsize/32]; /* contains (A, B, C, D(, E)) */ - dword X[16]; /* current 16-word chunk */ - unsigned int i; /* counter */ - dword nbytes; /* # of bytes not yet processed */ - - /* initialize */ - MDinit(MDbuf); - - /* process message in 16-word chunks */ - for (nbytes=insize; nbytes > 63; nbytes-=64) { - for (i=0; i<16; i++) { - X[i] = BYTES_TO_DWORD(in); - in += 4; - } - compress(MDbuf, X); - } /* length mod 64 bytes left */ - - /* finish: */ - MDfinish(MDbuf, (const byte *)in, insize, 0); - - for (i=0; i