|
|
|
@ -46,7 +46,7 @@ void main(void) { |
|
|
|
int createKeypair(void) { |
|
|
|
int createKeypair(void) { |
|
|
|
/*** CREATE KEYPAIR ***/ |
|
|
|
/*** CREATE KEYPAIR ***/ |
|
|
|
const char* P_string = "3203431780337000"; |
|
|
|
const char* P_string = "3203431780337000"; |
|
|
|
const char* alpha_string = "AFFE425634534"; |
|
|
|
const char* alpha_string = "AFFE12345678AFFE"; |
|
|
|
const char* Priv_a_string = "9778729279583412"; |
|
|
|
const char* Priv_a_string = "9778729279583412"; |
|
|
|
const char* Priv_b_string = "4825234752983495"; |
|
|
|
const char* Priv_b_string = "4825234752983495"; |
|
|
|
|
|
|
|
|
|
|
|
@ -83,24 +83,42 @@ int createKeypair(void) { |
|
|
|
t_encryptionArithmetic pub_a; |
|
|
|
t_encryptionArithmetic pub_a; |
|
|
|
encryptionArithmetic_Init(&pub_a, KEY_LENGTH); |
|
|
|
encryptionArithmetic_Init(&pub_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&alpha, &priv_a, &P, &pub_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&alpha, &priv_a, &P, &pub_a, KEY_LENGTH); |
|
|
|
|
|
|
|
printf("Calculated public key for person A: 0x"); |
|
|
|
|
|
|
|
for (int num_bytes = KEY_LENGTH / 64; num_bytes >= 0; num_bytes--) { |
|
|
|
|
|
|
|
printf("%X", *((uint32_t*)(pub_a.number + num_bytes))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
/* initialize and calculate public key b */ |
|
|
|
/* initialize and calculate public key b */ |
|
|
|
t_encryptionArithmetic pub_b; |
|
|
|
t_encryptionArithmetic pub_b; |
|
|
|
encryptionArithmetic_Init(&pub_b, KEY_LENGTH); |
|
|
|
encryptionArithmetic_Init(&pub_b, KEY_LENGTH); |
|
|
|
squareAndMultiply(&alpha, &priv_b, &P, &pub_b, KEY_LENGTH); |
|
|
|
squareAndMultiply(&alpha, &priv_b, &P, &pub_b, KEY_LENGTH); |
|
|
|
|
|
|
|
printf("Calculated public key for person B: 0x"); |
|
|
|
|
|
|
|
for (int num_bytes = KEY_LENGTH / 64; num_bytes >= 0; num_bytes--) { |
|
|
|
|
|
|
|
printf("%X", *((uint32_t*)(pub_b.number + num_bytes))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize and calculate session key for person a */ |
|
|
|
/* initialize and calculate session key for person a */ |
|
|
|
t_encryptionArithmetic session_key_a; |
|
|
|
t_encryptionArithmetic session_key_a; |
|
|
|
encryptionArithmetic_Init(&session_key_a, KEY_LENGTH); |
|
|
|
encryptionArithmetic_Init(&session_key_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_b, &priv_a, &P, &session_key_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_b, &priv_a, &P, &session_key_a, KEY_LENGTH); |
|
|
|
printf("Calculated session key for person A: 0x%x\n", *session_key_a.number); |
|
|
|
printf("Calculated session key for person A: 0x"); |
|
|
|
|
|
|
|
for (int num_bytes = KEY_LENGTH / 64; num_bytes >= 0; num_bytes--) { |
|
|
|
|
|
|
|
printf("%X", *((uint32_t*)(session_key_a.number + num_bytes))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
/* initialize and calculate session key for person b */ |
|
|
|
/* initialize and calculate session key for person b */ |
|
|
|
t_encryptionArithmetic session_key_b; |
|
|
|
t_encryptionArithmetic session_key_b; |
|
|
|
encryptionArithmetic_Init(&session_key_b, KEY_LENGTH); |
|
|
|
encryptionArithmetic_Init(&session_key_b, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_a, &priv_b, &P, &session_key_b, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_a, &priv_b, &P, &session_key_b, KEY_LENGTH); |
|
|
|
printf("Calculated session key for person B: 0x%x\n", *session_key_b.number); |
|
|
|
printf("Calculated session key for person B: 0x"); |
|
|
|
|
|
|
|
for (int num_bytes = KEY_LENGTH / 64; num_bytes >= 0; num_bytes--) { |
|
|
|
|
|
|
|
printf("%X", *((uint32_t*)(session_key_b.number + num_bytes))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -108,9 +126,9 @@ int createKeypair(void) { |
|
|
|
int calculateSessionKey(void) { |
|
|
|
int calculateSessionKey(void) { |
|
|
|
|
|
|
|
|
|
|
|
/*** Calculate Session Key ***/ |
|
|
|
/*** Calculate Session Key ***/ |
|
|
|
const char* P_string = "B8C6440FA3B64CB9";
|
|
|
|
const char* P_string = "3203431780337000";
|
|
|
|
const char* Priv_a_string = "C8B2014E72001DD"; |
|
|
|
const char* Priv_a_string = "9778729279583412"; |
|
|
|
const char* Pub_b_string = "69DF372122D2E892"; |
|
|
|
const char* Pub_b_string = "13BED5BE5045000"; |
|
|
|
|
|
|
|
|
|
|
|
// P has to be a prime number! Large prime number (64bit): 3203431780337000
|
|
|
|
// P has to be a prime number! Large prime number (64bit): 3203431780337000
|
|
|
|
t_encryptionArithmetic P; |
|
|
|
t_encryptionArithmetic P; |
|
|
|
@ -138,7 +156,11 @@ int calculateSessionKey(void) { |
|
|
|
t_encryptionArithmetic session_key_a; |
|
|
|
t_encryptionArithmetic session_key_a; |
|
|
|
encryptionArithmetic_Init(&session_key_a, KEY_LENGTH); |
|
|
|
encryptionArithmetic_Init(&session_key_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_b, &priv_a, &P, &session_key_a, KEY_LENGTH); |
|
|
|
squareAndMultiply(&pub_b, &priv_a, &P, &session_key_a, KEY_LENGTH); |
|
|
|
printf("Calculated session key for person A: 0x%x\n", *session_key_a.number); |
|
|
|
printf("Calculated session key for person A: 0x"); |
|
|
|
|
|
|
|
for (int num_bytes = KEY_LENGTH / 64; num_bytes >= 0; num_bytes--) { |
|
|
|
|
|
|
|
printf("%X", *((uint32_t*)(session_key_a.number + num_bytes))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
printf("\n"); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |