Remove /* foo.c */ comments
[oweals/openssl.git] / crypto / evp / bio_enc.c
index 4409a91242b473eefd8b27e49d18c06d79cb7049..9754031e2bda5ce30485dfe546d8c01ebeeea95f 100644 (file)
@@ -1,4 +1,3 @@
-/* crypto/evp/bio_enc.c */
 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  * All rights reserved.
  *
@@ -58,7 +57,7 @@
 
 #include <stdio.h>
 #include <errno.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/buffer.h>
 #include <openssl/evp.h>
 
@@ -83,7 +82,7 @@ typedef struct enc_struct {
     int cont;                   /* <= 0 when finished */
     int finished;
     int ok;                     /* bad decrypt */
-    EVP_CIPHER_CTX cipher;
+    EVP_CIPHER_CTX *cipher;
     /*
      * buf is larger than ENC_BLOCK_SIZE because EVP_DecryptUpdate can return
      * up to a block more data than is presented to it
@@ -112,21 +111,21 @@ static int enc_new(BIO *bi)
 {
     BIO_ENC_CTX *ctx;
 
-    ctx = OPENSSL_malloc(sizeof(BIO_ENC_CTX));
+    ctx = OPENSSL_zalloc(sizeof(*ctx));
     if (ctx == NULL)
-        return (0);
-    EVP_CIPHER_CTX_init(&ctx->cipher);
+        return 0;
 
-    ctx->buf_len = 0;
-    ctx->buf_off = 0;
+    ctx->cipher = EVP_CIPHER_CTX_new();
+    if (ctx->cipher == NULL) {
+        OPENSSL_free(ctx);
+        return 0;
+    }
     ctx->cont = 1;
-    ctx->finished = 0;
     ctx->ok = 1;
-
     bi->init = 0;
     bi->ptr = (char *)ctx;
     bi->flags = 0;
-    return (1);
+    return 1;
 }
 
 static int enc_free(BIO *a)
@@ -136,9 +135,8 @@ static int enc_free(BIO *a)
     if (a == NULL)
         return (0);
     b = (BIO_ENC_CTX *)a->ptr;
-    EVP_CIPHER_CTX_cleanup(&(b->cipher));
-    OPENSSL_cleanse(a->ptr, sizeof(BIO_ENC_CTX));
-    OPENSSL_free(a->ptr);
+    EVP_CIPHER_CTX_free(b->cipher);
+    OPENSSL_clear_free(a->ptr, sizeof(BIO_ENC_CTX));
     a->ptr = NULL;
     a->init = 0;
     a->flags = 0;
@@ -191,7 +189,7 @@ static int enc_read(BIO *b, char *out, int outl)
             /* Should be continue next time we are called? */
             if (!BIO_should_retry(b->next_bio)) {
                 ctx->cont = i;
-                i = EVP_CipherFinal_ex(&(ctx->cipher),
+                i = EVP_CipherFinal_ex(ctx->cipher,
                                        (unsigned char *)ctx->buf,
                                        &(ctx->buf_len));
                 ctx->ok = i;
@@ -201,7 +199,7 @@ static int enc_read(BIO *b, char *out, int outl)
                 break;
             }
         } else {
-            if (!EVP_CipherUpdate(&(ctx->cipher),
+            if (!EVP_CipherUpdate(ctx->cipher,
                                   (unsigned char *)ctx->buf, &ctx->buf_len,
                                   (unsigned char *)&(ctx->buf[BUF_OFFSET]),
                                   i)) {
@@ -264,7 +262,7 @@ static int enc_write(BIO *b, const char *in, int inl)
     ctx->buf_off = 0;
     while (inl > 0) {
         n = (inl > ENC_BLOCK_SIZE) ? ENC_BLOCK_SIZE : inl;
-        if (!EVP_CipherUpdate(&(ctx->cipher),
+        if (!EVP_CipherUpdate(ctx->cipher,
                               (unsigned char *)ctx->buf, &ctx->buf_len,
                               (unsigned char *)in, n)) {
             BIO_clear_retry_flags(b);
@@ -305,8 +303,8 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
     case BIO_CTRL_RESET:
         ctx->ok = 1;
         ctx->finished = 0;
-        if (!EVP_CipherInit_ex(&(ctx->cipher), NULL, NULL, NULL, NULL,
-                               ctx->cipher.encrypt))
+        if (!EVP_CipherInit_ex(ctx->cipher, NULL, NULL, NULL, NULL,
+                               EVP_CIPHER_CTX_encrypting(ctx->cipher)))
             return 0;
         ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
         break;
@@ -338,7 +336,7 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
         if (!ctx->finished) {
             ctx->finished = 1;
             ctx->buf_off = 0;
-            ret = EVP_CipherFinal_ex(&(ctx->cipher),
+            ret = EVP_CipherFinal_ex(ctx->cipher,
                                      (unsigned char *)ctx->buf,
                                      &(ctx->buf_len));
             ctx->ok = (int)ret;
@@ -362,14 +360,16 @@ static long enc_ctrl(BIO *b, int cmd, long num, void *ptr)
         break;
     case BIO_C_GET_CIPHER_CTX:
         c_ctx = (EVP_CIPHER_CTX **)ptr;
-        (*c_ctx) = &(ctx->cipher);
+        *c_ctx = ctx->cipher;
         b->init = 1;
         break;
     case BIO_CTRL_DUP:
         dbio = (BIO *)ptr;
         dctx = (BIO_ENC_CTX *)dbio->ptr;
-        EVP_CIPHER_CTX_init(&dctx->cipher);
-        ret = EVP_CIPHER_CTX_copy(&dctx->cipher, &ctx->cipher);
+        dctx->cipher = EVP_CIPHER_CTX_new();
+        if (dctx->cipher == NULL)
+            return 0;
+        ret = EVP_CIPHER_CTX_copy(dctx->cipher, ctx->cipher);
         if (ret)
             dbio->init = 1;
         break;
@@ -429,7 +429,7 @@ int BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k,
 
     b->init = 1;
     ctx = (BIO_ENC_CTX *)b->ptr;
-    if (!EVP_CipherInit_ex(&(ctx->cipher), c, NULL, k, i, e))
+    if (!EVP_CipherInit_ex(ctx->cipher, c, NULL, k, i, e))
         return 0;
 
     if (b->callback != NULL)