FreeBSD/contrib/ntp/ntpd/ntp_leapsec.c
/* given a reader and a reader arg, calculate and validate the the hash
 * signature of a NIST leap second file.
 */
given a reader and a reader arg, calculate and validate the the hash
signature of a NIST leap second file.
given a reader and a reader arg calculate and validate the the hash signature of a NIST leap second file .
int
leapsec_validate(
	leapsec_reader func,
	void *         farg)
{
	isc_sha1_t     mdctx;
	sha1_digest    rdig, ldig; 
	char           line[50];
	int            hlseen = -1;
	isc_sha1_init(&mdctx);
	while (get_line(func, farg, line, sizeof(line))) {
		if (!strncmp(line, "#h", 2))
			hlseen = do_leap_hash(&rdig, line+2);
		else if (!strncmp(line, "#@", 2))
			do_hash_data(&mdctx, line+2);
		else if (!strncmp(line, "#$", 2))
			do_hash_data(&mdctx, line+2);
		else if (isdigit((unsigned char)line[0]))
			do_hash_data(&mdctx, line);
	}
	isc_sha1_final(&mdctx, ldig.hv);
	isc_sha1_invalidate(&mdctx);
	if (0 > hlseen)
		return LSVALID_NOHASH;
	if (0 == hlseen)
		return LSVALID_BADFORMAT;
	if (0 != memcmp(&rdig, &ldig, sizeof(sha1_digest)))
		return LSVALID_BADHASH;
	return LSVALID_GOODHASH;
}
int leapsec_validate ( leapsec_reader func , void * farg ) { isc_sha1_t mdctx ; sha1_digest rdig , ldig ; char line [ 50 ] ; int hlseen = -1 ; isc_sha1_init ( & mdctx ) ; while ( get_line ( func , farg , line , sizeof ( line ) ) ) { if ( ! strncmp ( line , " " , 2 ) ) hlseen = do_leap_hash ( & rdig , line + 2 ) ; else if ( ! strncmp ( line , " " , 2 ) ) do_hash_data ( & mdctx , line + 2 ) ; else if ( ! strncmp ( line , " " , 2 ) ) do_hash_data ( & mdctx , line + 2 ) ; else if ( isdigit ( ( unsigned char ) line [ 0 ] ) ) do_hash_data ( & mdctx , line ) ; } isc_sha1_final ( & mdctx , ldig . hv ) ; isc_sha1_invalidate ( & mdctx ) ; if ( 0 > hlseen ) return LSVALID_NOHASH ; if ( 0 == hlseen ) return LSVALID_BADFORMAT ; if ( 0 != memcmp ( & rdig , & ldig , sizeof ( sha1_digest ) ) ) return LSVALID_BADHASH ; return LSVALID_GOODHASH ; }
given a reader and a reader arg, calculate and validate the the hash
 signature of a NIST leap second file.
given a reader and a reader arg calculate and validate the the hash signature of a NIST leap second file .
/* remote / local digests */