コード例 #1
0
ファイル: ake6mnta.cpp プロジェクト: J0s3f/FiSH-irssi
Big H1(char *string)
{ // Hash a zero-terminated string to a number < modulus
    Big h,p;
    char s[HASH_LEN];
    int i,j; 
    sha sh;

    shs_init(&sh);

    for (i=0;;i++)
    {
        if (string[i]==0) break;
        shs_process(&sh,string[i]);
    }
    shs_hash(&sh,s);
    p=get_modulus();
    h=1; j=0; i=1;
    forever
    {
        h*=256; 
        if (j==HASH_LEN)  {h+=i++; j=0;}
        else         h+=s[j++];
        if (h>=p) break;
    }
    h%=p;
    return h;
}
コード例 #2
0
ファイル: ake6mnta.cpp プロジェクト: J0s3f/FiSH-irssi
Big H2(ZZn6 y)
{ // Hash and compress an Fp6 to a big number
    sha sh;
    ZZn u,v,w;
	ZZn2 x;
    Big a,h,p,xx[2];
    char s[HASH_LEN];
    int i,j,m;

    shs_init(&sh);
	y.get(x);
    x.get(u,v);
    xx[0]=u; xx[1]=v;
   
    for (i=0;i<2;i++)
    {
        a=xx[i];
        while (a>0)
        {
            m=a%256;
            shs_process(&sh,m);
            a/=256;
        }
    }
    shs_hash(&sh,s);
    h=from_binary(HASH_LEN,s);
    return h;
}
コード例 #3
0
ファイル: MRSTRONG.C プロジェクト: karllen/Windows_Program
static void fill_pool(csprng *rng)
{ /* hash down output of RNG to re-fill the pool */
    int i;
    sha sh;
    shs_init(&sh);
    for (i=0;i<128;i++) shs_process(&sh,sbrand(rng));
    shs_hash(&sh,rng->pool);
    rng->pool_ptr=0;
}
コード例 #4
0
ファイル: ecsver2.c プロジェクト: excrucio/MIRACL
static void hashing(FILE *fp,big hash)
{   /* compute hash function */
    char h[20];
    sha sh;
    int i,ch;
    shs_init(&sh);
    while ((ch=fgetc(fp))!=EOF) shs_process(&sh,ch);
    shs_hash(&sh,h);
    bytes_to_big(20,h,hash);
}
コード例 #5
0
ファイル: ecsign_s.c プロジェクト: J0s3f/FiSH-irssi
static void hashing(miracl *mip,FILE *fp,big hash)
{ /* compute hash function */
    char h[20];
    int len,ch;
    sha sh;
    shs_init(&sh);
    while ((ch=fgetc(fp))!=EOF) shs_process(&sh,ch);
    shs_hash(&sh,h);
    len=(MIRACL*MR_STATIC)/8;
    if (len>20) len=20;
    bytes_to_big(mip,len,h,hash);
}
コード例 #6
0
ファイル: mcl_ecpbs_common.c プロジェクト: robgjansen/pbs
void mcl_ecpbs_Hhash(big result, char *info, big m) {
	char hash[20];
	int i;
	sha sh;
	shs_init(&sh);
	for (i = 0; info[i] != 0; i++) {
		shs_process(&sh, info[i]);
	}
	shs_hash(&sh, hash);
	bytes_to_big(20, hash, result);
	mcl_ecpbs_mod(result, m);
}
コード例 #7
0
ファイル: ECSVER.CPP プロジェクト: flomar/CrypTool-VS2015
static Big hash(ifstream &fp)
{ /* compute hash function */
    char ch,s[20];
    char uch;
    int i;
    Big h;
    sha_r sh;
    shs_init(&sh);
    forever 
    { /* read in bytes from message file */
        fp.get(ch);
        if (fp.eof()) break;
        shs_process(&sh,ch);
    }
    shs_hash(&sh,s);
    h=from_binary(20,s);
    return h;
}
コード例 #8
0
ファイル: MRSTRONG.C プロジェクト: karllen/Windows_Program
void strong_init(csprng *rng,int rawlen,char *raw,mr_unsign32 tod)
{ /* initialise from at least 128 byte string of raw  *
   * random (keyboard?) input, and 32-bit time-of-day */
    int i;
    mr_unsign32 hash[MR_HASH_BYTES/4];
    sha sh;
    rng->pool_ptr=0;
    for (i=0;i<NK;i++) rng->ira[i]=0;
    if (rawlen>0)
    {
        shs_init(&sh);
        for (i=0;i<rawlen;i++)
            shs_process(&sh,raw[i]);
        shs_hash(&sh,(char *)hash);

/* initialise PRNG from distilled randomness */

        for (i=0;i<MR_HASH_BYTES/4;i++) sirand(rng,hash[i]);
    }
    sirand(rng,tod);

    fill_pool(rng);
}
コード例 #9
0
ファイル: hash.c プロジェクト: dalistudio/cdkey
// 计算 CDKEY 中 hash 散列的值
big key_hash(unsigned int Key, unsigned char Type, unsigned char Data, big rx, big ry)
{
	unsigned char buf[128], m[132], sha_out[20];
	unsigned long dw;
	int i, j, len, len2;
	sha sh;
	big hash;

	KEY tmp;
	tmp.a = Key; // 钥匙的值

	m[0] = tmp.b[3]; // 取钥匙的第3个字节
	m[1] = tmp.b[2]; // 取钥匙的第2个字节
	m[2] = Type; // CDKEY 中类型的值
	m[3] = Data; // CDKEY 中数据的值

	// 循环将 RX 的值放入 m[] 数组中,作为用于生成散列的内容。
	len = rx->len * 4; // 获得RX的长度
	big_to_bytes(len, rx, (char*)buf, FALSE); // 将 rx 转成 数值
	for (i = len - 1, j = 4; i >= 0; i--, j++)  m[j] = buf[i]; // 循环将 rx 写入 m[]

	// 循环将 RY 的值放入 m[] 数组中,作为用于生成散列的内容。
	len2 = ry->len * 4; // 获得RY的长度
	big_to_bytes(len2, ry, (char*)buf, FALSE); // 将 ry 转成 数值
	for (i = len2 - 1, j = len + 4; i >= 0; i--, j++) m[j] = buf[i]; // 循环将 ry 写入 m[]

	// 开始散列
	shs_init(&sh); // 初始化 sha1 散列
	for (i = 0; i < (4 + rx->len + ry->len); i++)
		shs_process(&sh, m[i]); // 将 m[] 写入 sha1 处理
	shs_hash(&sh, (char*)sha_out); // 计算 sha1 散列值

	memcpy(&dw, sha_out, 4); // 将前4字节写入 dw
	dw = dw & 0x7FFFFFFF; // 取后 31bit 数值
	hash = mirvar(dw);
	return hash; // 返回31bit散列的值
}
コード例 #10
0
ファイル: mnt_pair.cpp プロジェクト: J0s3f/FiSH-irssi
void PFC::start_hash(void)
{
	shs_init(&SH);
}