line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
#include "ppport.h" |
7
|
|
|
|
|
|
|
#include "uECC.h" |
8
|
|
|
|
|
|
|
#include "uECC.c" |
9
|
|
|
|
|
|
|
#include "get_curve.c" |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MODULE = MicroECC PACKAGE = MicroECC |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
TYPEMAP: <
|
16
|
|
|
|
|
|
|
const char * T_PV |
17
|
|
|
|
|
|
|
const uint8_t * T_PV |
18
|
|
|
|
|
|
|
uint8_t * T_PV |
19
|
|
|
|
|
|
|
END |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
int |
22
|
|
|
|
|
|
|
curve_public_key_size(int curve_id) |
23
|
|
|
|
|
|
|
CODE: |
24
|
0
|
|
|
|
|
|
RETVAL = uECC_curve_public_key_size(get_curve(curve_id)); |
25
|
|
|
|
|
|
|
OUTPUT: |
26
|
|
|
|
|
|
|
RETVAL |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
int |
29
|
|
|
|
|
|
|
curve_private_key_size(int curve_id) |
30
|
|
|
|
|
|
|
CODE: |
31
|
0
|
|
|
|
|
|
RETVAL = uECC_curve_private_key_size(get_curve(curve_id)); |
32
|
|
|
|
|
|
|
OUTPUT: |
33
|
|
|
|
|
|
|
RETVAL |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
void |
36
|
|
|
|
|
|
|
make_key(int curve_id) |
37
|
|
|
|
|
|
|
INIT: |
38
|
|
|
|
|
|
|
int pubkey_len, privkey_len; |
39
|
|
|
|
|
|
|
uint8_t *pubkey, *privkey; |
40
|
|
|
|
|
|
|
uECC_Curve curve; |
41
|
|
|
|
|
|
|
int res; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
PPCODE: |
44
|
0
|
|
|
|
|
|
curve = get_curve(curve_id); |
45
|
0
|
|
|
|
|
|
pubkey_len = uECC_curve_public_key_size(curve); |
46
|
0
|
|
|
|
|
|
privkey_len = uECC_curve_private_key_size(curve); |
47
|
0
|
|
|
|
|
|
pubkey = (uint8_t *)malloc(pubkey_len); |
48
|
0
|
|
|
|
|
|
privkey = (uint8_t *)malloc(privkey_len); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
res = uECC_make_key(pubkey, privkey, curve); |
51
|
0
|
0
|
|
|
|
|
if(res) { |
52
|
0
|
0
|
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(pubkey, pubkey_len))); |
53
|
0
|
0
|
|
|
|
|
XPUSHs(sv_2mortal(newSVpv(privkey, privkey_len))); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
0
|
|
|
|
|
XPUSHs(sv_2mortal(newSVnv(errno))); |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
free(pubkey); |
59
|
0
|
|
|
|
|
|
free(privkey); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
int |
62
|
|
|
|
|
|
|
valid_public_key(const uint8_t *pubkey, int curve_id) |
63
|
|
|
|
|
|
|
CODE: |
64
|
0
|
|
|
|
|
|
RETVAL = uECC_valid_public_key(pubkey, get_curve(curve_id)); |
65
|
|
|
|
|
|
|
OUTPUT: |
66
|
|
|
|
|
|
|
RETVAL |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
SV * |
69
|
|
|
|
|
|
|
shared_secret(const uint8_t *pubkey, const uint8_t *privkey, int curve_id) |
70
|
|
|
|
|
|
|
CODE: |
71
|
|
|
|
|
|
|
uint8_t *secret; |
72
|
|
|
|
|
|
|
int secret_size; |
73
|
|
|
|
|
|
|
SV *d; |
74
|
|
|
|
|
|
|
int ret; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
uECC_Curve curve = get_curve(curve_id); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
secret_size = uECC_curve_public_key_size(curve) / 2; |
79
|
0
|
|
|
|
|
|
secret = (uint8_t *)malloc(secret_size); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
ret = uECC_shared_secret(pubkey, privkey, secret, curve); |
82
|
0
|
0
|
|
|
|
|
if(ret) { |
83
|
0
|
|
|
|
|
|
d = newSVpv(secret, 32); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
0
|
|
|
|
|
|
d = sv_newmortal(); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
free(secret); |
89
|
0
|
|
|
|
|
|
RETVAL = d; |
90
|
|
|
|
|
|
|
OUTPUT: |
91
|
|
|
|
|
|
|
RETVAL |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
SV * |
94
|
|
|
|
|
|
|
compute_public_key(const uint8_t *private_key, int curve_id) |
95
|
|
|
|
|
|
|
CODE: |
96
|
0
|
|
|
|
|
|
int public_key_size = uECC_curve_public_key_size(get_curve(curve_id)); |
97
|
0
|
|
|
|
|
|
uint8_t *public_key = (uint8_t *)malloc(public_key_size); |
98
|
0
|
|
|
|
|
|
int res = uECC_compute_public_key(private_key, public_key, get_curve(curve_id)); |
99
|
|
|
|
|
|
|
SV *d; |
100
|
0
|
0
|
|
|
|
|
if(res) { |
101
|
0
|
|
|
|
|
|
d = newSVpv(public_key, public_key_size); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
d = sv_newmortal(); |
105
|
|
|
|
|
|
|
} |
106
|
0
|
|
|
|
|
|
RETVAL = d; |
107
|
0
|
|
|
|
|
|
free(public_key); |
108
|
|
|
|
|
|
|
OUTPUT: |
109
|
|
|
|
|
|
|
RETVAL |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
SV * |
112
|
|
|
|
|
|
|
sign(const uint8_t *private_key, const uint8_t *hash, unsigned hash_size, int curve_id) |
113
|
|
|
|
|
|
|
CODE: |
114
|
0
|
|
|
|
|
|
int public_key_size = uECC_curve_public_key_size(get_curve(curve_id)); |
115
|
0
|
|
|
|
|
|
uint8_t *signature = (uint8_t *)malloc(public_key_size); |
116
|
0
|
|
|
|
|
|
int res = uECC_sign(private_key, hash, hash_size, signature, get_curve(curve_id)); |
117
|
|
|
|
|
|
|
SV *d; |
118
|
0
|
0
|
|
|
|
|
if(res) { |
119
|
0
|
|
|
|
|
|
d = newSVpv(signature, public_key_size); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
else { |
122
|
0
|
|
|
|
|
|
d = sv_newmortal(); |
123
|
|
|
|
|
|
|
} |
124
|
0
|
|
|
|
|
|
RETVAL = d; |
125
|
0
|
|
|
|
|
|
free(signature); |
126
|
|
|
|
|
|
|
OUTPUT: |
127
|
|
|
|
|
|
|
RETVAL |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
int |
130
|
|
|
|
|
|
|
verify(const uint8_t *public_key, const uint8_t *hash, unsigned hash_size, const uint8_t *signature, int curve_id) |
131
|
|
|
|
|
|
|
CODE: |
132
|
0
|
|
|
|
|
|
RETVAL = uECC_verify(public_key, hash, hash_size, signature, get_curve(curve_id)); |
133
|
|
|
|
|
|
|
OUTPUT: |
134
|
|
|
|
|
|
|
RETVAL |