libcryptx-perl/inc/CryptX_Mac_F9.xs.inc

158 lines
4.8 KiB
PHP
Raw Normal View History

2018-03-22 15:51:09 +01:00
MODULE = CryptX PACKAGE = Crypt::Mac::F9
2018-03-22 15:54:03 +01:00
PROTOTYPES: DISABLE
2018-03-22 15:51:09 +01:00
### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
Crypt::Mac::F9
2018-03-22 15:54:03 +01:00
new(Class, char * cipher_name, SV * key)
2018-03-22 15:51:09 +01:00
CODE:
{
STRLEN k_len=0;
unsigned char *k=NULL;
int rv;
int id;
2018-03-22 15:54:03 +01:00
id = _find_cipher(cipher_name);
if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name);
2018-03-22 15:51:09 +01:00
if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
k = (unsigned char *) SvPVbyte(key, k_len);
2018-03-22 15:54:03 +01:00
Newz(0, RETVAL, 1, f9_state);
2018-03-22 15:51:09 +01:00
if (!RETVAL) croak("FATAL: Newz failed");
2018-03-22 15:54:03 +01:00
rv = f9_init(RETVAL, id, k, (unsigned long)k_len);
if (rv != CRYPT_OK) {
Safefree(RETVAL);
croak("FATAL: f9_init failed: %s", error_to_string(rv));
}
2018-03-22 15:51:09 +01:00
}
OUTPUT:
RETVAL
void
DESTROY(Crypt::Mac::F9 self)
CODE:
Safefree(self);
Crypt::Mac::F9
clone(Crypt::Mac::F9 self)
CODE:
2018-03-22 15:54:03 +01:00
Newz(0, RETVAL, 1, f9_state);
2018-03-22 15:51:09 +01:00
if (!RETVAL) croak("FATAL: Newz failed");
2018-03-22 15:54:03 +01:00
Copy(self, RETVAL, 1, f9_state);
2018-03-22 15:51:09 +01:00
OUTPUT:
RETVAL
void
2018-03-22 15:54:03 +01:00
add(Crypt::Mac::F9 self, ...)
PPCODE:
2018-03-22 15:51:09 +01:00
{
2018-03-22 15:54:03 +01:00
int rv, i;
2018-03-22 15:51:09 +01:00
STRLEN in_data_len;
unsigned char *in_data;
2018-03-22 15:54:03 +01:00
for(i = 1; i < items; i++) {
in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
if (in_data_len > 0) {
rv = f9_process(self, in_data, (unsigned long)in_data_len);
if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv));
}
2018-03-22 15:51:09 +01:00
}
2018-03-22 15:54:03 +01:00
XPUSHs(ST(0)); /* return self */
2018-03-22 15:51:09 +01:00
}
SV *
mac(Crypt::Mac::F9 self)
2018-03-22 15:54:03 +01:00
ALIAS:
hexmac = 1
b64mac = 2
b64umac = 3
2018-03-22 15:51:09 +01:00
CODE:
{
unsigned char mac[MAXBLOCKSIZE];
2018-03-22 15:54:03 +01:00
unsigned long maclen, outlen;
2018-03-22 15:51:09 +01:00
int rv;
2018-03-22 15:54:03 +01:00
char out[MAXBLOCKSIZE*2];
2018-03-22 15:51:09 +01:00
2018-03-22 15:54:03 +01:00
maclen = sizeof(mac);
rv = f9_done(self, mac, &maclen);
2018-03-22 15:51:09 +01:00
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
2018-03-22 15:54:03 +01:00
outlen = sizeof(out);
if (ix == 3) {
rv = base64url_encode(mac, maclen, (unsigned char*)out, &outlen);
if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
RETVAL = newSVpvn(out, outlen);
}
if (ix == 2) {
rv = base64_encode(mac, maclen, (unsigned char*)out, &outlen);
if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
RETVAL = newSVpvn(out, outlen);
}
if (ix == 1) {
rv = _base16_encode(mac, maclen, (unsigned char *)out, &outlen);
if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
RETVAL = newSVpvn(out, outlen);
}
else {
RETVAL = newSVpvn((char * )mac, maclen);
}
2018-03-22 15:51:09 +01:00
}
OUTPUT:
RETVAL
SV *
2018-03-22 15:54:03 +01:00
f9(char * cipher_name, SV * key, ...)
ALIAS:
f9_hex = 1
f9_b64 = 2
f9_b64u = 3
2018-03-22 15:51:09 +01:00
CODE:
{
2018-03-22 15:54:03 +01:00
STRLEN inlen, klen;
unsigned char *in;
unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
int rv, i;
2018-03-22 15:51:09 +01:00
unsigned char mac[MAXBLOCKSIZE];
2018-03-22 15:54:03 +01:00
unsigned long len = sizeof(mac), outlen;
char out[MAXBLOCKSIZE*2];
f9_state st;
2018-03-22 15:51:09 +01:00
2018-03-22 15:54:03 +01:00
int id = _find_cipher(cipher_name);
if (id == -1) croak("FATAL: find_cipher failed for '%s'", cipher_name);
rv = f9_init(&st, id, k, (unsigned long)klen);
if (rv != CRYPT_OK) croak("FATAL: f9_init failed: %s", error_to_string(rv));
for (i = 2; i < items; i++) {
in = (unsigned char *)SvPVbyte(ST(i), inlen);
if (inlen > 0) {
rv = f9_process(&st, in, (unsigned long)inlen);
if (rv != CRYPT_OK) croak("FATAL: f9_process failed: %s", error_to_string(rv));
}
}
rv = f9_done(&st, mac, &len);
2018-03-22 15:51:09 +01:00
if (rv != CRYPT_OK) croak("FATAL: f9_done failed: %s", error_to_string(rv));
2018-03-22 15:54:03 +01:00
outlen = sizeof(out);
if (ix == 3) {
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);
}
else if (ix == 2) {
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);
}
else if (ix == 1) {
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);
}
else {
RETVAL = newSVpvn((char *) mac, len);
}
2018-03-22 15:51:09 +01:00
}
OUTPUT:
RETVAL