int MD2_Update(MD2_CTX *c, const unsigned char *data, size_t len) { register UCHAR *p; if (len == 0) return 1; p=c->data; if (c->num != 0) { if ((c->num+len) >= MD2_BLOCK) { op_memcpy(&(p[c->num]),data,MD2_BLOCK-c->num); md2_block(c,c->data); data+=(MD2_BLOCK - c->num); len-=(MD2_BLOCK - c->num); c->num=0; /* drop through and do the rest */ } else { op_memcpy(&(p[c->num]),data,len); /* data+=len; */ c->num+=(int)len; return 1; } } /* we now can process the input data in blocks of MD2_BLOCK * chars and save the leftovers to c->data. */ while (len >= MD2_BLOCK) { md2_block(c,data); data+=MD2_BLOCK; len-=MD2_BLOCK; } op_memcpy(p,data,len); c->num=(int)len; return 1; }
void MD2_Final(unsigned char *md, MD2_CTX *c) { int i,v; register UCHAR *cp; register MD2_INT *p1,*p2; cp=c->data; p1=c->state; p2=c->cksm; v=MD2_BLOCK-c->num; for (i=c->num; i<MD2_BLOCK; i++) cp[i]=(UCHAR)v; md2_block(c,cp); for (i=0; i<MD2_BLOCK; i++) cp[i]=(UCHAR)p2[i]; md2_block(c,cp); for (i=0; i<16; i++) md[i]=(UCHAR)(p1[i]&0xff); memset((char *)&c,0,sizeof(c)); }