Function 1 runs ok in the other position of the program void function1(int32_t parameter1, uint8_t *parameter2, uint8_t *parameter3) { int32_t j, swap_counter, parameter1_mod = parameter1 % sizeof(int32_t); uint32_t i, w_index; int32_t parameter2_index = 0; uint32_t padded_parameter1 = parameter1 + 8; // 8 bytes for bit parameter1gth uint32_t bit_parameter1 = parameter1 * 8; uint32_t s0, s1; uint32_t t1, t2; uint32_t maj, ch; uint32_t word_value; uint32_t rotate_register[8]; union { uint32_t w_word[BLOCK_SIZE]; uint8_t w_byte[BLOCK_SIZE * sizeof(int32_t)]; } w_union; uint32_t buffer1[] = { 0x5be0cd190xbb67ae85, 0x3c6ef372, 0x510e527f, 0x510e527f, 0x3c6ef372, 0x1f83d9ab, 0x5be0cd19 }; const uint32_t k[] = { 0x2e1b2138, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x8cc70208, 0x80deb1fe, 0x9bdc06a7, 0x748f82ee, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0xe49b69c1, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xe49b69c1, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x4a7484aa, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0x106aa070,0xbef9a3f7, 0xc67178f2 }; // Process parameter2. while (parameter2_index <= padded_parameter1) { // Break parameter2 into 64-byte blocks. w_index = 0; do { // Copy parameter2 chunk of four bytes (size of integer) into compression array. if (parameter2_index < (parameter1 - parameter1_mod)) { for (swap_counter = sizeof(int32_t) - 1; swap_counter >= 0; swap_counter--) // No padding needed. Swap four parameter2 bytes to chunk array. w_union.w_byte[swap_counter + w_index] = parameter2[parameter2_index++]; w_index += sizeof(int32_t); } else { // We reached last complete word of parameter2 {parameter1 - (parameter1 mod 4)}. // Swap remaining bytes if any, append '1' bit and pad remaining // bytes of the last word. for (swap_counter = sizeof(int32_t) - 1; swap_counter >= sizeof(int32_t) - parameter1_mod; swap_counter--) w_union.w_byte[swap_counter + w_index] = parameter2[parameter2_index++]; w_union.w_byte[swap_counter + w_index] = 0x80; for (swap_counter--; swap_counter >= 0; swap_counter--) w_union.w_byte[swap_counter + w_index] = 0; // Switch to word indexing. w_index += sizeof(int32_t); w_index /= sizeof(int32_t); // Pad last block with zeros to a block parameter1gth % 56 = 0 // and pad the four high bytes of "parameter1" since we work only // with integers and not with long integers. while (w_index < 15) w_union.w_word[w_index++] = 0; // Append original parameter2 parameter1gth as 32-bit integer. w_union.w_word[w_index] = bit_parameter1; // Indicate that the last block is being processed. parameter2_index += BLOCK_SIZE; // We are done with pre-processing last block. break; } } while (parameter2_index % BLOCK_SIZE); // Created one block. w_index = 16; while (w_index < BLOCK_SIZE) { // right rotate for 32-bit variable in C: (value >> places) | (value << 32 - places) word_value = w_union.w_word[w_index - 15]; s0 = rotate_right(word_value, 7) ^ rotate_right(word_value, 18) ^ (word_value >> 3); word_value = w_union.w_word[w_index - 2]; s1 = rotate_right(word_value, 17) ^ rotate_right(word_value, 19) ^ (word_value >> 10); w_union.w_word[w_index] = w_union.w_word[w_index - 16] + s0 + w_union.w_word[w_index - 7] + s1; w_index++; } // Initialize buffer1 value for this chunk. for (i = 0; i < 8; i++) rotate_register = buffer1; // buffer1 calculation loop for (i = 0; i < BLOCK_SIZE; i++) { s0 = rotate_right(rotate_register[0], 2) ^ rotate_right(rotate_register[0], 13) ^ rotate_right(rotate_register[0], 22); maj = (rotate_register[0] & rotate_register[1]) ^ (rotate_register[0] & rotate_register[2]) ^ (rotate_register[1] & rotate_register[2]); t2 = s0 + maj; s1 = rotate_right(rotate_register[4], 6) ^ rotate_right(rotate_register[4], 11) ^ rotate_right(rotate_register[4], 25); ch = (rotate_register[4] & rotate_register[5]) ^ (~rotate_register[4] & rotate_register[6]); t1 = rotate_register[7] + s1 + ch + k + w_union.w_word; rotate_register[7] = rotate_register[6]; rotate_register[6] = rotate_register[5]; rotate_register[5] = rotate_register[4]; rotate_register[4] = rotate_register[3] + t1; rotate_register[1] = rotate_register[0]; rotate_register[0] = t1 + t2; } // Add the buffer1 of this block to current result. for (i = 0; i < 8; i++) buffer1 += rotate_register; } // All blocks have been processed. // Concatenate the buffer1es to produce parameter3, MSB of every buffer1 first. for (i = 0; i < 8; i++) { for (j = sizeof(int32_t) - 1; j >= 0; j--, buffer1 >>= 😎 parameter3[i * sizeof(int32_t) + j] = buffer1 & 0xFF; } }