J
James Leddy
Hello,
I know you can cast a void pointer to an int, char, or any other type of
pointer, but can you do the reverse, cast an int or char pointer as a void
pounter?
This is the blowfish encipher algorithim and I need to make xl and xr void
because they come from a char * buffer, but I need them as unsigned longs.
void encipher_dword(void *xl, void *xr)
{
unsigned long *temp;
unsigned long *al, *ar;
int i;
al = (unsigned long *) xl;
ar = (unsigned long *) xr;
for (i = 0; i < N; i++) {
*al = *al ^ P;
*ar = f(al) ^ *ar;
SWAP(al, ar, temp);
}
SWAP(al, ar, temp);
*ar = *ar ^ P[N];
*al = *al ^ P[N + 1];
xl = (void *) al; //can I do this?
xr = ar; //should I do it like this?
}
I thought of another solution being to swap the actual values in al and ar,
insted of just the addresses, but I thought that would be slower
implementation.
Thanks,
I know you can cast a void pointer to an int, char, or any other type of
pointer, but can you do the reverse, cast an int or char pointer as a void
pounter?
This is the blowfish encipher algorithim and I need to make xl and xr void
because they come from a char * buffer, but I need them as unsigned longs.
void encipher_dword(void *xl, void *xr)
{
unsigned long *temp;
unsigned long *al, *ar;
int i;
al = (unsigned long *) xl;
ar = (unsigned long *) xr;
for (i = 0; i < N; i++) {
*al = *al ^ P;
*ar = f(al) ^ *ar;
SWAP(al, ar, temp);
}
SWAP(al, ar, temp);
*ar = *ar ^ P[N];
*al = *al ^ P[N + 1];
xl = (void *) al; //can I do this?
xr = ar; //should I do it like this?
}
I thought of another solution being to swap the actual values in al and ar,
insted of just the addresses, but I thought that would be slower
implementation.
Thanks,