summaryrefslogtreecommitdiff
path: root/inc/CryptX_Mac_XCBC.xs.inc
diff options
context:
space:
mode:
Diffstat (limited to 'inc/CryptX_Mac_XCBC.xs.inc')
-rw-r--r--inc/CryptX_Mac_XCBC.xs.inc89
1 files changed, 89 insertions, 0 deletions
diff --git a/inc/CryptX_Mac_XCBC.xs.inc b/inc/CryptX_Mac_XCBC.xs.inc
index 48647f7f..2d269187 100644
--- a/inc/CryptX_Mac_XCBC.xs.inc
+++ b/inc/CryptX_Mac_XCBC.xs.inc
@@ -135,3 +135,92 @@ hexmac(Crypt::Mac::XCBC self)
}
OUTPUT:
RETVAL
+
+SV *
+xcbc(char * cipher_name, SV * key, SV * data)
+ CODE:
+ {
+ STRLEN inlen, klen;
+ unsigned char *in = (unsigned char *)SvPVbyte(data, inlen);
+ unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
+ int rv;
+ unsigned char mac[MAXBLOCKSIZE];
+ unsigned long len = sizeof(mac);
+ int id = _find_cipher(cipher_name);
+ if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
+ rv = xcbc_memory(id, k, klen, in, inlen, mac, &len);
+ if (rv != CRYPT_OK) croak("FATAL: xcbc_memory failed: %s", error_to_string(rv));
+ RETVAL = newSVpvn((char *) mac, len);
+ }
+ OUTPUT:
+ RETVAL
+
+SV *
+xcbc_hex(char * cipher_name, SV * key, SV * data)
+ CODE:
+ {
+ STRLEN inlen, klen;
+ unsigned char *in = (unsigned char *)SvPVbyte(data, inlen);
+ unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
+ int rv;
+ unsigned char mac[MAXBLOCKSIZE];
+ unsigned long len = sizeof(mac), outlen;
+ char out[MAXBLOCKSIZE*2];
+ int id = _find_cipher(cipher_name);
+ if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
+ rv = xcbc_memory(id, k, klen, in, inlen, mac, &len);
+ if (rv != CRYPT_OK) croak("FATAL: xcbc_memory failed: %s", error_to_string(rv));
+ outlen = sizeof(out);
+ rv = _base16_encode(mac, len, (unsigned char *)out, &outlen);
+ if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
+ RETVAL = newSVpvn((char *) out, outlen);
+ }
+ OUTPUT:
+ RETVAL
+
+SV *
+xcbc_b64(char * cipher_name, SV * key, SV * data)
+ CODE:
+ {
+ STRLEN inlen, klen;
+ unsigned char *in = (unsigned char *)SvPVbyte(data, inlen);
+ unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
+ int rv;
+ unsigned char mac[MAXBLOCKSIZE];
+ unsigned long len = sizeof(mac), outlen;
+ char out[MAXBLOCKSIZE*2];
+ int id = _find_cipher(cipher_name);
+ if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
+ rv = xcbc_memory(id, k, klen, in, inlen, mac, &len);
+ if (rv != CRYPT_OK) croak("FATAL: xcbc_memory failed: %s", error_to_string(rv));
+ outlen = sizeof(out);
+ rv = base64_encode(mac, len, (unsigned char *)out, &outlen);
+ if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
+ RETVAL = newSVpvn((char *) out, outlen);
+
+ }
+ OUTPUT:
+ RETVAL
+
+SV *
+xcbc_b64u(char * cipher_name, SV * key, SV * data)
+ CODE:
+ {
+ STRLEN inlen, klen;
+ unsigned char *in = (unsigned char *)SvPVbyte(data, inlen);
+ unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
+ int rv;
+ unsigned char mac[MAXBLOCKSIZE];
+ unsigned long len = sizeof(mac), outlen;
+ char out[MAXBLOCKSIZE*2];
+ int id = _find_cipher(cipher_name);
+ if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
+ rv = xcbc_memory(id, k, klen, in, inlen, mac, &len);
+ if (rv != CRYPT_OK) croak("FATAL: xcbc_memory failed: %s", error_to_string(rv));
+ outlen = sizeof(out);
+ rv = base64url_encode(mac, len, (unsigned char *)out, &outlen);
+ if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
+ RETVAL = newSVpvn((char *) out, outlen);
+ }
+ OUTPUT:
+ RETVAL