xs/argon2id.xs

filter: Statementstmt 100% 63 / 63 Branchbran 97.3% 37 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 99.0% 100 / 101 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« Primitives.xs ↑ Summary src/blake2b.c »
1 SV *
2 argon2id(...)
3 PREINIT:
4 static const named known[] = {
5 { "password", 1 }, { "salt", 1 }, { "secret", 1 }, { "data", 1 },
6 { "memory", 0 }, { "passes", 0 }, { "lanes", 0 }, { "bytes", 0 }
7 };
8 SV *slot[8];
9 613 const char *door = "Crypt::Symmetric::Primitives::argon2id";
10 symprim_argon2_in in;
11 613 uint32_t bytes = 32;
12 STRLEN len;
13 int code;
14 CODE:
15 /* A name given twice is taken as a hash would take it: the last one
16 * stands, and an undef last one means it was not given. */
17 613 named_arguments(aTHX_ door, &ST(0), items, known, 8, slot);
18 458 ▶ if (!slot[0])
Branch: 1 branch
BranchTrueFalseTotal
if (!slot[0]) 2 456 458
19 2 croak("argon2id needs a password");
20 456 ▶ if (!slot[1])
Branch: 1 branch
BranchTrueFalseTotal
if (!slot[1]) 1 455 456
21 1 croak("argon2id needs a salt");
22 455 ▶ if (!slot[4])
Branch: 1 branch
BranchTrueFalseTotal
if (!slot[4]) 2 453 455
23 2 croak("argon2id needs a memory cost");
24 453 ▶ if (!slot[5])
Branch: 1 branch
BranchTrueFalseTotal
if (!slot[5]) 1 452 453
25 1 croak("argon2id needs a number of passes");
26 452 memset(&in, 0, sizeof in);
27 452 in.memory_kib = number_between(aTHX_ "argon2id", "memory", slot[4], 8, 0xFFFFFFFFUL);
28 447 in.passes = number_between(aTHX_ "argon2id", "passes", slot[5], 1, 0xFFFFFFFFUL);
29 443 ▶ in.lanes = slot[6] ? number_between(aTHX_ "argon2id", "lanes", slot[6], 1, SYMPRIM_ARGON2_LANES_MAX) : 1;
Branch: 1 branch
BranchTrueFalseTotal
in.lanes = slot[6] ? number_between(aTHX_ "argon2id", "lanes", slot[6], 1, SYMPRIM_ARGON2_LANES_MAX) : 1; 397 46 443
30 441 ▶ if (slot[7])
Branch: 1 branch
BranchTrueFalseTotal
if (slot[7]) 407 34 441
31 407 bytes = number_between(aTHX_ "argon2id", "bytes", slot[7], SYMPRIM_ARGON2_TAG_MIN, 1024 * 1024);
32 439 ▶ if (in.memory_kib / 8 < in.lanes)
Branch: 1 branch
BranchTrueFalseTotal
if (in.memory_kib / 8 < in.lanes) 1 438 439
33 1 croak("argon2id needs at least 8 KiB of memory a lane");
34 438 in.password = bytes_at(aTHX_ slot[0], &len);
35 438 in.password_len = len;
36 438 in.salt = bytes_at(aTHX_ slot[1], &len);
37 438 in.salt_len = len;
38 438 ▶ if (in.salt_len < SYMPRIM_ARGON2_SALT_MIN)
Branch: 1 branch
BranchTrueFalseTotal
if (in.salt_len < SYMPRIM_ARGON2_SALT_MIN) 1 437 438
39 1 croak("an argon2id salt is at least 8 bytes");
40 437 ▶ if (slot[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (slot[2]) { 341 96 437
41 341 in.secret = bytes_at(aTHX_ slot[2], &len);
42 341 in.secret_len = len;
43 }
44 437 ▶ if (slot[3]) {
Branch: 1 branch
BranchTrueFalseTotal
if (slot[3]) { 337 100 437
45 337 in.data = bytes_at(aTHX_ slot[3], &len);
46 337 in.data_len = len;
47 }
48 437 RETVAL = newSV(bytes);
49 437 SvPOK_only(RETVAL);
50 437 code = symprim_argon2id(&in, (uint8_t *)SvPVX(RETVAL), bytes);
51 437 ▶ if (code == SYMPRIM_E_MEMORY) {
Branch: 1 branch
BranchTrueFalseTotal
if (code == SYMPRIM_E_MEMORY) { 4 433 437
52 4 SvREFCNT_dec(RETVAL);
53 4 croak("argon2id could not get %lu KiB of memory", (unsigned long)in.memory_kib);
54 }
55 433 engine_agreed(aTHX_ code, RETVAL, NULL, 0);
56 433 SvPVX(RETVAL)[bytes] = '\0';
57 433 SvCUR_set(RETVAL, bytes);
58 OUTPUT:
59 RETVAL
60  
61 void
62 _allocator_hook(fail_after)
63 IV fail_after
64 CODE:
65 20 hook_fail_after = fail_after;
66 20 hook_calls = 0;
67 20 hook_live = 0;
68 20 symprim_set_allocator(&hooked_allocator);
69  
70 void
71 _allocator_restore()
72 CODE:
73 20 symprim_set_allocator(NULL);
74  
75 IV
76 _allocator_calls()
77 CODE:
78 8 ▶ RETVAL = hook_calls;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hook_calls; 6 2 8
79 OUTPUT:
80 RETVAL
81  
82 IV
83 _allocator_live()
84 CODE:
85 9 ▶ RETVAL = hook_live;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = hook_live; 6 3 9
86 OUTPUT:
87 RETVAL
88  
89 IV
90 _allocator_resize(from, to)
91 SV *from
92 SV *to
93 PREINIT:
94 27 uint32_t first, second, i, kept = 0;
95 27 ▶ uint8_t *p = NULL, *q;
Branch: 1 branch
BranchTrueFalseTotal
uint8_t *p = NULL, *q; 27 0 27
96 CODE:
97 /* What the engine's realloc does through whichever allocator is set, for
98 * a test of the one above: a block of from bytes, or none at all when
99 * from is 0, made to bytes long. The answer is how many of the bytes
100 * written to the first block are still there in the second, or -1 where
101 * memory was refused. */
102 27 first = number_between(aTHX_ "_allocator_resize", "the first size", settled(aTHX_ from), 0, 65536);
103 26 second = number_between(aTHX_ "_allocator_resize", "the second size", settled(aTHX_ to), 1, 65536);
104 25 ▶ if (first) {
Branch: 1 branch
BranchTrueFalseTotal
if (first) { 22 3 25
105 22 p = (uint8_t *)symprim_malloc(first);
106 22 ▶ if (p)
Branch: 1 branch
BranchTrueFalseTotal
if (p) 21 1 22
107 21 memset(p, 0x5A, first);
108 }
109 25 q = (uint8_t *)symprim_realloc(p, second);
110 25 ▶ if (!q) {
Branch: 1 branch
BranchTrueFalseTotal
if (!q) { 3 22 25
111 3 symprim_free(p);
112 3 RETVAL = -1;
113 } else {
114 1432 ▶ for (i = 0; i < first && i < second; i++)
Branch: 2 branches
BranchTrueFalseTotal
for (i = 0; i < first && i < second; i++) 1416 16 1432
for (i = 0; i < first && i < second; i++) 1410 6 1416
115 1410 kept += q[i] == 0x5A;
116 22 symprim_free(q);
117 22 RETVAL = (IV)kept;
118 }
119 OUTPUT:
120 RETVAL
« Primitives.xs ↑ Summary src/blake2b.c »