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