line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = CryptX PACKAGE = Crypt::Stream::Salsa20 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Crypt::Stream::Salsa20 |
6
|
|
|
|
|
|
|
new(Class, SV * key, SV * nonce, UV counter = 0, int rounds = 20) |
7
|
|
|
|
|
|
|
CODE: |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
int rv; |
10
|
578
|
|
|
|
|
|
STRLEN iv_len=0, k_len=0; |
11
|
578
|
|
|
|
|
|
unsigned char *iv=NULL, *k=NULL; |
12
|
|
|
|
|
|
|
|
13
|
578
|
50
|
|
|
|
|
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); |
14
|
578
|
50
|
|
|
|
|
if (!SvPOK(nonce)) croak("FATAL: nonce must be string/buffer scalar"); |
15
|
578
|
50
|
|
|
|
|
k = (unsigned char *)SvPVbyte(key, k_len); |
16
|
578
|
50
|
|
|
|
|
iv = (unsigned char *)SvPVbyte(nonce, iv_len); |
17
|
|
|
|
|
|
|
|
18
|
578
|
|
|
|
|
|
Newz(0, RETVAL, 1, salsa20_state); |
19
|
578
|
50
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
20
|
|
|
|
|
|
|
|
21
|
578
|
|
|
|
|
|
rv = salsa20_setup(RETVAL, k, (unsigned long)k_len, rounds); |
22
|
578
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
23
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
24
|
0
|
|
|
|
|
|
croak("FATAL: salsa20_setup failed: %s", error_to_string(rv)); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
578
|
|
|
|
|
|
rv = salsa20_ivctr64(RETVAL, iv, (unsigned long)iv_len, (ulong64)counter); |
28
|
578
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
29
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
30
|
0
|
|
|
|
|
|
croak("FATAL: salsa20_ivctr64 failed: %s", error_to_string(rv)); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
OUTPUT: |
34
|
|
|
|
|
|
|
RETVAL |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
void |
37
|
|
|
|
|
|
|
DESTROY(Crypt::Stream::Salsa20 self) |
38
|
|
|
|
|
|
|
CODE: |
39
|
578
|
|
|
|
|
|
salsa20_done(self); |
40
|
578
|
|
|
|
|
|
Safefree(self); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Crypt::Stream::Salsa20 |
43
|
|
|
|
|
|
|
clone(Crypt::Stream::Salsa20 self) |
44
|
|
|
|
|
|
|
CODE: |
45
|
0
|
|
|
|
|
|
Newz(0, RETVAL, 1, salsa20_state); |
46
|
0
|
0
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
47
|
0
|
|
|
|
|
|
Copy(self, RETVAL, 1, salsa20_state); |
48
|
|
|
|
|
|
|
OUTPUT: |
49
|
|
|
|
|
|
|
RETVAL |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
SV * |
52
|
|
|
|
|
|
|
keystream(Crypt::Stream::Salsa20 self, STRLEN out_len) |
53
|
|
|
|
|
|
|
CODE: |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
int rv; |
56
|
|
|
|
|
|
|
unsigned char *out_data; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
if (out_len == 0) { |
59
|
0
|
|
|
|
|
|
RETVAL = newSVpvn("", 0); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
else { |
62
|
0
|
|
|
|
|
|
RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
63
|
0
|
|
|
|
|
|
SvPOK_only(RETVAL); |
64
|
0
|
|
|
|
|
|
SvCUR_set(RETVAL, out_len); |
65
|
0
|
|
|
|
|
|
out_data = (unsigned char *)SvPVX(RETVAL); |
66
|
0
|
|
|
|
|
|
rv = salsa20_keystream(self, out_data, (unsigned long)out_len); |
67
|
0
|
0
|
|
|
|
|
if (rv != CRYPT_OK) { |
68
|
0
|
|
|
|
|
|
SvREFCNT_dec(RETVAL); |
69
|
0
|
|
|
|
|
|
croak("FATAL: salsa20_keystream failed: %s", error_to_string(rv)); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
OUTPUT: |
74
|
|
|
|
|
|
|
RETVAL |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
SV * |
77
|
|
|
|
|
|
|
crypt(Crypt::Stream::Salsa20 self, SV * data) |
78
|
|
|
|
|
|
|
CODE: |
79
|
|
|
|
|
|
|
{ |
80
|
|
|
|
|
|
|
int rv; |
81
|
|
|
|
|
|
|
STRLEN in_data_len; |
82
|
|
|
|
|
|
|
unsigned char *in_data, *out_data; |
83
|
|
|
|
|
|
|
|
84
|
578
|
50
|
|
|
|
|
in_data = (unsigned char *)SvPVbyte(data, in_data_len); |
85
|
578
|
50
|
|
|
|
|
if (in_data_len == 0) { |
86
|
0
|
|
|
|
|
|
RETVAL = newSVpvn("", 0); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
else { |
89
|
578
|
|
|
|
|
|
RETVAL = NEWSV(0, in_data_len); /* avoid zero! */ |
90
|
578
|
|
|
|
|
|
SvPOK_only(RETVAL); |
91
|
578
|
|
|
|
|
|
SvCUR_set(RETVAL, in_data_len); |
92
|
578
|
|
|
|
|
|
out_data = (unsigned char *)SvPVX(RETVAL); |
93
|
578
|
|
|
|
|
|
rv = salsa20_crypt(self, in_data, (unsigned long)in_data_len, out_data); |
94
|
578
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
95
|
0
|
|
|
|
|
|
SvREFCNT_dec(RETVAL); |
96
|
0
|
|
|
|
|
|
croak("FATAL: salsa20_crypt failed: %s", error_to_string(rv)); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
OUTPUT: |
101
|
|
|
|
|
|
|
RETVAL |