This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modmath.c
90 lines (72 loc) · 1.95 KB
/
modmath.c
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
/*
gcc -o keymath keymath.c -lgmp
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <gmp.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include "util.h"
#include "gmpecc.h"
#include "base58/libbase58.h"
#include "rmd160/rmd160.h"
#include "sha256/sha256.h"
struct Elliptic_Curve EC;
struct Point G;
struct Point DoublingG[256];
const char *version = "0.1.211009";
const char *EC_constant_N = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141";
const char *EC_constant_P = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f";
const char *EC_constant_Gx = "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798";
const char *EC_constant_Gy = "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8";
char *str_output = NULL;
char *str_input = NULL;
char *str_publickey_ptr = NULL;
char str_publickey[132];
char str_rmd160[41];
char str_address[41];
mpz_t A,B,C;
int FLAG_NUMBER = 0;
mpz_t inversemultiplier,number;
int main(int argc, char **argv) {
char buffer_input[1024];
mpz_init_set_str(EC.p, EC_constant_P, 16);
mpz_init_set_str(EC.n, EC_constant_N, 16);
mpz_init_set_str(G.x , EC_constant_Gx, 16);
mpz_init_set_str(G.y , EC_constant_Gy, 16);
mpz_init_set_ui(A,0);
mpz_init_set_ui(B,0);
mpz_init_set_ui(C,0);
mpz_init(number);
mpz_init(inversemultiplier);
if(argc < 4) {
printf("Missing parameters\n");
exit(0);
}
mpz_set_str(A,argv[1],0);
mpz_set_str(B,argv[3],0);
switch(argv[2][0]) {
case '+':
mpz_add(C,A,B);
mpz_mod(C,C,EC.n);
break;
case '-':
mpz_sub(C,A,B);
mpz_mod(C,C,EC.n);
break;
case '/':
mpz_invert(inversemultiplier,B,EC.n);
mpz_mul(C,A,inversemultiplier);
mpz_mod(C,C,EC.n);
break;
case 'x':
mpz_mul(C,A,B);
mpz_mod(C,C,EC.n);
break;
}
gmp_printf("Result: %Zx\n\n",C);
}