inc/CryptX_AuthEnc_ChaCha20Poly1305.xs.inc

filter: Statementstmt 84.9% 124 / 146 Branchbran 39.4% 93 / 236 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 56.8% 217 / 382 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_AuthEnc_EAX.xs.inc ↑ Summary inc/CryptX_AuthEnc_GCM.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::AuthEnc::ChaCha20Poly1305
2  
3 PROTOTYPES: DISABLE
4  
5 Crypt::AuthEnc::ChaCha20Poly1305
6 new(Class, SV * key, SV * nonce = NULL)
7 CODE:
8 {
9 int rv;
10 8 STRLEN iv_len=0, k_len=0;
11 8 unsigned char *iv=NULL, *k=NULL;
12  
13 8 ▶ if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 8 0 8
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 8 8
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 0 0
14 8 k = (unsigned char *) SvPVbyte(key, k_len);
15 8 ▶ if (nonce) {
Branch: 1 branch
BranchTrueFalseTotal
if (nonce) { 7 1 8
16 7 ▶ if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 7 0 7
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 7 7
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
17 7 iv = (unsigned char *) SvPVbyte(nonce, iv_len);
18 }
19  
20 8 Newz(0, RETVAL, 1, struct cryptx_authenc_chacha20poly1305_struct);
21 8 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 8 8
22  
23 8 rv = chacha20poly1305_init(&RETVAL->state, k, (unsigned long)k_len);
24 8 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 8 8
25 0 zeromem(RETVAL, sizeof(*RETVAL));
26 0 Safefree(RETVAL);
27 0 croak("FATAL: chacha20poly1305_init failed: %s", error_to_string(rv));
28 }
29  
30 8 ▶ if (iv && iv_len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (iv && iv_len > 0) { 7 1 8
if (iv && iv_len > 0) { 7 0 7
31 7 rv = chacha20poly1305_setiv(&RETVAL->state, iv, (unsigned long)iv_len);
32 7 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 7 7
33 0 zeromem(RETVAL, sizeof(*RETVAL));
34 0 Safefree(RETVAL);
35 0 croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv));
36 }
37 }
38 }
39 OUTPUT:
40 RETVAL
41  
42 void
43 DESTROY(Crypt::AuthEnc::ChaCha20Poly1305 self)
44 CODE:
45 10 ▶ if (self) {
Branch: 1 branch
BranchTrueFalseTotal
if (self) { 10 0 10
46 10 zeromem(self, sizeof(*self));
47 10 Safefree(self);
48 }
49  
50 Crypt::AuthEnc::ChaCha20Poly1305
51 clone(Crypt::AuthEnc::ChaCha20Poly1305 self)
52 CODE:
53 2 Newz(0, RETVAL, 1, struct cryptx_authenc_chacha20poly1305_struct);
54 2 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 2 2
55 2 Copy(self, RETVAL, 1, struct cryptx_authenc_chacha20poly1305_struct);
56 OUTPUT:
57 RETVAL
58  
59 void
60 set_iv(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce)
61 PPCODE:
62 {
63 int rv;
64 1 STRLEN iv_len=0;
65 1 unsigned char *iv=NULL;
66  
67 1 ▶ if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 1 1
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
68 1 iv = (unsigned char *) SvPVbyte(nonce, iv_len);
69 1 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 0 1 1
70 1 rv = chacha20poly1305_setiv(&self->state, iv, (unsigned long)iv_len);
71 1 ▶ if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv failed: %s", error_to_string(rv)); 0 1 1
72 1 ▶ XPUSHs(ST(0)); /* return self */;
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */; 0 1 1
73 }
74  
75 void
76 set_iv_rfc7905(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * nonce, UV seqnum)
77 PPCODE:
78 {
79 int rv;
80 0 STRLEN iv_len=0;
81 0 unsigned char *iv=NULL;
82  
83 0 ▶ if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 0 0
84 0 iv = (unsigned char *) SvPVbyte(nonce, iv_len);
85 0 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 0 0 0
86 0 rv = chacha20poly1305_setiv_rfc7905(&self->state, iv, (unsigned long)iv_len, (ulong64)seqnum);
87 0 ▶ if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv_rfc7905 failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_setiv_rfc7905 failed: %s", error_to_string(rv)); 0 0 0
88 0 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 0 0
89 }
90  
91 void
92 adata_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
93 PPCODE:
94 {
95 int rv;
96 STRLEN in_data_len;
97 unsigned char *in_data;
98  
99 8 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 0 8 8
100 8 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
101 8 rv = chacha20poly1305_add_aad(&self->state, in_data, (unsigned long)in_data_len);
102 8 ▶ if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_add_aad failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_add_aad failed: %s", error_to_string(rv)); 0 8 8
103 8 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 8 8
104 }
105  
106 SV *
107 decrypt_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
108 CODE:
109 {
110 int rv;
111 STRLEN in_data_len;
112 unsigned char *in_data, *out_data;
113  
114 22 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 0 22 22
115 22 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
116 22 ▶ if (in_data_len == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len == 0) { 0 22 22
117 0 RETVAL = newSVpvn("", 0);
118 }
119 else {
120 22 RETVAL = NEWSV(0, in_data_len); /* avoid zero! */
121 22 SvPOK_only(RETVAL);
122 22 SvCUR_set(RETVAL, in_data_len);
123 22 *SvEND(RETVAL) = '\0';
124 22 out_data = (unsigned char *)SvPVX(RETVAL);
125 22 rv = chacha20poly1305_decrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
126 22 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 22 22
127 0 SvREFCNT_dec(RETVAL);
128 0 croak("FATAL: chacha20poly1305_decrypt failed: %s", error_to_string(rv));
129 }
130 }
131 }
132 OUTPUT:
133 RETVAL
134  
135 SV *
136 encrypt_add(Crypt::AuthEnc::ChaCha20Poly1305 self, SV * data)
137 CODE:
138 {
139 int rv;
140 STRLEN in_data_len;
141 unsigned char *in_data, *out_data;
142  
143 11 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 2 9 11
144 9 in_data = (unsigned char *)SvPVbyte(data, in_data_len);
145 9 ▶ if (in_data_len == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len == 0) { 0 9 9
146 0 RETVAL = newSVpvn("", 0);
147 }
148 else {
149 9 RETVAL = NEWSV(0, in_data_len); /* avoid zero! */
150 9 SvPOK_only(RETVAL);
151 9 SvCUR_set(RETVAL, in_data_len);
152 9 *SvEND(RETVAL) = '\0';
153 9 out_data = (unsigned char *)SvPVX(RETVAL);
154 9 rv = chacha20poly1305_encrypt(&self->state, in_data, (unsigned long)in_data_len, out_data);
155 9 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 9 9
156 0 SvREFCNT_dec(RETVAL);
157 0 croak("FATAL: chacha20poly1305_encrypt failed: %s", error_to_string(rv));
158 }
159 }
160 }
161 OUTPUT:
162 RETVAL
163  
164 void
165 encrypt_done(Crypt::AuthEnc::ChaCha20Poly1305 self)
166 PPCODE:
167 {
168 int rv;
169 unsigned char tag[MAXBLOCKSIZE];
170 9 unsigned long tag_len = sizeof(tag);
171  
172 9 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 2 7 9
173 7 rv = chacha20poly1305_done(&self->state, tag, &tag_len);
174 7 ▶ if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv)); 0 7 7
175 7 self->finalized = 1;
176 7 ▶ XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len))); 0 7 7
177 7 zeromem(tag, sizeof(tag));
178 }
179  
180 void
181 decrypt_done(Crypt::AuthEnc::ChaCha20Poly1305 self, ...)
182 PPCODE:
183 {
184 int rv;
185 unsigned char tag[MAXBLOCKSIZE];
186 3 unsigned long tag_len = sizeof(tag);
187 STRLEN expected_tag_len;
188 unsigned char *expected_tag;
189  
190 3 ▶ if (self->finalized) croak("FATAL: AEAD object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: AEAD object already finalized"); 0 3 3
191 3 rv = chacha20poly1305_done(&self->state, tag, &tag_len);
192 3 ▶ if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: chacha20poly1305_done failed: %s", error_to_string(rv)); 0 3 3
193 3 self->finalized = 1;
194 3 ▶ if (items == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) { 2 1 3
195 2 ▶ XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len))); 0 2 2
196 2 zeromem(tag, sizeof(tag));
197 }
198 else {
199 1 ▶ if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar"); 0 1 1
if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(ST(1))) croak("FATAL: expected_tag must be string/buffer scalar"); 0 0 0
200 1 expected_tag = (unsigned char *) SvPVbyte(ST(1), expected_tag_len);
201 1 ▶ if (expected_tag_len!=tag_len) {
Branch: 1 branch
BranchTrueFalseTotal
if (expected_tag_len!=tag_len) { 0 1 1
202 0 ▶ XPUSHs(sv_2mortal(newSViv(0))); /* false */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(0))); /* false */ 0 0 0
203 }
204 1 ▶ else if (mem_neq(expected_tag, tag, tag_len)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (mem_neq(expected_tag, tag, tag_len)) { 0 1 1
205 0 ▶ XPUSHs(sv_2mortal(newSViv(0))); /* false */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(0))); /* false */ 0 0 0
206 }
207 else {
208 1 ▶ XPUSHs(sv_2mortal(newSViv(1))); /* true */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(1))); /* true */ 0 1 1
209 }
210 }
211 }
212  
213 void
214 chacha20poly1305_encrypt_authenticate(SV *key, SV *nonce, SV *header, SV *plaintext)
215 PPCODE:
216 {
217 31 STRLEN k_len = 0, n_len = 0, h_len = 0, pt_len = 0;
218 31 unsigned char *k = NULL, *n = NULL, *h = NULL, *pt = NULL;
219 int rv;
220 unsigned char tag[MAXBLOCKSIZE];
221 31 unsigned long tag_len = sizeof(tag);
222 SV *output;
223  
224 31 ▶ if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 31 0 31
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 2 29 31
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 2 0 2
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 2 0 2
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 2 2
225 31 k = (unsigned char *) SvPVbyte(key, k_len);
226 31 ▶ if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 31 0 31
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 2 29 31
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 2 0 2
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 2 0 2
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 2 2
227 31 n = (unsigned char *) SvPVbyte(nonce, n_len);
228 31 ▶ if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar"); 31 0 31
if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar"); 0 31 31
if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(plaintext)) croak("FATAL: plaintext must be string/buffer scalar"); 0 0 0
229 31 pt = (unsigned char *) SvPVbyte(plaintext, pt_len);
230 31 ▶ if (header && SvOK(header)) {
Branch: 2 branches
BranchTrueFalseTotal
if (header && SvOK(header)) { 31 0 31
if (header && SvOK(header)) { 31 0 31
231 31 ▶ if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 31 0 31
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 31 31
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
232 31 h = (unsigned char *) SvPVbyte(header, h_len);
233 31 zeromem(tag, sizeof(tag));
234 }
235  
236 31 ▶ output = NEWSV(0, pt_len > 0 ? pt_len : 1); /* avoid zero! */
Branch: 1 branch
BranchTrueFalseTotal
output = NEWSV(0, pt_len > 0 ? pt_len : 1); /* avoid zero! */ 31 0 31
237 31 SvPOK_only(output);
238 31 SvCUR_set(output, pt_len);
239 31 *SvEND(output) = '\0';
240  
241 31 rv = chacha20poly1305_memory(k, (unsigned long)k_len, n, (unsigned long)n_len, h, (unsigned long)h_len,
242 31 pt, (unsigned long)pt_len, (unsigned char *)SvPVX(output), tag, &tag_len,
243 CHACHA20POLY1305_ENCRYPT);
244  
245 31 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 2 29 31
246 2 SvREFCNT_dec(output);
247 2 croak("FATAL: chacha20poly1305_memory failed: %s", error_to_string(rv));
248 }
249 29 ▶ XPUSHs(sv_2mortal(output));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(output)); 0 29 29
250 29 ▶ XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn((char*)tag, tag_len))); 0 29 29
251 }
252  
253 void
254 chacha20poly1305_decrypt_verify(SV *key, SV *nonce, SV *header, SV *ciphertext, SV *tagsv)
255 PPCODE:
256 {
257 26 STRLEN k_len = 0, n_len = 0, h_len = 0, ct_len = 0, t_len = 0;
258 26 unsigned char *k = NULL, *n = NULL, *h = NULL, *ct = NULL, *t = NULL;
259 int rv;
260 unsigned char tag[MAXBLOCKSIZE];
261 unsigned long tag_len;
262 SV *output;
263  
264 26 ▶ if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 26 0 26
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 25 26
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 1 1
265 26 k = (unsigned char *) SvPVbyte(key, k_len);
266 26 ▶ if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 26 0 26
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 1 25 26
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(nonce)) croak("FATAL: nonce must be string/buffer scalar"); 0 1 1
267 26 n = (unsigned char *) SvPVbyte(nonce, n_len);
268 26 ▶ if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar"); 26 0 26
if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar"); 0 26 26
if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(ciphertext)) croak("FATAL: ciphertext must be string/buffer scalar"); 0 0 0
269 26 ct = (unsigned char *) SvPVbyte(ciphertext, ct_len);
270 26 ▶ if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar"); 26 0 26
if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar"); 0 26 26
if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(tagsv)) croak("FATAL: tag must be string/buffer scalar"); 0 0 0
271 26 t = (unsigned char *) SvPVbyte(tagsv, t_len);
272 26 ▶ if (header && SvOK(header)) {
Branch: 2 branches
BranchTrueFalseTotal
if (header && SvOK(header)) { 26 0 26
if (header && SvOK(header)) { 26 0 26
273 26 ▶ if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar");
Branch: 5 branches
BranchTrueFalseTotal
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 26 0 26
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 26 26
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
if (!SvPOK_spec(header)) croak("FATAL: header must be string/buffer scalar"); 0 0 0
274 26 h = (unsigned char *) SvPVbyte(header, h_len);
275 26 zeromem(tag, sizeof(tag));
276 }
277  
278 26 ▶ output = NEWSV(0, ct_len > 0 ? ct_len : 1); /* avoid zero! */
Branch: 1 branch
BranchTrueFalseTotal
output = NEWSV(0, ct_len > 0 ? ct_len : 1); /* avoid zero! */ 26 0 26
279 26 SvPOK_only(output);
280 26 SvCUR_set(output, ct_len);
281 26 *SvEND(output) = '\0';
282 /* Clamp malformed tags to the stack buffer size before copying. */
283 26 tag_len = (unsigned long)(t_len > sizeof(tag) ? sizeof(tag) : t_len);
284 26 ▶ if (tag_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (tag_len > 0) { 24 2 26
285 24 Copy(t, tag, tag_len, unsigned char);
286 }
287  
288 26 rv = chacha20poly1305_memory(k, (unsigned long)k_len, n, (unsigned long)n_len, h, (unsigned long)h_len,
289 26 ct, (unsigned long)ct_len, (unsigned char *)SvPVX(output), tag, &tag_len,
290 CHACHA20POLY1305_DECRYPT);
291  
292 26 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 10 16 26
293 10 SvREFCNT_dec(output);
294 10 ▶ XPUSHs(sv_2mortal(newSVpvn(NULL,0))); /* undef */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpvn(NULL,0))); /* undef */ 0 10 10
295 }
296 else {
297 16 ▶ XPUSHs(sv_2mortal(output));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(output)); 0 16 16
298 }
299 }
« inc/CryptX_AuthEnc_EAX.xs.inc ↑ Summary inc/CryptX_AuthEnc_GCM.xs.inc »