/** * Core function implementing the chain hash algorithm. * @see stretch_recovery_key() * * @param ch A pointer to a bitlocker_chain_hash_t structure * @param result Will contain the resulting hash key (32 bytes) * @return TRUE if result can be trusted, FALSE otherwise */ unsafe static bool stretch_key(bitlocker_chain_hash_t ch, byte[] result) { //size_t size = sizeof(bitlocker_chain_hash_t); //uint64_t loop = 0; //for(loop = 0; loop < 0x100000; ++loop) //{ // SHA256((unsigned char *)ch, size, ch->updated_hash); // ch->hash_count++; //} for (int loop = 0; loop < 0x100000; loop++) { byte[] data = getBytes(ch); byte[] sha = CalcSha256(data, data.Length); CopyToPointer(ch.updated_hash, sha, SHA256_DIGEST_LENGTH); ch.hash_count++; } //memcpy(result, ch->updated_hash, SHA256_DIGEST_LENGTH); for (byte b = 0; b < SHA256_DIGEST_LENGTH; b++) { result[b] = ch.updated_hash[b]; } //Array.Copy(ch.updated_hash, result, SHA256_DIGEST_LENGTH); return(true); }
/** * Function implementing the stretching of a hashed user password. * @see stretch_key() * * @param user_hash The 32-bytes hash from SHA256(SHA256(UTF16(user_password))) * @param salt The salt used for crypto (16 bytes) * @param result Will contain the resulting hash key (32 bytes) * @return TRUE if result can be trusted, FALSE otherwise */ unsafe bool stretch_user_key(byte[] user_hash, byte[] salt, byte[] result) { //size_t size = sizeof(bitlocker_chain_hash_t); //bitlocker_chain_hash_t ch; bitlocker_chain_hash_t ch = new bitlocker_chain_hash_t(); //memset(&ch, 0, size); //memcpy(ch.password_hash, user_hash, SHA256_DIGEST_LENGTH); //memcpy(ch.salt, salt, SALT_LENGTH); CopyToPointer(ch.password_hash, user_hash, SHA256_DIGEST_LENGTH); CopyToPointer(ch.salt, salt, SALT_LENGTH); //xprintf(L_INFO, "Stretching the user password, it could take some time...\n"); //if (!stretch_key(&ch, result)) // return FALSE; if (!stretch_key(ch, result)) { return(false); } //xprintf(L_INFO, "Stretching of the user password is now ok!\n"); ///* Wipe out with zeros */ //memset(&ch, 0, size); return(true); }
unsafe static byte[] getBytes(bitlocker_chain_hash_t str) { //int len = 32 + 32 + 16 + 8; //int len = 184;// Marshal.SizeOf(str); int len = 88;// sizeof(bitlocker_chain_hash_t);// *myArray.Length; byte[] arr = new byte[len]; IntPtr ptr = Marshal.AllocHGlobal(len); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, len); Marshal.FreeHGlobal(ptr); //bitlocker_chain_hash_t t = new bitlocker_chain_hash_t(); //ByteArrayToStructure(arr, ref t); return(arr); }
unsafe static byte[] getBytes(bitlocker_chain_hash_t str) { //int len = 32 + 32 + 16 + 8; //int len = 184;// Marshal.SizeOf(str); int len = 88;// sizeof(bitlocker_chain_hash_t);// *myArray.Length; byte[] arr = new byte[len]; IntPtr ptr = Marshal.AllocHGlobal(len); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, len); Marshal.FreeHGlobal(ptr); //bitlocker_chain_hash_t t = new bitlocker_chain_hash_t(); //ByteArrayToStructure(arr, ref t); return arr; }
/** * Core function implementing the chain hash algorithm. * @see stretch_recovery_key() * * @param ch A pointer to a bitlocker_chain_hash_t structure * @param result Will contain the resulting hash key (32 bytes) * @return TRUE if result can be trusted, FALSE otherwise */ unsafe static bool stretch_key(bitlocker_chain_hash_t ch, byte[] result) { //size_t size = sizeof(bitlocker_chain_hash_t); //uint64_t loop = 0; //for(loop = 0; loop < 0x100000; ++loop) //{ // SHA256((unsigned char *)ch, size, ch->updated_hash); // ch->hash_count++; //} for (int loop = 0; loop < 0x100000; loop++) { byte[] data = getBytes(ch); byte[] sha = CalcSha256(data, data.Length); CopyToPointer(ch.updated_hash, sha, SHA256_DIGEST_LENGTH); ch.hash_count++; } //memcpy(result, ch->updated_hash, SHA256_DIGEST_LENGTH); for (byte b = 0; b < SHA256_DIGEST_LENGTH; b++) result[b] = ch.updated_hash[b]; //Array.Copy(ch.updated_hash, result, SHA256_DIGEST_LENGTH); return true; }
/** * Function implementing the stretching of a hashed user password. * @see stretch_key() * * @param user_hash The 32-bytes hash from SHA256(SHA256(UTF16(user_password))) * @param salt The salt used for crypto (16 bytes) * @param result Will contain the resulting hash key (32 bytes) * @return TRUE if result can be trusted, FALSE otherwise */ unsafe bool stretch_user_key(byte[] user_hash, byte[] salt, byte[] result) { //size_t size = sizeof(bitlocker_chain_hash_t); //bitlocker_chain_hash_t ch; bitlocker_chain_hash_t ch = new bitlocker_chain_hash_t(); //memset(&ch, 0, size); //memcpy(ch.password_hash, user_hash, SHA256_DIGEST_LENGTH); //memcpy(ch.salt, salt, SALT_LENGTH); CopyToPointer(ch.password_hash, user_hash, SHA256_DIGEST_LENGTH); CopyToPointer(ch.salt, salt, SALT_LENGTH); //xprintf(L_INFO, "Stretching the user password, it could take some time...\n"); //if (!stretch_key(&ch, result)) // return FALSE; if (!stretch_key(ch, result)) return false; //xprintf(L_INFO, "Stretching of the user password is now ok!\n"); ///* Wipe out with zeros */ //memset(&ch, 0, size); return true; }