xref: /onnv-gate/usr/src/common/openssl/crypto/comp/comp_lib.c (revision 0:68f95e015346)
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 
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 #if 0
24*0Sstevel@tonic-gate 	else
25*0Sstevel@tonic-gate 		CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
26*0Sstevel@tonic-gate #endif
27*0Sstevel@tonic-gate 	return(ret);
28*0Sstevel@tonic-gate 	}
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate void COMP_CTX_free(COMP_CTX *ctx)
31*0Sstevel@tonic-gate 	{
32*0Sstevel@tonic-gate 	/* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate 	if(ctx == NULL)
35*0Sstevel@tonic-gate 	    return;
36*0Sstevel@tonic-gate 
37*0Sstevel@tonic-gate 	if (ctx->meth->finish != NULL)
38*0Sstevel@tonic-gate 		ctx->meth->finish(ctx);
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate 	OPENSSL_free(ctx);
41*0Sstevel@tonic-gate 	}
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
44*0Sstevel@tonic-gate 	     unsigned char *in, int ilen)
45*0Sstevel@tonic-gate 	{
46*0Sstevel@tonic-gate 	int ret;
47*0Sstevel@tonic-gate 	if (ctx->meth->compress == NULL)
48*0Sstevel@tonic-gate 		{
49*0Sstevel@tonic-gate 		/* ZZZZZZZZZZZZZZZZZ */
50*0Sstevel@tonic-gate 		return(-1);
51*0Sstevel@tonic-gate 		}
52*0Sstevel@tonic-gate 	ret=ctx->meth->compress(ctx,out,olen,in,ilen);
53*0Sstevel@tonic-gate 	if (ret > 0)
54*0Sstevel@tonic-gate 		{
55*0Sstevel@tonic-gate 		ctx->compress_in+=ilen;
56*0Sstevel@tonic-gate 		ctx->compress_out+=ret;
57*0Sstevel@tonic-gate 		}
58*0Sstevel@tonic-gate 	return(ret);
59*0Sstevel@tonic-gate 	}
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
62*0Sstevel@tonic-gate 	     unsigned char *in, int ilen)
63*0Sstevel@tonic-gate 	{
64*0Sstevel@tonic-gate 	int ret;
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate 	if (ctx->meth->expand == NULL)
67*0Sstevel@tonic-gate 		{
68*0Sstevel@tonic-gate 		/* ZZZZZZZZZZZZZZZZZ */
69*0Sstevel@tonic-gate 		return(-1);
70*0Sstevel@tonic-gate 		}
71*0Sstevel@tonic-gate 	ret=ctx->meth->expand(ctx,out,olen,in,ilen);
72*0Sstevel@tonic-gate 	if (ret > 0)
73*0Sstevel@tonic-gate 		{
74*0Sstevel@tonic-gate 		ctx->expand_in+=ilen;
75*0Sstevel@tonic-gate 		ctx->expand_out+=ret;
76*0Sstevel@tonic-gate 		}
77*0Sstevel@tonic-gate 	return(ret);
78*0Sstevel@tonic-gate 	}
79