Esempio n. 1
0
/**
 Process a block of memory though the hash
 @param md     The hash state
 @param in     The data to hash
 @param inlen  The length of the data (octets)
 @return CRYPT_OK if successful
 */
int ltc_md2_process(ltc_md2_ctx *ctx, const unsigned char *in,
    unsigned long inlen)
{
    unsigned long n;

    LTC_ARGCHK(ctx != NULL);
    LTC_ARGCHK(in != NULL);

    if (ctx->curlen > sizeof(ctx->buf)) {                            
        return CRYPT_INVALID_ARG; 
    }                            

    while (inlen > 0) {
        n = MIN(inlen, (16 - ctx->curlen));
        CC_XMEMCPY(ctx->buf + ctx->curlen, in, (size_t)n);
        ctx->curlen += n;
        in             += n;
        inlen          -= n;
        
        /* is 16 bytes full? */
        if (ctx->curlen == 16) {
            md2_compress(ctx);
            md2_update_chksum(ctx);
            ctx->curlen = 0;
        }
    }
    return CRYPT_OK;
}
Esempio n. 2
0
/**
 Terminate the hash to get the digest
 @param md  The hash state
 @param out [out] The destination of the hash (16 bytes)
 @return CRYPT_OK if successful
 */
int ltc_md2_done(ltc_md2_ctx *ctx, unsigned char *out)
{
    unsigned long i, k;
    
    LTC_ARGCHK(ctx  != NULL);
    LTC_ARGCHK(out != NULL);
        
    if (ctx->curlen >= sizeof(ctx->buf)) {
        return CRYPT_INVALID_ARG;
    }
    
    
    /* pad the message */
    k = 16 - ctx->curlen;
    for (i = ctx->curlen; i < 16; i++) {
        ctx->buf[i] = (unsigned char)k;
    }
    
    /* hash and update */
    md2_compress(ctx);
    md2_update_chksum(ctx);
    
    /* hash checksum */
    CC_XMEMCPY(ctx->buf, ctx->chksum, 16);
    md2_compress(ctx);
    
    /* output is lower 16 bytes of X */
    CC_XMEMCPY(out, ctx->X, 16);
    
#ifdef LTC_CLEAN_STACK
    CC_XZEROMEM(ctx, sizeof(hash_state));
#endif
    return CRYPT_OK;
}
Esempio n. 3
0
int md2_done(md2_state * md2, unsigned char *hash)
{
    unsigned long i, k;

    if (md2->curlen >= sizeof(md2->buf)) {
       return CRYPT_INVALID_ARG;
    }

    /* pad the message */
    k = 16 - md2->curlen;
    for (i = md2->curlen; i < 16; i++) {
        md2->buf[i] = (unsigned char)k;
    }

    /* hash and update */
    md2_compress(md2);
    md2_update_chksum(md2);

    /* hash checksum */
    memcpy(md2->buf, md2->chksum, 16);
    md2_compress(md2);

    /* output is lower 16 bytes of X */
    memcpy(hash, md2->X, 16);

    return CRYPT_OK;
}
Esempio n. 4
0
File: md2.c Progetto: avokhmin/RPM5
int md2Digest(md2Param * mp, byte *digest)
{
	uint32_t i, k;

	/* pad the message */
	k = 16 - mp->offset;
	for (i = mp->offset; i < 16; i++) {
		mp->buf[i] = (byte)k;
	}

	/* hash and update */
	md2_compress(mp);
	md2_update_chksum(mp);

	/* hash checksum */
	memcpy(mp->buf, mp->chksum, 16);
	md2_compress(mp);

	/* output is lower 16 bytes of X */
	memcpy(digest, mp->X, 16);

	memset(mp, 0, sizeof(*mp));

	return 0;
}
Esempio n. 5
0
int32_t psMd2Update(psMd2_t *md, const unsigned char *buf, uint32_t len)
{
    uint32_t n;

# ifdef CRYPTO_ASSERT
    psAssert(md != NULL);
    psAssert(buf != NULL);
    if (md->curlen > sizeof(md->buf))
    {
        psTraceCrypto("psMd2Update error\n");
        return PS_LIMIT_FAIL;
    }
# endif
    while (len > 0)
    {
        n = min(len, (16 - md->curlen));
        memcpy(md->buf + md->curlen, buf, (size_t) n);
        md->curlen += n;
        buf            += n;
        len            -= n;

        /* is 16 bytes full? */
        if (md->curlen == 16)
        {
            md2_compress(md);
            md2_update_chksum(md);
            md->curlen = 0;
        }
    }
    return PS_SUCCESS;
}
Esempio n. 6
0
int32 matrixMd2Final(hash_state * md, unsigned char *hash)
{
    unsigned long i, k;

    sslAssert(md != NULL);
    sslAssert(hash != NULL);

    if (md->md2.curlen >= sizeof(md->md2.buf)) {
       return CRYPT_INVALID_ARG;
    }


    /* pad the message */
    k = 16 - md->md2.curlen;
    for (i = md->md2.curlen; i < 16; i++) {
        md->md2.buf[i] = (unsigned char)k;
    }

    /* hash and update */
    md2_compress(md);
    md2_update_chksum(md);

    /* hash checksum */
    memcpy(md->md2.buf, md->md2.chksum, 16);
    md2_compress(md);

    /* output is lower 16 bytes of X */
    memcpy(hash, md->md2.X, 16);

#ifdef CLEAN_STACK
    psZeromem(md, sizeof(hash_state));
#endif
    return CRYPT_OK;
}
Esempio n. 7
0
int32 psMd2Final(psDigestContext_t * md, unsigned char *hash)
{
	uint32 i, k;

	psAssert(md != NULL);
	psAssert(hash != NULL);

	if (md->md2.curlen >= sizeof(md->md2.buf)) {
		psTraceCrypto("psMd2Final error\n");
		return PS_LIMIT_FAIL;
	}


	/* pad the message */
	k = 16 - md->md2.curlen;
	for (i = md->md2.curlen; i < 16; i++) {
		md->md2.buf[i] = (unsigned char)k;
	}

	/* hash and update */
	md2_compress(md);
	md2_update_chksum(md);

	/* hash checksum */
	memcpy(md->md2.buf, md->md2.chksum, 16);
	md2_compress(md);

	/* output is lower 16 bytes of X */
	memcpy(hash, md->md2.X, 16);

	memset(md, 0x0, sizeof(psDigestContext_t));
	return PS_SUCCESS;
}
Esempio n. 8
0
int32 psMd2Update(psDigestContext_t *md, const unsigned char *buf, uint32 len)
{
	uint32 n;

	psAssert(md != NULL);
	psAssert(buf != NULL);
	if (md->md2.curlen > sizeof(md->md2.buf)) {
		psTraceCrypto("psMd2Update error\n");
		return PS_LIMIT_FAIL;
	}
	while (len > 0) {
		n = min(len, (16 - md->md2.curlen));
		memcpy(md->md2.buf + md->md2.curlen, buf, (size_t)n);
		md->md2.curlen += n;
		buf            += n;
		len            -= n;

		/* is 16 bytes full? */
		if (md->md2.curlen == 16) {
			md2_compress(md);
			md2_update_chksum(md);
			md->md2.curlen = 0;
		}
	}
	return PS_SUCCESS;
}
Esempio n. 9
0
/**
   Terminate the hash to get the digest
   @param md  The hash state
   @param out [out] The destination of the hash (16 bytes)
   @return CRYPT_OK if successful
*/
int md2_done(hash_state * md, unsigned char *out)
{
    unsigned long i, k;

    LTC_ARGCHK(md  != NULL);
    LTC_ARGCHK(out != NULL);

    if (md->md2.curlen >= sizeof(md->md2.buf)) {
       return CRYPT_INVALID_ARG;
    }


    /* pad the message */
    k = 16 - md->md2.curlen;
    for (i = md->md2.curlen; i < 16; i++) {
        md->md2.buf[i] = (unsigned char)k;
    }

    /* hash and update */
    md2_compress(md);
    md2_update_chksum(md);

    /* hash checksum */
    XMEMCPY(md->md2.buf, md->md2.chksum, 16);
    md2_compress(md);

    /* output is lower 16 bytes of X */
    XMEMCPY(out, md->md2.X, 16);

#ifdef LTC_CLEAN_STACK
    zeromem(md, sizeof(hash_state));
#endif
    return CRYPT_OK;
}
Esempio n. 10
0
File: md2.c Progetto: AndreRH/wine
void md2_update(MD2_CTX *md2, const unsigned char *buf, ULONG len)
{
    unsigned long n;

    assert(md2->curlen <= sizeof(md2->buf));

    while (len > 0) {
        n = min(len, (16 - md2->curlen));
        memcpy(md2->buf + md2->curlen, buf, (size_t)n);
        md2->curlen += n;
        buf         += n;
        len         -= n;

        /* is 16 bytes full? */
        if (md2->curlen == 16) {
            md2_compress(md2);
            md2_update_chksum(md2);
            md2->curlen = 0;
        }
    }
}
Esempio n. 11
0
/* Process the remaining bytes in the internal buffer and the usual
   prolog according to the standard and write the result to RESBUF.  */
void *
md2_finish_ctx (struct md2_ctx *ctx, void *resbuf)
{
  unsigned long i, k;

  /* pad the message */
  k = 16 - ctx->curlen;
  for (i = ctx->curlen; i < 16; i++)
    {
      ctx->buf[i] = (unsigned char) k;
    }

  /* hash and update */
  md2_compress (ctx);
  md2_update_chksum (ctx);

  /* hash checksum */
  memcpy (ctx->buf, ctx->chksum, 16);
  md2_compress (ctx);

  return md2_read_ctx (ctx, resbuf);
}
Esempio n. 12
0
int md2_process(md2_state *md2, const unsigned char *buf, unsigned long len)
{
    unsigned long n;
    
    if (md2->curlen > sizeof(md2->buf)) {                            
       return CRYPT_INVALID_ARG;                                                           
    }                                                                                       
    while (len > 0) {
        n = MIN(len, (16 - md2->curlen));
        memcpy(md2->buf + md2->curlen, buf, (size_t)n);
        md2->curlen += n;
        buf         += n;
        len         -= n;

        /* is 16 bytes full? */
        if (md2->curlen == 16) {
            md2_compress(md2);
            md2_update_chksum(md2);
            md2->curlen = 0;
        }
    }
    return CRYPT_OK;
}
Esempio n. 13
0
void
md2_process_bytes (const void *buffer, size_t len, struct md2_ctx *ctx)
{
  const char *in = buffer;
  unsigned long n;

  while (len > 0)
    {
      n = MIN (len, (16 - ctx->curlen));
      memcpy (ctx->buf + ctx->curlen, in, (size_t) n);
      ctx->curlen += n;
      in += n;
      len -= n;

      /* is 16 bytes full? */
      if (ctx->curlen == 16)
        {
          md2_compress (ctx);
          md2_update_chksum (ctx);
          ctx->curlen = 0;
        }
    }
}
Esempio n. 14
0
File: md2.c Progetto: AndreRH/wine
void md2_finalize(MD2_CTX * md2, unsigned char *hash)
{
    unsigned long i, k;

    assert(md2->curlen <= sizeof(md2->buf));

    /* pad the message */
    k = 16 - md2->curlen;
    for (i = md2->curlen; i < 16; i++) {
        md2->buf[i] = (unsigned char)k;
    }

    /* hash and update */
    md2_compress(md2);
    md2_update_chksum(md2);

    /* hash checksum */
    memcpy(md2->buf, md2->chksum, 16);
    md2_compress(md2);

    /* output is lower 16 bytes of X */
    memcpy(hash, md2->X, 16);
}
Esempio n. 15
0
/**
   Process a block of memory though the hash
   @param md     The hash state
   @param in     The data to hash
   @param inlen  The length of the data (octets)
   @return CRYPT_OK if successful
*/
int md2_process(hash_state *md, const unsigned char *in, unsigned long inlen)
{
    unsigned long n;
    LTC_ARGCHK(md != NULL);
    LTC_ARGCHK(in != NULL);
    if (md-> md2 .curlen > sizeof(md-> md2 .buf)) {                            
       return CRYPT_INVALID_ARG;                                                           
    }                                                                                       
    while (inlen > 0) {
        n = MIN(inlen, (16 - md->md2.curlen));
        XMEMCPY(md->md2.buf + md->md2.curlen, in, (size_t)n);
        md->md2.curlen += n;
        in             += n;
        inlen          -= n;

        /* is 16 bytes full? */
        if (md->md2.curlen == 16) {
            md2_compress(md);
            md2_update_chksum(md);
            md->md2.curlen = 0;
        }
    }
    return CRYPT_OK;
}
Esempio n. 16
0
File: md2.c Progetto: avokhmin/RPM5
int md2Update(md2Param *mp, const byte *data, size_t size)
{
	uint32_t proclength;

	#if (MP_WBITS == 64)
	mpw add[1];
	mpsetw(1, add, size);
	mplshift(1, add, 3);
	mpadd(1, mp->length, add);
	#elif (MP_WBITS == 32)
	mpw add[2];
	mpsetw(2, add, size);
	mplshift(2, add, 3);
	(void) mpadd(2, mp->length, add);
	#else
	# error
	#endif

	while (size > 0) {
		proclength = ((mp->offset + size) > 16U) ? (16U - mp->offset) : size;
/*@-mayaliasunique@*/
		memcpy(((byte *)mp->buf) + mp->offset, data, proclength);
/*@=mayaliasunique@*/
		size -= proclength;
		data += proclength;
		mp->offset += proclength;

		/* is 16 bytes full? */
		if (mp->offset == 16U) {
			md2_compress(mp);
			md2_update_chksum(mp);
			mp->offset = 0;
		}
	}
	return 0;
}
Esempio n. 17
0
int32 matrixMd2Update(hash_state *md, const unsigned char *buf, unsigned long len)
{
    unsigned long n;
    sslAssert(md != NULL);
    sslAssert(buf != NULL);
    if (md-> md2 .curlen > sizeof(md-> md2 .buf)) {                            
       return CRYPT_INVALID_ARG;                                                           
    }                                                                                       
    while (len > 0) {
        n = MIN(len, (16 - md->md2.curlen));
        memcpy(md->md2.buf + md->md2.curlen, buf, (size_t)n);
        md->md2.curlen += n;
        buf            += n;
        len            -= n;

        /* is 16 bytes full? */
        if (md->md2.curlen == 16) {
            md2_compress(md);
            md2_update_chksum(md);
            md->md2.curlen = 0;
        }
    }
    return CRYPT_OK;
}