2 * Copyright (C) 2001 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS-EXTRA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include <gnutls_int.h>
22 #include <gnutls_errors.h>
23 #include <gnutls_extensions.h>
25 #include <gnutls_openpgp.h>
26 #include <gnutls_extra.h>
27 #include <gnutls_algorithms.h>
29 extern gnutls_extension_entry _gnutls_extensions
[];
30 extern const int _gnutls_extensions_size
;
34 static int _gnutls_add_srp_extension(void) {
37 /* find the last element */
38 for(i
=0;i
<_gnutls_extensions_size
;i
++) {
39 if (_gnutls_extensions
[i
].name
==NULL
) break;
42 if (_gnutls_extensions
[i
].name
==NULL
&& (i
< _gnutls_extensions_size
-1)) {
43 _gnutls_extensions
[i
].name
= TOSTR(GNUTLS_EXTENSION_SRP
);
44 _gnutls_extensions
[i
].type
= GNUTLS_EXTENSION_SRP
;
45 _gnutls_extensions
[i
].gnutls_ext_func_recv
= _gnutls_srp_recv_params
;
46 _gnutls_extensions
[i
].gnutls_ext_func_send
= _gnutls_srp_send_params
;
48 _gnutls_extensions
[i
+1].name
= 0;
53 return GNUTLS_E_MEMORY_ERROR
;
56 extern const int _gnutls_kx_algorithms_size
;
57 extern gnutls_kx_algo_entry _gnutls_kx_algorithms
[];
58 extern MOD_AUTH_STRUCT srp_auth_struct
;
60 static int _gnutls_add_srp_auth_struct(void) {
63 /* find the last element */
64 for(i
=0;i
<_gnutls_kx_algorithms_size
;i
++) {
65 if (_gnutls_kx_algorithms
[i
].name
==NULL
) break;
68 if (_gnutls_kx_algorithms
[i
].name
==NULL
&& (i
< _gnutls_kx_algorithms_size
-1)) {
69 _gnutls_kx_algorithms
[i
].name
= "SRP";
70 _gnutls_kx_algorithms
[i
].algorithm
= GNUTLS_KX_SRP
;
71 _gnutls_kx_algorithms
[i
].auth_struct
= &srp_auth_struct
;
73 _gnutls_kx_algorithms
[i
+1].name
= 0;
78 return GNUTLS_E_MEMORY_ERROR
;
82 extern OPENPGP_KEY_CREATION_TIME_FUNC _E_gnutls_openpgp_extract_key_creation_time
;
83 extern OPENPGP_KEY_EXPIRATION_TIME_FUNC _E_gnutls_openpgp_extract_key_expiration_time
;
84 extern OPENPGP_VERIFY_KEY_FUNC _E_gnutls_openpgp_verify_key
;
85 extern OPENPGP_CERT2GNUTLS_CERT _E_gnutls_openpgp_cert2gnutls_cert
;
86 extern OPENPGP_FINGERPRINT _E_gnutls_openpgp_fingerprint
;
87 extern OPENPGP_KEY_REQUEST _E_gnutls_openpgp_request_key
;
89 static void _gnutls_add_openpgp_functions(void) {
90 _E_gnutls_openpgp_verify_key
= gnutls_openpgp_verify_key
;
91 _E_gnutls_openpgp_extract_key_expiration_time
= gnutls_openpgp_extract_key_expiration_time
;
92 _E_gnutls_openpgp_extract_key_creation_time
= gnutls_openpgp_extract_key_creation_time
;
93 _E_gnutls_openpgp_fingerprint
= gnutls_openpgp_fingerprint
;
94 _E_gnutls_openpgp_request_key
= _gnutls_openpgp_request_key
;
95 _E_gnutls_openpgp_cert2gnutls_cert
= _gnutls_openpgp_cert2gnutls_cert
;
100 static int _gnutls_init_extra
= 0;
103 * gnutls_global_init_extra - This function initializes the global state of gnutls-extra
105 * This function initializes the global state of gnutls-extra library to defaults.
106 * Returns zero on success.
108 * Note that gnutls_global_init() has to be called before this function.
109 * If this function is not called then the gnutls-extra library will not
113 int gnutls_global_init_extra(void) {
116 _gnutls_init_extra
++;
118 if (_gnutls_init_extra
!=1) {
122 ret
= _gnutls_add_srp_auth_struct();
128 ret
= _gnutls_add_srp_extension();
134 _gnutls_add_openpgp_functions();