2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS 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 3 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 License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 /* This file contains the Anonymous Diffie-Hellman key exchange part of
24 * the anonymous authentication. The functions here are used in the
28 #include <gnutls_int.h>
32 #include "gnutls_auth.h"
33 #include "gnutls_errors.h"
34 #include "gnutls_dh.h"
35 #include "auth/anon.h"
36 #include "gnutls_num.h"
37 #include "gnutls_mpi.h"
38 #include <gnutls_state.h>
39 #include <auth/dh_common.h>
41 static int gen_anon_server_kx (gnutls_session_t
, gnutls_buffer_st
*);
42 static int proc_anon_client_kx (gnutls_session_t
, uint8_t *, size_t);
43 static int proc_anon_server_kx (gnutls_session_t
, uint8_t *, size_t);
45 const mod_auth_st anon_auth_struct
= {
50 _gnutls_gen_dh_common_client_kx
, /* this can be shared */
55 NULL
, /* certificate */
63 gen_anon_server_kx (gnutls_session_t session
, gnutls_buffer_st
* data
)
68 gnutls_dh_params_t dh_params
;
69 gnutls_anon_server_credentials_t cred
;
71 cred
= (gnutls_anon_server_credentials_t
)
72 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
76 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
80 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
81 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
85 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
92 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
93 sizeof (anon_auth_info_st
), 1)) < 0)
99 _gnutls_dh_set_group (session
, g
, p
);
101 ret
= _gnutls_dh_common_print_server_kx (session
, g
, p
, dh_params
->q_bits
, data
);
112 proc_anon_client_kx (gnutls_session_t session
, uint8_t * data
,
115 gnutls_anon_server_credentials_t cred
;
118 gnutls_dh_params_t dh_params
;
119 const bigint_t
*mpis
;
121 cred
= (gnutls_anon_server_credentials_t
)
122 _gnutls_get_cred (session
->key
, GNUTLS_CRD_ANON
, NULL
);
126 return GNUTLS_E_INSUFFICIENT_CREDENTIALS
;
130 _gnutls_get_dh_params (cred
->dh_params
, cred
->params_func
, session
);
131 mpis
= _gnutls_dh_params_to_mpi (dh_params
);
135 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS
;
141 ret
= _gnutls_proc_dh_common_client_kx (session
, data
, _data_size
, g
, p
, NULL
);
148 proc_anon_server_kx (gnutls_session_t session
, uint8_t * data
,
156 _gnutls_auth_info_set (session
, GNUTLS_CRD_ANON
,
157 sizeof (anon_auth_info_st
), 1)) < 0)
163 ret
= _gnutls_proc_dh_common_server_kx (session
, data
, _data_size
);
173 #endif /* ENABLE_ANON */