2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2009, 2010 Free
3 * Software Foundation, Inc.
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS.
9 * The GnuTLS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library 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 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 /* This file contains the Anonymous Diffie-Hellman key exchange part of
27 * the anonymous authentication. The functions here are used in the
31 #include <gnutls_int.h>
35 #include "gnutls_auth.h"
36 #include "gnutls_errors.h"
37 #include "gnutls_dh.h"
38 #include "auth_anon.h"
39 #include "gnutls_num.h"
40 #include "gnutls_mpi.h"
41 #include <gnutls_state.h>
42 #include <auth_dh_common.h>
44 static int gen_anon_server_kx (gnutls_session_t
, opaque
**);
45 static int proc_anon_client_kx (gnutls_session_t
, opaque
*, size_t);
46 static int proc_anon_server_kx (gnutls_session_t
, opaque
*, size_t);
48 const mod_auth_st anon_auth_struct
= {
53 _gnutls_gen_dh_common_client_kx
, /* this can be shared */
58 NULL
, /* certificate */
66 gen_anon_server_kx (gnutls_session_t session
, opaque
** data
)
71 gnutls_dh_params_t dh_params
;
72 gnutls_anon_server_credentials_t cred
;
74 cred
= (gnutls_anon_server_credentials_t
)
75 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
79 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
83 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
84 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
88 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
95 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
96 sizeof (anon_auth_info_st
), 1)) < 0)
102 _gnutls_dh_set_group (session
, g
, p
);
104 ret
= _gnutls_dh_common_print_server_kx (session
, g
, p
, data
, 0);
115 proc_anon_client_kx (gnutls_session_t session
, opaque
* data
,
118 gnutls_anon_server_credentials_t cred
;
121 gnutls_dh_params_t dh_params
;
122 const bigint_t
*mpis
;
124 cred
= (gnutls_anon_server_credentials_t
)
125 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
129 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
133 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
134 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
138 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
144 ret
= _gnutls_proc_dh_common_client_kx (session
, data
, _data_size
, g
, p
);
151 proc_anon_server_kx (gnutls_session_t session
, opaque
* data
,
159 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
160 sizeof (anon_auth_info_st
), 1)) < 0)
166 ret
= _gnutls_proc_dh_common_server_kx (session
, data
, _data_size
, 0);
176 #endif /* ENABLE_ANON */