RSA crypto initial draft
This commit is contained in:
parent
1cd0b619ef
commit
24922e59c6
4 changed files with 179 additions and 15 deletions
54
main.c
54
main.c
|
|
@ -1,9 +1,10 @@
|
|||
#include <ch32fun.h>
|
||||
#include <rand.h>
|
||||
#include <rsa.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define LED_PIN PD6
|
||||
#define FREQ 2
|
||||
#define BLINK_DELAY 1000 / FREQ
|
||||
|
||||
void exit_blink() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
|
|
@ -12,28 +13,53 @@ void exit_blink() {
|
|||
funDigitalWrite(LED_PIN, FUN_LOW);
|
||||
Delay_Ms(50);
|
||||
}
|
||||
}
|
||||
|
||||
while (1){};
|
||||
|
||||
funDigitalWrite(LED_PIN, FUN_HIGH);
|
||||
void enter_blink() {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
funDigitalWrite(LED_PIN, FUN_HIGH);
|
||||
Delay_Ms(200);
|
||||
funDigitalWrite(LED_PIN, FUN_LOW);
|
||||
Delay_Ms(200);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
SystemInit();
|
||||
|
||||
// Enable GPIOs
|
||||
funGpioInitAll();
|
||||
printf("Entering...");
|
||||
|
||||
funGpioInitAll();
|
||||
funPinMode(LED_PIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP);
|
||||
|
||||
int i = 0;
|
||||
while (i < gcd(930, 10)) {
|
||||
i++;
|
||||
funDigitalWrite(LED_PIN, FUN_HIGH);
|
||||
Delay_Ms(BLINK_DELAY);
|
||||
funDigitalWrite(LED_PIN, FUN_LOW);
|
||||
Delay_Ms(BLINK_DELAY);
|
||||
enter_blink();
|
||||
|
||||
uint64_t p = gen_prime(1 << 15, 1 << 16);
|
||||
uint64_t q = gen_prime(1 << 15, 1 << 16);
|
||||
|
||||
while (p == q) p = gen_prime(1 << 15, 1 << 16);
|
||||
|
||||
uint64_t n = p * q;
|
||||
|
||||
// Make these work by patching printf
|
||||
printf("P: %llu\n", p);
|
||||
printf("Q: %llu\n", q);
|
||||
printf("N: %llu\n", n);
|
||||
|
||||
for (int idx = 0; idx < 16; idx++) {
|
||||
funDigitalWrite(LED_PIN, p >> idx & 1);
|
||||
Delay_Ms(200);
|
||||
}
|
||||
for (int idx = 0; idx < 16; idx++) {
|
||||
funDigitalWrite(LED_PIN, q >> idx & 1);
|
||||
Delay_Ms(200);
|
||||
}
|
||||
for (int idx = 0; idx < 16; idx++) {
|
||||
funDigitalWrite(LED_PIN, n >> idx & 1);
|
||||
Delay_Ms(200);
|
||||
}
|
||||
|
||||
// Exit and hang forever
|
||||
exit_blink();
|
||||
while (1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue