2 * Copyright (C) 2001, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS-EXTRA.
9 * GnuTLS-extra is free software: you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
14 * GnuTLS-extra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see
21 * <http://www.gnu.org/licenses/>.
24 #include <gnutls_int.h>
25 #include <gnutls_errors.h>
26 #include <gnutls_extensions.h>
27 #include <gnutls_algorithms.h>
28 #include <ext_inner_application.h>
36 #include "minilzo/minilzo.h"
37 #elif HAVE_LZO_LZO1X_H
38 #include <lzo/lzo1x.h>
43 #include <gnutls/extra.h>
46 #include <gnutls_compress.h>
48 /* the number of the compression algorithms available in the compression
51 extern int _gnutls_comp_algorithms_size
;
53 typedef int (*LZO_FUNC
) ();
54 extern LZO_FUNC _gnutls_lzo1x_decompress_safe
;
55 extern LZO_FUNC _gnutls_lzo1x_1_compress
;
57 extern gnutls_compression_entry _gnutls_compression_algorithms
[];
60 _gnutls_add_lzo_comp (void)
64 /* find the last element */
65 for (i
= 0; i
< _gnutls_comp_algorithms_size
; i
++)
67 if (_gnutls_compression_algorithms
[i
].name
== NULL
)
71 if (_gnutls_compression_algorithms
[i
].name
== NULL
72 && (i
< _gnutls_comp_algorithms_size
- 1))
74 _gnutls_compression_algorithms
[i
].name
= "GNUTLS_COMP_LZO";
75 _gnutls_compression_algorithms
[i
].id
= GNUTLS_COMP_LZO
;
76 _gnutls_compression_algorithms
[i
].num
= 0xf2;
78 _gnutls_compression_algorithms
[i
+ 1].name
= 0;
80 /* Now enable the lzo functions: */
81 _gnutls_lzo1x_decompress_safe
= lzo1x_decompress_safe
;
82 _gnutls_lzo1x_1_compress
= lzo1x_1_compress
;
88 return GNUTLS_E_MEMORY_ERROR
;
92 static int _gnutls_init_extra
= 0;
95 * gnutls_global_init_extra:
97 * This function initializes the global state of gnutls-extra library
100 * Note that gnutls_global_init() has to be called before this
101 * function. If this function is not called then the gnutls-extra
102 * library will not be usable.
104 * This function is not thread safe, see the discussion for
105 * gnutls_global_init() on how to deal with that.
107 * Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
108 * otherwise an error code is returned.
111 gnutls_global_init_extra (void)
115 /* If the version of libgnutls != version of
116 * libextra, then do not initialize the library.
117 * This is because it may break things.
119 if (strcmp (gnutls_check_version (NULL
), VERSION
) != 0)
121 return GNUTLS_E_LIBRARY_VERSION_MISMATCH
;
124 _gnutls_init_extra
++;
126 if (_gnutls_init_extra
!= 1)
129 ret
= _gnutls_ext_register (&ext_mod_ia
);
130 if (ret
!= GNUTLS_E_SUCCESS
)
133 /* Initialize the LZO library
136 if (lzo_init () != LZO_E_OK
)
137 return GNUTLS_E_LZO_INIT_FAILED
;
139 /* Add the LZO compression method in the list of compression
142 ret
= _gnutls_add_lzo_comp ();
152 #ifdef gcry_fips_mode_active
153 /* Libgcrypt manual says that gcry_version_check must be called
154 before calling gcry_fips_mode_active. */
155 gcry_check_version (NULL
);
156 if (gcry_fips_mode_active ())
158 ret
= gnutls_register_md5_handler ();
160 fprintf (stderr
, "gnutls_register_md5_handler: %s\n",
161 gnutls_strerror (ret
));
170 * gnutls_extra_check_version:
171 * @req_version: version string to compare with, or %NULL.
173 * Check GnuTLS Extra Library version.
175 * See %GNUTLS_EXTRA_VERSION for a suitable @req_version string.
177 * Return value: Check that the version of the library is at
178 * minimum the one given as a string in @req_version and return the
179 * actual version string of the library; return %NULL if the
180 * condition is not met. If %NULL is passed to this function no
181 * check is done and only the version string is returned.
184 gnutls_extra_check_version (const char *req_version
)
186 if (!req_version
|| strverscmp (req_version
, VERSION
) <= 0)