33 lines
868 B
C
33 lines
868 B
C
#include "rsa.h"
|
|
|
|
rsa_t rsa_init(size_t len) {
|
|
rsa_t rsa;
|
|
|
|
printf("Generating two primes of length %d bits\n", RSA_BLOCK_SIZE / 2);
|
|
//printf("Generating p...\n");
|
|
rsa.p = bigint_prime(len / 2);
|
|
printf("p = %lu\n", ((uint64_t)rsa.p.data[1] << 32) + (uint64_t)rsa.p.data[0]);
|
|
//printf("p = %u\n", rsa.p.data[0]);
|
|
//printf("Generating q...\n");
|
|
rsa.q = bigint_prime(len / 2);
|
|
printf("q = %lu\n", ((uint64_t)rsa.q.data[1] << 32) + (uint64_t)rsa.q.data[0]);
|
|
//printf("q = %u\n", rsa.q.data[0]);
|
|
|
|
|
|
return rsa;
|
|
}
|
|
|
|
rsa_t rsa_generate_keys(size_t block_size) {
|
|
size_t len = block_size / sizeof(uint32_t) / 8;
|
|
rsa_t rsa = rsa_init(len);
|
|
bigint_destroy(rsa.p);
|
|
bigint_destroy(rsa.q);
|
|
for (int i = 0; i < 18; i++) {
|
|
bigint_t p = bigint_prime(len / 2);
|
|
printf("%lu\n", ((uint64_t)p.data[1] << 32) + (uint64_t)p.data[0]);
|
|
bigint_destroy(p);
|
|
}
|
|
return rsa;
|
|
}
|
|
|