Digest-MD6
view release on metacpan or search on metacpan
src/md6_mode.c view on Meta::CPAN
/* MD6 Constant Vector Q (continued).
*/
#if (w==16) /* for variant version */
/* 60 16-bit words */
static const md6_word Q[60] =
{
0x7311, 0xc281, 0x2425, 0xcfa0,
0x6432, 0x2864, 0x34aa, 0xc8e7,
0xb604, 0x50e9, 0xef68, 0xb7c1,
0xe8fb, 0x2390, 0x8d9f, 0x06f1,
0xdd2e, 0x76cb, 0xa691, 0xe5bf,
0x0cd0, 0xd63b, 0x2c30, 0xbc41,
0x1f8c, 0xcf68, 0x2305, 0x8f8a,
0x54e5, 0xed5b, 0x88e3, 0x775d,
0x4ad1, 0x2aae, 0x0a6d, 0x6031,
0x3e7f, 0x16bb, 0x8822, 0x2e0d,
0x8af8, 0x671d, 0x3fb5, 0x0c2c,
0x995a, 0xd117, 0x8bd2, 0x5c31,
0xc878, 0xc1dd, 0x04c4, 0xb633,
0x3b72, 0x066c, 0x7a15, 0x52ac,
0x0d6f, 0x3522, 0x631e, 0xffcb,
};
#endif
#if (w==8) /* for variant version */
/* 120 8-bit words */
static const md6_word Q[120] =
{
0x73, 0x11, 0xc2, 0x81, 0x24, 0x25, 0xcf, 0xa0,
0x64, 0x32, 0x28, 0x64, 0x34, 0xaa, 0xc8, 0xe7,
0xb6, 0x04, 0x50, 0xe9, 0xef, 0x68, 0xb7, 0xc1,
0xe8, 0xfb, 0x23, 0x90, 0x8d, 0x9f, 0x06, 0xf1,
0xdd, 0x2e, 0x76, 0xcb, 0xa6, 0x91, 0xe5, 0xbf,
0x0c, 0xd0, 0xd6, 0x3b, 0x2c, 0x30, 0xbc, 0x41,
0x1f, 0x8c, 0xcf, 0x68, 0x23, 0x05, 0x8f, 0x8a,
0x54, 0xe5, 0xed, 0x5b, 0x88, 0xe3, 0x77, 0x5d,
0x4a, 0xd1, 0x2a, 0xae, 0x0a, 0x6d, 0x60, 0x31,
0x3e, 0x7f, 0x16, 0xbb, 0x88, 0x22, 0x2e, 0x0d,
0x8a, 0xf8, 0x67, 0x1d, 0x3f, 0xb5, 0x0c, 0x2c,
0x99, 0x5a, 0xd1, 0x17, 0x8b, 0xd2, 0x5c, 0x31,
0xc8, 0x78, 0xc1, 0xdd, 0x04, 0xc4, 0xb6, 0x33,
0x3b, 0x72, 0x06, 0x6c, 0x7a, 0x15, 0x52, 0xac,
0x0d, 0x6f, 0x35, 0x22, 0x63, 0x1e, 0xff, 0xcb,
};
#endif
/* Endianness.
*/
/* routines for dealing with byte ordering */
int md6_byte_order = 0;
/* md6_byte_order describes the endianness of the
** underlying machine:
** 0 = unknown
** 1 = little-endian
** 2 = big-endian
*/
/* Macros to detect machine byte order; these
** presume that md6_byte_order has been setup by
** md6_detect_byte_order()
*/
#define MD6_LITTLE_ENDIAN (md6_byte_order == 1)
#define MD6_BIG_ENDIAN (md6_byte_order == 2)
void md6_detect_byte_order( void )
/* determine if underlying machine is little-endian or big-endian
** set global variable md6_byte_order to reflect result
** Written to work for any w.
*/
{ md6_word x = 1 | (((md6_word)2)<<(w-8));
unsigned char *cp = (unsigned char *)&x;
if ( *cp == 1 ) md6_byte_order = 1; /* little-endian */
else if ( *cp == 2 ) md6_byte_order = 2; /* big-endian */
else md6_byte_order = 0; /* unknown */
}
md6_word md6_byte_reverse( md6_word x )
/* return byte-reversal of md6_word x.
** Written to work for any w, w=8,16,32,64.
*/
{
#define mask8 ((md6_word)0x00ff00ff00ff00ffULL)
#define mask16 ((md6_word)0x0000ffff0000ffffULL)
#if (w==64)
x = (x << 32) | (x >> 32);
#endif
#if (w >= 32)
x = ((x & mask16) << 16) | ((x & ~mask16) >> 16);
#endif
#if (w >= 16)
x = ((x & mask8) << 8) | ((x & ~mask8) >> 8);
#endif
return x;
}
void md6_reverse_little_endian( md6_word *x, int count )
/* Byte-reverse words x[0...count-1] if machine is little_endian */
{
int i;
if (MD6_LITTLE_ENDIAN)
for (i=0;i<count;i++)
x[i] = md6_byte_reverse(x[i]);
}
/* Appending one bit string onto another.
*/
void append_bits( unsigned char *dest, unsigned int destlen,
unsigned char *src, unsigned int srclen )
/* Append bit string src to the end of bit string dest
** Input:
** dest a bit string of destlen bits, starting in dest[0]
** if destlen is not a multiple of 8, the high-order
** bits are used first
** src a bit string of srclen bits, starting in src[0]
** if srclen is not a multiple of 8, the high-order
** bits are used first
** Modifies:
( run in 0.721 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )