remove some more useless code. The mingw target can now be built
[openssl.git] / crypto / pkcs7 / bio_ber.c
index e4b9db03cf7368066734fb8d8b45345661f96229..895a91177be828eb8d0875044e34b44041a95963 100644 (file)
@@ -62,7 +62,6 @@
 #include <openssl/buffer.h>
 #include <openssl/evp.h>
 
-#ifndef NOPROTO
 static int ber_write(BIO *h,char *buf,int num);
 static int ber_read(BIO *h,char *buf,int size);
 /*static int ber_puts(BIO *h,char *str); */
@@ -70,16 +69,7 @@ static int ber_read(BIO *h,char *buf,int size);
 static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
 static int ber_new(BIO *h);
 static int ber_free(BIO *data);
-#else
-static int ber_write();
-static int ber_read();
-/*static int ber_puts(); */
-/*static int ber_gets(); */
-static long ber_ctrl();
-static int ber_new();
-static int ber_free();
-#endif
-
+static long ber_callback_ctrl(BIO *h,int cmd,void *(*fp)());
 #define BER_BUF_SIZE   (32)
 
 /* This is used to hold the state of the BER objects being read. */
@@ -103,7 +93,7 @@ typedef struct bio_ber_struct
        /* most of the following are used when doing non-blocking IO */
        /* reading */
        long num_left;  /* number of bytes still to read/write in block */
-       int depth;      /* used with idefinite encoding. */
+       int depth;      /* used with indefinite encoding. */
        int finished;   /* No more read data */
 
        /* writting */ 
@@ -126,6 +116,7 @@ static BIO_METHOD methods_ber=
        ber_ctrl,
        ber_new,
        ber_free,
+       ber_callback_ctrl,
        };
 
 BIO_METHOD *BIO_f_ber(void)
@@ -137,7 +128,7 @@ static int ber_new(BIO *bi)
        {
        BIO_BER_CTX *ctx;
 
-       ctx=(BIO_BER_CTX *)Malloc(sizeof(BIO_BER_CTX));
+       ctx=(BIO_BER_CTX *)OPENSSL_malloc(sizeof(BIO_BER_CTX));
        if (ctx == NULL) return(0);
 
        memset((char *)ctx,0,sizeof(BIO_BER_CTX));
@@ -154,8 +145,8 @@ static int ber_free(BIO *a)
 
        if (a == NULL) return(0);
        b=(BIO_BER_CTX *)a->ptr;
-       memset(a->ptr,0,sizeof(BIO_BER_CTX));
-       Free(a->ptr);
+       OPENSSL_cleanse(a->ptr,sizeof(BIO_BER_CTX));
+       OPENSSL_free(a->ptr);
        a->ptr=NULL;
        a->init=0;
        a->flags=0;
@@ -348,7 +339,7 @@ static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
        case BIO_CTRL_RESET:
                ctx->ok=1;
                ctx->finished=0;
-               EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
+               EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
                        ctx->cipher.berrypt);
                ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
                break;
@@ -385,7 +376,7 @@ again:
                        {
                        ctx->finished=1;
                        ctx->buf_off=0;
-                       ret=EVP_CipherFinal(&(ctx->cipher),
+                       ret=EVP_CipherFinal_ex(&(ctx->cipher),
                                (unsigned char *)ctx->buf,
                                &(ctx->buf_len));
                        ctx->ok=(int)ret;
@@ -420,6 +411,20 @@ again:
        return(ret);
        }
 
+static long ber_callback_ctrl(BIO *b, int cmd, void *(*fp)())
+       {
+       long ret=1;
+
+       if (b->next_bio == NULL) return(0);
+       switch (cmd)
+               {
+       default:
+               ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
+               break;
+               }
+       return(ret);
+       }
+
 /*
 void BIO_set_cipher_ctx(b,c)
 BIO *b;
@@ -453,7 +458,7 @@ void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
 
        b->init=1;
        ctx=(BIO_ENC_CTX *)b->ptr;
-       EVP_CipherInit(&(ctx->cipher),c,k,i,e);
+       EVP_CipherInit_ex(&(ctx->cipher),c,NULL,k,i,e);
        
        if (b->callback != NULL)
                b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);