Hi all,
My code is giving the desired o/p, but at the end its producing segmentation fault.
(I know this is very column and also I have checked other posts, but couldn't understand the solution)
Here is my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "blake.h"
int genShortMsg(int hashbitlen);
int
main()
{
int ret_val;
ret_val = genShortMsg(256);
return 0;
}
int
genShortMsg(int hashbitlen)
{
int msglen, msgbytelen;
BitSequence Msg[7], MD[64];
msglen=55;
msgbytelen = (msglen+7)/8;
int ch, started;
BitSequence ich;
int i;
if ( msgbytelen == 0 ) {
Msg[0] = 0x00;
}
memset(Msg, 0x00, msgbytelen);
started = 0;
char str[] = "14B06DD54EB364";
int j;
for(j=0;j<strlen(str);j++){
ch=str[j];
if ( (ch >= '0') && (ch <= '9') )
ich = ch - '0';
else if ( (ch >= 'A') && (ch <= 'F') )
ich = ch - 'A' + 10;
else if ( (ch >= 'a') && (ch <= 'f') )
ich = ch - 'a' + 10;
for ( i=0; i<msgbytelen-1; i++ )Msg[i] = (Msg[i] << 4) | (Msg[i+1] >> 4);
Msg[msgbytelen-1] = (Msg[msgbytelen-1] << 4) | ich;
}
for(i=0;i<64;i++)MD[i]=0;
Hash(256, Msg, msglen, MD);
for(i=0;i<32;++i)printf("%02X",MD[i]);
printf("\n");
return 0;
}
It prints correct o/p(computed by Hash(.......)), but crashes when genShortMsg() returns.
Thanks in advance for the reply