updated licenses
[gnutls.git] / lib / auth / anon_ecdh.c
blob63e72edd4a42723c839354ba7273eada93c302a4
1 /*
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
25 * handshake.
28 #include <gnutls_int.h>
30 #ifdef ENABLE_ANON
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/ecdh_common.h>
40 #include <ext/ecc.h>
42 static int gen_anon_ecdh_server_kx (gnutls_session_t, gnutls_buffer_st*);
43 static int proc_anon_ecdh_client_kx (gnutls_session_t, uint8_t *, size_t);
44 static int proc_anon_ecdh_server_kx (gnutls_session_t, uint8_t *, size_t);
46 const mod_auth_st anon_ecdh_auth_struct = {
47 "ANON ECDH",
48 NULL,
49 NULL,
50 gen_anon_ecdh_server_kx,
51 _gnutls_gen_ecdh_common_client_kx, /* this can be shared */
52 NULL,
53 NULL,
55 NULL,
56 NULL, /* certificate */
57 proc_anon_ecdh_server_kx,
58 proc_anon_ecdh_client_kx,
59 NULL,
60 NULL
63 static int
64 gen_anon_ecdh_server_kx (gnutls_session_t session, gnutls_buffer_st* data)
66 int ret;
67 gnutls_anon_server_credentials_t cred;
69 cred = (gnutls_anon_server_credentials_t)
70 _gnutls_get_cred (session->key, GNUTLS_CRD_ANON, NULL);
71 if (cred == NULL)
73 gnutls_assert ();
74 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
77 if ((ret =
78 _gnutls_auth_info_set (session, GNUTLS_CRD_ANON,
79 sizeof (anon_auth_info_st), 1)) < 0)
81 gnutls_assert ();
82 return ret;
85 ret = _gnutls_ecdh_common_print_server_kx (session, data, _gnutls_session_ecc_curve_get(session));
86 if (ret < 0)
88 gnutls_assert ();
91 return ret;
95 static int
96 proc_anon_ecdh_client_kx (gnutls_session_t session, uint8_t * data,
97 size_t _data_size)
99 gnutls_anon_server_credentials_t cred;
101 cred = (gnutls_anon_server_credentials_t)
102 _gnutls_get_cred (session->key, GNUTLS_CRD_ANON, NULL);
103 if (cred == NULL)
105 gnutls_assert ();
106 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
109 return _gnutls_proc_ecdh_common_client_kx (session, data, _data_size,
110 _gnutls_session_ecc_curve_get(session), NULL);
114 proc_anon_ecdh_server_kx (gnutls_session_t session, uint8_t * data,
115 size_t _data_size)
118 int ret;
120 /* set auth_info */
121 if ((ret =
122 _gnutls_auth_info_set (session, GNUTLS_CRD_ANON,
123 sizeof (anon_auth_info_st), 1)) < 0)
125 gnutls_assert ();
126 return ret;
129 ret = _gnutls_proc_ecdh_common_server_kx (session, data, _data_size);
130 if (ret < 0)
132 gnutls_assert ();
133 return ret;
136 return 0;
139 #endif /* ENABLE_ANON */