+ /*
+ * Attempt to allocate the output buffer.
+ */
+ output_buffer = (u_char *)malloc(buffer_size);
+ if (output_buffer == NULL) {
+ free(input_buffer);
+ EVP_CIPHER_CTX_free(ctx);
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "esp_print: can't allocate memory for decryption buffer");
+ }
+
+ if (!EVP_Cipher(ctx, output_buffer, input_buffer, ctlen)) {
+ free(input_buffer);
+ (*ndo->ndo_warning)(ndo, "EVP_Cipher failed");
+ return;
+ }
+ free(input_buffer);
+ EVP_CIPHER_CTX_free(ctx);
+
+ /*
+ * Pointer to the plaintext.
+ */
+ pt = output_buffer;
+
+ /*
+ * Length of the plaintext, which is the same as the length
+ * of the ciphertext.
+ */
+ ptlen = ctlen;
+
+ /*
+ * Switch to the output buffer for dissection, and
+ * save it on the buffer stack so it can be freed.
+ */
+ if (!nd_push_buffer(ndo, output_buffer, pt, pt + ctlen)) {
+ free(output_buffer);
+ (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+ "esp_print: can't push buffer on buffer stack");
+ }
+ ep = pt + ptlen;
+
+ /*
+ * Sanity check for pad length; if it, plus 2 for the pad
+ * length and next header fields, is bigger than the ciphertext
+ * length (which is also the plaintext length), it's too big.
+ *
+ * XXX - the check can fail if the packet is corrupt *or* if
+ * it was not decrypted with the correct key, so that the
+ * "plaintext" is not what was being sent.
+ */
+ padlen = GET_U_1(ep - 2);
+ if (padlen + 2 > ptlen) {
+ nd_print_trunc(ndo);
+ return;
+ }
+
+ /* Get the next header */
+ nh = GET_U_1(ep - 1);
+
+ ND_PRINT(": ");
+
+ /* Now dissect the plaintext. */
+ ip_print_demux(ndo, pt, ptlen - (padlen + 2), ver, fragmented,
+ ttl_hl, nh, bp2);
+
+ /* Pop the buffer, freeing it. */
+ nd_pop_buffer(ndo);
+#endif