libraries/WM_Libraries/Platform/Common/crypto/wm_crypto_hard.c
s32 tls_crypto_md5_final(psDigestContext_t * md, unsigned char *hash)
{
	s32 i;
	u32 val;
#ifndef HAVE_NATIVE_INT64
	u32	n;
#endif

//	psAssert(md != NULL);
	if (hash == NULL) {
		psTraceCrypto("NULL hash storage passed to psMd5Final\n");
		return PS_ARG_FAIL;
	}

/*
	increase the length of the message
 */
#ifdef HAVE_NATIVE_INT64
	md->md5.length += md->md5.curlen << 3;
#else
	n = (md->md5.lengthLo + (md->md5.curlen << 3)) & 0xFFFFFFFFL;
	if (n < md->md5.lengthLo) {
		md->md5.lengthHi++;
	}
	md->md5.lengthHi += (md->md5.curlen >> 29);
	md->md5.lengthLo = n;
#endif /* HAVE_NATIVE_INT64 */

/*
	append the '1' bit
 */
	md->md5.buf[md->md5.curlen++] = (unsigned char)0x80;

/*
	if the length is currently above 56 bytes we append zeros then compress.
	Then we can fall back to padding zeros and length encoding like normal.
 */
	if (md->md5.curlen > 56) {
		while (md->md5.curlen < 64) {
			md->md5.buf[md->md5.curlen++] = (unsigned char)0;
		}
		hd_md5_compress(md);
		md->md5.curlen = 0;
	}

/*
	pad upto 56 bytes of zeroes
 */
	while (md->md5.curlen < 56) {
		md->md5.buf[md->md5.curlen++] = (unsigned char)0;
	}
/*
	store length
 */
#ifdef HAVE_NATIVE_INT64
	STORE64L(md->md5.length, md->md5.buf+56);
#else
	STORE32L(md->md5.lengthLo, md->md5.buf+56);
	STORE32L(md->md5.lengthHi, md->md5.buf+60);
#endif /* HAVE_NATIVE_INT64 */
	hd_md5_compress(md);

/*
	copy output
 */
	for (i = 0; i < 4; i++) {
		val = tls_reg_read32(HR_CRYPTO_SHA1_DIGEST0 + (4*i));
		STORE32L(val, hash+(4*i));
	}
	memset(md, 0x0, sizeof(psDigestContext_t));
	return MD5_HASH_SIZE;
}
/**
 * @brief			This function ends a MD5 operation and produces a Message-Digest.
 *				This function finalizes MD5 algorithm, i.e. ends an MD5 Message-Digest operation, 
 *				writing the Message-Digest in the 16-byte buffer pointed to by hash in according to the information stored in context. 
 *
 * @param[in]		md		MD5 Digest Context. 
 * @param[in]		hash 	the Message-Digest
 *
 * @retval  		16  		success, return the hash size.
 * @retval  		<0   	failed  
 *
 * @note			None
 */
@brief                       This function ends a MD5 operation and produces a Message-Digest.
This function finalizes MD5 algorithm, i.e. ends an MD5 Message-Digest operation,
writing the Message-Digest in the 16-byte buffer pointed to by hash in according to the information stored in context.

@param[in]           md              MD5 Digest Context.
@param[in]           hash    the Message-Digest

@retval              16              success, return the hash size.
@retval              <0      failed

@note                        None
@brief This function ends a MD5 operation and produces a Message - Digest . This function finalizes MD5 algorithm i . e . ends an MD5 Message - Digest operation writing the Message - Digest in the 16 - byte buffer pointed to by hash in according to the information stored in context . @param [ in ] md MD5 Digest Context . @param [ in ] hash the Message - Digest @retval 16 success return the hash size . @retval <0 failed @note None
s32 tls_crypto_md5_final(psDigestContext_t * md, unsigned char *hash)
{
	s32 i;
	u32 val;
#ifndef HAVE_NATIVE_INT64
	u32	n;
#endif
	if (hash == NULL) {
		psTraceCrypto("NULL hash storage passed to psMd5Final\n");
		return PS_ARG_FAIL;
	}
#ifdef HAVE_NATIVE_INT64
	md->md5.length += md->md5.curlen << 3;
#else
	n = (md->md5.lengthLo + (md->md5.curlen << 3)) & 0xFFFFFFFFL;
	if (n < md->md5.lengthLo) {
		md->md5.lengthHi++;
	}
	md->md5.lengthHi += (md->md5.curlen >> 29);
	md->md5.lengthLo = n;
#endif 
	md->md5.buf[md->md5.curlen++] = (unsigned char)0x80;
	if (md->md5.curlen > 56) {
		while (md->md5.curlen < 64) {
			md->md5.buf[md->md5.curlen++] = (unsigned char)0;
		}
		hd_md5_compress(md);
		md->md5.curlen = 0;
	}
	while (md->md5.curlen < 56) {
		md->md5.buf[md->md5.curlen++] = (unsigned char)0;
	}
#ifdef HAVE_NATIVE_INT64
	STORE64L(md->md5.length, md->md5.buf+56);
#else
	STORE32L(md->md5.lengthLo, md->md5.buf+56);
	STORE32L(md->md5.lengthHi, md->md5.buf+60);
#endif 
	hd_md5_compress(md);
	for (i = 0; i < 4; i++) {
		val = tls_reg_read32(HR_CRYPTO_SHA1_DIGEST0 + (4*i));
		STORE32L(val, hash+(4*i));
	}
	memset(md, 0x0, sizeof(psDigestContext_t));
	return MD5_HASH_SIZE;
}
s32 tls_crypto_md5_final ( psDigestContext_t * md , unsigned char * hash ) { s32 i ; u32 val ; #ifndef HAVE_NATIVE_INT64 u32 n ; #endif if ( hash == NULL ) { psTraceCrypto ( " \n " ) ; return PS_ARG_FAIL ; } #ifdef HAVE_NATIVE_INT64 md -> md5 . length += md -> md5 . curlen << 3 ; #else n = ( md -> md5 . lengthLo + ( md -> md5 . curlen << 3 ) ) & 0xFFFFFFFFL ; if ( n < md -> md5 . lengthLo ) { md -> md5 . lengthHi ++ ; } md -> md5 . lengthHi += ( md -> md5 . curlen >> 29 ) ; md -> md5 . lengthLo = n ; #endif md -> md5 . buf [ md -> md5 . curlen ++ ] = ( unsigned char ) 0x80 ; if ( md -> md5 . curlen > 56 ) { while ( md -> md5 . curlen < 64 ) { md -> md5 . buf [ md -> md5 . curlen ++ ] = ( unsigned char ) 0 ; } hd_md5_compress ( md ) ; md -> md5 . curlen = 0 ; } while ( md -> md5 . curlen < 56 ) { md -> md5 . buf [ md -> md5 . curlen ++ ] = ( unsigned char ) 0 ; } #ifdef HAVE_NATIVE_INT64 STORE64L ( md -> md5 . length , md -> md5 . buf + 56 ) ; #else STORE32L ( md -> md5 . lengthLo , md -> md5 . buf + 56 ) ; STORE32L ( md -> md5 . lengthHi , md -> md5 . buf + 60 ) ; #endif hd_md5_compress ( md ) ; for ( i = 0 ; i < 4 ; i ++ ) { val = tls_reg_read32 ( HR_CRYPTO_SHA1_DIGEST0 + ( 4 * i ) ) ; STORE32L ( val , hash + ( 4 * i ) ) ; } memset ( md , 0x0 , sizeof ( psDigestContext_t ) ) ; return MD5_HASH_SIZE ; }
@brief                       This function ends a MD5 operation and produces a Message-Digest.
@brief This function ends a MD5 operation and produces a Message - Digest .
//	psAssert(md != NULL); /*
	increase the length of the message
 */ /* HAVE_NATIVE_INT64 */ /*
	append the '1' bit
 */ /*
	if the length is currently above 56 bytes we append zeros then compress.
	Then we can fall back to padding zeros and length encoding like normal.
 */ /*
	pad upto 56 bytes of zeroes
 */ /*
	store length
 */ /* HAVE_NATIVE_INT64 */ /*
	copy output
 */