blowfish requires data come in 64 bit blocks
now should i use a loop to copy the data or memcpy() ???
Code:
// NAME: blf_padData
// pads data into 64-bit blocks
// void* data buffer you want to pad
// unsigned int len length in bits(uchar)
// int &NumofBlocks place to store num of 64 bit blocks
//////////////////////////////////////////////////////////////
unsigned long* blf_padData( void* data, const unsigned int len, int &NumofBlocks){
unsigned int w,x,y,z; //counters
unsigned char* d; //pointer to cast data into;
unsigned long* pdata = 0;//pointer to the padded data.
unsigned long temp;
if (!data)
return NULL;
d = (unsigned char*)data;
//get the size of the buffer needed
NumofBlocks = len/8; //64-bit blocks
if (0 != len%8) //if it doesnt fit perfect then add a block
NumofBlocks++;
//make the buffer
pdata = (unsigned long*) malloc( 8 * NumofBlocks); //8 = sizeof(unsigned long)*2 64-bit blocks
w = 0;
if (!pdata)
return NULL;
//copy all of data into pdata
for(x = 0, z = 0; x < NumofBlocks; x++){
for(int loopc = 0; loopc < 2; loopc++){
temp = 0x00000000;
for(y = 0; y < 4; y++){
temp <<= 8;
if(z < len)
temp = temp | d[z];
z++;
}
pdata[w] = temp;
w++;
}
}
//memset(pdata, 0, 8*NumofBlocks);
//memcpy( pdata, data, len);
return pdata;
}