line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include "src/chacha/chacha.c" |
2
|
|
|
|
|
|
|
#include "src/chacha/poly1305.c" |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
MODULE = Crypt::OpenSSH::ChachaPoly PACKAGE = Crypt::OpenSSH::ChachaPoly |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
PROTOTYPES: ENABLE |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Crypt::OpenSSH::ChachaPoly |
9
|
|
|
|
|
|
|
new(class,key) |
10
|
|
|
|
|
|
|
SV *class |
11
|
|
|
|
|
|
|
SV *key |
12
|
|
|
|
|
|
|
CODE: |
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
STRLEN keysize; |
15
|
12
|
|
|
|
|
|
keysize = SvCUR(key); |
16
|
|
|
|
|
|
|
|
17
|
12
|
50
|
|
|
|
|
if (keysize != 16 && keysize != 32) |
|
|
50
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
croak ("The key must be 128 or 256 bits long"); |
19
|
|
|
|
|
|
|
|
20
|
12
|
|
|
|
|
|
Newxz(RETVAL, 1, struct chacha_ctx); |
21
|
12
|
50
|
|
|
|
|
chacha_keysetup(RETVAL, (unsigned char *) SvPV_nolen(key), keysize*8); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
OUTPUT: |
24
|
|
|
|
|
|
|
RETVAL |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
SV * |
27
|
|
|
|
|
|
|
encrypt(self,data) |
28
|
|
|
|
|
|
|
Crypt::OpenSSH::ChachaPoly self |
29
|
|
|
|
|
|
|
SV *data |
30
|
|
|
|
|
|
|
ALIAS: |
31
|
|
|
|
|
|
|
decrypt = 1 |
32
|
|
|
|
|
|
|
CODE: |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
STRLEN size; |
35
|
12
|
100
|
|
|
|
|
void *bytes = SvPV(data,size); |
36
|
|
|
|
|
|
|
|
37
|
12
|
50
|
|
|
|
|
if (size) { |
38
|
12
|
|
|
|
|
|
RETVAL = NEWSV (0, size); |
39
|
12
|
|
|
|
|
|
SvPOK_only (RETVAL); |
40
|
12
|
|
|
|
|
|
SvCUR_set (RETVAL, size); |
41
|
12
|
50
|
|
|
|
|
chacha_encrypt_bytes(self, bytes, (unsigned char *) SvPV_nolen(RETVAL), (int) size); |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
|
RETVAL = newSVpv ("", 0); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
OUTPUT: |
48
|
|
|
|
|
|
|
RETVAL |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
void |
51
|
|
|
|
|
|
|
ivsetup(self,iv,counter) |
52
|
|
|
|
|
|
|
Crypt::OpenSSH::ChachaPoly self |
53
|
|
|
|
|
|
|
SV *iv |
54
|
|
|
|
|
|
|
SV *counter |
55
|
|
|
|
|
|
|
CODE: |
56
|
|
|
|
|
|
|
{ |
57
|
12
|
50
|
|
|
|
|
STRLEN iv_l ; unsigned char *iv_p = (unsigned char *) SvPVbyte (iv, iv_l); |
58
|
|
|
|
|
|
|
/* anything beyond 64 bits is ignored */ |
59
|
12
|
50
|
|
|
|
|
if (iv_l < 8) { |
60
|
0
|
|
|
|
|
|
croak("ivsetup: iv must be 64 bits long!"); |
61
|
|
|
|
|
|
|
} |
62
|
12
|
50
|
|
|
|
|
STRLEN counter_l ; unsigned char *counter_p = (unsigned char *) SvPVbyte (counter, counter_l); |
63
|
12
|
100
|
|
|
|
|
if (counter_l == 0) |
64
|
6
|
|
|
|
|
|
counter_p = NULL; |
65
|
|
|
|
|
|
|
/* anything beyond 8 chars is ignored */ |
66
|
6
|
50
|
|
|
|
|
else if (counter_l < 8) |
67
|
0
|
|
|
|
|
|
croak ("ivsetup: counter must be 64 bits long!"); |
68
|
12
|
|
|
|
|
|
chacha_ivsetup(self, iv_p, counter_p); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
void |
72
|
|
|
|
|
|
|
DESTROY(self) |
73
|
|
|
|
|
|
|
Crypt::OpenSSH::ChachaPoly self |
74
|
|
|
|
|
|
|
CODE: |
75
|
12
|
|
|
|
|
|
Safefree(self); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
SV * |
78
|
|
|
|
|
|
|
poly1305(self,data,key) |
79
|
|
|
|
|
|
|
Crypt::OpenSSH::ChachaPoly self |
80
|
|
|
|
|
|
|
SV *data |
81
|
|
|
|
|
|
|
SV *key |
82
|
|
|
|
|
|
|
CODE: |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
STRLEN size; |
85
|
6
|
100
|
|
|
|
|
void *databytes = SvPV(data,size); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
STRLEN keysize; |
88
|
6
|
|
|
|
|
|
keysize = SvCUR(key); |
89
|
6
|
50
|
|
|
|
|
if (keysize != POLY1305_KEYLEN) |
90
|
0
|
|
|
|
|
|
croak("Key is incorrect size"); |
91
|
6
|
50
|
|
|
|
|
void *keybytes = SvPV_nolen(key); |
92
|
|
|
|
|
|
|
|
93
|
6
|
|
|
|
|
|
RETVAL = NEWSV(0, POLY1305_TAGLEN); |
94
|
6
|
|
|
|
|
|
SvPOK_only (RETVAL); |
95
|
6
|
|
|
|
|
|
SvCUR_set (RETVAL, POLY1305_TAGLEN); |
96
|
6
|
50
|
|
|
|
|
poly1305_auth((unsigned char *) SvPV_nolen(RETVAL),databytes,(int) size,keybytes); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
OUTPUT: |
99
|
|
|
|
|
|
|
RETVAL |