line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "src/blowfish/blowfish.c" |
2
|
|
|
|
|
|
|
#include "src/ed25519/keypair.c" |
3
|
|
|
|
|
|
|
#include "src/ed25519/sign.c" |
4
|
|
|
|
|
|
|
#include "src/ed25519/verify.c" |
5
|
|
|
|
|
|
|
#include "src/ed25519/sha512.c" |
6
|
|
|
|
|
|
|
#define select(a,b,c) ed25519_select (a, b, c) |
7
|
|
|
|
|
|
|
#include "src/ed25519/ge.c" |
8
|
|
|
|
|
|
|
#include "src/ed25519/fe.c" |
9
|
|
|
|
|
|
|
#define load_3(x) sc_load_3(x) |
10
|
|
|
|
|
|
|
#define load_4(x) sc_load_4(x) |
11
|
|
|
|
|
|
|
#include "src/ed25519/sc.c" |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MODULE = Net::SSH::Perl PACKAGE = Net::SSH::Perl::Key::Ed25519 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
blf_ctx * |
18
|
|
|
|
|
|
|
bf_init() |
19
|
|
|
|
|
|
|
CODE: |
20
|
|
|
|
|
|
|
{ |
21
|
32
|
|
|
|
|
|
Newxz(RETVAL, 1, blf_ctx); |
22
|
32
|
|
|
|
|
|
Blowfish_initstate(RETVAL); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
OUTPUT: |
25
|
|
|
|
|
|
|
RETVAL |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
void |
28
|
|
|
|
|
|
|
bf_expandstate(ctx, sv_data, sv_key) |
29
|
|
|
|
|
|
|
blf_ctx *ctx |
30
|
|
|
|
|
|
|
SV *sv_data |
31
|
|
|
|
|
|
|
SV *sv_key |
32
|
|
|
|
|
|
|
CODE: |
33
|
|
|
|
|
|
|
{ |
34
|
32
|
50
|
|
|
|
|
STRLEN datalen; unsigned char *data = (unsigned char *) SvPVbyte(sv_data,datalen); |
35
|
32
|
50
|
|
|
|
|
STRLEN keylen; unsigned char *key = (unsigned char *) SvPVbyte(sv_key,keylen); |
36
|
32
|
|
|
|
|
|
Blowfish_expandstate(ctx, data, datalen, key, keylen); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
void |
40
|
|
|
|
|
|
|
bf_expand0state(ctx,sv_key) |
41
|
|
|
|
|
|
|
blf_ctx *ctx |
42
|
|
|
|
|
|
|
SV *sv_key |
43
|
|
|
|
|
|
|
CODE: |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
STRLEN keylen; |
46
|
4096
|
50
|
|
|
|
|
unsigned char *key = (unsigned char *) SvPVbyte(sv_key,keylen); |
47
|
4096
|
|
|
|
|
|
Blowfish_expand0state(ctx,key,keylen); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
SV * |
51
|
|
|
|
|
|
|
bf_encrypt_iterate(ctx, sv_data, sv_rounds) |
52
|
|
|
|
|
|
|
blf_ctx *ctx |
53
|
|
|
|
|
|
|
SV *sv_data |
54
|
|
|
|
|
|
|
SV *sv_rounds |
55
|
|
|
|
|
|
|
CODE: |
56
|
32
|
|
|
|
|
|
{ |
57
|
|
|
|
|
|
|
STRLEN datalen; |
58
|
32
|
50
|
|
|
|
|
unsigned char *data = (unsigned char *) SvPVbyte(sv_mortalcopy(sv_data),datalen); |
59
|
32
|
50
|
|
|
|
|
if (datalen % 8) |
60
|
0
|
|
|
|
|
|
croak("data must be in 8-byte chunks"); |
61
|
|
|
|
|
|
|
|
62
|
32
|
|
|
|
|
|
uint16_t words = datalen / 4; |
63
|
32
|
|
|
|
|
|
uint32_t cdata[words]; |
64
|
32
|
|
|
|
|
|
uint16_t j = 0; |
65
|
|
|
|
|
|
|
int i; |
66
|
32
|
50
|
|
|
|
|
int rounds = SvIVx(sv_rounds); |
67
|
|
|
|
|
|
|
|
68
|
288
|
100
|
|
|
|
|
for (i=0; i
|
69
|
256
|
|
|
|
|
|
cdata[i] = Blowfish_stream2word(data, datalen, &j); |
70
|
2080
|
100
|
|
|
|
|
for (i=0; i
|
71
|
2048
|
|
|
|
|
|
blf_enc(ctx, cdata, sizeof(cdata) / sizeof(uint64_t)); |
72
|
|
|
|
|
|
|
|
73
|
288
|
100
|
|
|
|
|
for (i=0; i
|
74
|
256
|
|
|
|
|
|
data[4 * i + 3] = (cdata[i] >> 24) & 0xff; |
75
|
256
|
|
|
|
|
|
data[4 * i + 2] = (cdata[i] >> 16) & 0xff; |
76
|
256
|
|
|
|
|
|
data[4 * i + 1] = (cdata[i] >> 8) & 0xff; |
77
|
256
|
|
|
|
|
|
data[4 * i ] = cdata[i] & 0xff; |
78
|
|
|
|
|
|
|
} |
79
|
32
|
|
|
|
|
|
RETVAL = newSVpvn ((char *) data, datalen); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
OUTPUT: |
82
|
|
|
|
|
|
|
RETVAL |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
void |
85
|
|
|
|
|
|
|
ed25519_generate_keypair (secret) |
86
|
|
|
|
|
|
|
SV *secret |
87
|
|
|
|
|
|
|
PPCODE: |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
STRLEN secret_l; unsigned char *secret_p; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
unsigned char public_key[32]; |
92
|
|
|
|
|
|
|
unsigned char private_key[64]; |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
|
secret_p = (unsigned char *)SvPVbyte (secret, secret_l); |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
|
if (secret_l != 32) |
97
|
0
|
|
|
|
|
|
croak ("secret has wrong length (!= 32)"); |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
|
ed25519_create_keypair (public_key, private_key, (unsigned char *)secret_p); |
100
|
|
|
|
|
|
|
|
101
|
1
|
50
|
|
|
|
|
EXTEND (SP, 2); |
102
|
1
|
|
|
|
|
|
PUSHs (sv_2mortal (newSVpvn ((char *)public_key, sizeof public_key))); |
103
|
1
|
|
|
|
|
|
PUSHs (sv_2mortal (newSVpvn ((char *)private_key, sizeof private_key))); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
SV * |
107
|
|
|
|
|
|
|
ed25519_sign_message (message, private_key) |
108
|
|
|
|
|
|
|
SV *message; |
109
|
|
|
|
|
|
|
SV *private_key; |
110
|
|
|
|
|
|
|
CODE: |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
unsigned char signature[64]; |
113
|
|
|
|
|
|
|
|
114
|
1
|
50
|
|
|
|
|
STRLEN message_l ; char *message_p = SvPVbyte (message , message_l ); |
115
|
1
|
50
|
|
|
|
|
STRLEN private_key_l; char *private_key_p = SvPVbyte (private_key, private_key_l); |
116
|
|
|
|
|
|
|
|
117
|
1
|
50
|
|
|
|
|
if (private_key_l != 64) |
118
|
0
|
|
|
|
|
|
croak ("private key has wrong length (!= 64)"); |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
|
ed25519_sign (signature, (unsigned char *)message_p, message_l, (unsigned char *)private_key_p); |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
|
RETVAL = newSVpvn ((char *)signature, sizeof signature); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
OUTPUT: |
125
|
|
|
|
|
|
|
RETVAL |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
bool |
128
|
|
|
|
|
|
|
ed25519_verify_message (SV *message, SV *public_key, SV *signature) |
129
|
|
|
|
|
|
|
CODE: |
130
|
|
|
|
|
|
|
{ |
131
|
1
|
50
|
|
|
|
|
STRLEN signature_l ; char *signature_p = SvPVbyte (signature , signature_l ); |
132
|
1
|
50
|
|
|
|
|
STRLEN message_l ; char *message_p = SvPVbyte (message , message_l ); |
133
|
1
|
50
|
|
|
|
|
STRLEN public_key_l; char *public_key_p = SvPVbyte (public_key, public_key_l); |
134
|
|
|
|
|
|
|
|
135
|
1
|
50
|
|
|
|
|
if (public_key_l != 32) |
136
|
0
|
|
|
|
|
|
croak ("public key has wrong length (!= 32)"); |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
|
RETVAL = ed25519_verify ((unsigned char *)signature_p, (unsigned char *)message_p, message_l, (unsigned char *)public_key_p); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
OUTPUT: |
141
|
|
|
|
|
|
|
RETVAL |