inc/CryptX_Digest_KangarooTwelve.xs.inc

filter: Statementstmt 90.4% 38 / 42 Branchbran 66.6% 24 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 79.4% 62 / 78 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_PRNG.xs.inc ↑ Summary inc/CryptX_Digest.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::Digest::KangarooTwelve
2  
3 PROTOTYPES: DISABLE
4  
5 #define CRYPTX_DIGEST_KANGAROOTWELVE_MAX_OUTPUT_LEN 1000000000UL
6  
7 Crypt::Digest::KangarooTwelve
8 new(Class, int num)
9 CODE:
10 {
11 int rv;
12  
13 15 Newz(0, RETVAL, 1, struct digest_shake_struct);
14 15 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 15 15
15  
16 15 RETVAL->num = num;
17 15 RETVAL->squeezing = 0;
18 15 rv = kangaroo_twelve_init(&RETVAL->state, RETVAL->num);
19 15 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 15 15
20 0 Safefree(RETVAL);
21 0 croak("FATAL: kangaroo_twelve_init failed: %s", error_to_string(rv));
22 }
23 }
24 OUTPUT:
25 RETVAL
26  
27 void
28 DESTROY(Crypt::Digest::KangarooTwelve self)
29 CODE:
30 16 Safefree(self);
31  
32 void
33 reset(Crypt::Digest::KangarooTwelve self)
34 PPCODE:
35 {
36 int rv;
37 1 rv = kangaroo_twelve_init(&self->state, self->num);
38 1 ▶ if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_init failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_init failed: %s", error_to_string(rv)); 0 1 1
39 1 self->squeezing = 0;
40 1 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 1 1
41 }
42  
43 Crypt::Digest::KangarooTwelve
44 clone(Crypt::Digest::KangarooTwelve self)
45 CODE:
46 1 Newz(0, RETVAL, 1, struct digest_shake_struct);
47 1 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 1 1
48 1 Copy(self, RETVAL, 1, struct digest_shake_struct);
49 OUTPUT:
50 RETVAL
51  
52 void
53 add(Crypt::Digest::KangarooTwelve self, ...)
54 PPCODE:
55 {
56 STRLEN inlen;
57 int rv, i;
58 unsigned char *in;
59  
60 7 ▶ if (self->squeezing) croak("FATAL: cannot add after done; call reset first");
Branch: 1 branch
BranchTrueFalseTotal
if (self->squeezing) croak("FATAL: cannot add after done; call reset first"); 1 6 7
61  
62 12 ▶ for(i=1; i<items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i<items; i++) { 6 6 12
63 6 in = (unsigned char *)SvPVbyte(ST(i), inlen);
64 6 ▶ if (inlen>0) {
Branch: 1 branch
BranchTrueFalseTotal
if (inlen>0) { 6 0 6
65 6 rv = kangaroo_twelve_process(&self->state, in, (unsigned long)inlen);
66 6 ▶ if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_process failed: %s", error_to_string(rv)); 0 6 6
67 }
68 }
69 6 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 6 6
70 }
71  
72 void
73 customization(Crypt::Digest::KangarooTwelve self, ...)
74 PPCODE:
75 {
76 STRLEN inlen;
77 int rv, i;
78 unsigned char *in;
79  
80 5 ▶ if (self->squeezing) croak("FATAL: cannot add after done; call reset first");
Branch: 1 branch
BranchTrueFalseTotal
if (self->squeezing) croak("FATAL: cannot add after done; call reset first"); 1 4 5
81  
82 8 ▶ for(i=1; i<items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i<items; i++) { 4 4 8
83 4 in = (unsigned char *)SvPVbyte(ST(i), inlen);
84 4 ▶ if (inlen>0) {
Branch: 1 branch
BranchTrueFalseTotal
if (inlen>0) { 4 0 4
85 4 rv = kangaroo_twelve_customization(&self->state, in, (unsigned long)inlen);
86 4 ▶ if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_customization failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: kangaroo_twelve_customization failed: %s", error_to_string(rv)); 0 4 4
87 }
88 }
89 4 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 4 4
90 }
91  
92 SV *
93 done(Crypt::Digest::KangarooTwelve self, unsigned long out_len)
94 CODE:
95 {
96 int rv;
97 unsigned char *out_data;
98  
99 18 ▶ if (out_len == 0) croak("FATAL: invalid output length");
Branch: 1 branch
BranchTrueFalseTotal
if (out_len == 0) croak("FATAL: invalid output length"); 1 17 18
100 17 ▶ if (out_len > CRYPTX_DIGEST_KANGAROOTWELVE_MAX_OUTPUT_LEN) croak("FATAL: output length too large");
Branch: 1 branch
BranchTrueFalseTotal
if (out_len > CRYPTX_DIGEST_KANGAROOTWELVE_MAX_OUTPUT_LEN) croak("FATAL: output length too large"); 2 15 17
101 15 RETVAL = NEWSV(0, out_len); /* avoid zero! */
102 15 SvPOK_only(RETVAL);
103 15 SvCUR_set(RETVAL, out_len);
104 15 *SvEND(RETVAL) = '\0';
105 15 out_data = (unsigned char *)SvPVX(RETVAL);
106 15 rv = kangaroo_twelve_done(&self->state, out_data, out_len);
107 15 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 15 15
108 0 SvREFCNT_dec(RETVAL);
109 0 croak("FATAL: kangaroo_twelve_done failed: %s", error_to_string(rv));
110 }
111 15 self->squeezing = 1;
112 }
113 OUTPUT:
114 RETVAL
« inc/CryptX_PRNG.xs.inc ↑ Summary inc/CryptX_Digest.xs.inc »