| 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 |
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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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_xcbc_struct); |
| 23 |
31 |
▶ | if (!RETVAL) croak("FATAL: Newz failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) croak("FATAL: Newz failed"); |
0 |
31 |
31 |
|
| 24 |
|
| |
| 25 |
31 |
| rv = xcbc_init(&RETVAL->state, id, k, (unsigned long)k_len); |
| 26 |
31 |
▶ | if (rv != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { |
0 |
31 |
31 |
|
| 27 |
0 |
| Safefree(RETVAL); |
| 28 |
0 |
| croak("FATAL: xcbc_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::XCBC self) |
| 37 |
|
| CODE: |
| 38 |
|
| { |
| 39 |
31 |
| zeromem(&self->state, sizeof(xcbc_state)); |
| 40 |
31 |
| Safefree(self); |
| 41 |
|
| } |
| 42 |
|
| |
| 43 |
|
| Crypt::Mac::XCBC |
| 44 |
|
| clone(Crypt::Mac::XCBC self) |
| 45 |
|
| CODE: |
| 46 |
0 |
| Newz(0, RETVAL, 1, struct cryptx_mac_xcbc_struct); |
| 47 |
0 |
▶ | if (!RETVAL) croak("FATAL: Newz failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) croak("FATAL: Newz failed"); |
0 |
0 |
0 |
|
| 48 |
0 |
| Copy(self, RETVAL, 1, struct cryptx_mac_xcbc_struct); |
| 49 |
|
| OUTPUT: |
| 50 |
|
| RETVAL |
| 51 |
|
| |
| 52 |
|
| void |
| 53 |
|
| add(Crypt::Mac::XCBC 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
| Branch | True | False | Total |
| if (self->finalized) croak("FATAL: MAC object already finalized"); |
1 |
35 |
36 |
|
| 61 |
80 |
▶ | for(i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| if (in_data_len > 0) { |
37 |
8 |
45 |
|
| 64 |
37 |
| rv = xcbc_process(&self->state, in_data, (unsigned long)in_data_len); |
| 65 |
37 |
▶ | if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv)); |
0 |
37 |
37 |
|
| 66 |
|
| } |
| 67 |
|
| } |
| 68 |
35 |
▶ | XPUSHs(ST(0)); /* return self */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(ST(0)); /* return self */ |
0 |
35 |
35 |
|
| 69 |
|
| } |
| 70 |
|
| |
| 71 |
|
| SV * |
| 72 |
|
| mac(Crypt::Mac::XCBC 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
| Branch | True | False | Total |
| if (self->finalized) croak("FATAL: MAC object already finalized"); |
1 |
31 |
32 |
|
| 85 |
31 |
| maclen = sizeof(mac); |
| 86 |
31 |
| rv = xcbc_done(&self->state, mac, &maclen); |
| 87 |
31 |
▶ | if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: xcbc_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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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 |
|
| xcbc(char * cipher_name, SV * key, ...) |
| 115 |
|
| ALIAS: |
| 116 |
|
| xcbc_hex = 1 |
| 117 |
|
| xcbc_b64 = 2 |
| 118 |
|
| xcbc_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
| Branch | True | False | Total |
| 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 |
|
| xcbc_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
| Branch | True | False | Total |
| if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name); |
0 |
52 |
52 |
|
| 133 |
52 |
| rv = xcbc_init(&st, id, k, (unsigned long)klen); |
| 134 |
52 |
▶ | if (rv != CRYPT_OK) croak("FATAL: xcbc_init failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: xcbc_init failed: %s", error_to_string(rv)); |
0 |
52 |
52 |
|
| 135 |
112 |
▶ | for (i = 2; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| if (inlen > 0) { |
44 |
16 |
60 |
|
| 138 |
44 |
| rv = xcbc_process(&st, in, (unsigned long)inlen); |
| 139 |
44 |
▶ | if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: xcbc_process failed: %s", error_to_string(rv)); |
0 |
44 |
44 |
|
| 140 |
|
| } |
| 141 |
|
| } |
| 142 |
52 |
| rv = xcbc_done(&st, mac, &len); |
| 143 |
52 |
▶ | if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: xcbc_done failed: %s", error_to_string(rv)); |
0 |
52 |
52 |
|
| 144 |
|
| |
| 145 |
52 |
| outlen = sizeof(out); |
| 146 |
52 |
▶ | if (ix == 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| 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 |