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
61
62
63
64
65
66
67
68
|
#ifndef __LIB_5__
#define __LIB_5__
#include <stdlib.h>
#include <stdint.h>
#include <gmp.h>
#include <openssl/bn.h>
struct dh_param {
mpz_t A;
mpz_t B;
unsigned char *a;
unsigned char *b;
unsigned char *p;
unsigned char *g;
mpz_t s1;
mpz_t s2;
};
// global openssl context for auxaliry results
BN_CTX *ctx;
struct extended_euclid {
int d;
int s;
int t;
};
struct extended_euclid_bignum {
BIGNUM *d;
BIGNUM *s;
BIGNUM *t;
};
struct rsa_key {
int exponent;
int modulo;
};
struct rsa_key_bignum {
BIGNUM *exponent;
BIGNUM *modulo;
};
void mod_bignums(unsigned char *number, unsigned char *mod, unsigned int base, unsigned char **erg);
void modexp_bignums(unsigned char *base, unsigned char *exp, unsigned char *mod, int string_base,
mpz_t *erg_mp);
void modexp_mpz(mpz_t *base_mp, unsigned char *exp, unsigned char *mod, int string_base,
mpz_t *erg_mp);
void dh_init(struct dh_param *dh);
void dh_generate_secret_keys(struct dh_param *dh);
void dh_generate_public_keys(struct dh_param *dh);
void dh_get_session_key(struct dh_param *dh);
void do_dh_key_exchange(struct dh_param *dh);
void sha1_key_from_dh(struct dh_param *dh, unsigned char *key);
void dh_mitm(struct dh_param *dh);
int rsa_decrypt_bignum(BIGNUM *message, BIGNUM *res, struct rsa_key_bignum *private);
int rsa_encrypt_bignum(BIGNUM *message, BIGNUM *res, struct rsa_key_bignum *public);
void die(char *message);
int rsa_decrpyt(int message, struct rsa_key *private);
int rsa_encrypt(int message, struct rsa_key *public);
int modulo(int a, int b);
void extended_euclid_algo(int a, int b, struct extended_euclid *e);
int rsa_generate_key_bignum(struct rsa_key_bignum *public, struct rsa_key_bignum *private);
int free_rsa_key_bignum(struct rsa_key_bignum *t);
int modular_multiplicative_inverse_bignum_my(BIGNUM *res, BIGNUM *number, BIGNUM *modulo);
int modular_multiplicative_inverse(int number, int _modulo);
#endif
|