Primitives.xs

filter: Statementstmt 98.0% 149 / 152 Branchbran 96.1% 146 / 154 (2 uncoverable) Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 97.0% 295 / 306 (2 uncoverable) CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/abi.xs ↑ Summary xs/argon2id.xs »
1 #define PERL_NO_GET_CONTEXT
2 /* Where perl was built to keep a heap for each interpreter, XSUB.h turns
3 * malloc and free into calls that need an interpreter in hand, and the
4 * allocator a test installs below has none. What is allocated in this file
5 * is freed in this file, so the plain ones are the right ones. */
6 #define NO_XSLOCKS
7 #include "EXTERN.h"
8 #include "perl.h"
9 #include "XSUB.h"
10  
11 #include "symprim/config.h"
12 #include "symprim/symprim.h"
13 #include "symprim/abi.h"
14 #include "symprim/argon2id.h"
15 #include "symprim/blake2b.h"
16 #include "symprim/random.h"
17 #include "symprim/wipe.h"
18 #include "symprim/xchacha20poly1305.h"
19  
20 /* ---- hooks for tests ------------------------------------------------------ */
21  
22 6 static int failing_random(void *buf, size_t len)
23 {
24 PERL_UNUSED_ARG(buf);
25 PERL_UNUSED_ARG(len);
26 6 return SYMPRIM_E_RANDOM;
27 }
28  
29 /* An allocator a test can make fail on the Nth call, and that counts what is
30 * still held. Not per interpreter: tests only. What it hands out is filled
31 * with a pattern: fresh memory from the system is often all zero, and code
32 * that reads what it never wrote, or frees a pointer it never set, then
33 * passes by luck. */
34 static IV hook_fail_after = -1;
35 static IV hook_calls = 0;
36 static IV hook_live = 0;
37  
38 21 static void *hooked_malloc(size_t size)
39 {
40 void *p;
41  
42 21 hook_calls++;
43 21 ▶ if (hook_fail_after == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_fail_after == 0) 9 12 21
44 9 return NULL;
45 12 ▶ if (hook_fail_after > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_fail_after > 0) 4 8 12
46 4 hook_fail_after--;
47 12 p = malloc(size);
48 /* The system refusing a test the few bytes it asks for is not something
49 * a test can arrange.
50 # uncoverable branch false
51 # uncoverable condition right */
52 12 ▶ if (p) {
Branch: 1 branch
BranchTrueFalseTotal
if (p) { 12 0 12
53 12 hook_live++;
54 12 memset(p, 0xA5, size);
55 }
56 12 return p;
57 }
58  
59 /* Growing what a test holds. From nothing it is a malloc, and is counted,
60 * refused and filled as one. */
61 7 static void *hooked_realloc(void *ptr, size_t size)
62 {
63 7 ▶ if (!ptr)
Branch: 1 branch
BranchTrueFalseTotal
if (!ptr) 3 4 7
64 3 return hooked_malloc(size);
65 4 hook_calls++;
66 4 ▶ if (hook_fail_after == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_fail_after == 0) 1 3 4
67 1 return NULL;
68 3 ▶ if (hook_fail_after > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (hook_fail_after > 0) 1 2 3
69 1 hook_fail_after--;
70 3 return realloc(ptr, size);
71 }
72  
73 12 static void hooked_free(void *ptr)
74 {
75 12 hook_live--;
76 12 free(ptr);
77 12 }
78  
79 static const symprim_allocator hooked_allocator = { hooked_malloc, hooked_realloc, hooked_free };
80  
81 /* ---- what the engine refuses, by name ------------------------------------- */
82  
83 /* Every answer the engine has, in the order of its numbers. */
84 static const struct { int code; const char *name; } error_names[] = {
85 { SYMPRIM_OK, "SYMPRIM_OK" },
86 { SYMPRIM_E_ARGUMENT, "SYMPRIM_E_ARGUMENT" },
87 { SYMPRIM_E_MEMORY, "SYMPRIM_E_MEMORY" },
88 { SYMPRIM_E_RANDOM, "SYMPRIM_E_RANDOM" },
89 { SYMPRIM_E_NOLOCK, "SYMPRIM_E_NOLOCK" },
90 { SYMPRIM_E_AUTH, "SYMPRIM_E_AUTH" },
91 };
92  
93 /* ---- the two halves of a door --------------------------------------------- *
94 *
95 * A door reads its arguments in two halves, and the order is the rule.
96 *
97 * In the FIRST half every argument is read. Reading can run Perl code: the
98 * FETCH of a tied scalar or array, an object turning itself into a string or
99 * a number, a warning handler when undef or a word is used as a number. That
100 * code can change, shrink or free any scalar the caller still owns, the
101 * other arguments among them. So in this half nothing is pointed at: a
102 * number is turned into a C number at once, clicks are copied out of their
103 * arrays, and a byte string is either the caller's own scalar, already plain
104 * bytes, or a private copy that no Perl code can reach.
105 *
106 * In the SECOND half pointers are taken, by bytes_at alone, which looks at
107 * a scalar and runs nothing. From the first pointer to the engine's return
108 * no Perl code runs. If the first half left a caller's scalar no longer
109 * plain bytes, bytes_at says so and the call croaks.
110 *
111 * settled, text_of and bytes_of are the first half. bytes_at is the second. */
112  
113 /* A copy made in the first half is this call's own, and nothing is to be
114 * hung on it. Under -T a copy of what came from outside is marked as its
115 * source was, and before perl 5.18 a marked scalar shows only the private
116 * flags of what it holds, so that every test below would take it for
117 * nothing at all. The mark comes off the copy. The caller's own scalar keeps
118 * its own. */
119 8908 static SV *unmarked(pTHX_ SV *copy)
120 {
121 8908 ▶ if (SvMAGICAL(copy))
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(copy)) 4 8904 8908
122 4 sv_unmagic(copy, PERL_MAGIC_taint);
123 8908 return copy;
124 }
125  
126 /* A scalar whose value is fetched when it is read (a tied one, a capture
127 * variable such as $1, a substr, an element of a tied array) is fetched
128 * once, here, into a plain copy, and every later read is of the copy. A
129 * test of whether such an argument is defined would otherwise see what the
130 * read before last left behind, and a key given in $1 would count as no
131 * key. From perl 5.18 a scalar whose only magic is the mark of -T is read
132 * where it stands: its flags are true, and copying it would double every
133 * input of a program run under -T. Before 5.18 its flags do not say what it
134 * holds, and it is copied as the rest are. */
135 45768 static SV *settled(pTHX_ SV *sv)
136 {
137 /* Kept alive for as long as the call lasts, whatever the caller's code
138 * does with its own reference meanwhile. */
139 45768 sv = sv_2mortal(SvREFCNT_inc_simple_NN(sv));
140 45768 ▶ if (!SvGMAGICAL(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvGMAGICAL(sv)) 36805 8963 45768
141 36805 return sv;
142 #if PERL_REVISION > 5 || (PERL_REVISION == 5 && PERL_VERSION >= 18)
143 {
144 8963 MAGIC *mg = SvMAGIC(sv);
145  
146 /* A scalar that says its value is fetched has something hung on it,
147 * so there is always a first thing here to look at.
148 # uncoverable condition right count:1 */
149 8963 ▶ if (mg && mg->mg_type == PERL_MAGIC_taint && !mg->mg_moremagic) {
Branch: 3 branches
BranchTrueFalseTotal
if (mg && mg->mg_type == PERL_MAGIC_taint && !mg->mg_moremagic) { 8963 0 8963
if (mg && mg->mg_type == PERL_MAGIC_taint && !mg->mg_moremagic) { 10 8953 8963
if (mg && mg->mg_type == PERL_MAGIC_taint && !mg->mg_moremagic) { 9 1 10
150 9 SvGETMAGIC(sv);
151 9 return sv;
152 }
153 }
154 #endif
155 8954 return unmarked(aTHX_ sv_mortalcopy(sv));
156 }
157  
158 /* The same, and an object that turns itself into a string does that once,
159 * here, as well. A reference that does not is refused. Its text would be
160 * an address in memory: as a password it is one that can never be given
161 * again, and as a message it is nothing its sender meant. */
162 31254 static SV *text_of(pTHX_ SV *sv)
163 {
164 SV *said, *copy;
165  
166 31254 sv = settled(aTHX_ sv);
167 31215 ▶ if (!SvROK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(sv)) 31208 7 31215
168 31208 return sv;
169 7 ▶ said = SvAMAGIC(sv) ? amagic_call(sv, &PL_sv_undef, string_amg, AMGf_noright | AMGf_unary) : NULL;
Branch: 3 branches
BranchTrueFalseTotal
said = SvAMAGIC(sv) ? amagic_call(sv, &PL_sv_undef, string_amg, AMGf_noright | AMGf_unary) : NULL; 7 0 7
said = SvAMAGIC(sv) ? amagic_call(sv, &PL_sv_undef, string_amg, AMGf_noright | AMGf_unary) : NULL; 6 1 7
said = SvAMAGIC(sv) ? amagic_call(sv, &PL_sv_undef, string_amg, AMGf_noright | AMGf_unary) : NULL; 6 0 6
170 7 ▶ if (!said)
Branch: 1 branch
BranchTrueFalseTotal
if (!said) 1 6 7
171 1 croak("a reference is not bytes");
172 6 copy = sv_newmortal();
173 6 sv_copypv(copy, said);
174 6 return unmarked(aTHX_ copy);
175 }
176  
177 /* An argument read as bytes. What comes back is plain bytes now: the
178 * caller's own scalar when it already is, and otherwise a private copy made
179 * so. Making it so warns for undef, which becomes no bytes, and croaks for
180 * a character above 255, as every byte argument of every door does. */
181 31254 static SV *bytes_of(pTHX_ SV *sv)
182 {
183 STRLEN len;
184  
185 31254 sv = text_of(aTHX_ sv);
186 31214 ▶ if (SvPOK(sv) && !SvUTF8(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (SvPOK(sv) && !SvUTF8(sv)) 31209 5 31214
if (SvPOK(sv) && !SvUTF8(sv)) 31198 11 31209
187 31198 return sv;
188 16 sv = unmarked(aTHX_ sv_mortalcopy(sv));
189 (void)SvPVbyte_force(sv, len);
190 8 return sv;
191 }
192  
193 /* The second half: where the bytes of an argument are, and how many. Runs
194 * no Perl code and changes nothing. */
195 17432 static const uint8_t *bytes_at(pTHX_ SV *sv, STRLEN *len)
196 {
197 17432 ▶ if (!SvPOK(sv) || SvUTF8(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(sv) || SvUTF8(sv)) 17431 1 17432
if (!SvPOK(sv) || SvUTF8(sv)) 1 17430 17431
198 2 croak("an argument was changed while the others were being read");
199 17430 *len = SvCUR(sv);
200 17430 return (const uint8_t *)SvPVX_const(sv);
201 }
202  
203 /* The same without the croak, for a door that has something to wipe first:
204 * NULL where bytes_at would croak. */
205 7159 static const uint8_t *bytes_at_or_null(SV *sv, STRLEN *len)
206 {
207 7159 ▶ if (!SvPOK(sv) || SvUTF8(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(sv) || SvUTF8(sv)) 7158 1 7159
if (!SvPOK(sv) || SvUTF8(sv)) 1 7157 7158
208 2 return NULL;
209 7157 *len = SvCUR(sv);
210 7157 return (const uint8_t *)SvPVX_const(sv);
211 }
212  
213 /* ---- numbers -------------------------------------------------------------- */
214  
215 /* A whole number spelt as text: an optional sign and digits, then at most a
216 * point with nothing but zeros behind it, with spaces allowed before and
217 * after as perl allows them. Nothing else is one: no other fraction and no
218 * exponent. Text is judged by what it says and never by the floating point
219 * number nearest to it, which would take 411.99999999999999999 for 412 on
220 * one perl and not on another. */
221 947 static int whole_text(const char *p, STRLEN len, int64_t *out)
222 {
223 947 const int64_t most = INT64_C(9007199254740992);
224 947 STRLEN at = 0;
225 947 int64_t value = 0;
226 947 int negative = 0;
227  
228 950 ▶ while (at < len && isSPACE(p[at]))
Branch: 2 branches
BranchTrueFalseTotal
while (at < len && isSPACE(p[at])) 945 5 950
while (at < len && isSPACE(p[at])) 3 942 945
229 3 at++;
230 947 ▶ if (at < len && (p[at] == '-' || p[at] == '+'))
Branch: 3 branches
BranchTrueFalseTotal
if (at < len && (p[at] == '-' || p[at] == '+')) 942 5 947
if (at < len && (p[at] == '-' || p[at] == '+')) 939 3 942
if (at < len && (p[at] == '-' || p[at] == '+')) 3 936 939
231 6 negative = p[at++] == '-';
232 947 ▶ if (at >= len || !isDIGIT(p[at]))
Branch: 2 branches
BranchTrueFalseTotal
if (at >= len || !isDIGIT(p[at])) 940 7 947
if (at >= len || !isDIGIT(p[at])) 8 932 940
233 15 return 0;
234 2815 ▶ for (; at < len && isDIGIT(p[at]); at++) {
Branch: 2 branches
BranchTrueFalseTotal
for (; at < len && isDIGIT(p[at]); at++) { 1905 910 2815
for (; at < len && isDIGIT(p[at]); at++) { 1885 20 1905
235 1885 value = value * 10 + (p[at] - '0');
236 1885 ▶ if (value > most)
Branch: 1 branch
BranchTrueFalseTotal
if (value > most) 2 1883 1885
237 2 return 0;
238 }
239 930 ▶ if (at < len && p[at] == '.')
Branch: 2 branches
BranchTrueFalseTotal
if (at < len && p[at] == '.') 20 910 930
if (at < len && p[at] == '.') 8 12 20
240 33 ▶ for (at++; at < len && p[at] == '0'; at++)
Branch: 2 branches
BranchTrueFalseTotal
for (at++; at < len && p[at] == '0'; at++) 30 3 33
for (at++; at < len && p[at] == '0'; at++) 25 5 30
241 ;
242 933 ▶ while (at < len && isSPACE(p[at]))
Branch: 2 branches
BranchTrueFalseTotal
while (at < len && isSPACE(p[at])) 18 915 933
while (at < len && isSPACE(p[at])) 3 15 18
243 3 at++;
244 930 ▶ if (at != len)
Branch: 1 branch
BranchTrueFalseTotal
if (at != len) 15 915 930
245 15 return 0;
246 915 ▶ *out = negative ? -value : value;
Branch: 1 branch
BranchTrueFalseTotal
*out = negative ? -value : value; 2 913 915
247 915 return 1;
248 }
249  
250 /* A number from Perl is a whole number and nothing else: a fraction is
251 * refused, never rounded, since two programs that round differently would
252 * be two different keys, and a word or undef is not taken for 0. Nor is a
253 * reference, whatever it would turn itself into. The answer is 64 bits wide
254 * whatever an integer is on this perl, and is held to 2**53 either way, past
255 * which a floating point number no longer holds every whole number: so the
256 * same value is a number, or is not one, on every perl alike. A string that
257 * has never been used as a number is read as text. Runs no Perl code when sv
258 * is plain, as a settled one is. */
259 3293 static int whole_number(pTHX_ SV *sv, int64_t *out)
260 {
261 3293 const int64_t most = INT64_C(9007199254740992);
262 NV nv;
263  
264 3293 sv = settled(aTHX_ sv);
265 3293 ▶ if (!SvOK(sv) || SvROK(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(sv) || SvROK(sv)) 3290 3 3293
if (!SvOK(sv) || SvROK(sv)) 10 3280 3290
266 13 return 0;
267 3280 ▶ if (SvPOK(sv) && !SvIOKp(sv) && !SvNOKp(sv))
Branch: 3 branches
BranchTrueFalseTotal
if (SvPOK(sv) && !SvIOKp(sv) && !SvNOKp(sv)) 1088 2192 3280
if (SvPOK(sv) && !SvIOKp(sv) && !SvNOKp(sv)) 948 140 1088
if (SvPOK(sv) && !SvIOKp(sv) && !SvNOKp(sv)) 947 1 948
268 947 return whole_text(SvPVX_const(sv), SvCUR(sv), out);
269 2333 ▶ if (!looks_like_number(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!looks_like_number(sv)) 2 2331 2333
270 2 return 0;
271 2331 ▶ if (SvIOK(sv) && !SvNOK(sv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(sv) && !SvNOK(sv)) { 2318 13 2331
if (SvIOK(sv) && !SvNOK(sv)) { 2317 1 2318
272 /* An integer held unsigned is past every signed one, and is read as
273 * the unsigned one it is. Where an integer is 64 bits that puts it
274 * past the most this takes, so it is never read at all and only the
275 * refusal is met. Where an integer is 32 bits it is a number from
276 * 2**31 to 2**32 - 1, which is one this takes.
277 # uncoverable condition right count:2 class:ignore_covered_err */
278 2317 ▶ if (SvIsUV(sv) && (uint64_t)SvUVX(sv) > (uint64_t)most)
Branch: 2 branches
BranchTrueFalseTotal
if (SvIsUV(sv) && (uint64_t)SvUVX(sv) > (uint64_t)most) 1 2316 2317
if (SvIsUV(sv) && (uint64_t)SvUVX(sv) > (uint64_t)most) 1 0 1
279 1 return 0;
280 /*
281 # uncoverable condition left class:ignore_covered_err */
282 2316 ▶ *out = SvIsUV(sv) ? (int64_t)SvUVX(sv) : (int64_t)SvIVX(sv);
Branch: 1 branch
BranchTrueFalseTotal
*out = SvIsUV(sv) ? (int64_t)SvUVX(sv) : (int64_t)SvIVX(sv); 0 2316 2316
283 2316 ▶ return *out >= -most && *out <= most;
Branch: 2 branches
BranchTrueFalseTotal
return *out >= -most && *out <= most; 2315 1 2316
return *out >= -most && *out <= most; 2314 1 2315
284 }
285 14 nv = SvNV(sv);
286 14 ▶ if (!(nv >= -9007199254740992.0 && nv <= 9007199254740992.0))
Branch: 2 branches
BranchTrueFalseTotal
if (!(nv >= -9007199254740992.0 && nv <= 9007199254740992.0)) 11 3 14
if (!(nv >= -9007199254740992.0 && nv <= 9007199254740992.0)) 2 9 11
287 5 return 0;
288 9 *out = (int64_t)nv;
289 9 return (NV)*out == nv;
290 }
291  
292 /* A cost, a length, a side or a radius, by name: a whole number. One that
293 * is under zero or too big for 32 bits becomes the largest 32 bit number,
294 * which whoever takes it refuses like any other that is out of range. What
295 * is not a whole number at all is refused here. */
296 964 static uint32_t number_named(pTHX_ const char *door, const char *name, SV *sv)
297 {
298 int64_t value;
299  
300 964 ▶ if (!whole_number(aTHX_ sv, &value))
Branch: 1 branch
BranchTrueFalseTotal
if (!whole_number(aTHX_ sv, &value)) 28 936 964
301 28 croak("%s: %s is a whole number", door, name);
302 936 ▶ return value < 0 || value > INT64_C(0xFFFFFFFF) ? 0xFFFFFFFFUL : (uint32_t)value;
Branch: 2 branches
BranchTrueFalseTotal
return value < 0 || value > INT64_C(0xFFFFFFFF) ? 0xFFFFFFFFUL : (uint32_t)value; 935 1 936
return value < 0 || value > INT64_C(0xFFFFFFFF) ? 0xFFFFFFFFUL : (uint32_t)value; 934 1 935
303 }
304  
305 /* A number that must lie between two others, and says so when it does not. */
306 2329 static uint32_t number_between(pTHX_ const char *door, const char *name, SV *sv,
307 uint32_t least, uint32_t most)
308 {
309 int64_t value;
310  
311 2329 ▶ if (!whole_number(aTHX_ sv, &value) || value < (int64_t)least || value > (int64_t)most)
Branch: 3 branches
BranchTrueFalseTotal
if (!whole_number(aTHX_ sv, &value) || value < (int64_t)least || value > (int64_t)most) 2297 32 2329
if (!whole_number(aTHX_ sv, &value) || value < (int64_t)least || value > (int64_t)most) 2285 12 2297
if (!whole_number(aTHX_ sv, &value) || value < (int64_t)least || value > (int64_t)most) 14 2271 2285
312 58 croak("%s: %s is a whole number from %lu to %lu", door, name,
313 (unsigned long)least, (unsigned long)most);
314 2271 return (uint32_t)value;
315 }
316  
317 /* ---- when the engine refuses what a door let through ---------------------- */
318  
319 /* Every door looks at what it is given before the engine does, and refuses
320 * in words of its own. The engine looks again. Were it ever to refuse what a
321 * door had let through, the two would have come apart: the caller is then
322 * told in the engine's words, and nothing is left behind, since what was
323 * being made is let go and what was secret is wiped. No test can make them
324 * come apart, because each check a door makes is one the engine makes. */
325 2115 static void engine_agreed(pTHX_ int code, SV *made, void *secret, size_t len)
326 {
327 /*
328 # uncoverable branch true
329 # uncoverable condition left */
330 2115 ▶ if (code != SYMPRIM_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (code != SYMPRIM_OK) { 0 2115 2115
331 0 SvREFCNT_dec(made); /* # uncoverable statement */
332 0 symprim_wipe(secret, len); /* # uncoverable statement */
333 0 croak("%s", symprim_error_message(code)); /* # uncoverable statement */
334 }
335 2115 }
336  
337 /* ---- a hash object -------------------------------------------------------- */
338  
339 /* The state of a hash object is kept where Perl code cannot reach it: in
340 * memory of its own, hung on the object by magic that only this file can
341 * make. So a dump of the object shows no key, a string blessed into the
342 * class is not an object, a thread gets a state of its own, and the state
343 * is wiped when the object goes. */
344 569 static int blake2b_gone(pTHX_ SV *sv, MAGIC *mg)
345 {
346 PERL_UNUSED_ARG(sv);
347 569 symprim_wipe(mg->mg_ptr, sizeof(symprim_blake2b_state));
348 569 Safefree(mg->mg_ptr);
349 569 mg->mg_ptr = NULL;
350 569 return 0;
351 }
352  
353 #ifdef USE_ITHREADS
354 static int blake2b_cloned(pTHX_ MAGIC *mg, CLONE_PARAMS *param)
355 {
356 symprim_blake2b_state *copy;
357  
358 PERL_UNUSED_ARG(param);
359 Newx(copy, 1, symprim_blake2b_state);
360 Copy(mg->mg_ptr, copy, 1, symprim_blake2b_state);
361 mg->mg_ptr = (char *)copy;
362 return 0;
363 }
364 #endif
365  
366 static MGVTBL blake2b_magic = {
367 NULL, NULL, NULL, NULL, blake2b_gone, NULL,
368 #ifdef USE_ITHREADS
369 blake2b_cloned,
370 #else
371 NULL,
372 #endif
373 NULL
374 };
375  
376 /* Hangs a state on a new object. From here the object owns it. */
377 569 static void blake2b_attach(pTHX_ SV *object, symprim_blake2b_state *state)
378 {
379 569 MAGIC *mg = sv_magicext(object, NULL, PERL_MAGIC_ext, &blake2b_magic, (const char *)state, 0);
380  
381 #ifdef USE_ITHREADS
382 mg->mg_flags |= MGf_DUP;
383 #else
384 PERL_UNUSED_VAR(mg);
385 #endif
386 569 }
387  
388 1734 static symprim_blake2b_state *blake2b_state(pTHX_ SV *self)
389 {
390 MAGIC *mg;
391  
392 1734 ▶ if (SvROK(self) && SvTYPE(SvRV(self)) >= SVt_PVMG)
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(self) && SvTYPE(SvRV(self)) >= SVt_PVMG) 1733 1 1734
if (SvROK(self) && SvTYPE(SvRV(self)) >= SVt_PVMG) 1732 1 1733
393 1734 ▶ for (mg = SvMAGIC(SvRV(self)); mg; mg = mg->mg_moremagic)
Branch: 1 branch
BranchTrueFalseTotal
for (mg = SvMAGIC(SvRV(self)); mg; mg = mg->mg_moremagic) 1728 6 1734
394 /* A state is hung on in the same step as what marks the object,
395 * and is taken off only as the object goes, so what is marked
396 * as this file's always has one.
397 # uncoverable condition right count:3 */
398 1728 ▶ if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &blake2b_magic && mg->mg_ptr)
Branch: 3 branches
BranchTrueFalseTotal
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &blake2b_magic && mg->mg_ptr) 1727 1 1728
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &blake2b_magic && mg->mg_ptr) 1726 1 1727
if (mg->mg_type == PERL_MAGIC_ext && mg->mg_virtual == &blake2b_magic && mg->mg_ptr) 1726 0 1726
399 1726 return (symprim_blake2b_state *)mg->mg_ptr;
400 8 croak("not a Crypt::Symmetric::Primitives::BLAKE2b object");
401 return NULL;
402 }
403  
404 /* ---- names and values ----------------------------------------------------- */
405  
406 /* A door that takes names and values says which names it knows, and which
407 * of them are read as bytes. */
408 typedef struct {
409 const char *name;
410 int bytes;
411 } named;
412  
413 /* The first half of such a door: its values sorted into slots in the order
414 * of its table. A name given twice is taken as a hash would take it, the
415 * last one standing, and a value of undef is a name not given: its slot is
416 * NULL. A value read as bytes comes back from bytes_of, and any other
417 * settled. */
418 1263 static void named_arguments(pTHX_ const char *door, SV **args, I32 items,
419 const named *known, I32 count, SV **slots)
420 {
421 I32 i, j;
422  
423 1263 ▶ if (items & 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items & 1) 2 1261 1263
424 2 croak("%s takes name and value pairs", door);
425 8753 ▶ for (j = 0; j < count; j++)
Branch: 1 branch
BranchTrueFalseTotal
for (j = 0; j < count; j++) 7492 1261 8753
426 7492 slots[j] = NULL;
427 6256 ▶ for (i = 0; i < items; i += 2) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 0; i < items; i += 2) { 5202 1054 6256
428 5202 SV *name = bytes_of(aTHX_ args[i]);
429 5190 SV *value = settled(aTHX_ args[i + 1]);
430 5178 const char *spelt = SvPVX_const(name);
431 5178 STRLEN spelt_len = SvCUR(name);
432  
433 /* A name is all of what was given, a zero byte in it included. */
434 20902 ▶ for (j = 0; j < count && !(strlen(known[j].name) == spelt_len && memEQ(known[j].name, spelt, spelt_len)); j++)
Branch: 3 branches
BranchTrueFalseTotal
for (j = 0; j < count && !(strlen(known[j].name) == spelt_len && memEQ(known[j].name, spelt, spelt_len)); j++) 20720 182 20902
for (j = 0; j < count && !(strlen(known[j].name) == spelt_len && memEQ(known[j].name, spelt, spelt_len)); j++) 12892 7828 20720
for (j = 0; j < count && !(strlen(known[j].name) == spelt_len && memEQ(known[j].name, spelt, spelt_len)); j++) 2832 4996 7828
435 ;
436 5178 ▶ if (j == count)
Branch: 1 branch
BranchTrueFalseTotal
if (j == count) 182 4996 5178
437 182 croak("%s does not know '%s'", door, spelt);
438 4996 ▶ if (!SvOK(value))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(value)) 11 4985 4996
439 11 slots[j] = NULL;
440 else
441 4985 ▶ slots[j] = known[j].bytes ? bytes_of(aTHX_ value) : value;
Branch: 1 branch
BranchTrueFalseTotal
slots[j] = known[j].bytes ? bytes_of(aTHX_ value) : value; 2771 2214 4985
442 }
443 1054 }
444  
445 MODULE = Crypt::Symmetric::Primitives PACKAGE = Crypt::Symmetric::Primitives
446  
447 PROTOTYPES: DISABLE
448  
449 INCLUDE: xs/services.xs
450  
451 INCLUDE: xs/blake2b.xs
452  
453 INCLUDE: xs/argon2id.xs
454  
455 INCLUDE: xs/aead.xs
456  
457 INCLUDE: xs/abi.xs
« xs/abi.xs ↑ Summary xs/argon2id.xs »