rsa_arduino/RSA_arduino.ino
2024-03-05 14:15:03 +01:00

60 lines
1.3 KiB
C++

#include <stdlib.h>
#include <stdio.h>
#include "rsa.h"
#include "prng.h"
#include "constantes.h"
#include <LiquidCrystal.h>
struct entropy_pool s_entropy;
int sensorValue = 0;
int switchState = 0;
// e -> public key
// d -> private key
unsigned long n, e, d = 0;
// LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal lcd(11, 10, 5, 4, 3, 2);
void setup(){
pinMode(BUTTON, INPUT);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
// Generate our entropy pool
init_entropy();
// Entropy pool if full, the switch on the red LED
digitalWrite(LED_PIN, HIGH);
}
void loop(){
Serial.println("Start generation key");
while(1){
switchState = digitalRead(BUTTON);
// If we push the button, we generate new keys
if (switchState == HIGH){
lcd.clear();
// Now, we can generate our keys
generateKeys(&e, &d, &n);
if (DEBUG){
Serial.println("e: " + String(e));
Serial.println("d: " + String(d));
Serial.println("n: " + String(n));
}
lcd.setCursor(0, 0);
lcd.print("e:" + String(e) + "," + String(n));
lcd.setCursor(0, 1);
lcd.print("d:" + String(d) + "," + String(n));
}
}
}