File Coverage

inc/CryptX_Mac_XCBC.xs.inc
Criterion Covered Total %
statement 61 66 92.4
branch 43 64 67.1
condition n/a
subroutine n/a
pod n/a
total 104 130 80.0


line stmt bran cond sub pod time code
1             MODULE = CryptX PACKAGE = Crypt::Mac::XCBC
2              
3             PROTOTYPES: DISABLE
4              
5             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
6              
7             Crypt::Mac::XCBC
8             new(Class, char * cipher_name, SV * key)
9             CODE:
10             {
11 30           STRLEN k_len=0;
12 30           unsigned char *k=NULL;
13             int rv;
14             int id;
15              
16 30           id = cryptx_internal_find_cipher(cipher_name);
17 30 50         if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
18              
19 30 50         if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
20 30 50         k = (unsigned char *) SvPVbyte(key, k_len);
21              
22 30           Newz(0, RETVAL, 1, xcbc_state);
23 30 50         if (!RETVAL) croak("FATAL: Newz failed");
24              
25 30           rv = xcbc_init(RETVAL, id, k, (unsigned long)k_len);
26 30 50         if (rv != CRYPT_OK) {
27 0           Safefree(RETVAL);
28 0           croak("FATAL: xcbc_init failed: %s", error_to_string(rv));
29             }
30             }
31             OUTPUT:
32             RETVAL
33              
34             void
35             DESTROY(Crypt::Mac::XCBC self)
36             CODE:
37 30           Safefree(self);
38              
39             Crypt::Mac::XCBC
40             clone(Crypt::Mac::XCBC self)
41             CODE:
42 0           Newz(0, RETVAL, 1, xcbc_state);
43 0 0         if (!RETVAL) croak("FATAL: Newz failed");
44 0           Copy(self, RETVAL, 1, xcbc_state);
45             OUTPUT:
46             RETVAL
47              
48             void
49             add(Crypt::Mac::XCBC self, ...)
50             PPCODE:
51             {
52             int rv, i;
53             STRLEN in_data_len;
54             unsigned char *in_data;
55              
56 76 100         for(i = 1; i < items; i++) {
57 42 100         in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
58 42 100         if (in_data_len > 0) {
59 34           rv = xcbc_process(self, in_data, (unsigned long)in_data_len);
60 34 50         if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv));
61             }
62             }
63 34 50         XPUSHs(ST(0)); /* return self */
64             }
65              
66             SV *
67             mac(Crypt::Mac::XCBC self)
68             ALIAS:
69             hexmac = 1
70             b64mac = 2
71             b64umac = 3
72             CODE:
73             {
74             unsigned char mac[MAXBLOCKSIZE];
75             unsigned long maclen, outlen;
76             int rv;
77             char out[MAXBLOCKSIZE*2+1];
78              
79 30           maclen = sizeof(mac);
80 30           rv = xcbc_done(self, mac, &maclen);
81 30 50         if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
82 30           outlen = sizeof(out);
83 30 100         if (ix == 3) {
84 1           rv = base64url_encode(mac, maclen, out, &outlen);
85 1 50         if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
86 1           RETVAL = newSVpvn(out, outlen);
87             }
88 29 100         else if (ix == 2) {
89 1           rv = base64_encode(mac, maclen, out, &outlen);
90 1 50         if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
91 1           RETVAL = newSVpvn(out, outlen);
92             }
93 28 100         else if (ix == 1) {
94 14           rv = base16_encode(mac, maclen, out, &outlen, 0);
95 14 50         if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
96 14           RETVAL = newSVpvn(out, outlen);
97             }
98             else {
99 14           RETVAL = newSVpvn((char * )mac, maclen);
100             }
101             }
102             OUTPUT:
103             RETVAL
104              
105             SV *
106             xcbc(char * cipher_name, SV * key, ...)
107             ALIAS:
108             xcbc_hex = 1
109             xcbc_b64 = 2
110             xcbc_b64u = 3
111             CODE:
112             {
113             STRLEN inlen, klen;
114             unsigned char *in;
115 52 50         unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
116             int rv, i;
117             unsigned char mac[MAXBLOCKSIZE];
118 52           unsigned long len = sizeof(mac), outlen;
119             char out[MAXBLOCKSIZE*2];
120             xcbc_state st;
121              
122 52           int id = cryptx_internal_find_cipher(cipher_name);
123 52 50         if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
124 52           rv = xcbc_init(&st, id, k, (unsigned long)klen);
125 52 50         if (rv != CRYPT_OK) croak("FATAL: xcbc_init failed: %s", error_to_string(rv));
126 112 100         for (i = 2; i < items; i++) {
127 60 100         in = (unsigned char *)SvPVbyte(ST(i), inlen);
128 60 100         if (inlen > 0) {
129 44           rv = xcbc_process(&st, in, (unsigned long)inlen);
130 44 50         if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv));
131             }
132             }
133 52           rv = xcbc_done(&st, mac, &len);
134 52 50         if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv));
135              
136 52           outlen = sizeof(out);
137 52 100         if (ix == 3) {
138 13           rv = base64url_encode(mac, len, out, &outlen);
139 13 50         if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
140 13           RETVAL = newSVpvn((char *) out, outlen);
141             }
142 39 100         else if (ix == 2) {
143 13           rv = base64_encode(mac, len, out, &outlen);
144 13 50         if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
145 13           RETVAL = newSVpvn(out, outlen);
146             }
147 26 100         else if (ix == 1) {
148 13           rv = base16_encode(mac, len, out, &outlen, 0);
149 13 50         if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
150 13           RETVAL = newSVpvn(out, outlen);
151             }
152             else {
153 13           RETVAL = newSVpvn((char *) mac, len);
154             }
155             }
156             OUTPUT:
157             RETVAL