#ifndef __LIB_5__ #define __LIB_5__ #include #include #include #include #include #include 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