示例#1
0
void SHA1_Update(void *c_opaque, const REBYTE *data, REBCNT len)
    {
    SHA_CTX *c = (SHA_CTX*)c_opaque;
    ULONG *p;
    int ew,ec,sw,sc;
    ULONG l;

    if (len == 0) return;

    l=(c->Nl+((SHA_LONG)len<<3))&(SHA_LONG)-1;
    if (l < c->Nl) /* overflow */
        c->Nh++;
    c->Nh+=(len>>29);
    c->Nl=l;

    if (c->num != 0)
        {
        p=c->data;
        sw=c->num>>2;
        sc=c->num&0x03;

        if ((c->num+len) >= SHA_CBLOCK)
            {
            l= p[sw];
            M_p_c2nl(data,l,sc);
            p[sw++]=l;
            for (; sw<SHA_LBLOCK; sw++)
                {
                M_c2nl(data,l);
                p[sw]=l;
                }
            len-=(SHA_CBLOCK-c->num);

            sha1_block(c,p,64);
            c->num=0;
            /* drop through and do the rest */
            }
        else
            {
            c->num+=(int)len;
            if ((sc+len) < 4) /* ugly, add char's to a word */
                {
                l= p[sw];
                M_p_c2nl_p(data,l,sc,len);
                p[sw]=l;
                }
            else
                {
                ew=(c->num>>2);
                ec=(c->num&0x03);
                l= p[sw];
                M_p_c2nl(data,l,sc);
                p[sw++]=l;
                for (; sw < ew; sw++)
                    { M_c2nl(data,l); p[sw]=l; }
                if (ec)
                    {
                    M_c2nl_p(data,l,ec);
                    p[sw]=l;
                    }
                }
            return;
            }
        }
示例#2
0
void
SHA_Update(SHA_CTX *c, const void *in, size_t len)
	{
	u_int32_t *p;
	int ew,ec,sw,sc;
	u_int32_t l;
	const unsigned char *data = in;

	if (len == 0) return;

	l=(c->Nl+(len<<3))&0xffffffffL;
	if (l < c->Nl) /* overflow */
		c->Nh++;
	c->Nh+=(len>>29);
	c->Nl=l;

	if (c->num != 0)
		{
		p=c->data;
		sw=c->num>>2;
		sc=c->num&0x03;

		if ((c->num+len) >= SHA_CBLOCK)
			{
			l= p[sw];
			M_p_c2nl(data,l,sc);
			p[sw++]=l;
			for (; sw<SHA_LBLOCK; sw++)
				{
				M_c2nl(data,l);
				p[sw]=l;
				}
			len-=(SHA_CBLOCK-c->num);

			sha_block(c,p,64);
			c->num=0;
			/* drop through and do the rest */
			}
		else
			{
			c->num+=(int)len;
			if ((sc+len) < 4) /* ugly, add char's to a word */
				{
				l= p[sw];
				M_p_c2nl_p(data,l,sc,len);
				p[sw]=l;
				}
			else
				{
				ew=(c->num>>2);
				ec=(c->num&0x03);
				l= p[sw];
				M_p_c2nl(data,l,sc);
				p[sw++]=l;
				for (; sw < ew; sw++)
					{ M_c2nl(data,l); p[sw]=l; }
				if (ec)
					{
					M_c2nl_p(data,l,ec);
					p[sw]=l;
					}
				}
			return;
			}
		}