1/** 2 * Author......: See docs/credits.txt 3 * License.....: MIT 4 */ 5 6#include "inc_vendor.h" 7#include "inc_types.h" 8#include "inc_platform.h" 9#include "inc_common.h" 10#include "inc_truecrypt_keyfile.h" 11 12DECLSPEC u32 u8add (const u32 a, const u32 b) 13{ 14 const u32 a1 = (a >> 0) & 0xff; 15 const u32 a2 = (a >> 8) & 0xff; 16 const u32 a3 = (a >> 16) & 0xff; 17 const u32 a4 = (a >> 24) & 0xff; 18 19 const u32 b1 = (b >> 0) & 0xff; 20 const u32 b2 = (b >> 8) & 0xff; 21 const u32 b3 = (b >> 16) & 0xff; 22 const u32 b4 = (b >> 24) & 0xff; 23 24 const u32 r1 = (a1 + b1) & 0xff; 25 const u32 r2 = (a2 + b2) & 0xff; 26 const u32 r3 = (a3 + b3) & 0xff; 27 const u32 r4 = (a4 + b4) & 0xff; 28 29 const u32 r = r1 << 0 30 | r2 << 8 31 | r3 << 16 32 | r4 << 24; 33 34 return r; 35} 36 37DECLSPEC u32 hc_apply_keyfile_tc (u32 *w, const int pw_len, const GLOBAL_AS tc_t *tc) 38{ 39 if (tc->keyfile_enabled == 0) return pw_len; 40 41 if (pw_len > 64) 42 { 43 w[ 0] = u8add (w[ 0], tc->keyfile_buf32[ 0]); 44 w[ 1] = u8add (w[ 1], tc->keyfile_buf32[ 1]); 45 w[ 2] = u8add (w[ 2], tc->keyfile_buf32[ 2]); 46 w[ 3] = u8add (w[ 3], tc->keyfile_buf32[ 3]); 47 w[ 4] = u8add (w[ 4], tc->keyfile_buf32[ 4]); 48 w[ 5] = u8add (w[ 5], tc->keyfile_buf32[ 5]); 49 w[ 6] = u8add (w[ 6], tc->keyfile_buf32[ 6]); 50 w[ 7] = u8add (w[ 7], tc->keyfile_buf32[ 7]); 51 w[ 8] = u8add (w[ 8], tc->keyfile_buf32[ 8]); 52 w[ 9] = u8add (w[ 9], tc->keyfile_buf32[ 9]); 53 w[10] = u8add (w[10], tc->keyfile_buf32[10]); 54 w[11] = u8add (w[11], tc->keyfile_buf32[11]); 55 w[12] = u8add (w[12], tc->keyfile_buf32[12]); 56 w[13] = u8add (w[13], tc->keyfile_buf32[13]); 57 w[14] = u8add (w[14], tc->keyfile_buf32[14]); 58 w[15] = u8add (w[15], tc->keyfile_buf32[15]); 59 w[16] = u8add (w[16], tc->keyfile_buf32[16]); 60 w[17] = u8add (w[17], tc->keyfile_buf32[17]); 61 w[18] = u8add (w[18], tc->keyfile_buf32[18]); 62 w[19] = u8add (w[19], tc->keyfile_buf32[19]); 63 w[20] = u8add (w[20], tc->keyfile_buf32[20]); 64 w[21] = u8add (w[21], tc->keyfile_buf32[21]); 65 w[22] = u8add (w[22], tc->keyfile_buf32[22]); 66 w[23] = u8add (w[23], tc->keyfile_buf32[23]); 67 w[24] = u8add (w[24], tc->keyfile_buf32[24]); 68 w[25] = u8add (w[25], tc->keyfile_buf32[25]); 69 w[26] = u8add (w[26], tc->keyfile_buf32[26]); 70 w[27] = u8add (w[27], tc->keyfile_buf32[27]); 71 w[28] = u8add (w[28], tc->keyfile_buf32[28]); 72 w[29] = u8add (w[29], tc->keyfile_buf32[29]); 73 w[30] = u8add (w[30], tc->keyfile_buf32[30]); 74 w[31] = u8add (w[31], tc->keyfile_buf32[31]); 75 76 return 128; 77 } 78 else 79 { 80 w[ 0] = u8add (w[ 0], tc->keyfile_buf16[ 0]); 81 w[ 1] = u8add (w[ 1], tc->keyfile_buf16[ 1]); 82 w[ 2] = u8add (w[ 2], tc->keyfile_buf16[ 2]); 83 w[ 3] = u8add (w[ 3], tc->keyfile_buf16[ 3]); 84 w[ 4] = u8add (w[ 4], tc->keyfile_buf16[ 4]); 85 w[ 5] = u8add (w[ 5], tc->keyfile_buf16[ 5]); 86 w[ 6] = u8add (w[ 6], tc->keyfile_buf16[ 6]); 87 w[ 7] = u8add (w[ 7], tc->keyfile_buf16[ 7]); 88 w[ 8] = u8add (w[ 8], tc->keyfile_buf16[ 8]); 89 w[ 9] = u8add (w[ 9], tc->keyfile_buf16[ 9]); 90 w[10] = u8add (w[10], tc->keyfile_buf16[10]); 91 w[11] = u8add (w[11], tc->keyfile_buf16[11]); 92 w[12] = u8add (w[12], tc->keyfile_buf16[12]); 93 w[13] = u8add (w[13], tc->keyfile_buf16[13]); 94 w[14] = u8add (w[14], tc->keyfile_buf16[14]); 95 w[15] = u8add (w[15], tc->keyfile_buf16[15]); 96 97 return 64; 98 } 99} 100