|
|
|
|
@ -22,7 +22,7 @@ |
|
|
|
|
#define VALUE_LENGTH 32 |
|
|
|
|
#define MESSAGE_DIGEST_LENGTH 160 |
|
|
|
|
#define BLOCK_LENGTH (512/8) |
|
|
|
|
#define INPUT_MESSAGE ("Testnachricht 123") |
|
|
|
|
#define INPUT_MESSAGE ("abc") |
|
|
|
|
|
|
|
|
|
#pragma region SHA1-Constants |
|
|
|
|
// initial hash values
|
|
|
|
|
@ -112,31 +112,41 @@ void main(void) { |
|
|
|
|
printf("\n------ Stages ------\n\n"); |
|
|
|
|
#pragma region Stages calculations |
|
|
|
|
uint32_t (*f_ptr)(uint32_t, uint32_t, uint32_t) = &SHA1_f1; // use: (*f_ptr)(b,c,d);
|
|
|
|
|
uint8_t t = 1; |
|
|
|
|
uint8_t stage = 1; |
|
|
|
|
// print header row
|
|
|
|
|
printf("\tA\t\tB\t\tC\t\tD\t\tE\n"); |
|
|
|
|
|
|
|
|
|
// stage 1...4
|
|
|
|
|
for (uint32_t i = 0; i < 80; i++) { |
|
|
|
|
uint32_t T = leftRotate(a, 5) + ((*f_ptr)(b, c, d)) + e + k[t] + WordArray[i]; |
|
|
|
|
for (uint32_t t = 0; t < 80; t++) { |
|
|
|
|
uint32_t T = leftRotate(a, 5) + ((*f_ptr)(b, c, d)) + e + k[stage] + WordArray[t]; |
|
|
|
|
e = d; |
|
|
|
|
d = c; |
|
|
|
|
c = leftRotate(b, 30); |
|
|
|
|
b = a; |
|
|
|
|
a = T; |
|
|
|
|
|
|
|
|
|
// print row
|
|
|
|
|
printf("t= %02d:\t%08X\t%08X\t%08X\t%08X\t%08X\t\n", t, a, b, c, d, e); |
|
|
|
|
|
|
|
|
|
// switch stages
|
|
|
|
|
if (i == 19) { f_ptr = SHA1_f2; t = 2; } |
|
|
|
|
else if (i == 39) { f_ptr = SHA1_f3; t = 3; } |
|
|
|
|
else if (i == 59) { f_ptr = SHA1_f4; t = 4; } |
|
|
|
|
if (t == 19) { f_ptr = SHA1_f2; stage = 2; printf("Switched to stage 2.\n"); } |
|
|
|
|
else if (t == 39) { f_ptr = SHA1_f3; stage = 3; printf("Switched to stage 3.\n"); } |
|
|
|
|
else if (t == 59) { f_ptr = SHA1_f4; stage = 4; printf("Switched to stage 4.\n"); } |
|
|
|
|
} |
|
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
printf("\n------ Intermediate hash calculation ------\n\n"); |
|
|
|
|
#pragma region intermediate hash calculation |
|
|
|
|
h[0] = a + h[0]; |
|
|
|
|
h[1] = b + h[1]; |
|
|
|
|
h[2] = c + h[2]; |
|
|
|
|
h[3] = d + h[3]; |
|
|
|
|
h[4] = e + h[4]; |
|
|
|
|
uint32_t summand[5] = { a, b, c, d, e }; |
|
|
|
|
for (uint8_t i = 0; i < 5; i++) { |
|
|
|
|
// calculate
|
|
|
|
|
uint32_t h_new = summand[i] + h[i]; |
|
|
|
|
// print
|
|
|
|
|
printf("H[%i] = %08X + %08X = %08X\n", i, summand[i], h[i], h_new); |
|
|
|
|
// set value
|
|
|
|
|
h[i] = h_new; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#pragma endregion |
|
|
|
|
#pragma endregion |
|
|
|
|
|
|
|
|
|
|