ClientCollectors/ARODataCollector/external/tcpdump-4.1.1/print-esp.c
int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
				      int initiator,
				      u_char spii[8], u_char spir[8],
				      u_char *buf, u_char *end)
{
	struct sa_list *sa;
	u_char *iv;
	int len;
	EVP_CIPHER_CTX ctx;

	/* initiator arg is any non-zero value */
	if(initiator) initiator=1;
				       
	/* see if we can find the SA, and if so, decode it */
	for (sa = ndo->ndo_sa_list_head; sa != NULL; sa = sa->next) {
		if (sa->spi == 0
		    && initiator == sa->initiator
		    && memcmp(spii, sa->spii, 8) == 0
		    && memcmp(spir, sa->spir, 8) == 0)
			break;
	}

	if(sa == NULL) return 0;
	if(sa->evp == NULL) return 0;

	/*
	 * remove authenticator, and see if we still have something to
	 * work with
	 */
	end = end - sa->authlen;
	iv  = buf;
	buf = buf + sa->ivlen;
	len = end-buf;

	if(end <= buf) return 0;

	memset(&ctx, 0, sizeof(ctx));
	if (EVP_CipherInit(&ctx, sa->evp, sa->secret, NULL, 0) < 0)
		(*ndo->ndo_warning)(ndo, "espkey init failed");
	EVP_CipherInit(&ctx, NULL, NULL, iv, 0);
	EVP_Cipher(&ctx, buf, buf, len);
	EVP_CIPHER_CTX_cleanup(&ctx);

	ndo->ndo_packetp = buf;
	ndo->ndo_snapend = end;

	return 1;
	
}
/*
 * this will adjust ndo_packetp and ndo_snapend to new buffer!
 */
this will adjust ndo_packetp and ndo_snapend to new buffer!
this will adjust ndo_packetp and ndo_snapend to new buffer!
int esp_print_decrypt_buffer_by_ikev2(netdissect_options *ndo,
				      int initiator,
				      u_char spii[8], u_char spir[8],
				      u_char *buf, u_char *end)
{
	struct sa_list *sa;
	u_char *iv;
	int len;
	EVP_CIPHER_CTX ctx;
	if(initiator) initiator=1;
	for (sa = ndo->ndo_sa_list_head; sa != NULL; sa = sa->next) {
		if (sa->spi == 0
		    && initiator == sa->initiator
		    && memcmp(spii, sa->spii, 8) == 0
		    && memcmp(spir, sa->spir, 8) == 0)
			break;
	}
	if(sa == NULL) return 0;
	if(sa->evp == NULL) return 0;
	end = end - sa->authlen;
	iv  = buf;
	buf = buf + sa->ivlen;
	len = end-buf;
	if(end <= buf) return 0;
	memset(&ctx, 0, sizeof(ctx));
	if (EVP_CipherInit(&ctx, sa->evp, sa->secret, NULL, 0) < 0)
		(*ndo->ndo_warning)(ndo, "espkey init failed");
	EVP_CipherInit(&ctx, NULL, NULL, iv, 0);
	EVP_Cipher(&ctx, buf, buf, len);
	EVP_CIPHER_CTX_cleanup(&ctx);
	ndo->ndo_packetp = buf;
	ndo->ndo_snapend = end;
	return 1;
}
int esp_print_decrypt_buffer_by_ikev2 ( netdissect_options * ndo , int initiator , u_char spii [ 8 ] , u_char spir [ 8 ] , u_char * buf , u_char * end ) { struct sa_list * sa ; u_char * iv ; int len ; EVP_CIPHER_CTX ctx ; if ( initiator ) initiator = 1 ; for ( sa = ndo -> ndo_sa_list_head ; sa != NULL ; sa = sa -> next ) { if ( sa -> spi == 0 && initiator == sa -> initiator && memcmp ( spii , sa -> spii , 8 ) == 0 && memcmp ( spir , sa -> spir , 8 ) == 0 ) break ; } if ( sa == NULL ) return 0 ; if ( sa -> evp == NULL ) return 0 ; end = end - sa -> authlen ; iv = buf ; buf = buf + sa -> ivlen ; len = end - buf ; if ( end <= buf ) return 0 ; memset ( & ctx , 0 , sizeof ( ctx ) ) ; if ( EVP_CipherInit ( & ctx , sa -> evp , sa -> secret , NULL , 0 ) < 0 ) ( * ndo -> ndo_warning ) ( ndo , " " ) ; EVP_CipherInit ( & ctx , NULL , NULL , iv , 0 ) ; EVP_Cipher ( & ctx , buf , buf , len ) ; EVP_CIPHER_CTX_cleanup ( & ctx ) ; ndo -> ndo_packetp = buf ; ndo -> ndo_snapend = end ; return 1 ; }
this will adjust ndo_packetp and ndo_snapend to new buffer!
this will adjust ndo_packetp and ndo_snapend to new buffer!
/* initiator arg is any non-zero value */ /* see if we can find the SA, and if so, decode it */ /*
	 * remove authenticator, and see if we still have something to
	 * work with
	 */