summaryrefslogtreecommitdiff
path: root/src/openssl/kw_des.c
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2016-07-27 15:33:38 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2016-07-27 15:39:05 +0900
commitd4d35351fd63a7051a7cbef2002cb0c641925ec3 (patch)
treed390d823f40a886547b932f9bd9239fe81ef6056 /src/openssl/kw_des.c
parentcaccc67c33486a1d1b29f227071851961b29a722 (diff)
downloadxmlsec1-d4d35351fd63a7051a7cbef2002cb0c641925ec3.tar.gz
xmlsec1-d4d35351fd63a7051a7cbef2002cb0c641925ec3.tar.bz2
xmlsec1-d4d35351fd63a7051a7cbef2002cb0c641925ec3.zip
Imported Upstream version 1.2.22upstream/1.2.22upstream
Change-Id: I4d17734839f021e46aef7a30483ac17e8c85fb1d Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
Diffstat (limited to 'src/openssl/kw_des.c')
-rw-r--r--src/openssl/kw_des.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/openssl/kw_des.c b/src/openssl/kw_des.c
index 9d55e107..c9642579 100644
--- a/src/openssl/kw_des.c
+++ b/src/openssl/kw_des.c
@@ -7,7 +7,7 @@
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
- * Copyright (C) 2002-2010 Aleksey Sanin <aleksey@aleksey.com>
+ * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
*/
#ifndef XMLSEC_NO_DES
#include "globals.h"
@@ -505,7 +505,7 @@ xmlSecOpenSSLKWDes3Encrypt(const xmlSecByte *key, xmlSecSize keySize,
const xmlSecByte *in, xmlSecSize inSize,
xmlSecByte *out, xmlSecSize outSize,
int enc) {
- EVP_CIPHER_CTX cipherCtx;
+ EVP_CIPHER_CTX * cipherCtx;
int updateLen;
int finalLen;
int ret;
@@ -519,42 +519,55 @@ xmlSecOpenSSLKWDes3Encrypt(const xmlSecByte *key, xmlSecSize keySize,
xmlSecAssert2(out != NULL, -1);
xmlSecAssert2(outSize >= inSize, -1);
- EVP_CIPHER_CTX_init(&cipherCtx);
- ret = EVP_CipherInit(&cipherCtx, EVP_des_ede3_cbc(), key, iv, enc);
+ cipherCtx = EVP_CIPHER_CTX_new();
+ if(cipherCtx == NULL) {
+ xmlSecError(XMLSEC_ERRORS_HERE,
+ NULL,
+ "EVP_CIPHER_CTX_new",
+ XMLSEC_ERRORS_R_CRYPTO_FAILED,
+ XMLSEC_ERRORS_NO_MESSAGE);
+ return(-1);
+ }
+
+ ret = EVP_CipherInit(cipherCtx, EVP_des_ede3_cbc(), key, iv, enc);
if(ret != 1) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"EVP_CipherInit",
XMLSEC_ERRORS_R_CRYPTO_FAILED,
XMLSEC_ERRORS_NO_MESSAGE);
+ EVP_CIPHER_CTX_free(cipherCtx);
return(-1);
}
-#ifndef XMLSEC_OPENSSL_096
- EVP_CIPHER_CTX_set_padding(&cipherCtx, 0);
-#endif /* XMLSEC_OPENSSL_096 */
+ EVP_CIPHER_CTX_set_padding(cipherCtx, 0);
- ret = EVP_CipherUpdate(&cipherCtx, out, &updateLen, in, inSize);
+ ret = EVP_CipherUpdate(cipherCtx, out, &updateLen, in, inSize);
if(ret != 1) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"EVP_CipherUpdate",
XMLSEC_ERRORS_R_CRYPTO_FAILED,
XMLSEC_ERRORS_NO_MESSAGE);
+ EVP_CIPHER_CTX_free(cipherCtx);
return(-1);
}
- ret = EVP_CipherFinal(&cipherCtx, out + updateLen, &finalLen);
+ ret = EVP_CipherFinal(cipherCtx, out + updateLen, &finalLen);
if(ret != 1) {
xmlSecError(XMLSEC_ERRORS_HERE,
NULL,
"EVP_CipherFinal",
XMLSEC_ERRORS_R_CRYPTO_FAILED,
XMLSEC_ERRORS_NO_MESSAGE);
+ EVP_CIPHER_CTX_free(cipherCtx);
return(-1);
}
- EVP_CIPHER_CTX_cleanup(&cipherCtx);
+ /* cleanup */
+ EVP_CIPHER_CTX_free(cipherCtx);
+
+ /* done */
return(updateLen + finalLen);
}