summaryrefslogtreecommitdiff
path: root/lib/lib5.h
blob: 0c2571fce3fccd12cca8bdebab33f69e7a43e887 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifndef __LIB_5__
#define __LIB_5__

#include <stdlib.h>
#include <stdint.h>
#include <gmp.h>
#include <math.h>
#include <openssl/bn.h>
#include<openssl/bio.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;
};

struct dh_param_bignum {
	BIGNUM *A;
	BIGNUM *B;
	BIGNUM *a;
	BIGNUM *b;
	BIGNUM *p;
	BIGNUM *g;
	BIGNUM *s1;
	BIGNUM *s2;
};

struct srp_context {
	BIGNUM *salt;
	BIGNUM *v;
	BIGNUM *g;
	BIGNUM *N;
	BIGNUM *a;
	BIGNUM *u;
	BIGNUM *k;
	BIGNUM *b;
	BIGNUM *B;
	BIGNUM *A;
	char client_K[20];
	char server_K[20];
};

// global openssl context for auxaliry results
BN_CTX *ctx;
BIO *out;

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 dh_init_bignum(struct dh_param_bignum *dh);
void dh_generate_secret_keys_bignum(struct dh_param_bignum *dh);
void dh_generate_public_keys_bignum(struct dh_param_bignum *dh);
void dh_get_session_key_bignum(struct dh_param_bignum *dh);
void do_dh_key_exchange_bignum(struct dh_param_bignum *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);
void extended_euclid_algo_bignum(BIGNUM *a, BIGNUM *b, struct extended_euclid_bignum *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);
int rsa_broadcast_cube(BIGNUM *res, BIGNUM **a, BIGNUM **n);
int chinese_remainder_theorem_bignum(BIGNUM *solution, BIGNUM *sol_no_mod, BIGNUM **a, BIGNUM **n, int len);
int check_co_prime_bignum(BIGNUM *a, BIGNUM *b);
int check_co_prime_bignum(BIGNUM *a, BIGNUM *b);
int __chinese_remainder_theorem_bignum(BIGNUM *solution, BIGNUM *sol_no_mod, BIGNUM **a, BIGNUM **n, int len);
int check_co_prime(int a, int b);
int __chinese_remainder_theorem(int *a, int *n, int len);
int nth_root_bignum(BIGNUM *res, BIGNUM *number, BIGNUM *n);
double nth_root_wr(double x, int n);
void srp_server_init(char *email, char *password, struct srp_context *srpc);
void srp_client_send1(char *email, struct srp_context *srpc);
void srp_server_send1(struct srp_context *srpc);
void srp_compute_uH(struct srp_context *srpc);
void srp_client_prepare_k(struct srp_context *srpc, char *password);
void srp_server_prepare_k(struct srp_context *srpc);
void srp_context_init(struct srp_context *s);
void srp_client_s_0_prepare_k(struct srp_context *srpc);
void ssrp_compute_uH(struct srp_context *srpc);
void ssrp_server_send1(struct srp_context *srpc);
void ssrp_client_prepare_k(struct srp_context *srpc, char *password);
void srp_server_prepare_k(struct srp_context *srpc);
void ssrp_dictionary_attack(struct srp_context *srpc);
#endif