inc/CryptX_Mac_F9.xs.inc

filter: Statementstmt 93.2% 69 / 74 Branchbran 56.4% 44 / 78 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.3% 113 / 152 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_Mac_BLAKE2s.xs.inc ↑ Summary inc/CryptX_Mac_PMAC.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::Mac::F9
2  
3 PROTOTYPES: DISABLE
4  
5 ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
6  
7 Crypt::Mac::F9
8 new(Class, char * cipher_name, SV * key)
9 CODE:
10 {
11 31 STRLEN k_len=0;
12 31 unsigned char *k=NULL;
13 int rv;
14 int id;
15  
16 31 id = cryptx_internal_find_cipher(cipher_name);
17 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
18  
19 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
20 31 k = (unsigned char *) SvPVbyte(key, k_len);
21  
22 31 Newz(0, RETVAL, 1, struct cryptx_mac_f9_struct);
23 31 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 31 31
24  
25 31 rv = f9_init(&RETVAL->state, id, k, (unsigned long)k_len);
26 31 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 31 31
27 0 Safefree(RETVAL);
28 0 croak("FATAL: f9_init failed: %s", error_to_string(rv));
29 }
30 31 RETVAL->finalized = 0;
31 }
32 OUTPUT:
33 RETVAL
34  
35 void
36 DESTROY(Crypt::Mac::F9 self)
37 CODE:
38 {
39 31 zeromem(&self->state, sizeof(f9_state));
40 31 Safefree(self);
41 }
42  
43 Crypt::Mac::F9
44 clone(Crypt::Mac::F9 self)
45 CODE:
46 0 Newz(0, RETVAL, 1, struct cryptx_mac_f9_struct);
47 0 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 0 0
48 0 Copy(self, RETVAL, 1, struct cryptx_mac_f9_struct);
49 OUTPUT:
50 RETVAL
51  
52 void
53 add(Crypt::Mac::F9 self, ...)
54 PPCODE:
55 {
56 int rv, i;
57 STRLEN in_data_len;
58 unsigned char *in_data;
59  
60 36 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 35 36
61 80 ▶ for(i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 1; i < items; i++) { 45 35 80
62 45 in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
63 45 ▶ if (in_data_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len > 0) { 37 8 45
64 37 rv = f9_process(&self->state, in_data, (unsigned long)in_data_len);
65 37 ▶ if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv)); 0 37 37
66 }
67 }
68 35 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 35 35
69 }
70  
71 SV *
72 mac(Crypt::Mac::F9 self)
73 ALIAS:
74 hexmac = 1
75 b64mac = 2
76 b64umac = 3
77 CODE:
78 {
79 unsigned char mac[MAXBLOCKSIZE];
80 unsigned long maclen, outlen;
81 int rv;
82 char out[MAXBLOCKSIZE*2+1];
83  
84 32 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 31 32
85 31 maclen = sizeof(mac);
86 31 rv = f9_done(&self->state, mac, &maclen);
87 31 ▶ if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv)); 0 31 31
88 31 self->finalized = 1;
89 31 outlen = sizeof(out);
90 31 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 1 30 31
91 1 rv = base64url_encode(mac, maclen, out, &outlen);
92 1 ▶ if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); 0 1 1
93 1 RETVAL = newSVpvn(out, outlen);
94 }
95 30 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 1 29 30
96 1 rv = base64_encode(mac, maclen, out, &outlen);
97 1 ▶ if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); 0 1 1
98 1 RETVAL = newSVpvn(out, outlen);
99 }
100 29 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 15 14 29
101 15 rv = base16_encode(mac, maclen, out, &outlen, 0);
102 15 ▶ if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); 0 15 15
103 15 RETVAL = newSVpvn(out, outlen);
104 }
105 else {
106 14 RETVAL = newSVpvn((char * )mac, maclen);
107 }
108 31 zeromem(mac, sizeof(mac));
109 }
110 OUTPUT:
111 RETVAL
112  
113 SV *
114 f9(char * cipher_name, SV * key, ...)
115 ALIAS:
116 f9_hex = 1
117 f9_b64 = 2
118 f9_b64u = 3
119 CODE:
120 {
121 STRLEN inlen, klen;
122 unsigned char *in;
123 52 ▶ 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"); 52 0 52
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 52 52
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
124 52 unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
125 int rv, i;
126 unsigned char mac[MAXBLOCKSIZE];
127 52 unsigned long len = sizeof(mac), outlen;
128 char out[MAXBLOCKSIZE*2+1];
129 f9_state st;
130  
131 52 int id = cryptx_internal_find_cipher(cipher_name);
132 52 ▶ 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 52 52
133 52 rv = f9_init(&st, id, k, (unsigned long)klen);
134 52 ▶ if (rv != CRYPT_OK) croak("FATAL: f9_init failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: f9_init failed: %s", error_to_string(rv)); 0 52 52
135 112 ▶ for (i = 2; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i++) { 60 52 112
136 60 in = (unsigned char *)SvPVbyte(ST(i), inlen);
137 60 ▶ if (inlen > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (inlen > 0) { 44 16 60
138 44 rv = f9_process(&st, in, (unsigned long)inlen);
139 44 ▶ if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv)); 0 44 44
140 }
141 }
142 52 rv = f9_done(&st, mac, &len);
143 52 ▶ if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv)); 0 52 52
144  
145 52 outlen = sizeof(out);
146 52 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 13 39 52
147 13 rv = base64url_encode(mac, len, out, &outlen);
148 13 ▶ if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv)); 0 13 13
149 13 RETVAL = newSVpvn((char *) out, outlen);
150 }
151 39 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 13 26 39
152 13 rv = base64_encode(mac, len, out, &outlen);
153 13 ▶ if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv)); 0 13 13
154 13 RETVAL = newSVpvn(out, outlen);
155 }
156 26 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 13 13 26
157 13 rv = base16_encode(mac, len, out, &outlen, 0);
158 13 ▶ if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv)); 0 13 13
159 13 RETVAL = newSVpvn(out, outlen);
160 }
161 else {
162 13 RETVAL = newSVpvn((char *) mac, len);
163 }
164 52 zeromem(mac, sizeof(mac));
165 }
166 OUTPUT:
167 RETVAL
« inc/CryptX_Mac_BLAKE2s.xs.inc ↑ Summary inc/CryptX_Mac_PMAC.xs.inc »