Example #1
0
void sha3_process(sha3 *sh,int byte)
{
	int cnt=(int)(sh->length%sh->rate);
	int i,j,b=cnt%8;
	cnt/=8;
	i=cnt%5; j=cnt/5;  /* process by columns! */
	sh->S[i][j]^=((mr_unsign64)byte<<(8*b));
	sh->length++;
	if (sh->length%sh->rate==0) shs_transform(sh);
}
Example #2
0
void shs256_process(sha256 *sh,int byte)
{ /* process the next message byte */
    int cnt;

    cnt=(int)((sh->length[0]/32)%16);
    
    sh->w[cnt]<<=8;
    sh->w[cnt]|=(mr_unsign32)(byte&0xFF);

    sh->length[0]+=8;
    if (sh->length[0]==0L) { sh->length[1]++; sh->length[0]=0L; }
    if ((sh->length[0]%512)==0) shs_transform(sh);
}
Example #3
0
void shs384_process(sha384 *sh,int byte)
{ /* process the next message byte */
    int cnt;
    
    cnt=(int)((sh->length[0]/48)%16);
    
    sh->w[cnt]<<=8;
    sh->w[cnt]|=(mr_unsign64)(byte&0xFF);

    sh->length[0]+=8;
    if (sh->length[0]==0L) { sh->length[1]++; sh->length[0]=0L; }
    if ((sh->length[0]%1024)==0) shs_transform(sh);
}
Example #4
0
void shs256_hash(sha256 *sh,char hash[32])
{   /* pad message and finish - supply digest */
    int i;
    mr_unsign32 len0,len1;
    len0=sh->length[0];
    len1=sh->length[1];
    shs256_process(sh,PAD);
    while ((sh->length[0]%512)!=448) shs256_process(sh,ZERO);
    sh->w[14]=len1;
    sh->w[15]=len0;
    shs_transform(sh);
    for (i=0; i<32; i++)
    {   /* convert to bytes */
        hash[i]=(char)((sh->h[i/4]>>(8*(3-i%4))) & 0xffL);
    }
    shs256_init(sh);
}
Example #5
0
void shs384_hash(sha384 *sh,char hash[48])
{ /* pad message and finish - supply digest */
    int i;
    mr_unsign64 len0,len1;
    len0=sh->length[0];
    len1=sh->length[1];
    shs384_process(sh,PAD);
    while ((sh->length[0]%1024)!=896) shs384_process(sh,ZERO);
    sh->w[14]=len1;
    sh->w[15]=len0;    
    shs_transform(sh);
    for (i=0;i<48;i++)
    { /* convert to bytes */
        hash[i]=(char)((sh->h[i/8]>>(8*(7-i%8))) & 0xffL);
    }
    shs384_init(sh);
}