FreeBSD/sys/kgssapi/krb5/krb5_mech.c
/*
 * Make a token with the given type and length (the length includes
 * the TOK_ID), initialising the token header appropriately. Return a
 * pointer to the TOK_ID of the token.  A new mbuf is allocated with
 * the framing header plus hlen bytes of space.
 *
 * Format is as follows:
 *
 *	0x60			[APPLICATION 0] SEQUENCE
 *	DER encoded length	length of oid + type + inner token length
 *	0x06 NN <oid data>	OID of mechanism type
 *	TT TT			TOK_ID
 *	<inner token>		data for inner token
 *	
 * 1:		der encoded length
 */
Make a token with the given type and length (the length includes
the TOK_ID), initialising the token header appropriately. Return a
pointer to the TOK_ID of the token.  A new mbuf is allocated with
the framing header plus hlen bytes of space.

Format is as follows.

0x60                    [APPLICATION 0] SEQUENCE
DER encoded length      length of oid + type + inner token length
0x06 NN       OID of mechanism type
TT TT                   TOK_ID
           data for inner token

der encoded length
Make a token with the given type and length ( the length includes the TOK_ID ) initialising the token header appropriately . Return a pointer to the TOK_ID of the token . A new mbuf is allocated with the framing header plus hlen bytes of space . Format is as follows . 0x60 [ APPLICATION 0 ] SEQUENCE DER encoded length length of oid + type + inner token length 0x06 NN OID of mechanism type TT TT TOK_ID data for inner token der encoded length
static void *
krb5_make_token(char tok_id[2], size_t hlen, size_t len, struct mbuf **mp)
{
	size_t inside_len, len_len, tlen;
	gss_OID oid = &krb5_mech_oid;
	struct mbuf *m;
	uint8_t *p;
	inside_len = 2 + oid->length + len;
	if (inside_len < 128)
		len_len = 1;
	else if (inside_len < 0x100)
		len_len = 2;
	else if (inside_len < 0x10000)
		len_len = 3;
	else if (inside_len < 0x1000000)
		len_len = 4;
	else
		len_len = 5;
	tlen = 1 + len_len + 2 + oid->length + hlen;
	KASSERT(tlen <= MLEN, ("token head too large"));
	MGET(m, M_WAITOK, MT_DATA);
	M_ALIGN(m, tlen);
	m->m_len = tlen;
	p = (uint8_t *) m->m_data;
	*p++ = 0x60;
	switch (len_len) {
	case 1:
		*p++ = inside_len;
		break;
	case 2:
		*p++ = 0x81;
		*p++ = inside_len;
		break;
	case 3:
		*p++ = 0x82;
		*p++ = inside_len >> 8;
		*p++ = inside_len;
		break;
	case 4:
		*p++ = 0x83;
		*p++ = inside_len >> 16;
		*p++ = inside_len >> 8;
		*p++ = inside_len;
		break;
	case 5:
		*p++ = 0x84;
		*p++ = inside_len >> 24;
		*p++ = inside_len >> 16;
		*p++ = inside_len >> 8;
		*p++ = inside_len;
		break;
	}
	*p++ = 0x06;
	*p++ = oid->length;
	bcopy(oid->elements, p, oid->length);
	p += oid->length;
	p[0] = tok_id[0];
	p[1] = tok_id[1];
	*mp = m;
	return (p);
}
static void * krb5_make_token ( char tok_id [ 2 ] , size_t hlen , size_t len , struct mbuf * * mp ) { size_t inside_len , len_len , tlen ; gss_OID oid = & krb5_mech_oid ; struct mbuf * m ; uint8_t * p ; inside_len = 2 + oid -> length + len ; if ( inside_len < 128 ) len_len = 1 ; else if ( inside_len < 0x100 ) len_len = 2 ; else if ( inside_len < 0x10000 ) len_len = 3 ; else if ( inside_len < 0x1000000 ) len_len = 4 ; else len_len = 5 ; tlen = 1 + len_len + 2 + oid -> length + hlen ; KASSERT ( tlen <= MLEN , ( " " ) ) ; MGET ( m , M_WAITOK , MT_DATA ) ; M_ALIGN ( m , tlen ) ; m -> m_len = tlen ; p = ( uint8_t * ) m -> m_data ; * p ++ = 0x60 ; switch ( len_len ) { case 1 : * p ++ = inside_len ; break ; case 2 : * p ++ = 0x81 ; * p ++ = inside_len ; break ; case 3 : * p ++ = 0x82 ; * p ++ = inside_len >> 8 ; * p ++ = inside_len ; break ; case 4 : * p ++ = 0x83 ; * p ++ = inside_len >> 16 ; * p ++ = inside_len >> 8 ; * p ++ = inside_len ; break ; case 5 : * p ++ = 0x84 ; * p ++ = inside_len >> 24 ; * p ++ = inside_len >> 16 ; * p ++ = inside_len >> 8 ; * p ++ = inside_len ; break ; } * p ++ = 0x06 ; * p ++ = oid -> length ; bcopy ( oid -> elements , p , oid -> length ) ; p += oid -> length ; p [ 0 ] = tok_id [ 0 ] ; p [ 1 ] = tok_id [ 1 ] ; * mp = m ; return ( p ) ; }
Make a token with the given type and length (the length includes
 the TOK_ID), initialising the token header appropriately.
Make a token with the given type and length ( the length includes the TOK_ID ) initialising the token header appropriately .