1*0Sstevel@tonic-gate #include <stdio.h>
2*0Sstevel@tonic-gate #include <stdlib.h>
3*0Sstevel@tonic-gate #include <string.h>
4*0Sstevel@tonic-gate #include <openssl/objects.h>
5*0Sstevel@tonic-gate #include <openssl/comp.h>
6*0Sstevel@tonic-gate
COMP_CTX_new(COMP_METHOD * meth)7*0Sstevel@tonic-gate COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8*0Sstevel@tonic-gate {
9*0Sstevel@tonic-gate COMP_CTX *ret;
10*0Sstevel@tonic-gate
11*0Sstevel@tonic-gate if ((ret=(COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL)
12*0Sstevel@tonic-gate {
13*0Sstevel@tonic-gate /* ZZZZZZZZZZZZZZZZ */
14*0Sstevel@tonic-gate return(NULL);
15*0Sstevel@tonic-gate }
16*0Sstevel@tonic-gate memset(ret,0,sizeof(COMP_CTX));
17*0Sstevel@tonic-gate ret->meth=meth;
18*0Sstevel@tonic-gate if ((ret->meth->init != NULL) && !ret->meth->init(ret))
19*0Sstevel@tonic-gate {
20*0Sstevel@tonic-gate OPENSSL_free(ret);
21*0Sstevel@tonic-gate ret=NULL;
22*0Sstevel@tonic-gate }
23*0Sstevel@tonic-gate return(ret);
24*0Sstevel@tonic-gate }
25*0Sstevel@tonic-gate
COMP_CTX_free(COMP_CTX * ctx)26*0Sstevel@tonic-gate void COMP_CTX_free(COMP_CTX *ctx)
27*0Sstevel@tonic-gate {
28*0Sstevel@tonic-gate if(ctx == NULL)
29*0Sstevel@tonic-gate return;
30*0Sstevel@tonic-gate
31*0Sstevel@tonic-gate if (ctx->meth->finish != NULL)
32*0Sstevel@tonic-gate ctx->meth->finish(ctx);
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gate OPENSSL_free(ctx);
35*0Sstevel@tonic-gate }
36*0Sstevel@tonic-gate
COMP_compress_block(COMP_CTX * ctx,unsigned char * out,int olen,unsigned char * in,int ilen)37*0Sstevel@tonic-gate int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
38*0Sstevel@tonic-gate unsigned char *in, int ilen)
39*0Sstevel@tonic-gate {
40*0Sstevel@tonic-gate int ret;
41*0Sstevel@tonic-gate if (ctx->meth->compress == NULL)
42*0Sstevel@tonic-gate {
43*0Sstevel@tonic-gate /* ZZZZZZZZZZZZZZZZZ */
44*0Sstevel@tonic-gate return(-1);
45*0Sstevel@tonic-gate }
46*0Sstevel@tonic-gate ret=ctx->meth->compress(ctx,out,olen,in,ilen);
47*0Sstevel@tonic-gate if (ret > 0)
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate ctx->compress_in+=ilen;
50*0Sstevel@tonic-gate ctx->compress_out+=ret;
51*0Sstevel@tonic-gate }
52*0Sstevel@tonic-gate return(ret);
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate
COMP_expand_block(COMP_CTX * ctx,unsigned char * out,int olen,unsigned char * in,int ilen)55*0Sstevel@tonic-gate int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
56*0Sstevel@tonic-gate unsigned char *in, int ilen)
57*0Sstevel@tonic-gate {
58*0Sstevel@tonic-gate int ret;
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate if (ctx->meth->expand == NULL)
61*0Sstevel@tonic-gate {
62*0Sstevel@tonic-gate /* ZZZZZZZZZZZZZZZZZ */
63*0Sstevel@tonic-gate return(-1);
64*0Sstevel@tonic-gate }
65*0Sstevel@tonic-gate ret=ctx->meth->expand(ctx,out,olen,in,ilen);
66*0Sstevel@tonic-gate if (ret > 0)
67*0Sstevel@tonic-gate {
68*0Sstevel@tonic-gate ctx->expand_in+=ilen;
69*0Sstevel@tonic-gate ctx->expand_out+=ret;
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate return(ret);
72*0Sstevel@tonic-gate }
73