inc/CryptX_AuthEnc_CCM.xs.inc

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