Crypt-OpenSSL-Blowfish
view release on metacpan or search on metacpan
Blowfish.xs view on Meta::CPAN
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#define NEED_mg_findext
#include "ppport.h"
#include <openssl/blowfish.h>
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#include <openssl/evp.h>
#include <openssl/provider.h>
#endif
/*==========================================================*/
/* */
/* hexdump.xs: */
/* https://gist.github.com/mcnewton/14322391d50240ec9ebf */
/* */
/* Matthew Newton @mcnewton */
/* See hexdump.xs for LICENSE information */
/*==========================================================*/
#ifdef INCLUDE_HEXDUMP
#include "hexdump.xs"
#endif
/*==================================================*/
/* */
/* Macro to swap from little endian to big endian */
/* */
/*==================================================*/
# undef n2l
# define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
l|=((unsigned long)(*((c)++)))<<16L, \
l|=((unsigned long)(*((c)++)))<< 8L, \
l|=((unsigned long)(*((c)++))))
/*==================================================*/
/* */
/* Macro to swap from big endian to little endian */
/* */
/*==================================================*/
# undef l2n
# define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
*((c)++)=(unsigned char)(((l)>>16L)&0xff), \
*((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
*((c)++)=(unsigned char)(((l) )&0xff))
/*============================================*/
/* */
/* ensure_hv(SV *sv, const char *identifier) */
/* */
/* Helper function Taken from p5-Git-Raw */
/* to ensure that a value is a hash. It is */
/* used to verify that the 'options' passed */
/* in the constructor is valid */
/* */
/*============================================*/
STATIC HV *ensure_hv(pTHX_ SV *sv, const char *identifier) {
if (!SvROK(sv) || SvTYPE(SvRV(sv)) != SVt_PVHV)
croak("Invalid type for '%s', expected a hash", identifier);
return (HV *) SvRV(sv);
}
/*======================================================================*/
/* */
/* big_endian(const unsigned char *in, unsigned char *out) */
/* */
/* Swap the endianness of the block of data 'in'. This is only */
/* required for compatability with the original version of */
/* Crypt::OpenSSL::Blowfish. Which calls BF_encrypt and BF_decrypt */
/* without switching to big endian first. This function is called if */
/* Crypt::OpenSSL::Blowfish is created without any options (other than */
/* the key). */
/* */
/*======================================================================*/
void big_endian(const unsigned char *in, unsigned char *out)
{
BF_LONG l;
BF_LONG d[2];
n2l(in, l);
d[0] = l;
n2l(in, l);
d[1] = l;
Copy(d, out, 2, BF_LONG);
l = d[0] = d[1] = 0;
}
/*======================================================================*/
/* */
/* return_big_endian(const unsigned char *in) */
/* */
/* Swap the endianness of the block of data 'in'. This is only */
/* required for compatability with the original version of */
/* Crypt::OpenSSL::Blowfish. Which calls BF_encrypt and BF_decrypt */
/* without switching to big endian first. This function is called if */
/* Crypt::OpenSSL::Blowfish is created without any options (other than */
/* the key) or if the Modules get_big_endian is called. */
( run in 0.642 second using v1.01-cache-2.11-cpan-39bf76dae61 )