You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
ASYD/ASYD_Cryptograhpy/SW03-DHKE/main.c

73 lines
2.1 KiB

/**
*--------------------------------------------------------------------\n
* HSLU T&A Hochschule Luzern Technik+Architektur \n
*--------------------------------------------------------------------\n
*
* \brief ASYD assignment crypto 03
* \file
* \author Basil Estermann, basil.estermann@stud.hslu.ch
* Simon Frei, simon.frei@stud.hslu.ch
* Jonas Arnold, jonas.arnold@stud.hslu.ch
* \date 10.03.2023
*
*--------------------------------------------------------------------
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "encryptionArithmetic.h"
#include "DHKE.h"
#define KEY_LENGTH 64
void main(void) {
/* Initialize variables */
// P has to be a prime number! Large prime number (64bit): 3203431780337000
t_encryptionArithmetic P;
encryptionArithmetic_Init(&P, KEY_LENGTH);
if (encryptionArithmetic_stringToHex("3203431780337000", P.number, KEY_LENGTH) == false) {
printf("ERROR: Creating P.");
return 1000000;
}
// alpha not required for session key generation
//t_encryptionArithmetic alpha;
//encryptionArithmetic_Init(&alpha, KEY_LENGTH);
//if (encryptionArithmetic_stringToHex("13", alpha.number, KEY_LENGTH) == false) {
// printf("ERROR: Creating alpha.");
// return 1000001;
//}
t_encryptionArithmetic pub;
encryptionArithmetic_Init(&pub, KEY_LENGTH);
if (encryptionArithmetic_stringToHex("1370122177720875", pub.number, KEY_LENGTH) == false) {
printf("ERROR: Creating pub.");
return 1000002;
}
t_encryptionArithmetic priv;
encryptionArithmetic_Init(&priv, KEY_LENGTH);
if (encryptionArithmetic_stringToHex("9778729279583412", priv.number, KEY_LENGTH) == false) {
printf("ERROR: Creating priv.");
return 1000003;
}
t_encryptionArithmetic session_key;
encryptionArithmetic_Init(&session_key, KEY_LENGTH);
/* Create session key */
squareAndMultiply(&pub, &priv, &P, &session_key, KEY_LENGTH);
/* Write session key */
printf("%i",*session_key.number);
return 0;
}