1 /* ====================================================================
2  * Copyright (c) 2002 Johnny Shelley.  All rights reserved.
3  *
4  * Bcrypt is licensed under the BSD software license. See the file
5  * called 'LICENSE' that you should have received with this software
6  * for details
7  * ====================================================================
8  */
9 
10 #include "includes.h"
11 #include "defines.h"
12 #include "functions.h"
13 
docompress(char ** input,uLong sz)14 uLong docompress(char **input, uLong sz) {
15   uLong newsz;
16   char *output;
17 
18   newsz = sz + (sz *.1) + 13;
19   if ((output = malloc(newsz + 1)) == NULL)
20     memerror();
21 
22   memset(output, 0, newsz + 1);
23 
24   compress((Bytef *) output, &newsz, (const Bytef *) *input,  sz);
25 
26   free(*input);
27   if ((*input = malloc(newsz)) == NULL)
28     memerror();
29 
30   memcpy(*input, output, newsz);
31 
32   free(output);
33 
34   return(newsz);
35 }
36 
douncompress(char ** input,uLong sz,BCoptions options)37 uLong douncompress(char **input, uLong sz, BCoptions options) {
38   char *output;
39 
40   if ((output = malloc(options.origsize + 1)) == NULL)
41     memerror();
42 
43   memset(output, 0, options.origsize + 1);
44 
45   uncompress((Bytef *) output, (uLong *) &options.origsize,
46 	(const Bytef *) *input, sz);
47 
48   free(*input);
49   if ((*input = malloc(options.origsize)) == NULL)
50     memerror();
51 
52   memcpy(*input, output, options.origsize);
53 
54   free(output);
55 
56   return(options.origsize);
57 }
58