2 * Copyright (C) 2001, 2004, 2005, 2007 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GNUTLS-EXTRA.
8 * GNUTLS-EXTRA is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <gnutls_int.h>
23 #include <gnutls_errors.h>
24 #include <gnutls_extensions.h>
25 #include <gnutls_openpgp.h>
26 #include <gnutls_extra.h>
27 #include <gnutls_extra_hooks.h>
28 #include <gnutls_algorithms.h>
31 # include "minilzo/minilzo.h"
32 # elif HAVE_LZO_LZO1X_H
33 # include <lzo/lzo1x.h>
40 /* the number of the compression algorithms available in the compression
43 extern int _gnutls_comp_algorithms_size
;
45 /* Functions in gnutls that have not been initialized.
48 typedef int (*LZO_FUNC
) ();
49 extern LZO_FUNC _gnutls_lzo1x_decompress_safe
;
50 extern LZO_FUNC _gnutls_lzo1x_1_compress
;
52 extern gnutls_compression_entry _gnutls_compression_algorithms
[];
55 _gnutls_add_lzo_comp (void)
59 /* find the last element */
60 for (i
= 0; i
< _gnutls_comp_algorithms_size
; i
++)
62 if (_gnutls_compression_algorithms
[i
].name
== NULL
)
66 if (_gnutls_compression_algorithms
[i
].name
== NULL
67 && (i
< _gnutls_comp_algorithms_size
- 1))
69 _gnutls_compression_algorithms
[i
].name
= "GNUTLS_COMP_LZO";
70 _gnutls_compression_algorithms
[i
].id
= GNUTLS_COMP_LZO
;
71 _gnutls_compression_algorithms
[i
].num
= 0xf2;
73 _gnutls_compression_algorithms
[i
+ 1].name
= 0;
75 /* Now enable the lzo functions: */
76 _gnutls_lzo1x_decompress_safe
= lzo1x_decompress_safe
;
77 _gnutls_lzo1x_1_compress
= lzo1x_1_compress
;
83 return GNUTLS_E_MEMORY_ERROR
;
87 static int _gnutls_init_extra
= 0;
90 * gnutls_global_init_extra - This function initializes the global state of gnutls-extra
92 * This function initializes the global state of gnutls-extra library
93 * to defaults. Returns zero on success.
95 * Note that gnutls_global_init() has to be called before this
96 * function. If this function is not called then the gnutls-extra
97 * library will not be usable.
101 gnutls_global_init_extra (void)
105 /* If the version of libgnutls != version of
106 * libextra, then do not initialize the library.
107 * This is because it may break things.
109 if (strcmp (gnutls_check_version (NULL
), VERSION
) != 0)
111 return GNUTLS_E_LIBRARY_VERSION_MISMATCH
;
114 _gnutls_init_extra
++;
116 if (_gnutls_init_extra
!= 1)
121 /* Initialize the LZO library
124 if (lzo_init () != LZO_E_OK
)
126 return GNUTLS_E_LZO_INIT_FAILED
;
129 /* Add the LZO compression method in the list of compression
132 ret
= _gnutls_add_lzo_comp ();
140 /* Register the openpgp functions. This is because some
141 * of them are defined to be NULL in the main library.
143 _gnutls_add_openpgp_functions (_gnutls_openpgp_verify_key
,
144 _gnutls_openpgp_get_raw_key_creation_time
,
145 _gnutls_openpgp_get_raw_key_expiration_time
,
146 _gnutls_openpgp_fingerprint
,
147 _gnutls_openpgp_request_key
,
148 _gnutls_openpgp_raw_key_to_gcert
,
149 _gnutls_openpgp_raw_privkey_to_gkey
,
150 _gnutls_openpgp_crt_to_gcert
,
151 _gnutls_openpgp_privkey_to_gkey
,
152 gnutls_openpgp_crt_deinit
,
153 gnutls_openpgp_keyring_deinit
,
154 gnutls_openpgp_privkey_deinit
);
159 #include <strverscmp.h>
162 * gnutls_extra_check_version - This function checks the library's version
163 * @req_version: the version to check
165 * Check that the version of the gnutls-extra library is at minimum
166 * the requested one and return the version string; return NULL if the
167 * condition is not satisfied. If a NULL is passed to this function,
168 * no check is done, but the version string is simply returned.
172 gnutls_extra_check_version (const char *req_version
)
174 if (!req_version
|| strverscmp (req_version
, VERSION
) <= 0)