fi
- for ac_header in openssl/evp.h
+ if test "$ac_cv_lib_crypto_DES_cbc_encrypt" = "yes"; then
+ for ac_header in openssl/evp.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "openssl/evp.h" "ac_cv_header_openssl_evp_h" "$ac_includes_default"
if test "x$ac_cv_header_openssl_evp_h" = xyes; then :
done
+ #
+ # OK, do we have EVP_CIPHER_CTX_new?
+ # If so, we use it to allocate an
+ # EVP_CIPHER_CTX, as EVP_CIPHER_CTX may be
+ # opaque; otherwise, we allocate it ourselves.
+ #
+ for ac_func in EVP_CIPHER_CTX_new
+do :
+ ac_fn_c_check_func "$LINENO" "EVP_CIPHER_CTX_new" "ac_cv_func_EVP_CIPHER_CTX_new"
+if test "x$ac_cv_func_EVP_CIPHER_CTX_new" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_EVP_CIPHER_CTX_NEW 1
+_ACEOF
+
+fi
+done
+
+ fi
fi
AC_CHECK_HEADER(openssl/crypto.h,
[
AC_CHECK_LIB(crypto, DES_cbc_encrypt)
- AC_CHECK_HEADERS(openssl/evp.h)
+ if test "$ac_cv_lib_crypto_DES_cbc_encrypt" = "yes"; then
+ AC_CHECK_HEADERS(openssl/evp.h)
+ #
+ # OK, do we have EVP_CIPHER_CTX_new?
+ # If so, we use it to allocate an
+ # EVP_CIPHER_CTX, as EVP_CIPHER_CTX may be
+ # opaque; otherwise, we allocate it ourselves.
+ #
+ AC_CHECK_FUNCS(EVP_CIPHER_CTX_new)
+ fi
])
fi
int secretlen;
};
+#ifndef HAVE_EVP_CIPHER_CTX_NEW
+/*
+ * Allocate an EVP_CIPHER_CTX.
+ * Used if we have an older version of OpenSSL that doesn't provide
+ * routines to allocate and free them.
+ */
+static EVP_CIPHER_CTX *
+EVP_CIPHER_CTX_new(void)
+{
+ EVP_CIPHER_CTX *ctx;
+
+ ctx = malloc(sizeof (EVP_CIPHER_CTX));
+ if (ctx == NULL)
+ return (NULL);
+ memset(ctx, 0, sizeof(*ctx));
+ return (ctx);
+}
+
+static void
+EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
+{
+ EVP_CIPHER_CTX_cleanup(ctx);
+ free(ctx);
+}
+#endif
+
/*
* this will adjust ndo_packetp and ndo_snapend to new buffer!
*/
struct sa_list *sa;
const u_char *iv;
int len;
- EVP_CIPHER_CTX ctx;
+ EVP_CIPHER_CTX *ctx;
/* initiator arg is any non-zero value */
if(initiator) initiator=1;
if(end <= buf) return 0;
- memset(&ctx, 0, sizeof(ctx));
- if (EVP_CipherInit(&ctx, sa->evp, sa->secret, NULL, 0) < 0)
+ ctx = EVP_CIPHER_CTX_new();
+ if (ctx == NULL)
+ return 0;
+ 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);
+ EVP_CipherInit(ctx, NULL, NULL, iv, 0);
+ EVP_Cipher(ctx, buf, buf, len);
+ EVP_CIPHER_CTX_free(ctx);
ndo->ndo_packetp = buf;
ndo->ndo_snapend = end;
int ivlen = 0;
const u_char *ivoff;
const u_char *p;
- EVP_CIPHER_CTX ctx;
+ EVP_CIPHER_CTX *ctx;
#endif
esp = (const struct newesp *)bp;
ep = ep - sa->authlen;
if (sa->evp) {
- memset(&ctx, 0, sizeof(ctx));
- if (EVP_CipherInit(&ctx, sa->evp, secret, NULL, 0) < 0)
- (*ndo->ndo_warning)(ndo, "espkey init failed");
-
- p = ivoff;
- EVP_CipherInit(&ctx, NULL, NULL, p, 0);
- EVP_Cipher(&ctx, p + ivlen, p + ivlen, ep - (p + ivlen));
- EVP_CIPHER_CTX_cleanup(&ctx);
- advance = ivoff - (const u_char *)esp + ivlen;
+ ctx = EVP_CIPHER_CTX_new();
+ if (ctx != NULL) {
+ if (EVP_CipherInit(ctx, sa->evp, secret, NULL, 0) < 0)
+ (*ndo->ndo_warning)(ndo, "espkey init failed");
+
+ p = ivoff;
+ EVP_CipherInit(ctx, NULL, NULL, p, 0);
+ EVP_Cipher(ctx, p + ivlen, p + ivlen, ep - (p + ivlen));
+ EVP_CIPHER_CTX_free(ctx);
+ advance = ivoff - (const u_char *)esp + ivlen;
+ } else
+ advance = sizeof(struct newesp);
} else
advance = sizeof(struct newesp);