FreeBSD/contrib/ntp/ntpd/ntp_crypto.c
/*
 * crypto_send - construct extension field from value components
 *
 * The value and signature fields are zero-padded to a word boundary.
 * Note: it is not polite to send a nonempty signature with zero
 * timestamp or a nonzero timestamp with an empty signature, but those
 * rules are not enforced here.
 *
 * XXX This code won't work on a box with 16-bit ints.
 */
construct extension field from value components
The value and signature fields are zero-padded to a word boundary.
Note: it is not polite to send a nonempty signature with zero
timestamp or a nonzero timestamp with an empty signature, but those
rules are not enforced here.

XXX This code won't work on a box with 16-bit ints.
construct extension field from value components The value and signature fields are zero - padded to a word boundary . Note : it is not polite to send a nonempty signature with zero timestamp or a nonzero timestamp with an empty signature but those rules are not enforced here . XXX This code won ' t work on a box with 16 - bit ints .
int
crypto_send(
	struct exten *ep,	
	struct value *vp,	
	int	start		
	)
{
	u_int	len, vallen, siglen, opcode;
	u_int	i, j;
	len = 16;				
	vallen = ntohl(vp->vallen);
	INSIST(vallen <= MAX_VALLEN);
	len += ((vallen + 3) / 4 + 1) * 4; 
	siglen = ntohl(vp->siglen);
	len += ((siglen + 3) / 4 + 1) * 4; 
	if (start + len > sizeof(struct pkt) - MAX_MAC_LEN)
		return (0);
	ep->tstamp = vp->tstamp;
	ep->fstamp = vp->fstamp;
	ep->vallen = vp->vallen;
	i = 0;
	if (vallen > 0 && vp->ptr != NULL) {
		j = vallen / 4;
		if (j * 4 < vallen)
			ep->pkt[i + j++] = 0;
		memcpy(&ep->pkt[i], vp->ptr, vallen);
		i += j;
	}
	ep->pkt[i++] = vp->siglen;
	if (siglen > 0 && vp->sig != NULL) {
		j = siglen / 4;
		if (j * 4 < siglen)
			ep->pkt[i + j++] = 0;
		memcpy(&ep->pkt[i], vp->sig, siglen);
	}
	opcode = ntohl(ep->opcode);
	ep->opcode = htonl((opcode & 0xffff0000) | len); 
	ENSURE(len <= MAX_VALLEN);
	return (len);
}
int crypto_send ( struct exten * ep , struct value * vp , int start ) { u_int len , vallen , siglen , opcode ; u_int i , j ; len = 16 ; vallen = ntohl ( vp -> vallen ) ; INSIST ( vallen <= MAX_VALLEN ) ; len += ( ( vallen + 3 ) / 4 + 1 ) * 4 ; siglen = ntohl ( vp -> siglen ) ; len += ( ( siglen + 3 ) / 4 + 1 ) * 4 ; if ( start + len > sizeof ( struct pkt ) - MAX_MAC_LEN ) return ( 0 ) ; ep -> tstamp = vp -> tstamp ; ep -> fstamp = vp -> fstamp ; ep -> vallen = vp -> vallen ; i = 0 ; if ( vallen > 0 && vp -> ptr != NULL ) { j = vallen / 4 ; if ( j * 4 < vallen ) ep -> pkt [ i + j ++ ] = 0 ; memcpy ( & ep -> pkt [ i ] , vp -> ptr , vallen ) ; i += j ; } ep -> pkt [ i ++ ] = vp -> siglen ; if ( siglen > 0 && vp -> sig != NULL ) { j = siglen / 4 ; if ( j * 4 < siglen ) ep -> pkt [ i + j ++ ] = 0 ; memcpy ( & ep -> pkt [ i ] , vp -> sig , siglen ) ; } opcode = ntohl ( ep -> opcode ) ; ep -> opcode = htonl ( ( opcode & 0xffff0000 ) | len ) ; ENSURE ( len <= MAX_VALLEN ) ; return ( len ) ; }
crypto_send - construct extension field from value components
 The value and signature fields are zero-padded to a word boundary.
crypto_send - construct extension field from value components The value and signature fields are zero - padded to a word boundary .
/* extension field pointer */ /* value pointer */ /* buffer offset */ /*
	 * Calculate extension field length and check for buffer
	 * overflow. Leave room for the MAC.
	 */ /* XXX Document! */ /*
	 * Copy timestamps.
	 */ /*
	 * Copy value. If the data field is empty or zero length,
	 * encode an empty value with length zero.
	 */ /*
	 * Copy signature. If the signature field is empty or zero
	 * length, encode an empty signature with length zero.
	 */ /* i += j; */ /* We don't use i after this */