FreeBSD/contrib/ntp/libntp/a_md5encrypt.c
/*
 * Calculate the reference id from the address. If it is an IPv4
 * address, use it as is. If it is an IPv6 address, do a md5 on
 * it and use the bottom 4 bytes.
 * The result is in network byte order.
 */
Calculate the reference id from the address. If it is an IPv4
address, use it as is. If it is an IPv6 address, do a md5 on
it and use the bottom 4 bytes.
The result is in network byte order.
Calculate the reference id from the address . If it is an IPv4 address use it as is . If it is an IPv6 address do a md5 on it and use the bottom 4 bytes . The result is in network byte order .
u_int32
addr2refid(sockaddr_u *addr)
{
	u_char		digest[20];
	u_int32		addr_refid;
	EVP_MD_CTX	*ctx;
	u_int		len;
	if (IS_IPV4(addr))
		return (NSRCADR(addr));
	INIT_SSL();
	ctx = EVP_MD_CTX_new();
	EVP_MD_CTX_init(ctx);
#ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW
	EVP_MD_CTX_set_flags(ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
#endif
	if (!EVP_DigestInit_ex(ctx, EVP_md5(), NULL)) {
		msyslog(LOG_ERR,
		    "MD5 init failed");
		EVP_MD_CTX_free(ctx);	
		exit(1);
	}
	EVP_DigestUpdate(ctx, (u_char *)PSOCK_ADDR6(addr),
	    sizeof(struct in6_addr));
	EVP_DigestFinal(ctx, digest, &len);
	EVP_MD_CTX_free(ctx);
	memcpy(&addr_refid, digest, sizeof(addr_refid));
	return (addr_refid);
}
u_int32 addr2refid ( sockaddr_u * addr ) { u_char digest [ 20 ] ; u_int32 addr_refid ; EVP_MD_CTX * ctx ; u_int len ; if ( IS_IPV4 ( addr ) ) return ( NSRCADR ( addr ) ) ; INIT_SSL ( ) ; ctx = EVP_MD_CTX_new ( ) ; EVP_MD_CTX_init ( ctx ) ; #ifdef EVP_MD_CTX_FLAG_NON_FIPS_ALLOW EVP_MD_CTX_set_flags ( ctx , EVP_MD_CTX_FLAG_NON_FIPS_ALLOW ) ; #endif if ( ! EVP_DigestInit_ex ( ctx , EVP_md5 ( ) , NULL ) ) { msyslog ( LOG_ERR , " " ) ; EVP_MD_CTX_free ( ctx ) ; exit ( 1 ) ; } EVP_DigestUpdate ( ctx , ( u_char * ) PSOCK_ADDR6 ( addr ) , sizeof ( struct in6_addr ) ) ; EVP_DigestFinal ( ctx , digest , & len ) ; EVP_MD_CTX_free ( ctx ) ; memcpy ( & addr_refid , digest , sizeof ( addr_refid ) ) ; return ( addr_refid ) ; }
Calculate the reference id from the address.
Calculate the reference id from the address .
/* MD5 is not used as a crypto hash here. */ /* pedantic... but safe */