Compare commits

..

No commits in common. "6b64e0c18b02c3caf72313cdac979694b3fcd865" and "b16c3b098a6ec23ac36bdf21b922472e6d3943a5" have entirely different histories.

13
main.c
View file

@ -5,6 +5,7 @@
#include <stdio.h> #include <stdio.h>
#define LED_PIN PD6 #define LED_PIN PD6
#define RSA_16
void exit_blink() { void exit_blink() {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
@ -26,28 +27,24 @@ void enter_blink() {
int main() { int main() {
SystemInit(); SystemInit();
sprand(0);
printf("Entering...\n");
funGpioInitAll(); funGpioInitAll();
funPinMode(LED_PIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP); funPinMode(LED_PIN, GPIO_Speed_10MHz | GPIO_CNF_OUT_PP);
enter_blink(); enter_blink();
#ifdef RANDOM
uint64_t p = gen_prime(1 << 15, 1 << 16); uint64_t p = gen_prime(1 << 15, 1 << 16);
uint64_t q = p; uint64_t q = gen_prime(1 << 15, 1 << 16);
while (p == q) p = gen_prime(1 << 15, 1 << 16); while (p == q) p = gen_prime(1 << 15, 1 << 16);
#else
uint64_t p = 56857;
uint64_t q = 47963;
#endif
uint64_t n = p * q; uint64_t n = p * q;
uint64_t phi_n = (p - 1) * (q - 1); uint64_t phi_n = (p - 1) * (q - 1);
// 'e' is public. E for encrypt. // 'e' is public. E for encrypt.
uint64_t e = 0; uint64_t e = prand_range(3, phi_n - 1);
while (gcd(e, phi_n) != 1) e = prand_range(3, phi_n - 1); while (gcd(e, phi_n) != 1) e = prand_range(3, phi_n - 1);
// 'd' is our private key. D as in decrypt // 'd' is our private key. D as in decrypt