inc/CryptX_Mac_HMAC.xs.inc

filter: Statementstmt 93.2% 69 / 74 Branchbran 71.7% 56 / 78 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 82.2% 125 / 152 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« inc/CryptX_BigInt_LTM.xs.inc ↑ Summary inc/CryptX_Mac_BLAKE2b.xs.inc »
1 MODULE = CryptX PACKAGE = Crypt::Mac::HMAC
2  
3 PROTOTYPES: DISABLE
4  
5 ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
6  
7 Crypt::Mac::HMAC
8 new(Class, char * hash_name, SV * key)
9 CODE:
10 {
11 1778 STRLEN k_len=0;
12 1778 unsigned char *k=NULL;
13 int rv;
14 int id;
15  
16 1778 id = cryptx_internal_find_hash(hash_name);
17 1778 ▶ if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name);
Branch: 1 branch
BranchTrueFalseTotal
if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name); 1 1777 1778
18  
19 1777 ▶ 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"); 1776 1 1777
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 1775 1776
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 1 1
20 1776 k = (unsigned char *) SvPVbyte(key, k_len);
21  
22 1776 Newz(0, RETVAL, 1, struct cryptx_mac_hmac_struct);
23 1776 ▶ if (!RETVAL) croak("FATAL: Newz failed");
Branch: 1 branch
BranchTrueFalseTotal
if (!RETVAL) croak("FATAL: Newz failed"); 0 1776 1776
24  
25 1776 rv = hmac_init(&RETVAL->state, id, k, (unsigned long)k_len);
26 1776 ▶ if (rv != CRYPT_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) { 0 1776 1776
27 0 Safefree(RETVAL);
28 0 croak("FATAL: hmac_init failed: %s", error_to_string(rv));
29 }
30 1776 RETVAL->finalized = 0;
31 }
32 OUTPUT:
33 RETVAL
34  
35 void
36 DESTROY(Crypt::Mac::HMAC self)
37 CODE:
38 {
39 1776 zeromem(&self->state, sizeof(hmac_state));
40 1776 Safefree(self);
41 }
42  
43 Crypt::Mac::HMAC
44 clone(Crypt::Mac::HMAC self)
45 CODE:
46 0 Newz(0, RETVAL, 1, struct cryptx_mac_hmac_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_hmac_struct);
49 OUTPUT:
50 RETVAL
51  
52 void
53 add(Crypt::Mac::HMAC self, ...)
54 PPCODE:
55 {
56 int rv, i;
57 STRLEN in_data_len;
58 unsigned char *in_data;
59  
60 1780 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 1779 1780
61 3568 ▶ for(i = 1; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 1; i < items; i++) { 1789 1779 3568
62 1789 in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
63 1789 ▶ if (in_data_len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (in_data_len > 0) { 1768 21 1789
64 1768 rv = hmac_process(&self->state, in_data, (unsigned long)in_data_len);
65 1768 ▶ if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv)); 0 1768 1768
66 }
67 }
68 1779 ▶ XPUSHs(ST(0)); /* return self */
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(ST(0)); /* return self */ 0 1779 1779
69 }
70  
71 SV *
72 mac(Crypt::Mac::HMAC 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 1776 ▶ if (self->finalized) croak("FATAL: MAC object already finalized");
Branch: 1 branch
BranchTrueFalseTotal
if (self->finalized) croak("FATAL: MAC object already finalized"); 1 1775 1776
85 1775 maclen = sizeof(mac);
86 1775 rv = hmac_done(&self->state, mac, &maclen);
87 1775 ▶ if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv)); 0 1775 1775
88 1775 self->finalized = 1;
89 1775 outlen = sizeof(out);
90 1775 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 1 1774 1775
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 1774 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 1 1773 1774
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 1773 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 20 1753 1773
101 20 rv = base16_encode(mac, maclen, out, &outlen, 0);
102 20 ▶ 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 20 20
103 20 RETVAL = newSVpvn(out, outlen);
104 }
105 else {
106 1753 RETVAL = newSVpvn((char * )mac, maclen);
107 }
108 1775 zeromem(mac, sizeof(mac));
109 }
110 OUTPUT:
111 RETVAL
112  
113 SV *
114 hmac(char * hash_name, SV * key, ...)
115 ALIAS:
116 hmac_hex = 1
117 hmac_b64 = 2
118 hmac_b64u = 3
119 CODE:
120 {
121 STRLEN inlen, klen;
122 unsigned char *in;
123 93 ▶ 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"); 92 1 93
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 91 92
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 1 0 1
if (!SvPOK_spec(key)) croak("FATAL: key must be string/buffer scalar"); 0 1 1
124 92 unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
125 int rv, i;
126 unsigned char mac[MAXBLOCKSIZE];
127 92 unsigned long len = sizeof(mac), outlen;
128 char out[MAXBLOCKSIZE*2+1];
129 hmac_state st;
130  
131 92 int id = cryptx_internal_find_hash(hash_name);
132 92 ▶ if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name);
Branch: 1 branch
BranchTrueFalseTotal
if (id == -1) croak("FATAL: find_hash failed for '%s'", hash_name); 1 91 92
133 91 rv = hmac_init(&st, id, k, (unsigned long)klen);
134 91 ▶ if (rv != CRYPT_OK) croak("FATAL: hmac_init failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: hmac_init failed: %s", error_to_string(rv)); 0 91 91
135 190 ▶ for (i = 2; i < items; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = 2; i < items; i++) { 99 91 190
136 99 in = (unsigned char *)SvPVbyte(ST(i), inlen);
137 99 ▶ if (inlen > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (inlen > 0) { 83 16 99
138 83 rv = hmac_process(&st, in, (unsigned long)inlen);
139 83 ▶ if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: hmac_process failed: %s", error_to_string(rv)); 0 83 83
140 }
141 }
142 91 rv = hmac_done(&st, mac, &len);
143 91 ▶ if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv));
Branch: 1 branch
BranchTrueFalseTotal
if (rv != CRYPT_OK) croak("FATAL: hmac_done failed: %s", error_to_string(rv)); 0 91 91
144  
145 91 outlen = sizeof(out);
146 91 ▶ if (ix == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (ix == 3) { 13 78 91
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 78 ▶ else if (ix == 2) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 2) { 13 65 78
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 65 ▶ else if (ix == 1) {
Branch: 1 branch
BranchTrueFalseTotal
else if (ix == 1) { 52 13 65
157 52 rv = base16_encode(mac, len, out, &outlen, 0);
158 52 ▶ 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 52 52
159 52 RETVAL = newSVpvn(out, outlen);
160 }
161 else {
162 13 RETVAL = newSVpvn((char *) mac, len);
163 }
164 91 zeromem(mac, sizeof(mac));
165 }
166 OUTPUT:
167 RETVAL
« inc/CryptX_BigInt_LTM.xs.inc ↑ Summary inc/CryptX_Mac_BLAKE2b.xs.inc »