fixes build with openssl 1.1

Sat, 04 Feb 2017 12:41:11 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 04 Feb 2017 12:41:11 +0100
changeset 260
26f5f817429e
parent 259
6c8d5f8a1d6f
child 261
f60d742a62a0

fixes build with openssl 1.1

libidav/crypto.c file | annotate | diff | comparison | revisions
libidav/crypto.h file | annotate | diff | comparison | revisions
--- a/libidav/crypto.c	Fri Dec 16 17:16:16 2016 +0100
+++ b/libidav/crypto.c	Sat Feb 04 12:41:11 2017 +0100
@@ -47,18 +47,19 @@
 }
 
 void aes_decrypter_init(AESDecrypter *dec) {
-    EVP_CIPHER_CTX_init(&dec->ctx);
+    //EVP_CIPHER_CTX_init(&dec->ctx);
+    dec->ctx = EVP_CIPHER_CTX_new();
     dec->init = 1;
     if(dec->key->type == DAV_KEY_AES128) {
         EVP_DecryptInit_ex(
-                &dec->ctx,
+                dec->ctx,
                 EVP_aes_128_cbc(),
                 NULL,
                 dec->key->data,
                 dec->ivtmp);
     } else if(dec->key->type == DAV_KEY_AES256) {
         EVP_DecryptInit_ex(
-                &dec->ctx,
+                dec->ctx,
                 EVP_aes_256_cbc(),
                 NULL,
                 dec->key->data,
@@ -89,7 +90,7 @@
     
     int outlen = len + 16;
     unsigned char *out = malloc(outlen);
-    EVP_DecryptUpdate(&dec->ctx, out, &len, buf, len);
+    EVP_DecryptUpdate(dec->ctx, out, &len, buf, len);
     ssize_t wlen = dec->write(out, 1, len, dec->stream);
     SHA256_Update(&dec->sha256, out, wlen);
     free(out);
@@ -100,11 +101,12 @@
     if(dec->init) {
         void *out = malloc(128);
         int len = 0;
-        EVP_DecryptFinal_ex(&dec->ctx, out, &len);
+        EVP_DecryptFinal_ex(dec->ctx, out, &len);
         dec->write(out, 1, len, dec->stream);
         SHA256_Update(&dec->sha256, out, len);
         free(out);
-        EVP_CIPHER_CTX_cleanup(&dec->ctx);
+        //EVP_CIPHER_CTX_cleanup(&dec->ctx);
+        EVP_CIPHER_CTX_free(dec->ctx);
     }
 }
 
@@ -131,11 +133,12 @@
     enc->iv = iv;
     enc->ivlen = 16;
     
-    EVP_CIPHER_CTX_init(&enc->ctx);
+    //EVP_CIPHER_CTX_init(&enc->ctx);
+    enc->ctx = EVP_CIPHER_CTX_new();
     if(key->type == DAV_KEY_AES128) {
-        EVP_EncryptInit_ex(&enc->ctx, EVP_aes_128_cbc(), NULL, key->data, enc->iv);
+        EVP_EncryptInit_ex(enc->ctx, EVP_aes_128_cbc(), NULL, key->data, enc->iv);
     } else if(key->type == DAV_KEY_AES256) {
-        EVP_EncryptInit_ex(&enc->ctx, EVP_aes_256_cbc(), NULL, key->data, enc->iv);
+        EVP_EncryptInit_ex(enc->ctx, EVP_aes_256_cbc(), NULL, key->data, enc->iv);
     } else {
         fprintf(stderr, "unknown key type\n");
         exit(-1);
@@ -177,11 +180,11 @@
         if(enc->iv) {
             memcpy(out, enc->iv, ivl);
         }
-        EVP_EncryptUpdate(&enc->ctx, out + ivl, &outlen, in, in_len);
+        EVP_EncryptUpdate(enc->ctx, out + ivl, &outlen, in, in_len);
         free(in);
     } else {
         out = malloc(16);
-        EVP_EncryptFinal_ex(&enc->ctx, out, &outlen);
+        EVP_EncryptFinal_ex(enc->ctx, out, &outlen);
         enc->end = 1;
         free(in);
     }
@@ -205,7 +208,8 @@
     if(enc->iv) {
         free(enc->iv);
     }
-    EVP_CIPHER_CTX_cleanup(&enc->ctx);
+    //EVP_CIPHER_CTX_cleanup(&enc->ctx);
+    EVP_CIPHER_CTX_free(enc->ctx);
     free(enc);
 }
 
@@ -216,24 +220,26 @@
         return NULL;
     }
     
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
+    //EVP_CIPHER_CTX ctx;
+    //EVP_CIPHER_CTX_init(&ctx);
+    EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
     if(key->type == DAV_KEY_AES128) {
         EVP_EncryptInit_ex(
-                &ctx,
+                ctx,
                 EVP_aes_128_cbc(),
                 NULL,
                 (unsigned char*)key->data,
                 iv);
     } else if(key->type == DAV_KEY_AES256) {
         EVP_EncryptInit_ex(
-                &ctx,
+                ctx,
                 EVP_aes_256_cbc(),
                 NULL,
                 (unsigned char*)key->data,
                 iv);
     } else {
-        EVP_CIPHER_CTX_cleanup(&ctx);
+        //EVP_CIPHER_CTX_cleanup(&ctx);
+        EVP_CIPHER_CTX_free(ctx);
         return NULL;
     }
     
@@ -243,13 +249,14 @@
     memcpy(buf, iv, 16);
     
     int l = buflen - 16;
-    EVP_EncryptUpdate(&ctx, buf + 16, &l, (unsigned char*)in, len);
+    EVP_EncryptUpdate(ctx, buf + 16, &l, (unsigned char*)in, len);
     
     int f = 0;
-    EVP_EncryptFinal_ex(&ctx, buf + 16 + l, &f);
+    EVP_EncryptFinal_ex(ctx, buf + 16 + l, &f);
     char *out = util_base64encode((char*)buf, 16 + l + f);
     free(buf);
-    EVP_CIPHER_CTX_cleanup(&ctx);
+    EVP_CIPHER_CTX_free(ctx);
+    //EVP_CIPHER_CTX_cleanup(&ctx);
     
     return out;
 }
@@ -258,24 +265,26 @@
     int len;
     unsigned char *buf = (unsigned char*)util_base64decode_len(in, &len);
     
-    EVP_CIPHER_CTX ctx;
-    EVP_CIPHER_CTX_init(&ctx);
+    //EVP_CIPHER_CTX ctx;
+    //EVP_CIPHER_CTX_init(&ctx);
+    EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
     if(key->type == DAV_KEY_AES128) {
         EVP_DecryptInit_ex(
-                &ctx,
+                ctx,
                 EVP_aes_128_cbc(),
                 NULL,
                 key->data,
                 buf);
     } else if(key->type == DAV_KEY_AES256) {
         EVP_DecryptInit_ex(
-                &ctx,
+                ctx,
                 EVP_aes_256_cbc(),
                 NULL,
                 key->data,
                 buf);
     } else {
-        EVP_CIPHER_CTX_cleanup(&ctx);
+        //EVP_CIPHER_CTX_cleanup(&ctx);
+        EVP_CIPHER_CTX_free(ctx);
         return NULL;
     }
     
@@ -285,11 +294,12 @@
     int inlen = len - 16;
     int f = 0; 
     
-    EVP_DecryptUpdate(&ctx, out, &outlen, in_buf, inlen);
-    EVP_DecryptFinal_ex(&ctx, out + outlen, &f);
+    EVP_DecryptUpdate(ctx, out, &outlen, in_buf, inlen);
+    EVP_DecryptFinal_ex(ctx, out + outlen, &f);
     out[outlen + f] = '\0';
     free(buf);
-    EVP_CIPHER_CTX_cleanup(&ctx);
+    //EVP_CIPHER_CTX_cleanup(&ctx);
+    EVP_CIPHER_CTX_free(ctx);
     
     *length = outlen + f;
     return (char*)out;
--- a/libidav/crypto.h	Fri Dec 16 17:16:16 2016 +0100
+++ b/libidav/crypto.h	Sat Feb 04 12:41:11 2017 +0100
@@ -47,7 +47,7 @@
 #endif
 
 typedef struct {
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx;
     SHA256_CTX     sha256;
     void           *stream;
     dav_write_func write;
@@ -58,7 +58,7 @@
 } AESDecrypter;
 
 typedef struct {
-    EVP_CIPHER_CTX ctx;
+    EVP_CIPHER_CTX *ctx;
     SHA256_CTX     sha256;
     void           *iv;
     size_t         ivlen;

mercurial