Commit d11c8deb authored by yids's avatar yids

- some stuff on key generator

- some cleaning up and defining
parent 6c691b4e
Pipeline #16 skipped
......@@ -19,7 +19,7 @@
#define BLOCK_SIZE 16
#define NUM_BLOCKS 4
#define NUM_ECC_DIGITS 24 //size of privkey, curvesize in bytes
#define CURVE uECC_secp192r1()
LCDI2C lcd = LCDI2C(2,16,0x50,0);
aes_context ctx; // context for the cbc crypto stuff
......@@ -28,9 +28,16 @@ aes_context ctx; // context for the cbc crypto stuff
RH_ASK driver(5000);
RHDatagram manager(driver, ADDRESS);
// uECC keys
uint8_t privkey[25] = {0x50, 0xEA, 0x8F, 0x57, 0xFD, 0xBE, 0x75, 0xAE, 0x17, 0x70, 0xC6, 0xF0, 0x51, 0x11, 0x5C, 0xA, 0xF6, 0xFE, 0xCF, 0x4, 0xC9, 0xBD, 0xFC, 0x7D, 0xD6};
uint8_t pubkey[48] = {0x27, 0x8C, 0x41, 0x2C, 0x1F, 0xF2, 0xA9, 0xCB, 0x78, 0xC4, 0x1E, 0xBB, 0x2B, 0x32, 0x32, 0x34, 0xC3, 0x5B, 0xD1, 0x87, 0x52, 0x6C, 0xBD, 0x7F, 0x44, 0x73, 0xDC, 0xF0, 0xFC, 0x93, 0x97, 0x99, 0x46, 0x16, 0xE0, 0x8F, 0x65, 0xA4, 0xCB, 0x65, 0x59, 0xA8, 0xBF, 0xFD, 0xB4, 0x61, 0x23, 0xA8};
// uECC keys 256bit
/*
uint8_t privkey[NUM_ECC_DIGITS+1] = {0xDB, 0x5A, 0xDF, 0xBD, 0xFD, 0xE3, 0x25, 0xD2, 0xB6, 0x5C, 0x6A, 0xEA, 0xAF, 0xC4, 0xC4, 0xD9, 0x7B, 0x5E, 0x99, 0xD6, 0x66, 0xEC, 0xA0, 0xA4, 0x6F, 0xB, 0xBD, 0x42, 0x25, 0xEE, 0x3E, 0x40, 0xF4};
uint8_t pubkey[NUM_ECC_DIGITS*2] = {0x12, 0x70, 0x13, 0x5, 0x57, 0xAD, 0xDD, 0x9C, 0x9D, 0xC, 0x60, 0x2F, 0xE2, 0xC4, 0x9C, 0x4, 0x99, 0x77, 0x2D, 0x22, 0xA6, 0x46, 0x9C, 0xC6, 0xE4, 0x7D, 0x4C, 0x9D, 0x7E, 0x1F, 0xD6, 0x94, 0xC5, 0x23, 0xF1, 0x21, 0x32, 0x4B, 0x6B, 0xB, 0x65, 0xB, 0x57, 0x7E, 0x66, 0x1D, 0xA5, 0x41, 0x7, 0xF5, 0xE2, 0x1C, 0x38, 0x98, 0xFB, 0x95, 0xBA, 0x1B, 0xA3, 0x2B, 0x35, 0x26, 0x1D, 0xF6};
*/
// uECC keys 192bit
uint8_t pubkey[NUM_ECC_DIGITS*2] = {0x99, 0x61, 0xB5, 0x38, 0xB3, 0x83, 0x7E, 0xFB, 0xD9, 0x3F, 0x71, 0xA3, 0x81, 0x77, 0xB0, 0x48, 0x32, 0x29, 0x24, 0x6B, 0x76, 0x48, 0x9C, 0x7A, 0x70, 0xFD, 0x3F, 0xC4, 0xB8, 0xAB, 0x8E, 0xCD, 0x31, 0x88, 0x50, 0x2D, 0xE6, 0x53, 0x49, 0xE8, 0xC0, 0xB4, 0xB5, 0xC6, 0x4F, 0x97, 0x7F, 0x6B};
uint8_t privkey[NUM_ECC_DIGITS+1] = {0xAD, 0x98, 0x8E, 0xC4, 0x79, 0x1D, 0xE0, 0x2C, 0xEE, 0xF8, 0xB0, 0xAA, 0xC9, 0x3E, 0x6F, 0x9D, 0x1E, 0x5E, 0xF7, 0x96, 0xD7, 0x3F, 0x7F, 0x2E, 0xF4};
uint8_t* generateIV()
{
......@@ -112,30 +119,31 @@ static int RNG(uint8_t *dest, unsigned size) {
void generateKeys()
{
const struct uECC_Curve_t * curve = uECC_secp192r1();
uint8_t private1[25];
uint8_t public1[48];
uint8_t secret1[24];
Serial.println("generating keys");
const struct uECC_Curve_t * curve = CURVE;
uint8_t private1[NUM_ECC_DIGITS+1];
uint8_t public1[NUM_ECC_DIGITS*2];
uint8_t secret1[NUM_ECC_DIGITS];
unsigned long a = millis();
uECC_make_key(public1, private1, curve);
unsigned long b = millis();
Serial.print("Generated keypair in "); Serial.print(b-a); Serial.println("Milliseconds");
Serial.println("Public key:");
Serial.print("uint8_t pubkey[NUM_ECC_DIGITS*2] = {");
for( int i = 0 ; i < sizeof(public1); i++){
Serial.print("0x");
Serial.print(public1[i], HEX);
Serial.print(", ");
}
Serial.println("");
Serial.println("Private key:");
Serial.println("}");
Serial.print("uint8_t privkey[NUM_ECC_DIGITS+1] = {");
for( int i = 0 ; i < sizeof(private1); i++){
Serial.print("0x");
Serial.print(private1[i], HEX);
Serial.print(", ");
}
Serial.println("");
Serial.println("}");
}
void setup()
......@@ -164,12 +172,12 @@ void hashSecret(uint8_t *p_secret)
void loop()
{
// generateKeys(); function to generate keys, have to make a program for this to run on a computer
// generateKeys(); //function to generate keys, have to make a program for this to run on a computer
// crypto vars //
uint8_t remotePubkey[48];
uint8_t sharedSecret[NUM_ECC_DIGITS];
const struct uECC_Curve_t * curve = uECC_secp192r1();
const struct uECC_Curve_t * curve = CURVE;
// Radio vars //
uint8_t* receivedData;
......@@ -186,20 +194,17 @@ void loop()
Serial.print(" : ");
Serial.print(id);
Serial.println(" : ");
if (id == 50){ // receiving a public key...
for (int i = 0 ; i < NUM_ECC_DIGITS*2 ; i++){
remotePubkey[i] = buf[i];
//Serial.println(remotePubkey.x[i]);
}
}
if (id == 50){ // receiving a public key...
for (int i = 0 ; i < NUM_ECC_DIGITS*2 ; i++){
remotePubkey[i] = buf[i];
}
}
if (id == 51){ // receiving an encrypted message...
Serial.println("Storing received message");
receivedData = buf;
Serial.println((char*)receivedData);
}
if (id == 51){ // receiving an encrypted message...
Serial.println("Storing received message");
receivedData = buf;
Serial.println((char*)receivedData);
}
}
if(uECC_valid_public_key(remotePubkey, curve) == 1){
......
......@@ -17,15 +17,24 @@
#define ADDRESS 5
#define NUM_ECC_DIGITS 24 //size of privkey, curvesize in bytes
#define CURVE uECC_secp192r1()
aes_context ctx;
RH_ASK driver(5000);
RHDatagram manager(driver, ADDRESS);
// uECC keys
uint8_t privkey[25] = {0xED, 0x3F, 0xB6, 0xB, 0x20, 0x3F, 0x54, 0xEE, 0xCF, 0xAF, 0xFC, 0xB6, 0x1F, 0x89, 0x1, 0x4, 0x5B, 0xFF, 0x67, 0xEF, 0xDA, 0xFF, 0xD7, 0xD2, 0xD6};
uint8_t pubkey[48] = {0xC3, 0xFB, 0xBD, 0xF3, 0x31, 0x6E, 0x12, 0x63, 0x6A, 0x5F, 0x2, 0xAB, 0x18, 0xF0, 0xF3, 0x43, 0xB3, 0x18, 0xA2, 0x6D, 0x60, 0x28, 0xC4, 0x5F, 0x33, 0x5E, 0x4D, 0xEC, 0x99, 0xA6, 0xF, 0x42, 0xFE, 0x55, 0xD6, 0x2C, 0x78, 0x8A, 0x4C, 0x22, 0xCC, 0x17, 0xF2, 0x6E, 0x4B, 0xC4, 0xFD, 0x22};
// uECC keys 256bit
/*
uint8_t privkey[NUM_ECC_DIGITS+1] = {0x59, 0x7F, 0xF2, 0x59, 0xC4, 0x3E, 0xD3, 0xDE, 0x76, 0xDF, 0xD6, 0xB1, 0x6A, 0x7F, 0x75, 0xE3, 0x49, 0xC4, 0x3F, 0xDB, 0x29, 0xAB, 0xDC, 0xDC, 0x67, 0x4A, 0x7F, 0xEF, 0xB, 0xF2, 0xA5, 0xFB, 0xF4};
uint8_t pubkey[NUM_ECC_DIGITS*2] = {0x5C, 0x54, 0x4F, 0x7D, 0x8B, 0x59, 0x58, 0x9C, 0x10, 0xDF, 0xD2, 0x63, 0x88, 0x7F, 0xFB, 0x2C, 0x93, 0xF8, 0x5F, 0xFD, 0xF6, 0x24, 0x1, 0xFE, 0x97, 0xEB, 0x64, 0xED, 0x2, 0xC1, 0x13, 0x4B, 0x86, 0x79, 0xE0, 0x5A, 0x34, 0xE4, 0xFB, 0x6E, 0xDA, 0xC8, 0x37, 0xA5, 0xDB, 0xC7, 0x9F, 0x5E, 0xAC, 0xA1, 0x75, 0x54, 0xA2, 0x15, 0xB6, 0x33, 0x97, 0x27, 0x53, 0x93, 0x81, 0x34, 0x5B, 0xDE};
uint8_t remotePubkey[NUM_ECC_DIGITS*2] = {0x12, 0x70, 0x13, 0x5, 0x57, 0xAD, 0xDD, 0x9C, 0x9D, 0xC, 0x60, 0x2F, 0xE2, 0xC4, 0x9C, 0x4, 0x99, 0x77, 0x2D, 0x22, 0xA6, 0x46, 0x9C, 0xC6, 0xE4, 0x7D, 0x4C, 0x9D, 0x7E, 0x1F, 0xD6, 0x94, 0xC5, 0x23, 0xF1, 0x21, 0x32, 0x4B, 0x6B, 0xB, 0x65, 0xB, 0x57, 0x7E, 0x66, 0x1D, 0xA5, 0x41, 0x7, 0xF5, 0xE2, 0x1C, 0x38, 0x98, 0xFB, 0x95, 0xBA, 0x1B, 0xA3, 0x2B, 0x35, 0x26, 0x1D, 0xF6};
*/
// uECC keys 192bit
uint8_t pubkey[NUM_ECC_DIGITS*2] = {0x67, 0xCF, 0x6C, 0x6F, 0x64, 0x19, 0xCC, 0xBF, 0x44, 0x60, 0x36, 0x2C, 0x99, 0x1D, 0x8C, 0x38, 0xFB, 0x6D, 0x18, 0xF2, 0x24, 0xEC, 0x8F, 0x8, 0xAB, 0x23, 0x76, 0xC, 0x4F, 0xA4, 0x63, 0x55, 0x26, 0xF8, 0x30, 0x9A, 0xA7, 0x6C, 0x55, 0x54, 0x10, 0x31, 0x0, 0xCA, 0x55, 0xF9, 0xC1, 0xFA};
uint8_t privkey[NUM_ECC_DIGITS+1] = {0xF6, 0x8B, 0x9B, 0x7F, 0xD9, 0xF8, 0xF7, 0x8C, 0x1, 0x1F, 0x6F, 0xF1, 0x9A, 0x6D, 0xC, 0xFC, 0xD4, 0x78, 0xBE, 0x26, 0x85, 0x78, 0xFD, 0xCA, 0xF4};
uint8_t remotePubkey[48] = {0x27, 0x8C, 0x41, 0x2C, 0x1F, 0xF2, 0xA9, 0xCB, 0x78, 0xC4, 0x1E, 0xBB, 0x2B, 0x32, 0x32, 0x34, 0xC3, 0x5B, 0xD1, 0x87, 0x52, 0x6C, 0xBD, 0x7F, 0x44, 0x73, 0xDC, 0xF0, 0xFC, 0x93, 0x97, 0x99, 0x46, 0x16, 0xE0, 0x8F, 0x65, 0xA4, 0xCB, 0x65, 0x59, 0xA8, 0xBF, 0xFD, 0xB4, 0x61, 0x23, 0xA8};
uint8_t remotePubkey[NUM_ECC_DIGITS*2] = {0x99, 0x61, 0xB5, 0x38, 0xB3, 0x83, 0x7E, 0xFB, 0xD9, 0x3F, 0x71, 0xA3, 0x81, 0x77, 0xB0, 0x48, 0x32, 0x29, 0x24, 0x6B, 0x76, 0x48, 0x9C, 0x7A, 0x70, 0xFD, 0x3F, 0xC4, 0xB8, 0xAB, 0x8E, 0xCD, 0x31, 0x88, 0x50, 0x2D, 0xE6, 0x53, 0x49, 0xE8, 0xC0, 0xB4, 0xB5, 0xC6, 0x4F, 0x97, 0x7F, 0x6B};
uint8_t* generateIV()
{
......@@ -41,7 +50,7 @@ uint8_t* generateIV()
return buffer;
}
char* encryptAES(uint8_t* p_secret, char* p_data, const aes_context ctx)
char* encryptAES(char* p_data, const aes_context ctx)
{
Serial.print("data:");
Serial.println(p_data);
......@@ -52,7 +61,7 @@ char* encryptAES(uint8_t* p_secret, char* p_data, const aes_context ctx)
return p_data;
}
char* decryptAES(uint8_t* p_secret, char* p_data, const aes_context ctx)
char* decryptAES(char* p_data, const aes_context ctx)
{
Serial.print("decrypting data...");
aes128_cbc_dec_continue(ctx, p_data, BLOCK_SIZE*NUM_BLOCKS);
......@@ -119,11 +128,11 @@ void hashSecret(uint8_t *p_secret)
void loop()
{
// crypto vars //
uint8_t sharedSecret[24];
const struct uECC_Curve_t * curve = uECC_secp192r1();
// char* data = "Hallo";
// char* encryptedData;
// uint8_t iv[16] = {4,9,4,9,4,9,4,9,4,9,4,9,4,9,4,9};
uint8_t sharedSecret[NUM_ECC_DIGITS];
const struct uECC_Curve_t * curve = CURVE;
char* data = "Hallo";
char* encryptedData;
uint8_t iv[16] = {4,9,4,9,4,9,4,9,4,9,4,9,4,9,4,9};
sendPubkey();
if(uECC_valid_public_key(remotePubkey, curve) == 1){
......@@ -136,7 +145,7 @@ void loop()
// ctx = aes128_cbc_enc_start(&sharedSecret, iv);
// encryptedData = encryptAES(&sharedSecret, data, ctx);
// encryptedData = encryptAES(data, ctx);
//
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment