line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
MODULE = CryptX PACKAGE = Crypt::Mac::Poly1305 |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY! |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Crypt::Mac::Poly1305 |
8
|
|
|
|
|
|
|
new(Class, SV * key) |
9
|
|
|
|
|
|
|
CODE: |
10
|
|
|
|
|
|
|
{ |
11
|
18
|
|
|
|
|
|
STRLEN k_len=0; |
12
|
18
|
|
|
|
|
|
unsigned char *k=NULL; |
13
|
|
|
|
|
|
|
int rv; |
14
|
|
|
|
|
|
|
|
15
|
18
|
50
|
|
|
|
|
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); |
16
|
18
|
50
|
|
|
|
|
k = (unsigned char *) SvPVbyte(key, k_len); |
17
|
|
|
|
|
|
|
|
18
|
18
|
|
|
|
|
|
Newz(0, RETVAL, 1, poly1305_state); |
19
|
18
|
50
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
20
|
|
|
|
|
|
|
|
21
|
18
|
|
|
|
|
|
rv = poly1305_init(RETVAL, k, (unsigned long)k_len); |
22
|
18
|
50
|
|
|
|
|
if (rv != CRYPT_OK) { |
23
|
0
|
|
|
|
|
|
Safefree(RETVAL); |
24
|
0
|
|
|
|
|
|
croak("FATAL: poly1305_init failed: %s", error_to_string(rv)); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
OUTPUT: |
28
|
|
|
|
|
|
|
RETVAL |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
void |
31
|
|
|
|
|
|
|
DESTROY(Crypt::Mac::Poly1305 self) |
32
|
|
|
|
|
|
|
CODE: |
33
|
18
|
|
|
|
|
|
Safefree(self); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Crypt::Mac::Poly1305 |
36
|
|
|
|
|
|
|
clone(Crypt::Mac::Poly1305 self) |
37
|
|
|
|
|
|
|
CODE: |
38
|
0
|
|
|
|
|
|
Newz(0, RETVAL, 1, poly1305_state); |
39
|
0
|
0
|
|
|
|
|
if (!RETVAL) croak("FATAL: Newz failed"); |
40
|
0
|
|
|
|
|
|
Copy(self, RETVAL, 1, poly1305_state); |
41
|
|
|
|
|
|
|
OUTPUT: |
42
|
|
|
|
|
|
|
RETVAL |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
void |
45
|
|
|
|
|
|
|
add(Crypt::Mac::Poly1305 self, ...) |
46
|
|
|
|
|
|
|
PPCODE: |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
int rv, i; |
49
|
|
|
|
|
|
|
STRLEN in_data_len; |
50
|
|
|
|
|
|
|
unsigned char *in_data; |
51
|
|
|
|
|
|
|
|
52
|
52
|
100
|
|
|
|
|
for(i = 1; i < items; i++) { |
53
|
30
|
100
|
|
|
|
|
in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len); |
54
|
30
|
100
|
|
|
|
|
if (in_data_len > 0) { |
55
|
26
|
|
|
|
|
|
rv = poly1305_process(self, in_data, (unsigned long)in_data_len); |
56
|
26
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv)); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
22
|
50
|
|
|
|
|
XPUSHs(ST(0)); /* return self */ |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
SV * |
63
|
|
|
|
|
|
|
mac(Crypt::Mac::Poly1305 self) |
64
|
|
|
|
|
|
|
ALIAS: |
65
|
|
|
|
|
|
|
hexmac = 1 |
66
|
|
|
|
|
|
|
b64mac = 2 |
67
|
|
|
|
|
|
|
b64umac = 3 |
68
|
|
|
|
|
|
|
CODE: |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
unsigned char mac[MAXBLOCKSIZE]; |
71
|
|
|
|
|
|
|
unsigned long maclen, outlen; |
72
|
|
|
|
|
|
|
int rv; |
73
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2+1]; |
74
|
|
|
|
|
|
|
|
75
|
18
|
|
|
|
|
|
maclen = sizeof(mac); |
76
|
18
|
|
|
|
|
|
rv = poly1305_done(self, mac, &maclen); |
77
|
18
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv)); |
78
|
18
|
|
|
|
|
|
outlen = sizeof(out); |
79
|
18
|
100
|
|
|
|
|
if (ix == 3) { |
80
|
1
|
|
|
|
|
|
rv = base64url_encode(mac, maclen, out, &outlen); |
81
|
1
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
82
|
1
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
83
|
|
|
|
|
|
|
} |
84
|
17
|
100
|
|
|
|
|
else if (ix == 2) { |
85
|
1
|
|
|
|
|
|
rv = base64_encode(mac, maclen, out, &outlen); |
86
|
1
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
87
|
1
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
88
|
|
|
|
|
|
|
} |
89
|
16
|
100
|
|
|
|
|
else if (ix == 1) { |
90
|
8
|
|
|
|
|
|
rv = base16_encode(mac, maclen, out, &outlen, 0); |
91
|
8
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
92
|
8
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
else { |
95
|
8
|
|
|
|
|
|
RETVAL = newSVpvn((char * )mac, maclen); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
OUTPUT: |
99
|
|
|
|
|
|
|
RETVAL |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
SV * |
102
|
|
|
|
|
|
|
poly1305(SV * key, ...) |
103
|
|
|
|
|
|
|
ALIAS: |
104
|
|
|
|
|
|
|
poly1305_hex = 1 |
105
|
|
|
|
|
|
|
poly1305_b64 = 2 |
106
|
|
|
|
|
|
|
poly1305_b64u = 3 |
107
|
|
|
|
|
|
|
CODE: |
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
STRLEN inlen, klen; |
110
|
|
|
|
|
|
|
unsigned char *in; |
111
|
28
|
50
|
|
|
|
|
unsigned char *k = (unsigned char *)SvPVbyte(key, klen); |
112
|
|
|
|
|
|
|
int rv, i; |
113
|
|
|
|
|
|
|
unsigned char mac[MAXBLOCKSIZE]; |
114
|
28
|
|
|
|
|
|
unsigned long len = sizeof(mac), outlen; |
115
|
|
|
|
|
|
|
char out[MAXBLOCKSIZE*2]; |
116
|
|
|
|
|
|
|
poly1305_state st; |
117
|
|
|
|
|
|
|
|
118
|
28
|
|
|
|
|
|
rv = poly1305_init(&st, k, (unsigned long)klen); |
119
|
28
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: poly1305_init failed: %s", error_to_string(rv)); |
120
|
64
|
100
|
|
|
|
|
for (i = 1; i < items; i++) { |
121
|
36
|
100
|
|
|
|
|
in = (unsigned char *)SvPVbyte(ST(i), inlen); |
122
|
36
|
100
|
|
|
|
|
if (inlen > 0) { |
123
|
28
|
|
|
|
|
|
rv = poly1305_process(&st, in, (unsigned long)inlen); |
124
|
28
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: poly1305_process failed: %s", error_to_string(rv)); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
28
|
|
|
|
|
|
rv = poly1305_done(&st, mac, &len); |
128
|
28
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: poly1305_done failed: %s", error_to_string(rv)); |
129
|
|
|
|
|
|
|
|
130
|
28
|
|
|
|
|
|
outlen = sizeof(out); |
131
|
28
|
100
|
|
|
|
|
if (ix == 3) { |
132
|
7
|
|
|
|
|
|
rv = base64url_encode(mac, len, out, &outlen); |
133
|
7
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); |
134
|
7
|
|
|
|
|
|
RETVAL = newSVpvn((char *) out, outlen); |
135
|
|
|
|
|
|
|
} |
136
|
21
|
100
|
|
|
|
|
else if (ix == 2) { |
137
|
7
|
|
|
|
|
|
rv = base64_encode(mac, len, out, &outlen); |
138
|
7
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); |
139
|
7
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
140
|
|
|
|
|
|
|
} |
141
|
14
|
100
|
|
|
|
|
else if (ix == 1) { |
142
|
7
|
|
|
|
|
|
rv = base16_encode(mac, len, out, &outlen, 0); |
143
|
7
|
50
|
|
|
|
|
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); |
144
|
7
|
|
|
|
|
|
RETVAL = newSVpvn(out, outlen); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
else { |
147
|
7
|
|
|
|
|
|
RETVAL = newSVpvn((char *) mac, len); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
OUTPUT: |
151
|
|
|
|
|
|
|
RETVAL |