inc/CryptX_AuthEnc_EAX.xs.inc

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