-
Notifications
You must be signed in to change notification settings - Fork 0
/
rsa.h
60 lines (47 loc) · 1.31 KB
/
rsa.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Author: T. Briggs
* Date: 2019-02-22
* RSA shared header
*/
#ifndef _RSA_H
#define _RSA_H
#include <gmp.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h> // For uint64
#include <stdlib.h> //
#include <math.h> // maths
typedef mpz_t rsakey_t;
typedef struct {
unsigned int num_bits;
unsigned int enc_block_size;
unsigned int dec_block_size;
rsakey_t p;
rsakey_t q;
rsakey_t n;
rsakey_t d;
rsakey_t e;
} rsa_keys_t;
typedef struct
{
rsa_keys_t *keys;
int *found;
mpz_t p;
//pthread_mutex_t lock;
} rsa_decrypt_t;
#ifdef linux
// how many byte shall we read from random source
#define RANDOM_DEVICE "/dev/urandom"
#define NUM_RANDOM_BYTES 32
#endif
//#define DEFAULT_E 65537
#define DEFAULT_E 101
void rsa_genkeys(unsigned int num_bits, rsa_keys_t *keys);
size_t rsa_encrypt(char *message, char *encrypted, int message_bytes, rsa_keys_t *keys);
size_t rsa_decrypt(char *message, char *decrypted, int message_bytes, rsa_keys_t *keys);
void rsa_testkeys(rsa_keys_t *keys);
void rsa_read_public_keys(rsa_keys_t *keys, const char *fname);
void rsa_read_private_keys(rsa_keys_t *keys, const char *fname);
void rsa_write_public_keys(rsa_keys_t *keys, const char *fname);
void rsa_write_private_keys(rsa_keys_t *keys, const char *fname);
#endif