FreeBSD/contrib/ntp/libntp/a_md5encrypt.c
/*
 * MD5authdecrypt - verify MD5 message authenticator
 *
 * Returns one if digest valid, zero if invalid.
 */
verify MD5 message authenticator
Returns one if digest valid, zero if invalid.
verify MD5 message authenticator Returns one if digest valid zero if invalid .
int
MD5authdecrypt(
	int		type,	
	const u_char *	key,	
	u_int32	*	pkt,	
	size_t		length,	
	size_t		size	
	)
{
	u_char	digest[EVP_MAX_MD_SIZE];
	u_int	len;
	EVP_MD_CTX *ctx;
	INIT_SSL();
	ctx = EVP_MD_CTX_new();
	if (!(ctx && EVP_DigestInit(ctx, EVP_get_digestbynid(type)))) {
		msyslog(LOG_ERR,
		    "MAC decrypt: digest init failed");
		EVP_MD_CTX_free(ctx);
		return (0);
	}
	EVP_DigestUpdate(ctx, key, cache_secretsize);
	EVP_DigestUpdate(ctx, (u_char *)pkt, length);
	EVP_DigestFinal(ctx, digest, &len);
	EVP_MD_CTX_free(ctx);
	if (len > MAX_MAC_LEN - 4)
	    len = MAX_MAC_LEN - 4;
	if (size != (size_t)len + 4) {
		msyslog(LOG_ERR,
		    "MAC decrypt: MAC length error");
		return (0);
	}
	return !isc_tsmemcmp(digest, (u_char *)pkt + length + 4, len);
}
int MD5authdecrypt ( int type , const u_char * key , u_int32 * pkt , size_t length , size_t size ) { u_char digest [ EVP_MAX_MD_SIZE ] ; u_int len ; EVP_MD_CTX * ctx ; INIT_SSL ( ) ; ctx = EVP_MD_CTX_new ( ) ; if ( ! ( ctx && EVP_DigestInit ( ctx , EVP_get_digestbynid ( type ) ) ) ) { msyslog ( LOG_ERR , " " ) ; EVP_MD_CTX_free ( ctx ) ; return ( 0 ) ; } EVP_DigestUpdate ( ctx , key , cache_secretsize ) ; EVP_DigestUpdate ( ctx , ( u_char * ) pkt , length ) ; EVP_DigestFinal ( ctx , digest , & len ) ; EVP_MD_CTX_free ( ctx ) ; if ( len > MAX_MAC_LEN - 4 ) len = MAX_MAC_LEN - 4 ; if ( size != ( size_t ) len + 4 ) { msyslog ( LOG_ERR , " " ) ; return ( 0 ) ; } return ! isc_tsmemcmp ( digest , ( u_char * ) pkt + length + 4 , len ) ; }
MD5authdecrypt - verify MD5 message authenticator
 Returns one if digest valid, zero if invalid.
MD5authdecrypt - verify MD5 message authenticator Returns one if digest valid zero if invalid .
/* hash algorithm */ /* key pointer */ /* packet pointer */ /* packet length */ /* MAC size */ /*
	 * Compute digest of key concatenated with packet. Note: the
	 * key type and digest type have been verified when the key
	 * was created.
	 */ /* If the MAC is longer than the MAX then truncate it. */