4 * Created on: 22/02/2009
9 #include <apr_base64.h>
11 /* fills in the first 5 bytes of target with the base64 bit encoded hash
13 it is endian safe, and adds a null terminator, so target must have space for 6 bytes
15 char * encode_30bithash(unsigned hash
, char * target
)
18 unsigned char source
[4];
19 // possibly a faster way, but needs to be endian safe, including bit endianness
20 source
[0]=(hash
&0x3fc00000)>>22;
21 source
[1]=(hash
&0x003fc000)>>14;
22 source
[2]=(hash
&0x00003fc0)>>6;
23 source
[3]=(hash
&0x0000003f)<<2;
25 apr_base64_encode (temp_result
, (void *)source
, 4);
26 memcpy(target
,temp_result
,5);
32 /* decodes a 5 bytes base 64bit string to the lower 30 bits of an int
34 it is endian safe, and assumes an input string of 5 bytes
36 unsigned decode_30bithash(const char * source
)
39 unsigned char target
[7];
40 memcpy(temp_source
,source
,5);
46 apr_base64_decode ((void*)target
, temp_source
);
48 result
= target
[0] << 22;
49 result
|= target
[1] << 14;
50 result
|= target
[2] << 6;
51 result
|= target
[3] >> 2;