aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/openssl/openssl_crypter.c
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2008-04-30 14:02:25 +0000
committerMartin Willi <martin@strongswan.org>2008-04-30 14:02:25 +0000
commitf5475fa440db647c524e04bead3f4599653499a8 (patch)
tree1707c193d078d6083c9c97eadd33f774b8e2ed74 /src/libstrongswan/plugins/openssl/openssl_crypter.c
parentd691080cfc4e5f9c0b955a1d7d53ad20c1be5a7a (diff)
downloadstrongswan-f5475fa440db647c524e04bead3f4599653499a8.tar.bz2
strongswan-f5475fa440db647c524e04bead3f4599653499a8.tar.xz
crypter_t api supports in-place encryption using NULL as output parameter
Diffstat (limited to 'src/libstrongswan/plugins/openssl/openssl_crypter.c')
-rw-r--r--src/libstrongswan/plugins/openssl/openssl_crypter.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libstrongswan/plugins/openssl/openssl_crypter.c b/src/libstrongswan/plugins/openssl/openssl_crypter.c
index 8cbeac5d4..8b9b37904 100644
--- a/src/libstrongswan/plugins/openssl/openssl_crypter.c
+++ b/src/libstrongswan/plugins/openssl/openssl_crypter.c
@@ -116,13 +116,20 @@ static void crypt(private_openssl_crypter_t *this, chunk_t data,
chunk_t iv, chunk_t *dst, int enc)
{
int len;
+ u_char *out;
+
+ out = data.ptr;
+ if (dst)
+ {
+ *dst = chunk_alloc(data.len);
+ out = dst->ptr;
+ }
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
EVP_CipherInit_ex(&ctx, this->cipher, NULL, this->key.ptr, iv.ptr, enc);
EVP_CIPHER_CTX_set_padding(&ctx, 0); /* disable padding */
- *dst = chunk_alloc(data.len);
- EVP_CipherUpdate(&ctx, dst->ptr, &len, data.ptr, data.len);
- EVP_CipherFinal_ex(&ctx, dst->ptr, &len); /* since padding is disabled this does nothing */
+ EVP_CipherUpdate(&ctx, out, &len, data.ptr, data.len);
+ EVP_CipherFinal_ex(&ctx, out, &len); /* since padding is disabled this does nothing */
EVP_CIPHER_CTX_cleanup(&ctx);
}