2 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GNUTLS.
8 * The GNUTLS library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25 /* This file contains the Anonymous Diffie Hellman key exchange part of
26 * the anonymous authentication. The functions here are used in the
30 #include <gnutls_int.h>
34 #include "gnutls_auth_int.h"
35 #include "gnutls_errors.h"
36 #include "gnutls_dh.h"
37 #include "auth_anon.h"
38 #include "gnutls_num.h"
39 #include "gnutls_mpi.h"
40 #include <gnutls_state.h>
41 #include <auth_dh_common.h>
43 static int gen_anon_server_kx (gnutls_session_t
, opaque
**);
44 static int proc_anon_client_kx (gnutls_session_t
, opaque
*, size_t);
45 static int proc_anon_server_kx (gnutls_session_t
, opaque
*, size_t);
47 const mod_auth_st anon_auth_struct
= {
52 _gnutls_gen_dh_common_client_kx
, /* this can be shared */
57 NULL
, /* certificate */
65 gen_anon_server_kx (gnutls_session_t session
, opaque
** data
)
70 gnutls_dh_params_t dh_params
;
71 gnutls_anon_server_credentials_t cred
;
73 cred
= (gnutls_anon_server_credentials_t
)
74 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
78 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
82 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
83 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
87 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
94 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
95 sizeof (anon_auth_info_st
), 1)) < 0)
101 _gnutls_dh_set_group (session
, g
, p
);
103 ret
= _gnutls_dh_common_print_server_kx (session
, g
, p
, data
, 0);
114 proc_anon_client_kx (gnutls_session_t session
, opaque
* data
,
117 gnutls_anon_server_credentials_t cred
;
121 gnutls_dh_params_t dh_params
;
124 bits
= _gnutls_dh_get_allowed_prime_bits (session
);
126 cred
= (gnutls_anon_server_credentials_t
)
127 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
131 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
135 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
136 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
140 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
146 ret
= _gnutls_proc_dh_common_client_kx (session
, data
, _data_size
, g
, p
);
153 proc_anon_server_kx (gnutls_session_t session
, opaque
* data
,
161 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
162 sizeof (anon_auth_info_st
), 1)) < 0)
168 ret
= _gnutls_proc_dh_common_server_kx (session
, data
, _data_size
, 0);
178 #endif /* ENABLE_ANON */