Tizen 2.0 Release
[external/libgnutls26.git] / lib / gnutls_anon_cred.c
1 /*
2  * Copyright (C) 2001, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
3  * Foundation, Inc.
4  *
5  * Author: Nikos Mavrogiannopoulos
6  *
7  * This file is part of GnuTLS.
8  *
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.
13  *
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.
18  *
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,
22  * USA
23  *
24  */
25
26 #include "gnutls_int.h"
27
28 #ifdef ENABLE_ANON
29
30 #include "gnutls_errors.h"
31 #include "auth_anon.h"
32 #include "gnutls_auth.h"
33 #include "gnutls_dh.h"
34 #include "gnutls_num.h"
35 #include "gnutls_mpi.h"
36
37 /**
38  * gnutls_anon_free_server_credentials:
39  * @sc: is a #gnutls_anon_server_credentials_t structure.
40  *
41  * This structure is complex enough to manipulate directly thus this
42  * helper function is provided in order to free (deallocate) it.
43  **/
44 void
45 gnutls_anon_free_server_credentials (gnutls_anon_server_credentials_t sc)
46 {
47
48   gnutls_free (sc);
49 }
50
51 /**
52  * gnutls_anon_allocate_server_credentials:
53  * @sc: is a pointer to a #gnutls_anon_server_credentials_t structure.
54  *
55  * This structure is complex enough to manipulate directly thus this
56  * helper function is provided in order to allocate it.
57  *
58  * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
59  **/
60 int
61 gnutls_anon_allocate_server_credentials (gnutls_anon_server_credentials_t *
62                                          sc)
63 {
64
65   *sc = gnutls_calloc (1, sizeof (anon_server_credentials_st));
66
67   return 0;
68 }
69
70
71 /**
72  * gnutls_anon_free_client_credentials:
73  * @sc: is a #gnutls_anon_client_credentials_t structure.
74  *
75  * This structure is complex enough to manipulate directly thus this
76  * helper function is provided in order to free (deallocate) it.
77  **/
78 void
79 gnutls_anon_free_client_credentials (gnutls_anon_client_credentials_t sc)
80 {
81 }
82
83 static struct gnutls_anon_client_credentials_st anon_dummy_struct;
84 static const gnutls_anon_client_credentials_t anon_dummy = &anon_dummy_struct;
85
86 /**
87  * gnutls_anon_allocate_client_credentials:
88  * @sc: is a pointer to a #gnutls_anon_client_credentials_t structure.
89  *
90  * This structure is complex enough to manipulate directly thus
91  * this helper function is provided in order to allocate it.
92  *
93  * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
94  **/
95 int
96 gnutls_anon_allocate_client_credentials (gnutls_anon_client_credentials_t *
97                                          sc)
98 {
99   /* anon_dummy is only there for *sc not to be null.
100    * it is not used at all;
101    */
102   *sc = anon_dummy;
103
104   return 0;
105 }
106
107 /**
108  * gnutls_anon_set_server_dh_params:
109  * @res: is a gnutls_anon_server_credentials_t structure
110  * @dh_params: is a structure that holds Diffie-Hellman parameters.
111  *
112  * This function will set the Diffie-Hellman parameters for an
113  * anonymous server to use.  These parameters will be used in
114  * Anonymous Diffie-Hellman cipher suites.
115  **/
116 void
117 gnutls_anon_set_server_dh_params (gnutls_anon_server_credentials_t res,
118                                   gnutls_dh_params_t dh_params)
119 {
120   res->dh_params = dh_params;
121 }
122
123 /**
124  * gnutls_anon_set_server_params_function:
125  * @res: is a gnutls_certificate_credentials_t structure
126  * @func: is the function to be called
127  *
128  * This function will set a callback in order for the server to get
129  * the Diffie-Hellman parameters for anonymous authentication.  The
130  * callback should return zero on success.
131  **/
132 void
133 gnutls_anon_set_server_params_function (gnutls_anon_server_credentials_t res,
134                                         gnutls_params_function * func)
135 {
136   res->params_func = func;
137 }
138
139 #endif