aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/https/tls
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/https/tls')
-rw-r--r--src/daemon/https/tls/auth_anon.c76
-rw-r--r--src/daemon/https/tls/auth_anon.h16
-rw-r--r--src/daemon/https/tls/auth_cert.c408
-rw-r--r--src/daemon/https/tls/auth_cert.h84
-rw-r--r--src/daemon/https/tls/auth_dh_common.c142
-rw-r--r--src/daemon/https/tls/auth_dh_common.h18
-rw-r--r--src/daemon/https/tls/auth_dhe.c150
-rw-r--r--src/daemon/https/tls/auth_rsa.c169
-rw-r--r--src/daemon/https/tls/auth_rsa_export.c158
-rw-r--r--src/daemon/https/tls/debug.c22
-rw-r--r--src/daemon/https/tls/debug.h8
-rw-r--r--src/daemon/https/tls/ext_cert_type.c48
-rw-r--r--src/daemon/https/tls/ext_cert_type.h4
-rw-r--r--src/daemon/https/tls/ext_max_record.c28
-rw-r--r--src/daemon/https/tls/ext_max_record.h8
-rw-r--r--src/daemon/https/tls/ext_oprfi.c58
-rw-r--r--src/daemon/https/tls/ext_oprfi.h4
-rw-r--r--src/daemon/https/tls/ext_server_name.c40
-rw-r--r--src/daemon/https/tls/ext_server_name.h4
-rw-r--r--src/daemon/https/tls/gnutls_alert.c48
-rw-r--r--src/daemon/https/tls/gnutls_algorithms.c416
-rw-r--r--src/daemon/https/tls/gnutls_algorithms.h98
-rw-r--r--src/daemon/https/tls/gnutls_anon_cred.c48
-rw-r--r--src/daemon/https/tls/gnutls_asn1_tab.c2
-rw-r--r--src/daemon/https/tls/gnutls_auth.c104
-rw-r--r--src/daemon/https/tls/gnutls_auth.h28
-rw-r--r--src/daemon/https/tls/gnutls_auth_int.h8
-rw-r--r--src/daemon/https/tls/gnutls_buffers.c302
-rw-r--r--src/daemon/https/tls/gnutls_buffers.h54
-rw-r--r--src/daemon/https/tls/gnutls_cert.c282
-rw-r--r--src/daemon/https/tls/gnutls_cert.h32
-rw-r--r--src/daemon/https/tls/gnutls_cipher.c156
-rw-r--r--src/daemon/https/tls/gnutls_cipher.h12
-rw-r--r--src/daemon/https/tls/gnutls_cipher_int.c48
-rw-r--r--src/daemon/https/tls/gnutls_cipher_int.h16
-rw-r--r--src/daemon/https/tls/gnutls_compress.c20
-rw-r--r--src/daemon/https/tls/gnutls_compress.h12
-rw-r--r--src/daemon/https/tls/gnutls_compress_int.c66
-rw-r--r--src/daemon/https/tls/gnutls_compress_int.h8
-rw-r--r--src/daemon/https/tls/gnutls_constate.c374
-rw-r--r--src/daemon/https/tls/gnutls_constate.h20
-rw-r--r--src/daemon/https/tls/gnutls_datum.c24
-rw-r--r--src/daemon/https/tls/gnutls_datum.h26
-rw-r--r--src/daemon/https/tls/gnutls_dh.c54
-rw-r--r--src/daemon/https/tls/gnutls_dh.h16
-rw-r--r--src/daemon/https/tls/gnutls_dh_primes.c48
-rw-r--r--src/daemon/https/tls/gnutls_errors.c24
-rw-r--r--src/daemon/https/tls/gnutls_errors.h58
-rw-r--r--src/daemon/https/tls/gnutls_extensions.c118
-rw-r--r--src/daemon/https/tls/gnutls_extensions.h24
-rw-r--r--src/daemon/https/tls/gnutls_global.c148
-rw-r--r--src/daemon/https/tls/gnutls_global.h14
-rw-r--r--src/daemon/https/tls/gnutls_handshake.c954
-rw-r--r--src/daemon/https/tls/gnutls_handshake.h38
-rw-r--r--src/daemon/https/tls/gnutls_hash_int.c162
-rw-r--r--src/daemon/https/tls/gnutls_hash_int.h26
-rw-r--r--src/daemon/https/tls/gnutls_int.h176
-rw-r--r--src/daemon/https/tls/gnutls_kx.c228
-rw-r--r--src/daemon/https/tls/gnutls_kx.h26
-rw-r--r--src/daemon/https/tls/gnutls_mem.c42
-rw-r--r--src/daemon/https/tls/gnutls_mem.h30
-rw-r--r--src/daemon/https/tls/gnutls_mpi.c86
-rw-r--r--src/daemon/https/tls/gnutls_mpi.h66
-rw-r--r--src/daemon/https/tls/gnutls_num.c28
-rw-r--r--src/daemon/https/tls/gnutls_num.h26
-rw-r--r--src/daemon/https/tls/gnutls_pk.c316
-rw-r--r--src/daemon/https/tls/gnutls_pk.h20
-rw-r--r--src/daemon/https/tls/gnutls_priority.c114
-rw-r--r--src/daemon/https/tls/gnutls_record.c336
-rw-r--r--src/daemon/https/tls/gnutls_record.h12
-rw-r--r--src/daemon/https/tls/gnutls_rsa_export.c52
-rw-r--r--src/daemon/https/tls/gnutls_rsa_export.h6
-rw-r--r--src/daemon/https/tls/gnutls_session.c4
-rw-r--r--src/daemon/https/tls/gnutls_session_pack.c366
-rw-r--r--src/daemon/https/tls/gnutls_session_pack.h8
-rw-r--r--src/daemon/https/tls/gnutls_sig.c216
-rw-r--r--src/daemon/https/tls/gnutls_sig.h36
-rw-r--r--src/daemon/https/tls/gnutls_state.c410
-rw-r--r--src/daemon/https/tls/gnutls_state.h36
-rw-r--r--src/daemon/https/tls/gnutls_str.c42
-rw-r--r--src/daemon/https/tls/gnutls_str.h32
-rw-r--r--src/daemon/https/tls/gnutls_supplemental.c64
-rw-r--r--src/daemon/https/tls/gnutls_supplemental.h6
-rw-r--r--src/daemon/https/tls/gnutls_ui.c190
-rw-r--r--src/daemon/https/tls/gnutls_x509.c424
-rw-r--r--src/daemon/https/tls/gnutls_x509.h18
-rw-r--r--src/daemon/https/tls/pkix_asn1_tab.c2
-rw-r--r--src/daemon/https/tls/x509_b64.c104
-rw-r--r--src/daemon/https/tls/x509_b64.h8
89 files changed, 4435 insertions, 4428 deletions
diff --git a/src/daemon/https/tls/auth_anon.c b/src/daemon/https/tls/auth_anon.c
index d20e55cf..1d6922cc 100644
--- a/src/daemon/https/tls/auth_anon.c
+++ b/src/daemon/https/tls/auth_anon.c
@@ -40,52 +40,52 @@
40#include <gnutls_state.h> 40#include <gnutls_state.h>
41#include <auth_dh_common.h> 41#include <auth_dh_common.h>
42 42
43static int mhd_gtls_gen_anon_server_kx (mhd_gtls_session_t, opaque **); 43static int MHD_gtls_gen_anon_server_kx (MHD_gtls_session_t, opaque **);
44static int mhd_gtls_proc_anon_client_kx (mhd_gtls_session_t, opaque *, 44static int MHD_gtls_proc_anon_client_kx (MHD_gtls_session_t, opaque *,
45 size_t); 45 size_t);
46static int mhd_gtls_proc_anon_server_kx (mhd_gtls_session_t, opaque *, 46static int MHD_gtls_proc_anon_server_kx (MHD_gtls_session_t, opaque *,
47 size_t); 47 size_t);
48 48
49const mhd_gtls_mod_auth_st mhd_gtls_anon_auth_struct = { 49const MHD_gtls_mod_auth_st MHD_gtls_anon_auth_struct = {
50 "ANON", 50 "ANON",
51 NULL, 51 NULL,
52 NULL, 52 NULL,
53 mhd_gtls_gen_anon_server_kx, 53 MHD_gtls_gen_anon_server_kx,
54 mhd_gtls_gen_dh_common_client_kx, /* this can be shared */ 54 MHD_gtls_gen_dh_common_client_kx, /* this can be shared */
55 NULL, 55 NULL,
56 NULL, 56 NULL,
57 57
58 NULL, 58 NULL,
59 NULL, /* certificate */ 59 NULL, /* certificate */
60 mhd_gtls_proc_anon_server_kx, 60 MHD_gtls_proc_anon_server_kx,
61 mhd_gtls_proc_anon_client_kx, 61 MHD_gtls_proc_anon_client_kx,
62 NULL, 62 NULL,
63 NULL 63 NULL
64}; 64};
65 65
66static int 66static int
67mhd_gtls_gen_anon_server_kx (mhd_gtls_session_t session, opaque ** data) 67MHD_gtls_gen_anon_server_kx (MHD_gtls_session_t session, opaque ** data)
68{ 68{
69 mpi_t g, p; 69 mpi_t g, p;
70 const mpi_t *mpis; 70 const mpi_t *mpis;
71 int ret; 71 int ret;
72 mhd_gtls_dh_params_t dh_params; 72 MHD_gtls_dh_params_t dh_params;
73 mhd_gtls_anon_server_credentials_t cred; 73 MHD_gtls_anon_server_credentials_t cred;
74 74
75 cred = (mhd_gtls_anon_server_credentials_t) 75 cred = (MHD_gtls_anon_server_credentials_t)
76 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_ANON, NULL); 76 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_ANON, NULL);
77 if (cred == NULL) 77 if (cred == NULL)
78 { 78 {
79 gnutls_assert (); 79 MHD_gnutls_assert ();
80 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 80 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
81 } 81 }
82 82
83 dh_params = 83 dh_params =
84 mhd_gtls_get_dh_params (cred->dh_params, cred->params_func, session); 84 MHD_gtls_get_dh_params (cred->dh_params, cred->params_func, session);
85 mpis = mhd_gtls_dh_params_to_mpi (dh_params); 85 mpis = MHD_gtls_dh_params_to_mpi (dh_params);
86 if (mpis == NULL) 86 if (mpis == NULL)
87 { 87 {
88 gnutls_assert (); 88 MHD_gnutls_assert ();
89 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS; 89 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
90 } 90 }
91 91
@@ -93,19 +93,19 @@ mhd_gtls_gen_anon_server_kx (mhd_gtls_session_t session, opaque ** data)
93 g = mpis[1]; 93 g = mpis[1];
94 94
95 if ((ret = 95 if ((ret =
96 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON, 96 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON,
97 sizeof (anon_auth_info_st), 1)) < 0) 97 sizeof (anon_auth_info_st), 1)) < 0)
98 { 98 {
99 gnutls_assert (); 99 MHD_gnutls_assert ();
100 return ret; 100 return ret;
101 } 101 }
102 102
103 mhd_gtls_dh_set_group (session, g, p); 103 MHD_gtls_dh_set_group (session, g, p);
104 104
105 ret = mhd_gtls_dh_common_print_server_kx (session, g, p, data, 0); 105 ret = MHD_gtls_dh_common_print_server_kx (session, g, p, data, 0);
106 if (ret < 0) 106 if (ret < 0)
107 { 107 {
108 gnutls_assert (); 108 MHD_gnutls_assert ();
109 } 109 }
110 110
111 return ret; 111 return ret;
@@ -113,46 +113,46 @@ mhd_gtls_gen_anon_server_kx (mhd_gtls_session_t session, opaque ** data)
113 113
114 114
115static int 115static int
116mhd_gtls_proc_anon_client_kx (mhd_gtls_session_t session, opaque * data, 116MHD_gtls_proc_anon_client_kx (MHD_gtls_session_t session, opaque * data,
117 size_t _data_size) 117 size_t _data_size)
118{ 118{
119 mhd_gtls_anon_server_credentials_t cred; 119 MHD_gtls_anon_server_credentials_t cred;
120 int bits; 120 int bits;
121 int ret; 121 int ret;
122 mpi_t p, g; 122 mpi_t p, g;
123 mhd_gtls_dh_params_t dh_params; 123 MHD_gtls_dh_params_t dh_params;
124 const mpi_t *mpis; 124 const mpi_t *mpis;
125 125
126 bits = mhd_gtls_dh_get_allowed_prime_bits (session); 126 bits = MHD_gtls_dh_get_allowed_prime_bits (session);
127 127
128 cred = (mhd_gtls_anon_server_credentials_t) 128 cred = (MHD_gtls_anon_server_credentials_t)
129 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_ANON, NULL); 129 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_ANON, NULL);
130 if (cred == NULL) 130 if (cred == NULL)
131 { 131 {
132 gnutls_assert (); 132 MHD_gnutls_assert ();
133 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 133 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
134 } 134 }
135 135
136 dh_params = 136 dh_params =
137 mhd_gtls_get_dh_params (cred->dh_params, cred->params_func, session); 137 MHD_gtls_get_dh_params (cred->dh_params, cred->params_func, session);
138 mpis = mhd_gtls_dh_params_to_mpi (dh_params); 138 mpis = MHD_gtls_dh_params_to_mpi (dh_params);
139 if (mpis == NULL) 139 if (mpis == NULL)
140 { 140 {
141 gnutls_assert (); 141 MHD_gnutls_assert ();
142 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS; 142 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
143 } 143 }
144 144
145 p = mpis[0]; 145 p = mpis[0];
146 g = mpis[1]; 146 g = mpis[1];
147 147
148 ret = mhd_gtls_proc_dh_common_client_kx (session, data, _data_size, g, p); 148 ret = MHD_gtls_proc_dh_common_client_kx (session, data, _data_size, g, p);
149 149
150 return ret; 150 return ret;
151 151
152} 152}
153 153
154int 154int
155mhd_gtls_proc_anon_server_kx (mhd_gtls_session_t session, opaque * data, 155MHD_gtls_proc_anon_server_kx (MHD_gtls_session_t session, opaque * data,
156 size_t _data_size) 156 size_t _data_size)
157{ 157{
158 158
@@ -160,17 +160,17 @@ mhd_gtls_proc_anon_server_kx (mhd_gtls_session_t session, opaque * data,
160 160
161 /* set auth_info */ 161 /* set auth_info */
162 if ((ret = 162 if ((ret =
163 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON, 163 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON,
164 sizeof (anon_auth_info_st), 1)) < 0) 164 sizeof (anon_auth_info_st), 1)) < 0)
165 { 165 {
166 gnutls_assert (); 166 MHD_gnutls_assert ();
167 return ret; 167 return ret;
168 } 168 }
169 169
170 ret = mhd_gtls_proc_dh_common_server_kx (session, data, _data_size, 0); 170 ret = MHD_gtls_proc_dh_common_server_kx (session, data, _data_size, 0);
171 if (ret < 0) 171 if (ret < 0)
172 { 172 {
173 gnutls_assert (); 173 MHD_gnutls_assert ();
174 return ret; 174 return ret;
175 } 175 }
176 176
diff --git a/src/daemon/https/tls/auth_anon.h b/src/daemon/https/tls/auth_anon.h
index ca5f3bfb..4602ab23 100644
--- a/src/daemon/https/tls/auth_anon.h
+++ b/src/daemon/https/tls/auth_anon.h
@@ -22,27 +22,27 @@
22 * 22 *
23 */ 23 */
24 24
25/* this is not to be included by gnutls_anon.c */ 25/* this is not to be included by MHD_gnutls_anon.c */
26#include <gnutls_auth.h> 26#include <gnutls_auth.h>
27#include <auth_dh_common.h> 27#include <auth_dh_common.h>
28 28
29typedef struct mhd_gtls_anon_server_credentials_st 29typedef struct MHD_gtls_anon_server_credentials_st
30{ 30{
31 mhd_gtls_dh_params_t dh_params; 31 MHD_gtls_dh_params_t dh_params;
32 /* this callback is used to retrieve the DH or RSA 32 /* this callback is used to retrieve the DH or RSA
33 * parameters. 33 * parameters.
34 */ 34 */
35 gnutls_params_function *params_func; 35 MHD_gnutls_params_function *params_func;
36} mhd_anon_server_credentials_st; 36} mhd_anon_server_credentials_st;
37 37
38typedef struct mhd_gtls_anon_client_credentials_st 38typedef struct MHD_gtls_anon_client_credentials_st
39{ 39{
40 int dummy; 40 int dummy;
41} mhd_anon_client_credentials_st; 41} mhd_anon_client_credentials_st;
42 42
43typedef struct mhd_gtls_anon_auth_info_st 43typedef struct MHD_gtls_anon_auth_info_st
44{ 44{
45 mhd_gtls_dh_info_st dh; 45 MHD_gtls_dh_info_st dh;
46} *mhd_anon_auth_info_t; 46} *mhd_anon_auth_info_t;
47 47
48typedef struct mhd_gtls_anon_auth_info_st anon_auth_info_st; 48typedef struct MHD_gtls_anon_auth_info_st anon_auth_info_st;
diff --git a/src/daemon/https/tls/auth_cert.c b/src/daemon/https/tls/auth_cert.c
index 7f0369ca..f3bbeba9 100644
--- a/src/daemon/https/tls/auth_cert.c
+++ b/src/daemon/https/tls/auth_cert.c
@@ -45,17 +45,17 @@
45#include <gnutls_x509.h> 45#include <gnutls_x509.h>
46#include "debug.h" 46#include "debug.h"
47 47
48static gnutls_cert *alloc_and_load_x509_certs (gnutls_x509_crt_t * certs, 48static MHD_gnutls_cert *alloc_and_load_x509_certs (MHD_gnutls_x509_crt_t * certs,
49 unsigned); 49 unsigned);
50static gnutls_privkey *alloc_and_load_x509_key (gnutls_x509_privkey_t key); 50static MHD_gnutls_privkey *alloc_and_load_x509_key (MHD_gnutls_x509_privkey_t key);
51 51
52 52
53/* Copies data from a internal certificate struct (gnutls_cert) to 53/* Copies data from a internal certificate struct (MHD_gnutls_cert) to
54 * exported certificate struct (cert_auth_info_t) 54 * exported certificate struct (cert_auth_info_t)
55 */ 55 */
56static int 56static int
57_gnutls_copy_certificate_auth_info (cert_auth_info_t info, 57MHD__gnutls_copy_certificate_auth_info (cert_auth_info_t info,
58 gnutls_cert * cert, int ncerts) 58 MHD_gnutls_cert * cert, int ncerts)
59{ 59{
60 /* Copy peer's information to auth_info_t 60 /* Copy peer's information to auth_info_t
61 */ 61 */
@@ -69,10 +69,10 @@ _gnutls_copy_certificate_auth_info (cert_auth_info_t info,
69 } 69 }
70 70
71 info->raw_certificate_list = 71 info->raw_certificate_list =
72 gnutls_calloc (1, sizeof (gnutls_datum_t) * ncerts); 72 MHD_gnutls_calloc (1, sizeof (MHD_gnutls_datum_t) * ncerts);
73 if (info->raw_certificate_list == NULL) 73 if (info->raw_certificate_list == NULL)
74 { 74 {
75 gnutls_assert (); 75 MHD_gnutls_assert ();
76 return GNUTLS_E_MEMORY_ERROR; 76 return GNUTLS_E_MEMORY_ERROR;
77 } 77 }
78 78
@@ -81,11 +81,11 @@ _gnutls_copy_certificate_auth_info (cert_auth_info_t info,
81 if (cert->raw.size > 0) 81 if (cert->raw.size > 0)
82 { 82 {
83 ret = 83 ret =
84 _gnutls_set_datum (&info->raw_certificate_list[i], 84 MHD__gnutls_set_datum (&info->raw_certificate_list[i],
85 cert[i].raw.data, cert[i].raw.size); 85 cert[i].raw.data, cert[i].raw.size);
86 if (ret < 0) 86 if (ret < 0)
87 { 87 {
88 gnutls_assert (); 88 MHD_gnutls_assert ();
89 goto clear; 89 goto clear;
90 } 90 }
91 } 91 }
@@ -97,9 +97,9 @@ _gnutls_copy_certificate_auth_info (cert_auth_info_t info,
97clear: 97clear:
98 98
99 for (j = 0; j < i; j++) 99 for (j = 0; j < i; j++)
100 _gnutls_free_datum (&info->raw_certificate_list[j]); 100 MHD__gnutls_free_datum (&info->raw_certificate_list[j]);
101 101
102 gnutls_free (info->raw_certificate_list); 102 MHD_gnutls_free (info->raw_certificate_list);
103 info->raw_certificate_list = NULL; 103 info->raw_certificate_list = NULL;
104 104
105 return ret; 105 return ret;
@@ -112,7 +112,7 @@ clear:
112 * -1 otherwise. 112 * -1 otherwise.
113 */ 113 */
114inline static int 114inline static int
115_gnutls_check_pk_algo_in_list (const enum MHD_GNUTLS_PublicKeyAlgorithm 115MHD__gnutls_check_pk_algo_in_list (const enum MHD_GNUTLS_PublicKeyAlgorithm
116 *pk_algos, int pk_algos_length, 116 *pk_algos, int pk_algos_length,
117 enum MHD_GNUTLS_PublicKeyAlgorithm 117 enum MHD_GNUTLS_PublicKeyAlgorithm
118 algo_to_check) 118 algo_to_check)
@@ -133,39 +133,39 @@ _gnutls_check_pk_algo_in_list (const enum MHD_GNUTLS_PublicKeyAlgorithm
133 * specified in cert. 133 * specified in cert.
134 */ 134 */
135static int 135static int
136_gnutls_cert_get_issuer_dn (gnutls_cert * cert, gnutls_datum_t * odn) 136MHD__gnutls_cert_get_issuer_dn (MHD_gnutls_cert * cert, MHD_gnutls_datum_t * odn)
137{ 137{
138 ASN1_TYPE dn; 138 ASN1_TYPE dn;
139 int len, result; 139 int len, result;
140 int start, end; 140 int start, end;
141 141
142 if ((result = asn1_create_element 142 if ((result = MHD__asn1_create_element
143 (_gnutls_get_pkix (), "PKIX1.Certificate", &dn)) != ASN1_SUCCESS) 143 (MHD__gnutls_get_pkix (), "PKIX1.Certificate", &dn)) != ASN1_SUCCESS)
144 { 144 {
145 gnutls_assert (); 145 MHD_gnutls_assert ();
146 return mhd_gtls_asn2err (result); 146 return MHD_gtls_asn2err (result);
147 } 147 }
148 148
149 result = asn1_der_decoding (&dn, cert->raw.data, cert->raw.size, NULL); 149 result = MHD__asn1_der_decoding (&dn, cert->raw.data, cert->raw.size, NULL);
150 if (result != ASN1_SUCCESS) 150 if (result != ASN1_SUCCESS)
151 { 151 {
152 /* couldn't decode DER */ 152 /* couldn't decode DER */
153 gnutls_assert (); 153 MHD_gnutls_assert ();
154 asn1_delete_structure (&dn); 154 MHD__asn1_delete_structure (&dn);
155 return mhd_gtls_asn2err (result); 155 return MHD_gtls_asn2err (result);
156 } 156 }
157 157
158 result = asn1_der_decoding_startEnd (dn, cert->raw.data, cert->raw.size, 158 result = MHD__asn1_der_decoding_startEnd (dn, cert->raw.data, cert->raw.size,
159 "tbsCertificate.issuer", &start, &end); 159 "tbsCertificate.issuer", &start, &end);
160 160
161 if (result != ASN1_SUCCESS) 161 if (result != ASN1_SUCCESS)
162 { 162 {
163 /* couldn't decode DER */ 163 /* couldn't decode DER */
164 gnutls_assert (); 164 MHD_gnutls_assert ();
165 asn1_delete_structure (&dn); 165 MHD__asn1_delete_structure (&dn);
166 return mhd_gtls_asn2err (result); 166 return MHD_gtls_asn2err (result);
167 } 167 }
168 asn1_delete_structure (&dn); 168 MHD__asn1_delete_structure (&dn);
169 169
170 len = end - start + 1; 170 len = end - start + 1;
171 171
@@ -183,13 +183,13 @@ _gnutls_cert_get_issuer_dn (gnutls_cert * cert, gnutls_datum_t * odn)
183 * CAs and sign algorithms supported by the peer server. 183 * CAs and sign algorithms supported by the peer server.
184 */ 184 */
185static int 185static int
186_find_x509_cert (const mhd_gtls_cert_credentials_t cred, 186_find_x509_cert (const MHD_gtls_cert_credentials_t cred,
187 opaque * _data, size_t _data_size, 187 opaque * _data, size_t _data_size,
188 const enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos, 188 const enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos,
189 int pk_algos_length, int *indx) 189 int pk_algos_length, int *indx)
190{ 190{
191 unsigned size; 191 unsigned size;
192 gnutls_datum_t odn; 192 MHD_gnutls_datum_t odn;
193 opaque *data = _data; 193 opaque *data = _data;
194 ssize_t data_size = _data_size; 194 ssize_t data_size = _data_size;
195 unsigned i, j; 195 unsigned i, j;
@@ -201,7 +201,7 @@ _find_x509_cert (const mhd_gtls_cert_credentials_t cred,
201 { 201 {
202 202
203 DECR_LENGTH_RET (data_size, 2, 0); 203 DECR_LENGTH_RET (data_size, 2, 0);
204 size = mhd_gtls_read_uint16 (data); 204 size = MHD_gtls_read_uint16 (data);
205 DECR_LENGTH_RET (data_size, size, 0); 205 DECR_LENGTH_RET (data_size, size, 0);
206 data += 2; 206 data += 2;
207 207
@@ -210,10 +210,10 @@ _find_x509_cert (const mhd_gtls_cert_credentials_t cred,
210 for (j = 0; j < cred->cert_list_length[i]; j++) 210 for (j = 0; j < cred->cert_list_length[i]; j++)
211 { 211 {
212 if ((result = 212 if ((result =
213 _gnutls_cert_get_issuer_dn (&cred->cert_list[i][j], 213 MHD__gnutls_cert_get_issuer_dn (&cred->cert_list[i][j],
214 &odn)) < 0) 214 &odn)) < 0)
215 { 215 {
216 gnutls_assert (); 216 MHD_gnutls_assert ();
217 return result; 217 return result;
218 } 218 }
219 219
@@ -227,7 +227,7 @@ _find_x509_cert (const mhd_gtls_cert_credentials_t cred,
227 cert_pk = cred->cert_list[i][0].subject_pk_algorithm; 227 cert_pk = cred->cert_list[i][0].subject_pk_algorithm;
228 228
229 if ((memcmp (odn.data, data, size) == 0) && 229 if ((memcmp (odn.data, data, size) == 0) &&
230 (_gnutls_check_pk_algo_in_list 230 (MHD__gnutls_check_pk_algo_in_list
231 (pk_algos, pk_algos_length, cert_pk) == 0)) 231 (pk_algos, pk_algos_length, cert_pk) == 0))
232 { 232 {
233 *indx = i; 233 *indx = i;
@@ -255,7 +255,7 @@ _find_x509_cert (const mhd_gtls_cert_credentials_t cred,
255 * certificate request packet. 255 * certificate request packet.
256 */ 256 */
257static int 257static int
258get_issuers_num (mhd_gtls_session_t session, opaque * data, ssize_t data_size) 258get_issuers_num (MHD_gtls_session_t session, opaque * data, ssize_t data_size)
259{ 259{
260 int issuers_dn_len = 0, result; 260 int issuers_dn_len = 0, result;
261 unsigned size; 261 unsigned size;
@@ -275,7 +275,7 @@ get_issuers_num (mhd_gtls_session_t session, opaque * data, ssize_t data_size)
275 */ 275 */
276 result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 276 result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
277 DECR_LENGTH_COM (data_size, 2, goto error); 277 DECR_LENGTH_COM (data_size, 2, goto error);
278 size = mhd_gtls_read_uint16 (data); 278 size = MHD_gtls_read_uint16 (data);
279 279
280 result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 280 result = GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
281 DECR_LENGTH_COM (data_size, size, goto error); 281 DECR_LENGTH_COM (data_size, size, goto error);
@@ -304,14 +304,14 @@ error:
304 * packet. 304 * packet.
305 */ 305 */
306static int 306static int
307get_issuers (mhd_gtls_session_t session, 307get_issuers (MHD_gtls_session_t session,
308 gnutls_datum_t * issuers_dn, int issuers_len, 308 MHD_gnutls_datum_t * issuers_dn, int issuers_len,
309 opaque * data, size_t data_size) 309 opaque * data, size_t data_size)
310{ 310{
311 int i; 311 int i;
312 unsigned size; 312 unsigned size;
313 313
314 if (gnutls_certificate_type_get (session) != MHD_GNUTLS_CRT_X509) 314 if (MHD_gnutls_certificate_type_get (session) != MHD_GNUTLS_CRT_X509)
315 return 0; 315 return 0;
316 316
317 /* put the requested DNs to req_dn, only in case 317 /* put the requested DNs to req_dn, only in case
@@ -328,7 +328,7 @@ get_issuers (mhd_gtls_session_t session,
328 */ 328 */
329 data_size -= 2; 329 data_size -= 2;
330 330
331 size = mhd_gtls_read_uint16 (data); 331 size = MHD_gtls_read_uint16 (data);
332 332
333 data += 2; 333 data += 2;
334 334
@@ -345,26 +345,26 @@ get_issuers (mhd_gtls_session_t session,
345/* Calls the client get callback. 345/* Calls the client get callback.
346 */ 346 */
347static int 347static int
348call_get_cert_callback (mhd_gtls_session_t session, 348call_get_cert_callback (MHD_gtls_session_t session,
349 gnutls_datum_t * issuers_dn, 349 MHD_gnutls_datum_t * issuers_dn,
350 int issuers_dn_length, 350 int issuers_dn_length,
351 enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos, 351 enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos,
352 int pk_algos_length) 352 int pk_algos_length)
353{ 353{
354 unsigned i; 354 unsigned i;
355 gnutls_cert *local_certs = NULL; 355 MHD_gnutls_cert *local_certs = NULL;
356 gnutls_privkey *local_key = NULL; 356 MHD_gnutls_privkey *local_key = NULL;
357 gnutls_retr_st st; 357 MHD_gnutls_retr_st st;
358 int ret; 358 int ret;
359 enum MHD_GNUTLS_CertificateType type = 359 enum MHD_GNUTLS_CertificateType type =
360 gnutls_certificate_type_get (session); 360 MHD_gnutls_certificate_type_get (session);
361 mhd_gtls_cert_credentials_t cred; 361 MHD_gtls_cert_credentials_t cred;
362 362
363 cred = (mhd_gtls_cert_credentials_t) 363 cred = (MHD_gtls_cert_credentials_t)
364 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 364 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
365 if (cred == NULL) 365 if (cred == NULL)
366 { 366 {
367 gnutls_assert (); 367 MHD_gnutls_assert ();
368 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 368 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
369 } 369 }
370 370
@@ -384,7 +384,7 @@ call_get_cert_callback (mhd_gtls_session_t session,
384 384
385 if (ret < 0) 385 if (ret < 0)
386 { 386 {
387 gnutls_assert (); 387 MHD_gnutls_assert ();
388 return GNUTLS_E_INTERNAL_ERROR; 388 return GNUTLS_E_INTERNAL_ERROR;
389 } 389 }
390 390
@@ -393,7 +393,7 @@ call_get_cert_callback (mhd_gtls_session_t session,
393 393
394 if (type != st.type) 394 if (type != st.type)
395 { 395 {
396 gnutls_assert (); 396 MHD_gnutls_assert ();
397 ret = GNUTLS_E_INVALID_REQUEST; 397 ret = GNUTLS_E_INVALID_REQUEST;
398 goto cleanup; 398 goto cleanup;
399 } 399 }
@@ -407,12 +407,12 @@ call_get_cert_callback (mhd_gtls_session_t session,
407 } 407 }
408 else 408 else
409 { /* PGP */ 409 { /* PGP */
410 gnutls_assert (); 410 MHD_gnutls_assert ();
411 ret = GNUTLS_E_INVALID_REQUEST; 411 ret = GNUTLS_E_INVALID_REQUEST;
412 goto cleanup; 412 goto cleanup;
413 } 413 }
414 414
415 mhd_gtls_selected_certs_set (session, local_certs, 415 MHD_gtls_selected_certs_set (session, local_certs,
416 (local_certs != NULL) ? st.ncerts : 0, 416 (local_certs != NULL) ? st.ncerts : 0,
417 local_key, 1); 417 local_key, 1);
418 418
@@ -426,10 +426,10 @@ cleanup:
426 { 426 {
427 for (i = 0; i < st.ncerts; i++) 427 for (i = 0; i < st.ncerts; i++)
428 { 428 {
429 gnutls_x509_crt_deinit (st.cert.x509[i]); 429 MHD_gnutls_x509_crt_deinit (st.cert.x509[i]);
430 } 430 }
431 gnutls_free (st.cert.x509); 431 MHD_gnutls_free (st.cert.x509);
432 gnutls_x509_privkey_deinit (st.key.x509); 432 MHD_gnutls_x509_privkey_deinit (st.key.x509);
433 } 433 }
434 } 434 }
435 return ret; 435 return ret;
@@ -443,24 +443,24 @@ cleanup:
443 * algorithm (only in automatic mode). 443 * algorithm (only in automatic mode).
444 */ 444 */
445static int 445static int
446_select_client_cert (mhd_gtls_session_t session, 446_select_client_cert (MHD_gtls_session_t session,
447 opaque * _data, size_t _data_size, 447 opaque * _data, size_t _data_size,
448 enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos, 448 enum MHD_GNUTLS_PublicKeyAlgorithm *pk_algos,
449 int pk_algos_length) 449 int pk_algos_length)
450{ 450{
451 int result; 451 int result;
452 int indx = -1; 452 int indx = -1;
453 mhd_gtls_cert_credentials_t cred; 453 MHD_gtls_cert_credentials_t cred;
454 opaque *data = _data; 454 opaque *data = _data;
455 ssize_t data_size = _data_size; 455 ssize_t data_size = _data_size;
456 int issuers_dn_length; 456 int issuers_dn_length;
457 gnutls_datum_t *issuers_dn = NULL; 457 MHD_gnutls_datum_t *issuers_dn = NULL;
458 458
459 cred = (mhd_gtls_cert_credentials_t) 459 cred = (MHD_gtls_cert_credentials_t)
460 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 460 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
461 if (cred == NULL) 461 if (cred == NULL)
462 { 462 {
463 gnutls_assert (); 463 MHD_gnutls_assert ();
464 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 464 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
465 } 465 }
466 466
@@ -476,17 +476,17 @@ _select_client_cert (mhd_gtls_session_t session,
476 issuers_dn_length = get_issuers_num (session, data, data_size); 476 issuers_dn_length = get_issuers_num (session, data, data_size);
477 if (issuers_dn_length < 0) 477 if (issuers_dn_length < 0)
478 { 478 {
479 gnutls_assert (); 479 MHD_gnutls_assert ();
480 return issuers_dn_length; 480 return issuers_dn_length;
481 } 481 }
482 482
483 if (issuers_dn_length > 0) 483 if (issuers_dn_length > 0)
484 { 484 {
485 issuers_dn = 485 issuers_dn =
486 gnutls_malloc (sizeof (gnutls_datum_t) * issuers_dn_length); 486 MHD_gnutls_malloc (sizeof (MHD_gnutls_datum_t) * issuers_dn_length);
487 if (issuers_dn == NULL) 487 if (issuers_dn == NULL)
488 { 488 {
489 gnutls_assert (); 489 MHD_gnutls_assert ();
490 return GNUTLS_E_MEMORY_ERROR; 490 return GNUTLS_E_MEMORY_ERROR;
491 } 491 }
492 492
@@ -495,7 +495,7 @@ _select_client_cert (mhd_gtls_session_t session,
495 data, data_size); 495 data, data_size);
496 if (result < 0) 496 if (result < 0)
497 { 497 {
498 gnutls_assert (); 498 MHD_gnutls_assert ();
499 goto cleanup; 499 goto cleanup;
500 } 500 }
501 } 501 }
@@ -519,27 +519,27 @@ _select_client_cert (mhd_gtls_session_t session,
519 pk_algos, pk_algos_length, &indx); 519 pk_algos, pk_algos_length, &indx);
520 if (result < 0) 520 if (result < 0)
521 { 521 {
522 gnutls_assert (); 522 MHD_gnutls_assert ();
523 return result; 523 return result;
524 } 524 }
525 525
526 if (indx >= 0) 526 if (indx >= 0)
527 { 527 {
528 mhd_gtls_selected_certs_set (session, 528 MHD_gtls_selected_certs_set (session,
529 &cred->cert_list[indx][0], 529 &cred->cert_list[indx][0],
530 cred->cert_list_length[indx], 530 cred->cert_list_length[indx],
531 &cred->pkey[indx], 0); 531 &cred->pkey[indx], 0);
532 } 532 }
533 else 533 else
534 { 534 {
535 mhd_gtls_selected_certs_set (session, NULL, 0, NULL, 0); 535 MHD_gtls_selected_certs_set (session, NULL, 0, NULL, 0);
536 } 536 }
537 537
538 result = 0; 538 result = 0;
539 } 539 }
540 540
541cleanup: 541cleanup:
542 gnutls_free (issuers_dn); 542 MHD_gnutls_free (issuers_dn);
543 return result; 543 return result;
544 544
545} 545}
@@ -548,21 +548,21 @@ cleanup:
548 */ 548 */
549 549
550int 550int
551mhd_gtls_gen_x509_crt (mhd_gtls_session_t session, opaque ** data) 551MHD_gtls_gen_x509_crt (MHD_gtls_session_t session, opaque ** data)
552{ 552{
553 int ret, i; 553 int ret, i;
554 opaque *pdata; 554 opaque *pdata;
555 gnutls_cert *apr_cert_list; 555 MHD_gnutls_cert *apr_cert_list;
556 gnutls_privkey *apr_pkey; 556 MHD_gnutls_privkey *apr_pkey;
557 int apr_cert_list_length; 557 int apr_cert_list_length;
558 558
559 /* find the appropriate certificate 559 /* find the appropriate certificate
560 */ 560 */
561 if ((ret = 561 if ((ret =
562 mhd_gtls_get_selected_cert (session, &apr_cert_list, 562 MHD_gtls_get_selected_cert (session, &apr_cert_list,
563 &apr_cert_list_length, &apr_pkey)) < 0) 563 &apr_cert_list_length, &apr_pkey)) < 0)
564 { 564 {
565 gnutls_assert (); 565 MHD_gnutls_assert ();
566 return ret; 566 return ret;
567 } 567 }
568 568
@@ -583,19 +583,19 @@ mhd_gtls_gen_x509_crt (mhd_gtls_session_t session, opaque ** data)
583 * the one produced here ) 583 * the one produced here )
584 */ 584 */
585 585
586 (*data) = gnutls_malloc (ret); 586 (*data) = MHD_gnutls_malloc (ret);
587 pdata = (*data); 587 pdata = (*data);
588 588
589 if (pdata == NULL) 589 if (pdata == NULL)
590 { 590 {
591 gnutls_assert (); 591 MHD_gnutls_assert ();
592 return GNUTLS_E_MEMORY_ERROR; 592 return GNUTLS_E_MEMORY_ERROR;
593 } 593 }
594 mhd_gtls_write_uint24 (ret - 3, pdata); 594 MHD_gtls_write_uint24 (ret - 3, pdata);
595 pdata += 3; 595 pdata += 3;
596 for (i = 0; i < apr_cert_list_length; i++) 596 for (i = 0; i < apr_cert_list_length; i++)
597 { 597 {
598 mhd_gtls_write_datum24 (pdata, apr_cert_list[i].raw); 598 MHD_gtls_write_datum24 (pdata, apr_cert_list[i].raw);
599 pdata += (3 + apr_cert_list[i].raw.size); 599 pdata += (3 + apr_cert_list[i].raw.size);
600 } 600 }
601 601
@@ -603,30 +603,30 @@ mhd_gtls_gen_x509_crt (mhd_gtls_session_t session, opaque ** data)
603} 603}
604 604
605int 605int
606mhd_gtls_gen_cert_client_certificate (mhd_gtls_session_t session, 606MHD_gtls_gen_cert_client_certificate (MHD_gtls_session_t session,
607 opaque ** data) 607 opaque ** data)
608{ 608{
609 switch (session->security_parameters.cert_type) 609 switch (session->security_parameters.cert_type)
610 { 610 {
611 case MHD_GNUTLS_CRT_X509: 611 case MHD_GNUTLS_CRT_X509:
612 return mhd_gtls_gen_x509_crt (session, data); 612 return MHD_gtls_gen_x509_crt (session, data);
613 613
614 default: 614 default:
615 gnutls_assert (); 615 MHD_gnutls_assert ();
616 return GNUTLS_E_INTERNAL_ERROR; 616 return GNUTLS_E_INTERNAL_ERROR;
617 } 617 }
618} 618}
619 619
620int 620int
621mhd_gtls_gen_cert_server_certificate (mhd_gtls_session_t session, 621MHD_gtls_gen_cert_server_certificate (MHD_gtls_session_t session,
622 opaque ** data) 622 opaque ** data)
623{ 623{
624 switch (session->security_parameters.cert_type) 624 switch (session->security_parameters.cert_type)
625 { 625 {
626 case MHD_GNUTLS_CRT_X509: 626 case MHD_GNUTLS_CRT_X509:
627 return mhd_gtls_gen_x509_crt (session, data); 627 return MHD_gtls_gen_x509_crt (session, data);
628 default: 628 default:
629 gnutls_assert (); 629 MHD_gnutls_assert ();
630 return GNUTLS_E_INTERNAL_ERROR; 630 return GNUTLS_E_INTERNAL_ERROR;
631 } 631 }
632} 632}
@@ -634,49 +634,49 @@ mhd_gtls_gen_cert_server_certificate (mhd_gtls_session_t session,
634/* Process server certificate 634/* Process server certificate
635 */ 635 */
636 636
637#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) mhd_gtls_gcert_deinit(&peer_certificate_list[x]) 637#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) MHD_gtls_gcert_deinit(&peer_certificate_list[x])
638int 638int
639mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session, 639MHD_gtls_proc_x509_server_certificate (MHD_gtls_session_t session,
640 opaque * data, size_t data_size) 640 opaque * data, size_t data_size)
641{ 641{
642 int size, len, ret; 642 int size, len, ret;
643 opaque *p = data; 643 opaque *p = data;
644 cert_auth_info_t info; 644 cert_auth_info_t info;
645 mhd_gtls_cert_credentials_t cred; 645 MHD_gtls_cert_credentials_t cred;
646 ssize_t dsize = data_size; 646 ssize_t dsize = data_size;
647 int i, j, x; 647 int i, j, x;
648 gnutls_cert *peer_certificate_list; 648 MHD_gnutls_cert *peer_certificate_list;
649 int peer_certificate_list_size = 0; 649 int peer_certificate_list_size = 0;
650 gnutls_datum_t tmp; 650 MHD_gnutls_datum_t tmp;
651 651
652 cred = (mhd_gtls_cert_credentials_t) 652 cred = (MHD_gtls_cert_credentials_t)
653 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 653 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
654 if (cred == NULL) 654 if (cred == NULL)
655 { 655 {
656 gnutls_assert (); 656 MHD_gnutls_assert ();
657 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 657 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
658 } 658 }
659 659
660 660
661 if ((ret = 661 if ((ret =
662 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE, 662 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE,
663 sizeof (cert_auth_info_st), 1)) < 0) 663 sizeof (cert_auth_info_st), 1)) < 0)
664 { 664 {
665 gnutls_assert (); 665 MHD_gnutls_assert ();
666 return ret; 666 return ret;
667 } 667 }
668 668
669 info = mhd_gtls_get_auth_info (session); 669 info = MHD_gtls_get_auth_info (session);
670 670
671 if (data == NULL || data_size == 0) 671 if (data == NULL || data_size == 0)
672 { 672 {
673 gnutls_assert (); 673 MHD_gnutls_assert ();
674 /* no certificate was sent */ 674 /* no certificate was sent */
675 return GNUTLS_E_NO_CERTIFICATE_FOUND; 675 return GNUTLS_E_NO_CERTIFICATE_FOUND;
676 } 676 }
677 677
678 DECR_LEN (dsize, 3); 678 DECR_LEN (dsize, 3);
679 size = mhd_gtls_read_uint24 (p); 679 size = MHD_gtls_read_uint24 (p);
680 p += 3; 680 p += 3;
681 681
682 /* some implementations send 0B 00 00 06 00 00 03 00 00 00 682 /* some implementations send 0B 00 00 06 00 00 03 00 00 00
@@ -684,7 +684,7 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
684 */ 684 */
685 if (size == 0 || size == 3) 685 if (size == 0 || size == 3)
686 { 686 {
687 gnutls_assert (); 687 MHD_gnutls_assert ();
688 /* no certificate was sent */ 688 /* no certificate was sent */
689 return GNUTLS_E_NO_CERTIFICATE_FOUND; 689 return GNUTLS_E_NO_CERTIFICATE_FOUND;
690 } 690 }
@@ -693,7 +693,7 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
693 while (i > 0) 693 while (i > 0)
694 { 694 {
695 DECR_LEN (dsize, 3); 695 DECR_LEN (dsize, 3);
696 len = mhd_gtls_read_uint24 (p); 696 len = MHD_gtls_read_uint24 (p);
697 p += 3; 697 p += 3;
698 DECR_LEN (dsize, len); 698 DECR_LEN (dsize, len);
699 peer_certificate_list_size++; 699 peer_certificate_list_size++;
@@ -703,7 +703,7 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
703 703
704 if (peer_certificate_list_size == 0) 704 if (peer_certificate_list_size == 0)
705 { 705 {
706 gnutls_assert (); 706 MHD_gnutls_assert ();
707 return GNUTLS_E_NO_CERTIFICATE_FOUND; 707 return GNUTLS_E_NO_CERTIFICATE_FOUND;
708 } 708 }
709 709
@@ -712,14 +712,14 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
712 */ 712 */
713 713
714 peer_certificate_list = 714 peer_certificate_list =
715 gnutls_malloc (sizeof (gnutls_cert) * (peer_certificate_list_size)); 715 MHD_gnutls_malloc (sizeof (MHD_gnutls_cert) * (peer_certificate_list_size));
716 716
717 if (peer_certificate_list == NULL) 717 if (peer_certificate_list == NULL)
718 { 718 {
719 gnutls_assert (); 719 MHD_gnutls_assert ();
720 return GNUTLS_E_MEMORY_ERROR; 720 return GNUTLS_E_MEMORY_ERROR;
721 } 721 }
722 memset (peer_certificate_list, 0, sizeof (gnutls_cert) * 722 memset (peer_certificate_list, 0, sizeof (MHD_gnutls_cert) *
723 peer_certificate_list_size); 723 peer_certificate_list_size);
724 724
725 p = data + 3; 725 p = data + 3;
@@ -731,18 +731,18 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
731 731
732 for (j = 0; j < peer_certificate_list_size; j++) 732 for (j = 0; j < peer_certificate_list_size; j++)
733 { 733 {
734 len = mhd_gtls_read_uint24 (p); 734 len = MHD_gtls_read_uint24 (p);
735 p += 3; 735 p += 3;
736 736
737 tmp.size = len; 737 tmp.size = len;
738 tmp.data = p; 738 tmp.data = p;
739 739
740 if ((ret = 740 if ((ret =
741 mhd_gtls_x509_raw_cert_to_gcert (&peer_certificate_list 741 MHD_gtls_x509_raw_cert_to_gcert (&peer_certificate_list
742 [j], &tmp, 742 [j], &tmp,
743 CERT_ONLY_EXTENSIONS)) < 0) 743 CERT_ONLY_EXTENSIONS)) < 0)
744 { 744 {
745 gnutls_assert (); 745 MHD_gnutls_assert ();
746 goto cleanup; 746 goto cleanup;
747 } 747 }
748 748
@@ -751,19 +751,19 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
751 751
752 752
753 if ((ret = 753 if ((ret =
754 _gnutls_copy_certificate_auth_info (info, 754 MHD__gnutls_copy_certificate_auth_info (info,
755 peer_certificate_list, 755 peer_certificate_list,
756 peer_certificate_list_size)) < 0) 756 peer_certificate_list_size)) < 0)
757 { 757 {
758 gnutls_assert (); 758 MHD_gnutls_assert ();
759 goto cleanup; 759 goto cleanup;
760 } 760 }
761 761
762 if ((ret = 762 if ((ret =
763 _gnutls_check_key_usage (&peer_certificate_list[0], 763 MHD__gnutls_check_key_usage (&peer_certificate_list[0],
764 gnutls_kx_get (session))) < 0) 764 MHD_gnutls_kx_get (session))) < 0)
765 { 765 {
766 gnutls_assert (); 766 MHD_gnutls_assert ();
767 goto cleanup; 767 goto cleanup;
768 } 768 }
769 769
@@ -771,23 +771,23 @@ mhd_gtls_proc_x509_server_certificate (mhd_gtls_session_t session,
771 771
772cleanup: 772cleanup:
773 CLEAR_CERTS; 773 CLEAR_CERTS;
774 gnutls_free (peer_certificate_list); 774 MHD_gnutls_free (peer_certificate_list);
775 return ret; 775 return ret;
776 776
777} 777}
778 778
779#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) mhd_gtls_gcert_deinit(&peer_certificate_list[x]) 779#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) MHD_gtls_gcert_deinit(&peer_certificate_list[x])
780 780
781int 781int
782mhd_gtls_proc_cert_server_certificate (mhd_gtls_session_t session, 782MHD_gtls_proc_cert_server_certificate (MHD_gtls_session_t session,
783 opaque * data, size_t data_size) 783 opaque * data, size_t data_size)
784{ 784{
785 switch (session->security_parameters.cert_type) 785 switch (session->security_parameters.cert_type)
786 { 786 {
787 case MHD_GNUTLS_CRT_X509: 787 case MHD_GNUTLS_CRT_X509:
788 return mhd_gtls_proc_x509_server_certificate (session, data, data_size); 788 return MHD_gtls_proc_x509_server_certificate (session, data, data_size);
789 default: 789 default:
790 gnutls_assert (); 790 MHD_gnutls_assert ();
791 return GNUTLS_E_INTERNAL_ERROR; 791 return GNUTLS_E_INTERNAL_ERROR;
792 } 792 }
793} 793}
@@ -802,7 +802,7 @@ typedef enum CertificateSigType
802 * if true; 802 * if true;
803 */ 803 */
804inline static int 804inline static int
805_gnutls_check_supported_sign_algo (CertificateSigType algo) 805MHD__gnutls_check_supported_sign_algo (CertificateSigType algo)
806{ 806{
807 switch (algo) 807 switch (algo)
808 { 808 {
@@ -814,31 +814,31 @@ _gnutls_check_supported_sign_algo (CertificateSigType algo)
814} 814}
815 815
816int 816int
817mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data, 817MHD_gtls_proc_cert_cert_req (MHD_gtls_session_t session, opaque * data,
818 size_t data_size) 818 size_t data_size)
819{ 819{
820 int size, ret; 820 int size, ret;
821 opaque *p; 821 opaque *p;
822 mhd_gtls_cert_credentials_t cred; 822 MHD_gtls_cert_credentials_t cred;
823 ssize_t dsize; 823 ssize_t dsize;
824 int i, j; 824 int i, j;
825 enum MHD_GNUTLS_PublicKeyAlgorithm pk_algos[MAX_SIGN_ALGOS]; 825 enum MHD_GNUTLS_PublicKeyAlgorithm pk_algos[MAX_SIGN_ALGOS];
826 int pk_algos_length; 826 int pk_algos_length;
827 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 827 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
828 828
829 cred = (mhd_gtls_cert_credentials_t) 829 cred = (MHD_gtls_cert_credentials_t)
830 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 830 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
831 if (cred == NULL) 831 if (cred == NULL)
832 { 832 {
833 gnutls_assert (); 833 MHD_gnutls_assert ();
834 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 834 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
835 } 835 }
836 836
837 if ((ret = 837 if ((ret =
838 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE, 838 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE,
839 sizeof (cert_auth_info_st), 0)) < 0) 839 sizeof (cert_auth_info_st), 0)) < 0)
840 { 840 {
841 gnutls_assert (); 841 MHD_gnutls_assert ();
842 return ret; 842 return ret;
843 } 843 }
844 844
@@ -854,7 +854,7 @@ mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data,
854 for (i = 0; i < size; i++, p++) 854 for (i = 0; i < size; i++, p++)
855 { 855 {
856 DECR_LEN (dsize, 1); 856 DECR_LEN (dsize, 1);
857 if ((ret = _gnutls_check_supported_sign_algo (*p)) > 0) 857 if ((ret = MHD__gnutls_check_supported_sign_algo (*p)) > 0)
858 { 858 {
859 if (j < MAX_SIGN_ALGOS) 859 if (j < MAX_SIGN_ALGOS)
860 { 860 {
@@ -866,7 +866,7 @@ mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data,
866 866
867 if (pk_algos_length == 0) 867 if (pk_algos_length == 0)
868 { 868 {
869 gnutls_assert (); 869 MHD_gnutls_assert ();
870 return GNUTLS_E_UNKNOWN_PK_ALGORITHM; 870 return GNUTLS_E_UNKNOWN_PK_ALGORITHM;
871 } 871 }
872 872
@@ -885,7 +885,7 @@ mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data,
885 885
886 /* read the certificate authorities */ 886 /* read the certificate authorities */
887 DECR_LEN (dsize, 2); 887 DECR_LEN (dsize, 2);
888 size = mhd_gtls_read_uint16 (p); 888 size = MHD_gtls_read_uint16 (p);
889 p += 2; 889 p += 2;
890 890
891 DECR_LEN (dsize, size); 891 DECR_LEN (dsize, size);
@@ -896,7 +896,7 @@ mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data,
896 if ((ret = 896 if ((ret =
897 _select_client_cert (session, p, size, pk_algos, pk_algos_length)) < 0) 897 _select_client_cert (session, p, size, pk_algos, pk_algos_length)) < 0)
898 { 898 {
899 gnutls_assert (); 899 MHD_gnutls_assert ();
900 return ret; 900 return ret;
901 } 901 }
902 902
@@ -909,34 +909,34 @@ mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t session, opaque * data,
909} 909}
910 910
911int 911int
912mhd_gtls_gen_cert_client_cert_vrfy (mhd_gtls_session_t session, 912MHD_gtls_gen_cert_client_cert_vrfy (MHD_gtls_session_t session,
913 opaque ** data) 913 opaque ** data)
914{ 914{
915 int ret; 915 int ret;
916 gnutls_cert *apr_cert_list; 916 MHD_gnutls_cert *apr_cert_list;
917 gnutls_privkey *apr_pkey; 917 MHD_gnutls_privkey *apr_pkey;
918 int apr_cert_list_length, size; 918 int apr_cert_list_length, size;
919 gnutls_datum_t signature; 919 MHD_gnutls_datum_t signature;
920 920
921 *data = NULL; 921 *data = NULL;
922 922
923 /* find the appropriate certificate */ 923 /* find the appropriate certificate */
924 if ((ret = 924 if ((ret =
925 mhd_gtls_get_selected_cert (session, &apr_cert_list, 925 MHD_gtls_get_selected_cert (session, &apr_cert_list,
926 &apr_cert_list_length, &apr_pkey)) < 0) 926 &apr_cert_list_length, &apr_pkey)) < 0)
927 { 927 {
928 gnutls_assert (); 928 MHD_gnutls_assert ();
929 return ret; 929 return ret;
930 } 930 }
931 931
932 if (apr_cert_list_length > 0) 932 if (apr_cert_list_length > 0)
933 { 933 {
934 if ((ret = 934 if ((ret =
935 mhd_gtls_tls_sign_hdata (session, 935 MHD_gtls_tls_sign_hdata (session,
936 &apr_cert_list[0], 936 &apr_cert_list[0],
937 apr_pkey, &signature)) < 0) 937 apr_pkey, &signature)) < 0)
938 { 938 {
939 gnutls_assert (); 939 MHD_gnutls_assert ();
940 return ret; 940 return ret;
941 } 941 }
942 } 942 }
@@ -945,42 +945,42 @@ mhd_gtls_gen_cert_client_cert_vrfy (mhd_gtls_session_t session,
945 return 0; 945 return 0;
946 } 946 }
947 947
948 *data = gnutls_malloc (signature.size + 2); 948 *data = MHD_gnutls_malloc (signature.size + 2);
949 if (*data == NULL) 949 if (*data == NULL)
950 { 950 {
951 _gnutls_free_datum (&signature); 951 MHD__gnutls_free_datum (&signature);
952 return GNUTLS_E_MEMORY_ERROR; 952 return GNUTLS_E_MEMORY_ERROR;
953 } 953 }
954 size = signature.size; 954 size = signature.size;
955 mhd_gtls_write_uint16 (size, *data); 955 MHD_gtls_write_uint16 (size, *data);
956 956
957 memcpy (&(*data)[2], signature.data, size); 957 memcpy (&(*data)[2], signature.data, size);
958 958
959 _gnutls_free_datum (&signature); 959 MHD__gnutls_free_datum (&signature);
960 960
961 return size + 2; 961 return size + 2;
962} 962}
963 963
964int 964int
965mhd_gtls_proc_cert_client_cert_vrfy (mhd_gtls_session_t session, 965MHD_gtls_proc_cert_client_cert_vrfy (MHD_gtls_session_t session,
966 opaque * data, size_t data_size) 966 opaque * data, size_t data_size)
967{ 967{
968 int size, ret; 968 int size, ret;
969 ssize_t dsize = data_size; 969 ssize_t dsize = data_size;
970 opaque *pdata = data; 970 opaque *pdata = data;
971 gnutls_datum_t sig; 971 MHD_gnutls_datum_t sig;
972 cert_auth_info_t info = mhd_gtls_get_auth_info (session); 972 cert_auth_info_t info = MHD_gtls_get_auth_info (session);
973 gnutls_cert peer_cert; 973 MHD_gnutls_cert peer_cert;
974 974
975 if (info == NULL || info->ncerts == 0) 975 if (info == NULL || info->ncerts == 0)
976 { 976 {
977 gnutls_assert (); 977 MHD_gnutls_assert ();
978 /* we need this in order to get peer's certificate */ 978 /* we need this in order to get peer's certificate */
979 return GNUTLS_E_INTERNAL_ERROR; 979 return GNUTLS_E_INTERNAL_ERROR;
980 } 980 }
981 981
982 DECR_LEN (dsize, 2); 982 DECR_LEN (dsize, 2);
983 size = mhd_gtls_read_uint16 (pdata); 983 size = MHD_gtls_read_uint16 (pdata);
984 pdata += 2; 984 pdata += 2;
985 985
986 DECR_LEN (dsize, size); 986 DECR_LEN (dsize, size);
@@ -988,47 +988,47 @@ mhd_gtls_proc_cert_client_cert_vrfy (mhd_gtls_session_t session,
988 sig.data = pdata; 988 sig.data = pdata;
989 sig.size = size; 989 sig.size = size;
990 990
991 ret = mhd_gtls_raw_cert_to_gcert (&peer_cert, 991 ret = MHD_gtls_raw_cert_to_gcert (&peer_cert,
992 session->security_parameters.cert_type, 992 session->security_parameters.cert_type,
993 &info->raw_certificate_list[0], 993 &info->raw_certificate_list[0],
994 CERT_NO_COPY); 994 CERT_NO_COPY);
995 995
996 if (ret < 0) 996 if (ret < 0)
997 { 997 {
998 gnutls_assert (); 998 MHD_gnutls_assert ();
999 return ret; 999 return ret;
1000 } 1000 }
1001 1001
1002 if ((ret = mhd_gtls_verify_sig_hdata (session, &peer_cert, &sig)) < 0) 1002 if ((ret = MHD_gtls_verify_sig_hdata (session, &peer_cert, &sig)) < 0)
1003 { 1003 {
1004 gnutls_assert (); 1004 MHD_gnutls_assert ();
1005 mhd_gtls_gcert_deinit (&peer_cert); 1005 MHD_gtls_gcert_deinit (&peer_cert);
1006 return ret; 1006 return ret;
1007 } 1007 }
1008 mhd_gtls_gcert_deinit (&peer_cert); 1008 MHD_gtls_gcert_deinit (&peer_cert);
1009 1009
1010 return 0; 1010 return 0;
1011} 1011}
1012 1012
1013#define CERTTYPE_SIZE 3 1013#define CERTTYPE_SIZE 3
1014int 1014int
1015mhd_gtls_gen_cert_server_cert_req (mhd_gtls_session_t session, opaque ** data) 1015MHD_gtls_gen_cert_server_cert_req (MHD_gtls_session_t session, opaque ** data)
1016{ 1016{
1017 mhd_gtls_cert_credentials_t cred; 1017 MHD_gtls_cert_credentials_t cred;
1018 int size; 1018 int size;
1019 opaque *pdata; 1019 opaque *pdata;
1020 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 1020 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
1021 1021
1022 /* Now we need to generate the RDN sequence. This is 1022 /* Now we need to generate the RDN sequence. This is
1023 * already in the CERTIFICATE_CRED structure, to improve 1023 * already in the CERTIFICATE_CRED structure, to improve
1024 * performance. 1024 * performance.
1025 */ 1025 */
1026 1026
1027 cred = (mhd_gtls_cert_credentials_t) 1027 cred = (MHD_gtls_cert_credentials_t)
1028 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 1028 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
1029 if (cred == NULL) 1029 if (cred == NULL)
1030 { 1030 {
1031 gnutls_assert (); 1031 MHD_gnutls_assert ();
1032 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 1032 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
1033 } 1033 }
1034 1034
@@ -1044,12 +1044,12 @@ mhd_gtls_gen_cert_server_cert_req (mhd_gtls_session_t session, opaque ** data)
1044 functions (see below). */ 1044 functions (see below). */
1045 size += 1; 1045 size += 1;
1046 1046
1047 (*data) = gnutls_malloc (size); 1047 (*data) = MHD_gnutls_malloc (size);
1048 pdata = (*data); 1048 pdata = (*data);
1049 1049
1050 if (pdata == NULL) 1050 if (pdata == NULL)
1051 { 1051 {
1052 gnutls_assert (); 1052 MHD_gnutls_assert ();
1053 return GNUTLS_E_MEMORY_ERROR; 1053 return GNUTLS_E_MEMORY_ERROR;
1054 } 1054 }
1055 1055
@@ -1069,12 +1069,12 @@ mhd_gtls_gen_cert_server_cert_req (mhd_gtls_session_t session, opaque ** data)
1069 if (session->security_parameters.cert_type == MHD_GNUTLS_CRT_X509 && 1069 if (session->security_parameters.cert_type == MHD_GNUTLS_CRT_X509 &&
1070 session->internals.ignore_rdn_sequence == 0) 1070 session->internals.ignore_rdn_sequence == 0)
1071 { 1071 {
1072 mhd_gtls_write_datum16 (pdata, cred->x509_rdn_sequence); 1072 MHD_gtls_write_datum16 (pdata, cred->x509_rdn_sequence);
1073 /* pdata += cred->x509_rdn_sequence.size + 2; */ 1073 /* pdata += cred->x509_rdn_sequence.size + 2; */
1074 } 1074 }
1075 else 1075 else
1076 { 1076 {
1077 mhd_gtls_write_uint16 (0, pdata); 1077 MHD_gtls_write_uint16 (0, pdata);
1078 /* pdata+=2; */ 1078 /* pdata+=2; */
1079 } 1079 }
1080 1080
@@ -1090,10 +1090,10 @@ mhd_gtls_gen_cert_server_cert_req (mhd_gtls_session_t session, opaque ** data)
1090 * 1090 *
1091 */ 1091 */
1092int 1092int
1093mhd_gtls_get_selected_cert (mhd_gtls_session_t session, 1093MHD_gtls_get_selected_cert (MHD_gtls_session_t session,
1094 gnutls_cert ** apr_cert_list, 1094 MHD_gnutls_cert ** apr_cert_list,
1095 int *apr_cert_list_length, 1095 int *apr_cert_list_length,
1096 gnutls_privkey ** apr_pkey) 1096 MHD_gnutls_privkey ** apr_pkey)
1097{ 1097{
1098 if (session->security_parameters.entity == GNUTLS_SERVER) 1098 if (session->security_parameters.entity == GNUTLS_SERVER)
1099 { 1099 {
@@ -1107,7 +1107,7 @@ mhd_gtls_get_selected_cert (mhd_gtls_session_t session,
1107 1107
1108 if (*apr_cert_list_length == 0 || *apr_cert_list == NULL) 1108 if (*apr_cert_list_length == 0 || *apr_cert_list == NULL)
1109 { 1109 {
1110 gnutls_assert (); 1110 MHD_gnutls_assert ();
1111 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 1111 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
1112 } 1112 }
1113 1113
@@ -1128,70 +1128,70 @@ mhd_gtls_get_selected_cert (mhd_gtls_session_t session,
1128 return 0; 1128 return 0;
1129} 1129}
1130 1130
1131/* converts the given x509 certificate to gnutls_cert* and allocates 1131/* converts the given x509 certificate to MHD_gnutls_cert* and allocates
1132 * space for them. 1132 * space for them.
1133 */ 1133 */
1134static gnutls_cert * 1134static MHD_gnutls_cert *
1135alloc_and_load_x509_certs (gnutls_x509_crt_t * certs, unsigned ncerts) 1135alloc_and_load_x509_certs (MHD_gnutls_x509_crt_t * certs, unsigned ncerts)
1136{ 1136{
1137 gnutls_cert *local_certs; 1137 MHD_gnutls_cert *local_certs;
1138 int ret = 0; 1138 int ret = 0;
1139 unsigned i, j; 1139 unsigned i, j;
1140 1140
1141 if (certs == NULL) 1141 if (certs == NULL)
1142 return NULL; 1142 return NULL;
1143 1143
1144 local_certs = gnutls_malloc (sizeof (gnutls_cert) * ncerts); 1144 local_certs = MHD_gnutls_malloc (sizeof (MHD_gnutls_cert) * ncerts);
1145 if (local_certs == NULL) 1145 if (local_certs == NULL)
1146 { 1146 {
1147 gnutls_assert (); 1147 MHD_gnutls_assert ();
1148 return NULL; 1148 return NULL;
1149 } 1149 }
1150 1150
1151 for (i = 0; i < ncerts; i++) 1151 for (i = 0; i < ncerts; i++)
1152 { 1152 {
1153 ret = mhd_gtls_x509_crt_to_gcert (&local_certs[i], certs[i], 0); 1153 ret = MHD_gtls_x509_crt_to_gcert (&local_certs[i], certs[i], 0);
1154 if (ret < 0) 1154 if (ret < 0)
1155 break; 1155 break;
1156 } 1156 }
1157 1157
1158 if (ret < 0) 1158 if (ret < 0)
1159 { 1159 {
1160 gnutls_assert (); 1160 MHD_gnutls_assert ();
1161 for (j = 0; j < i; j++) 1161 for (j = 0; j < i; j++)
1162 { 1162 {
1163 mhd_gtls_gcert_deinit (&local_certs[j]); 1163 MHD_gtls_gcert_deinit (&local_certs[j]);
1164 } 1164 }
1165 gnutls_free (local_certs); 1165 MHD_gnutls_free (local_certs);
1166 return NULL; 1166 return NULL;
1167 } 1167 }
1168 1168
1169 return local_certs; 1169 return local_certs;
1170} 1170}
1171 1171
1172/* converts the given x509 key to gnutls_privkey* and allocates 1172/* converts the given x509 key to MHD_gnutls_privkey* and allocates
1173 * space for it. 1173 * space for it.
1174 */ 1174 */
1175static gnutls_privkey * 1175static MHD_gnutls_privkey *
1176alloc_and_load_x509_key (gnutls_x509_privkey_t key) 1176alloc_and_load_x509_key (MHD_gnutls_x509_privkey_t key)
1177{ 1177{
1178 gnutls_privkey *local_key; 1178 MHD_gnutls_privkey *local_key;
1179 int ret = 0; 1179 int ret = 0;
1180 1180
1181 if (key == NULL) 1181 if (key == NULL)
1182 return NULL; 1182 return NULL;
1183 1183
1184 local_key = gnutls_malloc (sizeof (gnutls_privkey)); 1184 local_key = MHD_gnutls_malloc (sizeof (MHD_gnutls_privkey));
1185 if (local_key == NULL) 1185 if (local_key == NULL)
1186 { 1186 {
1187 gnutls_assert (); 1187 MHD_gnutls_assert ();
1188 return NULL; 1188 return NULL;
1189 } 1189 }
1190 1190
1191 ret = _gnutls_x509_privkey_to_gkey (local_key, key); 1191 ret = MHD__gnutls_x509_privkey_to_gkey (local_key, key);
1192 if (ret < 0) 1192 if (ret < 0)
1193 { 1193 {
1194 gnutls_assert (); 1194 MHD_gnutls_assert ();
1195 return NULL; 1195 return NULL;
1196 } 1196 }
1197 1197
@@ -1199,7 +1199,7 @@ alloc_and_load_x509_key (gnutls_x509_privkey_t key)
1199} 1199}
1200 1200
1201void 1201void
1202mhd_gtls_selected_certs_deinit (mhd_gtls_session_t session) 1202MHD_gtls_selected_certs_deinit (MHD_gtls_session_t session)
1203{ 1203{
1204 if (session->internals.selected_need_free != 0) 1204 if (session->internals.selected_need_free != 0)
1205 { 1205 {
@@ -1207,16 +1207,16 @@ mhd_gtls_selected_certs_deinit (mhd_gtls_session_t session)
1207 1207
1208 for (i = 0; i < session->internals.selected_cert_list_length; i++) 1208 for (i = 0; i < session->internals.selected_cert_list_length; i++)
1209 { 1209 {
1210 mhd_gtls_gcert_deinit (&session->internals.selected_cert_list[i]); 1210 MHD_gtls_gcert_deinit (&session->internals.selected_cert_list[i]);
1211 } 1211 }
1212 gnutls_free (session->internals.selected_cert_list); 1212 MHD_gnutls_free (session->internals.selected_cert_list);
1213 session->internals.selected_cert_list = NULL; 1213 session->internals.selected_cert_list = NULL;
1214 session->internals.selected_cert_list_length = 0; 1214 session->internals.selected_cert_list_length = 0;
1215 1215
1216 mhd_gtls_gkey_deinit (session->internals.selected_key); 1216 MHD_gtls_gkey_deinit (session->internals.selected_key);
1217 if (session->internals.selected_key) 1217 if (session->internals.selected_key)
1218 { 1218 {
1219 gnutls_free (session->internals.selected_key); 1219 MHD_gnutls_free (session->internals.selected_key);
1220 session->internals.selected_key = NULL; 1220 session->internals.selected_key = NULL;
1221 } 1221 }
1222 } 1222 }
@@ -1225,11 +1225,11 @@ mhd_gtls_selected_certs_deinit (mhd_gtls_session_t session)
1225} 1225}
1226 1226
1227void 1227void
1228mhd_gtls_selected_certs_set (mhd_gtls_session_t session, 1228MHD_gtls_selected_certs_set (MHD_gtls_session_t session,
1229 gnutls_cert * certs, int ncerts, 1229 MHD_gnutls_cert * certs, int ncerts,
1230 gnutls_privkey * key, int need_free) 1230 MHD_gnutls_privkey * key, int need_free)
1231{ 1231{
1232 mhd_gtls_selected_certs_deinit (session); 1232 MHD_gtls_selected_certs_deinit (session);
1233 1233
1234 session->internals.selected_cert_list = certs; 1234 session->internals.selected_cert_list = certs;
1235 session->internals.selected_cert_list_length = ncerts; 1235 session->internals.selected_cert_list_length = ncerts;
@@ -1250,19 +1250,19 @@ mhd_gtls_selected_certs_set (mhd_gtls_session_t session,
1250 * 1250 *
1251 */ 1251 */
1252int 1252int
1253mhd_gtls_server_select_cert (mhd_gtls_session_t session, 1253MHD_gtls_server_select_cert (MHD_gtls_session_t session,
1254 enum MHD_GNUTLS_PublicKeyAlgorithm 1254 enum MHD_GNUTLS_PublicKeyAlgorithm
1255 requested_algo) 1255 requested_algo)
1256{ 1256{
1257 unsigned i; 1257 unsigned i;
1258 int idx, ret; 1258 int idx, ret;
1259 mhd_gtls_cert_credentials_t cred; 1259 MHD_gtls_cert_credentials_t cred;
1260 1260
1261 cred = (mhd_gtls_cert_credentials_t) 1261 cred = (MHD_gtls_cert_credentials_t)
1262 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 1262 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
1263 if (cred == NULL) 1263 if (cred == NULL)
1264 { 1264 {
1265 gnutls_assert (); 1265 MHD_gnutls_assert ();
1266 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 1266 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
1267 } 1267 }
1268 1268
@@ -1301,7 +1301,7 @@ mhd_gtls_server_select_cert (mhd_gtls_session_t session,
1301 */ 1301 */
1302 if (idx >= 0 && ret == 0) 1302 if (idx >= 0 && ret == 0)
1303 { 1303 {
1304 mhd_gtls_selected_certs_set (session, 1304 MHD_gtls_selected_certs_set (session,
1305 &cred->cert_list[idx][0], 1305 &cred->cert_list[idx][0],
1306 cred->cert_list_length[idx], 1306 cred->cert_list_length[idx],
1307 &cred->pkey[idx], 0); 1307 &cred->pkey[idx], 0);
@@ -1313,11 +1313,11 @@ mhd_gtls_server_select_cert (mhd_gtls_session_t session,
1313 return ret; 1313 return ret;
1314} 1314}
1315 1315
1316/* Frees the mhd_gtls_rsa_info_st structure. 1316/* Frees the MHD_gtls_rsa_info_st structure.
1317 */ 1317 */
1318void 1318void
1319mhd_gtls_free_rsa_info (rsa_info_st * rsa) 1319MHD_gtls_free_rsa_info (rsa_info_st * rsa)
1320{ 1320{
1321 _gnutls_free_datum (&rsa->modulus); 1321 MHD__gnutls_free_datum (&rsa->modulus);
1322 _gnutls_free_datum (&rsa->exponent); 1322 MHD__gnutls_free_datum (&rsa->exponent);
1323} 1323}
diff --git a/src/daemon/https/tls/auth_cert.h b/src/daemon/https/tls/auth_cert.h
index 9df2bd0d..aabfac76 100644
--- a/src/daemon/https/tls/auth_cert.h
+++ b/src/daemon/https/tls/auth_cert.h
@@ -34,16 +34,16 @@
34 * support a server that has multiple certificates 34 * support a server that has multiple certificates
35 */ 35 */
36 36
37typedef struct mhd_gtls_certificate_credentials_st 37typedef struct MHD_gtls_certificate_credentials_st
38{ 38{
39 mhd_gtls_dh_params_t dh_params; 39 MHD_gtls_dh_params_t dh_params;
40 mhd_gtls_rsa_params_t rsa_params; 40 MHD_gtls_rsa_params_t rsa_params;
41 /* this callback is used to retrieve the DH or RSA 41 /* this callback is used to retrieve the DH or RSA
42 * parameters. 42 * parameters.
43 */ 43 */
44 gnutls_params_function *params_func; 44 MHD_gnutls_params_function *params_func;
45 45
46 gnutls_cert **cert_list; 46 MHD_gnutls_cert **cert_list;
47 /* contains a list of a list of certificates. 47 /* contains a list of a list of certificates.
48 * eg (X509): [0] certificate1, certificate11, certificate111 48 * eg (X509): [0] certificate1, certificate11, certificate111
49 * (if more than one, one certificate certifies the one before) 49 * (if more than one, one certificate certifies the one before)
@@ -57,7 +57,7 @@ typedef struct mhd_gtls_certificate_credentials_st
57 * This is the same with the number of pkeys. 57 * This is the same with the number of pkeys.
58 */ 58 */
59 59
60 gnutls_privkey *pkey; 60 MHD_gnutls_privkey *pkey;
61 /* private keys. It contains ncerts private 61 /* private keys. It contains ncerts private
62 * keys. pkey[i] corresponds to certificate in 62 * keys. pkey[i] corresponds to certificate in
63 * cert_list[i][0]. 63 * cert_list[i][0].
@@ -66,19 +66,19 @@ typedef struct mhd_gtls_certificate_credentials_st
66 /* OpenPGP specific stuff */ 66 /* OpenPGP specific stuff */
67 67
68#ifndef KEYRING_HACK 68#ifndef KEYRING_HACK
69 gnutls_openpgp_keyring_t keyring; 69 MHD_gnutls_openpgp_keyring_t keyring;
70#else 70#else
71 gnutls_datum_t keyring; 71 MHD_gnutls_datum_t keyring;
72 int keyring_format; 72 int keyring_format;
73#endif 73#endif
74 74
75 /* X509 specific stuff */ 75 /* X509 specific stuff */
76 76
77 gnutls_x509_crt_t *x509_ca_list; 77 MHD_gnutls_x509_crt_t *x509_ca_list;
78 unsigned x509_ncas; /* number of CAs in the ca_list 78 unsigned x509_ncas; /* number of CAs in the ca_list
79 */ 79 */
80 80
81 gnutls_x509_crl_t *x509_crl_list; 81 MHD_gnutls_x509_crl_t *x509_crl_list;
82 unsigned x509_ncrls; /* number of CRLs in the crl_list 82 unsigned x509_ncrls; /* number of CRLs in the crl_list
83 */ 83 */
84 84
@@ -93,19 +93,19 @@ typedef struct mhd_gtls_certificate_credentials_st
93 * This is better than 93 * This is better than
94 * generating on every handshake. 94 * generating on every handshake.
95 */ 95 */
96 gnutls_datum_t x509_rdn_sequence; 96 MHD_gnutls_datum_t x509_rdn_sequence;
97 97
98 gnutls_certificate_client_retrieve_function *client_get_cert_callback; 98 MHD_gnutls_certificate_client_retrieve_function *client_get_cert_callback;
99 gnutls_certificate_server_retrieve_function *server_get_cert_callback; 99 MHD_gnutls_certificate_server_retrieve_function *server_get_cert_callback;
100} mhd_gtls_cert_credentials_st; 100} MHD_gtls_cert_credentials_st;
101 101
102typedef struct mhd_gtls_rsa_info_st 102typedef struct MHD_gtls_rsa_info_st
103{ 103{
104 gnutls_datum_t modulus; 104 MHD_gnutls_datum_t modulus;
105 gnutls_datum_t exponent; 105 MHD_gnutls_datum_t exponent;
106} rsa_info_st; 106} rsa_info_st;
107 107
108typedef struct mhd_gtls_cert_auth_info_st 108typedef struct MHD_gtls_cert_auth_info_st
109{ 109{
110 int certificate_requested; /* if the peer requested certificate 110 int certificate_requested; /* if the peer requested certificate
111 * this is non zero; 111 * this is non zero;
@@ -114,46 +114,46 @@ typedef struct mhd_gtls_cert_auth_info_st
114 /* These (dh/rsa) are just copies from the credentials_t structure. 114 /* These (dh/rsa) are just copies from the credentials_t structure.
115 * They must be freed. 115 * They must be freed.
116 */ 116 */
117 mhd_gtls_dh_info_st dh; 117 MHD_gtls_dh_info_st dh;
118 rsa_info_st rsa_export; 118 rsa_info_st rsa_export;
119 119
120 gnutls_datum_t *raw_certificate_list; /* holds the raw certificate of the 120 MHD_gnutls_datum_t *raw_certificate_list; /* holds the raw certificate of the
121 * peer. 121 * peer.
122 */ 122 */
123 unsigned int ncerts; /* holds the size of the list above */ 123 unsigned int ncerts; /* holds the size of the list above */
124} *cert_auth_info_t; 124} *cert_auth_info_t;
125 125
126typedef struct mhd_gtls_cert_auth_info_st cert_auth_info_st; 126typedef struct MHD_gtls_cert_auth_info_st cert_auth_info_st;
127 127
128void mhd_gtls_free_rsa_info (rsa_info_st * rsa); 128void MHD_gtls_free_rsa_info (rsa_info_st * rsa);
129 129
130/* AUTH X509 functions */ 130/* AUTH X509 functions */
131int mhd_gtls_gen_cert_server_certificate (mhd_gtls_session_t, opaque **); 131int MHD_gtls_gen_cert_server_certificate (MHD_gtls_session_t, opaque **);
132int mhd_gtls_gen_cert_client_certificate (mhd_gtls_session_t, opaque **); 132int MHD_gtls_gen_cert_client_certificate (MHD_gtls_session_t, opaque **);
133int mhd_gtls_gen_cert_client_cert_vrfy (mhd_gtls_session_t, opaque **); 133int MHD_gtls_gen_cert_client_cert_vrfy (MHD_gtls_session_t, opaque **);
134int mhd_gtls_gen_cert_server_cert_req (mhd_gtls_session_t, opaque **); 134int MHD_gtls_gen_cert_server_cert_req (MHD_gtls_session_t, opaque **);
135int mhd_gtls_proc_cert_cert_req (mhd_gtls_session_t, opaque *, size_t); 135int MHD_gtls_proc_cert_cert_req (MHD_gtls_session_t, opaque *, size_t);
136int mhd_gtls_proc_cert_client_cert_vrfy (mhd_gtls_session_t, opaque *, 136int MHD_gtls_proc_cert_client_cert_vrfy (MHD_gtls_session_t, opaque *,
137 size_t); 137 size_t);
138int mhd_gtls_proc_cert_server_certificate (mhd_gtls_session_t, opaque *, 138int MHD_gtls_proc_cert_server_certificate (MHD_gtls_session_t, opaque *,
139 size_t); 139 size_t);
140int mhd_gtls_get_selected_cert (mhd_gtls_session_t session, 140int MHD_gtls_get_selected_cert (MHD_gtls_session_t session,
141 gnutls_cert ** apr_cert_list, 141 MHD_gnutls_cert ** apr_cert_list,
142 int *apr_cert_list_length, 142 int *apr_cert_list_length,
143 gnutls_privkey ** apr_pkey); 143 MHD_gnutls_privkey ** apr_pkey);
144 144
145int mhd_gtls_server_select_cert (struct MHD_gtls_session_int *, 145int MHD_gtls_server_select_cert (struct MHD_gtls_session_int *,
146 enum MHD_GNUTLS_PublicKeyAlgorithm); 146 enum MHD_GNUTLS_PublicKeyAlgorithm);
147void mhd_gtls_selected_certs_deinit (mhd_gtls_session_t session); 147void MHD_gtls_selected_certs_deinit (MHD_gtls_session_t session);
148void mhd_gtls_selected_certs_set (mhd_gtls_session_t session, 148void MHD_gtls_selected_certs_set (MHD_gtls_session_t session,
149 gnutls_cert * certs, int ncerts, 149 MHD_gnutls_cert * certs, int ncerts,
150 gnutls_privkey * key, int need_free); 150 MHD_gnutls_privkey * key, int need_free);
151 151
152#define _gnutls_proc_cert_client_certificate mhd_gtls_proc_cert_server_certificate 152#define MHD__gnutls_proc_cert_client_certificate MHD_gtls_proc_cert_server_certificate
153 153
154mhd_gtls_rsa_params_t 154MHD_gtls_rsa_params_t
155mhd_gtls_certificate_get_rsa_params (mhd_gtls_rsa_params_t rsa_params, 155MHD_gtls_certificate_get_rsa_params (MHD_gtls_rsa_params_t rsa_params,
156 gnutls_params_function * func, 156 MHD_gnutls_params_function * func,
157 mhd_gtls_session_t); 157 MHD_gtls_session_t);
158 158
159#endif 159#endif
diff --git a/src/daemon/https/tls/auth_dh_common.c b/src/daemon/https/tls/auth_dh_common.c
index 4d471045..8fc6e391 100644
--- a/src/daemon/https/tls/auth_dh_common.c
+++ b/src/daemon/https/tls/auth_dh_common.c
@@ -39,19 +39,19 @@
39#include <auth_dh_common.h> 39#include <auth_dh_common.h>
40#include <gnutls_algorithms.h> 40#include <gnutls_algorithms.h>
41 41
42/* Frees the mhd_gtls_dh_info_st structure. 42/* Frees the MHD_gtls_dh_info_st structure.
43 */ 43 */
44void 44void
45mhd_gtls_free_dh_info (mhd_gtls_dh_info_st * dh) 45MHD_gtls_free_dh_info (MHD_gtls_dh_info_st * dh)
46{ 46{
47 dh->secret_bits = 0; 47 dh->secret_bits = 0;
48 _gnutls_free_datum (&dh->prime); 48 MHD__gnutls_free_datum (&dh->prime);
49 _gnutls_free_datum (&dh->generator); 49 MHD__gnutls_free_datum (&dh->generator);
50 _gnutls_free_datum (&dh->public_key); 50 MHD__gnutls_free_datum (&dh->public_key);
51} 51}
52 52
53int 53int
54mhd_gtls_proc_dh_common_client_kx (mhd_gtls_session_t session, 54MHD_gtls_proc_dh_common_client_kx (MHD_gtls_session_t session,
55 opaque * data, size_t _data_size, 55 opaque * data, size_t _data_size,
56 mpi_t g, mpi_t p) 56 mpi_t g, mpi_t p)
57{ 57{
@@ -62,33 +62,33 @@ mhd_gtls_proc_dh_common_client_kx (mhd_gtls_session_t session,
62 62
63 63
64 DECR_LEN (data_size, 2); 64 DECR_LEN (data_size, 2);
65 n_Y = mhd_gtls_read_uint16 (&data[0]); 65 n_Y = MHD_gtls_read_uint16 (&data[0]);
66 _n_Y = n_Y; 66 _n_Y = n_Y;
67 67
68 DECR_LEN (data_size, n_Y); 68 DECR_LEN (data_size, n_Y);
69 if (mhd_gtls_mpi_scan_nz (&session->key->client_Y, &data[2], &_n_Y)) 69 if (MHD_gtls_mpi_scan_nz (&session->key->client_Y, &data[2], &_n_Y))
70 { 70 {
71 gnutls_assert (); 71 MHD_gnutls_assert ();
72 return GNUTLS_E_MPI_SCAN_FAILED; 72 return GNUTLS_E_MPI_SCAN_FAILED;
73 } 73 }
74 74
75 mhd_gtls_dh_set_peer_public (session, session->key->client_Y); 75 MHD_gtls_dh_set_peer_public (session, session->key->client_Y);
76 76
77 session->key->KEY = 77 session->key->KEY =
78 mhd_gtls_calc_dh_key (session->key->client_Y, session->key->dh_secret, p); 78 MHD_gtls_calc_dh_key (session->key->client_Y, session->key->dh_secret, p);
79 79
80 if (session->key->KEY == NULL) 80 if (session->key->KEY == NULL)
81 { 81 {
82 gnutls_assert (); 82 MHD_gnutls_assert ();
83 return GNUTLS_E_MEMORY_ERROR; 83 return GNUTLS_E_MEMORY_ERROR;
84 } 84 }
85 85
86 mhd_gtls_mpi_release (&session->key->client_Y); 86 MHD_gtls_mpi_release (&session->key->client_Y);
87 mhd_gtls_mpi_release (&session->key->dh_secret); 87 MHD_gtls_mpi_release (&session->key->dh_secret);
88 88
89 ret = mhd_gtls_mpi_dprint (&session->key->key, session->key->KEY); 89 ret = MHD_gtls_mpi_dprint (&session->key->key, session->key->KEY);
90 90
91 mhd_gtls_mpi_release (&session->key->KEY); 91 MHD_gtls_mpi_release (&session->key->KEY);
92 92
93 if (ret < 0) 93 if (ret < 0)
94 { 94 {
@@ -99,7 +99,7 @@ mhd_gtls_proc_dh_common_client_kx (mhd_gtls_session_t session,
99} 99}
100 100
101int 101int
102mhd_gtls_gen_dh_common_client_kx (mhd_gtls_session_t session, opaque ** data) 102MHD_gtls_gen_dh_common_client_kx (MHD_gtls_session_t session, opaque ** data)
103{ 103{
104 mpi_t x = NULL, X = NULL; 104 mpi_t x = NULL, X = NULL;
105 size_t n_X; 105 size_t n_X;
@@ -107,69 +107,69 @@ mhd_gtls_gen_dh_common_client_kx (mhd_gtls_session_t session, opaque ** data)
107 107
108 *data = NULL; 108 *data = NULL;
109 109
110 X = mhd_gtls_calc_dh_secret (&x, session->key->client_g, 110 X = MHD_gtls_calc_dh_secret (&x, session->key->client_g,
111 session->key->client_p); 111 session->key->client_p);
112 if (X == NULL || x == NULL) 112 if (X == NULL || x == NULL)
113 { 113 {
114 gnutls_assert (); 114 MHD_gnutls_assert ();
115 ret = GNUTLS_E_MEMORY_ERROR; 115 ret = GNUTLS_E_MEMORY_ERROR;
116 goto error; 116 goto error;
117 } 117 }
118 118
119 mhd_gtls_dh_set_secret_bits (session, _gnutls_mpi_get_nbits (x)); 119 MHD_gtls_dh_set_secret_bits (session, MHD__gnutls_mpi_get_nbits (x));
120 120
121 mhd_gtls_mpi_print (NULL, &n_X, X); 121 MHD_gtls_mpi_print (NULL, &n_X, X);
122 (*data) = gnutls_malloc (n_X + 2); 122 (*data) = MHD_gnutls_malloc (n_X + 2);
123 if (*data == NULL) 123 if (*data == NULL)
124 { 124 {
125 ret = GNUTLS_E_MEMORY_ERROR; 125 ret = GNUTLS_E_MEMORY_ERROR;
126 goto error; 126 goto error;
127 } 127 }
128 128
129 mhd_gtls_mpi_print (&(*data)[2], &n_X, X); 129 MHD_gtls_mpi_print (&(*data)[2], &n_X, X);
130 mhd_gtls_mpi_release (&X); 130 MHD_gtls_mpi_release (&X);
131 131
132 mhd_gtls_write_uint16 (n_X, &(*data)[0]); 132 MHD_gtls_write_uint16 (n_X, &(*data)[0]);
133 133
134 /* calculate the key after calculating the message */ 134 /* calculate the key after calculating the message */
135 session->key->KEY = 135 session->key->KEY =
136 mhd_gtls_calc_dh_key (session->key->client_Y, x, session->key->client_p); 136 MHD_gtls_calc_dh_key (session->key->client_Y, x, session->key->client_p);
137 137
138 mhd_gtls_mpi_release (&x); 138 MHD_gtls_mpi_release (&x);
139 if (session->key->KEY == NULL) 139 if (session->key->KEY == NULL)
140 { 140 {
141 gnutls_assert (); 141 MHD_gnutls_assert ();
142 ret = GNUTLS_E_MEMORY_ERROR; 142 ret = GNUTLS_E_MEMORY_ERROR;
143 goto error; 143 goto error;
144 } 144 }
145 145
146 /* THESE SHOULD BE DISCARDED */ 146 /* THESE SHOULD BE DISCARDED */
147 mhd_gtls_mpi_release (&session->key->client_Y); 147 MHD_gtls_mpi_release (&session->key->client_Y);
148 mhd_gtls_mpi_release (&session->key->client_p); 148 MHD_gtls_mpi_release (&session->key->client_p);
149 mhd_gtls_mpi_release (&session->key->client_g); 149 MHD_gtls_mpi_release (&session->key->client_g);
150 150
151 ret = mhd_gtls_mpi_dprint (&session->key->key, session->key->KEY); 151 ret = MHD_gtls_mpi_dprint (&session->key->key, session->key->KEY);
152 152
153 mhd_gtls_mpi_release (&session->key->KEY); 153 MHD_gtls_mpi_release (&session->key->KEY);
154 154
155 if (ret < 0) 155 if (ret < 0)
156 { 156 {
157 gnutls_assert (); 157 MHD_gnutls_assert ();
158 goto error; 158 goto error;
159 } 159 }
160 160
161 return n_X + 2; 161 return n_X + 2;
162 162
163error: 163error:
164 mhd_gtls_mpi_release (&x); 164 MHD_gtls_mpi_release (&x);
165 mhd_gtls_mpi_release (&X); 165 MHD_gtls_mpi_release (&X);
166 gnutls_free (*data); 166 MHD_gnutls_free (*data);
167 *data = NULL; 167 *data = NULL;
168 return ret; 168 return ret;
169} 169}
170 170
171int 171int
172mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session, 172MHD_gtls_proc_dh_common_server_kx (MHD_gtls_session_t session,
173 opaque * data, size_t _data_size, int psk) 173 opaque * data, size_t _data_size, int psk)
174{ 174{
175 uint16_t n_Y, n_g, n_p; 175 uint16_t n_Y, n_g, n_p;
@@ -185,13 +185,13 @@ mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session,
185 if (psk != 0) 185 if (psk != 0)
186 { 186 {
187 DECR_LEN (data_size, 2); 187 DECR_LEN (data_size, 2);
188 psk_size = mhd_gtls_read_uint16 (&data[i]); 188 psk_size = MHD_gtls_read_uint16 (&data[i]);
189 DECR_LEN (data_size, psk_size); 189 DECR_LEN (data_size, psk_size);
190 i += 2 + psk_size; 190 i += 2 + psk_size;
191 } 191 }
192 192
193 DECR_LEN (data_size, 2); 193 DECR_LEN (data_size, 2);
194 n_p = mhd_gtls_read_uint16 (&data[i]); 194 n_p = MHD_gtls_read_uint16 (&data[i]);
195 i += 2; 195 i += 2;
196 196
197 DECR_LEN (data_size, n_p); 197 DECR_LEN (data_size, n_p);
@@ -199,7 +199,7 @@ mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session,
199 i += n_p; 199 i += n_p;
200 200
201 DECR_LEN (data_size, 2); 201 DECR_LEN (data_size, 2);
202 n_g = mhd_gtls_read_uint16 (&data[i]); 202 n_g = MHD_gtls_read_uint16 (&data[i]);
203 i += 2; 203 i += 2;
204 204
205 DECR_LEN (data_size, n_g); 205 DECR_LEN (data_size, n_g);
@@ -207,7 +207,7 @@ mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session,
207 i += n_g; 207 i += n_g;
208 208
209 DECR_LEN (data_size, 2); 209 DECR_LEN (data_size, 2);
210 n_Y = mhd_gtls_read_uint16 (&data[i]); 210 n_Y = MHD_gtls_read_uint16 (&data[i]);
211 i += 2; 211 i += 2;
212 212
213 DECR_LEN (data_size, n_Y); 213 DECR_LEN (data_size, n_Y);
@@ -218,41 +218,41 @@ mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session,
218 _n_g = n_g; 218 _n_g = n_g;
219 _n_p = n_p; 219 _n_p = n_p;
220 220
221 if (mhd_gtls_mpi_scan_nz (&session->key->client_Y, data_Y, &_n_Y) != 0) 221 if (MHD_gtls_mpi_scan_nz (&session->key->client_Y, data_Y, &_n_Y) != 0)
222 { 222 {
223 gnutls_assert (); 223 MHD_gnutls_assert ();
224 return GNUTLS_E_MPI_SCAN_FAILED; 224 return GNUTLS_E_MPI_SCAN_FAILED;
225 } 225 }
226 226
227 if (mhd_gtls_mpi_scan_nz (&session->key->client_g, data_g, &_n_g) != 0) 227 if (MHD_gtls_mpi_scan_nz (&session->key->client_g, data_g, &_n_g) != 0)
228 { 228 {
229 gnutls_assert (); 229 MHD_gnutls_assert ();
230 return GNUTLS_E_MPI_SCAN_FAILED; 230 return GNUTLS_E_MPI_SCAN_FAILED;
231 } 231 }
232 if (mhd_gtls_mpi_scan_nz (&session->key->client_p, data_p, &_n_p) != 0) 232 if (MHD_gtls_mpi_scan_nz (&session->key->client_p, data_p, &_n_p) != 0)
233 { 233 {
234 gnutls_assert (); 234 MHD_gnutls_assert ();
235 return GNUTLS_E_MPI_SCAN_FAILED; 235 return GNUTLS_E_MPI_SCAN_FAILED;
236 } 236 }
237 237
238 bits = mhd_gtls_dh_get_allowed_prime_bits (session); 238 bits = MHD_gtls_dh_get_allowed_prime_bits (session);
239 if (bits < 0) 239 if (bits < 0)
240 { 240 {
241 gnutls_assert (); 241 MHD_gnutls_assert ();
242 return bits; 242 return bits;
243 } 243 }
244 244
245 if (_gnutls_mpi_get_nbits (session->key->client_p) < (size_t) bits) 245 if (MHD__gnutls_mpi_get_nbits (session->key->client_p) < (size_t) bits)
246 { 246 {
247 /* the prime used by the peer is not acceptable 247 /* the prime used by the peer is not acceptable
248 */ 248 */
249 gnutls_assert (); 249 MHD_gnutls_assert ();
250 return GNUTLS_E_DH_PRIME_UNACCEPTABLE; 250 return GNUTLS_E_DH_PRIME_UNACCEPTABLE;
251 } 251 }
252 252
253 mhd_gtls_dh_set_group (session, session->key->client_g, 253 MHD_gtls_dh_set_group (session, session->key->client_g,
254 session->key->client_p); 254 session->key->client_p);
255 mhd_gtls_dh_set_peer_public (session, session->key->client_Y); 255 MHD_gtls_dh_set_peer_public (session, session->key->client_Y);
256 256
257 ret = n_Y + n_p + n_g + 6; 257 ret = n_Y + n_p + n_g + 6;
258 if (psk != 0) 258 if (psk != 0)
@@ -264,7 +264,7 @@ mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session,
264/* If the psk flag is set, then an empty psk_identity_hint will 264/* If the psk flag is set, then an empty psk_identity_hint will
265 * be inserted */ 265 * be inserted */
266int 266int
267mhd_gtls_dh_common_print_server_kx (mhd_gtls_session_t session, 267MHD_gtls_dh_common_print_server_kx (MHD_gtls_session_t session,
268 mpi_t g, mpi_t p, opaque ** data, int psk) 268 mpi_t g, mpi_t p, opaque ** data, int psk)
269{ 269{
270 mpi_t x, X; 270 mpi_t x, X;
@@ -272,28 +272,28 @@ mhd_gtls_dh_common_print_server_kx (mhd_gtls_session_t session,
272 int ret, data_size, pos; 272 int ret, data_size, pos;
273 uint8_t *pdata; 273 uint8_t *pdata;
274 274
275 X = mhd_gtls_calc_dh_secret (&x, g, p); 275 X = MHD_gtls_calc_dh_secret (&x, g, p);
276 if (X == NULL || x == NULL) 276 if (X == NULL || x == NULL)
277 { 277 {
278 gnutls_assert (); 278 MHD_gnutls_assert ();
279 return GNUTLS_E_MEMORY_ERROR; 279 return GNUTLS_E_MEMORY_ERROR;
280 } 280 }
281 281
282 session->key->dh_secret = x; 282 session->key->dh_secret = x;
283 mhd_gtls_dh_set_secret_bits (session, _gnutls_mpi_get_nbits (x)); 283 MHD_gtls_dh_set_secret_bits (session, MHD__gnutls_mpi_get_nbits (x));
284 284
285 mhd_gtls_mpi_print (NULL, &n_g, g); 285 MHD_gtls_mpi_print (NULL, &n_g, g);
286 mhd_gtls_mpi_print (NULL, &n_p, p); 286 MHD_gtls_mpi_print (NULL, &n_p, p);
287 mhd_gtls_mpi_print (NULL, &n_X, X); 287 MHD_gtls_mpi_print (NULL, &n_X, X);
288 288
289 data_size = n_g + n_p + n_X + 6; 289 data_size = n_g + n_p + n_X + 6;
290 if (psk != 0) 290 if (psk != 0)
291 data_size += 2; 291 data_size += 2;
292 292
293 (*data) = gnutls_malloc (data_size); 293 (*data) = MHD_gnutls_malloc (data_size);
294 if (*data == NULL) 294 if (*data == NULL)
295 { 295 {
296 mhd_gtls_mpi_release (&X); 296 MHD_gtls_mpi_release (&X);
297 return GNUTLS_E_MEMORY_ERROR; 297 return GNUTLS_E_MEMORY_ERROR;
298 } 298 }
299 299
@@ -302,24 +302,24 @@ mhd_gtls_dh_common_print_server_kx (mhd_gtls_session_t session,
302 302
303 if (psk != 0) 303 if (psk != 0)
304 { 304 {
305 mhd_gtls_write_uint16 (0, &pdata[pos]); 305 MHD_gtls_write_uint16 (0, &pdata[pos]);
306 pos += 2; 306 pos += 2;
307 } 307 }
308 308
309 mhd_gtls_mpi_print (&pdata[pos + 2], &n_p, p); 309 MHD_gtls_mpi_print (&pdata[pos + 2], &n_p, p);
310 mhd_gtls_write_uint16 (n_p, &pdata[pos]); 310 MHD_gtls_write_uint16 (n_p, &pdata[pos]);
311 311
312 pos += n_p + 2; 312 pos += n_p + 2;
313 313
314 mhd_gtls_mpi_print (&pdata[pos + 2], &n_g, g); 314 MHD_gtls_mpi_print (&pdata[pos + 2], &n_g, g);
315 mhd_gtls_write_uint16 (n_g, &pdata[pos]); 315 MHD_gtls_write_uint16 (n_g, &pdata[pos]);
316 316
317 pos += n_g + 2; 317 pos += n_g + 2;
318 318
319 mhd_gtls_mpi_print (&pdata[pos + 2], &n_X, X); 319 MHD_gtls_mpi_print (&pdata[pos + 2], &n_X, X);
320 mhd_gtls_mpi_release (&X); 320 MHD_gtls_mpi_release (&X);
321 321
322 mhd_gtls_write_uint16 (n_X, &pdata[pos]); 322 MHD_gtls_write_uint16 (n_X, &pdata[pos]);
323 323
324 ret = data_size; 324 ret = data_size;
325 325
diff --git a/src/daemon/https/tls/auth_dh_common.h b/src/daemon/https/tls/auth_dh_common.h
index c6129958..f09ce6dc 100644
--- a/src/daemon/https/tls/auth_dh_common.h
+++ b/src/daemon/https/tls/auth_dh_common.h
@@ -29,19 +29,19 @@ typedef struct
29{ 29{
30 int secret_bits; 30 int secret_bits;
31 31
32 gnutls_datum_t prime; 32 MHD_gnutls_datum_t prime;
33 gnutls_datum_t generator; 33 MHD_gnutls_datum_t generator;
34 gnutls_datum_t public_key; 34 MHD_gnutls_datum_t public_key;
35} mhd_gtls_dh_info_st; 35} MHD_gtls_dh_info_st;
36 36
37void mhd_gtls_free_dh_info (mhd_gtls_dh_info_st * dh); 37void MHD_gtls_free_dh_info (MHD_gtls_dh_info_st * dh);
38int mhd_gtls_gen_dh_common_client_kx (mhd_gtls_session_t, opaque **); 38int MHD_gtls_gen_dh_common_client_kx (MHD_gtls_session_t, opaque **);
39int mhd_gtls_proc_dh_common_client_kx (mhd_gtls_session_t session, 39int MHD_gtls_proc_dh_common_client_kx (MHD_gtls_session_t session,
40 opaque * data, size_t _data_size, 40 opaque * data, size_t _data_size,
41 mpi_t p, mpi_t g); 41 mpi_t p, mpi_t g);
42int mhd_gtls_dh_common_print_server_kx (mhd_gtls_session_t, mpi_t g, mpi_t p, 42int MHD_gtls_dh_common_print_server_kx (MHD_gtls_session_t, mpi_t g, mpi_t p,
43 opaque ** data, int psk); 43 opaque ** data, int psk);
44int mhd_gtls_proc_dh_common_server_kx (mhd_gtls_session_t session, 44int MHD_gtls_proc_dh_common_server_kx (MHD_gtls_session_t session,
45 opaque * data, size_t _data_size, 45 opaque * data, size_t _data_size,
46 int psk); 46 int psk);
47 47
diff --git a/src/daemon/https/tls/auth_dhe.c b/src/daemon/https/tls/auth_dhe.c
index 43aedf0b..fa535e55 100644
--- a/src/daemon/https/tls/auth_dhe.c
+++ b/src/daemon/https/tls/auth_dhe.c
@@ -39,103 +39,103 @@
39#include <gnutls_state.h> 39#include <gnutls_state.h>
40#include <auth_dh_common.h> 40#include <auth_dh_common.h>
41 41
42static int gen_dhe_server_kx (mhd_gtls_session_t, opaque **); 42static int gen_dhe_server_kx (MHD_gtls_session_t, opaque **);
43static int proc_dhe_server_kx (mhd_gtls_session_t, opaque *, size_t); 43static int proc_dhe_server_kx (MHD_gtls_session_t, opaque *, size_t);
44static int proc_dhe_client_kx (mhd_gtls_session_t, opaque *, size_t); 44static int proc_dhe_client_kx (MHD_gtls_session_t, opaque *, size_t);
45 45
46const mhd_gtls_mod_auth_st mhd_gtls_dhe_rsa_auth_struct = { 46const MHD_gtls_mod_auth_st MHD_gtls_dhe_rsa_auth_struct = {
47 "DHE_RSA", 47 "DHE_RSA",
48 mhd_gtls_gen_cert_server_certificate, 48 MHD_gtls_gen_cert_server_certificate,
49 mhd_gtls_gen_cert_client_certificate, 49 MHD_gtls_gen_cert_client_certificate,
50 gen_dhe_server_kx, 50 gen_dhe_server_kx,
51 mhd_gtls_gen_dh_common_client_kx, 51 MHD_gtls_gen_dh_common_client_kx,
52 mhd_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */ 52 MHD_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */
53 mhd_gtls_gen_cert_server_cert_req, /* server cert request */ 53 MHD_gtls_gen_cert_server_cert_req, /* server cert request */
54 54
55 mhd_gtls_proc_cert_server_certificate, 55 MHD_gtls_proc_cert_server_certificate,
56 _gnutls_proc_cert_client_certificate, 56 MHD__gnutls_proc_cert_client_certificate,
57 proc_dhe_server_kx, 57 proc_dhe_server_kx,
58 proc_dhe_client_kx, 58 proc_dhe_client_kx,
59 mhd_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */ 59 MHD_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */
60 mhd_gtls_proc_cert_cert_req /* proc server cert request */ 60 MHD_gtls_proc_cert_cert_req /* proc server cert request */
61}; 61};
62 62
63const mhd_gtls_mod_auth_st mhd_gtls_dhe_dss_auth_struct = { 63const MHD_gtls_mod_auth_st MHD_gtls_dhe_dss_auth_struct = {
64 "DHE_DSS", 64 "DHE_DSS",
65 mhd_gtls_gen_cert_server_certificate, 65 MHD_gtls_gen_cert_server_certificate,
66 mhd_gtls_gen_cert_client_certificate, 66 MHD_gtls_gen_cert_client_certificate,
67 gen_dhe_server_kx, 67 gen_dhe_server_kx,
68 mhd_gtls_gen_dh_common_client_kx, 68 MHD_gtls_gen_dh_common_client_kx,
69 mhd_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */ 69 MHD_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */
70 mhd_gtls_gen_cert_server_cert_req, /* server cert request */ 70 MHD_gtls_gen_cert_server_cert_req, /* server cert request */
71 71
72 mhd_gtls_proc_cert_server_certificate, 72 MHD_gtls_proc_cert_server_certificate,
73 _gnutls_proc_cert_client_certificate, 73 MHD__gnutls_proc_cert_client_certificate,
74 proc_dhe_server_kx, 74 proc_dhe_server_kx,
75 proc_dhe_client_kx, 75 proc_dhe_client_kx,
76 mhd_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */ 76 MHD_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */
77 mhd_gtls_proc_cert_cert_req /* proc server cert request */ 77 MHD_gtls_proc_cert_cert_req /* proc server cert request */
78}; 78};
79 79
80 80
81static int 81static int
82gen_dhe_server_kx (mhd_gtls_session_t session, opaque ** data) 82gen_dhe_server_kx (MHD_gtls_session_t session, opaque ** data)
83{ 83{
84 mpi_t g, p; 84 mpi_t g, p;
85 const mpi_t *mpis; 85 const mpi_t *mpis;
86 int ret = 0, data_size; 86 int ret = 0, data_size;
87 int bits; 87 int bits;
88 gnutls_cert *apr_cert_list; 88 MHD_gnutls_cert *apr_cert_list;
89 gnutls_privkey *apr_pkey; 89 MHD_gnutls_privkey *apr_pkey;
90 int apr_cert_list_length; 90 int apr_cert_list_length;
91 gnutls_datum_t signature, ddata; 91 MHD_gnutls_datum_t signature, ddata;
92 mhd_gtls_cert_credentials_t cred; 92 MHD_gtls_cert_credentials_t cred;
93 mhd_gtls_dh_params_t dh_params; 93 MHD_gtls_dh_params_t dh_params;
94 94
95 cred = (mhd_gtls_cert_credentials_t) 95 cred = (MHD_gtls_cert_credentials_t)
96 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 96 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
97 if (cred == NULL) 97 if (cred == NULL)
98 { 98 {
99 gnutls_assert (); 99 MHD_gnutls_assert ();
100 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 100 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
101 } 101 }
102 102
103 bits = mhd_gtls_dh_get_allowed_prime_bits (session); 103 bits = MHD_gtls_dh_get_allowed_prime_bits (session);
104 104
105 /* find the appropriate certificate */ 105 /* find the appropriate certificate */
106 if ((ret = 106 if ((ret =
107 mhd_gtls_get_selected_cert (session, &apr_cert_list, 107 MHD_gtls_get_selected_cert (session, &apr_cert_list,
108 &apr_cert_list_length, &apr_pkey)) < 0) 108 &apr_cert_list_length, &apr_pkey)) < 0)
109 { 109 {
110 gnutls_assert (); 110 MHD_gnutls_assert ();
111 return ret; 111 return ret;
112 } 112 }
113 113
114 dh_params = 114 dh_params =
115 mhd_gtls_get_dh_params (cred->dh_params, cred->params_func, session); 115 MHD_gtls_get_dh_params (cred->dh_params, cred->params_func, session);
116 mpis = mhd_gtls_dh_params_to_mpi (dh_params); 116 mpis = MHD_gtls_dh_params_to_mpi (dh_params);
117 if (mpis == NULL) 117 if (mpis == NULL)
118 { 118 {
119 gnutls_assert (); 119 MHD_gnutls_assert ();
120 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS; 120 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
121 } 121 }
122 122
123 p = mpis[0]; 123 p = mpis[0];
124 g = mpis[1]; 124 g = mpis[1];
125 125
126 if ((ret = mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE, 126 if ((ret = MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE,
127 sizeof (cert_auth_info_st), 0)) < 0) 127 sizeof (cert_auth_info_st), 0)) < 0)
128 { 128 {
129 gnutls_assert (); 129 MHD_gnutls_assert ();
130 return ret; 130 return ret;
131 } 131 }
132 132
133 mhd_gtls_dh_set_group (session, g, p); 133 MHD_gtls_dh_set_group (session, g, p);
134 134
135 ret = mhd_gtls_dh_common_print_server_kx (session, g, p, data, 0); 135 ret = MHD_gtls_dh_common_print_server_kx (session, g, p, data, 0);
136 if (ret < 0) 136 if (ret < 0)
137 { 137 {
138 gnutls_assert (); 138 MHD_gnutls_assert ();
139 return ret; 139 return ret;
140 } 140 }
141 data_size = ret; 141 data_size = ret;
@@ -148,58 +148,58 @@ gen_dhe_server_kx (mhd_gtls_session_t session, opaque ** data)
148 if (apr_cert_list_length > 0) 148 if (apr_cert_list_length > 0)
149 { 149 {
150 if ((ret = 150 if ((ret =
151 mhd_gtls_tls_sign_params (session, &apr_cert_list[0], 151 MHD_gtls_tls_sign_params (session, &apr_cert_list[0],
152 apr_pkey, &ddata, &signature)) < 0) 152 apr_pkey, &ddata, &signature)) < 0)
153 { 153 {
154 gnutls_assert (); 154 MHD_gnutls_assert ();
155 gnutls_free (*data); 155 MHD_gnutls_free (*data);
156 return ret; 156 return ret;
157 } 157 }
158 } 158 }
159 else 159 else
160 { 160 {
161 gnutls_assert (); 161 MHD_gnutls_assert ();
162 return data_size; /* do not put a signature - ILLEGAL! */ 162 return data_size; /* do not put a signature - ILLEGAL! */
163 } 163 }
164 164
165 *data = mhd_gtls_realloc_fast (*data, data_size + signature.size + 2); 165 *data = MHD_gtls_realloc_fast (*data, data_size + signature.size + 2);
166 if (*data == NULL) 166 if (*data == NULL)
167 { 167 {
168 _gnutls_free_datum (&signature); 168 MHD__gnutls_free_datum (&signature);
169 gnutls_assert (); 169 MHD_gnutls_assert ();
170 return GNUTLS_E_MEMORY_ERROR; 170 return GNUTLS_E_MEMORY_ERROR;
171 } 171 }
172 172
173 mhd_gtls_write_datum16 (&(*data)[data_size], signature); 173 MHD_gtls_write_datum16 (&(*data)[data_size], signature);
174 data_size += signature.size + 2; 174 data_size += signature.size + 2;
175 175
176 _gnutls_free_datum (&signature); 176 MHD__gnutls_free_datum (&signature);
177 177
178 return data_size; 178 return data_size;
179} 179}
180 180
181static int 181static int
182proc_dhe_server_kx (mhd_gtls_session_t session, opaque * data, 182proc_dhe_server_kx (MHD_gtls_session_t session, opaque * data,
183 size_t _data_size) 183 size_t _data_size)
184{ 184{
185 int sigsize; 185 int sigsize;
186 gnutls_datum_t vparams, signature; 186 MHD_gnutls_datum_t vparams, signature;
187 int ret; 187 int ret;
188 cert_auth_info_t info = mhd_gtls_get_auth_info (session); 188 cert_auth_info_t info = MHD_gtls_get_auth_info (session);
189 ssize_t data_size = _data_size; 189 ssize_t data_size = _data_size;
190 gnutls_cert peer_cert; 190 MHD_gnutls_cert peer_cert;
191 191
192 if (info == NULL || info->ncerts == 0) 192 if (info == NULL || info->ncerts == 0)
193 { 193 {
194 gnutls_assert (); 194 MHD_gnutls_assert ();
195 /* we need this in order to get peer's certificate */ 195 /* we need this in order to get peer's certificate */
196 return GNUTLS_E_INTERNAL_ERROR; 196 return GNUTLS_E_INTERNAL_ERROR;
197 } 197 }
198 198
199 ret = mhd_gtls_proc_dh_common_server_kx (session, data, _data_size, 0); 199 ret = MHD_gtls_proc_dh_common_server_kx (session, data, _data_size, 0);
200 if (ret < 0) 200 if (ret < 0)
201 { 201 {
202 gnutls_assert (); 202 MHD_gnutls_assert ();
203 return ret; 203 return ret;
204 } 204 }
205 205
@@ -209,29 +209,29 @@ proc_dhe_server_kx (mhd_gtls_session_t session, opaque * data,
209 vparams.data = data; 209 vparams.data = data;
210 210
211 DECR_LEN (data_size, 2); 211 DECR_LEN (data_size, 2);
212 sigsize = mhd_gtls_read_uint16 (&data[vparams.size]); 212 sigsize = MHD_gtls_read_uint16 (&data[vparams.size]);
213 213
214 DECR_LEN (data_size, sigsize); 214 DECR_LEN (data_size, sigsize);
215 signature.data = &data[vparams.size + 2]; 215 signature.data = &data[vparams.size + 2];
216 signature.size = sigsize; 216 signature.size = sigsize;
217 217
218 if ((ret = 218 if ((ret =
219 mhd_gtls_raw_cert_to_gcert (&peer_cert, 219 MHD_gtls_raw_cert_to_gcert (&peer_cert,
220 session->security_parameters.cert_type, 220 session->security_parameters.cert_type,
221 &info->raw_certificate_list[0], 221 &info->raw_certificate_list[0],
222 CERT_NO_COPY)) < 0) 222 CERT_NO_COPY)) < 0)
223 { 223 {
224 gnutls_assert (); 224 MHD_gnutls_assert ();
225 return ret; 225 return ret;
226 } 226 }
227 227
228 ret = 228 ret =
229 mhd_gtls_verify_sig_params (session, &peer_cert, &vparams, &signature); 229 MHD_gtls_verify_sig_params (session, &peer_cert, &vparams, &signature);
230 230
231 mhd_gtls_gcert_deinit (&peer_cert); 231 MHD_gtls_gcert_deinit (&peer_cert);
232 if (ret < 0) 232 if (ret < 0)
233 { 233 {
234 gnutls_assert (); 234 MHD_gnutls_assert ();
235 return ret; 235 return ret;
236 } 236 }
237 237
@@ -241,36 +241,36 @@ proc_dhe_server_kx (mhd_gtls_session_t session, opaque * data,
241 241
242 242
243static int 243static int
244proc_dhe_client_kx (mhd_gtls_session_t session, opaque * data, 244proc_dhe_client_kx (MHD_gtls_session_t session, opaque * data,
245 size_t _data_size) 245 size_t _data_size)
246{ 246{
247 mhd_gtls_cert_credentials_t cred; 247 MHD_gtls_cert_credentials_t cred;
248 int ret; 248 int ret;
249 mpi_t p, g; 249 mpi_t p, g;
250 const mpi_t *mpis; 250 const mpi_t *mpis;
251 mhd_gtls_dh_params_t dh_params; 251 MHD_gtls_dh_params_t dh_params;
252 252
253 cred = (mhd_gtls_cert_credentials_t) 253 cred = (MHD_gtls_cert_credentials_t)
254 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 254 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
255 if (cred == NULL) 255 if (cred == NULL)
256 { 256 {
257 gnutls_assert (); 257 MHD_gnutls_assert ();
258 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 258 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
259 } 259 }
260 260
261 dh_params = 261 dh_params =
262 mhd_gtls_get_dh_params (cred->dh_params, cred->params_func, session); 262 MHD_gtls_get_dh_params (cred->dh_params, cred->params_func, session);
263 mpis = mhd_gtls_dh_params_to_mpi (dh_params); 263 mpis = MHD_gtls_dh_params_to_mpi (dh_params);
264 if (mpis == NULL) 264 if (mpis == NULL)
265 { 265 {
266 gnutls_assert (); 266 MHD_gnutls_assert ();
267 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS; 267 return GNUTLS_E_NO_TEMPORARY_DH_PARAMS;
268 } 268 }
269 269
270 p = mpis[0]; 270 p = mpis[0];
271 g = mpis[1]; 271 g = mpis[1];
272 272
273 ret = mhd_gtls_proc_dh_common_client_kx (session, data, _data_size, g, p); 273 ret = MHD_gtls_proc_dh_common_client_kx (session, data, _data_size, g, p);
274 274
275 return ret; 275 return ret;
276 276
diff --git a/src/daemon/https/tls/auth_rsa.c b/src/daemon/https/tls/auth_rsa.c
index b3833814..7a66eae6 100644
--- a/src/daemon/https/tls/auth_rsa.c
+++ b/src/daemon/https/tls/auth_rsa.c
@@ -42,85 +42,85 @@
42#include <gnutls_x509.h> 42#include <gnutls_x509.h>
43#include <gc.h> 43#include <gc.h>
44 44
45int _gnutls_gen_rsa_client_kx (mhd_gtls_session_t, opaque **); 45int MHD__gnutls_gen_rsa_client_kx (MHD_gtls_session_t, opaque **);
46int _gnutls_proc_rsa_client_kx (mhd_gtls_session_t, opaque *, size_t); 46int MHD__gnutls_proc_rsa_client_kx (MHD_gtls_session_t, opaque *, size_t);
47 47
48const mhd_gtls_mod_auth_st mhd_gtls_rsa_auth_struct = { 48const MHD_gtls_mod_auth_st MHD_gtls_rsa_auth_struct = {
49 "RSA", 49 "RSA",
50 mhd_gtls_gen_cert_server_certificate, 50 MHD_gtls_gen_cert_server_certificate,
51 mhd_gtls_gen_cert_client_certificate, 51 MHD_gtls_gen_cert_client_certificate,
52 NULL, /* gen server kx */ 52 NULL, /* gen server kx */
53 _gnutls_gen_rsa_client_kx, 53 MHD__gnutls_gen_rsa_client_kx,
54 mhd_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */ 54 MHD_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */
55 mhd_gtls_gen_cert_server_cert_req, /* server cert request */ 55 MHD_gtls_gen_cert_server_cert_req, /* server cert request */
56 56
57 mhd_gtls_proc_cert_server_certificate, 57 MHD_gtls_proc_cert_server_certificate,
58 _gnutls_proc_cert_client_certificate, 58 MHD__gnutls_proc_cert_client_certificate,
59 NULL, /* proc server kx */ 59 NULL, /* proc server kx */
60 _gnutls_proc_rsa_client_kx, /* proc client kx */ 60 MHD__gnutls_proc_rsa_client_kx, /* proc client kx */
61 mhd_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */ 61 MHD_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */
62 mhd_gtls_proc_cert_cert_req /* proc server cert request */ 62 MHD_gtls_proc_cert_cert_req /* proc server cert request */
63}; 63};
64 64
65/* This function reads the RSA parameters from peer's certificate; 65/* This function reads the RSA parameters from peer's certificate;
66 */ 66 */
67int 67int
68_gnutls_get_public_rsa_params (mhd_gtls_session_t session, 68MHD__gnutls_get_public_rsa_params (MHD_gtls_session_t session,
69 mpi_t params[MAX_PUBLIC_PARAMS_SIZE], 69 mpi_t params[MAX_PUBLIC_PARAMS_SIZE],
70 int *params_len) 70 int *params_len)
71{ 71{
72 int ret; 72 int ret;
73 cert_auth_info_t info; 73 cert_auth_info_t info;
74 gnutls_cert peer_cert; 74 MHD_gnutls_cert peer_cert;
75 int i; 75 int i;
76 76
77 /* normal non export case */ 77 /* normal non export case */
78 78
79 info = mhd_gtls_get_auth_info (session); 79 info = MHD_gtls_get_auth_info (session);
80 80
81 if (info == NULL || info->ncerts == 0) 81 if (info == NULL || info->ncerts == 0)
82 { 82 {
83 gnutls_assert (); 83 MHD_gnutls_assert ();
84 return GNUTLS_E_INTERNAL_ERROR; 84 return GNUTLS_E_INTERNAL_ERROR;
85 } 85 }
86 86
87 ret = 87 ret =
88 mhd_gtls_raw_cert_to_gcert (&peer_cert, 88 MHD_gtls_raw_cert_to_gcert (&peer_cert,
89 session->security_parameters.cert_type, 89 session->security_parameters.cert_type,
90 &info->raw_certificate_list[0], 90 &info->raw_certificate_list[0],
91 CERT_ONLY_PUBKEY | CERT_NO_COPY); 91 CERT_ONLY_PUBKEY | CERT_NO_COPY);
92 92
93 if (ret < 0) 93 if (ret < 0)
94 { 94 {
95 gnutls_assert (); 95 MHD_gnutls_assert ();
96 return ret; 96 return ret;
97 } 97 }
98 98
99 99
100 /* EXPORT case: */ 100 /* EXPORT case: */
101 if (mhd_gtls_cipher_suite_get_kx_algo 101 if (MHD_gtls_cipher_suite_get_kx_algo
102 (&session->security_parameters.current_cipher_suite) 102 (&session->security_parameters.current_cipher_suite)
103 == MHD_GNUTLS_KX_RSA_EXPORT 103 == MHD_GNUTLS_KX_RSA_EXPORT
104 && _gnutls_mpi_get_nbits (peer_cert.params[0]) > 512) 104 && MHD__gnutls_mpi_get_nbits (peer_cert.params[0]) > 512)
105 { 105 {
106 106
107 mhd_gtls_gcert_deinit (&peer_cert); 107 MHD_gtls_gcert_deinit (&peer_cert);
108 108
109 if (session->key->rsa[0] == NULL || session->key->rsa[1] == NULL) 109 if (session->key->rsa[0] == NULL || session->key->rsa[1] == NULL)
110 { 110 {
111 gnutls_assert (); 111 MHD_gnutls_assert ();
112 return GNUTLS_E_INTERNAL_ERROR; 112 return GNUTLS_E_INTERNAL_ERROR;
113 } 113 }
114 114
115 if (*params_len < 2) 115 if (*params_len < 2)
116 { 116 {
117 gnutls_assert (); 117 MHD_gnutls_assert ();
118 return GNUTLS_E_INTERNAL_ERROR; 118 return GNUTLS_E_INTERNAL_ERROR;
119 } 119 }
120 *params_len = 2; 120 *params_len = 2;
121 for (i = 0; i < *params_len; i++) 121 for (i = 0; i < *params_len; i++)
122 { 122 {
123 params[i] = _gnutls_mpi_copy (session->key->rsa[i]); 123 params[i] = MHD__gnutls_mpi_copy (session->key->rsa[i]);
124 } 124 }
125 125
126 return 0; 126 return 0;
@@ -130,16 +130,16 @@ _gnutls_get_public_rsa_params (mhd_gtls_session_t session,
130 130
131 if (*params_len < peer_cert.params_size) 131 if (*params_len < peer_cert.params_size)
132 { 132 {
133 gnutls_assert (); 133 MHD_gnutls_assert ();
134 return GNUTLS_E_INTERNAL_ERROR; 134 return GNUTLS_E_INTERNAL_ERROR;
135 } 135 }
136 *params_len = peer_cert.params_size; 136 *params_len = peer_cert.params_size;
137 137
138 for (i = 0; i < *params_len; i++) 138 for (i = 0; i < *params_len; i++)
139 { 139 {
140 params[i] = _gnutls_mpi_copy (peer_cert.params[i]); 140 params[i] = MHD__gnutls_mpi_copy (peer_cert.params[i]);
141 } 141 }
142 mhd_gtls_gcert_deinit (&peer_cert); 142 MHD_gtls_gcert_deinit (&peer_cert);
143 143
144 return 0; 144 return 0;
145} 145}
@@ -147,43 +147,43 @@ _gnutls_get_public_rsa_params (mhd_gtls_session_t session,
147/* This function reads the RSA parameters from the private key 147/* This function reads the RSA parameters from the private key
148 */ 148 */
149int 149int
150_gnutls_get_private_rsa_params (mhd_gtls_session_t session, 150MHD__gnutls_get_private_rsa_params (MHD_gtls_session_t session,
151 mpi_t ** params, int *params_size) 151 mpi_t ** params, int *params_size)
152{ 152{
153 int bits; 153 int bits;
154 mhd_gtls_cert_credentials_t cred; 154 MHD_gtls_cert_credentials_t cred;
155 mhd_gtls_rsa_params_t rsa_params; 155 MHD_gtls_rsa_params_t rsa_params;
156 156
157 cred = (mhd_gtls_cert_credentials_t) 157 cred = (MHD_gtls_cert_credentials_t)
158 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 158 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
159 if (cred == NULL) 159 if (cred == NULL)
160 { 160 {
161 gnutls_assert (); 161 MHD_gnutls_assert ();
162 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 162 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
163 } 163 }
164 164
165 if (session->internals.selected_cert_list == NULL) 165 if (session->internals.selected_cert_list == NULL)
166 { 166 {
167 gnutls_assert (); 167 MHD_gnutls_assert ();
168 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 168 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
169 } 169 }
170 170
171 bits = 171 bits =
172 _gnutls_mpi_get_nbits (session->internals.selected_cert_list[0]. 172 MHD__gnutls_mpi_get_nbits (session->internals.selected_cert_list[0].
173 params[0]); 173 params[0]);
174 174
175 if (mhd_gtls_cipher_suite_get_kx_algo 175 if (MHD_gtls_cipher_suite_get_kx_algo
176 (&session->security_parameters.current_cipher_suite) 176 (&session->security_parameters.current_cipher_suite)
177 == MHD_GNUTLS_KX_RSA_EXPORT && bits > 512) 177 == MHD_GNUTLS_KX_RSA_EXPORT && bits > 512)
178 { 178 {
179 179
180 rsa_params = 180 rsa_params =
181 mhd_gtls_certificate_get_rsa_params (cred->rsa_params, 181 MHD_gtls_certificate_get_rsa_params (cred->rsa_params,
182 cred->params_func, session); 182 cred->params_func, session);
183 /* EXPORT case: */ 183 /* EXPORT case: */
184 if (rsa_params == NULL) 184 if (rsa_params == NULL)
185 { 185 {
186 gnutls_assert (); 186 MHD_gnutls_assert ();
187 return GNUTLS_E_NO_TEMPORARY_RSA_PARAMS; 187 return GNUTLS_E_NO_TEMPORARY_RSA_PARAMS;
188 } 188 }
189 189
@@ -206,18 +206,18 @@ _gnutls_get_private_rsa_params (mhd_gtls_session_t session,
206} 206}
207 207
208int 208int
209_gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data, 209MHD__gnutls_proc_rsa_client_kx (MHD_gtls_session_t session, opaque * data,
210 size_t _data_size) 210 size_t _data_size)
211{ 211{
212 gnutls_datum_t plaintext; 212 MHD_gnutls_datum_t plaintext;
213 gnutls_datum_t ciphertext; 213 MHD_gnutls_datum_t ciphertext;
214 int ret, dsize; 214 int ret, dsize;
215 mpi_t *params; 215 mpi_t *params;
216 int params_len; 216 int params_len;
217 int randomize_key = 0; 217 int randomize_key = 0;
218 ssize_t data_size = _data_size; 218 ssize_t data_size = _data_size;
219 219
220 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 220 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
221 { 221 {
222 /* SSL 3.0 222 /* SSL 3.0
223 */ 223 */
@@ -230,24 +230,24 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
230 */ 230 */
231 DECR_LEN (data_size, 2); 231 DECR_LEN (data_size, 2);
232 ciphertext.data = &data[2]; 232 ciphertext.data = &data[2];
233 dsize = mhd_gtls_read_uint16 (data); 233 dsize = MHD_gtls_read_uint16 (data);
234 234
235 if (dsize != data_size) 235 if (dsize != data_size)
236 { 236 {
237 gnutls_assert (); 237 MHD_gnutls_assert ();
238 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 238 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
239 } 239 }
240 ciphertext.size = dsize; 240 ciphertext.size = dsize;
241 } 241 }
242 242
243 ret = _gnutls_get_private_rsa_params (session, &params, &params_len); 243 ret = MHD__gnutls_get_private_rsa_params (session, &params, &params_len);
244 if (ret < 0) 244 if (ret < 0)
245 { 245 {
246 gnutls_assert (); 246 MHD_gnutls_assert ();
247 return ret; 247 return ret;
248 } 248 }
249 249
250 ret = mhd_gtls_pkcs1_rsa_decrypt (&plaintext, &ciphertext, params, params_len, 2); /* btype==2 */ 250 ret = MHD_gtls_pkcs1_rsa_decrypt (&plaintext, &ciphertext, params, params_len, 2); /* btype==2 */
251 251
252 if (ret < 0 || plaintext.size != TLS_MASTER_SIZE) 252 if (ret < 0 || plaintext.size != TLS_MASTER_SIZE)
253 { 253 {
@@ -255,8 +255,8 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
255 * the peer. Just use a random key. (in order to avoid 255 * the peer. Just use a random key. (in order to avoid
256 * attack against pkcs-1 formating). 256 * attack against pkcs-1 formating).
257 */ 257 */
258 gnutls_assert (); 258 MHD_gnutls_assert ();
259 _gnutls_x509_log ("auth_rsa: Possible PKCS #1 format attack\n"); 259 MHD__gnutls_x509_log ("auth_rsa: Possible PKCS #1 format attack\n");
260 randomize_key = 1; 260 randomize_key = 1;
261 } 261 }
262 else 262 else
@@ -264,8 +264,8 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
264 /* If the secret was properly formatted, then 264 /* If the secret was properly formatted, then
265 * check the version number. 265 * check the version number.
266 */ 266 */
267 if (_gnutls_get_adv_version_major (session) != plaintext.data[0] 267 if (MHD__gnutls_get_adv_version_major (session) != plaintext.data[0]
268 || _gnutls_get_adv_version_minor (session) != plaintext.data[1]) 268 || MHD__gnutls_get_adv_version_minor (session) != plaintext.data[1])
269 { 269 {
270 /* No error is returned here, if the version number check 270 /* No error is returned here, if the version number check
271 * fails. We proceed normally. 271 * fails. We proceed normally.
@@ -273,8 +273,8 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
273 * "Attacking RSA-based sessions in SSL/TLS" by Vlastimil Klima, 273 * "Attacking RSA-based sessions in SSL/TLS" by Vlastimil Klima,
274 * Ondej Pokorny and Tomas Rosa. 274 * Ondej Pokorny and Tomas Rosa.
275 */ 275 */
276 gnutls_assert (); 276 MHD_gnutls_assert ();
277 _gnutls_x509_log 277 MHD__gnutls_x509_log
278 ("auth_rsa: Possible PKCS #1 version check format attack\n"); 278 ("auth_rsa: Possible PKCS #1 version check format attack\n");
279 } 279 }
280 } 280 }
@@ -282,18 +282,18 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
282 if (randomize_key != 0) 282 if (randomize_key != 0)
283 { 283 {
284 session->key->key.size = TLS_MASTER_SIZE; 284 session->key->key.size = TLS_MASTER_SIZE;
285 session->key->key.data = gnutls_malloc (session->key->key.size); 285 session->key->key.data = MHD_gnutls_malloc (session->key->key.size);
286 if (session->key->key.data == NULL) 286 if (session->key->key.data == NULL)
287 { 287 {
288 gnutls_assert (); 288 MHD_gnutls_assert ();
289 return GNUTLS_E_MEMORY_ERROR; 289 return GNUTLS_E_MEMORY_ERROR;
290 } 290 }
291 291
292 /* we do not need strong random numbers here. 292 /* we do not need strong random numbers here.
293 */ 293 */
294 if (gc_nonce (session->key->key.data, session->key->key.size) != GC_OK) 294 if (MHD_gc_nonce (session->key->key.data, session->key->key.size) != GC_OK)
295 { 295 {
296 gnutls_assert (); 296 MHD_gnutls_assert ();
297 return GNUTLS_E_RANDOM_FAILED; 297 return GNUTLS_E_RANDOM_FAILED;
298 } 298 }
299 299
@@ -307,8 +307,8 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
307 /* This is here to avoid the version check attack 307 /* This is here to avoid the version check attack
308 * discussed above. 308 * discussed above.
309 */ 309 */
310 session->key->key.data[0] = _gnutls_get_adv_version_major (session); 310 session->key->key.data[0] = MHD__gnutls_get_adv_version_major (session);
311 session->key->key.data[1] = _gnutls_get_adv_version_minor (session); 311 session->key->key.data[1] = MHD__gnutls_get_adv_version_minor (session);
312 312
313 return 0; 313 return 0;
314} 314}
@@ -318,46 +318,53 @@ _gnutls_proc_rsa_client_kx (mhd_gtls_session_t session, opaque * data,
318/* return RSA(random) using the peers public key 318/* return RSA(random) using the peers public key
319 */ 319 */
320int 320int
321_gnutls_gen_rsa_client_kx (mhd_gtls_session_t session, opaque ** data) 321MHD__gnutls_gen_rsa_client_kx (MHD_gtls_session_t session, opaque ** data)
322{ 322{
323 cert_auth_info_t auth = session->key->auth_info; 323 cert_auth_info_t auth;
324 gnutls_datum_t sdata; /* data to send */ 324 MHD_gnutls_datum_t sdata; /* data to send */
325 mpi_t params[MAX_PUBLIC_PARAMS_SIZE]; 325 mpi_t params[MAX_PUBLIC_PARAMS_SIZE];
326 int params_len = MAX_PUBLIC_PARAMS_SIZE; 326 int params_len = MAX_PUBLIC_PARAMS_SIZE;
327 int ret, i; 327 int ret, i;
328 enum MHD_GNUTLS_Protocol ver; 328 enum MHD_GNUTLS_Protocol ver;
329 329
330 if (session->key == NULL)
331 {
332 MHD_gnutls_assert ();
333 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
334 }
335
336 auth = session->key->auth_info;
330 if (auth == NULL) 337 if (auth == NULL)
331 { 338 {
332 /* this shouldn't have happened. The proc_certificate 339 /* this shouldn't have happened. The proc_certificate
333 * function should have detected that. 340 * function should have detected that.
334 */ 341 */
335 gnutls_assert (); 342 MHD_gnutls_assert ();
336 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 343 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
337 } 344 }
338 345
339 session->key->key.size = TLS_MASTER_SIZE; 346 session->key->key.size = TLS_MASTER_SIZE;
340 session->key->key.data = gnutls_secure_malloc (session->key->key.size); 347 session->key->key.data = MHD_gnutls_secure_malloc (session->key->key.size);
341 348
342 if (session->key->key.data == NULL) 349 if (session->key->key.data == NULL)
343 { 350 {
344 gnutls_assert (); 351 MHD_gnutls_assert ();
345 return GNUTLS_E_MEMORY_ERROR; 352 return GNUTLS_E_MEMORY_ERROR;
346 } 353 }
347 354
348 if (gc_pseudo_random (session->key->key.data, 355 if (MHD_gc_pseudo_random (session->key->key.data,
349 session->key->key.size) != GC_OK) 356 session->key->key.size) != GC_OK)
350 { 357 {
351 gnutls_assert (); 358 MHD_gnutls_assert ();
352 return GNUTLS_E_RANDOM_FAILED; 359 return GNUTLS_E_RANDOM_FAILED;
353 } 360 }
354 361
355 ver = mhd_gtls_get_adv_version (session); 362 ver = MHD_gtls_get_adv_version (session);
356 363
357 if (session->internals.rsa_pms_version[0] == 0) 364 if (session->internals.rsa_pms_version[0] == 0)
358 { 365 {
359 session->key->key.data[0] = mhd_gtls_version_get_major (ver); 366 session->key->key.data[0] = MHD_gtls_version_get_major (ver);
360 session->key->key.data[1] = mhd_gtls_version_get_minor (ver); 367 session->key->key.data[1] = MHD_gtls_version_get_minor (ver);
361 } 368 }
362 else 369 else
363 { /* use the version provided */ 370 { /* use the version provided */
@@ -368,24 +375,24 @@ _gnutls_gen_rsa_client_kx (mhd_gtls_session_t session, opaque ** data)
368 /* move RSA parameters to key (session). 375 /* move RSA parameters to key (session).
369 */ 376 */
370 if ((ret = 377 if ((ret =
371 _gnutls_get_public_rsa_params (session, params, &params_len)) < 0) 378 MHD__gnutls_get_public_rsa_params (session, params, &params_len)) < 0)
372 { 379 {
373 gnutls_assert (); 380 MHD_gnutls_assert ();
374 return ret; 381 return ret;
375 } 382 }
376 383
377 if ((ret = 384 if ((ret =
378 mhd_gtls_pkcs1_rsa_encrypt (&sdata, &session->key->key, 385 MHD_gtls_pkcs1_rsa_encrypt (&sdata, &session->key->key,
379 params, params_len, 2)) < 0) 386 params, params_len, 2)) < 0)
380 { 387 {
381 gnutls_assert (); 388 MHD_gnutls_assert ();
382 return ret; 389 return ret;
383 } 390 }
384 391
385 for (i = 0; i < params_len; i++) 392 for (i = 0; i < params_len; i++)
386 mhd_gtls_mpi_release (&params[i]); 393 MHD_gtls_mpi_release (&params[i]);
387 394
388 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 395 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
389 { 396 {
390 /* SSL 3.0 */ 397 /* SSL 3.0 */
391 *data = sdata.data; 398 *data = sdata.data;
@@ -393,15 +400,15 @@ _gnutls_gen_rsa_client_kx (mhd_gtls_session_t session, opaque ** data)
393 } 400 }
394 else 401 else
395 { /* TLS 1 */ 402 { /* TLS 1 */
396 *data = gnutls_malloc (sdata.size + 2); 403 *data = MHD_gnutls_malloc (sdata.size + 2);
397 if (*data == NULL) 404 if (*data == NULL)
398 { 405 {
399 _gnutls_free_datum (&sdata); 406 MHD__gnutls_free_datum (&sdata);
400 return GNUTLS_E_MEMORY_ERROR; 407 return GNUTLS_E_MEMORY_ERROR;
401 } 408 }
402 mhd_gtls_write_datum16 (*data, sdata); 409 MHD_gtls_write_datum16 (*data, sdata);
403 ret = sdata.size + 2; 410 ret = sdata.size + 2;
404 _gnutls_free_datum (&sdata); 411 MHD__gnutls_free_datum (&sdata);
405 return ret; 412 return ret;
406 } 413 }
407 414
diff --git a/src/daemon/https/tls/auth_rsa_export.c b/src/daemon/https/tls/auth_rsa_export.c
index 5442c8ba..9269f704 100644
--- a/src/daemon/https/tls/auth_rsa_export.c
+++ b/src/daemon/https/tls/auth_rsa_export.c
@@ -43,105 +43,105 @@
43#include <gnutls_rsa_export.h> 43#include <gnutls_rsa_export.h>
44#include <gnutls_state.h> 44#include <gnutls_state.h>
45 45
46int _gnutls_gen_rsa_client_kx (mhd_gtls_session_t, opaque **); 46int MHD__gnutls_gen_rsa_client_kx (MHD_gtls_session_t, opaque **);
47int _gnutls_proc_rsa_client_kx (mhd_gtls_session_t, opaque *, size_t); 47int MHD__gnutls_proc_rsa_client_kx (MHD_gtls_session_t, opaque *, size_t);
48static int gen_rsa_export_server_kx (mhd_gtls_session_t, opaque **); 48static int gen_rsa_export_server_kx (MHD_gtls_session_t, opaque **);
49static int proc_rsa_export_server_kx (mhd_gtls_session_t, opaque *, size_t); 49static int proc_rsa_export_server_kx (MHD_gtls_session_t, opaque *, size_t);
50 50
51const mhd_gtls_mod_auth_st rsa_export_auth_struct = { 51const MHD_gtls_mod_auth_st rsa_export_auth_struct = {
52 "RSA EXPORT", 52 "RSA EXPORT",
53 mhd_gtls_gen_cert_server_certificate, 53 MHD_gtls_gen_cert_server_certificate,
54 mhd_gtls_gen_cert_client_certificate, 54 MHD_gtls_gen_cert_client_certificate,
55 gen_rsa_export_server_kx, 55 gen_rsa_export_server_kx,
56 _gnutls_gen_rsa_client_kx, 56 MHD__gnutls_gen_rsa_client_kx,
57 mhd_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */ 57 MHD_gtls_gen_cert_client_cert_vrfy, /* gen client cert vrfy */
58 mhd_gtls_gen_cert_server_cert_req, /* server cert request */ 58 MHD_gtls_gen_cert_server_cert_req, /* server cert request */
59 59
60 mhd_gtls_proc_cert_server_certificate, 60 MHD_gtls_proc_cert_server_certificate,
61 _gnutls_proc_cert_client_certificate, 61 MHD__gnutls_proc_cert_client_certificate,
62 proc_rsa_export_server_kx, 62 proc_rsa_export_server_kx,
63 _gnutls_proc_rsa_client_kx, /* proc client kx */ 63 MHD__gnutls_proc_rsa_client_kx, /* proc client kx */
64 mhd_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */ 64 MHD_gtls_proc_cert_client_cert_vrfy, /* proc client cert vrfy */
65 mhd_gtls_proc_cert_cert_req /* proc server cert request */ 65 MHD_gtls_proc_cert_cert_req /* proc server cert request */
66}; 66};
67 67
68static int 68static int
69gen_rsa_export_server_kx (mhd_gtls_session_t session, opaque ** data) 69gen_rsa_export_server_kx (MHD_gtls_session_t session, opaque ** data)
70{ 70{
71 mhd_gtls_rsa_params_t rsa_params; 71 MHD_gtls_rsa_params_t rsa_params;
72 const mpi_t *rsa_mpis; 72 const mpi_t *rsa_mpis;
73 size_t n_e, n_m; 73 size_t n_e, n_m;
74 uint8_t *data_e, *data_m; 74 uint8_t *data_e, *data_m;
75 int ret = 0, data_size; 75 int ret = 0, data_size;
76 gnutls_cert *apr_cert_list; 76 MHD_gnutls_cert *apr_cert_list;
77 gnutls_privkey *apr_pkey; 77 MHD_gnutls_privkey *apr_pkey;
78 int apr_cert_list_length; 78 int apr_cert_list_length;
79 gnutls_datum_t signature, ddata; 79 MHD_gnutls_datum_t signature, ddata;
80 mhd_gtls_cert_credentials_t cred; 80 MHD_gtls_cert_credentials_t cred;
81 81
82 cred = (mhd_gtls_cert_credentials_t) 82 cred = (MHD_gtls_cert_credentials_t)
83 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 83 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
84 if (cred == NULL) 84 if (cred == NULL)
85 { 85 {
86 gnutls_assert (); 86 MHD_gnutls_assert ();
87 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 87 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
88 } 88 }
89 89
90 /* find the appropriate certificate */ 90 /* find the appropriate certificate */
91 if ((ret = 91 if ((ret =
92 mhd_gtls_get_selected_cert (session, &apr_cert_list, 92 MHD_gtls_get_selected_cert (session, &apr_cert_list,
93 &apr_cert_list_length, &apr_pkey)) < 0) 93 &apr_cert_list_length, &apr_pkey)) < 0)
94 { 94 {
95 gnutls_assert (); 95 MHD_gnutls_assert ();
96 return ret; 96 return ret;
97 } 97 }
98 98
99 /* abort sending this message if we have a certificate 99 /* abort sending this message if we have a certificate
100 * of 512 bits or less. 100 * of 512 bits or less.
101 */ 101 */
102 if (apr_pkey && _gnutls_mpi_get_nbits (apr_pkey->params[0]) <= 512) 102 if (apr_pkey && MHD__gnutls_mpi_get_nbits (apr_pkey->params[0]) <= 512)
103 { 103 {
104 gnutls_assert (); 104 MHD_gnutls_assert ();
105 return GNUTLS_E_INT_RET_0; 105 return GNUTLS_E_INT_RET_0;
106 } 106 }
107 107
108 rsa_params = 108 rsa_params =
109 mhd_gtls_certificate_get_rsa_params (cred->rsa_params, cred->params_func, 109 MHD_gtls_certificate_get_rsa_params (cred->rsa_params, cred->params_func,
110 session); 110 session);
111 rsa_mpis = _gnutls_rsa_params_to_mpi (rsa_params); 111 rsa_mpis = MHD__gnutls_rsa_params_to_mpi (rsa_params);
112 if (rsa_mpis == NULL) 112 if (rsa_mpis == NULL)
113 { 113 {
114 gnutls_assert (); 114 MHD_gnutls_assert ();
115 return GNUTLS_E_NO_TEMPORARY_RSA_PARAMS; 115 return GNUTLS_E_NO_TEMPORARY_RSA_PARAMS;
116 } 116 }
117 117
118 if ((ret = mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE, 118 if ((ret = MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE,
119 sizeof (cert_auth_info_st), 0)) < 0) 119 sizeof (cert_auth_info_st), 0)) < 0)
120 { 120 {
121 gnutls_assert (); 121 MHD_gnutls_assert ();
122 return ret; 122 return ret;
123 } 123 }
124 124
125 mhd_gtls_rsa_export_set_pubkey (session, rsa_mpis[1], rsa_mpis[0]); 125 MHD_gtls_rsa_export_set_pubkey (session, rsa_mpis[1], rsa_mpis[0]);
126 126
127 mhd_gtls_mpi_print (NULL, &n_m, rsa_mpis[0]); 127 MHD_gtls_mpi_print (NULL, &n_m, rsa_mpis[0]);
128 mhd_gtls_mpi_print (NULL, &n_e, rsa_mpis[1]); 128 MHD_gtls_mpi_print (NULL, &n_e, rsa_mpis[1]);
129 129
130 (*data) = gnutls_malloc (n_e + n_m + 4); 130 (*data) = MHD_gnutls_malloc (n_e + n_m + 4);
131 if (*data == NULL) 131 if (*data == NULL)
132 { 132 {
133 return GNUTLS_E_MEMORY_ERROR; 133 return GNUTLS_E_MEMORY_ERROR;
134 } 134 }
135 135
136 data_m = &(*data)[0]; 136 data_m = &(*data)[0];
137 mhd_gtls_mpi_print (&data_m[2], &n_m, rsa_mpis[0]); 137 MHD_gtls_mpi_print (&data_m[2], &n_m, rsa_mpis[0]);
138 138
139 mhd_gtls_write_uint16 (n_m, data_m); 139 MHD_gtls_write_uint16 (n_m, data_m);
140 140
141 data_e = &data_m[2 + n_m]; 141 data_e = &data_m[2 + n_m];
142 mhd_gtls_mpi_print (&data_e[2], &n_e, rsa_mpis[1]); 142 MHD_gtls_mpi_print (&data_e[2], &n_e, rsa_mpis[1]);
143 143
144 mhd_gtls_write_uint16 (n_e, data_e); 144 MHD_gtls_write_uint16 (n_e, data_e);
145 145
146 data_size = n_m + n_e + 4; 146 data_size = n_m + n_e + 4;
147 147
@@ -154,33 +154,33 @@ gen_rsa_export_server_kx (mhd_gtls_session_t session, opaque ** data)
154 if (apr_cert_list_length > 0) 154 if (apr_cert_list_length > 0)
155 { 155 {
156 if ((ret = 156 if ((ret =
157 mhd_gtls_tls_sign_params (session, &apr_cert_list[0], 157 MHD_gtls_tls_sign_params (session, &apr_cert_list[0],
158 apr_pkey, &ddata, &signature)) < 0) 158 apr_pkey, &ddata, &signature)) < 0)
159 { 159 {
160 gnutls_assert (); 160 MHD_gnutls_assert ();
161 gnutls_free (*data); 161 MHD_gnutls_free (*data);
162 *data = NULL; 162 *data = NULL;
163 return ret; 163 return ret;
164 } 164 }
165 } 165 }
166 else 166 else
167 { 167 {
168 gnutls_assert (); 168 MHD_gnutls_assert ();
169 return data_size; /* do not put a signature - ILLEGAL! */ 169 return data_size; /* do not put a signature - ILLEGAL! */
170 } 170 }
171 171
172 *data = mhd_gtls_realloc_fast (*data, data_size + signature.size + 2); 172 *data = MHD_gtls_realloc_fast (*data, data_size + signature.size + 2);
173 if (*data == NULL) 173 if (*data == NULL)
174 { 174 {
175 _gnutls_free_datum (&signature); 175 MHD__gnutls_free_datum (&signature);
176 gnutls_assert (); 176 MHD_gnutls_assert ();
177 return GNUTLS_E_MEMORY_ERROR; 177 return GNUTLS_E_MEMORY_ERROR;
178 } 178 }
179 179
180 mhd_gtls_write_datum16 (&((*data)[data_size]), signature); 180 MHD_gtls_write_datum16 (&((*data)[data_size]), signature);
181 data_size += signature.size + 2; 181 data_size += signature.size + 2;
182 182
183 _gnutls_free_datum (&signature); 183 MHD__gnutls_free_datum (&signature);
184 184
185 return data_size; 185 return data_size;
186} 186}
@@ -188,49 +188,49 @@ gen_rsa_export_server_kx (mhd_gtls_session_t session, opaque ** data)
188/* if the peer's certificate is of 512 bits or less, returns non zero. 188/* if the peer's certificate is of 512 bits or less, returns non zero.
189 */ 189 */
190int 190int
191_gnutls_peers_cert_less_512 (mhd_gtls_session_t session) 191MHD__gnutls_peers_cert_less_512 (MHD_gtls_session_t session)
192{ 192{
193 gnutls_cert peer_cert; 193 MHD_gnutls_cert peer_cert;
194 int ret; 194 int ret;
195 cert_auth_info_t info = mhd_gtls_get_auth_info (session); 195 cert_auth_info_t info = MHD_gtls_get_auth_info (session);
196 196
197 if (info == NULL || info->ncerts == 0) 197 if (info == NULL || info->ncerts == 0)
198 { 198 {
199 gnutls_assert (); 199 MHD_gnutls_assert ();
200 /* we need this in order to get peer's certificate */ 200 /* we need this in order to get peer's certificate */
201 return 0; 201 return 0;
202 } 202 }
203 203
204 if ((ret = 204 if ((ret =
205 mhd_gtls_raw_cert_to_gcert (&peer_cert, 205 MHD_gtls_raw_cert_to_gcert (&peer_cert,
206 session->security_parameters.cert_type, 206 session->security_parameters.cert_type,
207 &info->raw_certificate_list[0], 207 &info->raw_certificate_list[0],
208 CERT_NO_COPY)) < 0) 208 CERT_NO_COPY)) < 0)
209 { 209 {
210 gnutls_assert (); 210 MHD_gnutls_assert ();
211 return 0; 211 return 0;
212 } 212 }
213 213
214 if (peer_cert.subject_pk_algorithm != MHD_GNUTLS_PK_RSA) 214 if (peer_cert.subject_pk_algorithm != MHD_GNUTLS_PK_RSA)
215 { 215 {
216 gnutls_assert (); 216 MHD_gnutls_assert ();
217 mhd_gtls_gcert_deinit (&peer_cert); 217 MHD_gtls_gcert_deinit (&peer_cert);
218 return 0; 218 return 0;
219 } 219 }
220 220
221 if (_gnutls_mpi_get_nbits (peer_cert.params[0]) <= 512) 221 if (MHD__gnutls_mpi_get_nbits (peer_cert.params[0]) <= 512)
222 { 222 {
223 mhd_gtls_gcert_deinit (&peer_cert); 223 MHD_gtls_gcert_deinit (&peer_cert);
224 return 1; 224 return 1;
225 } 225 }
226 226
227 mhd_gtls_gcert_deinit (&peer_cert); 227 MHD_gtls_gcert_deinit (&peer_cert);
228 228
229 return 0; 229 return 0;
230} 230}
231 231
232static int 232static int
233proc_rsa_export_server_kx (mhd_gtls_session_t session, 233proc_rsa_export_server_kx (MHD_gtls_session_t session,
234 opaque * data, size_t _data_size) 234 opaque * data, size_t _data_size)
235{ 235{
236 uint16_t n_m, n_e; 236 uint16_t n_m, n_e;
@@ -238,16 +238,16 @@ proc_rsa_export_server_kx (mhd_gtls_session_t session,
238 uint8_t *data_m; 238 uint8_t *data_m;
239 uint8_t *data_e; 239 uint8_t *data_e;
240 int i, sigsize; 240 int i, sigsize;
241 gnutls_datum_t vparams, signature; 241 MHD_gnutls_datum_t vparams, signature;
242 int ret; 242 int ret;
243 ssize_t data_size = _data_size; 243 ssize_t data_size = _data_size;
244 cert_auth_info_t info; 244 cert_auth_info_t info;
245 gnutls_cert peer_cert; 245 MHD_gnutls_cert peer_cert;
246 246
247 info = mhd_gtls_get_auth_info (session); 247 info = MHD_gtls_get_auth_info (session);
248 if (info == NULL || info->ncerts == 0) 248 if (info == NULL || info->ncerts == 0)
249 { 249 {
250 gnutls_assert (); 250 MHD_gnutls_assert ();
251 /* we need this in order to get peer's certificate */ 251 /* we need this in order to get peer's certificate */
252 return GNUTLS_E_INTERNAL_ERROR; 252 return GNUTLS_E_INTERNAL_ERROR;
253 } 253 }
@@ -256,7 +256,7 @@ proc_rsa_export_server_kx (mhd_gtls_session_t session,
256 i = 0; 256 i = 0;
257 257
258 DECR_LEN (data_size, 2); 258 DECR_LEN (data_size, 2);
259 n_m = mhd_gtls_read_uint16 (&data[i]); 259 n_m = MHD_gtls_read_uint16 (&data[i]);
260 i += 2; 260 i += 2;
261 261
262 DECR_LEN (data_size, n_m); 262 DECR_LEN (data_size, n_m);
@@ -264,7 +264,7 @@ proc_rsa_export_server_kx (mhd_gtls_session_t session,
264 i += n_m; 264 i += n_m;
265 265
266 DECR_LEN (data_size, 2); 266 DECR_LEN (data_size, 2);
267 n_e = mhd_gtls_read_uint16 (&data[i]); 267 n_e = MHD_gtls_read_uint16 (&data[i]);
268 i += 2; 268 i += 2;
269 269
270 DECR_LEN (data_size, n_e); 270 DECR_LEN (data_size, n_e);
@@ -274,19 +274,19 @@ proc_rsa_export_server_kx (mhd_gtls_session_t session,
274 _n_e = n_e; 274 _n_e = n_e;
275 _n_m = n_m; 275 _n_m = n_m;
276 276
277 if (mhd_gtls_mpi_scan_nz (&session->key->rsa[0], data_m, &_n_m) != 0) 277 if (MHD_gtls_mpi_scan_nz (&session->key->rsa[0], data_m, &_n_m) != 0)
278 { 278 {
279 gnutls_assert (); 279 MHD_gnutls_assert ();
280 return GNUTLS_E_MPI_SCAN_FAILED; 280 return GNUTLS_E_MPI_SCAN_FAILED;
281 } 281 }
282 282
283 if (mhd_gtls_mpi_scan_nz (&session->key->rsa[1], data_e, &_n_e) != 0) 283 if (MHD_gtls_mpi_scan_nz (&session->key->rsa[1], data_e, &_n_e) != 0)
284 { 284 {
285 gnutls_assert (); 285 MHD_gnutls_assert ();
286 return GNUTLS_E_MPI_SCAN_FAILED; 286 return GNUTLS_E_MPI_SCAN_FAILED;
287 } 287 }
288 288
289 mhd_gtls_rsa_export_set_pubkey (session, session->key->rsa[1], 289 MHD_gtls_rsa_export_set_pubkey (session, session->key->rsa[1],
290 session->key->rsa[0]); 290 session->key->rsa[0]);
291 291
292 /* VERIFY SIGNATURE */ 292 /* VERIFY SIGNATURE */
@@ -295,29 +295,29 @@ proc_rsa_export_server_kx (mhd_gtls_session_t session,
295 vparams.data = data; 295 vparams.data = data;
296 296
297 DECR_LEN (data_size, 2); 297 DECR_LEN (data_size, 2);
298 sigsize = mhd_gtls_read_uint16 (&data[vparams.size]); 298 sigsize = MHD_gtls_read_uint16 (&data[vparams.size]);
299 299
300 DECR_LEN (data_size, sigsize); 300 DECR_LEN (data_size, sigsize);
301 signature.data = &data[vparams.size + 2]; 301 signature.data = &data[vparams.size + 2];
302 signature.size = sigsize; 302 signature.size = sigsize;
303 303
304 if ((ret = 304 if ((ret =
305 mhd_gtls_raw_cert_to_gcert (&peer_cert, 305 MHD_gtls_raw_cert_to_gcert (&peer_cert,
306 session->security_parameters.cert_type, 306 session->security_parameters.cert_type,
307 &info->raw_certificate_list[0], 307 &info->raw_certificate_list[0],
308 CERT_NO_COPY)) < 0) 308 CERT_NO_COPY)) < 0)
309 { 309 {
310 gnutls_assert (); 310 MHD_gnutls_assert ();
311 return ret; 311 return ret;
312 } 312 }
313 313
314 ret = 314 ret =
315 mhd_gtls_verify_sig_params (session, &peer_cert, &vparams, &signature); 315 MHD_gtls_verify_sig_params (session, &peer_cert, &vparams, &signature);
316 316
317 mhd_gtls_gcert_deinit (&peer_cert); 317 MHD_gtls_gcert_deinit (&peer_cert);
318 if (ret < 0) 318 if (ret < 0)
319 { 319 {
320 gnutls_assert (); 320 MHD_gnutls_assert ();
321 } 321 }
322 322
323 return ret; 323 return ret;
diff --git a/src/daemon/https/tls/debug.c b/src/daemon/https/tls/debug.c
index 14c7b494..21cd945f 100644
--- a/src/daemon/https/tls/debug.c
+++ b/src/daemon/https/tls/debug.c
@@ -32,26 +32,26 @@
32 32
33 33
34void 34void
35_gnutls_print_state (mhd_gtls_session_t session) 35MHD__gnutls_print_state (MHD_gtls_session_t session)
36{ 36{
37 37
38 _gnutls_debug_log ("GNUTLS State:\n"); 38 MHD__gnutls_debug_log ("GNUTLS State:\n");
39 _gnutls_debug_log ("Connection End: %d\n", 39 MHD__gnutls_debug_log ("Connection End: %d\n",
40 session->security_parameters.entity); 40 session->security_parameters.entity);
41 _gnutls_debug_log ("Cipher Algorithm: %d\n", 41 MHD__gnutls_debug_log ("Cipher Algorithm: %d\n",
42 session->security_parameters.read_bulk_cipher_algorithm); 42 session->security_parameters.read_bulk_cipher_algorithm);
43 _gnutls_debug_log ("MAC algorithm: %d\n", 43 MHD__gnutls_debug_log ("MAC algorithm: %d\n",
44 session->security_parameters.read_mac_algorithm); 44 session->security_parameters.read_mac_algorithm);
45 _gnutls_debug_log ("Compression Algorithm: %d\n", 45 MHD__gnutls_debug_log ("Compression Algorithm: %d\n",
46 session->security_parameters.read_compression_algorithm); 46 session->security_parameters.read_compression_algorithm);
47 _gnutls_debug_log ("\n"); 47 MHD__gnutls_debug_log ("\n");
48 48
49} 49}
50 50
51#endif 51#endif
52 52
53const char * 53const char *
54_gnutls_packet2str (content_type_t packet) 54MHD__gnutls_packet2str (content_type_t packet)
55{ 55{
56 switch (packet) 56 switch (packet)
57 { 57 {
@@ -72,7 +72,7 @@ _gnutls_packet2str (content_type_t packet)
72} 72}
73 73
74const char * 74const char *
75_gnutls_handshake2str (gnutls_handshake_description_t handshake) 75MHD__gnutls_handshake2str (MHD_gnutls_handshake_description_t handshake)
76{ 76{
77 77
78 switch (handshake) 78 switch (handshake)
@@ -117,12 +117,12 @@ _gnutls_handshake2str (gnutls_handshake_description_t handshake)
117} 117}
118 118
119void 119void
120_gnutls_dump_mpi (const char *prefix, mpi_t a) 120MHD__gnutls_dump_mpi (const char *prefix, mpi_t a)
121{ 121{
122 opaque buf[1024]; 122 opaque buf[1024];
123 size_t n = sizeof buf; 123 size_t n = sizeof buf;
124 124
125 if (gcry_mpi_print (GCRYMPI_FMT_HEX, buf, n, &n, a)) 125 if (gcry_mpi_print (GCRYMPI_FMT_HEX, buf, n, &n, a))
126 strcpy (buf, "[can't print value]"); /* Flawfinder: ignore */ 126 strcpy (buf, "[can't print value]"); /* Flawfinder: ignore */
127 _gnutls_hard_log ("MPI: length: %d\n\t%s%s\n", (n - 1) / 2, prefix, buf); 127 MHD__gnutls_hard_log ("MPI: length: %d\n\t%s%s\n", (n - 1) / 2, prefix, buf);
128} 128}
diff --git a/src/daemon/https/tls/debug.h b/src/daemon/https/tls/debug.h
index ccaf0f17..637beca8 100644
--- a/src/daemon/https/tls/debug.h
+++ b/src/daemon/https/tls/debug.h
@@ -23,8 +23,8 @@
23 */ 23 */
24 24
25#ifdef DEBUG 25#ifdef DEBUG
26void _gnutls_print_state (mhd_gtls_session_t session); 26void MHD__gnutls_print_state (MHD_gtls_session_t session);
27#endif 27#endif
28const char *_gnutls_packet2str (content_type_t packet); 28const char *MHD__gnutls_packet2str (content_type_t packet);
29const char *_gnutls_handshake2str (gnutls_handshake_description_t handshake); 29const char *MHD__gnutls_handshake2str (MHD_gnutls_handshake_description_t handshake);
30void _gnutls_dump_mpi (const char *prefix, mpi_t a); 30void MHD__gnutls_dump_mpi (const char *prefix, mpi_t a);
diff --git a/src/daemon/https/tls/ext_cert_type.c b/src/daemon/https/tls/ext_cert_type.c
index 9e00120c..4feeb18f 100644
--- a/src/daemon/https/tls/ext_cert_type.c
+++ b/src/daemon/https/tls/ext_cert_type.c
@@ -33,12 +33,12 @@
33#include "gnutls_state.h" 33#include "gnutls_state.h"
34#include "gnutls_num.h" 34#include "gnutls_num.h"
35 35
36inline static int _gnutls_num2cert_type (int num); 36inline static int MHD__gnutls_num2cert_type (int num);
37inline static int _gnutls_cert_type2num (int record_size); 37inline static int MHD__gnutls_cert_type2num (int record_size);
38 38
39/* 39/*
40 * In case of a server: if a CERT_TYPE extension type is received then it stores 40 * In case of a server: if a CERT_TYPE extension type is received then it stores
41 * into the session security parameters the new value. The server may use gnutls_session_certificate_type_get(), 41 * into the session security parameters the new value. The server may use MHD_gnutls_session_certificate_type_get(),
42 * to access it. 42 * to access it.
43 * 43 *
44 * In case of a client: If a cert_types have been specified then we send the extension. 44 * In case of a client: If a cert_types have been specified then we send the extension.
@@ -46,7 +46,7 @@ inline static int _gnutls_cert_type2num (int record_size);
46 */ 46 */
47 47
48int 48int
49mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session, 49MHD_gtls_cert_type_recv_params (MHD_gtls_session_t session,
50 const opaque * data, size_t _data_size) 50 const opaque * data, size_t _data_size)
51{ 51{
52 int new_type = -1, ret, i; 52 int new_type = -1, ret, i;
@@ -59,27 +59,27 @@ mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session,
59 { 59 {
60 if (data_size != 1) 60 if (data_size != 1)
61 { 61 {
62 gnutls_assert (); 62 MHD_gnutls_assert ();
63 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 63 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
64 } 64 }
65 65
66 new_type = _gnutls_num2cert_type (data[0]); 66 new_type = MHD__gnutls_num2cert_type (data[0]);
67 67
68 if (new_type < 0) 68 if (new_type < 0)
69 { 69 {
70 gnutls_assert (); 70 MHD_gnutls_assert ();
71 return new_type; 71 return new_type;
72 } 72 }
73 73
74 /* Check if we support this cert_type */ 74 /* Check if we support this cert_type */
75 if ((ret = 75 if ((ret =
76 mhd_gtls_session_cert_type_supported (session, new_type)) < 0) 76 MHD_gtls_session_cert_type_supported (session, new_type)) < 0)
77 { 77 {
78 gnutls_assert (); 78 MHD_gnutls_assert ();
79 return ret; 79 return ret;
80 } 80 }
81 81
82 _gnutls_session_cert_type_set (session, new_type); 82 MHD__gnutls_session_cert_type_set (session, new_type);
83 } 83 }
84 } 84 }
85 else 85 else
@@ -96,17 +96,17 @@ mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session,
96 96
97 for (i = 0; i < len; i++) 97 for (i = 0; i < len; i++)
98 { 98 {
99 new_type = _gnutls_num2cert_type (data[i + 1]); 99 new_type = MHD__gnutls_num2cert_type (data[i + 1]);
100 100
101 if (new_type < 0) 101 if (new_type < 0)
102 continue; 102 continue;
103 103
104 /* Check if we support this cert_type */ 104 /* Check if we support this cert_type */
105 if ((ret = 105 if ((ret =
106 mhd_gtls_session_cert_type_supported (session, 106 MHD_gtls_session_cert_type_supported (session,
107 new_type)) < 0) 107 new_type)) < 0)
108 { 108 {
109 gnutls_assert (); 109 MHD_gnutls_assert ();
110 continue; 110 continue;
111 } 111 }
112 else 112 else
@@ -116,14 +116,14 @@ mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session,
116 116
117 if (new_type < 0) 117 if (new_type < 0)
118 { 118 {
119 gnutls_assert (); 119 MHD_gnutls_assert ();
120 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; 120 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
121 } 121 }
122 122
123 if ((ret = 123 if ((ret =
124 mhd_gtls_session_cert_type_supported (session, new_type)) < 0) 124 MHD_gtls_session_cert_type_supported (session, new_type)) < 0)
125 { 125 {
126 gnutls_assert (); 126 MHD_gnutls_assert ();
127 /* The peer has requested unsupported certificate 127 /* The peer has requested unsupported certificate
128 * types. Instead of failing, procceed normally. 128 * types. Instead of failing, procceed normally.
129 * (the ciphersuite selection would fail, or a 129 * (the ciphersuite selection would fail, or a
@@ -132,7 +132,7 @@ mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session,
132 return 0; 132 return 0;
133 } 133 }
134 134
135 _gnutls_session_cert_type_set (session, new_type); 135 MHD__gnutls_session_cert_type_set (session, new_type);
136 } 136 }
137 137
138 138
@@ -144,7 +144,7 @@ mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session,
144/* returns data_size or a negative number on failure 144/* returns data_size or a negative number on failure
145 */ 145 */
146int 146int
147mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data, 147MHD_gtls_cert_type_send_params (MHD_gtls_session_t session, opaque * data,
148 size_t data_size) 148 size_t data_size)
149{ 149{
150 unsigned len, i; 150 unsigned len, i;
@@ -171,7 +171,7 @@ mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data,
171 171
172 if (data_size < len + 1) 172 if (data_size < len + 1)
173 { 173 {
174 gnutls_assert (); 174 MHD_gnutls_assert ();
175 return GNUTLS_E_SHORT_MEMORY_BUFFER; 175 return GNUTLS_E_SHORT_MEMORY_BUFFER;
176 } 176 }
177 177
@@ -182,7 +182,7 @@ mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data,
182 for (i = 0; i < len; i++) 182 for (i = 0; i < len; i++)
183 { 183 {
184 data[i + 1] = 184 data[i + 1] =
185 _gnutls_cert_type2num (session->internals. 185 MHD__gnutls_cert_type2num (session->internals.
186 priorities.cert_type.priority[i]); 186 priorities.cert_type.priority[i]);
187 } 187 }
188 return len + 1; 188 return len + 1;
@@ -197,12 +197,12 @@ mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data,
197 len = 1; 197 len = 1;
198 if (data_size < len) 198 if (data_size < len)
199 { 199 {
200 gnutls_assert (); 200 MHD_gnutls_assert ();
201 return GNUTLS_E_SHORT_MEMORY_BUFFER; 201 return GNUTLS_E_SHORT_MEMORY_BUFFER;
202 } 202 }
203 203
204 data[0] = 204 data[0] =
205 _gnutls_cert_type2num (session->security_parameters.cert_type); 205 MHD__gnutls_cert_type2num (session->security_parameters.cert_type);
206 return len; 206 return len;
207 } 207 }
208 208
@@ -216,7 +216,7 @@ mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data,
216 * extensions draft. 216 * extensions draft.
217 */ 217 */
218inline static int 218inline static int
219_gnutls_num2cert_type (int num) 219MHD__gnutls_num2cert_type (int num)
220{ 220{
221 switch (num) 221 switch (num)
222 { 222 {
@@ -231,7 +231,7 @@ _gnutls_num2cert_type (int num)
231 * extensions draft. 231 * extensions draft.
232 */ 232 */
233inline static int 233inline static int
234_gnutls_cert_type2num (int cert_type) 234MHD__gnutls_cert_type2num (int cert_type)
235{ 235{
236 switch (cert_type) 236 switch (cert_type)
237 { 237 {
diff --git a/src/daemon/https/tls/ext_cert_type.h b/src/daemon/https/tls/ext_cert_type.h
index cd9b0acc..f80f7ba8 100644
--- a/src/daemon/https/tls/ext_cert_type.h
+++ b/src/daemon/https/tls/ext_cert_type.h
@@ -25,7 +25,7 @@
25/* Maps record size to numbers according to the 25/* Maps record size to numbers according to the
26 * extensions draft. 26 * extensions draft.
27 */ 27 */
28int mhd_gtls_cert_type_recv_params (mhd_gtls_session_t session, 28int MHD_gtls_cert_type_recv_params (MHD_gtls_session_t session,
29 const opaque * data, size_t data_size); 29 const opaque * data, size_t data_size);
30int mhd_gtls_cert_type_send_params (mhd_gtls_session_t session, opaque * data, 30int MHD_gtls_cert_type_send_params (MHD_gtls_session_t session, opaque * data,
31 size_t); 31 size_t);
diff --git a/src/daemon/https/tls/ext_max_record.c b/src/daemon/https/tls/ext_max_record.c
index 1b5f2be2..421a1739 100644
--- a/src/daemon/https/tls/ext_max_record.c
+++ b/src/daemon/https/tls/ext_max_record.c
@@ -32,7 +32,7 @@
32 32
33/* 33/*
34 * In case of a server: if a MAX_RECORD_SIZE extension type is received then it stores 34 * In case of a server: if a MAX_RECORD_SIZE extension type is received then it stores
35 * into the session the new value. The server may use gnutls_get_max_record_size(), 35 * into the session the new value. The server may use MHD_gnutls_get_max_record_size(),
36 * in order to access it. 36 * in order to access it.
37 * 37 *
38 * In case of a client: If a different max record size (than the default) has 38 * In case of a client: If a different max record size (than the default) has
@@ -41,7 +41,7 @@
41 */ 41 */
42 42
43int 43int
44mhd_gtls_max_record_recv_params (mhd_gtls_session_t session, 44MHD_gtls_max_record_recv_params (MHD_gtls_session_t session,
45 const opaque * data, size_t _data_size) 45 const opaque * data, size_t _data_size)
46{ 46{
47 ssize_t new_size; 47 ssize_t new_size;
@@ -53,11 +53,11 @@ mhd_gtls_max_record_recv_params (mhd_gtls_session_t session,
53 { 53 {
54 DECR_LEN (data_size, 1); 54 DECR_LEN (data_size, 1);
55 55
56 new_size = mhd_gtls_mre_num2record (data[0]); 56 new_size = MHD_gtls_mre_num2record (data[0]);
57 57
58 if (new_size < 0) 58 if (new_size < 0)
59 { 59 {
60 gnutls_assert (); 60 MHD_gnutls_assert ();
61 return new_size; 61 return new_size;
62 } 62 }
63 63
@@ -73,16 +73,16 @@ mhd_gtls_max_record_recv_params (mhd_gtls_session_t session,
73 73
74 if (data_size != 1) 74 if (data_size != 1)
75 { 75 {
76 gnutls_assert (); 76 MHD_gnutls_assert ();
77 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 77 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
78 } 78 }
79 79
80 new_size = mhd_gtls_mre_num2record (data[0]); 80 new_size = MHD_gtls_mre_num2record (data[0]);
81 81
82 if (new_size < 0 82 if (new_size < 0
83 || new_size != session->internals.proposed_record_size) 83 || new_size != session->internals.proposed_record_size)
84 { 84 {
85 gnutls_assert (); 85 MHD_gnutls_assert ();
86 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; 86 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
87 } 87 }
88 else 88 else
@@ -102,7 +102,7 @@ mhd_gtls_max_record_recv_params (mhd_gtls_session_t session,
102/* returns data_size or a negative number on failure 102/* returns data_size or a negative number on failure
103 */ 103 */
104int 104int
105mhd_gtls_max_record_send_params (mhd_gtls_session_t session, opaque * data, 105MHD_gtls_max_record_send_params (MHD_gtls_session_t session, opaque * data,
106 size_t data_size) 106 size_t data_size)
107{ 107{
108 uint16_t len; 108 uint16_t len;
@@ -116,12 +116,12 @@ mhd_gtls_max_record_send_params (mhd_gtls_session_t session, opaque * data,
116 len = 1; 116 len = 1;
117 if (data_size < len) 117 if (data_size < len)
118 { 118 {
119 gnutls_assert (); 119 MHD_gnutls_assert ();
120 return GNUTLS_E_SHORT_MEMORY_BUFFER; 120 return GNUTLS_E_SHORT_MEMORY_BUFFER;
121 } 121 }
122 122
123 data[0] = 123 data[0] =
124 (uint8_t) mhd_gtls_mre_record2num (session->internals. 124 (uint8_t) MHD_gtls_mre_record2num (session->internals.
125 proposed_record_size); 125 proposed_record_size);
126 return len; 126 return len;
127 } 127 }
@@ -137,13 +137,13 @@ mhd_gtls_max_record_send_params (mhd_gtls_session_t session, opaque * data,
137 len = 1; 137 len = 1;
138 if (data_size < len) 138 if (data_size < len)
139 { 139 {
140 gnutls_assert (); 140 MHD_gnutls_assert ();
141 return GNUTLS_E_SHORT_MEMORY_BUFFER; 141 return GNUTLS_E_SHORT_MEMORY_BUFFER;
142 } 142 }
143 143
144 data[0] = 144 data[0] =
145 (uint8_t) 145 (uint8_t)
146 mhd_gtls_mre_record2num 146 MHD_gtls_mre_record2num
147 (session->security_parameters.max_record_recv_size); 147 (session->security_parameters.max_record_recv_size);
148 return len; 148 return len;
149 } 149 }
@@ -158,7 +158,7 @@ mhd_gtls_max_record_send_params (mhd_gtls_session_t session, opaque * data,
158 * extensions draft. 158 * extensions draft.
159 */ 159 */
160int 160int
161mhd_gtls_mre_num2record (int num) 161MHD_gtls_mre_num2record (int num)
162{ 162{
163 switch (num) 163 switch (num)
164 { 164 {
@@ -179,7 +179,7 @@ mhd_gtls_mre_num2record (int num)
179 * extensions draft. 179 * extensions draft.
180 */ 180 */
181int 181int
182mhd_gtls_mre_record2num (uint16_t record_size) 182MHD_gtls_mre_record2num (uint16_t record_size)
183{ 183{
184 switch (record_size) 184 switch (record_size)
185 { 185 {
diff --git a/src/daemon/https/tls/ext_max_record.h b/src/daemon/https/tls/ext_max_record.h
index 361470a9..14686253 100644
--- a/src/daemon/https/tls/ext_max_record.h
+++ b/src/daemon/https/tls/ext_max_record.h
@@ -25,9 +25,9 @@
25/* Maps record size to numbers according to the 25/* Maps record size to numbers according to the
26 * extensions draft. 26 * extensions draft.
27 */ 27 */
28int mhd_gtls_mre_num2record (int num); 28int MHD_gtls_mre_num2record (int num);
29int mhd_gtls_mre_record2num (uint16_t record_size); 29int MHD_gtls_mre_record2num (uint16_t record_size);
30int mhd_gtls_max_record_recv_params (mhd_gtls_session_t session, 30int MHD_gtls_max_record_recv_params (MHD_gtls_session_t session,
31 const opaque * data, size_t data_size); 31 const opaque * data, size_t data_size);
32int mhd_gtls_max_record_send_params (mhd_gtls_session_t session, 32int MHD_gtls_max_record_send_params (MHD_gtls_session_t session,
33 opaque * data, size_t); 33 opaque * data, size_t);
diff --git a/src/daemon/https/tls/ext_oprfi.c b/src/daemon/https/tls/ext_oprfi.c
index b2dad0ff..09ef51cd 100644
--- a/src/daemon/https/tls/ext_oprfi.c
+++ b/src/daemon/https/tls/ext_oprfi.c
@@ -34,7 +34,7 @@
34#include <gnutls_num.h> 34#include <gnutls_num.h>
35 35
36static int 36static int
37oprfi_recv_server (mhd_gtls_session_t session, 37oprfi_recv_server (MHD_gtls_session_t session,
38 const opaque * data, size_t _data_size) 38 const opaque * data, size_t _data_size)
39{ 39{
40 ssize_t data_size = _data_size; 40 ssize_t data_size = _data_size;
@@ -42,26 +42,26 @@ oprfi_recv_server (mhd_gtls_session_t session,
42 42
43 if (!session->security_parameters.extensions.oprfi_cb) 43 if (!session->security_parameters.extensions.oprfi_cb)
44 { 44 {
45 gnutls_assert (); 45 MHD_gnutls_assert ();
46 return 0; 46 return 0;
47 } 47 }
48 48
49 DECR_LEN (data_size, 2); 49 DECR_LEN (data_size, 2);
50 len = mhd_gtls_read_uint16 (data); 50 len = MHD_gtls_read_uint16 (data);
51 data += 2; 51 data += 2;
52 52
53 if (len != data_size) 53 if (len != data_size)
54 { 54 {
55 gnutls_assert (); 55 MHD_gnutls_assert ();
56 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 56 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
57 } 57 }
58 58
59 /* Store incoming data. */ 59 /* Store incoming data. */
60 session->security_parameters.extensions.oprfi_client_len = len; 60 session->security_parameters.extensions.oprfi_client_len = len;
61 session->security_parameters.extensions.oprfi_client = gnutls_malloc (len); 61 session->security_parameters.extensions.oprfi_client = MHD_gnutls_malloc (len);
62 if (!session->security_parameters.extensions.oprfi_client) 62 if (!session->security_parameters.extensions.oprfi_client)
63 { 63 {
64 gnutls_assert (); 64 MHD_gnutls_assert ();
65 return GNUTLS_E_MEMORY_ERROR; 65 return GNUTLS_E_MEMORY_ERROR;
66 } 66 }
67 memcpy (session->security_parameters.extensions.oprfi_client, data, len); 67 memcpy (session->security_parameters.extensions.oprfi_client, data, len);
@@ -70,7 +70,7 @@ oprfi_recv_server (mhd_gtls_session_t session,
70} 70}
71 71
72static int 72static int
73oprfi_recv_client (mhd_gtls_session_t session, 73oprfi_recv_client (MHD_gtls_session_t session,
74 const opaque * data, size_t _data_size) 74 const opaque * data, size_t _data_size)
75{ 75{
76 ssize_t data_size = _data_size; 76 ssize_t data_size = _data_size;
@@ -78,32 +78,32 @@ oprfi_recv_client (mhd_gtls_session_t session,
78 78
79 if (session->security_parameters.extensions.oprfi_client == NULL) 79 if (session->security_parameters.extensions.oprfi_client == NULL)
80 { 80 {
81 gnutls_assert (); 81 MHD_gnutls_assert ();
82 return 0; 82 return 0;
83 } 83 }
84 84
85 DECR_LEN (data_size, 2); 85 DECR_LEN (data_size, 2);
86 len = mhd_gtls_read_uint16 (data); 86 len = MHD_gtls_read_uint16 (data);
87 data += 2; 87 data += 2;
88 88
89 if (len != data_size) 89 if (len != data_size)
90 { 90 {
91 gnutls_assert (); 91 MHD_gnutls_assert ();
92 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 92 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
93 } 93 }
94 94
95 if (len != session->security_parameters.extensions.oprfi_client_len) 95 if (len != session->security_parameters.extensions.oprfi_client_len)
96 { 96 {
97 gnutls_assert (); 97 MHD_gnutls_assert ();
98 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; 98 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
99 } 99 }
100 100
101 /* Store incoming data. */ 101 /* Store incoming data. */
102 session->security_parameters.extensions.oprfi_server_len = len; 102 session->security_parameters.extensions.oprfi_server_len = len;
103 session->security_parameters.extensions.oprfi_server = gnutls_malloc (len); 103 session->security_parameters.extensions.oprfi_server = MHD_gnutls_malloc (len);
104 if (!session->security_parameters.extensions.oprfi_server) 104 if (!session->security_parameters.extensions.oprfi_server)
105 { 105 {
106 gnutls_assert (); 106 MHD_gnutls_assert ();
107 return GNUTLS_E_MEMORY_ERROR; 107 return GNUTLS_E_MEMORY_ERROR;
108 } 108 }
109 memcpy (session->security_parameters.extensions.oprfi_server, data, len); 109 memcpy (session->security_parameters.extensions.oprfi_server, data, len);
@@ -112,7 +112,7 @@ oprfi_recv_client (mhd_gtls_session_t session,
112} 112}
113 113
114int 114int
115mhd_gtls_oprfi_recv_params (mhd_gtls_session_t session, 115MHD_gtls_oprfi_recv_params (MHD_gtls_session_t session,
116 const opaque * data, size_t data_size) 116 const opaque * data, size_t data_size)
117{ 117{
118#if MHD_DEBUG_TLS 118#if MHD_DEBUG_TLS
@@ -124,7 +124,7 @@ mhd_gtls_oprfi_recv_params (mhd_gtls_session_t session,
124} 124}
125 125
126static int 126static int
127oprfi_send_client (mhd_gtls_session_t session, opaque * data, 127oprfi_send_client (MHD_gtls_session_t session, opaque * data,
128 size_t _data_size) 128 size_t _data_size)
129{ 129{
130 opaque *p = data; 130 opaque *p = data;
@@ -135,7 +135,7 @@ oprfi_send_client (mhd_gtls_session_t session, opaque * data,
135 return 0; 135 return 0;
136 136
137 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER); 137 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER);
138 mhd_gtls_write_uint16 (oprf_size, p); 138 MHD_gtls_write_uint16 (oprf_size, p);
139 p += 2; 139 p += 2;
140 140
141 DECR_LENGTH_RET (data_size, oprf_size, GNUTLS_E_SHORT_MEMORY_BUFFER); 141 DECR_LENGTH_RET (data_size, oprf_size, GNUTLS_E_SHORT_MEMORY_BUFFER);
@@ -146,7 +146,7 @@ oprfi_send_client (mhd_gtls_session_t session, opaque * data,
146} 146}
147 147
148static int 148static int
149oprfi_send_server (mhd_gtls_session_t session, opaque * data, 149oprfi_send_server (MHD_gtls_session_t session, opaque * data,
150 size_t _data_size) 150 size_t _data_size)
151{ 151{
152 opaque *p = data; 152 opaque *p = data;
@@ -161,10 +161,10 @@ oprfi_send_server (mhd_gtls_session_t session, opaque * data,
161 session->security_parameters.extensions.oprfi_server_len = 161 session->security_parameters.extensions.oprfi_server_len =
162 session->security_parameters.extensions.oprfi_client_len; 162 session->security_parameters.extensions.oprfi_client_len;
163 session->security_parameters.extensions.oprfi_server = 163 session->security_parameters.extensions.oprfi_server =
164 gnutls_malloc (session->security_parameters.extensions.oprfi_server_len); 164 MHD_gnutls_malloc (session->security_parameters.extensions.oprfi_server_len);
165 if (!session->security_parameters.extensions.oprfi_server) 165 if (!session->security_parameters.extensions.oprfi_server)
166 { 166 {
167 gnutls_assert (); 167 MHD_gnutls_assert ();
168 return GNUTLS_E_MEMORY_ERROR; 168 return GNUTLS_E_MEMORY_ERROR;
169 } 169 }
170 170
@@ -176,13 +176,13 @@ oprfi_send_server (mhd_gtls_session_t session, opaque * data,
176 session->security_parameters.extensions.oprfi_server); 176 session->security_parameters.extensions.oprfi_server);
177 if (ret < 0) 177 if (ret < 0)
178 { 178 {
179 gnutls_assert (); 179 MHD_gnutls_assert ();
180 gnutls_free (session->security_parameters.extensions.oprfi_server); 180 MHD_gnutls_free (session->security_parameters.extensions.oprfi_server);
181 return ret; 181 return ret;
182 } 182 }
183 183
184 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER); 184 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER);
185 mhd_gtls_write_uint16 (session->security_parameters. 185 MHD_gtls_write_uint16 (session->security_parameters.
186 extensions.oprfi_server_len, p); 186 extensions.oprfi_server_len, p);
187 p += 2; 187 p += 2;
188 188
@@ -197,7 +197,7 @@ oprfi_send_server (mhd_gtls_session_t session, opaque * data,
197} 197}
198 198
199int 199int
200mhd_gtls_oprfi_send_params (mhd_gtls_session_t session, 200MHD_gtls_oprfi_send_params (MHD_gtls_session_t session,
201 opaque * data, size_t data_size) 201 opaque * data, size_t data_size)
202{ 202{
203#if MHD_DEBUG_TLS 203#if MHD_DEBUG_TLS
@@ -210,7 +210,7 @@ mhd_gtls_oprfi_send_params (mhd_gtls_session_t session,
210 210
211/** 211/**
212 * MHD_gtls_oprfi_enable_client: 212 * MHD_gtls_oprfi_enable_client:
213 * @session: is a #mhd_gtls_session_t structure. 213 * @session: is a #MHD_gtls_session_t structure.
214 * @len: length of Opaque PRF data to use in client. 214 * @len: length of Opaque PRF data to use in client.
215 * @data: Opaque PRF data to use in client. 215 * @data: Opaque PRF data to use in client.
216 * 216 *
@@ -222,7 +222,7 @@ mhd_gtls_oprfi_send_params (mhd_gtls_session_t session,
222 * may de-allocate it immediately after calling this function. 222 * may de-allocate it immediately after calling this function.
223 **/ 223 **/
224void 224void
225MHD_gtls_oprfi_enable_client (mhd_gtls_session_t session, 225MHD_gtls_oprfi_enable_client (MHD_gtls_session_t session,
226 size_t len, unsigned char *data) 226 size_t len, unsigned char *data)
227{ 227{
228 session->security_parameters.extensions.oprfi_client_len = len; 228 session->security_parameters.extensions.oprfi_client_len = len;
@@ -231,7 +231,7 @@ MHD_gtls_oprfi_enable_client (mhd_gtls_session_t session,
231 231
232/** 232/**
233 * MHD_gtls_oprfi_enable_server: 233 * MHD_gtls_oprfi_enable_server:
234 * @session: is a #mhd_gtls_session_t structure. 234 * @session: is a #MHD_gtls_session_t structure.
235 * @cb: function pointer to Opaque PRF extension server callback. 235 * @cb: function pointer to Opaque PRF extension server callback.
236 * @userdata: hook passed to callback function for passing application state. 236 * @userdata: hook passed to callback function for passing application state.
237 * 237 *
@@ -240,7 +240,7 @@ MHD_gtls_oprfi_enable_client (mhd_gtls_session_t session,
240 * provided callback @cb will be invoked. The callback must have the 240 * provided callback @cb will be invoked. The callback must have the
241 * following prototype: 241 * following prototype:
242 * 242 *
243 * int callback (mhd_gtls_session_t session, void *userdata, 243 * int callback (MHD_gtls_session_t session, void *userdata,
244 * size_t oprfi_len, const unsigned char *in_oprfi, 244 * size_t oprfi_len, const unsigned char *in_oprfi,
245 * unsigned char *out_oprfi); 245 * unsigned char *out_oprfi);
246 * 246 *
@@ -250,8 +250,8 @@ MHD_gtls_oprfi_enable_client (mhd_gtls_session_t session,
250 * handshake will be aborted. 250 * handshake will be aborted.
251 **/ 251 **/
252void 252void
253MHD_gtls_oprfi_enable_server (mhd_gtls_session_t session, 253MHD_gtls_oprfi_enable_server (MHD_gtls_session_t session,
254 gnutls_oprfi_callback_func cb, void *userdata) 254 MHD_gnutls_oprfi_callback_func cb, void *userdata)
255{ 255{
256 session->security_parameters.extensions.oprfi_cb = cb; 256 session->security_parameters.extensions.oprfi_cb = cb;
257 session->security_parameters.extensions.oprfi_userdata = userdata; 257 session->security_parameters.extensions.oprfi_userdata = userdata;
diff --git a/src/daemon/https/tls/ext_oprfi.h b/src/daemon/https/tls/ext_oprfi.h
index defb672b..a3265499 100644
--- a/src/daemon/https/tls/ext_oprfi.h
+++ b/src/daemon/https/tls/ext_oprfi.h
@@ -24,8 +24,8 @@
24 24
25#include <gnutls_int.h> 25#include <gnutls_int.h>
26 26
27int mhd_gtls_oprfi_recv_params (mhd_gtls_session_t state, 27int MHD_gtls_oprfi_recv_params (MHD_gtls_session_t state,
28 const opaque * data, size_t data_size); 28 const opaque * data, size_t data_size);
29 29
30int mhd_gtls_oprfi_send_params (mhd_gtls_session_t state, 30int MHD_gtls_oprfi_send_params (MHD_gtls_session_t state,
31 opaque * data, size_t data_size); 31 opaque * data, size_t data_size);
diff --git a/src/daemon/https/tls/ext_server_name.c b/src/daemon/https/tls/ext_server_name.c
index 64ef0b06..9878fe62 100644
--- a/src/daemon/https/tls/ext_server_name.c
+++ b/src/daemon/https/tls/ext_server_name.c
@@ -30,7 +30,7 @@
30 30
31/* 31/*
32 * In case of a server: if a NAME_DNS extension type is received then it stores 32 * In case of a server: if a NAME_DNS extension type is received then it stores
33 * into the session the value of NAME_DNS. The server may use gnutls_ext_get_server_name(), 33 * into the session the value of NAME_DNS. The server may use MHD_gnutls_ext_get_server_name(),
34 * in order to access it. 34 * in order to access it.
35 * 35 *
36 * In case of a client: If a proper NAME_DNS extension type is found in the session then 36 * In case of a client: If a proper NAME_DNS extension type is found in the session then
@@ -39,7 +39,7 @@
39 */ 39 */
40 40
41int 41int
42mhd_gtls_server_name_recv_params (mhd_gtls_session_t session, 42MHD_gtls_server_name_recv_params (MHD_gtls_session_t session,
43 const opaque * data, size_t _data_size) 43 const opaque * data, size_t _data_size)
44{ 44{
45 int i; 45 int i;
@@ -51,14 +51,14 @@ mhd_gtls_server_name_recv_params (mhd_gtls_session_t session,
51 if (session->security_parameters.entity == GNUTLS_SERVER) 51 if (session->security_parameters.entity == GNUTLS_SERVER)
52 { 52 {
53 DECR_LENGTH_RET (data_size, 2, 0); 53 DECR_LENGTH_RET (data_size, 2, 0);
54 len = mhd_gtls_read_uint16 (data); 54 len = MHD_gtls_read_uint16 (data);
55 55
56 if (len != data_size) 56 if (len != data_size)
57 { 57 {
58 /* This is unexpected packet length, but 58 /* This is unexpected packet length, but
59 * just ignore it, for now. 59 * just ignore it, for now.
60 */ 60 */
61 gnutls_assert (); 61 MHD_gnutls_assert ();
62 return 0; 62 return 0;
63 } 63 }
64 64
@@ -71,7 +71,7 @@ mhd_gtls_server_name_recv_params (mhd_gtls_session_t session,
71 p++; 71 p++;
72 72
73 DECR_LEN (data_size, 2); 73 DECR_LEN (data_size, 2);
74 len = mhd_gtls_read_uint16 (p); 74 len = MHD_gtls_read_uint16 (p);
75 p += 2; 75 p += 2;
76 76
77 DECR_LENGTH_RET (data_size, len, 0); 77 DECR_LENGTH_RET (data_size, len, 0);
@@ -96,7 +96,7 @@ mhd_gtls_server_name_recv_params (mhd_gtls_session_t session,
96 type = *p; 96 type = *p;
97 p++; 97 p++;
98 98
99 len = mhd_gtls_read_uint16 (p); 99 len = MHD_gtls_read_uint16 (p);
100 p += 2; 100 p += 2;
101 101
102 switch (type) 102 switch (type)
@@ -124,7 +124,7 @@ mhd_gtls_server_name_recv_params (mhd_gtls_session_t session,
124/* returns data_size or a negative number on failure 124/* returns data_size or a negative number on failure
125 */ 125 */
126int 126int
127mhd_gtls_server_name_send_params (mhd_gtls_session_t session, 127MHD_gtls_server_name_send_params (MHD_gtls_session_t session,
128 opaque * data, size_t _data_size) 128 opaque * data, size_t _data_size)
129{ 129{
130 int total_size = 0; 130 int total_size = 0;
@@ -163,7 +163,7 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
163 /* UINT16: write total size of all names 163 /* UINT16: write total size of all names
164 */ 164 */
165 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER); 165 DECR_LENGTH_RET (data_size, 2, GNUTLS_E_SHORT_MEMORY_BUFFER);
166 mhd_gtls_write_uint16 (total_size - 2, p); 166 MHD_gtls_write_uint16 (total_size - 2, p);
167 p += 2; 167 p += 2;
168 168
169 for (i = 0; 169 for (i = 0;
@@ -191,7 +191,7 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
191 *p = 0; /* NAME_DNS type */ 191 *p = 0; /* NAME_DNS type */
192 p++; 192 p++;
193 193
194 mhd_gtls_write_uint16 (len, p); 194 MHD_gtls_write_uint16 (len, p);
195 p += 2; 195 p += 2;
196 196
197 memcpy (p, 197 memcpy (p,
@@ -200,7 +200,7 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
200 p += len; 200 p += len;
201 break; 201 break;
202 default: 202 default:
203 gnutls_assert (); 203 MHD_gnutls_assert ();
204 return GNUTLS_E_INTERNAL_ERROR; 204 return GNUTLS_E_INTERNAL_ERROR;
205 } 205 }
206 } 206 }
@@ -210,8 +210,8 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
210} 210}
211 211
212/** 212/**
213 * MHD_gnutls_server_name_get - Used to get the server name indicator send by a client 213 * MHD__gnutls_server_name_get - Used to get the server name indicator send by a client
214 * @session: is a #mhd_gtls_session_t structure. 214 * @session: is a #MHD_gtls_session_t structure.
215 * @data: will hold the data 215 * @data: will hold the data
216 * @data_length: will hold the data length. Must hold the maximum size of data. 216 * @data_length: will hold the data length. Must hold the maximum size of data.
217 * @type: will hold the server name indicator type 217 * @type: will hold the server name indicator type
@@ -219,7 +219,7 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
219 * 219 *
220 * This function will allow you to get the name indication (if any), 220 * This function will allow you to get the name indication (if any),
221 * a client has sent. The name indication may be any of the enumeration 221 * a client has sent. The name indication may be any of the enumeration
222 * gnutls_server_name_type_t. 222 * MHD_gnutls_server_name_type_t.
223 * 223 *
224 * If @type is GNUTLS_NAME_DNS, then this function is to be used by servers 224 * If @type is GNUTLS_NAME_DNS, then this function is to be used by servers
225 * that support virtual hosting, and the data will be a null terminated UTF-8 string. 225 * that support virtual hosting, and the data will be a null terminated UTF-8 string.
@@ -233,7 +233,7 @@ mhd_gtls_server_name_send_params (mhd_gtls_session_t session,
233 * 233 *
234 **/ 234 **/
235int 235int
236MHD_gnutls_server_name_get (mhd_gtls_session_t session, void *data, 236MHD__gnutls_server_name_get (MHD_gtls_session_t session, void *data,
237 size_t * data_length, 237 size_t * data_length,
238 unsigned int *type, unsigned int indx) 238 unsigned int *type, unsigned int indx)
239{ 239{
@@ -241,7 +241,7 @@ MHD_gnutls_server_name_get (mhd_gtls_session_t session, void *data,
241#if MHD_DEBUG_TLS 241#if MHD_DEBUG_TLS
242 if (session->security_parameters.entity == GNUTLS_CLIENT) 242 if (session->security_parameters.entity == GNUTLS_CLIENT)
243 { 243 {
244 gnutls_assert (); 244 MHD_gnutls_assert ();
245 return GNUTLS_E_INVALID_REQUEST; 245 return GNUTLS_E_INVALID_REQUEST;
246 } 246 }
247#endif 247#endif
@@ -278,8 +278,8 @@ MHD_gnutls_server_name_get (mhd_gtls_session_t session, void *data,
278} 278}
279 279
280/** 280/**
281 * MHD_gnutls_server_name_set - Used to set a name indicator to be sent as an extension 281 * MHD__gnutls_server_name_set - Used to set a name indicator to be sent as an extension
282 * @session: is a #mhd_gtls_session_t structure. 282 * @session: is a #MHD_gtls_session_t structure.
283 * @type: specifies the indicator type 283 * @type: specifies the indicator type
284 * @name: is a string that contains the server name. 284 * @name: is a string that contains the server name.
285 * @name_length: holds the length of name 285 * @name_length: holds the length of name
@@ -295,15 +295,15 @@ MHD_gnutls_server_name_get (mhd_gtls_session_t session, void *data,
295 * 295 *
296 **/ 296 **/
297int 297int
298MHD_gnutls_server_name_set (mhd_gtls_session_t session, 298MHD__gnutls_server_name_set (MHD_gtls_session_t session,
299 gnutls_server_name_type_t type, 299 MHD_gnutls_server_name_type_t type,
300 const void *name, size_t name_length) 300 const void *name, size_t name_length)
301{ 301{
302 int server_names; 302 int server_names;
303 303
304 if (session->security_parameters.entity == GNUTLS_SERVER) 304 if (session->security_parameters.entity == GNUTLS_SERVER)
305 { 305 {
306 gnutls_assert (); 306 MHD_gnutls_assert ();
307 return GNUTLS_E_INVALID_REQUEST; 307 return GNUTLS_E_INVALID_REQUEST;
308 } 308 }
309 309
diff --git a/src/daemon/https/tls/ext_server_name.h b/src/daemon/https/tls/ext_server_name.h
index 5de9304f..f74ce191 100644
--- a/src/daemon/https/tls/ext_server_name.h
+++ b/src/daemon/https/tls/ext_server_name.h
@@ -22,7 +22,7 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gtls_server_name_recv_params (mhd_gtls_session_t session, 25int MHD_gtls_server_name_recv_params (MHD_gtls_session_t session,
26 const opaque * data, size_t data_size); 26 const opaque * data, size_t data_size);
27int mhd_gtls_server_name_send_params (mhd_gtls_session_t session, 27int MHD_gtls_server_name_send_params (MHD_gtls_session_t session,
28 opaque * data, size_t); 28 opaque * data, size_t);
diff --git a/src/daemon/https/tls/gnutls_alert.c b/src/daemon/https/tls/gnutls_alert.c
index 6a71aee3..b3ad303d 100644
--- a/src/daemon/https/tls/gnutls_alert.c
+++ b/src/daemon/https/tls/gnutls_alert.c
@@ -29,11 +29,11 @@
29 29
30typedef struct 30typedef struct
31{ 31{
32 gnutls_alert_description_t alert; 32 MHD_gnutls_alert_description_t alert;
33 const char *desc; 33 const char *desc;
34} gnutls_alert_entry; 34} MHD_gnutls_alert_entry;
35 35
36static const gnutls_alert_entry mhd_gtls_sup_alerts[] = { 36static const MHD_gnutls_alert_entry MHD_gtls_sup_alerts[] = {
37 {GNUTLS_A_CLOSE_NOTIFY, "Close notify"}, 37 {GNUTLS_A_CLOSE_NOTIFY, "Close notify"},
38 {GNUTLS_A_UNEXPECTED_MESSAGE, "Unexpected message"}, 38 {GNUTLS_A_UNEXPECTED_MESSAGE, "Unexpected message"},
39 {GNUTLS_A_BAD_RECORD_MAC, "Bad record MAC"}, 39 {GNUTLS_A_BAD_RECORD_MAC, "Bad record MAC"},
@@ -67,23 +67,23 @@ static const gnutls_alert_entry mhd_gtls_sup_alerts[] = {
67}; 67};
68 68
69#define GNUTLS_ALERT_LOOP(b) \ 69#define GNUTLS_ALERT_LOOP(b) \
70 const gnutls_alert_entry *p; \ 70 const MHD_gnutls_alert_entry *p; \
71 for(p = mhd_gtls_sup_alerts; p->desc != NULL; p++) { b ; } 71 for(p = MHD_gtls_sup_alerts; p->desc != NULL; p++) { b ; }
72 72
73#define GNUTLS_ALERT_ID_LOOP(a) \ 73#define GNUTLS_ALERT_ID_LOOP(a) \
74 GNUTLS_ALERT_LOOP( if(p->alert == alert) { a; break; }) 74 GNUTLS_ALERT_LOOP( if(p->alert == alert) { a; break; })
75 75
76 76
77/** 77/**
78 * MHD_gnutls_alert_get_name - Returns a string describing the alert number given 78 * MHD__gnutls_alert_get_name - Returns a string describing the alert number given
79 * @alert: is an alert number #mhd_gtls_session_t structure. 79 * @alert: is an alert number #MHD_gtls_session_t structure.
80 * 80 *
81 * This function will return a string that describes the given alert 81 * This function will return a string that describes the given alert
82 * number or NULL. See gnutls_alert_get(). 82 * number or NULL. See MHD_gnutls_alert_get().
83 * 83 *
84 **/ 84 **/
85const char * 85const char *
86MHD_gnutls_alert_get_name (gnutls_alert_description_t alert) 86MHD__gnutls_alert_get_name (MHD_gnutls_alert_description_t alert)
87{ 87{
88 const char *ret = NULL; 88 const char *ret = NULL;
89 89
@@ -93,8 +93,8 @@ MHD_gnutls_alert_get_name (gnutls_alert_description_t alert)
93} 93}
94 94
95/** 95/**
96 * MHD_gnutls_alert_send - This function sends an alert message to the peer 96 * MHD__gnutls_alert_send - This function sends an alert message to the peer
97 * @session: is a #mhd_gtls_session_t structure. 97 * @session: is a #MHD_gtls_session_t structure.
98 * @level: is the level of the alert 98 * @level: is the level of the alert
99 * @desc: is the alert description 99 * @desc: is the alert description
100 * 100 *
@@ -110,8 +110,8 @@ MHD_gnutls_alert_get_name (gnutls_alert_description_t alert)
110 * 110 *
111 **/ 111 **/
112int 112int
113MHD_gnutls_alert_send (mhd_gtls_session_t session, gnutls_alert_level_t level, 113MHD__gnutls_alert_send (MHD_gtls_session_t session, MHD_gnutls_alert_level_t level,
114 gnutls_alert_description_t desc) 114 MHD_gnutls_alert_description_t desc)
115{ 115{
116 uint8_t data[2]; 116 uint8_t data[2];
117 int ret; 117 int ret;
@@ -120,13 +120,13 @@ MHD_gnutls_alert_send (mhd_gtls_session_t session, gnutls_alert_level_t level,
120 data[0] = (uint8_t) level; 120 data[0] = (uint8_t) level;
121 data[1] = (uint8_t) desc; 121 data[1] = (uint8_t) desc;
122 122
123 name = MHD_gnutls_alert_get_name ((int) data[1]); 123 name = MHD__gnutls_alert_get_name ((int) data[1]);
124 if (name == NULL) 124 if (name == NULL)
125 name = "(unknown)"; 125 name = "(unknown)";
126 _gnutls_record_log ("REC: Sending Alert[%d|%d] - %s\n", data[0], 126 MHD__gnutls_record_log ("REC: Sending Alert[%d|%d] - %s\n", data[0],
127 data[1], name); 127 data[1], name);
128 128
129 if ((ret = mhd_gtls_send_int (session, GNUTLS_ALERT, -1, data, 2)) >= 0) 129 if ((ret = MHD_gtls_send_int (session, GNUTLS_ALERT, -1, data, 2)) >= 0)
130 return 0; 130 return 0;
131 else 131 else
132 return ret; 132 return ret;
@@ -245,8 +245,8 @@ MHD_gtls_error_to_alert (int err, int *level)
245 245
246 246
247/** 247/**
248 * MHD_gnutls_alert_send_appropriate - This function sends an alert to the peer depending on the error code 248 * MHD__gnutls_alert_send_appropriate - This function sends an alert to the peer depending on the error code
249 * @session: is a #mhd_gtls_session_t structure. 249 * @session: is a #MHD_gtls_session_t structure.
250 * @err: is an integer 250 * @err: is an integer
251 * 251 *
252 * Sends an alert to the peer depending on the error code returned by a gnutls 252 * Sends an alert to the peer depending on the error code returned by a gnutls
@@ -261,7 +261,7 @@ MHD_gtls_error_to_alert (int err, int *level)
261 * Returns zero on success. 261 * Returns zero on success.
262 */ 262 */
263int 263int
264MHD_gnutls_alert_send_appropriate (mhd_gtls_session_t session, int err) 264MHD__gnutls_alert_send_appropriate (MHD_gtls_session_t session, int err)
265{ 265{
266 int alert; 266 int alert;
267 int level; 267 int level;
@@ -272,12 +272,12 @@ MHD_gnutls_alert_send_appropriate (mhd_gtls_session_t session, int err)
272 return alert; 272 return alert;
273 } 273 }
274 274
275 return MHD_gnutls_alert_send (session, level, alert); 275 return MHD__gnutls_alert_send (session, level, alert);
276} 276}
277 277
278/** 278/**
279 * gnutls_alert_get - Returns the last alert number received. 279 * MHD_gnutls_alert_get - Returns the last alert number received.
280 * @session: is a #mhd_gtls_session_t structure. 280 * @session: is a #MHD_gtls_session_t structure.
281 * 281 *
282 * This function will return the last alert number received. This 282 * This function will return the last alert number received. This
283 * function should be called if GNUTLS_E_WARNING_ALERT_RECEIVED or 283 * function should be called if GNUTLS_E_WARNING_ALERT_RECEIVED or
@@ -288,8 +288,8 @@ MHD_gnutls_alert_send_appropriate (mhd_gtls_session_t session, int err)
288 * If no alert has been received the returned value is undefined. 288 * If no alert has been received the returned value is undefined.
289 * 289 *
290 **/ 290 **/
291gnutls_alert_description_t 291MHD_gnutls_alert_description_t
292gnutls_alert_get (mhd_gtls_session_t session) 292MHD_gnutls_alert_get (MHD_gtls_session_t session)
293{ 293{
294 return session->internals.last_alert; 294 return session->internals.last_alert;
295} 295}
diff --git a/src/daemon/https/tls/gnutls_algorithms.c b/src/daemon/https/tls/gnutls_algorithms.c
index c3daa08b..bef51b19 100644
--- a/src/daemon/https/tls/gnutls_algorithms.c
+++ b/src/daemon/https/tls/gnutls_algorithms.c
@@ -39,9 +39,9 @@ typedef struct
39 enum MHD_GNUTLS_CredentialsType client_type; 39 enum MHD_GNUTLS_CredentialsType client_type;
40 enum MHD_GNUTLS_CredentialsType server_type; /* The type of credentials a server 40 enum MHD_GNUTLS_CredentialsType server_type; /* The type of credentials a server
41 * needs to set */ 41 * needs to set */
42} gnutls_cred_map; 42} MHD_gnutls_cred_map;
43 43
44static const gnutls_cred_map mhd_gtls_cred_mappings[] = { 44static const MHD_gnutls_cred_map MHD_gtls_cred_mappings[] = {
45 {MHD_GNUTLS_KX_ANON_DH, 45 {MHD_GNUTLS_KX_ANON_DH,
46 MHD_GNUTLS_CRD_ANON, 46 MHD_GNUTLS_CRD_ANON,
47 MHD_GNUTLS_CRD_ANON}, 47 MHD_GNUTLS_CRD_ANON},
@@ -72,8 +72,8 @@ static const gnutls_cred_map mhd_gtls_cred_mappings[] = {
72}; 72};
73 73
74#define GNUTLS_KX_MAP_LOOP(b) \ 74#define GNUTLS_KX_MAP_LOOP(b) \
75 const gnutls_cred_map *p; \ 75 const MHD_gnutls_cred_map *p; \
76 for(p = mhd_gtls_cred_mappings; p->algorithm != 0; p++) { b ; } 76 for(p = MHD_gtls_cred_mappings; p->algorithm != 0; p++) { b ; }
77 77
78#define GNUTLS_KX_MAP_ALG_LOOP_SERVER(a) \ 78#define GNUTLS_KX_MAP_ALG_LOOP_SERVER(a) \
79 GNUTLS_KX_MAP_LOOP( if(p->server_type == type) { a; break; }) 79 GNUTLS_KX_MAP_LOOP( if(p->server_type == type) { a; break; })
@@ -93,14 +93,14 @@ typedef struct
93 * This is useful to certificate cipher suites, which check 93 * This is useful to certificate cipher suites, which check
94 * against the certificate key usage bits. 94 * against the certificate key usage bits.
95 */ 95 */
96} gnutls_pk_map; 96} MHD_gnutls_pk_map;
97 97
98/* This table maps the Key exchange algorithms to 98/* This table maps the Key exchange algorithms to
99 * the certificate algorithms. Eg. if we have 99 * the certificate algorithms. Eg. if we have
100 * RSA algorithm in the certificate then we can 100 * RSA algorithm in the certificate then we can
101 * use GNUTLS_KX_RSA or GNUTLS_KX_DHE_RSA. 101 * use GNUTLS_KX_RSA or GNUTLS_KX_DHE_RSA.
102 */ 102 */
103static const gnutls_pk_map mhd_gtls_pk_mappings[] = { 103static const MHD_gnutls_pk_map MHD_gtls_pk_mappings[] = {
104 {MHD_GNUTLS_KX_RSA, 104 {MHD_GNUTLS_KX_RSA,
105 MHD_GNUTLS_PK_RSA, 105 MHD_GNUTLS_PK_RSA,
106 CIPHER_ENCRYPT}, 106 CIPHER_ENCRYPT},
@@ -119,8 +119,8 @@ static const gnutls_pk_map mhd_gtls_pk_mappings[] = {
119}; 119};
120 120
121#define GNUTLS_PK_MAP_LOOP(b) \ 121#define GNUTLS_PK_MAP_LOOP(b) \
122 const gnutls_pk_map *p; \ 122 const MHD_gnutls_pk_map *p; \
123 for(p = mhd_gtls_pk_mappings; p->kx_algorithm != 0; p++) { b } 123 for(p = MHD_gtls_pk_mappings; p->kx_algorithm != 0; p++) { b }
124 124
125#define GNUTLS_PK_MAP_ALG_LOOP(a) \ 125#define GNUTLS_PK_MAP_ALG_LOOP(a) \
126 GNUTLS_PK_MAP_LOOP( if(p->kx_algorithm == kx_algorithm) { a; break; }) 126 GNUTLS_PK_MAP_LOOP( if(p->kx_algorithm == kx_algorithm) { a; break; })
@@ -134,9 +134,9 @@ typedef struct
134 int major; /* defined by the protocol */ 134 int major; /* defined by the protocol */
135 int minor; /* defined by the protocol */ 135 int minor; /* defined by the protocol */
136 int supported; /* 0 not supported, > 0 is supported */ 136 int supported; /* 0 not supported, > 0 is supported */
137} gnutls_version_entry; 137} MHD_gnutls_version_entry;
138 138
139static const gnutls_version_entry mhd_gtls_sup_versions[] = { 139static const MHD_gnutls_version_entry MHD_gtls_sup_versions[] = {
140 {"SSL3.0", 140 {"SSL3.0",
141 MHD_GNUTLS_PROTOCOL_SSL3, 141 MHD_GNUTLS_PROTOCOL_SSL3,
142 3, 142 3,
@@ -165,7 +165,7 @@ static const gnutls_version_entry mhd_gtls_sup_versions[] = {
165}; 165};
166 166
167/* Keep the contents of this struct the same as the previous one. */ 167/* Keep the contents of this struct the same as the previous one. */
168static const enum MHD_GNUTLS_Protocol mhd_gtls_supported_protocols[] = 168static const enum MHD_GNUTLS_Protocol MHD_gtls_supported_protocols[] =
169{ MHD_GNUTLS_PROTOCOL_SSL3, 169{ MHD_GNUTLS_PROTOCOL_SSL3,
170 MHD_GNUTLS_PROTOCOL_TLS1_0, 170 MHD_GNUTLS_PROTOCOL_TLS1_0,
171 MHD_GNUTLS_PROTOCOL_TLS1_1, 171 MHD_GNUTLS_PROTOCOL_TLS1_1,
@@ -174,13 +174,13 @@ static const enum MHD_GNUTLS_Protocol mhd_gtls_supported_protocols[] =
174}; 174};
175 175
176#define GNUTLS_VERSION_LOOP(b) \ 176#define GNUTLS_VERSION_LOOP(b) \
177 const gnutls_version_entry *p; \ 177 const MHD_gnutls_version_entry *p; \
178 for(p = mhd_gtls_sup_versions; p->name != NULL; p++) { b ; } 178 for(p = MHD_gtls_sup_versions; p->name != NULL; p++) { b ; }
179 179
180#define GNUTLS_VERSION_ALG_LOOP(a) \ 180#define GNUTLS_VERSION_ALG_LOOP(a) \
181 GNUTLS_VERSION_LOOP( if(p->id == version) { a; break; }) 181 GNUTLS_VERSION_LOOP( if(p->id == version) { a; break; })
182 182
183struct gnutls_cipher_entry 183struct MHD_gnutls_cipher_entry
184{ 184{
185 const char *name; 185 const char *name;
186 enum MHD_GNUTLS_CipherAlgorithm id; 186 enum MHD_GNUTLS_CipherAlgorithm id;
@@ -190,14 +190,14 @@ struct gnutls_cipher_entry
190 uint16_t iv; 190 uint16_t iv;
191 int export_flag; /* 0 non export */ 191 int export_flag; /* 0 non export */
192}; 192};
193typedef struct gnutls_cipher_entry gnutls_cipher_entry; 193typedef struct MHD_gnutls_cipher_entry MHD_gnutls_cipher_entry;
194 194
195/* Note that all algorithms are in CBC or STREAM modes. 195/* Note that all algorithms are in CBC or STREAM modes.
196 * Do not add any algorithms in other modes (avoid modified algorithms). 196 * Do not add any algorithms in other modes (avoid modified algorithms).
197 * View first: "The order of encryption and authentication for 197 * View first: "The order of encryption and authentication for
198 * protecting communications" by Hugo Krawczyk - CRYPTO 2001 198 * protecting communications" by Hugo Krawczyk - CRYPTO 2001
199 */ 199 */
200static const gnutls_cipher_entry mhd_gtls_algorithms[] = { 200static const MHD_gnutls_cipher_entry MHD_gtls_algorithms[] = {
201 {"AES-256-CBC", 201 {"AES-256-CBC",
202 MHD_GNUTLS_CIPHER_AES_256_CBC, 202 MHD_GNUTLS_CIPHER_AES_256_CBC,
203 16, 203 16,
@@ -272,7 +272,7 @@ static const gnutls_cipher_entry mhd_gtls_algorithms[] = {
272}; 272};
273 273
274/* Keep the contents of this struct the same as the previous one. */ 274/* Keep the contents of this struct the same as the previous one. */
275static const enum MHD_GNUTLS_CipherAlgorithm mhd_gtls_supported_ciphers[] = 275static const enum MHD_GNUTLS_CipherAlgorithm MHD_gtls_supported_ciphers[] =
276{ MHD_GNUTLS_CIPHER_AES_256_CBC, 276{ MHD_GNUTLS_CIPHER_AES_256_CBC,
277 MHD_GNUTLS_CIPHER_AES_128_CBC, 277 MHD_GNUTLS_CIPHER_AES_128_CBC,
278 MHD_GNUTLS_CIPHER_3DES_CBC, 278 MHD_GNUTLS_CIPHER_3DES_CBC,
@@ -289,22 +289,22 @@ static const enum MHD_GNUTLS_CipherAlgorithm mhd_gtls_supported_ciphers[] =
289}; 289};
290 290
291#define GNUTLS_LOOP(b) \ 291#define GNUTLS_LOOP(b) \
292 const gnutls_cipher_entry *p; \ 292 const MHD_gnutls_cipher_entry *p; \
293 for(p = mhd_gtls_algorithms; p->name != NULL; p++) { b ; } 293 for(p = MHD_gtls_algorithms; p->name != NULL; p++) { b ; }
294 294
295#define GNUTLS_ALG_LOOP(a) \ 295#define GNUTLS_ALG_LOOP(a) \
296 GNUTLS_LOOP( if(p->id == algorithm) { a; break; } ) 296 GNUTLS_LOOP( if(p->id == algorithm) { a; break; } )
297 297
298struct gnutls_hash_entry 298struct MHD_gnutls_hash_entry
299{ 299{
300 const char *name; 300 const char *name;
301 const char *oid; 301 const char *oid;
302 enum MHD_GNUTLS_HashAlgorithm id; 302 enum MHD_GNUTLS_HashAlgorithm id;
303 size_t key_size; /* in case of mac */ 303 size_t key_size; /* in case of mac */
304}; 304};
305typedef struct gnutls_hash_entry gnutls_hash_entry; 305typedef struct MHD_gnutls_hash_entry MHD_gnutls_hash_entry;
306 306
307static const gnutls_hash_entry mhd_gtls_hash_algorithms[] = { 307static const MHD_gnutls_hash_entry MHD_gtls_hash_algorithms[] = {
308 {"SHA1", 308 {"SHA1",
309 HASH_OID_SHA1, 309 HASH_OID_SHA1,
310 MHD_GNUTLS_MAC_SHA1, 310 MHD_GNUTLS_MAC_SHA1,
@@ -328,7 +328,7 @@ static const gnutls_hash_entry mhd_gtls_hash_algorithms[] = {
328}; 328};
329 329
330/* Keep the contents of this struct the same as the previous one. */ 330/* Keep the contents of this struct the same as the previous one. */
331static const enum MHD_GNUTLS_HashAlgorithm mhd_gtls_supported_macs[] = 331static const enum MHD_GNUTLS_HashAlgorithm MHD_gtls_supported_macs[] =
332{ MHD_GNUTLS_MAC_SHA1, 332{ MHD_GNUTLS_MAC_SHA1,
333 MHD_GNUTLS_MAC_MD5, 333 MHD_GNUTLS_MAC_MD5,
334 MHD_GNUTLS_MAC_SHA256, 334 MHD_GNUTLS_MAC_SHA256,
@@ -337,8 +337,8 @@ static const enum MHD_GNUTLS_HashAlgorithm mhd_gtls_supported_macs[] =
337}; 337};
338 338
339#define GNUTLS_HASH_LOOP(b) \ 339#define GNUTLS_HASH_LOOP(b) \
340 const gnutls_hash_entry *p; \ 340 const MHD_gnutls_hash_entry *p; \
341 for(p = mhd_gtls_hash_algorithms; p->name != NULL; p++) { b ; } 341 for(p = MHD_gtls_hash_algorithms; p->name != NULL; p++) { b ; }
342 342
343#define GNUTLS_HASH_ALG_LOOP(a) \ 343#define GNUTLS_HASH_ALG_LOOP(a) \
344 GNUTLS_HASH_LOOP( if(p->id == algorithm) { a; break; } ) 344 GNUTLS_HASH_LOOP( if(p->id == algorithm) { a; break; } )
@@ -348,11 +348,11 @@ static const enum MHD_GNUTLS_HashAlgorithm mhd_gtls_supported_macs[] =
348 { #name, name, id, wb, ml, cl} 348 { #name, name, id, wb, ml, cl}
349 349
350#define MAX_COMP_METHODS 5 350#define MAX_COMP_METHODS 5
351const int _gnutls_comp_algorithms_size = MAX_COMP_METHODS; 351const int MHD__gnutls_comp_algorithms_size = MAX_COMP_METHODS;
352 352
353/* the compression entry is defined in gnutls_algorithms.h */ 353/* the compression entry is defined in MHD_gnutls_algorithms.h */
354 354
355gnutls_compression_entry _gnutls_compression_algorithms[MAX_COMP_METHODS] = 355MHD_gnutls_compression_entry MHD__gnutls_compression_algorithms[MAX_COMP_METHODS] =
356 { GNUTLS_COMPRESSION_ENTRY (MHD_GNUTLS_COMP_NULL, 0x00, 0, 0, 0), 356 { GNUTLS_COMPRESSION_ENTRY (MHD_GNUTLS_COMP_NULL, 0x00, 0, 0, 0),
357#ifdef HAVE_LIBZ 357#ifdef HAVE_LIBZ
358 /* draft-ietf-tls-compression-02 */ 358 /* draft-ietf-tls-compression-02 */
@@ -367,7 +367,7 @@ gnutls_compression_entry _gnutls_compression_algorithms[MAX_COMP_METHODS] =
367}; 367};
368 368
369static const enum MHD_GNUTLS_CompressionMethod 369static const enum MHD_GNUTLS_CompressionMethod
370 mhd_gtls_supported_compressions[] = 370 MHD_gtls_supported_compressions[] =
371{ 371{
372#ifdef HAVE_LIBZ 372#ifdef HAVE_LIBZ
373 MHD_GNUTLS_COMP_DEFLATE, 373 MHD_GNUTLS_COMP_DEFLATE,
@@ -377,41 +377,41 @@ static const enum MHD_GNUTLS_CompressionMethod
377}; 377};
378 378
379#define GNUTLS_COMPRESSION_LOOP(b) \ 379#define GNUTLS_COMPRESSION_LOOP(b) \
380 const gnutls_compression_entry *p; \ 380 const MHD_gnutls_compression_entry *p; \
381 for(p = _gnutls_compression_algorithms; p->name != NULL; p++) { b ; } 381 for(p = MHD__gnutls_compression_algorithms; p->name != NULL; p++) { b ; }
382#define GNUTLS_COMPRESSION_ALG_LOOP(a) \ 382#define GNUTLS_COMPRESSION_ALG_LOOP(a) \
383 GNUTLS_COMPRESSION_LOOP( if(p->id == algorithm) { a; break; } ) 383 GNUTLS_COMPRESSION_LOOP( if(p->id == algorithm) { a; break; } )
384#define GNUTLS_COMPRESSION_ALG_LOOP_NUM(a) \ 384#define GNUTLS_COMPRESSION_ALG_LOOP_NUM(a) \
385 GNUTLS_COMPRESSION_LOOP( if(p->num == num) { a; break; } ) 385 GNUTLS_COMPRESSION_LOOP( if(p->num == num) { a; break; } )
386 386
387/* Key Exchange Section */ 387/* Key Exchange Section */
388extern mhd_gtls_mod_auth_st mhd_gtls_rsa_auth_struct; 388extern MHD_gtls_mod_auth_st MHD_gtls_rsa_auth_struct;
389extern mhd_gtls_mod_auth_st rsa_export_auth_struct; 389extern MHD_gtls_mod_auth_st rsa_export_auth_struct;
390extern mhd_gtls_mod_auth_st mhd_gtls_dhe_rsa_auth_struct; 390extern MHD_gtls_mod_auth_st MHD_gtls_dhe_rsa_auth_struct;
391extern mhd_gtls_mod_auth_st mhd_gtls_dhe_dss_auth_struct; 391extern MHD_gtls_mod_auth_st MHD_gtls_dhe_dss_auth_struct;
392extern mhd_gtls_mod_auth_st mhd_gtls_anon_auth_struct; 392extern MHD_gtls_mod_auth_st MHD_gtls_anon_auth_struct;
393extern mhd_gtls_mod_auth_st srp_auth_struct; 393extern MHD_gtls_mod_auth_st srp_auth_struct;
394extern mhd_gtls_mod_auth_st psk_auth_struct; 394extern MHD_gtls_mod_auth_st psk_auth_struct;
395extern mhd_gtls_mod_auth_st dhe_psk_auth_struct; 395extern MHD_gtls_mod_auth_st dhe_psk_auth_struct;
396extern mhd_gtls_mod_auth_st srp_rsa_auth_struct; 396extern MHD_gtls_mod_auth_st srp_rsa_auth_struct;
397extern mhd_gtls_mod_auth_st srp_dss_auth_struct; 397extern MHD_gtls_mod_auth_st srp_dss_auth_struct;
398 398
399typedef struct mhd_gtls_kx_algo_entry 399typedef struct MHD_gtls_kx_algo_entry
400{ 400{
401 const char *name; 401 const char *name;
402 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm; 402 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm;
403 mhd_gtls_mod_auth_st *auth_struct; 403 MHD_gtls_mod_auth_st *auth_struct;
404 int needs_dh_params; 404 int needs_dh_params;
405 int needs_rsa_params; 405 int needs_rsa_params;
406} mhd_gtls_kx_algo_entry_t; 406} MHD_gtls_kx_algo_entry_t;
407 407
408static const mhd_gtls_kx_algo_entry_t mhd_gtls_kx_algorithms[] = { 408static const MHD_gtls_kx_algo_entry_t MHD_gtls_kx_algorithms[] = {
409#ifdef ENABLE_ANON 409#ifdef ENABLE_ANON
410 {"ANON-DH", MHD_GNUTLS_KX_ANON_DH, &mhd_gtls_anon_auth_struct, 1, 0}, 410 {"ANON-DH", MHD_GNUTLS_KX_ANON_DH, &MHD_gtls_anon_auth_struct, 1, 0},
411#endif 411#endif
412 {"RSA", 412 {"RSA",
413 MHD_GNUTLS_KX_RSA, 413 MHD_GNUTLS_KX_RSA,
414 &mhd_gtls_rsa_auth_struct, 414 &MHD_gtls_rsa_auth_struct,
415 0, 415 0,
416 0}, 416 0},
417 {"RSA-EXPORT", 417 {"RSA-EXPORT",
@@ -421,12 +421,12 @@ static const mhd_gtls_kx_algo_entry_t mhd_gtls_kx_algorithms[] = {
421 1 /* needs RSA params */ }, 421 1 /* needs RSA params */ },
422 {"DHE-RSA", 422 {"DHE-RSA",
423 MHD_GNUTLS_KX_DHE_RSA, 423 MHD_GNUTLS_KX_DHE_RSA,
424 &mhd_gtls_dhe_rsa_auth_struct, 424 &MHD_gtls_dhe_rsa_auth_struct,
425 1, 425 1,
426 0}, 426 0},
427 {"DHE-DSS", 427 {"DHE-DSS",
428 MHD_GNUTLS_KX_DHE_DSS, 428 MHD_GNUTLS_KX_DHE_DSS,
429 &mhd_gtls_dhe_dss_auth_struct, 429 &MHD_gtls_dhe_dss_auth_struct,
430 1, 430 1,
431 0}, 431 0},
432 432
@@ -448,7 +448,7 @@ static const mhd_gtls_kx_algo_entry_t mhd_gtls_kx_algorithms[] = {
448}; 448};
449 449
450/* Keep the contents of this struct the same as the previous one. */ 450/* Keep the contents of this struct the same as the previous one. */
451static const enum MHD_GNUTLS_KeyExchangeAlgorithm mhd_gtls_supported_kxs[] = 451static const enum MHD_GNUTLS_KeyExchangeAlgorithm MHD_gtls_supported_kxs[] =
452{ 452{
453#ifdef ENABLE_ANON 453#ifdef ENABLE_ANON
454 MHD_GNUTLS_KX_ANON_DH, 454 MHD_GNUTLS_KX_ANON_DH,
@@ -470,8 +470,8 @@ static const enum MHD_GNUTLS_KeyExchangeAlgorithm mhd_gtls_supported_kxs[] =
470}; 470};
471 471
472#define GNUTLS_KX_LOOP(b) \ 472#define GNUTLS_KX_LOOP(b) \
473 const mhd_gtls_kx_algo_entry_t *p; \ 473 const MHD_gtls_kx_algo_entry_t *p; \
474 for(p = mhd_gtls_kx_algorithms; p->name != NULL; p++) { b ; } 474 for(p = MHD_gtls_kx_algorithms; p->name != NULL; p++) { b ; }
475 475
476#define GNUTLS_KX_ALG_LOOP(a) \ 476#define GNUTLS_KX_ALG_LOOP(a) \
477 GNUTLS_KX_LOOP( if(p->algorithm == algorithm) { a; break; } ) 477 GNUTLS_KX_LOOP( if(p->algorithm == algorithm) { a; break; } )
@@ -490,7 +490,7 @@ typedef struct
490 enum MHD_GNUTLS_Protocol version; /* this cipher suite is supported 490 enum MHD_GNUTLS_Protocol version; /* this cipher suite is supported
491 * from 'version' and above; 491 * from 'version' and above;
492 */ 492 */
493} mhd_gtls_cipher_suite_entry; 493} MHD_gtls_cipher_suite_entry;
494 494
495/* RSA with NULL cipher and MD5 MAC 495/* RSA with NULL cipher and MD5 MAC
496 * for test purposes. 496 * for test purposes.
@@ -586,9 +586,9 @@ typedef struct
586#define GNUTLS_DHE_RSA_CAMELLIA_128_CBC_SHA1 { 0x00,0x45 } 586#define GNUTLS_DHE_RSA_CAMELLIA_128_CBC_SHA1 { 0x00,0x45 }
587#define GNUTLS_DHE_RSA_CAMELLIA_256_CBC_SHA1 { 0x00,0x88 } 587#define GNUTLS_DHE_RSA_CAMELLIA_256_CBC_SHA1 { 0x00,0x88 }
588 588
589#define CIPHER_SUITES_COUNT sizeof(mhd_gtls_cs_algorithms)/sizeof(mhd_gtls_cipher_suite_entry)-1 589#define CIPHER_SUITES_COUNT sizeof(MHD_gtls_cs_algorithms)/sizeof(MHD_gtls_cipher_suite_entry)-1
590 590
591static const mhd_gtls_cipher_suite_entry mhd_gtls_cs_algorithms[] = { 591static const MHD_gtls_cipher_suite_entry MHD_gtls_cs_algorithms[] = {
592 /* ANON_DH */ 592 /* ANON_DH */
593 GNUTLS_CIPHER_SUITE_ENTRY (GNUTLS_ANON_DH_ARCFOUR_MD5, 593 GNUTLS_CIPHER_SUITE_ENTRY (GNUTLS_ANON_DH_ARCFOUR_MD5,
594 MHD_GNUTLS_CIPHER_ARCFOUR_128, 594 MHD_GNUTLS_CIPHER_ARCFOUR_128,
@@ -758,8 +758,8 @@ static const mhd_gtls_cipher_suite_entry mhd_gtls_cs_algorithms[] = {
758}; 758};
759 759
760#define GNUTLS_CIPHER_SUITE_LOOP(b) \ 760#define GNUTLS_CIPHER_SUITE_LOOP(b) \
761 const mhd_gtls_cipher_suite_entry *p; \ 761 const MHD_gtls_cipher_suite_entry *p; \
762 for(p = mhd_gtls_cs_algorithms; p->name != NULL; p++) { b ; } 762 for(p = MHD_gtls_cs_algorithms; p->name != NULL; p++) { b ; }
763 763
764#define GNUTLS_CIPHER_SUITE_ALG_LOOP(a) \ 764#define GNUTLS_CIPHER_SUITE_ALG_LOOP(a) \
765 GNUTLS_CIPHER_SUITE_LOOP( if( (p->id.suite[0] == suite->suite[0]) && (p->id.suite[1] == suite->suite[1])) { a; break; } ) 765 GNUTLS_CIPHER_SUITE_LOOP( if( (p->id.suite[0] == suite->suite[0]) && (p->id.suite[1] == suite->suite[1])) { a; break; } )
@@ -767,7 +767,7 @@ static const mhd_gtls_cipher_suite_entry mhd_gtls_cs_algorithms[] = {
767/* Generic Functions */ 767/* Generic Functions */
768 768
769int 769int
770mhd_gtls_mac_priority (mhd_gtls_session_t session, 770MHD_gtls_mac_priority (MHD_gtls_session_t session,
771 enum MHD_GNUTLS_HashAlgorithm algorithm) 771 enum MHD_GNUTLS_HashAlgorithm algorithm)
772{ /* actually returns the priority */ 772{ /* actually returns the priority */
773 unsigned int i; 773 unsigned int i;
@@ -780,14 +780,14 @@ mhd_gtls_mac_priority (mhd_gtls_session_t session,
780} 780}
781 781
782/** 782/**
783 * MHD_gnutls_mac_get_name - Returns a string with the name of the specified mac algorithm 783 * MHD__gnutls_mac_get_name - Returns a string with the name of the specified mac algorithm
784 * @algorithm: is a MAC algorithm 784 * @algorithm: is a MAC algorithm
785 * 785 *
786 * Returns: a string that contains the name of the specified MAC 786 * Returns: a string that contains the name of the specified MAC
787 * algorithm, or %NULL. 787 * algorithm, or %NULL.
788 **/ 788 **/
789const char * 789const char *
790MHD_gnutls_mac_get_name (enum MHD_GNUTLS_HashAlgorithm algorithm) 790MHD__gnutls_mac_get_name (enum MHD_GNUTLS_HashAlgorithm algorithm)
791{ 791{
792 const char *ret = NULL; 792 const char *ret = NULL;
793 793
@@ -817,7 +817,7 @@ MHD_gtls_mac_get_id (const char *name)
817} 817}
818 818
819/** 819/**
820 * MHD_gnutls_mac_get_key_size - Returns the length of the MAC's key size 820 * MHD__gnutls_mac_get_key_size - Returns the length of the MAC's key size
821 * @algorithm: is an encryption algorithm 821 * @algorithm: is an encryption algorithm
822 * 822 *
823 * Returns: length (in bytes) of the given MAC key size, or 0 if the 823 * Returns: length (in bytes) of the given MAC key size, or 0 if the
@@ -825,7 +825,7 @@ MHD_gtls_mac_get_id (const char *name)
825 * 825 *
826 **/ 826 **/
827size_t 827size_t
828MHD_gnutls_mac_get_key_size (enum MHD_GNUTLS_HashAlgorithm algorithm) 828MHD__gnutls_mac_get_key_size (enum MHD_GNUTLS_HashAlgorithm algorithm)
829{ 829{
830 size_t ret = 0; 830 size_t ret = 0;
831 831
@@ -849,11 +849,11 @@ MHD_gnutls_mac_get_key_size (enum MHD_GNUTLS_HashAlgorithm algorithm)
849const enum MHD_GNUTLS_HashAlgorithm * 849const enum MHD_GNUTLS_HashAlgorithm *
850MHD_gtls_mac_list (void) 850MHD_gtls_mac_list (void)
851{ 851{
852 return mhd_gtls_supported_macs; 852 return MHD_gtls_supported_macs;
853} 853}
854 854
855const char * 855const char *
856mhd_gtls_x509_mac_to_oid (enum MHD_GNUTLS_HashAlgorithm algorithm) 856MHD_gtls_x509_mac_to_oid (enum MHD_GNUTLS_HashAlgorithm algorithm)
857{ 857{
858 const char *ret = NULL; 858 const char *ret = NULL;
859 859
@@ -864,7 +864,7 @@ mhd_gtls_x509_mac_to_oid (enum MHD_GNUTLS_HashAlgorithm algorithm)
864} 864}
865 865
866enum MHD_GNUTLS_HashAlgorithm 866enum MHD_GNUTLS_HashAlgorithm
867mhd_gtls_x509_oid2mac_algorithm (const char *oid) 867MHD_gtls_x509_oid2mac_algorithm (const char *oid)
868{ 868{
869 enum MHD_GNUTLS_HashAlgorithm ret = 0; 869 enum MHD_GNUTLS_HashAlgorithm ret = 0;
870 870
@@ -880,7 +880,7 @@ mhd_gtls_x509_oid2mac_algorithm (const char *oid)
880} 880}
881 881
882int 882int
883mhd_gnutls_mac_is_ok (enum MHD_GNUTLS_HashAlgorithm algorithm) 883MHD_gnutls_mac_is_ok (enum MHD_GNUTLS_HashAlgorithm algorithm)
884{ 884{
885 ssize_t ret = -1; 885 ssize_t ret = -1;
886 GNUTLS_HASH_ALG_LOOP (ret = p->id); 886 GNUTLS_HASH_ALG_LOOP (ret = p->id);
@@ -893,7 +893,7 @@ mhd_gnutls_mac_is_ok (enum MHD_GNUTLS_HashAlgorithm algorithm)
893 893
894/* Compression Functions */ 894/* Compression Functions */
895int 895int
896mhd_gtls_compression_priority (mhd_gtls_session_t session, 896MHD_gtls_compression_priority (MHD_gtls_session_t session,
897 enum MHD_GNUTLS_CompressionMethod algorithm) 897 enum MHD_GNUTLS_CompressionMethod algorithm)
898{ /* actually returns the priority */ 898{ /* actually returns the priority */
899 unsigned int i; 899 unsigned int i;
@@ -907,7 +907,7 @@ mhd_gtls_compression_priority (mhd_gtls_session_t session,
907} 907}
908 908
909/** 909/**
910 * MHD_gnutls_compression_get_name - Returns a string with the name of the specified compression algorithm 910 * MHD__gnutls_compression_get_name - Returns a string with the name of the specified compression algorithm
911 * @algorithm: is a Compression algorithm 911 * @algorithm: is a Compression algorithm
912 * 912 *
913 * Returns: a pointer to a string that contains the name of the 913 * Returns: a pointer to a string that contains the name of the
@@ -953,7 +953,7 @@ MHD_gtls_compression_get_id (const char *name)
953 * 953 *
954 * Get a list of compression methods. Note that to be able to use LZO 954 * Get a list of compression methods. Note that to be able to use LZO
955 * compression, you must link to libgnutls-extra and call 955 * compression, you must link to libgnutls-extra and call
956 * gnutls_global_init_extra(). 956 * MHD_gnutls_global_init_extra().
957 * 957 *
958 * Returns: a zero-terminated list of %enum MHD_GNUTLS_CompressionMethod 958 * Returns: a zero-terminated list of %enum MHD_GNUTLS_CompressionMethod
959 * integers indicating the available compression methods. 959 * integers indicating the available compression methods.
@@ -961,12 +961,12 @@ MHD_gtls_compression_get_id (const char *name)
961const enum MHD_GNUTLS_CompressionMethod * 961const enum MHD_GNUTLS_CompressionMethod *
962MHD_gtls_compression_list (void) 962MHD_gtls_compression_list (void)
963{ 963{
964 return mhd_gtls_supported_compressions; 964 return MHD_gtls_supported_compressions;
965} 965}
966 966
967/* return the tls number of the specified algorithm */ 967/* return the tls number of the specified algorithm */
968int 968int
969mhd_gtls_compression_get_num (enum MHD_GNUTLS_CompressionMethod algorithm) 969MHD_gtls_compression_get_num (enum MHD_GNUTLS_CompressionMethod algorithm)
970{ 970{
971 int ret = -1; 971 int ret = -1;
972 972
@@ -977,7 +977,7 @@ mhd_gtls_compression_get_num (enum MHD_GNUTLS_CompressionMethod algorithm)
977} 977}
978 978
979int 979int
980mhd_gtls_compression_get_wbits (enum MHD_GNUTLS_CompressionMethod algorithm) 980MHD_gtls_compression_get_wbits (enum MHD_GNUTLS_CompressionMethod algorithm)
981{ 981{
982 int ret = -1; 982 int ret = -1;
983 /* avoid prefix */ 983 /* avoid prefix */
@@ -986,7 +986,7 @@ mhd_gtls_compression_get_wbits (enum MHD_GNUTLS_CompressionMethod algorithm)
986} 986}
987 987
988int 988int
989mhd_gtls_compression_get_mem_level (enum MHD_GNUTLS_CompressionMethod 989MHD_gtls_compression_get_mem_level (enum MHD_GNUTLS_CompressionMethod
990 algorithm) 990 algorithm)
991{ 991{
992 int ret = -1; 992 int ret = -1;
@@ -996,7 +996,7 @@ mhd_gtls_compression_get_mem_level (enum MHD_GNUTLS_CompressionMethod
996} 996}
997 997
998int 998int
999mhd_gtls_compression_get_comp_level (enum MHD_GNUTLS_CompressionMethod 999MHD_gtls_compression_get_comp_level (enum MHD_GNUTLS_CompressionMethod
1000 algorithm) 1000 algorithm)
1001{ 1001{
1002 int ret = -1; 1002 int ret = -1;
@@ -1009,7 +1009,7 @@ mhd_gtls_compression_get_comp_level (enum MHD_GNUTLS_CompressionMethod
1009 * method num 1009 * method num
1010 */ 1010 */
1011enum MHD_GNUTLS_CompressionMethod 1011enum MHD_GNUTLS_CompressionMethod
1012mhd_gtls_compression_get_id (int num) 1012MHD_gtls_compression_get_id_from_int (int num)
1013{ 1013{
1014 enum MHD_GNUTLS_CompressionMethod ret = -1; 1014 enum MHD_GNUTLS_CompressionMethod ret = -1;
1015 1015
@@ -1020,7 +1020,7 @@ mhd_gtls_compression_get_id (int num)
1020} 1020}
1021 1021
1022int 1022int
1023mhd_gtls_compression_is_ok (enum MHD_GNUTLS_CompressionMethod algorithm) 1023MHD_gtls_compression_is_ok (enum MHD_GNUTLS_CompressionMethod algorithm)
1024{ 1024{
1025 ssize_t ret = -1; 1025 ssize_t ret = -1;
1026 GNUTLS_COMPRESSION_ALG_LOOP (ret = p->id); 1026 GNUTLS_COMPRESSION_ALG_LOOP (ret = p->id);
@@ -1033,7 +1033,7 @@ mhd_gtls_compression_is_ok (enum MHD_GNUTLS_CompressionMethod algorithm)
1033 1033
1034/* CIPHER functions */ 1034/* CIPHER functions */
1035int 1035int
1036mhd_gtls_cipher_get_block_size (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1036MHD_gtls_cipher_get_block_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1037{ 1037{
1038 size_t ret = 0; 1038 size_t ret = 0;
1039 GNUTLS_ALG_LOOP (ret = p->blocksize); 1039 GNUTLS_ALG_LOOP (ret = p->blocksize);
@@ -1043,7 +1043,7 @@ mhd_gtls_cipher_get_block_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1043 1043
1044/* returns the priority */ 1044/* returns the priority */
1045int 1045int
1046mhd_gtls_cipher_priority (mhd_gtls_session_t session, 1046MHD_gtls_cipher_priority (MHD_gtls_session_t session,
1047 enum MHD_GNUTLS_CipherAlgorithm algorithm) 1047 enum MHD_GNUTLS_CipherAlgorithm algorithm)
1048{ 1048{
1049 unsigned int i; 1049 unsigned int i;
@@ -1056,7 +1056,7 @@ mhd_gtls_cipher_priority (mhd_gtls_session_t session,
1056} 1056}
1057 1057
1058int 1058int
1059mhd_gtls_cipher_is_block (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1059MHD_gtls_cipher_is_block (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1060{ 1060{
1061 size_t ret = 0; 1061 size_t ret = 0;
1062 1062
@@ -1066,14 +1066,14 @@ mhd_gtls_cipher_is_block (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1066} 1066}
1067 1067
1068/** 1068/**
1069 * MHD_gnutls_cipher_get_key_size - Returns the length of the cipher's key size 1069 * MHD__gnutls_cipher_get_key_size - Returns the length of the cipher's key size
1070 * @algorithm: is an encryption algorithm 1070 * @algorithm: is an encryption algorithm
1071 * 1071 *
1072 * Returns: length (in bytes) of the given cipher's key size, o 0 if 1072 * Returns: length (in bytes) of the given cipher's key size, o 0 if
1073 * the given cipher is invalid. 1073 * the given cipher is invalid.
1074 **/ 1074 **/
1075size_t 1075size_t
1076MHD_gnutls_cipher_get_key_size (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1076MHD__gnutls_cipher_get_key_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1077{ /* In bytes */ 1077{ /* In bytes */
1078 size_t ret = 0; 1078 size_t ret = 0;
1079 GNUTLS_ALG_LOOP (ret = p->keysize); 1079 GNUTLS_ALG_LOOP (ret = p->keysize);
@@ -1082,7 +1082,7 @@ MHD_gnutls_cipher_get_key_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1082} 1082}
1083 1083
1084int 1084int
1085mhd_gtls_cipher_get_iv_size (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1085MHD_gtls_cipher_get_iv_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1086{ /* In bytes */ 1086{ /* In bytes */
1087 size_t ret = 0; 1087 size_t ret = 0;
1088 GNUTLS_ALG_LOOP (ret = p->iv); 1088 GNUTLS_ALG_LOOP (ret = p->iv);
@@ -1091,7 +1091,7 @@ mhd_gtls_cipher_get_iv_size (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1091} 1091}
1092 1092
1093int 1093int
1094mhd_gtls_cipher_get_export_flag (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1094MHD_gtls_cipher_get_export_flag (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1095{ /* In bytes */ 1095{ /* In bytes */
1096 size_t ret = 0; 1096 size_t ret = 0;
1097 GNUTLS_ALG_LOOP (ret = p->export_flag); 1097 GNUTLS_ALG_LOOP (ret = p->export_flag);
@@ -1100,14 +1100,14 @@ mhd_gtls_cipher_get_export_flag (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1100} 1100}
1101 1101
1102/** 1102/**
1103 * MHD_gnutls_cipher_get_name - Returns a string with the name of the specified cipher algorithm 1103 * MHD__gnutls_cipher_get_name - Returns a string with the name of the specified cipher algorithm
1104 * @algorithm: is an encryption algorithm 1104 * @algorithm: is an encryption algorithm
1105 * 1105 *
1106 * Returns: a pointer to a string that contains the name of the 1106 * Returns: a pointer to a string that contains the name of the
1107 * specified cipher, or %NULL. 1107 * specified cipher, or %NULL.
1108 **/ 1108 **/
1109const char * 1109const char *
1110MHD_gnutls_cipher_get_name (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1110MHD__gnutls_cipher_get_name (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1111{ 1111{
1112 const char *ret = NULL; 1112 const char *ret = NULL;
1113 1113
@@ -1153,11 +1153,11 @@ MHD_gtls_cipher_get_id (const char *name)
1153const enum MHD_GNUTLS_CipherAlgorithm * 1153const enum MHD_GNUTLS_CipherAlgorithm *
1154MHD_gtls_cipher_list (void) 1154MHD_gtls_cipher_list (void)
1155{ 1155{
1156 return mhd_gtls_supported_ciphers; 1156 return MHD_gtls_supported_ciphers;
1157} 1157}
1158 1158
1159int 1159int
1160mhd_gtls_cipher_is_ok (enum MHD_GNUTLS_CipherAlgorithm algorithm) 1160MHD_gtls_cipher_is_ok (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1161{ 1161{
1162 ssize_t ret = -1; 1162 ssize_t ret = -1;
1163 GNUTLS_ALG_LOOP (ret = p->id); 1163 GNUTLS_ALG_LOOP (ret = p->id);
@@ -1169,17 +1169,17 @@ mhd_gtls_cipher_is_ok (enum MHD_GNUTLS_CipherAlgorithm algorithm)
1169} 1169}
1170 1170
1171/* Key EXCHANGE functions */ 1171/* Key EXCHANGE functions */
1172mhd_gtls_mod_auth_st * 1172MHD_gtls_mod_auth_st *
1173mhd_gtls_kx_auth_struct (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1173MHD_gtls_kx_auth_struct (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1174{ 1174{
1175 mhd_gtls_mod_auth_st *ret = NULL; 1175 MHD_gtls_mod_auth_st *ret = NULL;
1176 GNUTLS_KX_ALG_LOOP (ret = p->auth_struct); 1176 GNUTLS_KX_ALG_LOOP (ret = p->auth_struct);
1177 return ret; 1177 return ret;
1178 1178
1179} 1179}
1180 1180
1181int 1181int
1182mhd_gtls_kx_priority (mhd_gtls_session_t session, 1182MHD_gtls_kx_priority (MHD_gtls_session_t session,
1183 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1183 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1184{ 1184{
1185 unsigned int i; 1185 unsigned int i;
@@ -1192,14 +1192,14 @@ mhd_gtls_kx_priority (mhd_gtls_session_t session,
1192} 1192}
1193 1193
1194/** 1194/**
1195 * MHD_gnutls_kx_get_name - Returns a string with the name of the specified key exchange algorithm 1195 * MHD__gnutls_kx_get_name - Returns a string with the name of the specified key exchange algorithm
1196 * @algorithm: is a key exchange algorithm 1196 * @algorithm: is a key exchange algorithm
1197 * 1197 *
1198 * Returns: a pointer to a string that contains the name of the 1198 * Returns: a pointer to a string that contains the name of the
1199 * specified key exchange algorithm, or %NULL. 1199 * specified key exchange algorithm, or %NULL.
1200 **/ 1200 **/
1201const char * 1201const char *
1202MHD_gnutls_kx_get_name (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1202MHD__gnutls_kx_get_name (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1203{ 1203{
1204 const char *ret = NULL; 1204 const char *ret = NULL;
1205 1205
@@ -1240,11 +1240,11 @@ MHD_gtls_kx_get_id (const char *name)
1240const enum MHD_GNUTLS_KeyExchangeAlgorithm * 1240const enum MHD_GNUTLS_KeyExchangeAlgorithm *
1241MHD_gtls_kx_list (void) 1241MHD_gtls_kx_list (void)
1242{ 1242{
1243 return mhd_gtls_supported_kxs; 1243 return MHD_gtls_supported_kxs;
1244} 1244}
1245 1245
1246int 1246int
1247mhd_gtls_kx_is_ok (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1247MHD_gtls_kx_is_ok (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1248{ 1248{
1249 ssize_t ret = -1; 1249 ssize_t ret = -1;
1250 GNUTLS_KX_ALG_LOOP (ret = p->algorithm); 1250 GNUTLS_KX_ALG_LOOP (ret = p->algorithm);
@@ -1256,7 +1256,7 @@ mhd_gtls_kx_is_ok (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1256} 1256}
1257 1257
1258int 1258int
1259mhd_gtls_kx_needs_rsa_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1259MHD_gtls_kx_needs_rsa_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1260{ 1260{
1261 ssize_t ret = 0; 1261 ssize_t ret = 0;
1262 GNUTLS_KX_ALG_LOOP (ret = p->needs_rsa_params); 1262 GNUTLS_KX_ALG_LOOP (ret = p->needs_rsa_params);
@@ -1264,7 +1264,7 @@ mhd_gtls_kx_needs_rsa_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1264} 1264}
1265 1265
1266int 1266int
1267mhd_gtls_kx_needs_dh_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm) 1267MHD_gtls_kx_needs_dh_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1268{ 1268{
1269 ssize_t ret = 0; 1269 ssize_t ret = 0;
1270 GNUTLS_KX_ALG_LOOP (ret = p->needs_dh_params); 1270 GNUTLS_KX_ALG_LOOP (ret = p->needs_dh_params);
@@ -1273,14 +1273,14 @@ mhd_gtls_kx_needs_dh_params (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm)
1273 1273
1274/* Version */ 1274/* Version */
1275int 1275int
1276mhd_gtls_version_priority (mhd_gtls_session_t session, 1276MHD_gtls_version_priority (MHD_gtls_session_t session,
1277 enum MHD_GNUTLS_Protocol version) 1277 enum MHD_GNUTLS_Protocol version)
1278{ /* actually returns the priority */ 1278{ /* actually returns the priority */
1279 unsigned int i; 1279 unsigned int i;
1280 1280
1281 if (session->internals.priorities.protocol.priority == NULL) 1281 if (session->internals.priorities.protocol.priority == NULL)
1282 { 1282 {
1283 gnutls_assert (); 1283 MHD_gnutls_assert ();
1284 return -1; 1284 return -1;
1285 } 1285 }
1286 1286
@@ -1293,7 +1293,7 @@ mhd_gtls_version_priority (mhd_gtls_session_t session,
1293} 1293}
1294 1294
1295enum MHD_GNUTLS_Protocol 1295enum MHD_GNUTLS_Protocol
1296mhd_gtls_version_lowest (mhd_gtls_session_t session) 1296MHD_gtls_version_lowest (MHD_gtls_session_t session)
1297{ /* returns the lowest version supported */ 1297{ /* returns the lowest version supported */
1298 unsigned int i, min = 0xff; 1298 unsigned int i, min = 0xff;
1299 1299
@@ -1316,7 +1316,7 @@ mhd_gtls_version_lowest (mhd_gtls_session_t session)
1316} 1316}
1317 1317
1318enum MHD_GNUTLS_Protocol 1318enum MHD_GNUTLS_Protocol
1319mhd_gtls_version_max (mhd_gtls_session_t session) 1319MHD_gtls_version_max (MHD_gtls_session_t session)
1320{ /* returns the maximum version supported */ 1320{ /* returns the maximum version supported */
1321 unsigned int i, max = 0x00; 1321 unsigned int i, max = 0x00;
1322 1322
@@ -1339,14 +1339,14 @@ mhd_gtls_version_max (mhd_gtls_session_t session)
1339} 1339}
1340 1340
1341/** 1341/**
1342 * MHD_gnutls_protocol_get_name - Returns a string with the name of the specified SSL/TLS version 1342 * MHD__gnutls_protocol_get_name - Returns a string with the name of the specified SSL/TLS version
1343 * @version: is a (gnutls) version number 1343 * @version: is a (gnutls) version number
1344 * 1344 *
1345 * Returns: a string that contains the name of the specified TLS 1345 * Returns: a string that contains the name of the specified TLS
1346 * version (e.g., "TLS 1.0"), or %NULL. 1346 * version (e.g., "TLS 1.0"), or %NULL.
1347 **/ 1347 **/
1348const char * 1348const char *
1349MHD_gnutls_protocol_get_name (enum MHD_GNUTLS_Protocol version) 1349MHD__gnutls_protocol_get_name (enum MHD_GNUTLS_Protocol version)
1350{ 1350{
1351 const char *ret = NULL; 1351 const char *ret = NULL;
1352 1352
@@ -1387,11 +1387,11 @@ MHD_gtls_protocol_get_id (const char *name)
1387const enum MHD_GNUTLS_Protocol * 1387const enum MHD_GNUTLS_Protocol *
1388MHD_gtls_protocol_list (void) 1388MHD_gtls_protocol_list (void)
1389{ 1389{
1390 return mhd_gtls_supported_protocols; 1390 return MHD_gtls_supported_protocols;
1391} 1391}
1392 1392
1393int 1393int
1394mhd_gtls_version_get_minor (enum MHD_GNUTLS_Protocol version) 1394MHD_gtls_version_get_minor (enum MHD_GNUTLS_Protocol version)
1395{ 1395{
1396 int ret = -1; 1396 int ret = -1;
1397 1397
@@ -1400,7 +1400,7 @@ mhd_gtls_version_get_minor (enum MHD_GNUTLS_Protocol version)
1400} 1400}
1401 1401
1402enum MHD_GNUTLS_Protocol 1402enum MHD_GNUTLS_Protocol
1403mhd_gtls_version_get (int major, int minor) 1403MHD_gtls_version_get (int major, int minor)
1404{ 1404{
1405 int ret = -1; 1405 int ret = -1;
1406 1406
@@ -1411,7 +1411,7 @@ mhd_gtls_version_get (int major, int minor)
1411} 1411}
1412 1412
1413int 1413int
1414mhd_gtls_version_get_major (enum MHD_GNUTLS_Protocol version) 1414MHD_gtls_version_get_major (enum MHD_GNUTLS_Protocol version)
1415{ 1415{
1416 int ret = -1; 1416 int ret = -1;
1417 1417
@@ -1422,7 +1422,7 @@ mhd_gtls_version_get_major (enum MHD_GNUTLS_Protocol version)
1422/* Version Functions */ 1422/* Version Functions */
1423 1423
1424int 1424int
1425mhd_gtls_version_is_supported (mhd_gtls_session_t session, 1425MHD_gtls_version_is_supported (MHD_gtls_session_t session,
1426 const enum MHD_GNUTLS_Protocol version) 1426 const enum MHD_GNUTLS_Protocol version)
1427{ 1427{
1428 int ret = 0; 1428 int ret = 0;
@@ -1431,7 +1431,7 @@ mhd_gtls_version_is_supported (mhd_gtls_session_t session,
1431 if (ret == 0) 1431 if (ret == 0)
1432 return 0; 1432 return 0;
1433 1433
1434 if (mhd_gtls_version_priority (session, version) < 0) 1434 if (MHD_gtls_version_priority (session, version) < 0)
1435 return 0; /* disabled by the user */ 1435 return 0; /* disabled by the user */
1436 else 1436 else
1437 return 1; 1437 return 1;
@@ -1439,7 +1439,7 @@ mhd_gtls_version_is_supported (mhd_gtls_session_t session,
1439 1439
1440/* Type to KX mappings */ 1440/* Type to KX mappings */
1441enum MHD_GNUTLS_KeyExchangeAlgorithm 1441enum MHD_GNUTLS_KeyExchangeAlgorithm
1442mhd_gtls_map_kx_get_kx (enum MHD_GNUTLS_CredentialsType type, int server) 1442MHD_gtls_map_kx_get_kx (enum MHD_GNUTLS_CredentialsType type, int server)
1443{ 1443{
1444 enum MHD_GNUTLS_KeyExchangeAlgorithm ret = -1; 1444 enum MHD_GNUTLS_KeyExchangeAlgorithm ret = -1;
1445 1445
@@ -1455,7 +1455,7 @@ mhd_gtls_map_kx_get_kx (enum MHD_GNUTLS_CredentialsType type, int server)
1455} 1455}
1456 1456
1457enum MHD_GNUTLS_CredentialsType 1457enum MHD_GNUTLS_CredentialsType
1458mhd_gtls_map_kx_get_cred (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm, 1458MHD_gtls_map_kx_get_cred (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm,
1459 int server) 1459 int server)
1460{ 1460{
1461 enum MHD_GNUTLS_CredentialsType ret = -1; 1461 enum MHD_GNUTLS_CredentialsType ret = -1;
@@ -1475,7 +1475,7 @@ mhd_gtls_map_kx_get_cred (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm,
1475 1475
1476/* Cipher Suite's functions */ 1476/* Cipher Suite's functions */
1477enum MHD_GNUTLS_CipherAlgorithm 1477enum MHD_GNUTLS_CipherAlgorithm
1478mhd_gtls_cipher_suite_get_cipher_algo (const cipher_suite_st * suite) 1478MHD_gtls_cipher_suite_get_cipher_algo (const cipher_suite_st * suite)
1479{ 1479{
1480 int ret = 0; 1480 int ret = 0;
1481 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->block_algorithm); 1481 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->block_algorithm);
@@ -1483,7 +1483,7 @@ mhd_gtls_cipher_suite_get_cipher_algo (const cipher_suite_st * suite)
1483} 1483}
1484 1484
1485enum MHD_GNUTLS_Protocol 1485enum MHD_GNUTLS_Protocol
1486mhd_gtls_cipher_suite_get_version (const cipher_suite_st * suite) 1486MHD_gtls_cipher_suite_get_version (const cipher_suite_st * suite)
1487{ 1487{
1488 int ret = 0; 1488 int ret = 0;
1489 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->version); 1489 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->version);
@@ -1491,7 +1491,7 @@ mhd_gtls_cipher_suite_get_version (const cipher_suite_st * suite)
1491} 1491}
1492 1492
1493enum MHD_GNUTLS_KeyExchangeAlgorithm 1493enum MHD_GNUTLS_KeyExchangeAlgorithm
1494mhd_gtls_cipher_suite_get_kx_algo (const cipher_suite_st * suite) 1494MHD_gtls_cipher_suite_get_kx_algo (const cipher_suite_st * suite)
1495{ 1495{
1496 int ret = 0; 1496 int ret = 0;
1497 1497
@@ -1501,7 +1501,7 @@ mhd_gtls_cipher_suite_get_kx_algo (const cipher_suite_st * suite)
1501} 1501}
1502 1502
1503enum MHD_GNUTLS_HashAlgorithm 1503enum MHD_GNUTLS_HashAlgorithm
1504mhd_gtls_cipher_suite_get_mac_algo (const cipher_suite_st * suite) 1504MHD_gtls_cipher_suite_get_mac_algo (const cipher_suite_st * suite)
1505{ /* In bytes */ 1505{ /* In bytes */
1506 int ret = 0; 1506 int ret = 0;
1507 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->mac_algorithm); 1507 GNUTLS_CIPHER_SUITE_ALG_LOOP (ret = p->mac_algorithm);
@@ -1510,7 +1510,7 @@ mhd_gtls_cipher_suite_get_mac_algo (const cipher_suite_st * suite)
1510} 1510}
1511 1511
1512const char * 1512const char *
1513mhd_gtls_cipher_suite_get_name (cipher_suite_st * suite) 1513MHD_gtls_cipher_suite_get_name (cipher_suite_st * suite)
1514{ 1514{
1515 const char *ret = NULL; 1515 const char *ret = NULL;
1516 1516
@@ -1521,7 +1521,7 @@ mhd_gtls_cipher_suite_get_name (cipher_suite_st * suite)
1521} 1521}
1522 1522
1523static inline int 1523static inline int
1524_gnutls_cipher_suite_is_ok (cipher_suite_st * suite) 1524MHD__gnutls_cipher_suite_is_ok (cipher_suite_st * suite)
1525{ 1525{
1526 size_t ret; 1526 size_t ret;
1527 const char *name = NULL; 1527 const char *name = NULL;
@@ -1541,11 +1541,11 @@ _gnutls_cipher_suite_is_ok (cipher_suite_st * suite)
1541 1541
1542#define MAX_ELEM_SIZE 4 1542#define MAX_ELEM_SIZE 4
1543static inline int 1543static inline int
1544_gnutls_partition (mhd_gtls_session_t session, 1544MHD__gnutls_partition (MHD_gtls_session_t session,
1545 void *_base, 1545 void *_base,
1546 size_t nmemb, 1546 size_t nmemb,
1547 size_t size, 1547 size_t size,
1548 int (*compar) (mhd_gtls_session_t, 1548 int (*compar) (MHD_gtls_session_t,
1549 const void *, const void *)) 1549 const void *, const void *))
1550{ 1550{
1551 uint8_t *base = _base; 1551 uint8_t *base = _base;
@@ -1589,11 +1589,11 @@ _gnutls_partition (mhd_gtls_session_t session,
1589} 1589}
1590 1590
1591static void 1591static void
1592_gnutls_qsort (mhd_gtls_session_t session, 1592MHD__gnutls_qsort (MHD_gtls_session_t session,
1593 void *_base, 1593 void *_base,
1594 size_t nmemb, 1594 size_t nmemb,
1595 size_t size, 1595 size_t size,
1596 int (*compar) (mhd_gtls_session_t, const void *, const void *)) 1596 int (*compar) (MHD_gtls_session_t, const void *, const void *))
1597{ 1597{
1598 unsigned int pivot; 1598 unsigned int pivot;
1599 char *base = _base; 1599 char *base = _base;
@@ -1602,19 +1602,19 @@ _gnutls_qsort (mhd_gtls_session_t session,
1602#ifdef DEBUG 1602#ifdef DEBUG
1603 if (size > MAX_ELEM_SIZE) 1603 if (size > MAX_ELEM_SIZE)
1604 { 1604 {
1605 gnutls_assert (); 1605 MHD_gnutls_assert ();
1606 _gnutls_debug_log ("QSORT BUG\n"); 1606 MHD__gnutls_debug_log ("QSORT BUG\n");
1607 exit (1); 1607 exit (1);
1608 } 1608 }
1609#endif 1609#endif
1610 1610
1611 if (snmemb <= 1) 1611 if (snmemb <= 1)
1612 return; 1612 return;
1613 pivot = _gnutls_partition (session, _base, nmemb, size, compar); 1613 pivot = MHD__gnutls_partition (session, _base, nmemb, size, compar);
1614 1614
1615 _gnutls_qsort (session, base, pivot < nmemb ? pivot + 1 1615 MHD__gnutls_qsort (session, base, pivot < nmemb ? pivot + 1
1616 : pivot, size, compar); 1616 : pivot, size, compar);
1617 _gnutls_qsort (session, &base[(pivot + 1) * size], nmemb - pivot - 1, size, 1617 MHD__gnutls_qsort (session, &base[(pivot + 1) * size], nmemb - pivot - 1, size,
1618 compar); 1618 compar);
1619} 1619}
1620 1620
@@ -1622,28 +1622,28 @@ _gnutls_qsort (mhd_gtls_session_t session,
1622 * For use with qsort 1622 * For use with qsort
1623 */ 1623 */
1624static int 1624static int
1625_gnutls_compare_algo (mhd_gtls_session_t session, 1625MHD__gnutls_compare_algo (MHD_gtls_session_t session,
1626 const void *i_A1, const void *i_A2) 1626 const void *i_A1, const void *i_A2)
1627{ 1627{
1628 enum MHD_GNUTLS_KeyExchangeAlgorithm kA1 = 1628 enum MHD_GNUTLS_KeyExchangeAlgorithm kA1 =
1629 mhd_gtls_cipher_suite_get_kx_algo ((const cipher_suite_st *) i_A1); 1629 MHD_gtls_cipher_suite_get_kx_algo ((const cipher_suite_st *) i_A1);
1630 enum MHD_GNUTLS_KeyExchangeAlgorithm kA2 = 1630 enum MHD_GNUTLS_KeyExchangeAlgorithm kA2 =
1631 mhd_gtls_cipher_suite_get_kx_algo ((const cipher_suite_st *) i_A2); 1631 MHD_gtls_cipher_suite_get_kx_algo ((const cipher_suite_st *) i_A2);
1632 enum MHD_GNUTLS_CipherAlgorithm cA1 = 1632 enum MHD_GNUTLS_CipherAlgorithm cA1 =
1633 mhd_gtls_cipher_suite_get_cipher_algo ((const cipher_suite_st *) i_A1); 1633 MHD_gtls_cipher_suite_get_cipher_algo ((const cipher_suite_st *) i_A1);
1634 enum MHD_GNUTLS_CipherAlgorithm cA2 = 1634 enum MHD_GNUTLS_CipherAlgorithm cA2 =
1635 mhd_gtls_cipher_suite_get_cipher_algo ((const cipher_suite_st *) i_A2); 1635 MHD_gtls_cipher_suite_get_cipher_algo ((const cipher_suite_st *) i_A2);
1636 enum MHD_GNUTLS_HashAlgorithm mA1 = 1636 enum MHD_GNUTLS_HashAlgorithm mA1 =
1637 mhd_gtls_cipher_suite_get_mac_algo ((const cipher_suite_st *) i_A1); 1637 MHD_gtls_cipher_suite_get_mac_algo ((const cipher_suite_st *) i_A1);
1638 enum MHD_GNUTLS_HashAlgorithm mA2 = 1638 enum MHD_GNUTLS_HashAlgorithm mA2 =
1639 mhd_gtls_cipher_suite_get_mac_algo ((const cipher_suite_st *) i_A2); 1639 MHD_gtls_cipher_suite_get_mac_algo ((const cipher_suite_st *) i_A2);
1640 1640
1641 int p1 = (mhd_gtls_kx_priority (session, kA1) + 1) * 64; 1641 int p1 = (MHD_gtls_kx_priority (session, kA1) + 1) * 64;
1642 int p2 = (mhd_gtls_kx_priority (session, kA2) + 1) * 64; 1642 int p2 = (MHD_gtls_kx_priority (session, kA2) + 1) * 64;
1643 p1 += (mhd_gtls_cipher_priority (session, cA1) + 1) * 8; 1643 p1 += (MHD_gtls_cipher_priority (session, cA1) + 1) * 8;
1644 p2 += (mhd_gtls_cipher_priority (session, cA2) + 1) * 8; 1644 p2 += (MHD_gtls_cipher_priority (session, cA2) + 1) * 8;
1645 p1 += mhd_gtls_mac_priority (session, mA1); 1645 p1 += MHD_gtls_mac_priority (session, mA1);
1646 p2 += mhd_gtls_mac_priority (session, mA2); 1646 p2 += MHD_gtls_mac_priority (session, mA2);
1647 1647
1648 if (p1 > p2) 1648 if (p1 > p2)
1649 { 1649 {
@@ -1661,8 +1661,8 @@ _gnutls_compare_algo (mhd_gtls_session_t session,
1661 1661
1662#ifdef SORT_DEBUG 1662#ifdef SORT_DEBUG
1663static void 1663static void
1664_gnutls_bsort (mhd_gtls_session_t session, void *_base, size_t nmemb, 1664MHD__gnutls_bsort (MHD_gtls_session_t session, void *_base, size_t nmemb,
1665 size_t size, int (*compar) (mhd_gtls_session_t, const void *, 1665 size_t size, int (*compar) (MHD_gtls_session_t, const void *,
1666 const void *)) 1666 const void *))
1667{ 1667{
1668 unsigned int i, j; 1668 unsigned int i, j;
@@ -1685,7 +1685,7 @@ _gnutls_bsort (mhd_gtls_session_t session, void *_base, size_t nmemb,
1685#endif 1685#endif
1686 1686
1687int 1687int
1688mhd_gtls_supported_ciphersuites_sorted (mhd_gtls_session_t session, 1688MHD_gtls_supported_ciphersuites_sorted (MHD_gtls_session_t session,
1689 cipher_suite_st ** ciphers) 1689 cipher_suite_st ** ciphers)
1690{ 1690{
1691 1691
@@ -1694,34 +1694,34 @@ mhd_gtls_supported_ciphersuites_sorted (mhd_gtls_session_t session,
1694#endif 1694#endif
1695 int count; 1695 int count;
1696 1696
1697 count = mhd_gtls_supported_ciphersuites (session, ciphers); 1697 count = MHD_gtls_supported_ciphersuites (session, ciphers);
1698 if (count <= 0) 1698 if (count <= 0)
1699 { 1699 {
1700 gnutls_assert (); 1700 MHD_gnutls_assert ();
1701 return count; 1701 return count;
1702 } 1702 }
1703#ifdef SORT_DEBUG 1703#ifdef SORT_DEBUG
1704 _gnutls_debug_log ("Unsorted: \n"); 1704 MHD__gnutls_debug_log ("Unsorted: \n");
1705 for (i = 0; i < count; i++) 1705 for (i = 0; i < count; i++)
1706 _gnutls_debug_log ("\t%d: %s\n", i, 1706 MHD__gnutls_debug_log ("\t%d: %s\n", i,
1707 mhd_gtls_cipher_suite_get_name ((*ciphers)[i])); 1707 MHD_gtls_cipher_suite_get_name ((*ciphers)[i]));
1708#endif 1708#endif
1709 1709
1710 _gnutls_qsort (session, *ciphers, count, sizeof (cipher_suite_st), 1710 MHD__gnutls_qsort (session, *ciphers, count, sizeof (cipher_suite_st),
1711 _gnutls_compare_algo); 1711 MHD__gnutls_compare_algo);
1712 1712
1713#ifdef SORT_DEBUG 1713#ifdef SORT_DEBUG
1714 _gnutls_debug_log ("Sorted: \n"); 1714 MHD__gnutls_debug_log ("Sorted: \n");
1715 for (i = 0; i < count; i++) 1715 for (i = 0; i < count; i++)
1716 _gnutls_debug_log ("\t%d: %s\n", i, 1716 MHD__gnutls_debug_log ("\t%d: %s\n", i,
1717 mhd_gtls_cipher_suite_get_name ((*ciphers)[i])); 1717 MHD_gtls_cipher_suite_get_name ((*ciphers)[i]));
1718#endif 1718#endif
1719 1719
1720 return count; 1720 return count;
1721} 1721}
1722 1722
1723int 1723int
1724mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session, 1724MHD_gtls_supported_ciphersuites (MHD_gtls_session_t session,
1725 cipher_suite_st ** _ciphers) 1725 cipher_suite_st ** _ciphers)
1726{ 1726{
1727 1727
@@ -1736,22 +1736,22 @@ mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session,
1736 return 0; 1736 return 0;
1737 } 1737 }
1738 1738
1739 tmp_ciphers = gnutls_alloca (count * sizeof (cipher_suite_st)); 1739 tmp_ciphers = MHD_gnutls_alloca (count * sizeof (cipher_suite_st));
1740 if (tmp_ciphers == NULL) 1740 if (tmp_ciphers == NULL)
1741 return GNUTLS_E_MEMORY_ERROR; 1741 return GNUTLS_E_MEMORY_ERROR;
1742 1742
1743 ciphers = gnutls_malloc (count * sizeof (cipher_suite_st)); 1743 ciphers = MHD_gnutls_malloc (count * sizeof (cipher_suite_st));
1744 if (ciphers == NULL) 1744 if (ciphers == NULL)
1745 { 1745 {
1746 gnutls_afree (tmp_ciphers); 1746 MHD_gnutls_afree (tmp_ciphers);
1747 return GNUTLS_E_MEMORY_ERROR; 1747 return GNUTLS_E_MEMORY_ERROR;
1748 } 1748 }
1749 1749
1750 version = MHD_gnutls_protocol_get_version (session); 1750 version = MHD__gnutls_protocol_get_version (session);
1751 1751
1752 for (i = 0; i < count; i++) 1752 for (i = 0; i < count; i++)
1753 { 1753 {
1754 memcpy (&tmp_ciphers[i], &mhd_gtls_cs_algorithms[i].id, 1754 memcpy (&tmp_ciphers[i], &MHD_gtls_cs_algorithms[i].id,
1755 sizeof (cipher_suite_st)); 1755 sizeof (cipher_suite_st));
1756 } 1756 }
1757 1757
@@ -1766,19 +1766,19 @@ mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session,
1766 /* remove cipher suites which do not support the 1766 /* remove cipher suites which do not support the
1767 * protocol version used. 1767 * protocol version used.
1768 */ 1768 */
1769 if (mhd_gtls_cipher_suite_get_version (&tmp_ciphers[i]) > version) 1769 if (MHD_gtls_cipher_suite_get_version (&tmp_ciphers[i]) > version)
1770 continue; 1770 continue;
1771 1771
1772 if (mhd_gtls_kx_priority (session, 1772 if (MHD_gtls_kx_priority (session,
1773 mhd_gtls_cipher_suite_get_kx_algo 1773 MHD_gtls_cipher_suite_get_kx_algo
1774 (&tmp_ciphers[i])) < 0) 1774 (&tmp_ciphers[i])) < 0)
1775 continue; 1775 continue;
1776 if (mhd_gtls_mac_priority (session, 1776 if (MHD_gtls_mac_priority (session,
1777 mhd_gtls_cipher_suite_get_mac_algo 1777 MHD_gtls_cipher_suite_get_mac_algo
1778 (&tmp_ciphers[i])) < 0) 1778 (&tmp_ciphers[i])) < 0)
1779 continue; 1779 continue;
1780 if (mhd_gtls_cipher_priority (session, 1780 if (MHD_gtls_cipher_priority (session,
1781 mhd_gtls_cipher_suite_get_cipher_algo 1781 MHD_gtls_cipher_suite_get_cipher_algo
1782 (&tmp_ciphers[i])) < 0) 1782 (&tmp_ciphers[i])) < 0)
1783 continue; 1783 continue;
1784 1784
@@ -1792,27 +1792,27 @@ mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session,
1792 if (ret_count > 0 && ret_count != count) 1792 if (ret_count > 0 && ret_count != count)
1793 { 1793 {
1794 ciphers = 1794 ciphers =
1795 mhd_gtls_realloc_fast (ciphers, ret_count * sizeof (cipher_suite_st)); 1795 MHD_gtls_realloc_fast (ciphers, ret_count * sizeof (cipher_suite_st));
1796 } 1796 }
1797 else 1797 else
1798 { 1798 {
1799 if (ret_count != count) 1799 if (ret_count != count)
1800 { 1800 {
1801 gnutls_free (ciphers); 1801 MHD_gnutls_free (ciphers);
1802 ciphers = NULL; 1802 ciphers = NULL;
1803 } 1803 }
1804 } 1804 }
1805#endif 1805#endif
1806 1806
1807 gnutls_afree (tmp_ciphers); 1807 MHD_gnutls_afree (tmp_ciphers);
1808 1808
1809 /* This function can no longer return 0 cipher suites. 1809 /* This function can no longer return 0 cipher suites.
1810 * It returns an error code instead. 1810 * It returns an error code instead.
1811 */ 1811 */
1812 if (ret_count == 0) 1812 if (ret_count == 0)
1813 { 1813 {
1814 gnutls_assert (); 1814 MHD_gnutls_assert ();
1815 gnutls_free (ciphers); 1815 MHD_gnutls_free (ciphers);
1816 return GNUTLS_E_NO_CIPHER_SUITES; 1816 return GNUTLS_E_NO_CIPHER_SUITES;
1817 } 1817 }
1818 *_ciphers = ciphers; 1818 *_ciphers = ciphers;
@@ -1827,19 +1827,19 @@ mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session,
1827 */ 1827 */
1828#define SUPPORTED_COMPRESSION_METHODS session->internals.priorities.compression.num_algorithms 1828#define SUPPORTED_COMPRESSION_METHODS session->internals.priorities.compression.num_algorithms
1829int 1829int
1830mhd_gtls_supported_compression_methods (mhd_gtls_session_t session, 1830MHD_gtls_supported_compression_methods (MHD_gtls_session_t session,
1831 uint8_t ** comp) 1831 uint8_t ** comp)
1832{ 1832{
1833 unsigned int i, j; 1833 unsigned int i, j;
1834 1834
1835 *comp = gnutls_malloc (sizeof (uint8_t) * SUPPORTED_COMPRESSION_METHODS); 1835 *comp = MHD_gnutls_malloc (sizeof (uint8_t) * SUPPORTED_COMPRESSION_METHODS);
1836 if (*comp == NULL) 1836 if (*comp == NULL)
1837 return GNUTLS_E_MEMORY_ERROR; 1837 return GNUTLS_E_MEMORY_ERROR;
1838 1838
1839 for (i = j = 0; i < SUPPORTED_COMPRESSION_METHODS; i++) 1839 for (i = j = 0; i < SUPPORTED_COMPRESSION_METHODS; i++)
1840 { 1840 {
1841 int tmp = 1841 int tmp =
1842 mhd_gtls_compression_get_num (session->internals.priorities. 1842 MHD_gtls_compression_get_num (session->internals.priorities.
1843 compression.priority[i]); 1843 compression.priority[i]);
1844 1844
1845 /* remove private compression algorithms, if requested. 1845 /* remove private compression algorithms, if requested.
@@ -1847,7 +1847,7 @@ mhd_gtls_supported_compression_methods (mhd_gtls_session_t session,
1847 if (tmp == -1 || (tmp >= MIN_PRIVATE_COMP_ALGO 1847 if (tmp == -1 || (tmp >= MIN_PRIVATE_COMP_ALGO
1848 && session->internals.enable_private == 0)) 1848 && session->internals.enable_private == 0))
1849 { 1849 {
1850 gnutls_assert (); 1850 MHD_gnutls_assert ();
1851 continue; 1851 continue;
1852 } 1852 }
1853 1853
@@ -1857,8 +1857,8 @@ mhd_gtls_supported_compression_methods (mhd_gtls_session_t session,
1857 1857
1858 if (j == 0) 1858 if (j == 0)
1859 { 1859 {
1860 gnutls_assert (); 1860 MHD_gnutls_assert ();
1861 gnutls_free (*comp); 1861 MHD_gnutls_free (*comp);
1862 *comp = NULL; 1862 *comp = NULL;
1863 return GNUTLS_E_NO_COMPRESSION_ALGORITHMS; 1863 return GNUTLS_E_NO_COMPRESSION_ALGORITHMS;
1864 } 1864 }
@@ -1866,14 +1866,14 @@ mhd_gtls_supported_compression_methods (mhd_gtls_session_t session,
1866} 1866}
1867 1867
1868/** 1868/**
1869 * MHD_gnutls_certificate_type_get_name - Returns a string with the name of the specified certificate type 1869 * MHD__gnutls_certificate_type_get_name - Returns a string with the name of the specified certificate type
1870 * @type: is a certificate type 1870 * @type: is a certificate type
1871 * 1871 *
1872 * Returns: a string (or %NULL) that contains the name of the 1872 * Returns: a string (or %NULL) that contains the name of the
1873 * specified certificate type. 1873 * specified certificate type.
1874 **/ 1874 **/
1875const char * 1875const char *
1876MHD_gnutls_certificate_type_get_name (enum MHD_GNUTLS_CertificateType type) 1876MHD__gnutls_certificate_type_get_name (enum MHD_GNUTLS_CertificateType type)
1877{ 1877{
1878 const char *ret = NULL; 1878 const char *ret = NULL;
1879 1879
@@ -1902,7 +1902,7 @@ MHD_gtls_certificate_type_get_id (const char *name)
1902} 1902}
1903 1903
1904static const enum MHD_GNUTLS_CertificateType 1904static const enum MHD_GNUTLS_CertificateType
1905 mhd_gtls_supported_certificate_types[] = 1905 MHD_gtls_supported_certificate_types[] =
1906{ MHD_GNUTLS_CRT_X509, 1906{ MHD_GNUTLS_CRT_X509,
1907 0 1907 0
1908}; 1908};
@@ -1919,14 +1919,14 @@ static const enum MHD_GNUTLS_CertificateType
1919const enum MHD_GNUTLS_CertificateType * 1919const enum MHD_GNUTLS_CertificateType *
1920MHD_gtls_certificate_type_list (void) 1920MHD_gtls_certificate_type_list (void)
1921{ 1921{
1922 return mhd_gtls_supported_certificate_types; 1922 return MHD_gtls_supported_certificate_types;
1923} 1923}
1924 1924
1925/* returns the enum MHD_GNUTLS_PublicKeyAlgorithm which is compatible with 1925/* returns the enum MHD_GNUTLS_PublicKeyAlgorithm which is compatible with
1926 * the given enum MHD_GNUTLS_KeyExchangeAlgorithm. 1926 * the given enum MHD_GNUTLS_KeyExchangeAlgorithm.
1927 */ 1927 */
1928enum MHD_GNUTLS_PublicKeyAlgorithm 1928enum MHD_GNUTLS_PublicKeyAlgorithm
1929mhd_gtls_map_pk_get_pk (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm) 1929MHD_gtls_map_pk_get_pk (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm)
1930{ 1930{
1931 enum MHD_GNUTLS_PublicKeyAlgorithm ret = -1; 1931 enum MHD_GNUTLS_PublicKeyAlgorithm ret = -1;
1932 1932
@@ -1939,7 +1939,7 @@ mhd_gtls_map_pk_get_pk (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm)
1939 * ex. GNUTLS_KX_RSA requires a certificate able to encrypt... so returns CIPHER_ENCRYPT. 1939 * ex. GNUTLS_KX_RSA requires a certificate able to encrypt... so returns CIPHER_ENCRYPT.
1940 */ 1940 */
1941enum encipher_type 1941enum encipher_type
1942mhd_gtls_kx_encipher_type (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm) 1942MHD_gtls_kx_encipher_type (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm)
1943{ 1943{
1944 int ret = CIPHER_IGN; 1944 int ret = CIPHER_IGN;
1945 GNUTLS_PK_MAP_ALG_LOOP (ret = p->encipher_type) return ret; 1945 GNUTLS_PK_MAP_ALG_LOOP (ret = p->encipher_type) return ret;
@@ -1948,17 +1948,17 @@ mhd_gtls_kx_encipher_type (enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm)
1948 1948
1949/* signature algorithms; 1949/* signature algorithms;
1950 */ 1950 */
1951struct gnutls_sign_entry 1951struct MHD_gnutls_sign_entry
1952{ 1952{
1953 const char *name; 1953 const char *name;
1954 const char *oid; 1954 const char *oid;
1955 gnutls_sign_algorithm_t id; 1955 MHD_gnutls_sign_algorithm_t id;
1956 enum MHD_GNUTLS_PublicKeyAlgorithm pk; 1956 enum MHD_GNUTLS_PublicKeyAlgorithm pk;
1957 enum MHD_GNUTLS_HashAlgorithm mac; 1957 enum MHD_GNUTLS_HashAlgorithm mac;
1958}; 1958};
1959typedef struct gnutls_sign_entry gnutls_sign_entry; 1959typedef struct MHD_gnutls_sign_entry MHD_gnutls_sign_entry;
1960 1960
1961static const gnutls_sign_entry mhd_gtls_sign_algorithms[] = { 1961static const MHD_gnutls_sign_entry MHD_gtls_sign_algorithms[] = {
1962 {"RSA-SHA", 1962 {"RSA-SHA",
1963 SIG_RSA_SHA1_OID, 1963 SIG_RSA_SHA1_OID,
1964 GNUTLS_SIGN_RSA_SHA1, 1964 GNUTLS_SIGN_RSA_SHA1,
@@ -1993,17 +1993,17 @@ static const gnutls_sign_entry mhd_gtls_sign_algorithms[] = {
1993 1993
1994#define GNUTLS_SIGN_LOOP(b) \ 1994#define GNUTLS_SIGN_LOOP(b) \
1995 do { \ 1995 do { \
1996 const gnutls_sign_entry *p; \ 1996 const MHD_gnutls_sign_entry *p; \
1997 for(p = mhd_gtls_sign_algorithms; p->name != NULL; p++) { b ; } \ 1997 for(p = MHD_gtls_sign_algorithms; p->name != NULL; p++) { b ; } \
1998 } while (0) 1998 } while (0)
1999 1999
2000#define GNUTLS_SIGN_ALG_LOOP(a) \ 2000#define GNUTLS_SIGN_ALG_LOOP(a) \
2001 GNUTLS_SIGN_LOOP( if(p->id && p->id == sign) { a; break; } ) 2001 GNUTLS_SIGN_LOOP( if(p->id && p->id == sign) { a; break; } )
2002 2002
2003gnutls_sign_algorithm_t 2003MHD_gnutls_sign_algorithm_t
2004mhd_gtls_x509_oid2sign_algorithm (const char *oid) 2004MHD_gtls_x509_oid2sign_algorithm (const char *oid)
2005{ 2005{
2006 gnutls_sign_algorithm_t ret = 0; 2006 MHD_gnutls_sign_algorithm_t ret = 0;
2007 2007
2008 GNUTLS_SIGN_LOOP (if (strcmp (oid, p->oid) == 0) 2008 GNUTLS_SIGN_LOOP (if (strcmp (oid, p->oid) == 0)
2009 { 2009 {
@@ -2012,17 +2012,17 @@ mhd_gtls_x509_oid2sign_algorithm (const char *oid)
2012 2012
2013 if (ret == 0) 2013 if (ret == 0)
2014 { 2014 {
2015 _gnutls_x509_log ("Unknown SIGN OID: '%s'\n", oid); 2015 MHD__gnutls_x509_log ("Unknown SIGN OID: '%s'\n", oid);
2016 return GNUTLS_SIGN_UNKNOWN; 2016 return GNUTLS_SIGN_UNKNOWN;
2017 } 2017 }
2018 return ret; 2018 return ret;
2019} 2019}
2020 2020
2021gnutls_sign_algorithm_t 2021MHD_gnutls_sign_algorithm_t
2022mhd_gtls_x509_pk_to_sign (enum MHD_GNUTLS_PublicKeyAlgorithm pk, 2022MHD_gtls_x509_pk_to_sign (enum MHD_GNUTLS_PublicKeyAlgorithm pk,
2023 enum MHD_GNUTLS_HashAlgorithm mac) 2023 enum MHD_GNUTLS_HashAlgorithm mac)
2024{ 2024{
2025 gnutls_sign_algorithm_t ret = 0; 2025 MHD_gnutls_sign_algorithm_t ret = 0;
2026 2026
2027 GNUTLS_SIGN_LOOP (if (pk == p->pk && mac == p->mac) 2027 GNUTLS_SIGN_LOOP (if (pk == p->pk && mac == p->mac)
2028 { 2028 {
@@ -2035,13 +2035,13 @@ mhd_gtls_x509_pk_to_sign (enum MHD_GNUTLS_PublicKeyAlgorithm pk,
2035} 2035}
2036 2036
2037const char * 2037const char *
2038mhd_gtls_x509_sign_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm pk, 2038MHD_gtls_x509_sign_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm pk,
2039 enum MHD_GNUTLS_HashAlgorithm mac) 2039 enum MHD_GNUTLS_HashAlgorithm mac)
2040{ 2040{
2041 gnutls_sign_algorithm_t sign; 2041 MHD_gnutls_sign_algorithm_t sign;
2042 const char *ret = NULL; 2042 const char *ret = NULL;
2043 2043
2044 sign = mhd_gtls_x509_pk_to_sign (pk, mac); 2044 sign = MHD_gtls_x509_pk_to_sign (pk, mac);
2045 if (sign == GNUTLS_SIGN_UNKNOWN) 2045 if (sign == GNUTLS_SIGN_UNKNOWN)
2046 return NULL; 2046 return NULL;
2047 2047
@@ -2051,15 +2051,15 @@ mhd_gtls_x509_sign_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm pk,
2051 2051
2052/* pk algorithms; 2052/* pk algorithms;
2053 */ 2053 */
2054struct gnutls_pk_entry 2054struct MHD_gnutls_pk_entry
2055{ 2055{
2056 const char *name; 2056 const char *name;
2057 const char *oid; 2057 const char *oid;
2058 enum MHD_GNUTLS_PublicKeyAlgorithm id; 2058 enum MHD_GNUTLS_PublicKeyAlgorithm id;
2059}; 2059};
2060typedef struct gnutls_pk_entry gnutls_pk_entry; 2060typedef struct MHD_gnutls_pk_entry MHD_gnutls_pk_entry;
2061 2061
2062static const gnutls_pk_entry mhd_gtls_pk_algorithms[] = { 2062static const MHD_gnutls_pk_entry MHD_gtls_pk_algorithms[] = {
2063 {"RSA", 2063 {"RSA",
2064 PK_PKIX1_RSA_OID, 2064 PK_PKIX1_RSA_OID,
2065 MHD_GNUTLS_PK_RSA}, 2065 MHD_GNUTLS_PK_RSA},
@@ -2075,12 +2075,12 @@ static const gnutls_pk_entry mhd_gtls_pk_algorithms[] = {
2075}; 2075};
2076 2076
2077enum MHD_GNUTLS_PublicKeyAlgorithm 2077enum MHD_GNUTLS_PublicKeyAlgorithm
2078mhd_gtls_x509_oid2pk_algorithm (const char *oid) 2078MHD_gtls_x509_oid2pk_algorithm (const char *oid)
2079{ 2079{
2080 enum MHD_GNUTLS_PublicKeyAlgorithm ret = MHD_GNUTLS_PK_UNKNOWN; 2080 enum MHD_GNUTLS_PublicKeyAlgorithm ret = MHD_GNUTLS_PK_UNKNOWN;
2081 const gnutls_pk_entry *p; 2081 const MHD_gnutls_pk_entry *p;
2082 2082
2083 for (p = mhd_gtls_pk_algorithms; p->name != NULL; p++) 2083 for (p = MHD_gtls_pk_algorithms; p->name != NULL; p++)
2084 if (strcmp (p->oid, oid) == 0) 2084 if (strcmp (p->oid, oid) == 0)
2085 { 2085 {
2086 ret = p->id; 2086 ret = p->id;
@@ -2091,12 +2091,12 @@ mhd_gtls_x509_oid2pk_algorithm (const char *oid)
2091} 2091}
2092 2092
2093const char * 2093const char *
2094mhd_gtls_x509_pk_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm algorithm) 2094MHD_gtls_x509_pk_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm algorithm)
2095{ 2095{
2096 const char *ret = NULL; 2096 const char *ret = NULL;
2097 const gnutls_pk_entry *p; 2097 const MHD_gnutls_pk_entry *p;
2098 2098
2099 for (p = mhd_gtls_pk_algorithms; p->name != NULL; p++) 2099 for (p = MHD_gtls_pk_algorithms; p->name != NULL; p++)
2100 if (p->id == algorithm) 2100 if (p->id == algorithm)
2101 { 2101 {
2102 ret = p->oid; 2102 ret = p->oid;
diff --git a/src/daemon/https/tls/gnutls_algorithms.h b/src/daemon/https/tls/gnutls_algorithms.h
index c98e3c41..c0cb2332 100644
--- a/src/daemon/https/tls/gnutls_algorithms.h
+++ b/src/daemon/https/tls/gnutls_algorithms.h
@@ -28,105 +28,105 @@
28#include "gnutls_auth.h" 28#include "gnutls_auth.h"
29 29
30/* Functions for version handling. */ 30/* Functions for version handling. */
31enum MHD_GNUTLS_Protocol mhd_gtls_version_lowest (mhd_gtls_session_t session); 31enum MHD_GNUTLS_Protocol MHD_gtls_version_lowest (MHD_gtls_session_t session);
32enum MHD_GNUTLS_Protocol mhd_gtls_version_max (mhd_gtls_session_t session); 32enum MHD_GNUTLS_Protocol MHD_gtls_version_max (MHD_gtls_session_t session);
33int mhd_gtls_version_priority (mhd_gtls_session_t session, 33int MHD_gtls_version_priority (MHD_gtls_session_t session,
34 enum MHD_GNUTLS_Protocol version); 34 enum MHD_GNUTLS_Protocol version);
35int mhd_gtls_version_is_supported (mhd_gtls_session_t session, 35int MHD_gtls_version_is_supported (MHD_gtls_session_t session,
36 const enum MHD_GNUTLS_Protocol version); 36 const enum MHD_GNUTLS_Protocol version);
37int mhd_gtls_version_get_major (enum MHD_GNUTLS_Protocol ver); 37int MHD_gtls_version_get_major (enum MHD_GNUTLS_Protocol ver);
38int mhd_gtls_version_get_minor (enum MHD_GNUTLS_Protocol ver); 38int MHD_gtls_version_get_minor (enum MHD_GNUTLS_Protocol ver);
39enum MHD_GNUTLS_Protocol mhd_gtls_version_get (int major, int minor); 39enum MHD_GNUTLS_Protocol MHD_gtls_version_get (int major, int minor);
40 40
41/* Functions for MACs. */ 41/* Functions for MACs. */
42int mhd_gnutls_mac_is_ok (enum MHD_GNUTLS_HashAlgorithm algorithm); 42int MHD_gnutls_mac_is_ok (enum MHD_GNUTLS_HashAlgorithm algorithm);
43enum MHD_GNUTLS_HashAlgorithm mhd_gtls_x509_oid2mac_algorithm (const char 43enum MHD_GNUTLS_HashAlgorithm MHD_gtls_x509_oid2mac_algorithm (const char
44 *oid); 44 *oid);
45const char *mhd_gtls_x509_mac_to_oid (enum MHD_GNUTLS_HashAlgorithm mac); 45const char *MHD_gtls_x509_mac_to_oid (enum MHD_GNUTLS_HashAlgorithm mac);
46 46
47/* Functions for cipher suites. */ 47/* Functions for cipher suites. */
48int mhd_gtls_supported_ciphersuites (mhd_gtls_session_t session, 48int MHD_gtls_supported_ciphersuites (MHD_gtls_session_t session,
49 cipher_suite_st ** ciphers); 49 cipher_suite_st ** ciphers);
50int mhd_gtls_supported_ciphersuites_sorted (mhd_gtls_session_t session, 50int MHD_gtls_supported_ciphersuites_sorted (MHD_gtls_session_t session,
51 cipher_suite_st ** ciphers); 51 cipher_suite_st ** ciphers);
52int mhd_gtls_supported_compression_methods (mhd_gtls_session_t session, 52int MHD_gtls_supported_compression_methods (MHD_gtls_session_t session,
53 uint8_t ** comp); 53 uint8_t ** comp);
54const char *mhd_gtls_cipher_suite_get_name (cipher_suite_st * algorithm); 54const char *MHD_gtls_cipher_suite_get_name (cipher_suite_st * algorithm);
55enum MHD_GNUTLS_CipherAlgorithm mhd_gtls_cipher_suite_get_cipher_algo (const 55enum MHD_GNUTLS_CipherAlgorithm MHD_gtls_cipher_suite_get_cipher_algo (const
56 cipher_suite_st 56 cipher_suite_st
57 * 57 *
58 algorithm); 58 algorithm);
59enum MHD_GNUTLS_KeyExchangeAlgorithm mhd_gtls_cipher_suite_get_kx_algo (const 59enum MHD_GNUTLS_KeyExchangeAlgorithm MHD_gtls_cipher_suite_get_kx_algo (const
60 cipher_suite_st 60 cipher_suite_st
61 * 61 *
62 algorithm); 62 algorithm);
63enum MHD_GNUTLS_HashAlgorithm mhd_gtls_cipher_suite_get_mac_algo (const 63enum MHD_GNUTLS_HashAlgorithm MHD_gtls_cipher_suite_get_mac_algo (const
64 cipher_suite_st 64 cipher_suite_st
65 * 65 *
66 algorithm); 66 algorithm);
67enum MHD_GNUTLS_Protocol mhd_gtls_cipher_suite_get_version (const 67enum MHD_GNUTLS_Protocol MHD_gtls_cipher_suite_get_version (const
68 cipher_suite_st * 68 cipher_suite_st *
69 algorithm); 69 algorithm);
70cipher_suite_st mhd_gtls_cipher_suite_get_suite_name (cipher_suite_st * 70cipher_suite_st MHD_gtls_cipher_suite_get_suite_name (cipher_suite_st *
71 algorithm); 71 algorithm);
72 72
73/* Functions for ciphers. */ 73/* Functions for ciphers. */
74int mhd_gtls_cipher_get_block_size (enum MHD_GNUTLS_CipherAlgorithm 74int MHD_gtls_cipher_get_block_size (enum MHD_GNUTLS_CipherAlgorithm
75 algorithm); 75 algorithm);
76int mhd_gtls_cipher_is_block (enum MHD_GNUTLS_CipherAlgorithm algorithm); 76int MHD_gtls_cipher_is_block (enum MHD_GNUTLS_CipherAlgorithm algorithm);
77int mhd_gtls_cipher_is_ok (enum MHD_GNUTLS_CipherAlgorithm algorithm); 77int MHD_gtls_cipher_is_ok (enum MHD_GNUTLS_CipherAlgorithm algorithm);
78int mhd_gtls_cipher_get_iv_size (enum MHD_GNUTLS_CipherAlgorithm algorithm); 78int MHD_gtls_cipher_get_iv_size (enum MHD_GNUTLS_CipherAlgorithm algorithm);
79int mhd_gtls_cipher_get_export_flag (enum MHD_GNUTLS_CipherAlgorithm 79int MHD_gtls_cipher_get_export_flag (enum MHD_GNUTLS_CipherAlgorithm
80 algorithm); 80 algorithm);
81 81
82/* Functions for key exchange. */ 82/* Functions for key exchange. */
83int mhd_gtls_kx_needs_dh_params (enum MHD_GNUTLS_KeyExchangeAlgorithm 83int MHD_gtls_kx_needs_dh_params (enum MHD_GNUTLS_KeyExchangeAlgorithm
84 algorithm); 84 algorithm);
85int mhd_gtls_kx_needs_rsa_params (enum MHD_GNUTLS_KeyExchangeAlgorithm 85int MHD_gtls_kx_needs_rsa_params (enum MHD_GNUTLS_KeyExchangeAlgorithm
86 algorithm); 86 algorithm);
87mhd_gtls_mod_auth_st *mhd_gtls_kx_auth_struct (enum 87MHD_gtls_mod_auth_st *MHD_gtls_kx_auth_struct (enum
88 MHD_GNUTLS_KeyExchangeAlgorithm 88 MHD_GNUTLS_KeyExchangeAlgorithm
89 algorithm); 89 algorithm);
90int mhd_gtls_kx_is_ok (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm); 90int MHD_gtls_kx_is_ok (enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm);
91 91
92/* Functions for compression. */ 92/* Functions for compression. */
93int mhd_gtls_compression_is_ok (enum MHD_GNUTLS_CompressionMethod algorithm); 93int MHD_gtls_compression_is_ok (enum MHD_GNUTLS_CompressionMethod algorithm);
94int mhd_gtls_compression_get_num (enum MHD_GNUTLS_CompressionMethod 94int MHD_gtls_compression_get_num (enum MHD_GNUTLS_CompressionMethod
95 algorithm); 95 algorithm);
96enum MHD_GNUTLS_CompressionMethod mhd_gtls_compression_get_id (int num); 96enum MHD_GNUTLS_CompressionMethod MHD_gtls_compression_get_id_from_int (int num);
97int mhd_gtls_compression_get_mem_level (enum MHD_GNUTLS_CompressionMethod 97int MHD_gtls_compression_get_mem_level (enum MHD_GNUTLS_CompressionMethod
98 algorithm); 98 algorithm);
99int mhd_gtls_compression_get_comp_level (enum MHD_GNUTLS_CompressionMethod 99int MHD_gtls_compression_get_comp_level (enum MHD_GNUTLS_CompressionMethod
100 algorithm); 100 algorithm);
101int mhd_gtls_compression_get_wbits (enum MHD_GNUTLS_CompressionMethod 101int MHD_gtls_compression_get_wbits (enum MHD_GNUTLS_CompressionMethod
102 algorithm); 102 algorithm);
103 103
104/* Type to KX mappings. */ 104/* Type to KX mappings. */
105enum MHD_GNUTLS_KeyExchangeAlgorithm mhd_gtls_map_kx_get_kx (enum 105enum MHD_GNUTLS_KeyExchangeAlgorithm MHD_gtls_map_kx_get_kx (enum
106 MHD_GNUTLS_CredentialsType 106 MHD_GNUTLS_CredentialsType
107 type, 107 type,
108 int server); 108 int server);
109enum MHD_GNUTLS_CredentialsType mhd_gtls_map_kx_get_cred (enum 109enum MHD_GNUTLS_CredentialsType MHD_gtls_map_kx_get_cred (enum
110 MHD_GNUTLS_KeyExchangeAlgorithm 110 MHD_GNUTLS_KeyExchangeAlgorithm
111 algorithm, 111 algorithm,
112 int server); 112 int server);
113 113
114/* KX to PK mapping. */ 114/* KX to PK mapping. */
115enum MHD_GNUTLS_PublicKeyAlgorithm mhd_gtls_map_pk_get_pk (enum 115enum MHD_GNUTLS_PublicKeyAlgorithm MHD_gtls_map_pk_get_pk (enum
116 MHD_GNUTLS_KeyExchangeAlgorithm 116 MHD_GNUTLS_KeyExchangeAlgorithm
117 kx_algorithm); 117 kx_algorithm);
118enum MHD_GNUTLS_PublicKeyAlgorithm mhd_gtls_x509_oid2pk_algorithm (const char 118enum MHD_GNUTLS_PublicKeyAlgorithm MHD_gtls_x509_oid2pk_algorithm (const char
119 *oid); 119 *oid);
120const char *mhd_gtls_x509_pk_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm pk); 120const char *MHD_gtls_x509_pk_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm pk);
121 121
122enum encipher_type 122enum encipher_type
123{ CIPHER_ENCRYPT = 0, CIPHER_SIGN = 1, CIPHER_IGN }; 123{ CIPHER_ENCRYPT = 0, CIPHER_SIGN = 1, CIPHER_IGN };
124 124
125enum encipher_type mhd_gtls_kx_encipher_type (enum 125enum encipher_type MHD_gtls_kx_encipher_type (enum
126 MHD_GNUTLS_KeyExchangeAlgorithm 126 MHD_GNUTLS_KeyExchangeAlgorithm
127 algorithm); 127 algorithm);
128 128
129struct mhd_gtls_compression_entry 129struct MHD_gtls_compression_entry
130{ 130{
131 const char *name; 131 const char *name;
132 enum MHD_GNUTLS_CompressionMethod id; 132 enum MHD_GNUTLS_CompressionMethod id;
@@ -137,26 +137,26 @@ struct mhd_gtls_compression_entry
137 int mem_level; 137 int mem_level;
138 int comp_level; 138 int comp_level;
139}; 139};
140typedef struct mhd_gtls_compression_entry gnutls_compression_entry; 140typedef struct MHD_gtls_compression_entry MHD_gnutls_compression_entry;
141 141
142/* Functions for sign algorithms. */ 142/* Functions for sign algorithms. */
143gnutls_sign_algorithm_t mhd_gtls_x509_oid2sign_algorithm (const char *oid); 143MHD_gnutls_sign_algorithm_t MHD_gtls_x509_oid2sign_algorithm (const char *oid);
144gnutls_sign_algorithm_t mhd_gtls_x509_pk_to_sign (enum 144MHD_gnutls_sign_algorithm_t MHD_gtls_x509_pk_to_sign (enum
145 MHD_GNUTLS_PublicKeyAlgorithm 145 MHD_GNUTLS_PublicKeyAlgorithm
146 pk, 146 pk,
147 enum 147 enum
148 MHD_GNUTLS_HashAlgorithm 148 MHD_GNUTLS_HashAlgorithm
149 mac); 149 mac);
150const char *mhd_gtls_x509_sign_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm, 150const char *MHD_gtls_x509_sign_to_oid (enum MHD_GNUTLS_PublicKeyAlgorithm,
151 enum MHD_GNUTLS_HashAlgorithm mac); 151 enum MHD_GNUTLS_HashAlgorithm mac);
152 152
153int mhd_gtls_mac_priority (mhd_gtls_session_t session, 153int MHD_gtls_mac_priority (MHD_gtls_session_t session,
154 enum MHD_GNUTLS_HashAlgorithm algorithm); 154 enum MHD_GNUTLS_HashAlgorithm algorithm);
155int mhd_gtls_cipher_priority (mhd_gtls_session_t session, 155int MHD_gtls_cipher_priority (MHD_gtls_session_t session,
156 enum MHD_GNUTLS_CipherAlgorithm algorithm); 156 enum MHD_GNUTLS_CipherAlgorithm algorithm);
157int mhd_gtls_kx_priority (mhd_gtls_session_t session, 157int MHD_gtls_kx_priority (MHD_gtls_session_t session,
158 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm); 158 enum MHD_GNUTLS_KeyExchangeAlgorithm algorithm);
159int mhd_gtls_compression_priority (mhd_gtls_session_t session, 159int MHD_gtls_compression_priority (MHD_gtls_session_t session,
160 enum MHD_GNUTLS_CompressionMethod 160 enum MHD_GNUTLS_CompressionMethod
161 algorithm); 161 algorithm);
162 162
diff --git a/src/daemon/https/tls/gnutls_anon_cred.c b/src/daemon/https/tls/gnutls_anon_cred.c
index 3ea9768d..665a0758 100644
--- a/src/daemon/https/tls/gnutls_anon_cred.c
+++ b/src/daemon/https/tls/gnutls_anon_cred.c
@@ -36,23 +36,23 @@
36static const int anon_dummy; 36static const int anon_dummy;
37 37
38/** 38/**
39 * MHD_gnutls_anon_free_server_credentials - Used to free an allocated mhd_gtls_anon_server_credentials_t structure 39 * MHD__gnutls_anon_free_server_credentials - Used to free an allocated MHD_gtls_anon_server_credentials_t structure
40 * @sc: is an #mhd_gtls_anon_server_credentials_t structure. 40 * @sc: is an #MHD_gtls_anon_server_credentials_t structure.
41 * 41 *
42 * This structure is complex enough to manipulate directly thus this 42 * This structure is complex enough to manipulate directly thus this
43 * helper function is provided in order to free (deallocate) it. 43 * helper function is provided in order to free (deallocate) it.
44 **/ 44 **/
45void 45void
46MHD_gnutls_anon_free_server_credentials (mhd_gtls_anon_server_credentials_t 46MHD__gnutls_anon_free_server_credentials (MHD_gtls_anon_server_credentials_t
47 sc) 47 sc)
48{ 48{
49 49
50 gnutls_free (sc); 50 MHD_gnutls_free (sc);
51} 51}
52 52
53/** 53/**
54 * MHD_gnutls_anon_allocate_server_credentials - Used to allocate an mhd_gtls_anon_server_credentials_t structure 54 * MHD__gnutls_anon_allocate_server_credentials - Used to allocate an MHD_gtls_anon_server_credentials_t structure
55 * @sc: is a pointer to an #mhd_gtls_anon_server_credentials_t structure. 55 * @sc: is a pointer to an #MHD_gtls_anon_server_credentials_t structure.
56 * 56 *
57 * This structure is complex enough to manipulate directly thus this 57 * This structure is complex enough to manipulate directly thus this
58 * helper function is provided in order to allocate it. 58 * helper function is provided in order to allocate it.
@@ -60,10 +60,10 @@ MHD_gnutls_anon_free_server_credentials (mhd_gtls_anon_server_credentials_t
60 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 60 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
61 **/ 61 **/
62int 62int
63 MHD_gnutls_anon_allocate_server_credentials 63 MHD__gnutls_anon_allocate_server_credentials
64 (mhd_gtls_anon_server_credentials_t * sc) 64 (MHD_gtls_anon_server_credentials_t * sc)
65{ 65{
66 *sc = gnutls_calloc (1, sizeof (mhd_anon_server_credentials_st)); 66 *sc = MHD_gnutls_calloc (1, sizeof (mhd_anon_server_credentials_st));
67 if (*sc == NULL) 67 if (*sc == NULL)
68 return GNUTLS_E_MEMORY_ERROR; 68 return GNUTLS_E_MEMORY_ERROR;
69 69
@@ -72,21 +72,21 @@ int
72 72
73 73
74/** 74/**
75 * MHD_gnutls_anon_free_client_credentials - Used to free an allocated mhd_gtls_anon_client_credentials_t structure 75 * MHD__gnutls_anon_free_client_credentials - Used to free an allocated MHD_gtls_anon_client_credentials_t structure
76 * @sc: is an #mhd_gtls_anon_client_credentials_t structure. 76 * @sc: is an #MHD_gtls_anon_client_credentials_t structure.
77 * 77 *
78 * This structure is complex enough to manipulate directly thus this 78 * This structure is complex enough to manipulate directly thus this
79 * helper function is provided in order to free (deallocate) it. 79 * helper function is provided in order to free (deallocate) it.
80 **/ 80 **/
81void 81void
82MHD_gnutls_anon_free_client_credentials (mhd_gtls_anon_client_credentials_t 82MHD__gnutls_anon_free_client_credentials (MHD_gtls_anon_client_credentials_t
83 sc) 83 sc)
84{ 84{
85} 85}
86 86
87/** 87/**
88 * MHD_gnutls_anon_allocate_client_credentials - Used to allocate a credentials structure 88 * MHD__gnutls_anon_allocate_client_credentials - Used to allocate a credentials structure
89 * @sc: is a pointer to an #mhd_gtls_anon_client_credentials_t structure. 89 * @sc: is a pointer to an #MHD_gtls_anon_client_credentials_t structure.
90 * 90 *
91 * This structure is complex enough to manipulate directly thus 91 * This structure is complex enough to manipulate directly thus
92 * this helper function is provided in order to allocate it. 92 * this helper function is provided in order to allocate it.
@@ -94,8 +94,8 @@ MHD_gnutls_anon_free_client_credentials (mhd_gtls_anon_client_credentials_t
94 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 94 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
95 **/ 95 **/
96int 96int
97 MHD_gnutls_anon_allocate_client_credentials 97 MHD__gnutls_anon_allocate_client_credentials
98 (mhd_gtls_anon_client_credentials_t * sc) 98 (MHD_gtls_anon_client_credentials_t * sc)
99{ 99{
100 /* anon_dummy is only there for *sc not to be null. 100 /* anon_dummy is only there for *sc not to be null.
101 * it is not used at all; 101 * it is not used at all;
@@ -106,8 +106,8 @@ int
106} 106}
107 107
108/** 108/**
109 * MHD_gnutls_anon_set_server_dh_params - This function will set the DH parameters for a server to use 109 * MHD__gnutls_anon_set_server_dh_params - This function will set the DH parameters for a server to use
110 * @res: is a mhd_gtls_anon_server_credentials_t structure 110 * @res: is a MHD_gtls_anon_server_credentials_t structure
111 * @dh_params: is a structure that holds diffie hellman parameters. 111 * @dh_params: is a structure that holds diffie hellman parameters.
112 * 112 *
113 * This function will set the diffie hellman parameters for an 113 * This function will set the diffie hellman parameters for an
@@ -115,15 +115,15 @@ int
115 * Anonymous Diffie Hellman cipher suites. 115 * Anonymous Diffie Hellman cipher suites.
116 **/ 116 **/
117void 117void
118MHD_gnutls_anon_set_server_dh_params (mhd_gtls_anon_server_credentials_t res, 118MHD__gnutls_anon_set_server_dh_params (MHD_gtls_anon_server_credentials_t res,
119 mhd_gtls_dh_params_t dh_params) 119 MHD_gtls_dh_params_t dh_params)
120{ 120{
121 res->dh_params = dh_params; 121 res->dh_params = dh_params;
122} 122}
123 123
124/** 124/**
125 * MHD_gnutls_anon_set_server_params_function - This function will set the DH parameters callback 125 * MHD__gnutls_anon_set_server_params_function - This function will set the DH parameters callback
126 * @res: is a mhd_gtls_cert_credentials_t structure 126 * @res: is a MHD_gtls_cert_credentials_t structure
127 * @func: is the function to be called 127 * @func: is the function to be called
128 * 128 *
129 * This function will set a callback in order for the server to get 129 * This function will set a callback in order for the server to get
@@ -131,9 +131,9 @@ MHD_gnutls_anon_set_server_dh_params (mhd_gtls_anon_server_credentials_t res,
131 * callback should return zero on success. 131 * callback should return zero on success.
132 **/ 132 **/
133void 133void
134MHD_gnutls_anon_set_server_params_function (mhd_gtls_anon_server_credentials_t 134MHD__gnutls_anon_set_server_params_function (MHD_gtls_anon_server_credentials_t
135 res, 135 res,
136 gnutls_params_function * func) 136 MHD_gnutls_params_function * func)
137{ 137{
138 res->params_func = func; 138 res->params_func = func;
139} 139}
diff --git a/src/daemon/https/tls/gnutls_asn1_tab.c b/src/daemon/https/tls/gnutls_asn1_tab.c
index b2139578..9b511521 100644
--- a/src/daemon/https/tls/gnutls_asn1_tab.c
+++ b/src/daemon/https/tls/gnutls_asn1_tab.c
@@ -4,7 +4,7 @@
4 4
5#include <libtasn1.h> 5#include <libtasn1.h>
6 6
7const ASN1_ARRAY_TYPE gnutls_asn1_tab[] = { 7const ASN1_ARRAY_TYPE MHD_gnutlsMHD__asn1_tab[] = {
8 {"GNUTLS", 536872976, 0}, 8 {"GNUTLS", 536872976, 0},
9 {0, 1073741836, 0}, 9 {0, 1073741836, 0},
10 {"RSAPublicKey", 1610612741, 0}, 10 {"RSAPublicKey", 1610612741, 0},
diff --git a/src/daemon/https/tls/gnutls_auth.c b/src/daemon/https/tls/gnutls_auth.c
index 1b805c10..b1e1abe7 100644
--- a/src/daemon/https/tls/gnutls_auth.c
+++ b/src/daemon/https/tls/gnutls_auth.c
@@ -37,14 +37,14 @@
37 */ 37 */
38 38
39/** 39/**
40 * MHD_gnutls_credentials_clear - Clears all the credentials previously set 40 * MHD__gnutls_credentials_clear - Clears all the credentials previously set
41 * @session: is a #mhd_gtls_session_t structure. 41 * @session: is a #MHD_gtls_session_t structure.
42 * 42 *
43 * Clears all the credentials previously set in this session. 43 * Clears all the credentials previously set in this session.
44 * 44 *
45 **/ 45 **/
46void 46void
47MHD_gnutls_credentials_clear (mhd_gtls_session_t session) 47MHD__gnutls_credentials_clear (MHD_gtls_session_t session)
48{ 48{
49 if (session->key && session->key->cred) 49 if (session->key && session->key->cred)
50 { /* beginning of the list */ 50 { /* beginning of the list */
@@ -53,7 +53,7 @@ MHD_gnutls_credentials_clear (mhd_gtls_session_t session)
53 while (ccred != NULL) 53 while (ccred != NULL)
54 { 54 {
55 ncred = ccred->next; 55 ncred = ccred->next;
56 gnutls_free (ccred); 56 MHD_gnutls_free (ccred);
57 ccred = ncred; 57 ccred = ncred;
58 } 58 }
59 session->key->cred = NULL; 59 session->key->cred = NULL;
@@ -65,8 +65,8 @@ MHD_gnutls_credentials_clear (mhd_gtls_session_t session)
65 * { algorithm, credentials, pointer to next } 65 * { algorithm, credentials, pointer to next }
66 */ 66 */
67/** 67/**
68 * MHD_gnutls_credentials_set - Sets the needed credentials for the specified authentication algorithm. 68 * MHD__gnutls_credentials_set - Sets the needed credentials for the specified authentication algorithm.
69 * @session: is a #mhd_gtls_session_t structure. 69 * @session: is a #MHD_gtls_session_t structure.
70 * @type: is the type of the credentials 70 * @type: is the type of the credentials
71 * @cred: is a pointer to a structure. 71 * @cred: is a pointer to a structure.
72 * 72 *
@@ -77,20 +77,20 @@ MHD_gnutls_credentials_clear (mhd_gtls_session_t session)
77 * [ In order to minimize memory usage, and share credentials between 77 * [ In order to minimize memory usage, and share credentials between
78 * several threads gnutls keeps a pointer to cred, and not the whole cred 78 * several threads gnutls keeps a pointer to cred, and not the whole cred
79 * structure. Thus you will have to keep the structure allocated until 79 * structure. Thus you will have to keep the structure allocated until
80 * you call MHD_gnutls_deinit(). ] 80 * you call MHD__gnutls_deinit(). ]
81 * 81 *
82 * For GNUTLS_CRD_ANON cred should be mhd_gtls_anon_client_credentials_t in case of a client. 82 * For GNUTLS_CRD_ANON cred should be MHD_gtls_anon_client_credentials_t in case of a client.
83 * In case of a server it should be mhd_gtls_anon_server_credentials_t. 83 * In case of a server it should be MHD_gtls_anon_server_credentials_t.
84 * 84 *
85 * For GNUTLS_CRD_SRP cred should be gnutls_srp_client_credentials_t 85 * For GNUTLS_CRD_SRP cred should be MHD_gnutls_srp_client_credentials_t
86 * in case of a client, and gnutls_srp_server_credentials_t, in case 86 * in case of a client, and MHD_gnutls_srp_server_credentials_t, in case
87 * of a server. 87 * of a server.
88 * 88 *
89 * For GNUTLS_CRD_CERTIFICATE cred should be mhd_gtls_cert_credentials_t. 89 * For GNUTLS_CRD_CERTIFICATE cred should be MHD_gtls_cert_credentials_t.
90 * 90 *
91 **/ 91 **/
92int 92int
93MHD_gnutls_credentials_set (mhd_gtls_session_t session, 93MHD__gnutls_credentials_set (MHD_gtls_session_t session,
94 enum MHD_GNUTLS_CredentialsType type, void *cred) 94 enum MHD_GNUTLS_CredentialsType type, void *cred)
95{ 95{
96 auth_cred_st *ccred = NULL, *pcred = NULL; 96 auth_cred_st *ccred = NULL, *pcred = NULL;
@@ -99,7 +99,7 @@ MHD_gnutls_credentials_set (mhd_gtls_session_t session,
99 if (session->key->cred == NULL) 99 if (session->key->cred == NULL)
100 { /* beginning of the list */ 100 { /* beginning of the list */
101 101
102 session->key->cred = gnutls_malloc (sizeof (auth_cred_st)); 102 session->key->cred = MHD_gnutls_malloc (sizeof (auth_cred_st));
103 if (session->key->cred == NULL) 103 if (session->key->cred == NULL)
104 return GNUTLS_E_MEMORY_ERROR; 104 return GNUTLS_E_MEMORY_ERROR;
105 105
@@ -127,7 +127,7 @@ MHD_gnutls_credentials_set (mhd_gtls_session_t session,
127 127
128 if (exists == 0) 128 if (exists == 0)
129 { /* new entry */ 129 { /* new entry */
130 pcred->next = gnutls_malloc (sizeof (auth_cred_st)); 130 pcred->next = MHD_gnutls_malloc (sizeof (auth_cred_st));
131 if (pcred->next == NULL) 131 if (pcred->next == NULL)
132 return GNUTLS_E_MEMORY_ERROR; 132 return GNUTLS_E_MEMORY_ERROR;
133 133
@@ -141,7 +141,7 @@ MHD_gnutls_credentials_set (mhd_gtls_session_t session,
141 } 141 }
142 else 142 else
143 { /* modify existing entry */ 143 { /* modify existing entry */
144 gnutls_free (ccred->credentials); 144 MHD_gnutls_free (ccred->credentials);
145 ccred->credentials = cred; 145 ccred->credentials = cred;
146 } 146 }
147 } 147 }
@@ -151,7 +151,7 @@ MHD_gnutls_credentials_set (mhd_gtls_session_t session,
151 151
152/** 152/**
153 * MHD_gtls_auth_get_type - Returns the type of credentials for the current authentication schema. 153 * MHD_gtls_auth_get_type - Returns the type of credentials for the current authentication schema.
154 * @session: is a #mhd_gtls_session_t structure. 154 * @session: is a #MHD_gtls_session_t structure.
155 * 155 *
156 * Returns type of credentials for the current authentication schema. 156 * Returns type of credentials for the current authentication schema.
157 * The returned information is to be used to distinguish the function used 157 * The returned information is to be used to distinguish the function used
@@ -161,7 +161,7 @@ MHD_gnutls_credentials_set (mhd_gtls_session_t session,
161 * the same function are to be used to access the authentication data. 161 * the same function are to be used to access the authentication data.
162 **/ 162 **/
163enum MHD_GNUTLS_CredentialsType 163enum MHD_GNUTLS_CredentialsType
164MHD_gtls_auth_get_type (mhd_gtls_session_t session) 164MHD_gtls_auth_get_type (MHD_gtls_session_t session)
165{ 165{
166/* This is not the credentials we must set, but the authentication data 166/* This is not the credentials we must set, but the authentication data
167 * we get by the peer, so it should be reversed. 167 * we get by the peer, so it should be reversed.
@@ -169,14 +169,14 @@ MHD_gtls_auth_get_type (mhd_gtls_session_t session)
169 int server = session->security_parameters.entity == GNUTLS_SERVER ? 0 : 1; 169 int server = session->security_parameters.entity == GNUTLS_SERVER ? 0 : 1;
170 170
171 return 171 return
172 mhd_gtls_map_kx_get_cred (mhd_gtls_cipher_suite_get_kx_algo 172 MHD_gtls_map_kx_get_cred (MHD_gtls_cipher_suite_get_kx_algo
173 (&session->security_parameters. 173 (&session->security_parameters.
174 current_cipher_suite), server); 174 current_cipher_suite), server);
175} 175}
176 176
177/** 177/**
178 * MHD_gtls_auth_server_get_type - Returns the type of credentials for the server authentication schema. 178 * MHD_gtls_auth_server_get_type - Returns the type of credentials for the server authentication schema.
179 * @session: is a #mhd_gtls_session_t structure. 179 * @session: is a #MHD_gtls_session_t structure.
180 * 180 *
181 * Returns the type of credentials that were used for server authentication. 181 * Returns the type of credentials that were used for server authentication.
182 * The returned information is to be used to distinguish the function used 182 * The returned information is to be used to distinguish the function used
@@ -184,17 +184,17 @@ MHD_gtls_auth_get_type (mhd_gtls_session_t session)
184 * 184 *
185 **/ 185 **/
186enum MHD_GNUTLS_CredentialsType 186enum MHD_GNUTLS_CredentialsType
187MHD_gtls_auth_server_get_type (mhd_gtls_session_t session) 187MHD_gtls_auth_server_get_type (MHD_gtls_session_t session)
188{ 188{
189 return 189 return
190 mhd_gtls_map_kx_get_cred (mhd_gtls_cipher_suite_get_kx_algo 190 MHD_gtls_map_kx_get_cred (MHD_gtls_cipher_suite_get_kx_algo
191 (&session->security_parameters. 191 (&session->security_parameters.
192 current_cipher_suite), 1); 192 current_cipher_suite), 1);
193} 193}
194 194
195/** 195/**
196 * MHD_gtls_auth_client_get_type - Returns the type of credentials for the client authentication schema. 196 * MHD_gtls_auth_client_get_type - Returns the type of credentials for the client authentication schema.
197 * @session: is a #mhd_gtls_session_t structure. 197 * @session: is a #MHD_gtls_session_t structure.
198 * 198 *
199 * Returns the type of credentials that were used for client authentication. 199 * Returns the type of credentials that were used for client authentication.
200 * The returned information is to be used to distinguish the function used 200 * The returned information is to be used to distinguish the function used
@@ -202,10 +202,10 @@ MHD_gtls_auth_server_get_type (mhd_gtls_session_t session)
202 * 202 *
203 **/ 203 **/
204enum MHD_GNUTLS_CredentialsType 204enum MHD_GNUTLS_CredentialsType
205MHD_gtls_auth_client_get_type (mhd_gtls_session_t session) 205MHD_gtls_auth_client_get_type (MHD_gtls_session_t session)
206{ 206{
207 return 207 return
208 mhd_gtls_map_kx_get_cred (mhd_gtls_cipher_suite_get_kx_algo 208 MHD_gtls_map_kx_get_cred (MHD_gtls_cipher_suite_get_kx_algo
209 (&session->security_parameters. 209 (&session->security_parameters.
210 current_cipher_suite), 0); 210 current_cipher_suite), 0);
211} 211}
@@ -216,17 +216,17 @@ MHD_gtls_auth_client_get_type (mhd_gtls_session_t session)
216 * free that!!! 216 * free that!!!
217 */ 217 */
218const void * 218const void *
219mhd_gtls_get_kx_cred (mhd_gtls_session_t session, 219MHD_gtls_get_kx_cred (MHD_gtls_session_t session,
220 enum MHD_GNUTLS_KeyExchangeAlgorithm algo, int *err) 220 enum MHD_GNUTLS_KeyExchangeAlgorithm algo, int *err)
221{ 221{
222 int server = session->security_parameters.entity == GNUTLS_SERVER ? 1 : 0; 222 int server = session->security_parameters.entity == GNUTLS_SERVER ? 1 : 0;
223 223
224 return mhd_gtls_get_cred (session->key, 224 return MHD_gtls_get_cred (session->key,
225 mhd_gtls_map_kx_get_cred (algo, server), err); 225 MHD_gtls_map_kx_get_cred (algo, server), err);
226} 226}
227 227
228const void * 228const void *
229mhd_gtls_get_cred (mhd_gtls_key_st key, enum MHD_GNUTLS_CredentialsType type, 229MHD_gtls_get_cred (MHD_gtls_key_st key, enum MHD_GNUTLS_CredentialsType type,
230 int *err) 230 int *err)
231{ 231{
232 const void *retval = NULL; 232 const void *retval = NULL;
@@ -258,10 +258,10 @@ out:
258} 258}
259 259
260/*- 260/*-
261 * mhd_gtls_get_auth_info - Returns a pointer to authentication information. 261 * MHD_gtls_get_auth_info - Returns a pointer to authentication information.
262 * @session: is a #mhd_gtls_session_t structure. 262 * @session: is a #MHD_gtls_session_t structure.
263 * 263 *
264 * This function must be called after a succesful MHD_gnutls_handshake(). 264 * This function must be called after a succesful MHD__gnutls_handshake().
265 * Returns a pointer to authentication information. That information 265 * Returns a pointer to authentication information. That information
266 * is data obtained by the handshake protocol, the key exchange algorithm, 266 * is data obtained by the handshake protocol, the key exchange algorithm,
267 * and the TLS extensions messages. 267 * and the TLS extensions messages.
@@ -271,28 +271,28 @@ out:
271 * In case of GNUTLS_CRD_SRP returns a type of &srp_(server/client)_auth_info_t; 271 * In case of GNUTLS_CRD_SRP returns a type of &srp_(server/client)_auth_info_t;
272 -*/ 272 -*/
273void * 273void *
274mhd_gtls_get_auth_info (mhd_gtls_session_t session) 274MHD_gtls_get_auth_info (MHD_gtls_session_t session)
275{ 275{
276 return session->key->auth_info; 276 return session->key->auth_info;
277} 277}
278 278
279/*- 279/*-
280 * mhd_gtls_free_auth_info - Frees the auth info structure 280 * MHD_gtls_free_auth_info - Frees the auth info structure
281 * @session: is a #mhd_gtls_session_t structure. 281 * @session: is a #MHD_gtls_session_t structure.
282 * 282 *
283 * This function frees the auth info structure and sets it to 283 * This function frees the auth info structure and sets it to
284 * null. It must be called since some structures contain malloced 284 * null. It must be called since some structures contain malloced
285 * elements. 285 * elements.
286 -*/ 286 -*/
287void 287void
288mhd_gtls_free_auth_info (mhd_gtls_session_t session) 288MHD_gtls_free_auth_info (MHD_gtls_session_t session)
289{ 289{
290 mhd_gtls_dh_info_st *dh_info; 290 MHD_gtls_dh_info_st *dh_info;
291 rsa_info_st *rsa_info; 291 rsa_info_st *rsa_info;
292 292
293 if (session == NULL || session->key == NULL) 293 if (session == NULL || session->key == NULL)
294 { 294 {
295 gnutls_assert (); 295 MHD_gnutls_assert ();
296 return; 296 return;
297 } 297 }
298 298
@@ -302,19 +302,19 @@ mhd_gtls_free_auth_info (mhd_gtls_session_t session)
302 break; 302 break;
303 case MHD_GNUTLS_CRD_ANON: 303 case MHD_GNUTLS_CRD_ANON:
304 { 304 {
305 mhd_anon_auth_info_t info = mhd_gtls_get_auth_info (session); 305 mhd_anon_auth_info_t info = MHD_gtls_get_auth_info (session);
306 306
307 if (info == NULL) 307 if (info == NULL)
308 break; 308 break;
309 309
310 dh_info = &info->dh; 310 dh_info = &info->dh;
311 mhd_gtls_free_dh_info (dh_info); 311 MHD_gtls_free_dh_info (dh_info);
312 } 312 }
313 break; 313 break;
314 case MHD_GNUTLS_CRD_CERTIFICATE: 314 case MHD_GNUTLS_CRD_CERTIFICATE:
315 { 315 {
316 unsigned int i; 316 unsigned int i;
317 cert_auth_info_t info = mhd_gtls_get_auth_info (session); 317 cert_auth_info_t info = MHD_gtls_get_auth_info (session);
318 318
319 if (info == NULL) 319 if (info == NULL)
320 break; 320 break;
@@ -323,15 +323,15 @@ mhd_gtls_free_auth_info (mhd_gtls_session_t session)
323 rsa_info = &info->rsa_export; 323 rsa_info = &info->rsa_export;
324 for (i = 0; i < info->ncerts; i++) 324 for (i = 0; i < info->ncerts; i++)
325 { 325 {
326 _gnutls_free_datum (&info->raw_certificate_list[i]); 326 MHD__gnutls_free_datum (&info->raw_certificate_list[i]);
327 } 327 }
328 328
329 gnutls_free (info->raw_certificate_list); 329 MHD_gnutls_free (info->raw_certificate_list);
330 info->raw_certificate_list = NULL; 330 info->raw_certificate_list = NULL;
331 info->ncerts = 0; 331 info->ncerts = 0;
332 332
333 mhd_gtls_free_dh_info (dh_info); 333 MHD_gtls_free_dh_info (dh_info);
334 mhd_gtls_free_rsa_info (rsa_info); 334 MHD_gtls_free_rsa_info (rsa_info);
335 } 335 }
336 336
337 337
@@ -341,7 +341,7 @@ mhd_gtls_free_auth_info (mhd_gtls_session_t session)
341 341
342 } 342 }
343 343
344 gnutls_free (session->key->auth_info); 344 MHD_gnutls_free (session->key->auth_info);
345 session->key->auth_info = NULL; 345 session->key->auth_info = NULL;
346 session->key->auth_info_size = 0; 346 session->key->auth_info_size = 0;
347 session->key->auth_info_type = 0; 347 session->key->auth_info_type = 0;
@@ -354,16 +354,16 @@ mhd_gtls_free_auth_info (mhd_gtls_session_t session)
354 * info structure to a different type. 354 * info structure to a different type.
355 */ 355 */
356int 356int
357mhd_gtls_auth_info_set (mhd_gtls_session_t session, 357MHD_gtls_auth_info_set (MHD_gtls_session_t session,
358 enum MHD_GNUTLS_CredentialsType type, int size, 358 enum MHD_GNUTLS_CredentialsType type, int size,
359 int allow_change) 359 int allow_change)
360{ 360{
361 if (session->key->auth_info == NULL) 361 if (session->key->auth_info == NULL)
362 { 362 {
363 session->key->auth_info = gnutls_calloc (1, size); 363 session->key->auth_info = MHD_gnutls_calloc (1, size);
364 if (session->key->auth_info == NULL) 364 if (session->key->auth_info == NULL)
365 { 365 {
366 gnutls_assert (); 366 MHD_gnutls_assert ();
367 return GNUTLS_E_MEMORY_ERROR; 367 return GNUTLS_E_MEMORY_ERROR;
368 } 368 }
369 session->key->auth_info_type = type; 369 session->key->auth_info_type = type;
@@ -382,7 +382,7 @@ mhd_gtls_auth_info_set (mhd_gtls_session_t session,
382 if (MHD_gtls_auth_get_type (session) != 382 if (MHD_gtls_auth_get_type (session) !=
383 session->key->auth_info_type) 383 session->key->auth_info_type)
384 { 384 {
385 gnutls_assert (); 385 MHD_gnutls_assert ();
386 return GNUTLS_E_INVALID_REQUEST; 386 return GNUTLS_E_INVALID_REQUEST;
387 } 387 }
388 } 388 }
@@ -398,12 +398,12 @@ mhd_gtls_auth_info_set (mhd_gtls_session_t session,
398 session->key->auth_info_type) 398 session->key->auth_info_type)
399 { 399 {
400 400
401 mhd_gtls_free_auth_info (session); 401 MHD_gtls_free_auth_info (session);
402 402
403 session->key->auth_info = calloc (1, size); 403 session->key->auth_info = calloc (1, size);
404 if (session->key->auth_info == NULL) 404 if (session->key->auth_info == NULL)
405 { 405 {
406 gnutls_assert (); 406 MHD_gnutls_assert ();
407 return GNUTLS_E_MEMORY_ERROR; 407 return GNUTLS_E_MEMORY_ERROR;
408 } 408 }
409 409
diff --git a/src/daemon/https/tls/gnutls_auth.h b/src/daemon/https/tls/gnutls_auth.h
index a29a1faa..4956268c 100644
--- a/src/daemon/https/tls/gnutls_auth.h
+++ b/src/daemon/https/tls/gnutls_auth.h
@@ -25,27 +25,27 @@
25#ifndef GNUTLS_AUTH_H 25#ifndef GNUTLS_AUTH_H
26#define GNUTLS_AUTH_H 26#define GNUTLS_AUTH_H
27 27
28typedef struct mhd_gtls_mod_auth_st_int 28typedef struct MHD_gtls_mod_auth_st_int
29{ 29{
30 const char *name; /* null terminated */ 30 const char *name; /* null terminated */
31 int (*mhd_gtls_gen_server_certificate) (mhd_gtls_session_t, opaque **); 31 int (*MHD_gtls_gen_server_certificate) (MHD_gtls_session_t, opaque **);
32 int (*mhd_gtls_gen_client_certificate) (mhd_gtls_session_t, opaque **); 32 int (*MHD_gtls_gen_client_certificate) (MHD_gtls_session_t, opaque **);
33 int (*mhd_gtls_gen_server_kx) (mhd_gtls_session_t, opaque **); 33 int (*MHD_gtls_gen_server_kx) (MHD_gtls_session_t, opaque **);
34 int (*mhd_gtls_gen_client_kx) (mhd_gtls_session_t, opaque **); /* used in SRP */ 34 int (*MHD_gtls_gen_client_kx) (MHD_gtls_session_t, opaque **); /* used in SRP */
35 int (*mhd_gtls_gen_client_cert_vrfy) (mhd_gtls_session_t, opaque **); 35 int (*MHD_gtls_gen_client_cert_vrfy) (MHD_gtls_session_t, opaque **);
36 int (*mhd_gtls_gen_server_certificate_request) (mhd_gtls_session_t, 36 int (*MHD_gtls_gen_server_certificate_request) (MHD_gtls_session_t,
37 opaque **); 37 opaque **);
38 38
39 int (*mhd_gtls_process_server_certificate) (mhd_gtls_session_t, opaque *, 39 int (*MHD_gtls_process_server_certificate) (MHD_gtls_session_t, opaque *,
40 size_t); 40 size_t);
41 int (*mhd_gtls_process_client_certificate) (mhd_gtls_session_t, opaque *, 41 int (*MHD_gtls_process_client_certificate) (MHD_gtls_session_t, opaque *,
42 size_t); 42 size_t);
43 int (*mhd_gtls_process_server_kx) (mhd_gtls_session_t, opaque *, size_t); 43 int (*MHD_gtls_process_server_kx) (MHD_gtls_session_t, opaque *, size_t);
44 int (*mhd_gtls_process_client_kx) (mhd_gtls_session_t, opaque *, size_t); 44 int (*MHD_gtls_process_client_kx) (MHD_gtls_session_t, opaque *, size_t);
45 int (*mhd_gtls_process_client_cert_vrfy) (mhd_gtls_session_t, opaque *, 45 int (*MHD_gtls_process_client_cert_vrfy) (MHD_gtls_session_t, opaque *,
46 size_t); 46 size_t);
47 int (*mhd_gtls_process_server_certificate_request) (mhd_gtls_session_t, 47 int (*MHD_gtls_process_server_certificate_request) (MHD_gtls_session_t,
48 opaque *, size_t); 48 opaque *, size_t);
49} mhd_gtls_mod_auth_st; 49} MHD_gtls_mod_auth_st;
50 50
51#endif 51#endif
diff --git a/src/daemon/https/tls/gnutls_auth_int.h b/src/daemon/https/tls/gnutls_auth_int.h
index ac821277..425dc8a3 100644
--- a/src/daemon/https/tls/gnutls_auth_int.h
+++ b/src/daemon/https/tls/gnutls_auth_int.h
@@ -22,12 +22,12 @@
22 * 22 *
23 */ 23 */
24 24
25const void *mhd_gtls_get_cred (mhd_gtls_key_st key, 25const void *MHD_gtls_get_cred (MHD_gtls_key_st key,
26 enum MHD_GNUTLS_CredentialsType kx, int *err); 26 enum MHD_GNUTLS_CredentialsType kx, int *err);
27const void *mhd_gtls_get_kx_cred (mhd_gtls_session_t session, 27const void *MHD_gtls_get_kx_cred (MHD_gtls_session_t session,
28 enum MHD_GNUTLS_KeyExchangeAlgorithm algo, 28 enum MHD_GNUTLS_KeyExchangeAlgorithm algo,
29 int *err); 29 int *err);
30void *mhd_gtls_get_auth_info (mhd_gtls_session_t session); 30void *MHD_gtls_get_auth_info (MHD_gtls_session_t session);
31int mhd_gtls_auth_info_set (mhd_gtls_session_t session, 31int MHD_gtls_auth_info_set (MHD_gtls_session_t session,
32 enum MHD_GNUTLS_CredentialsType type, int size, 32 enum MHD_GNUTLS_CredentialsType type, int size,
33 int allow_change); 33 int allow_change);
diff --git a/src/daemon/https/tls/gnutls_buffers.c b/src/daemon/https/tls/gnutls_buffers.c
index 5ea95e5f..0a0f367b 100644
--- a/src/daemon/https/tls/gnutls_buffers.c
+++ b/src/daemon/https/tls/gnutls_buffers.c
@@ -30,20 +30,20 @@
30 * RECORD LAYER: 30 * RECORD LAYER:
31 * 1. uses a buffer to hold data (application/handshake), 31 * 1. uses a buffer to hold data (application/handshake),
32 * we got but they were not requested, yet. 32 * we got but they were not requested, yet.
33 * (see gnutls_record_buffer_put(), gnutls_record_buffer_get_size() etc.) 33 * (see MHD_gnutls_record_buffer_put(), MHD_gnutls_record_buffer_get_size() etc.)
34 * 34 *
35 * 2. uses a buffer to hold data that were incomplete (ie the read/write 35 * 2. uses a buffer to hold data that were incomplete (ie the read/write
36 * was interrupted) 36 * was interrupted)
37 * (see mhd_gtls_io_read_buffered(), mhd_gtls_io_write_buffered() etc.) 37 * (see MHD_gtls_io_read_buffered(), MHD_gtls_io_write_buffered() etc.)
38 * 38 *
39 * HANDSHAKE LAYER: 39 * HANDSHAKE LAYER:
40 * 1. Uses a buffer to hold data that was not sent or received 40 * 1. Uses a buffer to hold data that was not sent or received
41 * complete. (E.g. sent 10 bytes of a handshake packet that is 20 bytes 41 * complete. (E.g. sent 10 bytes of a handshake packet that is 20 bytes
42 * long). 42 * long).
43 * (see _gnutls_handshake_send_int(), _gnutls_handshake_recv_int()) 43 * (see MHD__gnutls_handshake_send_int(), MHD__gnutls_handshake_recv_int())
44 * 44 *
45 * 2. Uses buffer to hold the last received handshake message. 45 * 2. Uses buffer to hold the last received handshake message.
46 * (see mhd_gtls_handshake_buffer_put() etc.) 46 * (see MHD_gtls_handshake_buffer_put() etc.)
47 * 47 *
48 */ 48 */
49 49
@@ -68,8 +68,8 @@
68#endif 68#endif
69 69
70/** 70/**
71 * MHD_gnutls_transport_set_errno: 71 * MHD__gnutls_transport_set_errno:
72 * @session: is a #mhd_gtls_session_t structure. 72 * @session: is a #MHD_gtls_session_t structure.
73 * @err: error value to store in session-specific errno variable. 73 * @err: error value to store in session-specific errno variable.
74 * 74 *
75 * Store @err in the session-specific errno variable. Useful values 75 * Store @err in the session-specific errno variable. Useful values
@@ -77,24 +77,24 @@
77 * treated as real errors in the push/pull function. 77 * treated as real errors in the push/pull function.
78 * 78 *
79 * This function is useful in replacement push/pull functions set by 79 * This function is useful in replacement push/pull functions set by
80 * MHD_gnutls_transport_set_push_function and 80 * MHD__gnutls_transport_set_push_function and
81 * gnutls_transport_set_pullpush_function under Windows, where the 81 * MHD_gnutls_transport_set_pullpush_function under Windows, where the
82 * replacement push/pull may not have access to the same @errno 82 * replacement push/pull may not have access to the same @errno
83 * variable that is used by GnuTLS (e.g., the application is linked to 83 * variable that is used by GnuTLS (e.g., the application is linked to
84 * msvcr71.dll and gnutls is linked to msvcrt.dll). 84 * msvcr71.dll and gnutls is linked to msvcrt.dll).
85 * 85 *
86 * If you don't have the @session variable easily accessible from the 86 * If you don't have the @session variable easily accessible from the
87 * push/pull function, and don't worry about thread conflicts, you can 87 * push/pull function, and don't worry about thread conflicts, you can
88 * also use MHD_gnutls_transport_set_global_errno(). 88 * also use MHD__gnutls_transport_set_global_errno().
89 **/ 89 **/
90void 90void
91MHD_gnutls_transport_set_errno (mhd_gtls_session_t session, int err) 91MHD__gnutls_transport_set_errno (MHD_gtls_session_t session, int err)
92{ 92{
93 session->internals.errnum = err; 93 session->internals.errnum = err;
94} 94}
95 95
96/** 96/**
97 * MHD_gnutls_transport_set_global_errno: 97 * MHD__gnutls_transport_set_global_errno:
98 * @err: error value to store in global errno variable. 98 * @err: error value to store in global errno variable.
99 * 99 *
100 * Store @err in the global errno variable. Useful values for @err is 100 * Store @err in the global errno variable. Useful values for @err is
@@ -102,8 +102,8 @@ MHD_gnutls_transport_set_errno (mhd_gtls_session_t session, int err)
102 * errors in the push/pull function. 102 * errors in the push/pull function.
103 * 103 *
104 * This function is useful in replacement push/pull functions set by 104 * This function is useful in replacement push/pull functions set by
105 * MHD_gnutls_transport_set_push_function and 105 * MHD__gnutls_transport_set_push_function and
106 * gnutls_transport_set_pullpush_function under Windows, where the 106 * MHD_gnutls_transport_set_pullpush_function under Windows, where the
107 * replacement push/pull may not have access to the same @errno 107 * replacement push/pull may not have access to the same @errno
108 * variable that is used by GnuTLS (e.g., the application is linked to 108 * variable that is used by GnuTLS (e.g., the application is linked to
109 * msvcr71.dll and gnutls is linked to msvcrt.dll). 109 * msvcr71.dll and gnutls is linked to msvcrt.dll).
@@ -111,10 +111,10 @@ MHD_gnutls_transport_set_errno (mhd_gtls_session_t session, int err)
111 * Whether this function is thread safe or not depends on whether the 111 * Whether this function is thread safe or not depends on whether the
112 * global variable errno is thread safe, some system libraries make it 112 * global variable errno is thread safe, some system libraries make it
113 * a thread-local variable. When feasible, using the guaranteed 113 * a thread-local variable. When feasible, using the guaranteed
114 * thread-safe MHD_gnutls_transport_set_errno() may be better. 114 * thread-safe MHD__gnutls_transport_set_errno() may be better.
115 **/ 115 **/
116void 116void
117MHD_gnutls_transport_set_global_errno (int err) 117MHD__gnutls_transport_set_global_errno (int err)
118{ 118{
119 errno = err; 119 errno = err;
120} 120}
@@ -123,11 +123,11 @@ MHD_gnutls_transport_set_global_errno (int err)
123 * HANDSHAKE DATA. 123 * HANDSHAKE DATA.
124 */ 124 */
125int 125int
126mhd_gnutls_record_buffer_put (content_type_t type, 126MHD_gnutls_record_buffer_put (content_type_t type,
127 mhd_gtls_session_t session, opaque * data, 127 MHD_gtls_session_t session, opaque * data,
128 size_t length) 128 size_t length)
129{ 129{
130 mhd_gtls_buffer *buf; 130 MHD_gtls_buffer *buf;
131 131
132 if (length == 0) 132 if (length == 0)
133 return 0; 133 return 0;
@@ -136,30 +136,30 @@ mhd_gnutls_record_buffer_put (content_type_t type,
136 { 136 {
137 case GNUTLS_APPLICATION_DATA: 137 case GNUTLS_APPLICATION_DATA:
138 buf = &session->internals.application_data_buffer; 138 buf = &session->internals.application_data_buffer;
139 _gnutls_buffers_log ("BUF[REC]: Inserted %d bytes of Data(%d)\n", 139 MHD__gnutls_buffers_log ("BUF[REC]: Inserted %d bytes of Data(%d)\n",
140 length, type); 140 length, type);
141 break; 141 break;
142 142
143 case GNUTLS_HANDSHAKE: 143 case GNUTLS_HANDSHAKE:
144 buf = &session->internals.handshake_data_buffer; 144 buf = &session->internals.handshake_data_buffer;
145 _gnutls_buffers_log ("BUF[HSK]: Inserted %d bytes of Data(%d)\n", 145 MHD__gnutls_buffers_log ("BUF[HSK]: Inserted %d bytes of Data(%d)\n",
146 length, type); 146 length, type);
147 break; 147 break;
148 148
149 case GNUTLS_INNER_APPLICATION: 149 case GNUTLS_INNER_APPLICATION:
150 buf = &session->internals.ia_data_buffer; 150 buf = &session->internals.ia_data_buffer;
151 _gnutls_buffers_log ("BUF[IA]: Inserted %d bytes of Data(%d)\n", length, 151 MHD__gnutls_buffers_log ("BUF[IA]: Inserted %d bytes of Data(%d)\n", length,
152 type); 152 type);
153 break; 153 break;
154 154
155 default: 155 default:
156 gnutls_assert (); 156 MHD_gnutls_assert ();
157 return GNUTLS_E_INVALID_REQUEST; 157 return GNUTLS_E_INVALID_REQUEST;
158 } 158 }
159 159
160 if (mhd_gtls_buffer_append (buf, data, length) < 0) 160 if (MHD_gtls_buffer_append (buf, data, length) < 0)
161 { 161 {
162 gnutls_assert (); 162 MHD_gnutls_assert ();
163 return GNUTLS_E_MEMORY_ERROR; 163 return GNUTLS_E_MEMORY_ERROR;
164 } 164 }
165 165
@@ -167,8 +167,8 @@ mhd_gnutls_record_buffer_put (content_type_t type,
167} 167}
168 168
169int 169int
170mhd_gnutls_record_buffer_get_size (content_type_t type, 170MHD_gnutls_record_buffer_get_size (content_type_t type,
171 mhd_gtls_session_t session) 171 MHD_gtls_session_t session)
172{ 172{
173 switch (type) 173 switch (type)
174 { 174 {
@@ -188,7 +188,7 @@ mhd_gnutls_record_buffer_get_size (content_type_t type,
188 188
189/** 189/**
190 * MHD_gtls_record_check_pending - checks if there are any data to receive in gnutls buffers. 190 * MHD_gtls_record_check_pending - checks if there are any data to receive in gnutls buffers.
191 * @session: is a #mhd_gtls_session_t structure. 191 * @session: is a #MHD_gtls_session_t structure.
192 * 192 *
193 * This function checks if there are any data to receive 193 * This function checks if there are any data to receive
194 * in the gnutls buffers. Returns the size of that data or 0. 194 * in the gnutls buffers. Returns the size of that data or 0.
@@ -198,18 +198,18 @@ mhd_gnutls_record_buffer_get_size (content_type_t type,
198 * to work). 198 * to work).
199 **/ 199 **/
200size_t 200size_t
201MHD_gtls_record_check_pending (mhd_gtls_session_t session) 201MHD_gtls_record_check_pending (MHD_gtls_session_t session)
202{ 202{
203 return mhd_gnutls_record_buffer_get_size (GNUTLS_APPLICATION_DATA, session); 203 return MHD_gnutls_record_buffer_get_size (GNUTLS_APPLICATION_DATA, session);
204} 204}
205 205
206int 206int
207mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session, 207MHD_gtls_record_buffer_get (content_type_t type, MHD_gtls_session_t session,
208 opaque * data, size_t length) 208 opaque * data, size_t length)
209{ 209{
210 if (length == 0 || data == NULL) 210 if (length == 0 || data == NULL)
211 { 211 {
212 gnutls_assert (); 212 MHD_gnutls_assert ();
213 return GNUTLS_E_INVALID_REQUEST; 213 return GNUTLS_E_INVALID_REQUEST;
214 } 214 }
215 215
@@ -222,7 +222,7 @@ mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session,
222 length = session->internals.application_data_buffer.length; 222 length = session->internals.application_data_buffer.length;
223 } 223 }
224 224
225 _gnutls_buffers_log ("BUFFER[REC][AD]: Read %d bytes of Data(%d)\n", 225 MHD__gnutls_buffers_log ("BUFFER[REC][AD]: Read %d bytes of Data(%d)\n",
226 length, type); 226 length, type);
227 227
228 session->internals.application_data_buffer.length -= length; 228 session->internals.application_data_buffer.length -= length;
@@ -245,7 +245,7 @@ mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session,
245 length = session->internals.handshake_data_buffer.length; 245 length = session->internals.handshake_data_buffer.length;
246 } 246 }
247 247
248 _gnutls_buffers_log ("BUF[REC][HD]: Read %d bytes of Data(%d)\n", 248 MHD__gnutls_buffers_log ("BUF[REC][HD]: Read %d bytes of Data(%d)\n",
249 length, type); 249 length, type);
250 250
251 session->internals.handshake_data_buffer.length -= length; 251 session->internals.handshake_data_buffer.length -= length;
@@ -262,7 +262,7 @@ mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session,
262 if (length > session->internals.ia_data_buffer.length) 262 if (length > session->internals.ia_data_buffer.length)
263 length = session->internals.ia_data_buffer.length; 263 length = session->internals.ia_data_buffer.length;
264 264
265 _gnutls_buffers_log ("BUF[REC][IA]: Read %d bytes of Data(%d)\n", 265 MHD__gnutls_buffers_log ("BUF[REC][IA]: Read %d bytes of Data(%d)\n",
266 length, type); 266 length, type);
267 267
268 session->internals.ia_data_buffer.length -= length; 268 session->internals.ia_data_buffer.length -= length;
@@ -276,7 +276,7 @@ mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session,
276 break; 276 break;
277 277
278 default: 278 default:
279 gnutls_assert (); 279 MHD_gnutls_assert ();
280 return GNUTLS_E_INVALID_REQUEST; 280 return GNUTLS_E_INVALID_REQUEST;
281 } 281 }
282 282
@@ -284,19 +284,19 @@ mhd_gtls_record_buffer_get (content_type_t type, mhd_gtls_session_t session,
284} 284}
285 285
286/* This function is like read. But it does not return -1 on error. 286/* This function is like read. But it does not return -1 on error.
287 * It does return gnutls_errno instead. 287 * It does return MHD_gnutls_errno instead.
288 * 288 *
289 * Flags are only used if the default recv() function is being used. 289 * Flags are only used if the default recv() function is being used.
290 */ 290 */
291static ssize_t 291static ssize_t
292_gnutls_read (mhd_gtls_session_t session, void *iptr, 292MHD__gnutls_read (MHD_gtls_session_t session, void *iptr,
293 size_t sizeOfPtr, int flags) 293 size_t sizeOfPtr, int flags)
294{ 294{
295 size_t left; 295 size_t left;
296 ssize_t i = 0; 296 ssize_t i = 0;
297 char *ptr = iptr; 297 char *ptr = iptr;
298 unsigned j, x, sum = 0; 298 unsigned j, x, sum = 0;
299 gnutls_transport_ptr_t fd = session->internals.transport_recv_ptr; 299 MHD_gnutls_transport_ptr_t fd = session->internals.transport_recv_ptr;
300 300
301 session->internals.direction = 0; 301 session->internals.direction = 0;
302 302
@@ -304,7 +304,7 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
304 while (left > 0) 304 while (left > 0)
305 { 305 {
306 session->internals.errnum = 0; 306 session->internals.errnum = 0;
307 if (session->internals._gnutls_pull_func == NULL) 307 if (session->internals.MHD__gnutls_pull_func == NULL)
308 { 308 {
309 i = 309 i =
310 recv (GNUTLS_POINTER_TO_INT (fd), &ptr[sizeOfPtr - left], left, 310 recv (GNUTLS_POINTER_TO_INT (fd), &ptr[sizeOfPtr - left], left,
@@ -332,7 +332,7 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
332#endif 332#endif
333 } 333 }
334 else 334 else
335 i = session->internals._gnutls_pull_func (fd, 335 i = session->internals.MHD__gnutls_pull_func (fd,
336 &ptr[sizeOfPtr - left], 336 &ptr[sizeOfPtr - left],
337 left); 337 left);
338 338
@@ -341,7 +341,7 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
341 int err = session->internals.errnum ? session->internals.errnum 341 int err = session->internals.errnum ? session->internals.errnum
342 : errno; 342 : errno;
343 343
344 _gnutls_read_log ("READ: %d returned from %d, errno=%d gerrno=%d\n", 344 MHD__gnutls_read_log ("READ: %d returned from %d, errno=%d gerrno=%d\n",
345 i, fd, errno, session->internals.errnum); 345 i, fd, errno, session->internals.errnum);
346 346
347 if (err == EAGAIN || err == EINTR) 347 if (err == EAGAIN || err == EINTR)
@@ -349,12 +349,12 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
349 if (sizeOfPtr - left > 0) 349 if (sizeOfPtr - left > 0)
350 { 350 {
351 351
352 _gnutls_read_log ("READ: returning %d bytes from %d\n", 352 MHD__gnutls_read_log ("READ: returning %d bytes from %d\n",
353 sizeOfPtr - left, fd); 353 sizeOfPtr - left, fd);
354 354
355 goto finish; 355 goto finish;
356 } 356 }
357 gnutls_assert (); 357 MHD_gnutls_assert ();
358 358
359 if (err == EAGAIN) 359 if (err == EAGAIN)
360 return GNUTLS_E_AGAIN; 360 return GNUTLS_E_AGAIN;
@@ -362,14 +362,14 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
362 } 362 }
363 else 363 else
364 { 364 {
365 gnutls_assert (); 365 MHD_gnutls_assert ();
366 return GNUTLS_E_PULL_ERROR; 366 return GNUTLS_E_PULL_ERROR;
367 } 367 }
368 } 368 }
369 else 369 else
370 { 370 {
371 371
372 _gnutls_read_log ("READ: Got %d bytes from %d\n", i, fd); 372 MHD__gnutls_read_log ("READ: Got %d bytes from %d\n", i, fd);
373 373
374 if (i == 0) 374 if (i == 0)
375 break; /* EOF */ 375 break; /* EOF */
@@ -381,12 +381,12 @@ _gnutls_read (mhd_gtls_session_t session, void *iptr,
381 381
382finish: 382finish:
383 383
384 if (_gnutls_log_level >= 7) 384 if (MHD__gnutls_log_level >= 7)
385 { 385 {
386 char line[128]; 386 char line[128];
387 char tmp[16]; 387 char tmp[16];
388 388
389 _gnutls_read_log ("READ: read %d bytes from %d\n", (sizeOfPtr - left), 389 MHD__gnutls_read_log ("READ: read %d bytes from %d\n", (sizeOfPtr - left),
390 fd); 390 fd);
391 391
392 for (x = 0; x < ((sizeOfPtr - left) / 16) + 1; x++) 392 for (x = 0; x < ((sizeOfPtr - left) / 16) + 1; x++)
@@ -394,17 +394,17 @@ finish:
394 line[0] = 0; 394 line[0] = 0;
395 395
396 sprintf (tmp, "%.4x - ", x); 396 sprintf (tmp, "%.4x - ", x);
397 mhd_gtls_str_cat (line, sizeof (line), tmp); 397 MHD_gtls_str_cat (line, sizeof (line), tmp);
398 398
399 for (j = 0; j < 16; j++) 399 for (j = 0; j < 16; j++)
400 { 400 {
401 if (sum < (sizeOfPtr - left)) 401 if (sum < (sizeOfPtr - left))
402 { 402 {
403 sprintf (tmp, "%.2x ", ((unsigned char *) ptr)[sum++]); 403 sprintf (tmp, "%.2x ", ((unsigned char *) ptr)[sum++]);
404 mhd_gtls_str_cat (line, sizeof (line), tmp); 404 MHD_gtls_str_cat (line, sizeof (line), tmp);
405 } 405 }
406 } 406 }
407 _gnutls_read_log ("%s\n", line); 407 MHD__gnutls_read_log ("%s\n", line);
408 } 408 }
409 } 409 }
410 410
@@ -417,7 +417,7 @@ finish:
417 * Clears the peeked data (read with MSG_PEEK). 417 * Clears the peeked data (read with MSG_PEEK).
418 */ 418 */
419int 419int
420mhd_gtls_io_clear_peeked_data (mhd_gtls_session_t session) 420MHD_gtls_io_clear_peeked_data (MHD_gtls_session_t session)
421{ 421{
422 char *peekdata; 422 char *peekdata;
423 int ret, sum; 423 int ret, sum;
@@ -425,10 +425,10 @@ mhd_gtls_io_clear_peeked_data (mhd_gtls_session_t session)
425 if (session->internals.have_peeked_data == 0 || RCVLOWAT == 0) 425 if (session->internals.have_peeked_data == 0 || RCVLOWAT == 0)
426 return 0; 426 return 0;
427 427
428 peekdata = gnutls_alloca (RCVLOWAT); 428 peekdata = MHD_gnutls_alloca (RCVLOWAT);
429 if (peekdata == NULL) 429 if (peekdata == NULL)
430 { 430 {
431 gnutls_assert (); 431 MHD_gnutls_assert ();
432 return GNUTLS_E_MEMORY_ERROR; 432 return GNUTLS_E_MEMORY_ERROR;
433 } 433 }
434 434
@@ -436,18 +436,18 @@ mhd_gtls_io_clear_peeked_data (mhd_gtls_session_t session)
436 sum = 0; 436 sum = 0;
437 do 437 do
438 { /* we need this to finish now */ 438 { /* we need this to finish now */
439 ret = _gnutls_read (session, peekdata, RCVLOWAT - sum, 0); 439 ret = MHD__gnutls_read (session, peekdata, RCVLOWAT - sum, 0);
440 if (ret > 0) 440 if (ret > 0)
441 sum += ret; 441 sum += ret;
442 } 442 }
443 while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN || sum 443 while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN || sum
444 < RCVLOWAT); 444 < RCVLOWAT);
445 445
446 gnutls_afree (peekdata); 446 MHD_gnutls_afree (peekdata);
447 447
448 if (ret < 0) 448 if (ret < 0)
449 { 449 {
450 gnutls_assert (); 450 MHD_gnutls_assert ();
451 return ret; 451 return ret;
452 } 452 }
453 453
@@ -457,13 +457,13 @@ mhd_gtls_io_clear_peeked_data (mhd_gtls_session_t session)
457} 457}
458 458
459void 459void
460mhd_gtls_io_clear_read_buffer (mhd_gtls_session_t session) 460MHD_gtls_io_clear_read_buffer (MHD_gtls_session_t session)
461{ 461{
462 session->internals.record_recv_buffer.length = 0; 462 session->internals.record_recv_buffer.length = 0;
463} 463}
464 464
465/* This function is like recv(with MSG_PEEK). But it does not return -1 on error. 465/* This function is like recv(with MSG_PEEK). But it does not return -1 on error.
466 * It does return gnutls_errno instead. 466 * It does return MHD_gnutls_errno instead.
467 * This function reads data from the socket and keeps them in a buffer, of up to 467 * This function reads data from the socket and keeps them in a buffer, of up to
468 * MAX_RECV_SIZE. 468 * MAX_RECV_SIZE.
469 * 469 *
@@ -472,7 +472,7 @@ mhd_gtls_io_clear_read_buffer (mhd_gtls_session_t session)
472 * 472 *
473 */ 473 */
474ssize_t 474ssize_t
475mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr, 475MHD_gtls_io_read_buffered (MHD_gtls_session_t session, opaque ** iptr,
476 size_t sizeOfPtr, content_type_t recv_type) 476 size_t sizeOfPtr, content_type_t recv_type)
477{ 477{
478 ssize_t ret = 0, ret2 = 0; 478 ssize_t ret = 0, ret2 = 0;
@@ -486,14 +486,14 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
486 486
487 if (sizeOfPtr > MAX_RECV_SIZE || sizeOfPtr == 0) 487 if (sizeOfPtr > MAX_RECV_SIZE || sizeOfPtr == 0)
488 { 488 {
489 gnutls_assert (); /* internal error */ 489 MHD_gnutls_assert (); /* internal error */
490 return GNUTLS_E_INVALID_REQUEST; 490 return GNUTLS_E_INVALID_REQUEST;
491 } 491 }
492 492
493 /* If an external pull function is used, then do not leave 493 /* If an external pull function is used, then do not leave
494 * any data into the kernel buffer. 494 * any data into the kernel buffer.
495 */ 495 */
496 if (session->internals._gnutls_pull_func != NULL) 496 if (session->internals.MHD__gnutls_pull_func != NULL)
497 { 497 {
498 recvlowat = 0; 498 recvlowat = 0;
499 } 499 }
@@ -536,7 +536,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
536 if ((session->internals.record_recv_buffer.length + recvdata) 536 if ((session->internals.record_recv_buffer.length + recvdata)
537 > MAX_RECV_SIZE) 537 > MAX_RECV_SIZE)
538 { 538 {
539 gnutls_assert (); /* internal error */ 539 MHD_gnutls_assert (); /* internal error */
540 return GNUTLS_E_INVALID_REQUEST; 540 return GNUTLS_E_INVALID_REQUEST;
541 } 541 }
542 542
@@ -544,11 +544,11 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
544 */ 544 */
545 alloc_size = recvdata + session->internals.record_recv_buffer.length; 545 alloc_size = recvdata + session->internals.record_recv_buffer.length;
546 session->internals.record_recv_buffer.data = 546 session->internals.record_recv_buffer.data =
547 mhd_gtls_realloc_fast (session->internals.record_recv_buffer.data, 547 MHD_gtls_realloc_fast (session->internals.record_recv_buffer.data,
548 alloc_size); 548 alloc_size);
549 if (session->internals.record_recv_buffer.data == NULL) 549 if (session->internals.record_recv_buffer.data == NULL)
550 { 550 {
551 gnutls_assert (); 551 MHD_gnutls_assert ();
552 return GNUTLS_E_MEMORY_ERROR; 552 return GNUTLS_E_MEMORY_ERROR;
553 } 553 }
554 554
@@ -559,7 +559,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
559 /* READ DATA - but leave RCVLOWAT bytes in the kernel buffer. */ 559 /* READ DATA - but leave RCVLOWAT bytes in the kernel buffer. */
560 if (recvdata - recvlowat > 0) 560 if (recvdata - recvlowat > 0)
561 { 561 {
562 ret = _gnutls_read (session, &buf[buf_pos], recvdata - recvlowat, 0); 562 ret = MHD__gnutls_read (session, &buf[buf_pos], recvdata - recvlowat, 0);
563 563
564 /* return immediately if we got an interrupt or eagain 564 /* return immediately if we got an interrupt or eagain
565 * error. 565 * error.
@@ -574,9 +574,9 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
574 */ 574 */
575 if (ret > 0) 575 if (ret > 0)
576 { 576 {
577 _gnutls_read_log ("RB: Have %d bytes into buffer. Adding %d bytes.\n", 577 MHD__gnutls_read_log ("RB: Have %d bytes into buffer. Adding %d bytes.\n",
578 session->internals.record_recv_buffer.length, ret); 578 session->internals.record_recv_buffer.length, ret);
579 _gnutls_read_log ("RB: Requested %d bytes\n", sizeOfPtr); 579 MHD__gnutls_read_log ("RB: Requested %d bytes\n", sizeOfPtr);
580 session->internals.record_recv_buffer.length += ret; 580 session->internals.record_recv_buffer.length += ret;
581 } 581 }
582 582
@@ -589,7 +589,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
589 */ 589 */
590 if (ret == (recvdata - recvlowat) && recvlowat > 0) 590 if (ret == (recvdata - recvlowat) && recvlowat > 0)
591 { 591 {
592 ret2 = _gnutls_read (session, &buf[buf_pos], recvlowat, MSG_PEEK); 592 ret2 = MHD__gnutls_read (session, &buf[buf_pos], recvlowat, MSG_PEEK);
593 593
594 if (ret2 < 0 && MHD_gtls_error_is_fatal (ret2) == 0) 594 if (ret2 < 0 && MHD_gtls_error_is_fatal (ret2) == 0)
595 { 595 {
@@ -598,8 +598,8 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
598 598
599 if (ret2 > 0) 599 if (ret2 > 0)
600 { 600 {
601 _gnutls_read_log ("RB-PEEK: Read %d bytes in PEEK MODE.\n", ret2); 601 MHD__gnutls_read_log ("RB-PEEK: Read %d bytes in PEEK MODE.\n", ret2);
602 _gnutls_read_log 602 MHD__gnutls_read_log
603 ("RB-PEEK: Have %d bytes into buffer. Adding %d bytes.\nRB: Requested %d bytes\n", 603 ("RB-PEEK: Have %d bytes into buffer. Adding %d bytes.\nRB: Requested %d bytes\n",
604 session->internals.record_recv_buffer.length, ret2, sizeOfPtr); 604 session->internals.record_recv_buffer.length, ret2, sizeOfPtr);
605 session->internals.have_peeked_data = 1; 605 session->internals.have_peeked_data = 1;
@@ -610,7 +610,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
610 610
611 if (ret < 0 || ret2 < 0) 611 if (ret < 0 || ret2 < 0)
612 { 612 {
613 gnutls_assert (); 613 MHD_gnutls_assert ();
614 /* that's because they are initialized to 0 */ 614 /* that's because they are initialized to 0 */
615 return MIN (ret, ret2); 615 return MIN (ret, ret2);
616 } 616 }
@@ -619,13 +619,13 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
619 619
620 if (ret > 0 && ret < recvlowat) 620 if (ret > 0 && ret < recvlowat)
621 { 621 {
622 gnutls_assert (); 622 MHD_gnutls_assert ();
623 return GNUTLS_E_AGAIN; 623 return GNUTLS_E_AGAIN;
624 } 624 }
625 625
626 if (ret == 0) 626 if (ret == 0)
627 { /* EOF */ 627 { /* EOF */
628 gnutls_assert (); 628 MHD_gnutls_assert ();
629 return 0; 629 return 0;
630 } 630 }
631 631
@@ -634,7 +634,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
634 if ((ret > 0) && ((size_t) ret < sizeOfPtr)) 634 if ((ret > 0) && ((size_t) ret < sizeOfPtr))
635 { 635 {
636 /* Short Read */ 636 /* Short Read */
637 gnutls_assert (); 637 MHD_gnutls_assert ();
638 return GNUTLS_E_AGAIN; 638 return GNUTLS_E_AGAIN;
639 } 639 }
640 else 640 else
@@ -651,7 +651,7 @@ mhd_gtls_io_read_buffered (mhd_gtls_session_t session, opaque ** iptr,
651#define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y)) 651#define MEMSUB(x,y) ((ssize_t)((ptrdiff_t)x-(ptrdiff_t)y))
652 652
653inline static int 653inline static int
654_gnutls_buffer_insert (mhd_gtls_buffer * buffer, 654MHD__gnutls_buffer_insert (MHD_gtls_buffer * buffer,
655 const opaque * _data, size_t data_size) 655 const opaque * _data, size_t data_size)
656{ 656{
657 657
@@ -662,7 +662,7 @@ _gnutls_buffer_insert (mhd_gtls_buffer * buffer,
662 */ 662 */
663 if (data_size > buffer->length) 663 if (data_size > buffer->length)
664 { 664 {
665 gnutls_assert (); 665 MHD_gnutls_assert ();
666 /* this shouldn't have happened */ 666 /* this shouldn't have happened */
667 return GNUTLS_E_INTERNAL_ERROR; 667 return GNUTLS_E_INTERNAL_ERROR;
668 } 668 }
@@ -680,9 +680,9 @@ _gnutls_buffer_insert (mhd_gtls_buffer * buffer,
680 680
681 } 681 }
682 682
683 if (mhd_gtls_buffer_append (buffer, _data, data_size) < 0) 683 if (MHD_gtls_buffer_append (buffer, _data, data_size) < 0)
684 { 684 {
685 gnutls_assert (); 685 MHD_gnutls_assert ();
686 return GNUTLS_E_MEMORY_ERROR; 686 return GNUTLS_E_MEMORY_ERROR;
687 } 687 }
688 688
@@ -690,7 +690,7 @@ _gnutls_buffer_insert (mhd_gtls_buffer * buffer,
690} 690}
691 691
692inline static int 692inline static int
693_gnutls_buffer_get (mhd_gtls_buffer * buffer, 693MHD__gnutls_buffer_get (MHD_gtls_buffer * buffer,
694 const opaque ** ptr, size_t * ptr_size) 694 const opaque ** ptr, size_t * ptr_size)
695{ 695{
696 *ptr_size = buffer->length; 696 *ptr_size = buffer->length;
@@ -700,9 +700,9 @@ _gnutls_buffer_get (mhd_gtls_buffer * buffer,
700} 700}
701 701
702/* This function is like write. But it does not return -1 on error. 702/* This function is like write. But it does not return -1 on error.
703 * It does return gnutls_errno instead. 703 * It does return MHD_gnutls_errno instead.
704 * 704 *
705 * In case of E_AGAIN and E_INTERRUPTED errors, you must call gnutls_write_flush(), 705 * In case of E_AGAIN and E_INTERRUPTED errors, you must call MHD_gnutls_write_flush(),
706 * until it returns ok (0). 706 * until it returns ok (0).
707 * 707 *
708 * We need to push exactly the data in n, since we cannot send less 708 * We need to push exactly the data in n, since we cannot send less
@@ -711,7 +711,7 @@ _gnutls_buffer_get (mhd_gtls_buffer * buffer,
711 * 711 *
712 */ 712 */
713ssize_t 713ssize_t
714mhd_gtls_io_write_buffered (mhd_gtls_session_t session, 714MHD_gtls_io_write_buffered (MHD_gtls_session_t session,
715 const void *iptr, size_t n) 715 const void *iptr, size_t n)
716{ 716{
717 size_t left; 717 size_t left;
@@ -719,7 +719,7 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
719 ssize_t retval, i; 719 ssize_t retval, i;
720 const opaque *ptr; 720 const opaque *ptr;
721 int ret; 721 int ret;
722 gnutls_transport_ptr_t fd = session->internals.transport_send_ptr; 722 MHD_gnutls_transport_ptr_t fd = session->internals.transport_send_ptr;
723 723
724 /* to know where the procedure was interrupted. 724 /* to know where the procedure was interrupted.
725 */ 725 */
@@ -733,7 +733,7 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
733 */ 733 */
734 if (session->internals.record_send_buffer.length > 0 && iptr != NULL) 734 if (session->internals.record_send_buffer.length > 0 && iptr != NULL)
735 { 735 {
736 gnutls_assert (); 736 MHD_gnutls_assert ();
737 return GNUTLS_E_INVALID_REQUEST; 737 return GNUTLS_E_INVALID_REQUEST;
738 } 738 }
739 739
@@ -742,19 +742,19 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
742 if (iptr == NULL) 742 if (iptr == NULL)
743 { 743 {
744 /* checking is handled above */ 744 /* checking is handled above */
745 ret = _gnutls_buffer_get (&session->internals.record_send_buffer, &ptr, 745 ret = MHD__gnutls_buffer_get (&session->internals.record_send_buffer, &ptr,
746 &n); 746 &n);
747 if (ret < 0) 747 if (ret < 0)
748 { 748 {
749 gnutls_assert (); 749 MHD_gnutls_assert ();
750 return ret; 750 return ret;
751 } 751 }
752 752
753 _gnutls_write_log ("WRITE: Restoring old write. (%d bytes to send)\n", 753 MHD__gnutls_write_log ("WRITE: Restoring old write. (%d bytes to send)\n",
754 n); 754 n);
755 } 755 }
756 756
757 _gnutls_write_log ("WRITE: Will write %d bytes to %d.\n", n, fd); 757 MHD__gnutls_write_log ("WRITE: Will write %d bytes to %d.\n", n, fd);
758 758
759 i = 0; 759 i = 0;
760 left = n; 760 left = n;
@@ -763,7 +763,7 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
763 763
764 session->internals.errnum = 0; 764 session->internals.errnum = 0;
765 765
766 if (session->internals._gnutls_push_func == NULL) 766 if (session->internals.MHD__gnutls_push_func == NULL)
767 { 767 {
768 i = send (GNUTLS_POINTER_TO_INT (fd), &ptr[n - left], left, 0); 768 i = send (GNUTLS_POINTER_TO_INT (fd), &ptr[n - left], left, 0);
769#if HAVE_WINSOCK 769#if HAVE_WINSOCK
@@ -789,7 +789,7 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
789#endif 789#endif
790 } 790 }
791 else 791 else
792 i = session->internals._gnutls_push_func (fd, &ptr[n - left], left); 792 i = session->internals.MHD__gnutls_push_func (fd, &ptr[n - left], left);
793 793
794 if (i == -1) 794 if (i == -1)
795 { 795 {
@@ -801,15 +801,15 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
801 session->internals.record_send_buffer_prev_size += n - left; 801 session->internals.record_send_buffer_prev_size += n - left;
802 802
803 retval = 803 retval =
804 _gnutls_buffer_insert (&session->internals.record_send_buffer, 804 MHD__gnutls_buffer_insert (&session->internals.record_send_buffer,
805 &ptr[n - left], left); 805 &ptr[n - left], left);
806 if (retval < 0) 806 if (retval < 0)
807 { 807 {
808 gnutls_assert (); 808 MHD_gnutls_assert ();
809 return retval; 809 return retval;
810 } 810 }
811 811
812 _gnutls_write_log 812 MHD__gnutls_write_log
813 ("WRITE: Interrupted. Stored %d bytes to buffer. Already sent %d bytes.\n", 813 ("WRITE: Interrupted. Stored %d bytes to buffer. Already sent %d bytes.\n",
814 left, n - left); 814 left, n - left);
815 815
@@ -819,18 +819,18 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
819 } 819 }
820 else 820 else
821 { 821 {
822 gnutls_assert (); 822 MHD_gnutls_assert ();
823 return GNUTLS_E_PUSH_ERROR; 823 return GNUTLS_E_PUSH_ERROR;
824 } 824 }
825 } 825 }
826 left -= i; 826 left -= i;
827 827
828 if (_gnutls_log_level >= 7) 828 if (MHD__gnutls_log_level >= 7)
829 { 829 {
830 char line[128]; 830 char line[128];
831 char tmp[16]; 831 char tmp[16];
832 832
833 _gnutls_write_log 833 MHD__gnutls_write_log
834 ("WRITE: wrote %d bytes to %d. Left %d bytes. Total %d bytes.\n", 834 ("WRITE: wrote %d bytes to %d. Left %d bytes. Total %d bytes.\n",
835 i, fd, left, n); 835 i, fd, left, n);
836 for (x = 0; x < (unsigned) ((i) / 16) + 1; x++) 836 for (x = 0; x < (unsigned) ((i) / 16) + 1; x++)
@@ -841,19 +841,19 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
841 break; 841 break;
842 842
843 sprintf (tmp, "%.4x - ", x); 843 sprintf (tmp, "%.4x - ", x);
844 mhd_gtls_str_cat (line, sizeof (line), tmp); 844 MHD_gtls_str_cat (line, sizeof (line), tmp);
845 845
846 for (j = 0; j < 16; j++) 846 for (j = 0; j < 16; j++)
847 { 847 {
848 if (sum < n - left) 848 if (sum < n - left)
849 { 849 {
850 sprintf (tmp, "%.2x ", ((unsigned char *) ptr)[sum++]); 850 sprintf (tmp, "%.2x ", ((unsigned char *) ptr)[sum++]);
851 mhd_gtls_str_cat (line, sizeof (line), tmp); 851 MHD_gtls_str_cat (line, sizeof (line), tmp);
852 } 852 }
853 else 853 else
854 break; 854 break;
855 } 855 }
856 _gnutls_write_log ("%s\n", line); 856 MHD__gnutls_write_log ("%s\n", line);
857 } 857 }
858 } 858 }
859 } 859 }
@@ -872,15 +872,15 @@ mhd_gtls_io_write_buffered (mhd_gtls_session_t session,
872 * interrupted. 872 * interrupted.
873 */ 873 */
874ssize_t 874ssize_t
875mhd_gtls_io_write_flush (mhd_gtls_session_t session) 875MHD_gtls_io_write_flush (MHD_gtls_session_t session)
876{ 876{
877 ssize_t ret; 877 ssize_t ret;
878 878
879 if (session->internals.record_send_buffer.length == 0) 879 if (session->internals.record_send_buffer.length == 0)
880 return 0; /* done */ 880 return 0; /* done */
881 881
882 ret = mhd_gtls_io_write_buffered (session, NULL, 0); 882 ret = MHD_gtls_io_write_buffered (session, NULL, 0);
883 _gnutls_write_log ("WRITE FLUSH: %d [buffer: %d]\n", ret, 883 MHD__gnutls_write_log ("WRITE FLUSH: %d [buffer: %d]\n", ret,
884 session->internals.record_send_buffer.length); 884 session->internals.record_send_buffer.length);
885 885
886 return ret; 886 return ret;
@@ -891,17 +891,17 @@ mhd_gtls_io_write_flush (mhd_gtls_session_t session)
891 * interrupted. 891 * interrupted.
892 */ 892 */
893ssize_t 893ssize_t
894mhd_gtls_handshake_io_write_flush (mhd_gtls_session_t session) 894MHD_gtls_handshake_io_write_flush (MHD_gtls_session_t session)
895{ 895{
896 ssize_t ret; 896 ssize_t ret;
897 ret = mhd_gtls_handshake_io_send_int (session, 0, 0, NULL, 0); 897 ret = MHD_gtls_handshake_io_send_int (session, 0, 0, NULL, 0);
898 if (ret < 0) 898 if (ret < 0)
899 { 899 {
900 gnutls_assert (); 900 MHD_gnutls_assert ();
901 return ret; 901 return ret;
902 } 902 }
903 903
904 _gnutls_write_log ("HANDSHAKE_FLUSH: written[1] %d bytes\n", ret); 904 MHD__gnutls_write_log ("HANDSHAKE_FLUSH: written[1] %d bytes\n", ret);
905 905
906 if (session->internals.handshake_send_buffer.length == 0) 906 if (session->internals.handshake_send_buffer.length == 0)
907 { 907 {
@@ -916,9 +916,9 @@ mhd_gtls_handshake_io_write_flush (mhd_gtls_session_t session)
916 * protocol. Just makes sure that all data have been sent. 916 * protocol. Just makes sure that all data have been sent.
917 */ 917 */
918ssize_t 918ssize_t
919mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session, 919MHD_gtls_handshake_io_send_int (MHD_gtls_session_t session,
920 content_type_t type, 920 content_type_t type,
921 gnutls_handshake_description_t htype, 921 MHD_gnutls_handshake_description_t htype,
922 const void *iptr, size_t n) 922 const void *iptr, size_t n)
923{ 923{
924 size_t left; 924 size_t left;
@@ -933,12 +933,12 @@ mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session,
933 { 933 {
934 /* resuming previously interrupted write 934 /* resuming previously interrupted write
935 */ 935 */
936 gnutls_assert (); 936 MHD_gnutls_assert ();
937 ret = _gnutls_buffer_get (&session->internals.handshake_send_buffer, 937 ret = MHD__gnutls_buffer_get (&session->internals.handshake_send_buffer,
938 &ptr, &n); 938 &ptr, &n);
939 if (ret < 0) 939 if (ret < 0)
940 { 940 {
941 gnutls_assert (); 941 MHD_gnutls_assert ();
942 return retval; 942 return retval;
943 } 943 }
944 944
@@ -948,7 +948,7 @@ mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session,
948 } 948 }
949 else if (session->internals.handshake_send_buffer.length > 0) 949 else if (session->internals.handshake_send_buffer.length > 0)
950 { 950 {
951 gnutls_assert (); 951 MHD_gnutls_assert ();
952 return GNUTLS_E_INTERNAL_ERROR; 952 return GNUTLS_E_INTERNAL_ERROR;
953 } 953 }
954#ifdef WRITE_DEBUG 954#ifdef WRITE_DEBUG
@@ -956,65 +956,65 @@ mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session,
956 { 956 {
957 size_t sum = 0, x, j; 957 size_t sum = 0, x, j;
958 958
959 _gnutls_write_log ("HWRITE: will write %d bytes to %d.\n", n, 959 MHD__gnutls_write_log ("HWRITE: will write %d bytes to %d.\n", n,
960 gnutls_transport_get_ptr (session)); 960 MHD_gnutls_transport_get_ptr (session));
961 for (x = 0; x < ((n) / 16) + 1; x++) 961 for (x = 0; x < ((n) / 16) + 1; x++)
962 { 962 {
963 if (sum > n) 963 if (sum > n)
964 break; 964 break;
965 965
966 _gnutls_write_log ("%.4x - ", x); 966 MHD__gnutls_write_log ("%.4x - ", x);
967 for (j = 0; j < 16; j++) 967 for (j = 0; j < 16; j++)
968 { 968 {
969 if (sum < n) 969 if (sum < n)
970 { 970 {
971 _gnutls_write_log ("%.2x ", ((unsigned char *) ptr)[sum++]); 971 MHD__gnutls_write_log ("%.2x ", ((unsigned char *) ptr)[sum++]);
972 } 972 }
973 else 973 else
974 break; 974 break;
975 } 975 }
976 _gnutls_write_log ("\n"); 976 MHD__gnutls_write_log ("\n");
977 } 977 }
978 _gnutls_write_log ("\n"); 978 MHD__gnutls_write_log ("\n");
979 } 979 }
980#endif 980#endif
981 981
982 if (n == 0) 982 if (n == 0)
983 { /* if we have no data to send */ 983 { /* if we have no data to send */
984 gnutls_assert (); 984 MHD_gnutls_assert ();
985 return 0; 985 return 0;
986 } 986 }
987 else if (ptr == NULL) 987 else if (ptr == NULL)
988 { 988 {
989 gnutls_assert (); 989 MHD_gnutls_assert ();
990 return GNUTLS_E_INTERNAL_ERROR; 990 return GNUTLS_E_INTERNAL_ERROR;
991 } 991 }
992 992
993 left = n; 993 left = n;
994 while (left > 0) 994 while (left > 0)
995 { 995 {
996 ret = mhd_gtls_send_int (session, type, htype, &ptr[n - left], left); 996 ret = MHD_gtls_send_int (session, type, htype, &ptr[n - left], left);
997 997
998 if (ret <= 0) 998 if (ret <= 0)
999 { 999 {
1000 if (ret == 0) 1000 if (ret == 0)
1001 { 1001 {
1002 gnutls_assert (); 1002 MHD_gnutls_assert ();
1003 ret = GNUTLS_E_INTERNAL_ERROR; 1003 ret = GNUTLS_E_INTERNAL_ERROR;
1004 } 1004 }
1005 1005
1006 if (left > 0 && (ret == GNUTLS_E_INTERRUPTED || ret 1006 if (left > 0 && (ret == GNUTLS_E_INTERRUPTED || ret
1007 == GNUTLS_E_AGAIN)) 1007 == GNUTLS_E_AGAIN))
1008 { 1008 {
1009 gnutls_assert (); 1009 MHD_gnutls_assert ();
1010 1010
1011 retval = 1011 retval =
1012 _gnutls_buffer_insert (&session->internals. 1012 MHD__gnutls_buffer_insert (&session->internals.
1013 handshake_send_buffer, &ptr[n - left], 1013 handshake_send_buffer, &ptr[n - left],
1014 left); 1014 left);
1015 if (retval < 0) 1015 if (retval < 0)
1016 { 1016 {
1017 gnutls_assert (); 1017 MHD_gnutls_assert ();
1018 return retval; 1018 return retval;
1019 } 1019 }
1020 1020
@@ -1030,7 +1030,7 @@ mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session,
1030 session->internals.handshake_send_buffer.length = 0; 1030 session->internals.handshake_send_buffer.length = 0;
1031 } 1031 }
1032 1032
1033 gnutls_assert (); 1033 MHD_gnutls_assert ();
1034 return ret; 1034 return ret;
1035 } 1035 }
1036 left -= ret; 1036 left -= ret;
@@ -1049,9 +1049,9 @@ mhd_gtls_handshake_io_send_int (mhd_gtls_session_t session,
1049 * protocol. Makes sure that we have received all data. 1049 * protocol. Makes sure that we have received all data.
1050 */ 1050 */
1051ssize_t 1051ssize_t
1052mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session, 1052MHD_gtls_handshake_io_recv_int (MHD_gtls_session_t session,
1053 content_type_t type, 1053 content_type_t type,
1054 gnutls_handshake_description_t htype, 1054 MHD_gnutls_handshake_description_t htype,
1055 void *iptr, size_t sizeOfPtr) 1055 void *iptr, size_t sizeOfPtr)
1056{ 1056{
1057 size_t left; 1057 size_t left;
@@ -1064,7 +1064,7 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1064 1064
1065 if (sizeOfPtr == 0 || iptr == NULL) 1065 if (sizeOfPtr == 0 || iptr == NULL)
1066 { 1066 {
1067 gnutls_assert (); 1067 MHD_gnutls_assert ();
1068 return GNUTLS_E_INVALID_REQUEST; 1068 return GNUTLS_E_INVALID_REQUEST;
1069 } 1069 }
1070 1070
@@ -1075,7 +1075,7 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1075 { 1075 {
1076 /* if requested less data then return it. 1076 /* if requested less data then return it.
1077 */ 1077 */
1078 gnutls_assert (); 1078 MHD_gnutls_assert ();
1079 memcpy (iptr, session->internals.handshake_recv_buffer.data, 1079 memcpy (iptr, session->internals.handshake_recv_buffer.data,
1080 sizeOfPtr); 1080 sizeOfPtr);
1081 1081
@@ -1087,7 +1087,7 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1087 1087
1088 return sizeOfPtr; 1088 return sizeOfPtr;
1089 } 1089 }
1090 gnutls_assert (); 1090 MHD_gnutls_assert ();
1091 memcpy (iptr, session->internals.handshake_recv_buffer.data, 1091 memcpy (iptr, session->internals.handshake_recv_buffer.data,
1092 session->internals.handshake_recv_buffer.length); 1092 session->internals.handshake_recv_buffer.length);
1093 1093
@@ -1102,21 +1102,21 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1102 while (left > 0) 1102 while (left > 0)
1103 { 1103 {
1104 dsize = sizeOfPtr - left; 1104 dsize = sizeOfPtr - left;
1105 i = mhd_gtls_recv_int (session, type, htype, &ptr[dsize], left); 1105 i = MHD_gtls_recv_int (session, type, htype, &ptr[dsize], left);
1106 if (i < 0) 1106 if (i < 0)
1107 { 1107 {
1108 1108
1109 if (dsize > 0 && (i == GNUTLS_E_INTERRUPTED || i == GNUTLS_E_AGAIN)) 1109 if (dsize > 0 && (i == GNUTLS_E_INTERRUPTED || i == GNUTLS_E_AGAIN))
1110 { 1110 {
1111 gnutls_assert (); 1111 MHD_gnutls_assert ();
1112 1112
1113 session->internals.handshake_recv_buffer.data 1113 session->internals.handshake_recv_buffer.data
1114 = 1114 =
1115 mhd_gtls_realloc_fast (session->internals. 1115 MHD_gtls_realloc_fast (session->internals.
1116 handshake_recv_buffer.data, dsize); 1116 handshake_recv_buffer.data, dsize);
1117 if (session->internals.handshake_recv_buffer.data == NULL) 1117 if (session->internals.handshake_recv_buffer.data == NULL)
1118 { 1118 {
1119 gnutls_assert (); 1119 MHD_gnutls_assert ();
1120 return GNUTLS_E_MEMORY_ERROR; 1120 return GNUTLS_E_MEMORY_ERROR;
1121 } 1121 }
1122 1122
@@ -1131,7 +1131,7 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1131 else 1131 else
1132 session->internals.handshake_recv_buffer.length = 0; 1132 session->internals.handshake_recv_buffer.length = 0;
1133 1133
1134 gnutls_assert (); 1134 MHD_gnutls_assert ();
1135 1135
1136 return i; 1136 return i;
1137 } 1137 }
@@ -1155,7 +1155,7 @@ mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t session,
1155 * and finished messages. 1155 * and finished messages.
1156 */ 1156 */
1157int 1157int
1158mhd_gtls_handshake_buffer_put (mhd_gtls_session_t session, opaque * data, 1158MHD_gtls_handshake_buffer_put (MHD_gtls_session_t session, opaque * data,
1159 size_t length) 1159 size_t length)
1160{ 1160{
1161 1161
@@ -1172,16 +1172,16 @@ mhd_gtls_handshake_buffer_put (mhd_gtls_session_t session, opaque * data,
1172 internals. 1172 internals.
1173 max_handshake_data_buffer_size)) 1173 max_handshake_data_buffer_size))
1174 { 1174 {
1175 gnutls_assert (); 1175 MHD_gnutls_assert ();
1176 return GNUTLS_E_MEMORY_ERROR; 1176 return GNUTLS_E_MEMORY_ERROR;
1177 } 1177 }
1178 1178
1179 _gnutls_buffers_log ("BUF[HSK]: Inserted %d bytes of Data\n", length); 1179 MHD__gnutls_buffers_log ("BUF[HSK]: Inserted %d bytes of Data\n", length);
1180 1180
1181 if (mhd_gtls_buffer_append (&session->internals.handshake_hash_buffer, data, 1181 if (MHD_gtls_buffer_append (&session->internals.handshake_hash_buffer, data,
1182 length) < 0) 1182 length) < 0)
1183 { 1183 {
1184 gnutls_assert (); 1184 MHD_gnutls_assert ();
1185 return GNUTLS_E_MEMORY_ERROR; 1185 return GNUTLS_E_MEMORY_ERROR;
1186 } 1186 }
1187 1187
@@ -1189,7 +1189,7 @@ mhd_gtls_handshake_buffer_put (mhd_gtls_session_t session, opaque * data,
1189} 1189}
1190 1190
1191int 1191int
1192mhd_gtls_handshake_buffer_get_size (mhd_gtls_session_t session) 1192MHD_gtls_handshake_buffer_get_size (MHD_gtls_session_t session)
1193{ 1193{
1194 1194
1195 return session->internals.handshake_hash_buffer.length; 1195 return session->internals.handshake_hash_buffer.length;
@@ -1199,7 +1199,7 @@ mhd_gtls_handshake_buffer_get_size (mhd_gtls_session_t session)
1199 * and returns data from it (peek mode!) 1199 * and returns data from it (peek mode!)
1200 */ 1200 */
1201int 1201int
1202mhd_gtls_handshake_buffer_peek (mhd_gtls_session_t session, opaque * data, 1202MHD_gtls_handshake_buffer_peek (MHD_gtls_session_t session, opaque * data,
1203 size_t length) 1203 size_t length)
1204{ 1204{
1205 if (length > session->internals.handshake_hash_buffer.length) 1205 if (length > session->internals.handshake_hash_buffer.length)
@@ -1207,7 +1207,7 @@ mhd_gtls_handshake_buffer_peek (mhd_gtls_session_t session, opaque * data,
1207 length = session->internals.handshake_hash_buffer.length; 1207 length = session->internals.handshake_hash_buffer.length;
1208 } 1208 }
1209 1209
1210 _gnutls_buffers_log ("BUF[HSK]: Peeked %d bytes of Data\n", length); 1210 MHD__gnutls_buffers_log ("BUF[HSK]: Peeked %d bytes of Data\n", length);
1211 1211
1212 memcpy (data, session->internals.handshake_hash_buffer.data, length); 1212 memcpy (data, session->internals.handshake_hash_buffer.data, length);
1213 return length; 1213 return length;
@@ -1217,13 +1217,13 @@ mhd_gtls_handshake_buffer_peek (mhd_gtls_session_t session, opaque * data,
1217 * and returns data from it (peek mode!) 1217 * and returns data from it (peek mode!)
1218 */ 1218 */
1219int 1219int
1220mhd_gtls_handshake_buffer_get_ptr (mhd_gtls_session_t session, 1220MHD_gtls_handshake_buffer_get_ptr (MHD_gtls_session_t session,
1221 opaque ** data_ptr, size_t * length) 1221 opaque ** data_ptr, size_t * length)
1222{ 1222{
1223 if (length != NULL) 1223 if (length != NULL)
1224 *length = session->internals.handshake_hash_buffer.length; 1224 *length = session->internals.handshake_hash_buffer.length;
1225 1225
1226 _gnutls_buffers_log ("BUF[HSK]: Peeked %d bytes of Data\n", 1226 MHD__gnutls_buffers_log ("BUF[HSK]: Peeked %d bytes of Data\n",
1227 session->internals.handshake_hash_buffer.length); 1227 session->internals.handshake_hash_buffer.length);
1228 1228
1229 if (data_ptr != NULL) 1229 if (data_ptr != NULL)
@@ -1235,10 +1235,10 @@ mhd_gtls_handshake_buffer_get_ptr (mhd_gtls_session_t session,
1235/* Does not free the buffer 1235/* Does not free the buffer
1236 */ 1236 */
1237int 1237int
1238mhd_gtls_handshake_buffer_empty (mhd_gtls_session_t session) 1238MHD_gtls_handshake_buffer_empty (MHD_gtls_session_t session)
1239{ 1239{
1240 1240
1241 _gnutls_buffers_log ("BUF[HSK]: Emptied buffer\n"); 1241 MHD__gnutls_buffers_log ("BUF[HSK]: Emptied buffer\n");
1242 1242
1243 session->internals.handshake_hash_buffer.length = 0; 1243 session->internals.handshake_hash_buffer.length = 0;
1244 1244
@@ -1246,9 +1246,9 @@ mhd_gtls_handshake_buffer_empty (mhd_gtls_session_t session)
1246} 1246}
1247 1247
1248int 1248int
1249mhd_gtls_handshake_buffer_clear (mhd_gtls_session_t session) 1249MHD_gtls_handshake_buffer_clear (MHD_gtls_session_t session)
1250{ 1250{
1251 _gnutls_buffers_log ("BUF[HSK]: Cleared Data from buffer\n"); 1251 MHD__gnutls_buffers_log ("BUF[HSK]: Cleared Data from buffer\n");
1252 mhd_gtls_buffer_clear (&session->internals.handshake_hash_buffer); 1252 MHD_gtls_buffer_clear (&session->internals.handshake_hash_buffer);
1253 return 0; 1253 return 0;
1254} 1254}
diff --git a/src/daemon/https/tls/gnutls_buffers.h b/src/daemon/https/tls/gnutls_buffers.h
index 609c2095..918da673 100644
--- a/src/daemon/https/tls/gnutls_buffers.h
+++ b/src/daemon/https/tls/gnutls_buffers.h
@@ -22,46 +22,46 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gnutls_record_buffer_put (content_type_t type, 25int MHD_gnutls_record_buffer_put (content_type_t type,
26 mhd_gtls_session_t session, opaque * data, 26 MHD_gtls_session_t session, opaque * data,
27 size_t length); 27 size_t length);
28int mhd_gnutls_record_buffer_get_size (content_type_t type, 28int MHD_gnutls_record_buffer_get_size (content_type_t type,
29 mhd_gtls_session_t session); 29 MHD_gtls_session_t session);
30int mhd_gtls_record_buffer_get (content_type_t type, 30int MHD_gtls_record_buffer_get (content_type_t type,
31 mhd_gtls_session_t session, opaque * data, 31 MHD_gtls_session_t session, opaque * data,
32 size_t length); 32 size_t length);
33ssize_t mhd_gtls_io_read_buffered (mhd_gtls_session_t, opaque ** iptr, 33ssize_t MHD_gtls_io_read_buffered (MHD_gtls_session_t, opaque ** iptr,
34 size_t n, content_type_t); 34 size_t n, content_type_t);
35void mhd_gtls_io_clear_read_buffer (mhd_gtls_session_t); 35void MHD_gtls_io_clear_read_buffer (MHD_gtls_session_t);
36int mhd_gtls_io_clear_peeked_data (mhd_gtls_session_t session); 36int MHD_gtls_io_clear_peeked_data (MHD_gtls_session_t session);
37 37
38ssize_t mhd_gtls_io_write_buffered (mhd_gtls_session_t, const void *iptr, 38ssize_t MHD_gtls_io_write_buffered (MHD_gtls_session_t, const void *iptr,
39 size_t n); 39 size_t n);
40ssize_t mhd_gtls_io_write_buffered2 (mhd_gtls_session_t, const void *iptr, 40ssize_t MHD_gtls_io_write_buffered2 (MHD_gtls_session_t, const void *iptr,
41 size_t n, const void *iptr2, size_t n2); 41 size_t n, const void *iptr2, size_t n2);
42 42
43int mhd_gtls_handshake_buffer_get_size (mhd_gtls_session_t session); 43int MHD_gtls_handshake_buffer_get_size (MHD_gtls_session_t session);
44int mhd_gtls_handshake_buffer_peek (mhd_gtls_session_t session, opaque * data, 44int MHD_gtls_handshake_buffer_peek (MHD_gtls_session_t session, opaque * data,
45 size_t length); 45 size_t length);
46int mhd_gtls_handshake_buffer_put (mhd_gtls_session_t session, opaque * data, 46int MHD_gtls_handshake_buffer_put (MHD_gtls_session_t session, opaque * data,
47 size_t length); 47 size_t length);
48int mhd_gtls_handshake_buffer_clear (mhd_gtls_session_t session); 48int MHD_gtls_handshake_buffer_clear (MHD_gtls_session_t session);
49int mhd_gtls_handshake_buffer_empty (mhd_gtls_session_t session); 49int MHD_gtls_handshake_buffer_empty (MHD_gtls_session_t session);
50int mhd_gtls_handshake_buffer_get_ptr (mhd_gtls_session_t session, 50int MHD_gtls_handshake_buffer_get_ptr (MHD_gtls_session_t session,
51 opaque ** data_ptr, size_t * length); 51 opaque ** data_ptr, size_t * length);
52 52
53#define _gnutls_handshake_io_buffer_clear( session) \ 53#define MHD__gnutls_handshake_io_buffer_clear( session) \
54 mhd_gtls_buffer_clear( &session->internals.handshake_send_buffer); \ 54 MHD_gtls_buffer_clear( &session->internals.handshake_send_buffer); \
55 mhd_gtls_buffer_clear( &session->internals.handshake_recv_buffer); \ 55 MHD_gtls_buffer_clear( &session->internals.handshake_recv_buffer); \
56 session->internals.handshake_send_buffer_prev_size = 0 56 session->internals.handshake_send_buffer_prev_size = 0
57 57
58ssize_t mhd_gtls_handshake_io_recv_int (mhd_gtls_session_t, content_type_t, 58ssize_t MHD_gtls_handshake_io_recv_int (MHD_gtls_session_t, content_type_t,
59 gnutls_handshake_description_t, 59 MHD_gnutls_handshake_description_t,
60 void *, size_t); 60 void *, size_t);
61ssize_t mhd_gtls_handshake_io_send_int (mhd_gtls_session_t, content_type_t, 61ssize_t MHD_gtls_handshake_io_send_int (MHD_gtls_session_t, content_type_t,
62 gnutls_handshake_description_t, 62 MHD_gnutls_handshake_description_t,
63 const void *, size_t); 63 const void *, size_t);
64ssize_t mhd_gtls_io_write_flush (mhd_gtls_session_t session); 64ssize_t MHD_gtls_io_write_flush (MHD_gtls_session_t session);
65ssize_t mhd_gtls_handshake_io_write_flush (mhd_gtls_session_t session); 65ssize_t MHD_gtls_handshake_io_write_flush (MHD_gtls_session_t session);
66 66
67size_t MHD_gtls_record_check_pending (mhd_gtls_session_t session); 67size_t MHD_gtls_record_check_pending (MHD_gtls_session_t session);
diff --git a/src/daemon/https/tls/gnutls_cert.c b/src/daemon/https/tls/gnutls_cert.c
index 17e95e48..45e001d6 100644
--- a/src/daemon/https/tls/gnutls_cert.c
+++ b/src/daemon/https/tls/gnutls_cert.c
@@ -45,8 +45,8 @@
45#include "mpi.h" 45#include "mpi.h"
46 46
47/** 47/**
48 * MHD_gnutls_certificate_free_keys - Used to free all the keys from a mhd_gtls_cert_credentials_t structure 48 * MHD__gnutls_certificate_free_keys - Used to free all the keys from a MHD_gtls_cert_credentials_t structure
49 * @sc: is an #mhd_gtls_cert_credentials_t structure. 49 * @sc: is an #MHD_gtls_cert_credentials_t structure.
50 * 50 *
51 * This function will delete all the keys and the certificates associated 51 * This function will delete all the keys and the certificates associated
52 * with the given credentials. This function must not be called when a 52 * with the given credentials. This function must not be called when a
@@ -54,7 +54,7 @@
54 * 54 *
55 **/ 55 **/
56void 56void
57MHD_gnutls_certificate_free_keys (mhd_gtls_cert_credentials_t sc) 57MHD__gnutls_certificate_free_keys (MHD_gtls_cert_credentials_t sc)
58{ 58{
59 unsigned i, j; 59 unsigned i, j;
60 60
@@ -62,23 +62,23 @@ MHD_gnutls_certificate_free_keys (mhd_gtls_cert_credentials_t sc)
62 { 62 {
63 for (j = 0; j < sc->cert_list_length[i]; j++) 63 for (j = 0; j < sc->cert_list_length[i]; j++)
64 { 64 {
65 mhd_gtls_gcert_deinit (&sc->cert_list[i][j]); 65 MHD_gtls_gcert_deinit (&sc->cert_list[i][j]);
66 } 66 }
67 gnutls_free (sc->cert_list[i]); 67 MHD_gnutls_free (sc->cert_list[i]);
68 } 68 }
69 69
70 gnutls_free (sc->cert_list_length); 70 MHD_gnutls_free (sc->cert_list_length);
71 sc->cert_list_length = NULL; 71 sc->cert_list_length = NULL;
72 72
73 gnutls_free (sc->cert_list); 73 MHD_gnutls_free (sc->cert_list);
74 sc->cert_list = NULL; 74 sc->cert_list = NULL;
75 75
76 for (i = 0; i < sc->ncerts; i++) 76 for (i = 0; i < sc->ncerts; i++)
77 { 77 {
78 mhd_gtls_gkey_deinit (&sc->pkey[i]); 78 MHD_gtls_gkey_deinit (&sc->pkey[i]);
79 } 79 }
80 80
81 gnutls_free (sc->pkey); 81 MHD_gnutls_free (sc->pkey);
82 sc->pkey = NULL; 82 sc->pkey = NULL;
83 83
84 sc->ncerts = 0; 84 sc->ncerts = 0;
@@ -86,8 +86,8 @@ MHD_gnutls_certificate_free_keys (mhd_gtls_cert_credentials_t sc)
86} 86}
87 87
88/** 88/**
89 * MHD_gnutls_certificate_free_cas - Used to free all the CAs from a mhd_gtls_cert_credentials_t structure 89 * MHD__gnutls_certificate_free_cas - Used to free all the CAs from a MHD_gtls_cert_credentials_t structure
90 * @sc: is an #mhd_gtls_cert_credentials_t structure. 90 * @sc: is an #MHD_gtls_cert_credentials_t structure.
91 * 91 *
92 * This function will delete all the CAs associated 92 * This function will delete all the CAs associated
93 * with the given credentials. Servers that do not use 93 * with the given credentials. Servers that do not use
@@ -96,25 +96,25 @@ MHD_gnutls_certificate_free_keys (mhd_gtls_cert_credentials_t sc)
96 * 96 *
97 **/ 97 **/
98void 98void
99MHD_gnutls_certificate_free_cas (mhd_gtls_cert_credentials_t sc) 99MHD__gnutls_certificate_free_cas (MHD_gtls_cert_credentials_t sc)
100{ 100{
101 unsigned j; 101 unsigned j;
102 102
103 for (j = 0; j < sc->x509_ncas; j++) 103 for (j = 0; j < sc->x509_ncas; j++)
104 { 104 {
105 gnutls_x509_crt_deinit (sc->x509_ca_list[j]); 105 MHD_gnutls_x509_crt_deinit (sc->x509_ca_list[j]);
106 } 106 }
107 107
108 sc->x509_ncas = 0; 108 sc->x509_ncas = 0;
109 109
110 gnutls_free (sc->x509_ca_list); 110 MHD_gnutls_free (sc->x509_ca_list);
111 sc->x509_ca_list = NULL; 111 sc->x509_ca_list = NULL;
112 112
113} 113}
114 114
115/** 115/**
116 * MHD_gnutls_certificate_free_ca_names - Used to free all the CA names from a mhd_gtls_cert_credentials_t structure 116 * MHD__gnutls_certificate_free_ca_names - Used to free all the CA names from a MHD_gtls_cert_credentials_t structure
117 * @sc: is an #mhd_gtls_cert_credentials_t structure. 117 * @sc: is an #MHD_gtls_cert_credentials_t structure.
118 * 118 *
119 * This function will delete all the CA name in the 119 * This function will delete all the CA name in the
120 * given credentials. Clients may call this to save some memory 120 * given credentials. Clients may call this to save some memory
@@ -125,13 +125,13 @@ MHD_gnutls_certificate_free_cas (mhd_gtls_cert_credentials_t sc)
125 * 125 *
126 **/ 126 **/
127void 127void
128MHD_gnutls_certificate_free_ca_names (mhd_gtls_cert_credentials_t sc) 128MHD__gnutls_certificate_free_ca_names (MHD_gtls_cert_credentials_t sc)
129{ 129{
130 _gnutls_free_datum (&sc->x509_rdn_sequence); 130 MHD__gnutls_free_datum (&sc->x509_rdn_sequence);
131} 131}
132 132
133/*- 133/*-
134 * mhd_gtls_certificate_get_rsa_params - Returns the RSA parameters pointer 134 * MHD_gtls_certificate_get_rsa_params - Returns the RSA parameters pointer
135 * @rsa_params: holds the RSA parameters or NULL. 135 * @rsa_params: holds the RSA parameters or NULL.
136 * @func: function to retrieve the parameters or NULL. 136 * @func: function to retrieve the parameters or NULL.
137 * @session: The session. 137 * @session: The session.
@@ -139,12 +139,12 @@ MHD_gnutls_certificate_free_ca_names (mhd_gtls_cert_credentials_t sc)
139 * This function will return the rsa parameters pointer. 139 * This function will return the rsa parameters pointer.
140 * 140 *
141 -*/ 141 -*/
142mhd_gtls_rsa_params_t 142MHD_gtls_rsa_params_t
143mhd_gtls_certificate_get_rsa_params (mhd_gtls_rsa_params_t rsa_params, 143MHD_gtls_certificate_get_rsa_params (MHD_gtls_rsa_params_t rsa_params,
144 gnutls_params_function * func, 144 MHD_gnutls_params_function * func,
145 mhd_gtls_session_t session) 145 MHD_gtls_session_t session)
146{ 146{
147 gnutls_params_st params; 147 MHD_gnutls_params_st params;
148 int ret; 148 int ret;
149 149
150 if (session->internals.params.rsa_params) 150 if (session->internals.params.rsa_params)
@@ -171,8 +171,8 @@ mhd_gtls_certificate_get_rsa_params (mhd_gtls_rsa_params_t rsa_params,
171 171
172 172
173/** 173/**
174 * MHD_gnutls_certificate_free_credentials - Used to free an allocated mhd_gtls_cert_credentials_t structure 174 * MHD__gnutls_certificate_free_credentials - Used to free an allocated MHD_gtls_cert_credentials_t structure
175 * @sc: is an #mhd_gtls_cert_credentials_t structure. 175 * @sc: is an #MHD_gtls_cert_credentials_t structure.
176 * 176 *
177 * This structure is complex enough to manipulate directly thus 177 * This structure is complex enough to manipulate directly thus
178 * this helper function is provided in order to free (deallocate) it. 178 * this helper function is provided in order to free (deallocate) it.
@@ -182,26 +182,26 @@ mhd_gtls_certificate_get_rsa_params (mhd_gtls_rsa_params_t rsa_params,
182 * this function). 182 * this function).
183 **/ 183 **/
184void 184void
185MHD_gnutls_certificate_free_credentials (mhd_gtls_cert_credentials_t sc) 185MHD__gnutls_certificate_free_credentials (MHD_gtls_cert_credentials_t sc)
186{ 186{
187 MHD_gnutls_certificate_free_keys (sc); 187 MHD__gnutls_certificate_free_keys (sc);
188 MHD_gnutls_certificate_free_cas (sc); 188 MHD__gnutls_certificate_free_cas (sc);
189 MHD_gnutls_certificate_free_ca_names (sc); 189 MHD__gnutls_certificate_free_ca_names (sc);
190#ifdef ENABLE_PKI 190#ifdef ENABLE_PKI
191 MHD_gnutls_certificate_free_crls (sc); 191 MHD__gnutls_certificate_free_crls (sc);
192#endif 192#endif
193 193
194#ifdef KEYRING_HACK 194#ifdef KEYRING_HACK
195 _gnutls_free_datum (&sc->keyring); 195 MHD__gnutls_free_datum (&sc->keyring);
196#endif 196#endif
197 197
198 gnutls_free (sc); 198 MHD_gnutls_free (sc);
199} 199}
200 200
201 201
202/** 202/**
203 * MHD_gnutls_certificate_allocate_credentials - Used to allocate a mhd_gtls_cert_credentials_t structure 203 * MHD__gnutls_certificate_allocate_credentials - Used to allocate a MHD_gtls_cert_credentials_t structure
204 * @res: is a pointer to an #mhd_gtls_cert_credentials_t structure. 204 * @res: is a pointer to an #MHD_gtls_cert_credentials_t structure.
205 * 205 *
206 * This structure is complex enough to manipulate directly thus this 206 * This structure is complex enough to manipulate directly thus this
207 * helper function is provided in order to allocate it. 207 * helper function is provided in order to allocate it.
@@ -209,10 +209,10 @@ MHD_gnutls_certificate_free_credentials (mhd_gtls_cert_credentials_t sc)
209 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 209 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
210 **/ 210 **/
211int 211int
212MHD_gnutls_certificate_allocate_credentials (mhd_gtls_cert_credentials_t * 212MHD__gnutls_certificate_allocate_credentials (MHD_gtls_cert_credentials_t *
213 res) 213 res)
214{ 214{
215 *res = gnutls_calloc (1, sizeof (mhd_gtls_cert_credentials_st)); 215 *res = MHD_gnutls_calloc (1, sizeof (MHD_gtls_cert_credentials_st));
216 216
217 if (*res == NULL) 217 if (*res == NULL)
218 return GNUTLS_E_MEMORY_ERROR; 218 return GNUTLS_E_MEMORY_ERROR;
@@ -231,14 +231,14 @@ MHD_gnutls_certificate_allocate_credentials (mhd_gtls_cert_credentials_t *
231 * extensions in order to disable unneded algorithms. 231 * extensions in order to disable unneded algorithms.
232 */ 232 */
233int 233int
234mhd_gtls_selected_cert_supported_kx (mhd_gtls_session_t session, 234MHD_gtls_selected_cert_supported_kx (MHD_gtls_session_t session,
235 enum MHD_GNUTLS_KeyExchangeAlgorithm 235 enum MHD_GNUTLS_KeyExchangeAlgorithm
236 **alg, int *alg_size) 236 **alg, int *alg_size)
237{ 237{
238 enum MHD_GNUTLS_KeyExchangeAlgorithm kx; 238 enum MHD_GNUTLS_KeyExchangeAlgorithm kx;
239 enum MHD_GNUTLS_PublicKeyAlgorithm pk; 239 enum MHD_GNUTLS_PublicKeyAlgorithm pk;
240 enum MHD_GNUTLS_KeyExchangeAlgorithm kxlist[MAX_ALGOS]; 240 enum MHD_GNUTLS_KeyExchangeAlgorithm kxlist[MAX_ALGOS];
241 gnutls_cert *cert; 241 MHD_gnutls_cert *cert;
242 int i; 242 int i;
243 243
244 if (session->internals.selected_cert_list_length == 0) 244 if (session->internals.selected_cert_list_length == 0)
@@ -253,11 +253,11 @@ mhd_gtls_selected_cert_supported_kx (mhd_gtls_session_t session,
253 253
254 for (kx = 0; kx < MAX_ALGOS; kx++) 254 for (kx = 0; kx < MAX_ALGOS; kx++)
255 { 255 {
256 pk = mhd_gtls_map_pk_get_pk (kx); 256 pk = MHD_gtls_map_pk_get_pk (kx);
257 if (pk == cert->subject_pk_algorithm) 257 if (pk == cert->subject_pk_algorithm)
258 { 258 {
259 /* then check key usage */ 259 /* then check key usage */
260 if (_gnutls_check_key_usage (cert, kx) == 0) 260 if (MHD__gnutls_check_key_usage (cert, kx) == 0)
261 { 261 {
262 kxlist[i] = kx; 262 kxlist[i] = kx;
263 i++; 263 i++;
@@ -267,11 +267,11 @@ mhd_gtls_selected_cert_supported_kx (mhd_gtls_session_t session,
267 267
268 if (i == 0) 268 if (i == 0)
269 { 269 {
270 gnutls_assert (); 270 MHD_gnutls_assert ();
271 return GNUTLS_E_INVALID_REQUEST; 271 return GNUTLS_E_INVALID_REQUEST;
272 } 272 }
273 273
274 *alg = gnutls_calloc (1, sizeof (enum MHD_GNUTLS_KeyExchangeAlgorithm) * i); 274 *alg = MHD_gnutls_calloc (1, sizeof (enum MHD_GNUTLS_KeyExchangeAlgorithm) * i);
275 if (*alg == NULL) 275 if (*alg == NULL)
276 return GNUTLS_E_MEMORY_ERROR; 276 return GNUTLS_E_MEMORY_ERROR;
277 277
@@ -285,7 +285,7 @@ mhd_gtls_selected_cert_supported_kx (mhd_gtls_session_t session,
285 285
286/** 286/**
287 * MHD_gtls_certificate_server_set_request - Used to set whether to request a client certificate 287 * MHD_gtls_certificate_server_set_request - Used to set whether to request a client certificate
288 * @session: is an #mhd_gtls_session_t structure. 288 * @session: is an #MHD_gtls_session_t structure.
289 * @req: is one of GNUTLS_CERT_REQUEST, GNUTLS_CERT_REQUIRE 289 * @req: is one of GNUTLS_CERT_REQUEST, GNUTLS_CERT_REQUIRE
290 * 290 *
291 * This function specifies if we (in case of a server) are going 291 * This function specifies if we (in case of a server) are going
@@ -296,28 +296,28 @@ mhd_gtls_selected_cert_supported_kx (mhd_gtls_session_t session,
296 * send a certificate. 296 * send a certificate.
297 **/ 297 **/
298void 298void
299MHD_gtls_certificate_server_set_request (mhd_gtls_session_t session, 299MHD_gtls_certificate_server_set_request (MHD_gtls_session_t session,
300 gnutls_certificate_request_t req) 300 MHD_gnutls_certificate_request_t req)
301{ 301{
302 session->internals.send_cert_req = req; 302 session->internals.send_cert_req = req;
303} 303}
304 304
305/** 305/**
306 * MHD_gtls_certificate_client_set_retrieve_function - Used to set a callback to retrieve the certificate 306 * MHD_gtls_certificate_client_set_retrieve_function - Used to set a callback to retrieve the certificate
307 * @cred: is a #mhd_gtls_cert_credentials_t structure. 307 * @cred: is a #MHD_gtls_cert_credentials_t structure.
308 * @func: is the callback function 308 * @func: is the callback function
309 * 309 *
310 * This function sets a callback to be called in order to retrieve the certificate 310 * This function sets a callback to be called in order to retrieve the certificate
311 * to be used in the handshake. 311 * to be used in the handshake.
312 * The callback's function prototype is: 312 * The callback's function prototype is:
313 * int (*callback)(mhd_gtls_session_t, const gnutls_datum_t* req_ca_dn, int nreqs, 313 * int (*callback)(MHD_gtls_session_t, const MHD_gnutls_datum_t* req_ca_dn, int nreqs,
314 * const enum MHD_GNUTLS_PublicKeyAlgorithm* pk_algos, int pk_algos_length, gnutls_retr_st* st); 314 * const enum MHD_GNUTLS_PublicKeyAlgorithm* pk_algos, int pk_algos_length, MHD_gnutls_retr_st* st);
315 * 315 *
316 * @req_ca_cert is only used in X.509 certificates. 316 * @req_ca_cert is only used in X.509 certificates.
317 * Contains a list with the CA names that the server considers trusted. 317 * Contains a list with the CA names that the server considers trusted.
318 * Normally we should send a certificate that is signed 318 * Normally we should send a certificate that is signed
319 * by one of these CAs. These names are DER encoded. To get a more 319 * by one of these CAs. These names are DER encoded. To get a more
320 * meaningful value use the function gnutls_x509_rdn_get(). 320 * meaningful value use the function MHD_gnutls_x509_rdn_get().
321 * 321 *
322 * @pk_algos contains a list with server's acceptable signature algorithms. 322 * @pk_algos contains a list with server's acceptable signature algorithms.
323 * The certificate returned should support the server's given algorithms. 323 * The certificate returned should support the server's given algorithms.
@@ -333,21 +333,21 @@ MHD_gtls_certificate_server_set_request (mhd_gtls_session_t session,
333 * will be terminated. 333 * will be terminated.
334 **/ 334 **/
335void MHD_gtls_certificate_client_set_retrieve_function 335void MHD_gtls_certificate_client_set_retrieve_function
336 (mhd_gtls_cert_credentials_t cred, 336 (MHD_gtls_cert_credentials_t cred,
337 gnutls_certificate_client_retrieve_function * func) 337 MHD_gnutls_certificate_client_retrieve_function * func)
338{ 338{
339 cred->client_get_cert_callback = func; 339 cred->client_get_cert_callback = func;
340} 340}
341 341
342/** 342/**
343 * MHD_gtls_certificate_server_set_retrieve_function - Used to set a callback to retrieve the certificate 343 * MHD_gtls_certificate_server_set_retrieve_function - Used to set a callback to retrieve the certificate
344 * @cred: is a #mhd_gtls_cert_credentials_t structure. 344 * @cred: is a #MHD_gtls_cert_credentials_t structure.
345 * @func: is the callback function 345 * @func: is the callback function
346 * 346 *
347 * This function sets a callback to be called in order to retrieve the certificate 347 * This function sets a callback to be called in order to retrieve the certificate
348 * to be used in the handshake. 348 * to be used in the handshake.
349 * The callback's function prototype is: 349 * The callback's function prototype is:
350 * int (*callback)(mhd_gtls_session_t, gnutls_retr_st* st); 350 * int (*callback)(MHD_gtls_session_t, MHD_gnutls_retr_st* st);
351 * 351 *
352 * @st should contain the certificates and private keys. 352 * @st should contain the certificates and private keys.
353 * 353 *
@@ -359,14 +359,14 @@ void MHD_gtls_certificate_client_set_retrieve_function
359 * will be terminated. 359 * will be terminated.
360 **/ 360 **/
361void MHD_gtls_certificate_server_set_retrieve_function 361void MHD_gtls_certificate_server_set_retrieve_function
362 (mhd_gtls_cert_credentials_t cred, 362 (MHD_gtls_cert_credentials_t cred,
363 gnutls_certificate_server_retrieve_function * func) 363 MHD_gnutls_certificate_server_retrieve_function * func)
364{ 364{
365 cred->server_get_cert_callback = func; 365 cred->server_get_cert_callback = func;
366} 366}
367 367
368/*- 368/*-
369 * _gnutls_x509_extract_certificate_activation_time - This function returns the peer's certificate activation time 369 * MHD__gnutls_x509_extract_certificate_activation_time - This function returns the peer's certificate activation time
370 * @cert: should contain an X.509 DER encoded certificate 370 * @cert: should contain an X.509 DER encoded certificate
371 * 371 *
372 * This function will return the certificate's activation time in UNIX time 372 * This function will return the certificate's activation time in UNIX time
@@ -376,31 +376,31 @@ void MHD_gtls_certificate_server_set_retrieve_function
376 * 376 *
377 -*/ 377 -*/
378static time_t 378static time_t
379_gnutls_x509_get_raw_crt_activation_time (const gnutls_datum_t * cert) 379MHD__gnutls_x509_get_raw_crt_activation_time (const MHD_gnutls_datum_t * cert)
380{ 380{
381 gnutls_x509_crt_t xcert; 381 MHD_gnutls_x509_crt_t xcert;
382 time_t result; 382 time_t result;
383 383
384 result = gnutls_x509_crt_init (&xcert); 384 result = MHD_gnutls_x509_crt_init (&xcert);
385 if (result < 0) 385 if (result < 0)
386 return (time_t) - 1; 386 return (time_t) - 1;
387 387
388 result = gnutls_x509_crt_import (xcert, cert, GNUTLS_X509_FMT_DER); 388 result = MHD_gnutls_x509_crt_import (xcert, cert, GNUTLS_X509_FMT_DER);
389 if (result < 0) 389 if (result < 0)
390 { 390 {
391 gnutls_x509_crt_deinit (xcert); 391 MHD_gnutls_x509_crt_deinit (xcert);
392 return (time_t) - 1; 392 return (time_t) - 1;
393 } 393 }
394 394
395 result = gnutls_x509_crt_get_activation_time (xcert); 395 result = MHD_gnutls_x509_crt_get_activation_time (xcert);
396 396
397 gnutls_x509_crt_deinit (xcert); 397 MHD_gnutls_x509_crt_deinit (xcert);
398 398
399 return result; 399 return result;
400} 400}
401 401
402/*- 402/*-
403 * gnutls_x509_extract_certificate_expiration_time - This function returns the certificate's expiration time 403 * MHD_gnutls_x509_extract_certificate_expiration_time - This function returns the certificate's expiration time
404 * @cert: should contain an X.509 DER encoded certificate 404 * @cert: should contain an X.509 DER encoded certificate
405 * 405 *
406 * This function will return the certificate's expiration time in UNIX 406 * This function will return the certificate's expiration time in UNIX
@@ -410,25 +410,25 @@ _gnutls_x509_get_raw_crt_activation_time (const gnutls_datum_t * cert)
410 * 410 *
411 -*/ 411 -*/
412static time_t 412static time_t
413_gnutls_x509_get_raw_crt_expiration_time (const gnutls_datum_t * cert) 413MHD__gnutls_x509_get_raw_crt_expiration_time (const MHD_gnutls_datum_t * cert)
414{ 414{
415 gnutls_x509_crt_t xcert; 415 MHD_gnutls_x509_crt_t xcert;
416 time_t result; 416 time_t result;
417 417
418 result = gnutls_x509_crt_init (&xcert); 418 result = MHD_gnutls_x509_crt_init (&xcert);
419 if (result < 0) 419 if (result < 0)
420 return (time_t) - 1; 420 return (time_t) - 1;
421 421
422 result = gnutls_x509_crt_import (xcert, cert, GNUTLS_X509_FMT_DER); 422 result = MHD_gnutls_x509_crt_import (xcert, cert, GNUTLS_X509_FMT_DER);
423 if (result < 0) 423 if (result < 0)
424 { 424 {
425 gnutls_x509_crt_deinit (xcert); 425 MHD_gnutls_x509_crt_deinit (xcert);
426 return (time_t) - 1; 426 return (time_t) - 1;
427 } 427 }
428 428
429 result = gnutls_x509_crt_get_expiration_time (xcert); 429 result = MHD_gnutls_x509_crt_get_expiration_time (xcert);
430 430
431 gnutls_x509_crt_deinit (xcert); 431 MHD_gnutls_x509_crt_deinit (xcert);
432 432
433 return result; 433 return result;
434} 434}
@@ -440,34 +440,34 @@ _gnutls_x509_get_raw_crt_expiration_time (const gnutls_datum_t * cert)
440 * 440 *
441 * This function will try to verify the peer's certificate and return 441 * This function will try to verify the peer's certificate and return
442 * its status (trusted, invalid etc.). The value of @status should 442 * its status (trusted, invalid etc.). The value of @status should
443 * be one or more of the gnutls_certificate_status_t enumerated 443 * be one or more of the MHD_gnutls_certificate_status_t enumerated
444 * elements bitwise or'd. To avoid denial of service attacks some 444 * elements bitwise or'd. To avoid denial of service attacks some
445 * default upper limits regarding the certificate key size and chain 445 * default upper limits regarding the certificate key size and chain
446 * size are set. To override them use 446 * size are set. To override them use
447 * MHD_gnutls_certificate_set_verify_limits(). 447 * MHD__gnutls_certificate_set_verify_limits().
448 * 448 *
449 * Note that you must also check the peer's name in order to check if 449 * Note that you must also check the peer's name in order to check if
450 * the verified certificate belongs to the actual peer. 450 * the verified certificate belongs to the actual peer.
451 * 451 *
452 * This is the same as gnutls_x509_crt_list_verify() and uses the 452 * This is the same as MHD_gnutls_x509_crt_list_verify() and uses the
453 * loaded CAs in the credentials as trusted CAs. 453 * loaded CAs in the credentials as trusted CAs.
454 * 454 *
455 * Note that some commonly used X.509 Certificate Authorities are 455 * Note that some commonly used X.509 Certificate Authorities are
456 * still using Version 1 certificates. If you want to accept them, 456 * still using Version 1 certificates. If you want to accept them,
457 * you need to call MHD_gnutls_certificate_set_verify_flags() with, e.g., 457 * you need to call MHD__gnutls_certificate_set_verify_flags() with, e.g.,
458 * %GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT parameter. 458 * %GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT parameter.
459 * 459 *
460 * Returns: a negative error code on error and zero on success. 460 * Returns: a negative error code on error and zero on success.
461 **/ 461 **/
462int 462int
463MHD_gtls_certificate_verify_peers2 (mhd_gtls_session_t session, 463MHD_gtls_certificate_verify_peers2 (MHD_gtls_session_t session,
464 unsigned int *status) 464 unsigned int *status)
465{ 465{
466 cert_auth_info_t info; 466 cert_auth_info_t info;
467 467
468 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST); 468 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
469 469
470 info = mhd_gtls_get_auth_info (session); 470 info = MHD_gtls_get_auth_info (session);
471 if (info == NULL) 471 if (info == NULL)
472 { 472 {
473 return GNUTLS_E_NO_CERTIFICATE_FOUND; 473 return GNUTLS_E_NO_CERTIFICATE_FOUND;
@@ -476,10 +476,10 @@ MHD_gtls_certificate_verify_peers2 (mhd_gtls_session_t session,
476 if (info->raw_certificate_list == NULL || info->ncerts == 0) 476 if (info->raw_certificate_list == NULL || info->ncerts == 0)
477 return GNUTLS_E_NO_CERTIFICATE_FOUND; 477 return GNUTLS_E_NO_CERTIFICATE_FOUND;
478 478
479 switch (gnutls_certificate_type_get (session)) 479 switch (MHD_gnutls_certificate_type_get (session))
480 { 480 {
481 case MHD_GNUTLS_CRT_X509: 481 case MHD_GNUTLS_CRT_X509:
482 return _gnutls_x509_cert_verify_peers (session, status); 482 return MHD__gnutls_x509_cert_verify_peers (session, status);
483 default: 483 default:
484 return GNUTLS_E_INVALID_REQUEST; 484 return GNUTLS_E_INVALID_REQUEST;
485 } 485 }
@@ -495,15 +495,15 @@ MHD_gtls_certificate_verify_peers2 (mhd_gtls_session_t session,
495 * belongs to the actual peer. 495 * belongs to the actual peer.
496 * 496 *
497 * The return value should be one or more of the 497 * The return value should be one or more of the
498 * gnutls_certificate_status_t enumerated elements bitwise or'd, or a 498 * MHD_gnutls_certificate_status_t enumerated elements bitwise or'd, or a
499 * negative value on error. 499 * negative value on error.
500 * 500 *
501 * This is the same as gnutls_x509_crt_list_verify(). 501 * This is the same as MHD_gnutls_x509_crt_list_verify().
502 * 502 *
503 * Deprecated: Use MHD_gtls_certificate_verify_peers2() instead. 503 * Deprecated: Use MHD_gtls_certificate_verify_peers2() instead.
504 **/ 504 **/
505int 505int
506MHD_gtls_certificate_verify_peers (mhd_gtls_session_t session) 506MHD_gtls_certificate_verify_peers (MHD_gtls_session_t session)
507{ 507{
508 unsigned int status; 508 unsigned int status;
509 int ret; 509 int ret;
@@ -512,7 +512,7 @@ MHD_gtls_certificate_verify_peers (mhd_gtls_session_t session)
512 512
513 if (ret < 0) 513 if (ret < 0)
514 { 514 {
515 gnutls_assert (); 515 MHD_gnutls_assert ();
516 return ret; 516 return ret;
517 } 517 }
518 518
@@ -528,13 +528,13 @@ MHD_gtls_certificate_verify_peers (mhd_gtls_session_t session)
528 * Returns: (time_t)-1 on error. 528 * Returns: (time_t)-1 on error.
529 **/ 529 **/
530time_t 530time_t
531MHD_gtls_certificate_expiration_time_peers (mhd_gtls_session_t session) 531MHD_gtls_certificate_expiration_time_peers (MHD_gtls_session_t session)
532{ 532{
533 cert_auth_info_t info; 533 cert_auth_info_t info;
534 534
535 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST); 535 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
536 536
537 info = mhd_gtls_get_auth_info (session); 537 info = MHD_gtls_get_auth_info (session);
538 if (info == NULL) 538 if (info == NULL)
539 { 539 {
540 return (time_t) - 1; 540 return (time_t) - 1;
@@ -542,15 +542,15 @@ MHD_gtls_certificate_expiration_time_peers (mhd_gtls_session_t session)
542 542
543 if (info->raw_certificate_list == NULL || info->ncerts == 0) 543 if (info->raw_certificate_list == NULL || info->ncerts == 0)
544 { 544 {
545 gnutls_assert (); 545 MHD_gnutls_assert ();
546 return (time_t) - 1; 546 return (time_t) - 1;
547 } 547 }
548 548
549 switch (gnutls_certificate_type_get (session)) 549 switch (MHD_gnutls_certificate_type_get (session))
550 { 550 {
551 case MHD_GNUTLS_CRT_X509: 551 case MHD_GNUTLS_CRT_X509:
552 return 552 return
553 _gnutls_x509_get_raw_crt_expiration_time (&info->raw_certificate_list 553 MHD__gnutls_x509_get_raw_crt_expiration_time (&info->raw_certificate_list
554 [0]); 554 [0]);
555 default: 555 default:
556 return (time_t) - 1; 556 return (time_t) - 1;
@@ -567,13 +567,13 @@ MHD_gtls_certificate_expiration_time_peers (mhd_gtls_session_t session)
567 * Returns: (time_t)-1 on error. 567 * Returns: (time_t)-1 on error.
568 **/ 568 **/
569time_t 569time_t
570MHD_gtls_certificate_activation_time_peers (mhd_gtls_session_t session) 570MHD_gtls_certificate_activation_time_peers (MHD_gtls_session_t session)
571{ 571{
572 cert_auth_info_t info; 572 cert_auth_info_t info;
573 573
574 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST); 574 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
575 575
576 info = mhd_gtls_get_auth_info (session); 576 info = MHD_gtls_get_auth_info (session);
577 if (info == NULL) 577 if (info == NULL)
578 { 578 {
579 return (time_t) - 1; 579 return (time_t) - 1;
@@ -581,15 +581,15 @@ MHD_gtls_certificate_activation_time_peers (mhd_gtls_session_t session)
581 581
582 if (info->raw_certificate_list == NULL || info->ncerts == 0) 582 if (info->raw_certificate_list == NULL || info->ncerts == 0)
583 { 583 {
584 gnutls_assert (); 584 MHD_gnutls_assert ();
585 return (time_t) - 1; 585 return (time_t) - 1;
586 } 586 }
587 587
588 switch (gnutls_certificate_type_get (session)) 588 switch (MHD_gnutls_certificate_type_get (session))
589 { 589 {
590 case MHD_GNUTLS_CRT_X509: 590 case MHD_GNUTLS_CRT_X509:
591 return 591 return
592 _gnutls_x509_get_raw_crt_activation_time (&info->raw_certificate_list 592 MHD__gnutls_x509_get_raw_crt_activation_time (&info->raw_certificate_list
593 [0]); 593 [0]);
594 default: 594 default:
595 return (time_t) - 1; 595 return (time_t) - 1;
@@ -597,33 +597,33 @@ MHD_gtls_certificate_activation_time_peers (mhd_gtls_session_t session)
597} 597}
598 598
599int 599int
600mhd_gtls_raw_cert_to_gcert (gnutls_cert * gcert, 600MHD_gtls_raw_cert_to_gcert (MHD_gnutls_cert * gcert,
601 enum MHD_GNUTLS_CertificateType type, 601 enum MHD_GNUTLS_CertificateType type,
602 const gnutls_datum_t * raw_cert, 602 const MHD_gnutls_datum_t * raw_cert,
603 int flags /* OR of ConvFlags */ ) 603 int flags /* OR of ConvFlags */ )
604{ 604{
605 switch (type) 605 switch (type)
606 { 606 {
607 case MHD_GNUTLS_CRT_X509: 607 case MHD_GNUTLS_CRT_X509:
608 return mhd_gtls_x509_raw_cert_to_gcert (gcert, raw_cert, flags); 608 return MHD_gtls_x509_raw_cert_to_gcert (gcert, raw_cert, flags);
609 default: 609 default:
610 gnutls_assert (); 610 MHD_gnutls_assert ();
611 return GNUTLS_E_INTERNAL_ERROR; 611 return GNUTLS_E_INTERNAL_ERROR;
612 } 612 }
613} 613}
614 614
615int 615int
616mhd_gtls_raw_privkey_to_gkey (gnutls_privkey * key, 616MHD_gtls_raw_privkey_to_gkey (MHD_gnutls_privkey * key,
617 enum MHD_GNUTLS_CertificateType type, 617 enum MHD_GNUTLS_CertificateType type,
618 const gnutls_datum_t * raw_key, 618 const MHD_gnutls_datum_t * raw_key,
619 int key_enc /* DER or PEM */ ) 619 int key_enc /* DER or PEM */ )
620{ 620{
621 switch (type) 621 switch (type)
622 { 622 {
623 case MHD_GNUTLS_CRT_X509: 623 case MHD_GNUTLS_CRT_X509:
624 return _gnutls_x509_raw_privkey_to_gkey (key, raw_key, key_enc); 624 return MHD__gnutls_x509_raw_privkey_to_gkey (key, raw_key, key_enc);
625 default: 625 default:
626 gnutls_assert (); 626 MHD_gnutls_assert ();
627 return GNUTLS_E_INTERNAL_ERROR; 627 return GNUTLS_E_INTERNAL_ERROR;
628 } 628 }
629} 629}
@@ -639,30 +639,30 @@ mhd_gtls_raw_privkey_to_gkey (gnutls_privkey * key,
639 * The critical extensions will be catched by the verification functions. 639 * The critical extensions will be catched by the verification functions.
640 */ 640 */
641int 641int
642mhd_gtls_x509_raw_cert_to_gcert (gnutls_cert * gcert, 642MHD_gtls_x509_raw_cert_to_gcert (MHD_gnutls_cert * gcert,
643 const gnutls_datum_t * derCert, 643 const MHD_gnutls_datum_t * derCert,
644 int flags /* OR of ConvFlags */ ) 644 int flags /* OR of ConvFlags */ )
645{ 645{
646 int ret; 646 int ret;
647 gnutls_x509_crt_t cert; 647 MHD_gnutls_x509_crt_t cert;
648 648
649 ret = gnutls_x509_crt_init (&cert); 649 ret = MHD_gnutls_x509_crt_init (&cert);
650 if (ret < 0) 650 if (ret < 0)
651 { 651 {
652 gnutls_assert (); 652 MHD_gnutls_assert ();
653 return ret; 653 return ret;
654 } 654 }
655 655
656 ret = gnutls_x509_crt_import (cert, derCert, GNUTLS_X509_FMT_DER); 656 ret = MHD_gnutls_x509_crt_import (cert, derCert, GNUTLS_X509_FMT_DER);
657 if (ret < 0) 657 if (ret < 0)
658 { 658 {
659 gnutls_assert (); 659 MHD_gnutls_assert ();
660 gnutls_x509_crt_deinit (cert); 660 MHD_gnutls_x509_crt_deinit (cert);
661 return ret; 661 return ret;
662 } 662 }
663 663
664 ret = mhd_gtls_x509_crt_to_gcert (gcert, cert, flags); 664 ret = MHD_gtls_x509_crt_to_gcert (gcert, cert, flags);
665 gnutls_x509_crt_deinit (cert); 665 MHD_gnutls_x509_crt_deinit (cert);
666 666
667 return ret; 667 return ret;
668} 668}
@@ -670,12 +670,12 @@ mhd_gtls_x509_raw_cert_to_gcert (gnutls_cert * gcert,
670/* Like above but it accepts a parsed certificate instead. 670/* Like above but it accepts a parsed certificate instead.
671 */ 671 */
672int 672int
673mhd_gtls_x509_crt_to_gcert (gnutls_cert * gcert, 673MHD_gtls_x509_crt_to_gcert (MHD_gnutls_cert * gcert,
674 gnutls_x509_crt_t cert, unsigned int flags) 674 MHD_gnutls_x509_crt_t cert, unsigned int flags)
675{ 675{
676 int ret = 0; 676 int ret = 0;
677 677
678 memset (gcert, 0, sizeof (gnutls_cert)); 678 memset (gcert, 0, sizeof (MHD_gnutls_cert));
679 gcert->cert_type = MHD_GNUTLS_CRT_X509; 679 gcert->cert_type = MHD_GNUTLS_CRT_X509;
680 680
681 if (!(flags & CERT_NO_COPY)) 681 if (!(flags & CERT_NO_COPY))
@@ -687,38 +687,38 @@ mhd_gtls_x509_crt_to_gcert (gnutls_cert * gcert,
687 /* initially allocate a bogus size, just in case the certificate 687 /* initially allocate a bogus size, just in case the certificate
688 * fits in it. That way we minimize the DER encodings performed. 688 * fits in it. That way we minimize the DER encodings performed.
689 */ 689 */
690 der = gnutls_malloc (SMALL_DER); 690 der = MHD_gnutls_malloc (SMALL_DER);
691 if (der == NULL) 691 if (der == NULL)
692 { 692 {
693 gnutls_assert (); 693 MHD_gnutls_assert ();
694 return GNUTLS_E_MEMORY_ERROR; 694 return GNUTLS_E_MEMORY_ERROR;
695 } 695 }
696 696
697 ret = 697 ret =
698 gnutls_x509_crt_export (cert, GNUTLS_X509_FMT_DER, der, &der_size); 698 MHD_gnutls_x509_crt_export (cert, GNUTLS_X509_FMT_DER, der, &der_size);
699 if (ret < 0 && ret != GNUTLS_E_SHORT_MEMORY_BUFFER) 699 if (ret < 0 && ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
700 { 700 {
701 gnutls_assert (); 701 MHD_gnutls_assert ();
702 gnutls_free (der); 702 MHD_gnutls_free (der);
703 return ret; 703 return ret;
704 } 704 }
705 705
706 if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER) 706 if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
707 { 707 {
708 der = gnutls_realloc (der, der_size); 708 der = MHD_gnutls_realloc (der, der_size);
709 if (der == NULL) 709 if (der == NULL)
710 { 710 {
711 gnutls_assert (); 711 MHD_gnutls_assert ();
712 return GNUTLS_E_MEMORY_ERROR; 712 return GNUTLS_E_MEMORY_ERROR;
713 } 713 }
714 714
715 ret = 715 ret =
716 gnutls_x509_crt_export (cert, GNUTLS_X509_FMT_DER, der, 716 MHD_gnutls_x509_crt_export (cert, GNUTLS_X509_FMT_DER, der,
717 &der_size); 717 &der_size);
718 if (ret < 0) 718 if (ret < 0)
719 { 719 {
720 gnutls_assert (); 720 MHD_gnutls_assert ();
721 gnutls_free (der); 721 MHD_gnutls_free (der);
722 return ret; 722 return ret;
723 } 723 }
724 } 724 }
@@ -733,19 +733,19 @@ mhd_gtls_x509_crt_to_gcert (gnutls_cert * gcert,
733 733
734 if (flags & CERT_ONLY_EXTENSIONS || flags == 0) 734 if (flags & CERT_ONLY_EXTENSIONS || flags == 0)
735 { 735 {
736 gnutls_x509_crt_get_key_usage (cert, &gcert->key_usage, NULL); 736 MHD_gnutls_x509_crt_get_key_usage (cert, &gcert->key_usage, NULL);
737 gcert->version = gnutls_x509_crt_get_version (cert); 737 gcert->version = MHD_gnutls_x509_crt_get_version (cert);
738 } 738 }
739 gcert->subject_pk_algorithm = gnutls_x509_crt_get_pk_algorithm (cert, NULL); 739 gcert->subject_pk_algorithm = MHD_gnutls_x509_crt_get_pk_algorithm (cert, NULL);
740 740
741 if (flags & CERT_ONLY_PUBKEY || flags == 0) 741 if (flags & CERT_ONLY_PUBKEY || flags == 0)
742 { 742 {
743 gcert->params_size = MAX_PUBLIC_PARAMS_SIZE; 743 gcert->params_size = MAX_PUBLIC_PARAMS_SIZE;
744 ret = 744 ret =
745 _gnutls_x509_crt_get_mpis (cert, gcert->params, &gcert->params_size); 745 MHD__gnutls_x509_crt_get_mpis (cert, gcert->params, &gcert->params_size);
746 if (ret < 0) 746 if (ret < 0)
747 { 747 {
748 gnutls_assert (); 748 MHD_gnutls_assert ();
749 return ret; 749 return ret;
750 } 750 }
751 } 751 }
@@ -755,7 +755,7 @@ mhd_gtls_x509_crt_to_gcert (gnutls_cert * gcert,
755} 755}
756 756
757void 757void
758mhd_gtls_gcert_deinit (gnutls_cert * cert) 758MHD_gtls_gcert_deinit (MHD_gnutls_cert * cert)
759{ 759{
760 int i; 760 int i;
761 761
@@ -764,10 +764,10 @@ mhd_gtls_gcert_deinit (gnutls_cert * cert)
764 764
765 for (i = 0; i < cert->params_size; i++) 765 for (i = 0; i < cert->params_size; i++)
766 { 766 {
767 mhd_gtls_mpi_release (&cert->params[i]); 767 MHD_gtls_mpi_release (&cert->params[i]);
768 } 768 }
769 769
770 _gnutls_free_datum (&cert->raw); 770 MHD__gnutls_free_datum (&cert->raw);
771} 771}
772 772
773/** 773/**
@@ -778,20 +778,20 @@ mhd_gtls_gcert_deinit (gnutls_cert * cert)
778 * 778 *
779 * Set the callback function. The function must have this prototype: 779 * Set the callback function. The function must have this prototype:
780 * 780 *
781 * typedef int (*gnutls_sign_func) (mhd_gtls_session_t session, 781 * typedef int (*MHD_gnutls_sign_func) (MHD_gtls_session_t session,
782 * void *userdata, 782 * void *userdata,
783 * enum MHD_GNUTLS_CertificateType cert_type, 783 * enum MHD_GNUTLS_CertificateType cert_type,
784 * const gnutls_datum_t * cert, 784 * const MHD_gnutls_datum_t * cert,
785 * const gnutls_datum_t * hash, 785 * const MHD_gnutls_datum_t * hash,
786 * gnutls_datum_t * signature); 786 * MHD_gnutls_datum_t * signature);
787 * 787 *
788 * The @userdata parameter is passed to the @sign_func verbatim, and 788 * The @userdata parameter is passed to the @sign_func verbatim, and
789 * can be used to store application-specific data needed in the 789 * can be used to store application-specific data needed in the
790 * callback function. See also MHD_gtls_sign_callback_get(). 790 * callback function. See also MHD_gtls_sign_callback_get().
791 **/ 791 **/
792void 792void
793MHD_gtls_sign_callback_set (mhd_gtls_session_t session, 793MHD_gtls_sign_callback_set (MHD_gtls_session_t session,
794 gnutls_sign_func sign_func, void *userdata) 794 MHD_gnutls_sign_func sign_func, void *userdata)
795{ 795{
796 session->internals.sign_func = sign_func; 796 session->internals.sign_func = sign_func;
797 session->internals.sign_func_userdata = userdata; 797 session->internals.sign_func_userdata = userdata;
@@ -807,8 +807,8 @@ MHD_gtls_sign_callback_set (mhd_gtls_session_t session,
807 * Returns: The function pointer set by MHD_gtls_sign_callback_set(), or 807 * Returns: The function pointer set by MHD_gtls_sign_callback_set(), or
808 * if not set, %NULL. 808 * if not set, %NULL.
809 **/ 809 **/
810gnutls_sign_func 810MHD_gnutls_sign_func
811MHD_gtls_sign_callback_get (mhd_gtls_session_t session, void **userdata) 811MHD_gtls_sign_callback_get (MHD_gtls_session_t session, void **userdata)
812{ 812{
813 if (userdata) 813 if (userdata)
814 *userdata = session->internals.sign_func_userdata; 814 *userdata = session->internals.sign_func_userdata;
diff --git a/src/daemon/https/tls/gnutls_cert.h b/src/daemon/https/tls/gnutls_cert.h
index 129e7e16..b759fca5 100644
--- a/src/daemon/https/tls/gnutls_cert.h
+++ b/src/daemon/https/tls/gnutls_cert.h
@@ -48,7 +48,7 @@
48#define KEY_ENCIPHER_ONLY 1 48#define KEY_ENCIPHER_ONLY 1
49#define KEY_DECIPHER_ONLY 32768 49#define KEY_DECIPHER_ONLY 32768
50 50
51typedef struct gnutls_cert 51typedef struct MHD_gnutls_cert
52{ 52{
53 mpi_t params[MAX_PUBLIC_PARAMS_SIZE]; /* the size of params depends on the public 53 mpi_t params[MAX_PUBLIC_PARAMS_SIZE]; /* the size of params depends on the public
54 * key algorithm 54 * key algorithm
@@ -71,11 +71,11 @@ typedef struct gnutls_cert
71 */ 71 */
72 enum MHD_GNUTLS_CertificateType cert_type; 72 enum MHD_GNUTLS_CertificateType cert_type;
73 73
74 gnutls_datum_t raw; 74 MHD_gnutls_datum_t raw;
75 75
76} gnutls_cert; 76} MHD_gnutls_cert;
77 77
78typedef struct gnutls_privkey_int 78typedef struct MHD_gnutls_privkey_int
79{ 79{
80 mpi_t params[MAX_PRIV_PARAMS_SIZE]; /* the size of params depends on the public 80 mpi_t params[MAX_PRIV_PARAMS_SIZE]; /* the size of params depends on the public
81 * key algorithm 81 * key algorithm
@@ -96,9 +96,9 @@ typedef struct gnutls_privkey_int
96 int params_size; /* holds the number of params */ 96 int params_size; /* holds the number of params */
97 97
98 enum MHD_GNUTLS_PublicKeyAlgorithm pk_algorithm; 98 enum MHD_GNUTLS_PublicKeyAlgorithm pk_algorithm;
99} gnutls_privkey; 99} MHD_gnutls_privkey;
100 100
101struct MHD_gtls_session_int; /* because mhd_gtls_session_t is not defined when this file is included */ 101struct MHD_gtls_session_int; /* because MHD_gtls_session_t is not defined when this file is included */
102 102
103typedef enum ConvFlags 103typedef enum ConvFlags
104{ 104{
@@ -107,26 +107,26 @@ typedef enum ConvFlags
107 CERT_ONLY_EXTENSIONS = 16 107 CERT_ONLY_EXTENSIONS = 16
108} ConvFlags; 108} ConvFlags;
109 109
110int mhd_gtls_x509_raw_cert_to_gcert (gnutls_cert * gcert, 110int MHD_gtls_x509_raw_cert_to_gcert (MHD_gnutls_cert * gcert,
111 const gnutls_datum_t * derCert, 111 const MHD_gnutls_datum_t * derCert,
112 int flags); 112 int flags);
113int mhd_gtls_x509_crt_to_gcert (gnutls_cert * gcert, gnutls_x509_crt_t cert, 113int MHD_gtls_x509_crt_to_gcert (MHD_gnutls_cert * gcert, MHD_gnutls_x509_crt_t cert,
114 unsigned int flags); 114 unsigned int flags);
115 115
116void mhd_gtls_gkey_deinit (gnutls_privkey * key); 116void MHD_gtls_gkey_deinit (MHD_gnutls_privkey * key);
117void mhd_gtls_gcert_deinit (gnutls_cert * cert); 117void MHD_gtls_gcert_deinit (MHD_gnutls_cert * cert);
118 118
119int mhd_gtls_selected_cert_supported_kx (struct MHD_gtls_session_int *session, 119int MHD_gtls_selected_cert_supported_kx (struct MHD_gtls_session_int *session,
120 enum MHD_GNUTLS_KeyExchangeAlgorithm 120 enum MHD_GNUTLS_KeyExchangeAlgorithm
121 **alg, int *alg_size); 121 **alg, int *alg_size);
122 122
123int mhd_gtls_raw_cert_to_gcert (gnutls_cert * gcert, 123int MHD_gtls_raw_cert_to_gcert (MHD_gnutls_cert * gcert,
124 enum MHD_GNUTLS_CertificateType type, 124 enum MHD_GNUTLS_CertificateType type,
125 const gnutls_datum_t * raw_cert, 125 const MHD_gnutls_datum_t * raw_cert,
126 int flags /* OR of ConvFlags */ ); 126 int flags /* OR of ConvFlags */ );
127int mhd_gtls_raw_privkey_to_gkey (gnutls_privkey * key, 127int MHD_gtls_raw_privkey_to_gkey (MHD_gnutls_privkey * key,
128 enum MHD_GNUTLS_CertificateType type, 128 enum MHD_GNUTLS_CertificateType type,
129 const gnutls_datum_t * raw_key, 129 const MHD_gnutls_datum_t * raw_key,
130 int key_enc /* DER or PEM */ ); 130 int key_enc /* DER or PEM */ );
131 131
132#endif 132#endif
diff --git a/src/daemon/https/tls/gnutls_cipher.c b/src/daemon/https/tls/gnutls_cipher.c
index 69b62d16..94e87eb3 100644
--- a/src/daemon/https/tls/gnutls_cipher.c
+++ b/src/daemon/https/tls/gnutls_cipher.c
@@ -42,7 +42,7 @@
42#include <gc.h> 42#include <gc.h>
43 43
44inline static int 44inline static int
45is_write_comp_null (mhd_gtls_session_t session) 45is_write_comp_null (MHD_gtls_session_t session)
46{ 46{
47 if (session->security_parameters.write_compression_algorithm == 47 if (session->security_parameters.write_compression_algorithm ==
48 MHD_GNUTLS_COMP_NULL) 48 MHD_GNUTLS_COMP_NULL)
@@ -52,7 +52,7 @@ is_write_comp_null (mhd_gtls_session_t session)
52} 52}
53 53
54inline static int 54inline static int
55is_read_comp_null (mhd_gtls_session_t session) 55is_read_comp_null (MHD_gtls_session_t session)
56{ 56{
57 if (session->security_parameters.read_compression_algorithm == 57 if (session->security_parameters.read_compression_algorithm ==
58 MHD_GNUTLS_COMP_NULL) 58 MHD_GNUTLS_COMP_NULL)
@@ -68,13 +68,13 @@ is_read_comp_null (mhd_gtls_session_t session)
68 * If random pad != 0 then the random pad data will be appended. 68 * If random pad != 0 then the random pad data will be appended.
69 */ 69 */
70int 70int
71mhd_gtls_encrypt (mhd_gtls_session_t session, const opaque * headers, 71MHD_gtls_encrypt (MHD_gtls_session_t session, const opaque * headers,
72 size_t headers_size, const opaque * data, 72 size_t headers_size, const opaque * data,
73 size_t data_size, opaque * ciphertext, 73 size_t data_size, opaque * ciphertext,
74 size_t ciphertext_size, content_type_t type, int random_pad) 74 size_t ciphertext_size, content_type_t type, int random_pad)
75{ 75{
76 gnutls_datum_t plain; 76 MHD_gnutls_datum_t plain;
77 gnutls_datum_t comp; 77 MHD_gnutls_datum_t comp;
78 int ret; 78 int ret;
79 int free_comp = 1; 79 int free_comp = 1;
80 80
@@ -91,31 +91,31 @@ mhd_gtls_encrypt (mhd_gtls_session_t session, const opaque * headers,
91 /* Here comp is allocated and must be 91 /* Here comp is allocated and must be
92 * freed. 92 * freed.
93 */ 93 */
94 ret = _gnutls_m_plaintext2compressed (session, &comp, &plain); 94 ret = MHD__gnutls_m_plaintext2compressed (session, &comp, &plain);
95 if (ret < 0) 95 if (ret < 0)
96 { 96 {
97 gnutls_assert (); 97 MHD_gnutls_assert ();
98 return ret; 98 return ret;
99 } 99 }
100 } 100 }
101 101
102 ret = mhd_gtls_compressed2ciphertext (session, &ciphertext[headers_size], 102 ret = MHD_gtls_compressed2ciphertext (session, &ciphertext[headers_size],
103 ciphertext_size - headers_size, 103 ciphertext_size - headers_size,
104 comp, type, random_pad); 104 comp, type, random_pad);
105 105
106 if (free_comp) 106 if (free_comp)
107 _gnutls_free_datum (&comp); 107 MHD__gnutls_free_datum (&comp);
108 108
109 if (ret < 0) 109 if (ret < 0)
110 { 110 {
111 gnutls_assert (); 111 MHD_gnutls_assert ();
112 return ret; 112 return ret;
113 } 113 }
114 114
115 115
116 /* copy the headers */ 116 /* copy the headers */
117 memcpy (ciphertext, headers, headers_size); 117 memcpy (ciphertext, headers, headers_size);
118 mhd_gtls_write_uint16 (ret, &ciphertext[3]); 118 MHD_gtls_write_uint16 (ret, &ciphertext[3]);
119 119
120 return ret + headers_size; 120 return ret + headers_size;
121} 121}
@@ -124,12 +124,12 @@ mhd_gtls_encrypt (mhd_gtls_session_t session, const opaque * headers,
124 * Returns the decrypted data length. 124 * Returns the decrypted data length.
125 */ 125 */
126int 126int
127mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext, 127MHD_gtls_decrypt (MHD_gtls_session_t session, opaque * ciphertext,
128 size_t ciphertext_size, uint8_t * data, 128 size_t ciphertext_size, uint8_t * data,
129 size_t max_data_size, content_type_t type) 129 size_t max_data_size, content_type_t type)
130{ 130{
131 gnutls_datum_t gtxt; 131 MHD_gnutls_datum_t gtxt;
132 gnutls_datum_t gcipher; 132 MHD_gnutls_datum_t gcipher;
133 int ret; 133 int ret;
134 134
135 if (ciphertext_size == 0) 135 if (ciphertext_size == 0)
@@ -139,7 +139,7 @@ mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext,
139 gcipher.data = ciphertext; 139 gcipher.data = ciphertext;
140 140
141 ret = 141 ret =
142 mhd_gtls_ciphertext2compressed (session, data, max_data_size, 142 MHD_gtls_ciphertext2compressed (session, data, max_data_size,
143 gcipher, type); 143 gcipher, type);
144 if (ret < 0) 144 if (ret < 0)
145 { 145 {
@@ -153,14 +153,14 @@ mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext,
153 } 153 }
154 else 154 else
155 { 155 {
156 gnutls_datum_t gcomp; 156 MHD_gnutls_datum_t gcomp;
157 157
158 /* compression has this malloc overhead. 158 /* compression has this malloc overhead.
159 */ 159 */
160 160
161 gcomp.data = data; 161 gcomp.data = data;
162 gcomp.size = ret; 162 gcomp.size = ret;
163 ret = _gnutls_m_compressed2plaintext (session, &gtxt, &gcomp); 163 ret = MHD__gnutls_m_compressed2plaintext (session, &gtxt, &gcomp);
164 if (ret < 0) 164 if (ret < 0)
165 { 165 {
166 return ret; 166 return ret;
@@ -168,8 +168,8 @@ mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext,
168 168
169 if (gtxt.size > MAX_RECORD_RECV_SIZE) 169 if (gtxt.size > MAX_RECORD_RECV_SIZE)
170 { 170 {
171 gnutls_assert (); 171 MHD_gnutls_assert ();
172 _gnutls_free_datum (&gtxt); 172 MHD__gnutls_free_datum (&gtxt);
173 /* This shouldn't have happen and 173 /* This shouldn't have happen and
174 * is a TLS fatal error. 174 * is a TLS fatal error.
175 */ 175 */
@@ -179,15 +179,15 @@ mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext,
179 /* This check is not really needed */ 179 /* This check is not really needed */
180 if (max_data_size < MAX_RECORD_RECV_SIZE) 180 if (max_data_size < MAX_RECORD_RECV_SIZE)
181 { 181 {
182 gnutls_assert (); 182 MHD_gnutls_assert ();
183 _gnutls_free_datum (&gtxt); 183 MHD__gnutls_free_datum (&gtxt);
184 return GNUTLS_E_INTERNAL_ERROR; 184 return GNUTLS_E_INTERNAL_ERROR;
185 } 185 }
186 186
187 memcpy (data, gtxt.data, gtxt.size); 187 memcpy (data, gtxt.data, gtxt.size);
188 ret = gtxt.size; 188 ret = gtxt.size;
189 189
190 _gnutls_free_datum (&gtxt); 190 MHD__gnutls_free_datum (&gtxt);
191 } 191 }
192 192
193 return ret; 193 return ret;
@@ -204,11 +204,11 @@ mac_init (enum MHD_GNUTLS_HashAlgorithm mac, opaque * secret, int secret_size,
204 204
205 if (ver == MHD_GNUTLS_PROTOCOL_SSL3) 205 if (ver == MHD_GNUTLS_PROTOCOL_SSL3)
206 { /* SSL 3.0 */ 206 { /* SSL 3.0 */
207 td = mhd_gnutls_mac_init_ssl3 (mac, secret, secret_size); 207 td = MHD_gnutls_mac_init_ssl3 (mac, secret, secret_size);
208 } 208 }
209 else 209 else
210 { /* TLS 1.x */ 210 { /* TLS 1.x */
211 td = mhd_gtls_hmac_init (mac, secret, secret_size); 211 td = MHD_gtls_MHD_hmac_init (mac, secret, secret_size);
212 } 212 }
213 213
214 return td; 214 return td;
@@ -219,16 +219,16 @@ mac_deinit (mac_hd_t td, opaque * res, int ver)
219{ 219{
220 if (ver == MHD_GNUTLS_PROTOCOL_SSL3) 220 if (ver == MHD_GNUTLS_PROTOCOL_SSL3)
221 { /* SSL 3.0 */ 221 { /* SSL 3.0 */
222 mhd_gnutls_mac_deinit_ssl3 (td, res); 222 MHD_gnutls_mac_deinit_ssl3 (td, res);
223 } 223 }
224 else 224 else
225 { 225 {
226 mhd_gnutls_hmac_deinit (td, res); 226 MHD_gnutls_MHD_hmac_deinit (td, res);
227 } 227 }
228} 228}
229 229
230inline static int 230inline static int
231calc_enc_length (mhd_gtls_session_t session, int data_size, 231calc_enc_length (MHD_gtls_session_t session, int data_size,
232 int hash_size, uint8_t * pad, int random_pad, 232 int hash_size, uint8_t * pad, int random_pad,
233 cipher_type_t block_algo, uint16_t blocksize) 233 cipher_type_t block_algo, uint16_t blocksize)
234{ 234{
@@ -244,9 +244,9 @@ calc_enc_length (mhd_gtls_session_t session, int data_size,
244 244
245 break; 245 break;
246 case CIPHER_BLOCK: 246 case CIPHER_BLOCK:
247 if (gc_nonce (&rnd, 1) != GC_OK) 247 if (MHD_gc_nonce (&rnd, 1) != GC_OK)
248 { 248 {
249 gnutls_assert (); 249 MHD_gnutls_assert ();
250 return GNUTLS_E_RANDOM_FAILED; 250 return GNUTLS_E_RANDOM_FAILED;
251 } 251 }
252 252
@@ -276,7 +276,7 @@ calc_enc_length (mhd_gtls_session_t session, int data_size,
276 276
277 break; 277 break;
278 default: 278 default:
279 gnutls_assert (); 279 MHD_gnutls_assert ();
280 return GNUTLS_E_INTERNAL_ERROR; 280 return GNUTLS_E_INTERNAL_ERROR;
281 } 281 }
282 282
@@ -289,9 +289,9 @@ calc_enc_length (mhd_gtls_session_t session, int data_size,
289 * return the actual encrypted data length. 289 * return the actual encrypted data length.
290 */ 290 */
291int 291int
292mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session, 292MHD_gtls_compressed2ciphertext (MHD_gtls_session_t session,
293 opaque * cipher_data, int cipher_size, 293 opaque * cipher_data, int cipher_size,
294 gnutls_datum_t compressed, 294 MHD_gnutls_datum_t compressed,
295 content_type_t _type, int random_pad) 295 content_type_t _type, int random_pad)
296{ 296{
297 uint8_t MAC[MAX_HASH_SIZE]; 297 uint8_t MAC[MAX_HASH_SIZE];
@@ -302,21 +302,21 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
302 uint8_t type = _type; 302 uint8_t type = _type;
303 uint8_t major, minor; 303 uint8_t major, minor;
304 int hash_size = 304 int hash_size =
305 mhd_gnutls_hash_get_algo_len (session->security_parameters. 305 MHD_gnutls_hash_get_algo_len (session->security_parameters.
306 write_mac_algorithm); 306 write_mac_algorithm);
307 enum MHD_GNUTLS_Protocol ver; 307 enum MHD_GNUTLS_Protocol ver;
308 int blocksize = 308 int blocksize =
309 mhd_gtls_cipher_get_block_size (session->security_parameters. 309 MHD_gtls_cipher_get_block_size (session->security_parameters.
310 write_bulk_cipher_algorithm); 310 write_bulk_cipher_algorithm);
311 cipher_type_t block_algo = 311 cipher_type_t block_algo =
312 mhd_gtls_cipher_is_block (session->security_parameters. 312 MHD_gtls_cipher_is_block (session->security_parameters.
313 write_bulk_cipher_algorithm); 313 write_bulk_cipher_algorithm);
314 opaque *data_ptr; 314 opaque *data_ptr;
315 315
316 316
317 ver = MHD_gnutls_protocol_get_version (session); 317 ver = MHD__gnutls_protocol_get_version (session);
318 minor = mhd_gtls_version_get_minor (ver); 318 minor = MHD_gtls_version_get_minor (ver);
319 major = mhd_gtls_version_get_major (ver); 319 major = MHD_gtls_version_get_major (ver);
320 320
321 321
322 /* Initialize MAC */ 322 /* Initialize MAC */
@@ -328,26 +328,26 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
328 && session->security_parameters.write_mac_algorithm != 328 && session->security_parameters.write_mac_algorithm !=
329 MHD_GNUTLS_MAC_NULL) 329 MHD_GNUTLS_MAC_NULL)
330 { 330 {
331 gnutls_assert (); 331 MHD_gnutls_assert ();
332 return GNUTLS_E_INTERNAL_ERROR; 332 return GNUTLS_E_INTERNAL_ERROR;
333 } 333 }
334 334
335 c_length = mhd_gtls_conv_uint16 (compressed.size); 335 c_length = MHD_gtls_conv_uint16 (compressed.size);
336 336
337 if (td != GNUTLS_MAC_FAILED) 337 if (td != GNUTLS_MAC_FAILED)
338 { /* actually when the algorithm in not the NULL one */ 338 { /* actually when the algorithm in not the NULL one */
339 mhd_gnutls_hash (td, 339 MHD_gnutls_hash (td,
340 UINT64DATA (session->connection_state. 340 UINT64DATA (session->connection_state.
341 write_sequence_number), 8); 341 write_sequence_number), 8);
342 342
343 mhd_gnutls_hash (td, &type, 1); 343 MHD_gnutls_hash (td, &type, 1);
344 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_0) 344 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_0)
345 { /* TLS 1.0 or higher */ 345 { /* TLS 1.0 or higher */
346 mhd_gnutls_hash (td, &major, 1); 346 MHD_gnutls_hash (td, &major, 1);
347 mhd_gnutls_hash (td, &minor, 1); 347 MHD_gnutls_hash (td, &minor, 1);
348 } 348 }
349 mhd_gnutls_hash (td, &c_length, 2); 349 MHD_gnutls_hash (td, &c_length, 2);
350 mhd_gnutls_hash (td, compressed.data, compressed.size); 350 MHD_gnutls_hash (td, compressed.data, compressed.size);
351 mac_deinit (td, MAC, ver); 351 mac_deinit (td, MAC, ver);
352 } 352 }
353 353
@@ -359,7 +359,7 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
359 random_pad, block_algo, blocksize); 359 random_pad, block_algo, blocksize);
360 if (length < 0) 360 if (length < 0)
361 { 361 {
362 gnutls_assert (); 362 MHD_gnutls_assert ();
363 return length; 363 return length;
364 } 364 }
365 365
@@ -367,7 +367,7 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
367 */ 367 */
368 if (cipher_size < length) 368 if (cipher_size < length)
369 { 369 {
370 gnutls_assert (); 370 MHD_gnutls_assert ();
371 return GNUTLS_E_MEMORY_ERROR; 371 return GNUTLS_E_MEMORY_ERROR;
372 } 372 }
373 373
@@ -377,9 +377,9 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
377 { 377 {
378 /* copy the random IV. 378 /* copy the random IV.
379 */ 379 */
380 if (gc_nonce (data_ptr, blocksize) != GC_OK) 380 if (MHD_gc_nonce (data_ptr, blocksize) != GC_OK)
381 { 381 {
382 gnutls_assert (); 382 MHD_gnutls_assert ();
383 return GNUTLS_E_RANDOM_FAILED; 383 return GNUTLS_E_RANDOM_FAILED;
384 } 384 }
385 data_ptr += blocksize; 385 data_ptr += blocksize;
@@ -402,11 +402,11 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
402 /* Actual encryption (inplace). 402 /* Actual encryption (inplace).
403 */ 403 */
404 ret = 404 ret =
405 mhd_gtls_cipher_encrypt (session->connection_state.write_cipher_state, 405 MHD_gtls_cipher_encrypt (session->connection_state.write_cipher_state,
406 cipher_data, length); 406 cipher_data, length);
407 if (ret < 0) 407 if (ret < 0)
408 { 408 {
409 gnutls_assert (); 409 MHD_gnutls_assert ();
410 return ret; 410 return ret;
411 } 411 }
412 412
@@ -417,10 +417,10 @@ mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session,
417 * Returns the actual compressed packet size. 417 * Returns the actual compressed packet size.
418 */ 418 */
419int 419int
420mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session, 420MHD_gtls_ciphertext2compressed (MHD_gtls_session_t session,
421 opaque * compress_data, 421 opaque * compress_data,
422 int compress_size, 422 int compress_size,
423 gnutls_datum_t ciphertext, uint8_t type) 423 MHD_gnutls_datum_t ciphertext, uint8_t type)
424{ 424{
425 uint8_t MAC[MAX_HASH_SIZE]; 425 uint8_t MAC[MAX_HASH_SIZE];
426 uint16_t c_length; 426 uint16_t c_length;
@@ -432,15 +432,15 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
432 uint8_t major, minor; 432 uint8_t major, minor;
433 enum MHD_GNUTLS_Protocol ver; 433 enum MHD_GNUTLS_Protocol ver;
434 int hash_size = 434 int hash_size =
435 mhd_gnutls_hash_get_algo_len (session->security_parameters. 435 MHD_gnutls_hash_get_algo_len (session->security_parameters.
436 read_mac_algorithm); 436 read_mac_algorithm);
437 437
438 ver = MHD_gnutls_protocol_get_version (session); 438 ver = MHD__gnutls_protocol_get_version (session);
439 minor = mhd_gtls_version_get_minor (ver); 439 minor = MHD_gtls_version_get_minor (ver);
440 major = mhd_gtls_version_get_major (ver); 440 major = MHD_gtls_version_get_major (ver);
441 441
442 blocksize = 442 blocksize =
443 mhd_gtls_cipher_get_block_size (session->security_parameters. 443 MHD_gtls_cipher_get_block_size (session->security_parameters.
444 read_bulk_cipher_algorithm); 444 read_bulk_cipher_algorithm);
445 445
446 /* initialize MAC 446 /* initialize MAC
@@ -453,23 +453,23 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
453 && session->security_parameters.read_mac_algorithm != 453 && session->security_parameters.read_mac_algorithm !=
454 MHD_GNUTLS_MAC_NULL) 454 MHD_GNUTLS_MAC_NULL)
455 { 455 {
456 gnutls_assert (); 456 MHD_gnutls_assert ();
457 return GNUTLS_E_INTERNAL_ERROR; 457 return GNUTLS_E_INTERNAL_ERROR;
458 } 458 }
459 459
460 460
461 /* actual decryption (inplace) 461 /* actual decryption (inplace)
462 */ 462 */
463 switch (mhd_gtls_cipher_is_block 463 switch (MHD_gtls_cipher_is_block
464 (session->security_parameters.read_bulk_cipher_algorithm)) 464 (session->security_parameters.read_bulk_cipher_algorithm))
465 { 465 {
466 case CIPHER_STREAM: 466 case CIPHER_STREAM:
467 if ((ret = 467 if ((ret =
468 mhd_gtls_cipher_decrypt (session->connection_state. 468 MHD_gtls_cipher_decrypt (session->connection_state.
469 read_cipher_state, ciphertext.data, 469 read_cipher_state, ciphertext.data,
470 ciphertext.size)) < 0) 470 ciphertext.size)) < 0)
471 { 471 {
472 gnutls_assert (); 472 MHD_gnutls_assert ();
473 return ret; 473 return ret;
474 } 474 }
475 475
@@ -479,16 +479,16 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
479 case CIPHER_BLOCK: 479 case CIPHER_BLOCK:
480 if ((ciphertext.size < blocksize) || (ciphertext.size % blocksize != 0)) 480 if ((ciphertext.size < blocksize) || (ciphertext.size % blocksize != 0))
481 { 481 {
482 gnutls_assert (); 482 MHD_gnutls_assert ();
483 return GNUTLS_E_DECRYPTION_FAILED; 483 return GNUTLS_E_DECRYPTION_FAILED;
484 } 484 }
485 485
486 if ((ret = 486 if ((ret =
487 mhd_gtls_cipher_decrypt (session->connection_state. 487 MHD_gtls_cipher_decrypt (session->connection_state.
488 read_cipher_state, ciphertext.data, 488 read_cipher_state, ciphertext.data,
489 ciphertext.size)) < 0) 489 ciphertext.size)) < 0)
490 { 490 {
491 gnutls_assert (); 491 MHD_gnutls_assert ();
492 return ret; 492 return ret;
493 } 493 }
494 494
@@ -501,7 +501,7 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
501 501
502 if (ciphertext.size == 0) 502 if (ciphertext.size == 0)
503 { 503 {
504 gnutls_assert (); 504 MHD_gnutls_assert ();
505 return GNUTLS_E_DECRYPTION_FAILED; 505 return GNUTLS_E_DECRYPTION_FAILED;
506 } 506 }
507 } 507 }
@@ -512,7 +512,7 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
512 512
513 if (pad > ciphertext.size - hash_size) 513 if (pad > ciphertext.size - hash_size)
514 { 514 {
515 gnutls_assert (); 515 MHD_gnutls_assert ();
516 /* We do not fail here. We check below for the 516 /* We do not fail here. We check below for the
517 * the pad_failed. If zero means success. 517 * the pad_failed. If zero means success.
518 */ 518 */
@@ -530,33 +530,33 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
530 } 530 }
531 break; 531 break;
532 default: 532 default:
533 gnutls_assert (); 533 MHD_gnutls_assert ();
534 return GNUTLS_E_INTERNAL_ERROR; 534 return GNUTLS_E_INTERNAL_ERROR;
535 } 535 }
536 536
537 if (length < 0) 537 if (length < 0)
538 length = 0; 538 length = 0;
539 c_length = mhd_gtls_conv_uint16 ((uint16_t) length); 539 c_length = MHD_gtls_conv_uint16 ((uint16_t) length);
540 540
541 /* Pass the type, version, length and compressed through 541 /* Pass the type, version, length and compressed through
542 * MAC. 542 * MAC.
543 */ 543 */
544 if (td != GNUTLS_MAC_FAILED) 544 if (td != GNUTLS_MAC_FAILED)
545 { 545 {
546 mhd_gnutls_hash (td, 546 MHD_gnutls_hash (td,
547 UINT64DATA (session->connection_state. 547 UINT64DATA (session->connection_state.
548 read_sequence_number), 8); 548 read_sequence_number), 8);
549 549
550 mhd_gnutls_hash (td, &type, 1); 550 MHD_gnutls_hash (td, &type, 1);
551 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_0) 551 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_0)
552 { /* TLS 1.x */ 552 { /* TLS 1.x */
553 mhd_gnutls_hash (td, &major, 1); 553 MHD_gnutls_hash (td, &major, 1);
554 mhd_gnutls_hash (td, &minor, 1); 554 MHD_gnutls_hash (td, &minor, 1);
555 } 555 }
556 mhd_gnutls_hash (td, &c_length, 2); 556 MHD_gnutls_hash (td, &c_length, 2);
557 557
558 if (length > 0) 558 if (length > 0)
559 mhd_gnutls_hash (td, ciphertext.data, length); 559 MHD_gnutls_hash (td, ciphertext.data, length);
560 560
561 mac_deinit (td, MAC, ver); 561 mac_deinit (td, MAC, ver);
562 } 562 }
@@ -571,7 +571,7 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
571 */ 571 */
572 if (memcmp (MAC, &ciphertext.data[length], hash_size) != 0) 572 if (memcmp (MAC, &ciphertext.data[length], hash_size) != 0)
573 { 573 {
574 gnutls_assert (); 574 MHD_gnutls_assert ();
575 return GNUTLS_E_DECRYPTION_FAILED; 575 return GNUTLS_E_DECRYPTION_FAILED;
576 } 576 }
577 577
@@ -579,7 +579,7 @@ mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session,
579 */ 579 */
580 if (compress_size < length) 580 if (compress_size < length)
581 { 581 {
582 gnutls_assert (); 582 MHD_gnutls_assert ();
583 return GNUTLS_E_DECOMPRESSION_FAILED; 583 return GNUTLS_E_DECOMPRESSION_FAILED;
584 } 584 }
585 memcpy (compress_data, ciphertext.data, length); 585 memcpy (compress_data, ciphertext.data, length);
diff --git a/src/daemon/https/tls/gnutls_cipher.h b/src/daemon/https/tls/gnutls_cipher.h
index 511ee989..ab86d380 100644
--- a/src/daemon/https/tls/gnutls_cipher.h
+++ b/src/daemon/https/tls/gnutls_cipher.h
@@ -22,19 +22,19 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gtls_encrypt (mhd_gtls_session_t session, const opaque * headers, 25int MHD_gtls_encrypt (MHD_gtls_session_t session, const opaque * headers,
26 size_t headers_size, const opaque * data, 26 size_t headers_size, const opaque * data,
27 size_t data_size, opaque * ciphertext, 27 size_t data_size, opaque * ciphertext,
28 size_t ciphertext_size, content_type_t type, 28 size_t ciphertext_size, content_type_t type,
29 int random_pad); 29 int random_pad);
30 30
31int mhd_gtls_decrypt (mhd_gtls_session_t session, opaque * ciphertext, 31int MHD_gtls_decrypt (MHD_gtls_session_t session, opaque * ciphertext,
32 size_t ciphertext_size, uint8_t * data, 32 size_t ciphertext_size, uint8_t * data,
33 size_t data_size, content_type_t type); 33 size_t data_size, content_type_t type);
34int mhd_gtls_compressed2ciphertext (mhd_gtls_session_t session, 34int MHD_gtls_compressed2ciphertext (MHD_gtls_session_t session,
35 opaque * cipher_data, int cipher_size, 35 opaque * cipher_data, int cipher_size,
36 gnutls_datum_t compressed, 36 MHD_gnutls_datum_t compressed,
37 content_type_t _type, int random_pad); 37 content_type_t _type, int random_pad);
38int mhd_gtls_ciphertext2compressed (mhd_gtls_session_t session, 38int MHD_gtls_ciphertext2compressed (MHD_gtls_session_t session,
39 opaque * compress_data, int compress_size, 39 opaque * compress_data, int compress_size,
40 gnutls_datum_t ciphertext, uint8_t type); 40 MHD_gnutls_datum_t ciphertext, uint8_t type);
diff --git a/src/daemon/https/tls/gnutls_cipher_int.c b/src/daemon/https/tls/gnutls_cipher_int.c
index 836188aa..fef2c1d9 100644
--- a/src/daemon/https/tls/gnutls_cipher_int.c
+++ b/src/daemon/https/tls/gnutls_cipher_int.c
@@ -28,8 +28,8 @@
28#include <gnutls_datum.h> 28#include <gnutls_datum.h>
29 29
30cipher_hd_t 30cipher_hd_t
31mhd_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher, 31MHD_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher,
32 const gnutls_datum_t * key, const gnutls_datum_t * iv) 32 const MHD_gnutls_datum_t * key, const MHD_gnutls_datum_t * iv)
33{ 33{
34 cipher_hd_t ret = NULL; 34 cipher_hd_t ret = NULL;
35 int err = GC_INVALID_CIPHER; /* doesn't matter */ 35 int err = GC_INVALID_CIPHER; /* doesn't matter */
@@ -37,40 +37,40 @@ mhd_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher,
37 switch (cipher) 37 switch (cipher)
38 { 38 {
39 case MHD_GNUTLS_CIPHER_AES_128_CBC: 39 case MHD_GNUTLS_CIPHER_AES_128_CBC:
40 err = gc_cipher_open (GC_AES128, GC_CBC, &ret); 40 err = MHD_gc_cipher_open (GC_AES128, GC_CBC, &ret);
41 break; 41 break;
42 42
43 case MHD_GNUTLS_CIPHER_AES_256_CBC: 43 case MHD_GNUTLS_CIPHER_AES_256_CBC:
44 err = gc_cipher_open (GC_AES256, GC_CBC, &ret); 44 err = MHD_gc_cipher_open (GC_AES256, GC_CBC, &ret);
45 break; 45 break;
46 46
47 case MHD_GNUTLS_CIPHER_3DES_CBC: 47 case MHD_GNUTLS_CIPHER_3DES_CBC:
48 err = gc_cipher_open (GC_3DES, GC_CBC, &ret); 48 err = MHD_gc_cipher_open (GC_3DES, GC_CBC, &ret);
49 break; 49 break;
50 50
51 case MHD_GNUTLS_CIPHER_DES_CBC: 51 case MHD_GNUTLS_CIPHER_DES_CBC:
52 err = gc_cipher_open (GC_DES, GC_CBC, &ret); 52 err = MHD_gc_cipher_open (GC_DES, GC_CBC, &ret);
53 break; 53 break;
54 54
55 case MHD_GNUTLS_CIPHER_ARCFOUR_128: 55 case MHD_GNUTLS_CIPHER_ARCFOUR_128:
56 err = gc_cipher_open (GC_ARCFOUR128, GC_STREAM, &ret); 56 err = MHD_gc_cipher_open (GC_ARCFOUR128, GC_STREAM, &ret);
57 break; 57 break;
58 58
59 case MHD_GNUTLS_CIPHER_ARCFOUR_40: 59 case MHD_GNUTLS_CIPHER_ARCFOUR_40:
60 err = gc_cipher_open (GC_ARCFOUR40, GC_STREAM, &ret); 60 err = MHD_gc_cipher_open (GC_ARCFOUR40, GC_STREAM, &ret);
61 break; 61 break;
62 62
63 case MHD_GNUTLS_CIPHER_RC2_40_CBC: 63 case MHD_GNUTLS_CIPHER_RC2_40_CBC:
64 err = gc_cipher_open (GC_ARCTWO40, GC_CBC, &ret); 64 err = MHD_gc_cipher_open (GC_ARCTWO40, GC_CBC, &ret);
65 break; 65 break;
66 66
67#ifdef ENABLE_CAMELLIA 67#ifdef ENABLE_CAMELLIA
68 case MHD_GNUTLS_CIPHER_CAMELLIA_128_CBC: 68 case MHD_GNUTLS_CIPHER_CAMELLIA_128_CBC:
69 err = gc_cipher_open (GC_CAMELLIA128, GC_CBC, &ret); 69 err = MHD_gc_cipher_open (GC_CAMELLIA128, GC_CBC, &ret);
70 break; 70 break;
71 71
72 case MHD_GNUTLS_CIPHER_CAMELLIA_256_CBC: 72 case MHD_GNUTLS_CIPHER_CAMELLIA_256_CBC:
73 err = gc_cipher_open (GC_CAMELLIA256, GC_CBC, &ret); 73 err = MHD_gc_cipher_open (GC_CAMELLIA256, GC_CBC, &ret);
74 break; 74 break;
75#endif 75#endif
76 76
@@ -80,28 +80,28 @@ mhd_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher,
80 80
81 if (err == 0) 81 if (err == 0)
82 { 82 {
83 gc_cipher_setkey (ret, key->size, key->data); 83 MHD_gc_cipher_setkey (ret, key->size, key->data);
84 if (iv->data != NULL && iv->size > 0) 84 if (iv->data != NULL && iv->size > 0)
85 gc_cipher_setiv (ret, iv->size, iv->data); 85 MHD_gc_cipher_setiv (ret, iv->size, iv->data);
86 } 86 }
87 else if (cipher != MHD_GNUTLS_CIPHER_NULL) 87 else if (cipher != MHD_GNUTLS_CIPHER_NULL)
88 { 88 {
89 gnutls_assert (); 89 MHD_gnutls_assert ();
90 _gnutls_x509_log ("Crypto cipher[%d] error: %d\n", cipher, err); 90 MHD__gnutls_x509_log ("Crypto cipher[%d] error: %d\n", cipher, err);
91 /* FIXME: gc_strerror */ 91 /* FIXME: MHD_gc_strerror */
92 } 92 }
93 93
94 return ret; 94 return ret;
95} 95}
96 96
97int 97int
98mhd_gtls_cipher_encrypt (cipher_hd_t handle, void *text, int textlen) 98MHD_gtls_cipher_encrypt (cipher_hd_t handle, void *text, int textlen)
99{ 99{
100 if (handle != GNUTLS_CIPHER_FAILED) 100 if (handle != GNUTLS_CIPHER_FAILED)
101 { 101 {
102 if (gc_cipher_encrypt_inline (handle, textlen, text) != 0) 102 if (MHD_gc_cipher_encrypt_inline (handle, textlen, text) != 0)
103 { 103 {
104 gnutls_assert (); 104 MHD_gnutls_assert ();
105 return GNUTLS_E_INTERNAL_ERROR; 105 return GNUTLS_E_INTERNAL_ERROR;
106 } 106 }
107 } 107 }
@@ -109,14 +109,14 @@ mhd_gtls_cipher_encrypt (cipher_hd_t handle, void *text, int textlen)
109} 109}
110 110
111int 111int
112mhd_gtls_cipher_decrypt (cipher_hd_t handle, void *ciphertext, 112MHD_gtls_cipher_decrypt (cipher_hd_t handle, void *ciphertext,
113 int ciphertextlen) 113 int ciphertextlen)
114{ 114{
115 if (handle != GNUTLS_CIPHER_FAILED) 115 if (handle != GNUTLS_CIPHER_FAILED)
116 { 116 {
117 if (gc_cipher_decrypt_inline (handle, ciphertextlen, ciphertext) != 0) 117 if (MHD_gc_cipher_decrypt_inline (handle, ciphertextlen, ciphertext) != 0)
118 { 118 {
119 gnutls_assert (); 119 MHD_gnutls_assert ();
120 return GNUTLS_E_INTERNAL_ERROR; 120 return GNUTLS_E_INTERNAL_ERROR;
121 } 121 }
122 } 122 }
@@ -124,10 +124,10 @@ mhd_gtls_cipher_decrypt (cipher_hd_t handle, void *ciphertext,
124} 124}
125 125
126void 126void
127mhd_gnutls_cipher_deinit (cipher_hd_t handle) 127MHD_gnutls_cipher_deinit (cipher_hd_t handle)
128{ 128{
129 if (handle != GNUTLS_CIPHER_FAILED) 129 if (handle != GNUTLS_CIPHER_FAILED)
130 { 130 {
131 gc_cipher_close (handle); 131 MHD_gc_cipher_close (handle);
132 } 132 }
133} 133}
diff --git a/src/daemon/https/tls/gnutls_cipher_int.h b/src/daemon/https/tls/gnutls_cipher_int.h
index 6e2c8269..f00f945f 100644
--- a/src/daemon/https/tls/gnutls_cipher_int.h
+++ b/src/daemon/https/tls/gnutls_cipher_int.h
@@ -25,19 +25,19 @@
25#ifndef GNUTLS_CIPHER_INT 25#ifndef GNUTLS_CIPHER_INT
26# define GNUTLS_CIPHER_INT 26# define GNUTLS_CIPHER_INT
27 27
28#define cipher_hd_t gc_cipher_handle 28#define cipher_hd_t MHD_gc_cipher_handle
29#define GNUTLS_CIPHER_FAILED NULL 29#define GNUTLS_CIPHER_FAILED NULL
30 30
31// TODO gc_cipher_handle -> void * x3 31// TODO MHD_gc_cipher_handle -> void * x3
32void *mhd_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher, 32void *MHD_gtls_cipher_init (enum MHD_GNUTLS_CipherAlgorithm cipher,
33 const gnutls_datum_t * key, 33 const MHD_gnutls_datum_t * key,
34 const gnutls_datum_t * iv); 34 const MHD_gnutls_datum_t * iv);
35 35
36int mhd_gtls_cipher_encrypt (void *handle, void *text, int textlen); 36int MHD_gtls_cipher_encrypt (void *handle, void *text, int textlen);
37 37
38int mhd_gtls_cipher_decrypt (void *handle, 38int MHD_gtls_cipher_decrypt (void *handle,
39 void *ciphertext, int ciphertextlen); 39 void *ciphertext, int ciphertextlen);
40 40
41void mhd_gnutls_cipher_deinit (void *handle); 41void MHD_gnutls_cipher_deinit (void *handle);
42 42
43#endif /* GNUTLS_CIPHER_INT */ 43#endif /* GNUTLS_CIPHER_INT */
diff --git a/src/daemon/https/tls/gnutls_compress.c b/src/daemon/https/tls/gnutls_compress.c
index 9585fcf2..9552a72a 100644
--- a/src/daemon/https/tls/gnutls_compress.c
+++ b/src/daemon/https/tls/gnutls_compress.c
@@ -34,20 +34,20 @@
34/* These functions allocate the return value internally 34/* These functions allocate the return value internally
35 */ 35 */
36int 36int
37_gnutls_m_plaintext2compressed (mhd_gtls_session_t session, 37MHD__gnutls_m_plaintext2compressed (MHD_gtls_session_t session,
38 gnutls_datum_t * compressed, 38 MHD_gnutls_datum_t * compressed,
39 const gnutls_datum_t * plaintext) 39 const MHD_gnutls_datum_t * plaintext)
40{ 40{
41 int size; 41 int size;
42 opaque *data; 42 opaque *data;
43 43
44 size = 44 size =
45 mhd_gtls_compress (session->connection_state.write_compression_state, 45 MHD_gtls_compress (session->connection_state.write_compression_state,
46 plaintext->data, plaintext->size, &data, 46 plaintext->data, plaintext->size, &data,
47 MAX_RECORD_SEND_SIZE + EXTRA_COMP_SIZE); 47 MAX_RECORD_SEND_SIZE + EXTRA_COMP_SIZE);
48 if (size < 0) 48 if (size < 0)
49 { 49 {
50 gnutls_assert (); 50 MHD_gnutls_assert ();
51 return GNUTLS_E_COMPRESSION_FAILED; 51 return GNUTLS_E_COMPRESSION_FAILED;
52 } 52 }
53 compressed->data = data; 53 compressed->data = data;
@@ -57,20 +57,20 @@ _gnutls_m_plaintext2compressed (mhd_gtls_session_t session,
57} 57}
58 58
59int 59int
60_gnutls_m_compressed2plaintext (mhd_gtls_session_t session, 60MHD__gnutls_m_compressed2plaintext (MHD_gtls_session_t session,
61 gnutls_datum_t * plain, 61 MHD_gnutls_datum_t * plain,
62 const gnutls_datum_t * compressed) 62 const MHD_gnutls_datum_t * compressed)
63{ 63{
64 int size; 64 int size;
65 opaque *data; 65 opaque *data;
66 66
67 size = 67 size =
68 mhd_gtls_decompress (session->connection_state.read_compression_state, 68 MHD_gtls_decompress (session->connection_state.read_compression_state,
69 compressed->data, compressed->size, &data, 69 compressed->data, compressed->size, &data,
70 MAX_RECORD_RECV_SIZE); 70 MAX_RECORD_RECV_SIZE);
71 if (size < 0) 71 if (size < 0)
72 { 72 {
73 gnutls_assert (); 73 MHD_gnutls_assert ();
74 return GNUTLS_E_DECOMPRESSION_FAILED; 74 return GNUTLS_E_DECOMPRESSION_FAILED;
75 } 75 }
76 plain->data = data; 76 plain->data = data;
diff --git a/src/daemon/https/tls/gnutls_compress.h b/src/daemon/https/tls/gnutls_compress.h
index 7ccca5c3..c950e95d 100644
--- a/src/daemon/https/tls/gnutls_compress.h
+++ b/src/daemon/https/tls/gnutls_compress.h
@@ -22,9 +22,9 @@
22 * 22 *
23 */ 23 */
24 24
25int _gnutls_m_plaintext2compressed (mhd_gtls_session_t session, 25int MHD__gnutls_m_plaintext2compressed (MHD_gtls_session_t session,
26 gnutls_datum_t * compressed, 26 MHD_gnutls_datum_t * compressed,
27 const gnutls_datum_t * plaintext); 27 const MHD_gnutls_datum_t * plaintext);
28int _gnutls_m_compressed2plaintext (mhd_gtls_session_t session, 28int MHD__gnutls_m_compressed2plaintext (MHD_gtls_session_t session,
29 gnutls_datum_t * plain, 29 MHD_gnutls_datum_t * plain,
30 const gnutls_datum_t * compressed); 30 const MHD_gnutls_datum_t * compressed);
diff --git a/src/daemon/https/tls/gnutls_compress_int.c b/src/daemon/https/tls/gnutls_compress_int.c
index 1d272bed..6b97fac4 100644
--- a/src/daemon/https/tls/gnutls_compress_int.c
+++ b/src/daemon/https/tls/gnutls_compress_int.c
@@ -31,14 +31,14 @@
31 * decompress. 31 * decompress.
32 */ 32 */
33comp_hd_t 33comp_hd_t
34mhd_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d) 34MHD_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d)
35{ 35{
36 comp_hd_t ret; 36 comp_hd_t ret;
37 37
38 ret = gnutls_malloc (sizeof (struct comp_hd_t_STRUCT)); 38 ret = MHD_gnutls_malloc (sizeof (struct comp_hd_t_STRUCT));
39 if (ret == NULL) 39 if (ret == NULL)
40 { 40 {
41 gnutls_assert (); 41 MHD_gnutls_assert ();
42 return NULL; 42 return NULL;
43 } 43 }
44 44
@@ -54,14 +54,14 @@ mhd_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d)
54 int comp_level; 54 int comp_level;
55 z_stream *zhandle; 55 z_stream *zhandle;
56 56
57 window_bits = mhd_gtls_compression_get_wbits (method); 57 window_bits = MHD_gtls_compression_get_wbits (method);
58 mem_level = mhd_gtls_compression_get_mem_level (method); 58 mem_level = MHD_gtls_compression_get_mem_level (method);
59 comp_level = mhd_gtls_compression_get_comp_level (method); 59 comp_level = MHD_gtls_compression_get_comp_level (method);
60 60
61 ret->handle = gnutls_malloc (sizeof (z_stream)); 61 ret->handle = MHD_gnutls_malloc (sizeof (z_stream));
62 if (ret->handle == NULL) 62 if (ret->handle == NULL)
63 { 63 {
64 gnutls_assert (); 64 MHD_gnutls_assert ();
65 goto cleanup_ret; 65 goto cleanup_ret;
66 } 66 }
67 67
@@ -81,8 +81,8 @@ mhd_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d)
81 } 81 }
82 if (err != Z_OK) 82 if (err != Z_OK)
83 { 83 {
84 gnutls_assert (); 84 MHD_gnutls_assert ();
85 gnutls_free (ret->handle); 85 MHD_gnutls_free (ret->handle);
86 goto cleanup_ret; 86 goto cleanup_ret;
87 } 87 }
88 break; 88 break;
@@ -94,7 +94,7 @@ mhd_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod method, int d)
94 return ret; 94 return ret;
95 95
96cleanup_ret: 96cleanup_ret:
97 gnutls_free (ret); 97 MHD_gnutls_free (ret);
98 return NULL; 98 return NULL;
99} 99}
100 100
@@ -102,7 +102,7 @@ cleanup_ret:
102 * decompress. 102 * decompress.
103 */ 103 */
104void 104void
105mhd_gtls_comp_deinit (comp_hd_t handle, int d) 105MHD_gtls_comp_deinit (comp_hd_t handle, int d)
106{ 106{
107 if (handle != NULL) 107 if (handle != NULL)
108 { 108 {
@@ -119,8 +119,8 @@ mhd_gtls_comp_deinit (comp_hd_t handle, int d)
119 default: 119 default:
120 break; 120 break;
121 } 121 }
122 gnutls_free (handle->handle); 122 MHD_gnutls_free (handle->handle);
123 gnutls_free (handle); 123 MHD_gnutls_free (handle);
124 124
125 } 125 }
126} 126}
@@ -129,7 +129,7 @@ mhd_gtls_comp_deinit (comp_hd_t handle, int d)
129 */ 129 */
130 130
131int 131int
132mhd_gtls_compress (comp_hd_t handle, const opaque * plain, 132MHD_gtls_compress (comp_hd_t handle, const opaque * plain,
133 size_t plain_size, opaque ** compressed, 133 size_t plain_size, opaque ** compressed,
134 size_t max_comp_size) 134 size_t max_comp_size)
135{ 135{
@@ -139,7 +139,7 @@ mhd_gtls_compress (comp_hd_t handle, const opaque * plain,
139 */ 139 */
140 if (handle == NULL) 140 if (handle == NULL)
141 { 141 {
142 gnutls_assert (); 142 MHD_gnutls_assert ();
143 return GNUTLS_E_INTERNAL_ERROR; 143 return GNUTLS_E_INTERNAL_ERROR;
144 } 144 }
145 145
@@ -153,10 +153,10 @@ mhd_gtls_compress (comp_hd_t handle, const opaque * plain,
153 z_stream *zhandle; 153 z_stream *zhandle;
154 154
155 size = (plain_size + plain_size) + 10; 155 size = (plain_size + plain_size) + 10;
156 *compressed = gnutls_malloc (size); 156 *compressed = MHD_gnutls_malloc (size);
157 if (*compressed == NULL) 157 if (*compressed == NULL)
158 { 158 {
159 gnutls_assert (); 159 MHD_gnutls_assert ();
160 return GNUTLS_E_MEMORY_ERROR; 160 return GNUTLS_E_MEMORY_ERROR;
161 } 161 }
162 162
@@ -171,8 +171,8 @@ mhd_gtls_compress (comp_hd_t handle, const opaque * plain,
171 171
172 if (err != Z_OK || zhandle->avail_in != 0) 172 if (err != Z_OK || zhandle->avail_in != 0)
173 { 173 {
174 gnutls_assert (); 174 MHD_gnutls_assert ();
175 gnutls_free (*compressed); 175 MHD_gnutls_free (*compressed);
176 *compressed = NULL; 176 *compressed = NULL;
177 return GNUTLS_E_COMPRESSION_FAILED; 177 return GNUTLS_E_COMPRESSION_FAILED;
178 } 178 }
@@ -182,18 +182,18 @@ mhd_gtls_compress (comp_hd_t handle, const opaque * plain,
182 } 182 }
183#endif 183#endif
184 default: 184 default:
185 gnutls_assert (); 185 MHD_gnutls_assert ();
186 return GNUTLS_E_INTERNAL_ERROR; 186 return GNUTLS_E_INTERNAL_ERROR;
187 } /* switch */ 187 } /* switch */
188 188
189#ifdef COMPRESSION_DEBUG 189#ifdef COMPRESSION_DEBUG
190 _gnutls_debug_log ("Compression ratio: %f\n", 190 MHD__gnutls_debug_log ("Compression ratio: %f\n",
191 (float) ((float) compressed_size / (float) plain_size)); 191 (float) ((float) compressed_size / (float) plain_size));
192#endif 192#endif
193 193
194 if ((size_t) compressed_size > max_comp_size) 194 if ((size_t) compressed_size > max_comp_size)
195 { 195 {
196 gnutls_free (*compressed); 196 MHD_gnutls_free (*compressed);
197 *compressed = NULL; 197 *compressed = NULL;
198 return GNUTLS_E_COMPRESSION_FAILED; 198 return GNUTLS_E_COMPRESSION_FAILED;
199 } 199 }
@@ -204,7 +204,7 @@ mhd_gtls_compress (comp_hd_t handle, const opaque * plain,
204 204
205 205
206int 206int
207mhd_gtls_decompress (comp_hd_t handle, opaque * compressed, 207MHD_gtls_decompress (comp_hd_t handle, opaque * compressed,
208 size_t compressed_size, opaque ** plain, 208 size_t compressed_size, opaque ** plain,
209 size_t max_record_size) 209 size_t max_record_size)
210{ 210{
@@ -212,7 +212,7 @@ mhd_gtls_decompress (comp_hd_t handle, opaque * compressed,
212 212
213 if (compressed_size > max_record_size + EXTRA_COMP_SIZE) 213 if (compressed_size > max_record_size + EXTRA_COMP_SIZE)
214 { 214 {
215 gnutls_assert (); 215 MHD_gnutls_assert ();
216 return GNUTLS_E_DECOMPRESSION_FAILED; 216 return GNUTLS_E_DECOMPRESSION_FAILED;
217 } 217 }
218 218
@@ -221,7 +221,7 @@ mhd_gtls_decompress (comp_hd_t handle, opaque * compressed,
221 221
222 if (handle == NULL) 222 if (handle == NULL)
223 { 223 {
224 gnutls_assert (); 224 MHD_gnutls_assert ();
225 return GNUTLS_E_INTERNAL_ERROR; 225 return GNUTLS_E_INTERNAL_ERROR;
226 } 226 }
227 227
@@ -247,10 +247,10 @@ mhd_gtls_decompress (comp_hd_t handle, opaque * compressed,
247 do 247 do
248 { 248 {
249 out_size += 512; 249 out_size += 512;
250 *plain = mhd_gtls_realloc_fast (*plain, out_size); 250 *plain = MHD_gtls_realloc_fast (*plain, out_size);
251 if (*plain == NULL) 251 if (*plain == NULL)
252 { 252 {
253 gnutls_assert (); 253 MHD_gnutls_assert ();
254 return GNUTLS_E_MEMORY_ERROR; 254 return GNUTLS_E_MEMORY_ERROR;
255 } 255 }
256 256
@@ -268,8 +268,8 @@ mhd_gtls_decompress (comp_hd_t handle, opaque * compressed,
268 268
269 if (err != Z_OK) 269 if (err != Z_OK)
270 { 270 {
271 gnutls_assert (); 271 MHD_gnutls_assert ();
272 gnutls_free (*plain); 272 MHD_gnutls_free (*plain);
273 *plain = NULL; 273 *plain = NULL;
274 return GNUTLS_E_DECOMPRESSION_FAILED; 274 return GNUTLS_E_DECOMPRESSION_FAILED;
275 } 275 }
@@ -279,14 +279,14 @@ mhd_gtls_decompress (comp_hd_t handle, opaque * compressed,
279 } 279 }
280#endif 280#endif
281 default: 281 default:
282 gnutls_assert (); 282 MHD_gnutls_assert ();
283 return GNUTLS_E_INTERNAL_ERROR; 283 return GNUTLS_E_INTERNAL_ERROR;
284 } /* switch */ 284 } /* switch */
285 285
286 if ((size_t) plain_size > max_record_size) 286 if ((size_t) plain_size > max_record_size)
287 { 287 {
288 gnutls_assert (); 288 MHD_gnutls_assert ();
289 gnutls_free (*plain); 289 MHD_gnutls_free (*plain);
290 *plain = NULL; 290 *plain = NULL;
291 return GNUTLS_E_DECOMPRESSION_FAILED; 291 return GNUTLS_E_DECOMPRESSION_FAILED;
292 } 292 }
diff --git a/src/daemon/https/tls/gnutls_compress_int.h b/src/daemon/https/tls/gnutls_compress_int.h
index 32edae7a..672cb392 100644
--- a/src/daemon/https/tls/gnutls_compress_int.h
+++ b/src/daemon/https/tls/gnutls_compress_int.h
@@ -37,13 +37,13 @@ typedef struct comp_hd_t_STRUCT
37 enum MHD_GNUTLS_CompressionMethod algo; 37 enum MHD_GNUTLS_CompressionMethod algo;
38} *comp_hd_t; 38} *comp_hd_t;
39 39
40comp_hd_t mhd_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod, int d); 40comp_hd_t MHD_gtls_comp_init (enum MHD_GNUTLS_CompressionMethod, int d);
41void mhd_gtls_comp_deinit (comp_hd_t handle, int d); 41void MHD_gtls_comp_deinit (comp_hd_t handle, int d);
42 42
43int mhd_gtls_decompress (comp_hd_t handle, opaque * compressed, 43int MHD_gtls_decompress (comp_hd_t handle, opaque * compressed,
44 size_t compressed_size, opaque ** plain, 44 size_t compressed_size, opaque ** plain,
45 size_t max_record_size); 45 size_t max_record_size);
46int mhd_gtls_compress (comp_hd_t, const opaque * plain, size_t plain_size, 46int MHD_gtls_compress (comp_hd_t, const opaque * plain, size_t plain_size,
47 opaque ** compressed, size_t max_comp_size); 47 opaque ** compressed, size_t max_comp_size);
48 48
49#endif 49#endif
diff --git a/src/daemon/https/tls/gnutls_constate.c b/src/daemon/https/tls/gnutls_constate.c
index 9ace3533..e38b720f 100644
--- a/src/daemon/https/tls/gnutls_constate.c
+++ b/src/daemon/https/tls/gnutls_constate.c
@@ -56,7 +56,7 @@ static const int servwrite_length = sizeof (servwrite) - 1;
56 * (session->cipher_specs) 56 * (session->cipher_specs)
57 */ 57 */
58int 58int
59_gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size, 59MHD__gnutls_set_keys (MHD_gtls_session_t session, int hash_size, int IV_size,
60 int key_size, int export_flag) 60 int key_size, int export_flag)
61{ 61{
62 62
@@ -82,10 +82,10 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
82 if (export_flag == 0) 82 if (export_flag == 0)
83 block_size += 2 * IV_size; 83 block_size += 2 * IV_size;
84 84
85 key_block = gnutls_secure_malloc (block_size); 85 key_block = MHD_gnutls_secure_malloc (block_size);
86 if (key_block == NULL) 86 if (key_block == NULL)
87 { 87 {
88 gnutls_assert (); 88 MHD_gnutls_assert ();
89 return GNUTLS_E_MEMORY_ERROR; 89 return GNUTLS_E_MEMORY_ERROR;
90 } 90 }
91 91
@@ -100,46 +100,46 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
100 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3) 100 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3)
101 { /* SSL 3 */ 101 { /* SSL 3 */
102 ret = 102 ret =
103 mhd_gnutls_ssl3_generate_random 103 MHD_gnutls_ssl3_generate_random
104 (session->security_parameters.master_secret, TLS_MASTER_SIZE, rnd, 104 (session->security_parameters.master_secret, TLS_MASTER_SIZE, rnd,
105 2 * TLS_RANDOM_SIZE, block_size, key_block); 105 2 * TLS_RANDOM_SIZE, block_size, key_block);
106 } 106 }
107 else 107 else
108 { /* TLS 1.0 */ 108 { /* TLS 1.0 */
109 ret = 109 ret =
110 mhd_gtls_PRF (session, session->security_parameters.master_secret, 110 MHD_gtls_PRF (session, session->security_parameters.master_secret,
111 TLS_MASTER_SIZE, keyexp, keyexp_length, 111 TLS_MASTER_SIZE, keyexp, keyexp_length,
112 rnd, 2 * TLS_RANDOM_SIZE, block_size, key_block); 112 rnd, 2 * TLS_RANDOM_SIZE, block_size, key_block);
113 } 113 }
114 114
115 if (ret < 0) 115 if (ret < 0)
116 { 116 {
117 gnutls_assert (); 117 MHD_gnutls_assert ();
118 gnutls_free (key_block); 118 MHD_gnutls_free (key_block);
119 return ret; 119 return ret;
120 } 120 }
121 121
122 _gnutls_hard_log ("INT: KEY BLOCK[%d]: %s\n", block_size, 122 MHD__gnutls_hard_log ("INT: KEY BLOCK[%d]: %s\n", block_size,
123 mhd_gtls_bin2hex (key_block, block_size, buf, 123 MHD_gtls_bin2hex (key_block, block_size, buf,
124 sizeof (buf))); 124 sizeof (buf)));
125 125
126 pos = 0; 126 pos = 0;
127 if (hash_size > 0) 127 if (hash_size > 0)
128 { 128 {
129 if (_gnutls_sset_datum 129 if (MHD__gnutls_sset_datum
130 (&session->cipher_specs.client_write_mac_secret, 130 (&session->cipher_specs.client_write_mac_secret,
131 &key_block[pos], hash_size) < 0) 131 &key_block[pos], hash_size) < 0)
132 { 132 {
133 gnutls_free (key_block); 133 MHD_gnutls_free (key_block);
134 return GNUTLS_E_MEMORY_ERROR; 134 return GNUTLS_E_MEMORY_ERROR;
135 } 135 }
136 pos += hash_size; 136 pos += hash_size;
137 137
138 if (_gnutls_sset_datum 138 if (MHD__gnutls_sset_datum
139 (&session->cipher_specs.server_write_mac_secret, 139 (&session->cipher_specs.server_write_mac_secret,
140 &key_block[pos], hash_size) < 0) 140 &key_block[pos], hash_size) < 0)
141 { 141 {
142 gnutls_free (key_block); 142 MHD_gnutls_free (key_block);
143 return GNUTLS_E_MEMORY_ERROR; 143 return GNUTLS_E_MEMORY_ERROR;
144 } 144 }
145 pos += hash_size; 145 pos += hash_size;
@@ -168,20 +168,20 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
168 { /* export */ 168 { /* export */
169 free_keys = 1; 169 free_keys = 1;
170 170
171 client_write_key = gnutls_secure_malloc (EXPORT_FINAL_KEY_SIZE); 171 client_write_key = MHD_gnutls_secure_malloc (EXPORT_FINAL_KEY_SIZE);
172 if (client_write_key == NULL) 172 if (client_write_key == NULL)
173 { 173 {
174 gnutls_assert (); 174 MHD_gnutls_assert ();
175 gnutls_free (key_block); 175 MHD_gnutls_free (key_block);
176 return GNUTLS_E_MEMORY_ERROR; 176 return GNUTLS_E_MEMORY_ERROR;
177 } 177 }
178 178
179 server_write_key = gnutls_secure_malloc (EXPORT_FINAL_KEY_SIZE); 179 server_write_key = MHD_gnutls_secure_malloc (EXPORT_FINAL_KEY_SIZE);
180 if (server_write_key == NULL) 180 if (server_write_key == NULL)
181 { 181 {
182 gnutls_assert (); 182 MHD_gnutls_assert ();
183 gnutls_free (key_block); 183 MHD_gnutls_free (key_block);
184 gnutls_free (client_write_key); 184 MHD_gnutls_free (client_write_key);
185 return GNUTLS_E_MEMORY_ERROR; 185 return GNUTLS_E_MEMORY_ERROR;
186 } 186 }
187 187
@@ -190,7 +190,7 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
190 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3) 190 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3)
191 { /* SSL 3 */ 191 { /* SSL 3 */
192 ret = 192 ret =
193 mhd_gnutls_ssl3_hash_md5 (&key_block[pos], 193 MHD_gnutls_ssl3_hash_md5 (&key_block[pos],
194 key_size, rrnd, 194 key_size, rrnd,
195 2 * TLS_RANDOM_SIZE, 195 2 * TLS_RANDOM_SIZE,
196 EXPORT_FINAL_KEY_SIZE, 196 EXPORT_FINAL_KEY_SIZE,
@@ -200,7 +200,7 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
200 else 200 else
201 { /* TLS 1.0 */ 201 { /* TLS 1.0 */
202 ret = 202 ret =
203 mhd_gtls_PRF (session, &key_block[pos], key_size, 203 MHD_gtls_PRF (session, &key_block[pos], key_size,
204 cliwrite, cliwrite_length, 204 cliwrite, cliwrite_length,
205 rrnd, 205 rrnd,
206 2 * TLS_RANDOM_SIZE, 206 2 * TLS_RANDOM_SIZE,
@@ -209,10 +209,10 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
209 209
210 if (ret < 0) 210 if (ret < 0)
211 { 211 {
212 gnutls_assert (); 212 MHD_gnutls_assert ();
213 gnutls_free (key_block); 213 MHD_gnutls_free (key_block);
214 gnutls_free (server_write_key); 214 MHD_gnutls_free (server_write_key);
215 gnutls_free (client_write_key); 215 MHD_gnutls_free (client_write_key);
216 return ret; 216 return ret;
217 } 217 }
218 218
@@ -222,7 +222,7 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
222 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3) 222 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3)
223 { /* SSL 3 */ 223 { /* SSL 3 */
224 ret = 224 ret =
225 mhd_gnutls_ssl3_hash_md5 (&key_block[pos], key_size, 225 MHD_gnutls_ssl3_hash_md5 (&key_block[pos], key_size,
226 rnd, 2 * TLS_RANDOM_SIZE, 226 rnd, 2 * TLS_RANDOM_SIZE,
227 EXPORT_FINAL_KEY_SIZE, 227 EXPORT_FINAL_KEY_SIZE,
228 server_write_key); 228 server_write_key);
@@ -230,7 +230,7 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
230 else 230 else
231 { /* TLS 1.0 */ 231 { /* TLS 1.0 */
232 ret = 232 ret =
233 mhd_gtls_PRF (session, &key_block[pos], key_size, 233 MHD_gtls_PRF (session, &key_block[pos], key_size,
234 servwrite, servwrite_length, 234 servwrite, servwrite_length,
235 rrnd, 2 * TLS_RANDOM_SIZE, 235 rrnd, 2 * TLS_RANDOM_SIZE,
236 EXPORT_FINAL_KEY_SIZE, server_write_key); 236 EXPORT_FINAL_KEY_SIZE, server_write_key);
@@ -238,10 +238,10 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
238 238
239 if (ret < 0) 239 if (ret < 0)
240 { 240 {
241 gnutls_assert (); 241 MHD_gnutls_assert ();
242 gnutls_free (key_block); 242 MHD_gnutls_free (key_block);
243 gnutls_free (server_write_key); 243 MHD_gnutls_free (server_write_key);
244 gnutls_free (client_write_key); 244 MHD_gnutls_free (client_write_key);
245 return ret; 245 return ret;
246 } 246 }
247 247
@@ -249,41 +249,41 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
249 pos += key_size; 249 pos += key_size;
250 } 250 }
251 251
252 if (_gnutls_sset_datum 252 if (MHD__gnutls_sset_datum
253 (&session->cipher_specs.client_write_key, 253 (&session->cipher_specs.client_write_key,
254 client_write_key, client_write_key_size) < 0) 254 client_write_key, client_write_key_size) < 0)
255 { 255 {
256 gnutls_free (key_block); 256 MHD_gnutls_free (key_block);
257 gnutls_free (server_write_key); 257 MHD_gnutls_free (server_write_key);
258 gnutls_free (client_write_key); 258 MHD_gnutls_free (client_write_key);
259 return GNUTLS_E_MEMORY_ERROR; 259 return GNUTLS_E_MEMORY_ERROR;
260 } 260 }
261 _gnutls_hard_log ("INT: CLIENT WRITE KEY [%d]: %s\n", 261 MHD__gnutls_hard_log ("INT: CLIENT WRITE KEY [%d]: %s\n",
262 client_write_key_size, 262 client_write_key_size,
263 mhd_gtls_bin2hex (client_write_key, 263 MHD_gtls_bin2hex (client_write_key,
264 client_write_key_size, buf, 264 client_write_key_size, buf,
265 sizeof (buf))); 265 sizeof (buf)));
266 266
267 if (_gnutls_sset_datum 267 if (MHD__gnutls_sset_datum
268 (&session->cipher_specs.server_write_key, 268 (&session->cipher_specs.server_write_key,
269 server_write_key, server_write_key_size) < 0) 269 server_write_key, server_write_key_size) < 0)
270 { 270 {
271 gnutls_free (key_block); 271 MHD_gnutls_free (key_block);
272 gnutls_free (server_write_key); 272 MHD_gnutls_free (server_write_key);
273 gnutls_free (client_write_key); 273 MHD_gnutls_free (client_write_key);
274 return GNUTLS_E_MEMORY_ERROR; 274 return GNUTLS_E_MEMORY_ERROR;
275 } 275 }
276 276
277 _gnutls_hard_log ("INT: SERVER WRITE KEY [%d]: %s\n", 277 MHD__gnutls_hard_log ("INT: SERVER WRITE KEY [%d]: %s\n",
278 server_write_key_size, 278 server_write_key_size,
279 mhd_gtls_bin2hex (server_write_key, 279 MHD_gtls_bin2hex (server_write_key,
280 server_write_key_size, buf, 280 server_write_key_size, buf,
281 sizeof (buf))); 281 sizeof (buf)));
282 282
283 if (free_keys != 0) 283 if (free_keys != 0)
284 { 284 {
285 gnutls_free (server_write_key); 285 MHD_gnutls_free (server_write_key);
286 gnutls_free (client_write_key); 286 MHD_gnutls_free (client_write_key);
287 } 287 }
288 } 288 }
289 289
@@ -292,20 +292,20 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
292 */ 292 */
293 if (IV_size > 0 && export_flag == 0) 293 if (IV_size > 0 && export_flag == 0)
294 { 294 {
295 if (_gnutls_sset_datum 295 if (MHD__gnutls_sset_datum
296 (&session->cipher_specs.client_write_IV, &key_block[pos], 296 (&session->cipher_specs.client_write_IV, &key_block[pos],
297 IV_size) < 0) 297 IV_size) < 0)
298 { 298 {
299 gnutls_free (key_block); 299 MHD_gnutls_free (key_block);
300 return GNUTLS_E_MEMORY_ERROR; 300 return GNUTLS_E_MEMORY_ERROR;
301 } 301 }
302 pos += IV_size; 302 pos += IV_size;
303 303
304 if (_gnutls_sset_datum 304 if (MHD__gnutls_sset_datum
305 (&session->cipher_specs.server_write_IV, &key_block[pos], 305 (&session->cipher_specs.server_write_IV, &key_block[pos],
306 IV_size) < 0) 306 IV_size) < 0)
307 { 307 {
308 gnutls_free (key_block); 308 MHD_gnutls_free (key_block);
309 return GNUTLS_E_MEMORY_ERROR; 309 return GNUTLS_E_MEMORY_ERROR;
310 } 310 }
311 pos += IV_size; 311 pos += IV_size;
@@ -313,69 +313,69 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
313 } 313 }
314 else if (IV_size > 0 && export_flag != 0) 314 else if (IV_size > 0 && export_flag != 0)
315 { 315 {
316 opaque *iv_block = gnutls_alloca (IV_size * 2); 316 opaque *iv_block = MHD_gnutls_alloca (IV_size * 2);
317 if (iv_block == NULL) 317 if (iv_block == NULL)
318 { 318 {
319 gnutls_assert (); 319 MHD_gnutls_assert ();
320 gnutls_free (key_block); 320 MHD_gnutls_free (key_block);
321 return GNUTLS_E_MEMORY_ERROR; 321 return GNUTLS_E_MEMORY_ERROR;
322 } 322 }
323 323
324 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3) 324 if (session->security_parameters.version == MHD_GNUTLS_PROTOCOL_SSL3)
325 { /* SSL 3 */ 325 { /* SSL 3 */
326 ret = mhd_gnutls_ssl3_hash_md5 ("", 0, 326 ret = MHD_gnutls_ssl3_hash_md5 ("", 0,
327 rrnd, TLS_RANDOM_SIZE * 2, 327 rrnd, TLS_RANDOM_SIZE * 2,
328 IV_size, iv_block); 328 IV_size, iv_block);
329 329
330 if (ret < 0) 330 if (ret < 0)
331 { 331 {
332 gnutls_assert (); 332 MHD_gnutls_assert ();
333 gnutls_free (key_block); 333 MHD_gnutls_free (key_block);
334 gnutls_afree (iv_block); 334 MHD_gnutls_afree (iv_block);
335 return ret; 335 return ret;
336 } 336 }
337 337
338 ret = mhd_gnutls_ssl3_hash_md5 ("", 0, rnd, 338 ret = MHD_gnutls_ssl3_hash_md5 ("", 0, rnd,
339 TLS_RANDOM_SIZE * 2, 339 TLS_RANDOM_SIZE * 2,
340 IV_size, &iv_block[IV_size]); 340 IV_size, &iv_block[IV_size]);
341 341
342 } 342 }
343 else 343 else
344 { /* TLS 1.0 */ 344 { /* TLS 1.0 */
345 ret = mhd_gtls_PRF (session, "", 0, 345 ret = MHD_gtls_PRF (session, "", 0,
346 ivblock, ivblock_length, rrnd, 346 ivblock, ivblock_length, rrnd,
347 2 * TLS_RANDOM_SIZE, IV_size * 2, iv_block); 347 2 * TLS_RANDOM_SIZE, IV_size * 2, iv_block);
348 } 348 }
349 349
350 if (ret < 0) 350 if (ret < 0)
351 { 351 {
352 gnutls_assert (); 352 MHD_gnutls_assert ();
353 gnutls_afree (iv_block); 353 MHD_gnutls_afree (iv_block);
354 gnutls_free (key_block); 354 MHD_gnutls_free (key_block);
355 return ret; 355 return ret;
356 } 356 }
357 357
358 if (_gnutls_sset_datum 358 if (MHD__gnutls_sset_datum
359 (&session->cipher_specs.client_write_IV, iv_block, IV_size) < 0) 359 (&session->cipher_specs.client_write_IV, iv_block, IV_size) < 0)
360 { 360 {
361 gnutls_afree (iv_block); 361 MHD_gnutls_afree (iv_block);
362 gnutls_free (key_block); 362 MHD_gnutls_free (key_block);
363 return GNUTLS_E_MEMORY_ERROR; 363 return GNUTLS_E_MEMORY_ERROR;
364 } 364 }
365 365
366 if (_gnutls_sset_datum 366 if (MHD__gnutls_sset_datum
367 (&session->cipher_specs.server_write_IV, 367 (&session->cipher_specs.server_write_IV,
368 &iv_block[IV_size], IV_size) < 0) 368 &iv_block[IV_size], IV_size) < 0)
369 { 369 {
370 gnutls_afree (iv_block); 370 MHD_gnutls_afree (iv_block);
371 gnutls_free (key_block); 371 MHD_gnutls_free (key_block);
372 return GNUTLS_E_MEMORY_ERROR; 372 return GNUTLS_E_MEMORY_ERROR;
373 } 373 }
374 374
375 gnutls_afree (iv_block); 375 MHD_gnutls_afree (iv_block);
376 } 376 }
377 377
378 gnutls_free (key_block); 378 MHD_gnutls_free (key_block);
379 379
380 session->cipher_specs.generated_keys = 1; 380 session->cipher_specs.generated_keys = 1;
381 381
@@ -383,7 +383,7 @@ _gnutls_set_keys (mhd_gtls_session_t session, int hash_size, int IV_size,
383} 383}
384 384
385int 385int
386_gnutls_set_read_keys (mhd_gtls_session_t session) 386MHD__gnutls_set_read_keys (MHD_gtls_session_t session)
387{ 387{
388 int hash_size; 388 int hash_size;
389 int IV_size; 389 int IV_size;
@@ -394,17 +394,17 @@ _gnutls_set_read_keys (mhd_gtls_session_t session)
394 mac_algo = session->security_parameters.read_mac_algorithm; 394 mac_algo = session->security_parameters.read_mac_algorithm;
395 algo = session->security_parameters.read_bulk_cipher_algorithm; 395 algo = session->security_parameters.read_bulk_cipher_algorithm;
396 396
397 hash_size = mhd_gnutls_hash_get_algo_len (mac_algo); 397 hash_size = MHD_gnutls_hash_get_algo_len (mac_algo);
398 IV_size = mhd_gtls_cipher_get_iv_size (algo); 398 IV_size = MHD_gtls_cipher_get_iv_size (algo);
399 key_size = MHD_gnutls_cipher_get_key_size (algo); 399 key_size = MHD__gnutls_cipher_get_key_size (algo);
400 export_flag = mhd_gtls_cipher_get_export_flag (algo); 400 export_flag = MHD_gtls_cipher_get_export_flag (algo);
401 401
402 return _gnutls_set_keys (session, hash_size, IV_size, key_size, 402 return MHD__gnutls_set_keys (session, hash_size, IV_size, key_size,
403 export_flag); 403 export_flag);
404} 404}
405 405
406int 406int
407_gnutls_set_write_keys (mhd_gtls_session_t session) 407MHD__gnutls_set_write_keys (MHD_gtls_session_t session)
408{ 408{
409 int hash_size; 409 int hash_size;
410 int IV_size; 410 int IV_size;
@@ -415,12 +415,12 @@ _gnutls_set_write_keys (mhd_gtls_session_t session)
415 mac_algo = session->security_parameters.write_mac_algorithm; 415 mac_algo = session->security_parameters.write_mac_algorithm;
416 algo = session->security_parameters.write_bulk_cipher_algorithm; 416 algo = session->security_parameters.write_bulk_cipher_algorithm;
417 417
418 hash_size = mhd_gnutls_hash_get_algo_len (mac_algo); 418 hash_size = MHD_gnutls_hash_get_algo_len (mac_algo);
419 IV_size = mhd_gtls_cipher_get_iv_size (algo); 419 IV_size = MHD_gtls_cipher_get_iv_size (algo);
420 key_size = MHD_gnutls_cipher_get_key_size (algo); 420 key_size = MHD__gnutls_cipher_get_key_size (algo);
421 export_flag = mhd_gtls_cipher_get_export_flag (algo); 421 export_flag = MHD_gtls_cipher_get_export_flag (algo);
422 422
423 return _gnutls_set_keys (session, hash_size, IV_size, key_size, 423 return MHD__gnutls_set_keys (session, hash_size, IV_size, key_size,
424 export_flag); 424 export_flag);
425} 425}
426 426
@@ -437,12 +437,12 @@ _gnutls_set_write_keys (mhd_gtls_session_t session)
437 dst->max_record_recv_size = src->max_record_recv_size; \ 437 dst->max_record_recv_size = src->max_record_recv_size; \
438 dst->max_record_send_size = src->max_record_send_size; \ 438 dst->max_record_send_size = src->max_record_send_size; \
439 dst->version = src->version; \ 439 dst->version = src->version; \
440 memcpy( &dst->extensions, &src->extensions, sizeof(mhd_gtls_ext_st)); \ 440 memcpy( &dst->extensions, &src->extensions, sizeof(MHD_gtls_ext_st)); \
441 memcpy( &dst->inner_secret, &src->inner_secret, TLS_MASTER_SIZE); 441 memcpy( &dst->inner_secret, &src->inner_secret, TLS_MASTER_SIZE);
442 442
443static void 443static void
444_gnutls_cpy_read_security_parameters (mhd_gtls_security_param_st * 444MHD__gnutls_cpy_read_security_parameters (MHD_gtls_security_param_st *
445 dst, mhd_gtls_security_param_st * src) 445 dst, MHD_gtls_security_param_st * src)
446{ 446{
447 CPY_COMMON; 447 CPY_COMMON;
448 448
@@ -452,8 +452,8 @@ _gnutls_cpy_read_security_parameters (mhd_gtls_security_param_st *
452} 452}
453 453
454static void 454static void
455_gnutls_cpy_write_security_parameters (mhd_gtls_security_param_st * 455MHD__gnutls_cpy_write_security_parameters (MHD_gtls_security_param_st *
456 dst, mhd_gtls_security_param_st * src) 456 dst, MHD_gtls_security_param_st * src)
457{ 457{
458 CPY_COMMON; 458 CPY_COMMON;
459 459
@@ -469,15 +469,15 @@ _gnutls_cpy_write_security_parameters (mhd_gtls_security_param_st *
469 * This is to be called after sending the Change Cipher Spec packet. 469 * This is to be called after sending the Change Cipher Spec packet.
470 */ 470 */
471int 471int
472mhd_gtls_connection_state_init (mhd_gtls_session_t session) 472MHD_gtls_connection_state_init (MHD_gtls_session_t session)
473{ 473{
474 int ret; 474 int ret;
475 475
476/* Setup the master secret 476/* Setup the master secret
477 */ 477 */
478 if ((ret = mhd_gtls_generate_master (session, 0), 0) < 0) 478 if ((ret = MHD_gtls_generate_master (session, 0), 0) < 0)
479 { 479 {
480 gnutls_assert (); 480 MHD_gnutls_assert ();
481 return ret; 481 return ret;
482 } 482 }
483 483
@@ -490,39 +490,39 @@ mhd_gtls_connection_state_init (mhd_gtls_session_t session)
490 * (read encrypted data) 490 * (read encrypted data)
491 */ 491 */
492int 492int
493mhd_gtls_read_connection_state_init (mhd_gtls_session_t session) 493MHD_gtls_read_connection_state_init (MHD_gtls_session_t session)
494{ 494{
495 int mac_size; 495 int mac_size;
496 int rc; 496 int rc;
497 497
498 _gnutls_uint64zero (session->connection_state.read_sequence_number); 498 MHD__gnutls_uint64zero (session->connection_state.read_sequence_number);
499 499
500/* Update internals from CipherSuite selected. 500/* Update internals from CipherSuite selected.
501 * If we are resuming just copy the connection session 501 * If we are resuming just copy the connection session
502 */ 502 */
503 if (session->internals.resumed == RESUME_FALSE) 503 if (session->internals.resumed == RESUME_FALSE)
504 { 504 {
505 rc = mhd_gtls_set_read_cipher (session, 505 rc = MHD_gtls_set_read_cipher (session,
506 mhd_gtls_cipher_suite_get_cipher_algo 506 MHD_gtls_cipher_suite_get_cipher_algo
507 (&session->security_parameters. 507 (&session->security_parameters.
508 current_cipher_suite)); 508 current_cipher_suite));
509 if (rc < 0) 509 if (rc < 0)
510 return rc; 510 return rc;
511 rc = mhd_gtls_set_read_mac (session, 511 rc = MHD_gtls_set_read_mac (session,
512 mhd_gtls_cipher_suite_get_mac_algo 512 MHD_gtls_cipher_suite_get_mac_algo
513 (&session->security_parameters. 513 (&session->security_parameters.
514 current_cipher_suite)); 514 current_cipher_suite));
515 if (rc < 0) 515 if (rc < 0)
516 return rc; 516 return rc;
517 517
518 rc = mhd_gtls_set_kx (session, 518 rc = MHD_gtls_set_kx (session,
519 mhd_gtls_cipher_suite_get_kx_algo 519 MHD_gtls_cipher_suite_get_kx_algo
520 (&session->security_parameters. 520 (&session->security_parameters.
521 current_cipher_suite)); 521 current_cipher_suite));
522 if (rc < 0) 522 if (rc < 0)
523 return rc; 523 return rc;
524 524
525 rc = mhd_gtls_set_read_compression (session, 525 rc = MHD_gtls_set_read_compression (session,
526 session->internals. 526 session->internals.
527 compression_method); 527 compression_method);
528 if (rc < 0) 528 if (rc < 0)
@@ -530,54 +530,54 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
530 } 530 }
531 else 531 else
532 { /* RESUME_TRUE */ 532 { /* RESUME_TRUE */
533 _gnutls_cpy_read_security_parameters (&session->security_parameters, 533 MHD__gnutls_cpy_read_security_parameters (&session->security_parameters,
534 &session->internals. 534 &session->internals.
535 resumed_security_parameters); 535 resumed_security_parameters);
536 } 536 }
537 537
538 538
539 rc = _gnutls_set_read_keys (session); 539 rc = MHD__gnutls_set_read_keys (session);
540 if (rc < 0) 540 if (rc < 0)
541 return rc; 541 return rc;
542 542
543 _gnutls_handshake_log ("HSK[%x]: Cipher Suite: %s\n", 543 MHD__gnutls_handshake_log ("HSK[%x]: Cipher Suite: %s\n",
544 session, 544 session,
545 mhd_gtls_cipher_suite_get_name 545 MHD_gtls_cipher_suite_get_name
546 (&session->security_parameters. 546 (&session->security_parameters.
547 current_cipher_suite)); 547 current_cipher_suite));
548 548
549 if (mhd_gtls_compression_is_ok 549 if (MHD_gtls_compression_is_ok
550 (session->security_parameters.read_compression_algorithm) != 0) 550 (session->security_parameters.read_compression_algorithm) != 0)
551 { 551 {
552 gnutls_assert (); 552 MHD_gnutls_assert ();
553 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 553 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
554 } 554 }
555 555
556 if (mhd_gnutls_mac_is_ok 556 if (MHD_gnutls_mac_is_ok
557 (session->security_parameters.read_mac_algorithm) != 0) 557 (session->security_parameters.read_mac_algorithm) != 0)
558 { 558 {
559 gnutls_assert (); 559 MHD_gnutls_assert ();
560 return GNUTLS_E_INTERNAL_ERROR; 560 return GNUTLS_E_INTERNAL_ERROR;
561 } 561 }
562 562
563 /* Free all the previous keys/ sessions etc. 563 /* Free all the previous keys/ sessions etc.
564 */ 564 */
565 if (session->connection_state.read_mac_secret.data != NULL) 565 if (session->connection_state.read_mac_secret.data != NULL)
566 _gnutls_free_datum (&session->connection_state.read_mac_secret); 566 MHD__gnutls_free_datum (&session->connection_state.read_mac_secret);
567 567
568 if (session->connection_state.read_cipher_state != NULL) 568 if (session->connection_state.read_cipher_state != NULL)
569 mhd_gnutls_cipher_deinit (session->connection_state.read_cipher_state); 569 MHD_gnutls_cipher_deinit (session->connection_state.read_cipher_state);
570 570
571 if (session->connection_state.read_compression_state != NULL) 571 if (session->connection_state.read_compression_state != NULL)
572 mhd_gtls_comp_deinit (session->connection_state.read_compression_state, 572 MHD_gtls_comp_deinit (session->connection_state.read_compression_state,
573 1); 573 1);
574 574
575 575
576 mac_size = 576 mac_size =
577 mhd_gnutls_hash_get_algo_len (session->security_parameters. 577 MHD_gnutls_hash_get_algo_len (session->security_parameters.
578 read_mac_algorithm); 578 read_mac_algorithm);
579 579
580 _gnutls_handshake_log 580 MHD__gnutls_handshake_log
581 ("HSK[%x]: Initializing internal [read] cipher sessions\n", session); 581 ("HSK[%x]: Initializing internal [read] cipher sessions\n", session);
582 582
583 switch (session->security_parameters.entity) 583 switch (session->security_parameters.entity)
@@ -586,7 +586,7 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
586 /* initialize cipher session 586 /* initialize cipher session
587 */ 587 */
588 session->connection_state.read_cipher_state = 588 session->connection_state.read_cipher_state =
589 mhd_gtls_cipher_init (session->security_parameters. 589 MHD_gtls_cipher_init (session->security_parameters.
590 read_bulk_cipher_algorithm, 590 read_bulk_cipher_algorithm,
591 &session->cipher_specs.client_write_key, 591 &session->cipher_specs.client_write_key,
592 &session->cipher_specs.client_write_IV); 592 &session->cipher_specs.client_write_IV);
@@ -594,7 +594,7 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
594 && session->security_parameters.read_bulk_cipher_algorithm != 594 && session->security_parameters.read_bulk_cipher_algorithm !=
595 MHD_GNUTLS_CIPHER_NULL) 595 MHD_GNUTLS_CIPHER_NULL)
596 { 596 {
597 gnutls_assert (); 597 MHD_gnutls_assert ();
598 return GNUTLS_E_INTERNAL_ERROR; 598 return GNUTLS_E_INTERNAL_ERROR;
599 } 599 }
600 600
@@ -603,13 +603,13 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
603 */ 603 */
604 if (mac_size > 0) 604 if (mac_size > 0)
605 { 605 {
606 if (_gnutls_sset_datum (&session->connection_state.read_mac_secret, 606 if (MHD__gnutls_sset_datum (&session->connection_state.read_mac_secret,
607 session->cipher_specs. 607 session->cipher_specs.
608 client_write_mac_secret.data, 608 client_write_mac_secret.data,
609 session->cipher_specs. 609 session->cipher_specs.
610 client_write_mac_secret.size) < 0) 610 client_write_mac_secret.size) < 0)
611 { 611 {
612 gnutls_assert (); 612 MHD_gnutls_assert ();
613 return GNUTLS_E_MEMORY_ERROR; 613 return GNUTLS_E_MEMORY_ERROR;
614 } 614 }
615 615
@@ -619,7 +619,7 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
619#if MHD_DEBUG_TLS 619#if MHD_DEBUG_TLS
620 case GNUTLS_CLIENT: 620 case GNUTLS_CLIENT:
621 session->connection_state.read_cipher_state = 621 session->connection_state.read_cipher_state =
622 mhd_gtls_cipher_init (session->security_parameters. 622 MHD_gtls_cipher_init (session->security_parameters.
623 read_bulk_cipher_algorithm, 623 read_bulk_cipher_algorithm,
624 &session->cipher_specs.server_write_key, 624 &session->cipher_specs.server_write_key,
625 &session->cipher_specs.server_write_IV); 625 &session->cipher_specs.server_write_IV);
@@ -629,7 +629,7 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
629 && session->security_parameters.read_bulk_cipher_algorithm != 629 && session->security_parameters.read_bulk_cipher_algorithm !=
630 MHD_GNUTLS_CIPHER_NULL) 630 MHD_GNUTLS_CIPHER_NULL)
631 { 631 {
632 gnutls_assert (); 632 MHD_gnutls_assert ();
633 return GNUTLS_E_INTERNAL_ERROR; 633 return GNUTLS_E_INTERNAL_ERROR;
634 } 634 }
635 635
@@ -638,13 +638,13 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
638 */ 638 */
639 if (mac_size > 0) 639 if (mac_size > 0)
640 { 640 {
641 if (_gnutls_sset_datum (&session->connection_state.read_mac_secret, 641 if (MHD__gnutls_sset_datum (&session->connection_state.read_mac_secret,
642 session->cipher_specs. 642 session->cipher_specs.
643 server_write_mac_secret.data, 643 server_write_mac_secret.data,
644 session->cipher_specs. 644 session->cipher_specs.
645 server_write_mac_secret.size) < 0) 645 server_write_mac_secret.size) < 0)
646 { 646 {
647 gnutls_assert (); 647 MHD_gnutls_assert ();
648 return GNUTLS_E_MEMORY_ERROR; 648 return GNUTLS_E_MEMORY_ERROR;
649 } 649 }
650 } 650 }
@@ -652,17 +652,17 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
652 break; 652 break;
653#endif 653#endif
654 default: /* this check is useless */ 654 default: /* this check is useless */
655 gnutls_assert (); 655 MHD_gnutls_assert ();
656 return GNUTLS_E_INTERNAL_ERROR; 656 return GNUTLS_E_INTERNAL_ERROR;
657 } 657 }
658 658
659 session->connection_state.read_compression_state = 659 session->connection_state.read_compression_state =
660 mhd_gtls_comp_init (session->security_parameters. 660 MHD_gtls_comp_init (session->security_parameters.
661 read_compression_algorithm, 1); 661 read_compression_algorithm, 1);
662 662
663 if (session->connection_state.read_compression_state == GNUTLS_COMP_FAILED) 663 if (session->connection_state.read_compression_state == GNUTLS_COMP_FAILED)
664 { 664 {
665 gnutls_assert (); 665 MHD_gnutls_assert ();
666 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 666 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
667 } 667 }
668 668
@@ -675,39 +675,39 @@ mhd_gtls_read_connection_state_init (mhd_gtls_session_t session)
675 * (write encrypted data) 675 * (write encrypted data)
676 */ 676 */
677int 677int
678mhd_gtls_write_connection_state_init (mhd_gtls_session_t session) 678MHD_gtls_write_connection_state_init (MHD_gtls_session_t session)
679{ 679{
680 int mac_size; 680 int mac_size;
681 int rc; 681 int rc;
682 682
683 _gnutls_uint64zero (session->connection_state.write_sequence_number); 683 MHD__gnutls_uint64zero (session->connection_state.write_sequence_number);
684 684
685/* Update internals from CipherSuite selected. 685/* Update internals from CipherSuite selected.
686 * If we are resuming just copy the connection session 686 * If we are resuming just copy the connection session
687 */ 687 */
688 if (session->internals.resumed == RESUME_FALSE) 688 if (session->internals.resumed == RESUME_FALSE)
689 { 689 {
690 rc = mhd_gtls_set_write_cipher (session, 690 rc = MHD_gtls_set_write_cipher (session,
691 mhd_gtls_cipher_suite_get_cipher_algo 691 MHD_gtls_cipher_suite_get_cipher_algo
692 (&session->security_parameters. 692 (&session->security_parameters.
693 current_cipher_suite)); 693 current_cipher_suite));
694 if (rc < 0) 694 if (rc < 0)
695 return rc; 695 return rc;
696 rc = mhd_gtls_set_write_mac (session, 696 rc = MHD_gtls_set_write_mac (session,
697 mhd_gtls_cipher_suite_get_mac_algo 697 MHD_gtls_cipher_suite_get_mac_algo
698 (&session->security_parameters. 698 (&session->security_parameters.
699 current_cipher_suite)); 699 current_cipher_suite));
700 if (rc < 0) 700 if (rc < 0)
701 return rc; 701 return rc;
702 702
703 rc = mhd_gtls_set_kx (session, 703 rc = MHD_gtls_set_kx (session,
704 mhd_gtls_cipher_suite_get_kx_algo 704 MHD_gtls_cipher_suite_get_kx_algo
705 (&session->security_parameters. 705 (&session->security_parameters.
706 current_cipher_suite)); 706 current_cipher_suite));
707 if (rc < 0) 707 if (rc < 0)
708 return rc; 708 return rc;
709 709
710 rc = mhd_gtls_set_write_compression (session, 710 rc = MHD_gtls_set_write_compression (session,
711 session->internals. 711 session->internals.
712 compression_method); 712 compression_method);
713 if (rc < 0) 713 if (rc < 0)
@@ -715,31 +715,31 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
715 } 715 }
716 else 716 else
717 { /* RESUME_TRUE */ 717 { /* RESUME_TRUE */
718 _gnutls_cpy_write_security_parameters (&session->security_parameters, 718 MHD__gnutls_cpy_write_security_parameters (&session->security_parameters,
719 &session->internals. 719 &session->internals.
720 resumed_security_parameters); 720 resumed_security_parameters);
721 } 721 }
722 722
723 rc = _gnutls_set_write_keys (session); 723 rc = MHD__gnutls_set_write_keys (session);
724 if (rc < 0) 724 if (rc < 0)
725 return rc; 725 return rc;
726 726
727 _gnutls_handshake_log ("HSK[%x]: Cipher Suite: %s\n", session, 727 MHD__gnutls_handshake_log ("HSK[%x]: Cipher Suite: %s\n", session,
728 mhd_gtls_cipher_suite_get_name 728 MHD_gtls_cipher_suite_get_name
729 (&session->security_parameters. 729 (&session->security_parameters.
730 current_cipher_suite)); 730 current_cipher_suite));
731 731
732 if (mhd_gtls_compression_is_ok 732 if (MHD_gtls_compression_is_ok
733 (session->security_parameters.write_compression_algorithm) != 0) 733 (session->security_parameters.write_compression_algorithm) != 0)
734 { 734 {
735 gnutls_assert (); 735 MHD_gnutls_assert ();
736 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 736 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
737 } 737 }
738 738
739 if (mhd_gnutls_mac_is_ok 739 if (MHD_gnutls_mac_is_ok
740 (session->security_parameters.write_mac_algorithm) != 0) 740 (session->security_parameters.write_mac_algorithm) != 0)
741 { 741 {
742 gnutls_assert (); 742 MHD_gnutls_assert ();
743 return GNUTLS_E_INTERNAL_ERROR; 743 return GNUTLS_E_INTERNAL_ERROR;
744 } 744 }
745 745
@@ -748,20 +748,20 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
748 /* Free all the previous keys/ sessions etc. 748 /* Free all the previous keys/ sessions etc.
749 */ 749 */
750 if (session->connection_state.write_mac_secret.data != NULL) 750 if (session->connection_state.write_mac_secret.data != NULL)
751 _gnutls_free_datum (&session->connection_state.write_mac_secret); 751 MHD__gnutls_free_datum (&session->connection_state.write_mac_secret);
752 752
753 if (session->connection_state.write_cipher_state != NULL) 753 if (session->connection_state.write_cipher_state != NULL)
754 mhd_gnutls_cipher_deinit (session->connection_state.write_cipher_state); 754 MHD_gnutls_cipher_deinit (session->connection_state.write_cipher_state);
755 755
756 if (session->connection_state.write_compression_state != NULL) 756 if (session->connection_state.write_compression_state != NULL)
757 mhd_gtls_comp_deinit (session->connection_state.write_compression_state, 757 MHD_gtls_comp_deinit (session->connection_state.write_compression_state,
758 0); 758 0);
759 759
760 mac_size = 760 mac_size =
761 mhd_gnutls_hash_get_algo_len (session->security_parameters. 761 MHD_gnutls_hash_get_algo_len (session->security_parameters.
762 write_mac_algorithm); 762 write_mac_algorithm);
763 763
764 _gnutls_handshake_log 764 MHD__gnutls_handshake_log
765 ("HSK[%x]: Initializing internal [write] cipher sessions\n", session); 765 ("HSK[%x]: Initializing internal [write] cipher sessions\n", session);
766 766
767 switch (session->security_parameters.entity) 767 switch (session->security_parameters.entity)
@@ -770,7 +770,7 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
770 /* initialize cipher session 770 /* initialize cipher session
771 */ 771 */
772 session->connection_state.write_cipher_state = 772 session->connection_state.write_cipher_state =
773 mhd_gtls_cipher_init (session->security_parameters. 773 MHD_gtls_cipher_init (session->security_parameters.
774 write_bulk_cipher_algorithm, 774 write_bulk_cipher_algorithm,
775 &session->cipher_specs.server_write_key, 775 &session->cipher_specs.server_write_key,
776 &session->cipher_specs.server_write_IV); 776 &session->cipher_specs.server_write_IV);
@@ -780,7 +780,7 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
780 && session->security_parameters.write_bulk_cipher_algorithm != 780 && session->security_parameters.write_bulk_cipher_algorithm !=
781 MHD_GNUTLS_CIPHER_NULL) 781 MHD_GNUTLS_CIPHER_NULL)
782 { 782 {
783 gnutls_assert (); 783 MHD_gnutls_assert ();
784 return GNUTLS_E_INTERNAL_ERROR; 784 return GNUTLS_E_INTERNAL_ERROR;
785 } 785 }
786 786
@@ -790,13 +790,13 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
790 */ 790 */
791 if (mac_size > 0) 791 if (mac_size > 0)
792 { 792 {
793 if (_gnutls_sset_datum (&session->connection_state.write_mac_secret, 793 if (MHD__gnutls_sset_datum (&session->connection_state.write_mac_secret,
794 session->cipher_specs. 794 session->cipher_specs.
795 server_write_mac_secret.data, 795 server_write_mac_secret.data,
796 session->cipher_specs. 796 session->cipher_specs.
797 server_write_mac_secret.size) < 0) 797 server_write_mac_secret.size) < 0)
798 { 798 {
799 gnutls_assert (); 799 MHD_gnutls_assert ();
800 return GNUTLS_E_MEMORY_ERROR; 800 return GNUTLS_E_MEMORY_ERROR;
801 } 801 }
802 802
@@ -807,7 +807,7 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
807#if MHD_DEBUG_TLS 807#if MHD_DEBUG_TLS
808 case GNUTLS_CLIENT: 808 case GNUTLS_CLIENT:
809 session->connection_state.write_cipher_state = 809 session->connection_state.write_cipher_state =
810 mhd_gtls_cipher_init (session->security_parameters. 810 MHD_gtls_cipher_init (session->security_parameters.
811 write_bulk_cipher_algorithm, 811 write_bulk_cipher_algorithm,
812 &session->cipher_specs.client_write_key, 812 &session->cipher_specs.client_write_key,
813 &session->cipher_specs.client_write_IV); 813 &session->cipher_specs.client_write_IV);
@@ -817,7 +817,7 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
817 && session->security_parameters.write_bulk_cipher_algorithm != 817 && session->security_parameters.write_bulk_cipher_algorithm !=
818 MHD_GNUTLS_CIPHER_NULL) 818 MHD_GNUTLS_CIPHER_NULL)
819 { 819 {
820 gnutls_assert (); 820 MHD_gnutls_assert ();
821 return GNUTLS_E_INTERNAL_ERROR; 821 return GNUTLS_E_INTERNAL_ERROR;
822 } 822 }
823 823
@@ -825,13 +825,13 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
825 */ 825 */
826 if (mac_size > 0) 826 if (mac_size > 0)
827 { 827 {
828 if (_gnutls_sset_datum (&session->connection_state.write_mac_secret, 828 if (MHD__gnutls_sset_datum (&session->connection_state.write_mac_secret,
829 session->cipher_specs. 829 session->cipher_specs.
830 client_write_mac_secret.data, 830 client_write_mac_secret.data,
831 session->cipher_specs. 831 session->cipher_specs.
832 client_write_mac_secret.size) < 0) 832 client_write_mac_secret.size) < 0)
833 { 833 {
834 gnutls_assert (); 834 MHD_gnutls_assert ();
835 return GNUTLS_E_MEMORY_ERROR; 835 return GNUTLS_E_MEMORY_ERROR;
836 } 836 }
837 } 837 }
@@ -839,18 +839,18 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
839 break; 839 break;
840#endif 840#endif
841 default: 841 default:
842 gnutls_assert (); 842 MHD_gnutls_assert ();
843 return GNUTLS_E_INTERNAL_ERROR; 843 return GNUTLS_E_INTERNAL_ERROR;
844 } 844 }
845 845
846 846
847 session->connection_state.write_compression_state = 847 session->connection_state.write_compression_state =
848 mhd_gtls_comp_init (session->security_parameters. 848 MHD_gtls_comp_init (session->security_parameters.
849 write_compression_algorithm, 0); 849 write_compression_algorithm, 0);
850 850
851 if (session->connection_state.write_compression_state == GNUTLS_COMP_FAILED) 851 if (session->connection_state.write_compression_state == GNUTLS_COMP_FAILED)
852 { 852 {
853 gnutls_assert (); 853 MHD_gnutls_assert ();
854 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 854 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
855 } 855 }
856 856
@@ -860,15 +860,15 @@ mhd_gtls_write_connection_state_init (mhd_gtls_session_t session)
860/* Sets the specified cipher into the pending session 860/* Sets the specified cipher into the pending session
861 */ 861 */
862int 862int
863mhd_gtls_set_read_cipher (mhd_gtls_session_t session, 863MHD_gtls_set_read_cipher (MHD_gtls_session_t session,
864 enum MHD_GNUTLS_CipherAlgorithm algo) 864 enum MHD_GNUTLS_CipherAlgorithm algo)
865{ 865{
866 866
867 if (mhd_gtls_cipher_is_ok (algo) == 0) 867 if (MHD_gtls_cipher_is_ok (algo) == 0)
868 { 868 {
869 if (mhd_gtls_cipher_priority (session, algo) < 0) 869 if (MHD_gtls_cipher_priority (session, algo) < 0)
870 { 870 {
871 gnutls_assert (); 871 MHD_gnutls_assert ();
872 return GNUTLS_E_UNWANTED_ALGORITHM; 872 return GNUTLS_E_UNWANTED_ALGORITHM;
873 } 873 }
874 874
@@ -877,7 +877,7 @@ mhd_gtls_set_read_cipher (mhd_gtls_session_t session,
877 } 877 }
878 else 878 else
879 { 879 {
880 gnutls_assert (); 880 MHD_gnutls_assert ();
881 return GNUTLS_E_INTERNAL_ERROR; 881 return GNUTLS_E_INTERNAL_ERROR;
882 } 882 }
883 883
@@ -886,15 +886,15 @@ mhd_gtls_set_read_cipher (mhd_gtls_session_t session,
886} 886}
887 887
888int 888int
889mhd_gtls_set_write_cipher (mhd_gtls_session_t session, 889MHD_gtls_set_write_cipher (MHD_gtls_session_t session,
890 enum MHD_GNUTLS_CipherAlgorithm algo) 890 enum MHD_GNUTLS_CipherAlgorithm algo)
891{ 891{
892 892
893 if (mhd_gtls_cipher_is_ok (algo) == 0) 893 if (MHD_gtls_cipher_is_ok (algo) == 0)
894 { 894 {
895 if (mhd_gtls_cipher_priority (session, algo) < 0) 895 if (MHD_gtls_cipher_priority (session, algo) < 0)
896 { 896 {
897 gnutls_assert (); 897 MHD_gnutls_assert ();
898 return GNUTLS_E_UNWANTED_ALGORITHM; 898 return GNUTLS_E_UNWANTED_ALGORITHM;
899 } 899 }
900 900
@@ -903,7 +903,7 @@ mhd_gtls_set_write_cipher (mhd_gtls_session_t session,
903 } 903 }
904 else 904 else
905 { 905 {
906 gnutls_assert (); 906 MHD_gnutls_assert ();
907 return GNUTLS_E_INTERNAL_ERROR; 907 return GNUTLS_E_INTERNAL_ERROR;
908 } 908 }
909 909
@@ -915,17 +915,17 @@ mhd_gtls_set_write_cipher (mhd_gtls_session_t session,
915/* Sets the specified algorithm into pending compression session 915/* Sets the specified algorithm into pending compression session
916 */ 916 */
917int 917int
918mhd_gtls_set_read_compression (mhd_gtls_session_t session, 918MHD_gtls_set_read_compression (MHD_gtls_session_t session,
919 enum MHD_GNUTLS_CompressionMethod algo) 919 enum MHD_GNUTLS_CompressionMethod algo)
920{ 920{
921 921
922 if (mhd_gtls_compression_is_ok (algo) == 0) 922 if (MHD_gtls_compression_is_ok (algo) == 0)
923 { 923 {
924 session->security_parameters.read_compression_algorithm = algo; 924 session->security_parameters.read_compression_algorithm = algo;
925 } 925 }
926 else 926 else
927 { 927 {
928 gnutls_assert (); 928 MHD_gnutls_assert ();
929 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 929 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
930 } 930 }
931 return 0; 931 return 0;
@@ -933,17 +933,17 @@ mhd_gtls_set_read_compression (mhd_gtls_session_t session,
933} 933}
934 934
935int 935int
936mhd_gtls_set_write_compression (mhd_gtls_session_t session, 936MHD_gtls_set_write_compression (MHD_gtls_session_t session,
937 enum MHD_GNUTLS_CompressionMethod algo) 937 enum MHD_GNUTLS_CompressionMethod algo)
938{ 938{
939 939
940 if (mhd_gtls_compression_is_ok (algo) == 0) 940 if (MHD_gtls_compression_is_ok (algo) == 0)
941 { 941 {
942 session->security_parameters.write_compression_algorithm = algo; 942 session->security_parameters.write_compression_algorithm = algo;
943 } 943 }
944 else 944 else
945 { 945 {
946 gnutls_assert (); 946 MHD_gnutls_assert ();
947 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 947 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
948 } 948 }
949 return 0; 949 return 0;
@@ -953,22 +953,22 @@ mhd_gtls_set_write_compression (mhd_gtls_session_t session,
953/* Sets the specified kx algorithm into pending session 953/* Sets the specified kx algorithm into pending session
954 */ 954 */
955int 955int
956mhd_gtls_set_kx (mhd_gtls_session_t session, 956MHD_gtls_set_kx (MHD_gtls_session_t session,
957 enum MHD_GNUTLS_KeyExchangeAlgorithm algo) 957 enum MHD_GNUTLS_KeyExchangeAlgorithm algo)
958{ 958{
959 959
960 if (mhd_gtls_kx_is_ok (algo) == 0) 960 if (MHD_gtls_kx_is_ok (algo) == 0)
961 { 961 {
962 session->security_parameters.kx_algorithm = algo; 962 session->security_parameters.kx_algorithm = algo;
963 } 963 }
964 else 964 else
965 { 965 {
966 gnutls_assert (); 966 MHD_gnutls_assert ();
967 return GNUTLS_E_INTERNAL_ERROR; 967 return GNUTLS_E_INTERNAL_ERROR;
968 } 968 }
969 if (mhd_gtls_kx_priority (session, algo) < 0) 969 if (MHD_gtls_kx_priority (session, algo) < 0)
970 { 970 {
971 gnutls_assert (); 971 MHD_gnutls_assert ();
972 /* we shouldn't get here */ 972 /* we shouldn't get here */
973 return GNUTLS_E_UNWANTED_ALGORITHM; 973 return GNUTLS_E_UNWANTED_ALGORITHM;
974 } 974 }
@@ -979,22 +979,22 @@ mhd_gtls_set_kx (mhd_gtls_session_t session,
979 979
980/* Sets the specified mac algorithm into pending session */ 980/* Sets the specified mac algorithm into pending session */
981int 981int
982mhd_gtls_set_read_mac (mhd_gtls_session_t session, 982MHD_gtls_set_read_mac (MHD_gtls_session_t session,
983 enum MHD_GNUTLS_HashAlgorithm algo) 983 enum MHD_GNUTLS_HashAlgorithm algo)
984{ 984{
985 985
986 if (mhd_gnutls_mac_is_ok (algo) == 0) 986 if (MHD_gnutls_mac_is_ok (algo) == 0)
987 { 987 {
988 session->security_parameters.read_mac_algorithm = algo; 988 session->security_parameters.read_mac_algorithm = algo;
989 } 989 }
990 else 990 else
991 { 991 {
992 gnutls_assert (); 992 MHD_gnutls_assert ();
993 return GNUTLS_E_INTERNAL_ERROR; 993 return GNUTLS_E_INTERNAL_ERROR;
994 } 994 }
995 if (mhd_gtls_mac_priority (session, algo) < 0) 995 if (MHD_gtls_mac_priority (session, algo) < 0)
996 { 996 {
997 gnutls_assert (); 997 MHD_gnutls_assert ();
998 return GNUTLS_E_UNWANTED_ALGORITHM; 998 return GNUTLS_E_UNWANTED_ALGORITHM;
999 } 999 }
1000 1000
@@ -1004,22 +1004,22 @@ mhd_gtls_set_read_mac (mhd_gtls_session_t session,
1004} 1004}
1005 1005
1006int 1006int
1007mhd_gtls_set_write_mac (mhd_gtls_session_t session, 1007MHD_gtls_set_write_mac (MHD_gtls_session_t session,
1008 enum MHD_GNUTLS_HashAlgorithm algo) 1008 enum MHD_GNUTLS_HashAlgorithm algo)
1009{ 1009{
1010 1010
1011 if (mhd_gnutls_mac_is_ok (algo) == 0) 1011 if (MHD_gnutls_mac_is_ok (algo) == 0)
1012 { 1012 {
1013 session->security_parameters.write_mac_algorithm = algo; 1013 session->security_parameters.write_mac_algorithm = algo;
1014 } 1014 }
1015 else 1015 else
1016 { 1016 {
1017 gnutls_assert (); 1017 MHD_gnutls_assert ();
1018 return GNUTLS_E_INTERNAL_ERROR; 1018 return GNUTLS_E_INTERNAL_ERROR;
1019 } 1019 }
1020 if (mhd_gtls_mac_priority (session, algo) < 0) 1020 if (MHD_gtls_mac_priority (session, algo) < 0)
1021 { 1021 {
1022 gnutls_assert (); 1022 MHD_gnutls_assert ();
1023 return GNUTLS_E_UNWANTED_ALGORITHM; 1023 return GNUTLS_E_UNWANTED_ALGORITHM;
1024 } 1024 }
1025 1025
diff --git a/src/daemon/https/tls/gnutls_constate.h b/src/daemon/https/tls/gnutls_constate.h
index 184e7873..59b67249 100644
--- a/src/daemon/https/tls/gnutls_constate.h
+++ b/src/daemon/https/tls/gnutls_constate.h
@@ -22,20 +22,20 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gtls_connection_state_init (mhd_gtls_session_t session); 25int MHD_gtls_connection_state_init (MHD_gtls_session_t session);
26int mhd_gtls_read_connection_state_init (mhd_gtls_session_t session); 26int MHD_gtls_read_connection_state_init (MHD_gtls_session_t session);
27int mhd_gtls_write_connection_state_init (mhd_gtls_session_t session); 27int MHD_gtls_write_connection_state_init (MHD_gtls_session_t session);
28int mhd_gtls_set_write_cipher (mhd_gtls_session_t session, 28int MHD_gtls_set_write_cipher (MHD_gtls_session_t session,
29 enum MHD_GNUTLS_CipherAlgorithm algo); 29 enum MHD_GNUTLS_CipherAlgorithm algo);
30int mhd_gtls_set_write_mac (mhd_gtls_session_t session, 30int MHD_gtls_set_write_mac (MHD_gtls_session_t session,
31 enum MHD_GNUTLS_HashAlgorithm algo); 31 enum MHD_GNUTLS_HashAlgorithm algo);
32int mhd_gtls_set_read_cipher (mhd_gtls_session_t session, 32int MHD_gtls_set_read_cipher (MHD_gtls_session_t session,
33 enum MHD_GNUTLS_CipherAlgorithm algo); 33 enum MHD_GNUTLS_CipherAlgorithm algo);
34int mhd_gtls_set_read_mac (mhd_gtls_session_t session, 34int MHD_gtls_set_read_mac (MHD_gtls_session_t session,
35 enum MHD_GNUTLS_HashAlgorithm algo); 35 enum MHD_GNUTLS_HashAlgorithm algo);
36int mhd_gtls_set_read_compression (mhd_gtls_session_t session, 36int MHD_gtls_set_read_compression (MHD_gtls_session_t session,
37 enum MHD_GNUTLS_CompressionMethod algo); 37 enum MHD_GNUTLS_CompressionMethod algo);
38int mhd_gtls_set_write_compression (mhd_gtls_session_t session, 38int MHD_gtls_set_write_compression (MHD_gtls_session_t session,
39 enum MHD_GNUTLS_CompressionMethod algo); 39 enum MHD_GNUTLS_CompressionMethod algo);
40int mhd_gtls_set_kx (mhd_gtls_session_t session, 40int MHD_gtls_set_kx (MHD_gtls_session_t session,
41 enum MHD_GNUTLS_KeyExchangeAlgorithm algo); 41 enum MHD_GNUTLS_KeyExchangeAlgorithm algo);
diff --git a/src/daemon/https/tls/gnutls_datum.c b/src/daemon/https/tls/gnutls_datum.c
index d437ee2c..e9a660a4 100644
--- a/src/daemon/https/tls/gnutls_datum.c
+++ b/src/daemon/https/tls/gnutls_datum.c
@@ -34,31 +34,31 @@
34 34
35 35
36void 36void
37mhd_gtls_write_datum16 (opaque * dest, gnutls_datum_t dat) 37MHD_gtls_write_datum16 (opaque * dest, MHD_gnutls_datum_t dat)
38{ 38{
39 mhd_gtls_write_uint16 (dat.size, dest); 39 MHD_gtls_write_uint16 (dat.size, dest);
40 if (dat.data != NULL) 40 if (dat.data != NULL)
41 memcpy (&dest[2], dat.data, dat.size); 41 memcpy (&dest[2], dat.data, dat.size);
42} 42}
43 43
44void 44void
45mhd_gtls_write_datum24 (opaque * dest, gnutls_datum_t dat) 45MHD_gtls_write_datum24 (opaque * dest, MHD_gnutls_datum_t dat)
46{ 46{
47 mhd_gtls_write_uint24 (dat.size, dest); 47 MHD_gtls_write_uint24 (dat.size, dest);
48 if (dat.data != NULL) 48 if (dat.data != NULL)
49 memcpy (&dest[3], dat.data, dat.size); 49 memcpy (&dest[3], dat.data, dat.size);
50} 50}
51 51
52void 52void
53mhd_gtls_write_datum32 (opaque * dest, gnutls_datum_t dat) 53MHD_gtls_write_datum32 (opaque * dest, MHD_gnutls_datum_t dat)
54{ 54{
55 mhd_gtls_write_uint32 (dat.size, dest); 55 MHD_gtls_write_uint32 (dat.size, dest);
56 if (dat.data != NULL) 56 if (dat.data != NULL)
57 memcpy (&dest[4], dat.data, dat.size); 57 memcpy (&dest[4], dat.data, dat.size);
58} 58}
59 59
60void 60void
61mhd_gtls_write_datum8 (opaque * dest, gnutls_datum_t dat) 61MHD_gtls_write_datum8 (opaque * dest, MHD_gnutls_datum_t dat)
62{ 62{
63 dest[0] = (uint8_t) dat.size; 63 dest[0] = (uint8_t) dat.size;
64 if (dat.data != NULL) 64 if (dat.data != NULL)
@@ -67,8 +67,8 @@ mhd_gtls_write_datum8 (opaque * dest, gnutls_datum_t dat)
67 67
68 68
69int 69int
70mhd_gtls_set_datum_m (gnutls_datum_t * dat, const void *data, 70MHD_gtls_set_datum_m (MHD_gnutls_datum_t * dat, const void *data,
71 size_t data_size, gnutls_alloc_function galloc_func) 71 size_t data_size, MHD_gnutls_alloc_function galloc_func)
72{ 72{
73 if (data_size == 0 || data == NULL) 73 if (data_size == 0 || data == NULL)
74 { 74 {
@@ -88,9 +88,9 @@ mhd_gtls_set_datum_m (gnutls_datum_t * dat, const void *data,
88} 88}
89 89
90int 90int
91mhd_gtls_datum_append_m (gnutls_datum_t * dst, const void *data, 91MHD_gtls_datum_append_m (MHD_gnutls_datum_t * dst, const void *data,
92 size_t data_size, 92 size_t data_size,
93 gnutls_realloc_function grealloc_func) 93 MHD_gnutls_realloc_function grealloc_func)
94{ 94{
95 95
96 dst->data = grealloc_func (dst->data, data_size + dst->size); 96 dst->data = grealloc_func (dst->data, data_size + dst->size);
@@ -104,7 +104,7 @@ mhd_gtls_datum_append_m (gnutls_datum_t * dst, const void *data,
104} 104}
105 105
106void 106void
107mhd_gtls_free_datum_m (gnutls_datum_t * dat, gnutls_free_function gfree_func) 107MHD_gtls_free_datum_m (MHD_gnutls_datum_t * dat, MHD_gnutls_free_function gfree_func)
108{ 108{
109 if (dat->data != NULL) 109 if (dat->data != NULL)
110 gfree_func (dat->data); 110 gfree_func (dat->data);
diff --git a/src/daemon/https/tls/gnutls_datum.h b/src/daemon/https/tls/gnutls_datum.h
index f54e300b..634d527e 100644
--- a/src/daemon/https/tls/gnutls_datum.h
+++ b/src/daemon/https/tls/gnutls_datum.h
@@ -22,19 +22,19 @@
22 * 22 *
23 */ 23 */
24 24
25void mhd_gtls_write_datum16 (opaque * dest, gnutls_datum_t dat); 25void MHD_gtls_write_datum16 (opaque * dest, MHD_gnutls_datum_t dat);
26void mhd_gtls_write_datum24 (opaque * dest, gnutls_datum_t dat); 26void MHD_gtls_write_datum24 (opaque * dest, MHD_gnutls_datum_t dat);
27void mhd_gtls_write_datum32 (opaque * dest, gnutls_datum_t dat); 27void MHD_gtls_write_datum32 (opaque * dest, MHD_gnutls_datum_t dat);
28void mhd_gtls_write_datum8 (opaque * dest, gnutls_datum_t dat); 28void MHD_gtls_write_datum8 (opaque * dest, MHD_gnutls_datum_t dat);
29 29
30int mhd_gtls_set_datum_m (gnutls_datum_t * dat, const void *data, 30int MHD_gtls_set_datum_m (MHD_gnutls_datum_t * dat, const void *data,
31 size_t data_size, gnutls_alloc_function); 31 size_t data_size, MHD_gnutls_alloc_function);
32#define _gnutls_set_datum( x, y, z) mhd_gtls_set_datum_m(x,y,z, gnutls_malloc) 32#define MHD__gnutls_set_datum( x, y, z) MHD_gtls_set_datum_m(x,y,z, MHD_gnutls_malloc)
33#define _gnutls_sset_datum( x, y, z) mhd_gtls_set_datum_m(x,y,z, gnutls_secure_malloc) 33#define MHD__gnutls_sset_datum( x, y, z) MHD_gtls_set_datum_m(x,y,z, MHD_gnutls_secure_malloc)
34 34
35int mhd_gtls_datum_append_m (gnutls_datum_t * dat, const void *data, 35int MHD_gtls_datum_append_m (MHD_gnutls_datum_t * dat, const void *data,
36 size_t data_size, gnutls_realloc_function); 36 size_t data_size, MHD_gnutls_realloc_function);
37#define _gnutls_datum_append(x,y,z) mhd_gtls_datum_append_m(x,y,z, gnutls_realloc) 37#define MHD__gnutls_datum_append(x,y,z) MHD_gtls_datum_append_m(x,y,z, MHD_gnutls_realloc)
38 38
39void mhd_gtls_free_datum_m (gnutls_datum_t * dat, gnutls_free_function); 39void MHD_gtls_free_datum_m (MHD_gnutls_datum_t * dat, MHD_gnutls_free_function);
40#define _gnutls_free_datum(x) mhd_gtls_free_datum_m(x, gnutls_free) 40#define MHD__gnutls_free_datum(x) MHD_gtls_free_datum_m(x, MHD_gnutls_free)
diff --git a/src/daemon/https/tls/gnutls_dh.c b/src/daemon/https/tls/gnutls_dh.c
index 8cd5175d..d9dd4344 100644
--- a/src/daemon/https/tls/gnutls_dh.c
+++ b/src/daemon/https/tls/gnutls_dh.c
@@ -35,11 +35,11 @@
35 his_key = X ^ y mod p; 35 his_key = X ^ y mod p;
36 36
37// generate our secret and the public value (X) for it 37// generate our secret and the public value (X) for it
38 X = mhd_gtls_calc_dh_secret(&x, g, p); 38 X = MHD_gtls_calc_dh_secret(&x, g, p);
39// now we can calculate the shared secret 39// now we can calculate the shared secret
40 key = mhd_gtls_calc_dh_key(Y, x, g, p); 40 key = MHD_gtls_calc_dh_key(Y, x, g, p);
41 mhd_gtls_mpi_release(x); 41 MHD_gtls_mpi_release(x);
42 mhd_gtls_mpi_release(g); 42 MHD_gtls_mpi_release(g);
43*/ 43*/
44 44
45#define MAX_BITS 18000 45#define MAX_BITS 18000
@@ -47,24 +47,24 @@
47/* returns the public value (X), and the secret (ret_x). 47/* returns the public value (X), and the secret (ret_x).
48 */ 48 */
49mpi_t 49mpi_t
50mhd_gtls_calc_dh_secret (mpi_t * ret_x, mpi_t g, mpi_t prime) 50MHD_gtls_calc_dh_secret (mpi_t * ret_x, mpi_t g, mpi_t prime)
51{ 51{
52 mpi_t e, x; 52 mpi_t e, x;
53 int x_size = _gnutls_mpi_get_nbits (prime) - 1; 53 int x_size = MHD__gnutls_mpi_get_nbits (prime) - 1;
54 /* The size of the secret key is less than 54 /* The size of the secret key is less than
55 * prime/2 55 * prime/2
56 */ 56 */
57 57
58 if (x_size > MAX_BITS || x_size <= 0) 58 if (x_size > MAX_BITS || x_size <= 0)
59 { 59 {
60 gnutls_assert (); 60 MHD_gnutls_assert ();
61 return NULL; 61 return NULL;
62 } 62 }
63 63
64 x = _gnutls_mpi_new (x_size); 64 x = MHD__gnutls_mpi_new (x_size);
65 if (x == NULL) 65 if (x == NULL)
66 { 66 {
67 gnutls_assert (); 67 MHD_gnutls_assert ();
68 if (ret_x) 68 if (ret_x)
69 *ret_x = NULL; 69 *ret_x = NULL;
70 70
@@ -76,55 +76,55 @@ mhd_gtls_calc_dh_secret (mpi_t * ret_x, mpi_t g, mpi_t prime)
76 */ 76 */
77 do 77 do
78 { 78 {
79 _gnutls_mpi_randomize (x, (x_size / 8) * 8, GCRY_STRONG_RANDOM); 79 MHD__gnutls_mpi_randomize (x, (x_size / 8) * 8, GCRY_STRONG_RANDOM);
80 /* Check whether x is zero. 80 /* Check whether x is zero.
81 */ 81 */
82 } 82 }
83 while (_gnutls_mpi_cmp_ui (x, 0) == 0); 83 while (MHD__gnutls_mpi_cmp_ui (x, 0) == 0);
84 84
85 e = _gnutls_mpi_alloc_like (prime); 85 e = MHD__gnutls_mpi_alloc_like (prime);
86 if (e == NULL) 86 if (e == NULL)
87 { 87 {
88 gnutls_assert (); 88 MHD_gnutls_assert ();
89 if (ret_x) 89 if (ret_x)
90 *ret_x = NULL; 90 *ret_x = NULL;
91 91
92 mhd_gtls_mpi_release (&x); 92 MHD_gtls_mpi_release (&x);
93 return NULL; 93 return NULL;
94 } 94 }
95 95
96 _gnutls_mpi_powm (e, g, x, prime); 96 MHD__gnutls_mpi_powm (e, g, x, prime);
97 97
98 if (ret_x) 98 if (ret_x)
99 *ret_x = x; 99 *ret_x = x;
100 else 100 else
101 mhd_gtls_mpi_release (&x); 101 MHD_gtls_mpi_release (&x);
102 return e; 102 return e;
103} 103}
104 104
105 105
106mpi_t 106mpi_t
107mhd_gtls_calc_dh_key (mpi_t f, mpi_t x, mpi_t prime) 107MHD_gtls_calc_dh_key (mpi_t f, mpi_t x, mpi_t prime)
108{ 108{
109 mpi_t k; 109 mpi_t k;
110 int bits; 110 int bits;
111 111
112 bits = _gnutls_mpi_get_nbits (prime); 112 bits = MHD__gnutls_mpi_get_nbits (prime);
113 if (bits <= 0 || bits > MAX_BITS) 113 if (bits <= 0 || bits > MAX_BITS)
114 { 114 {
115 gnutls_assert (); 115 MHD_gnutls_assert ();
116 return NULL; 116 return NULL;
117 } 117 }
118 118
119 k = _gnutls_mpi_alloc_like (prime); 119 k = MHD__gnutls_mpi_alloc_like (prime);
120 if (k == NULL) 120 if (k == NULL)
121 return NULL; 121 return NULL;
122 _gnutls_mpi_powm (k, f, x, prime); 122 MHD__gnutls_mpi_powm (k, f, x, prime);
123 return k; 123 return k;
124} 124}
125 125
126/*- 126/*-
127 * mhd_gtls_get_dh_params - Returns the DH parameters pointer 127 * MHD_gtls_get_dh_params - Returns the DH parameters pointer
128 * @dh_params: is an DH parameters structure, or NULL. 128 * @dh_params: is an DH parameters structure, or NULL.
129 * @func: is a callback function to receive the parameters or NULL. 129 * @func: is a callback function to receive the parameters or NULL.
130 * @session: a gnutls session. 130 * @session: a gnutls session.
@@ -132,12 +132,12 @@ mhd_gtls_calc_dh_key (mpi_t f, mpi_t x, mpi_t prime)
132 * This function will return the dh parameters pointer. 132 * This function will return the dh parameters pointer.
133 * 133 *
134 -*/ 134 -*/
135mhd_gtls_dh_params_t 135MHD_gtls_dh_params_t
136mhd_gtls_get_dh_params (mhd_gtls_dh_params_t dh_params, 136MHD_gtls_get_dh_params (MHD_gtls_dh_params_t dh_params,
137 gnutls_params_function * func, 137 MHD_gnutls_params_function * func,
138 mhd_gtls_session_t session) 138 MHD_gtls_session_t session)
139{ 139{
140 gnutls_params_st params; 140 MHD_gnutls_params_st params;
141 int ret; 141 int ret;
142 142
143 /* if cached return the cached */ 143 /* if cached return the cached */
diff --git a/src/daemon/https/tls/gnutls_dh.h b/src/daemon/https/tls/gnutls_dh.h
index 6dec6e64..5d7341fc 100644
--- a/src/daemon/https/tls/gnutls_dh.h
+++ b/src/daemon/https/tls/gnutls_dh.h
@@ -25,14 +25,14 @@
25#ifndef GNUTLS_DH_H 25#ifndef GNUTLS_DH_H
26# define GNUTLS_DH_H 26# define GNUTLS_DH_H
27 27
28const mpi_t *mhd_gtls_dh_params_to_mpi (mhd_gtls_dh_params_t); 28const mpi_t *MHD_gtls_dh_params_to_mpi (MHD_gtls_dh_params_t);
29mpi_t mhd_gtls_calc_dh_secret (mpi_t * ret_x, mpi_t g, mpi_t prime); 29mpi_t MHD_gtls_calc_dh_secret (mpi_t * ret_x, mpi_t g, mpi_t prime);
30mpi_t mhd_gtls_calc_dh_key (mpi_t f, mpi_t x, mpi_t prime); 30mpi_t MHD_gtls_calc_dh_key (mpi_t f, mpi_t x, mpi_t prime);
31int mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned bits); 31int MHD_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned bits);
32 32
33mhd_gtls_dh_params_t 33MHD_gtls_dh_params_t
34mhd_gtls_get_dh_params (mhd_gtls_dh_params_t dh_params, 34MHD_gtls_get_dh_params (MHD_gtls_dh_params_t dh_params,
35 gnutls_params_function * func, 35 MHD_gnutls_params_function * func,
36 mhd_gtls_session_t session); 36 MHD_gtls_session_t session);
37 37
38#endif 38#endif
diff --git a/src/daemon/https/tls/gnutls_dh_primes.c b/src/daemon/https/tls/gnutls_dh_primes.c
index acd08a75..83776c42 100644
--- a/src/daemon/https/tls/gnutls_dh_primes.c
+++ b/src/daemon/https/tls/gnutls_dh_primes.c
@@ -36,7 +36,7 @@
36/* returns the prime and the generator of DH params. 36/* returns the prime and the generator of DH params.
37 */ 37 */
38const mpi_t * 38const mpi_t *
39mhd_gtls_dh_params_to_mpi (mhd_gtls_dh_params_t dh_primes) 39MHD_gtls_dh_params_to_mpi (MHD_gtls_dh_params_t dh_primes)
40{ 40{
41 if (dh_primes == NULL || dh_primes->params[1] == NULL 41 if (dh_primes == NULL || dh_primes->params[1] == NULL
42 || dh_primes->params[0] == NULL) 42 || dh_primes->params[0] == NULL)
@@ -48,7 +48,7 @@ mhd_gtls_dh_params_to_mpi (mhd_gtls_dh_params_t dh_primes)
48} 48}
49 49
50int 50int
51mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits) 51MHD_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
52{ 52{
53 mpi_t g = NULL, prime = NULL; 53 mpi_t g = NULL, prime = NULL;
54 gcry_error_t err; 54 gcry_error_t err;
@@ -75,7 +75,7 @@ mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
75 75
76 if (times) 76 if (times)
77 { 77 {
78 mhd_gtls_mpi_release (&prime); 78 MHD_gtls_mpi_release (&prime);
79 gcry_prime_release_factors (factors); 79 gcry_prime_release_factors (factors);
80 } 80 }
81 81
@@ -85,7 +85,7 @@ mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
85 85
86 if (err != 0) 86 if (err != 0)
87 { 87 {
88 gnutls_assert (); 88 MHD_gnutls_assert ();
89 result = GNUTLS_E_INTERNAL_ERROR; 89 result = GNUTLS_E_INTERNAL_ERROR;
90 goto cleanup; 90 goto cleanup;
91 } 91 }
@@ -98,7 +98,7 @@ mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
98 98
99 if (err != 0) 99 if (err != 0)
100 { 100 {
101 gnutls_assert (); 101 MHD_gnutls_assert ();
102 result = GNUTLS_E_INTERNAL_ERROR; 102 result = GNUTLS_E_INTERNAL_ERROR;
103 goto cleanup; 103 goto cleanup;
104 } 104 }
@@ -108,7 +108,7 @@ mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
108 err = gcry_prime_group_generator (&g, prime, factors, NULL); 108 err = gcry_prime_group_generator (&g, prime, factors, NULL);
109 if (err != 0) 109 if (err != 0)
110 { 110 {
111 gnutls_assert (); 111 MHD_gnutls_assert ();
112 result = GNUTLS_E_INTERNAL_ERROR; 112 result = GNUTLS_E_INTERNAL_ERROR;
113 goto cleanup; 113 goto cleanup;
114 } 114 }
@@ -119,17 +119,17 @@ mhd_gtls_dh_generate_prime (mpi_t * ret_g, mpi_t * ret_n, unsigned int bits)
119 if (ret_g) 119 if (ret_g)
120 *ret_g = g; 120 *ret_g = g;
121 else 121 else
122 mhd_gtls_mpi_release (&g); 122 MHD_gtls_mpi_release (&g);
123 if (ret_n) 123 if (ret_n)
124 *ret_n = prime; 124 *ret_n = prime;
125 else 125 else
126 mhd_gtls_mpi_release (&prime); 126 MHD_gtls_mpi_release (&prime);
127 127
128 return 0; 128 return 0;
129 129
130cleanup:gcry_prime_release_factors (factors); 130cleanup:gcry_prime_release_factors (factors);
131 mhd_gtls_mpi_release (&g); 131 MHD_gtls_mpi_release (&g);
132 mhd_gtls_mpi_release (&prime); 132 MHD_gtls_mpi_release (&prime);
133 133
134 return result; 134 return result;
135 135
@@ -139,20 +139,20 @@ cleanup:gcry_prime_release_factors (factors);
139 * generated one. 139 * generated one.
140 */ 140 */
141/** 141/**
142 * MHD_gnutls_dh_params_init - This function will initialize the DH parameters 142 * MHD__gnutls_dh_params_init - This function will initialize the DH parameters
143 * @dh_params: Is a structure that will hold the prime numbers 143 * @dh_params: Is a structure that will hold the prime numbers
144 * 144 *
145 * This function will initialize the DH parameters structure. 145 * This function will initialize the DH parameters structure.
146 * 146 *
147 **/ 147 **/
148int 148int
149MHD_gnutls_dh_params_init (mhd_gtls_dh_params_t * dh_params) 149MHD__gnutls_dh_params_init (MHD_gtls_dh_params_t * dh_params)
150{ 150{
151 151
152 (*dh_params) = gnutls_calloc (1, sizeof (mhd_gtls_dh_params_st)); 152 (*dh_params) = MHD_gnutls_calloc (1, sizeof (MHD_gtls_dh_params_st));
153 if (*dh_params == NULL) 153 if (*dh_params == NULL)
154 { 154 {
155 gnutls_assert (); 155 MHD_gnutls_assert ();
156 return GNUTLS_E_MEMORY_ERROR; 156 return GNUTLS_E_MEMORY_ERROR;
157 } 157 }
158 158
@@ -161,33 +161,33 @@ MHD_gnutls_dh_params_init (mhd_gtls_dh_params_t * dh_params)
161} 161}
162 162
163/** 163/**
164 * MHD_gnutls_dh_params_deinit - This function will deinitialize the DH parameters 164 * MHD__gnutls_dh_params_deinit - This function will deinitialize the DH parameters
165 * @dh_params: Is a structure that holds the prime numbers 165 * @dh_params: Is a structure that holds the prime numbers
166 * 166 *
167 * This function will deinitialize the DH parameters structure. 167 * This function will deinitialize the DH parameters structure.
168 * 168 *
169 **/ 169 **/
170void 170void
171MHD_gnutls_dh_params_deinit (mhd_gtls_dh_params_t dh_params) 171MHD__gnutls_dh_params_deinit (MHD_gtls_dh_params_t dh_params)
172{ 172{
173 if (dh_params == NULL) 173 if (dh_params == NULL)
174 return; 174 return;
175 175
176 mhd_gtls_mpi_release (&dh_params->params[0]); 176 MHD_gtls_mpi_release (&dh_params->params[0]);
177 mhd_gtls_mpi_release (&dh_params->params[1]); 177 MHD_gtls_mpi_release (&dh_params->params[1]);
178 178
179 gnutls_free (dh_params); 179 MHD_gnutls_free (dh_params);
180 180
181} 181}
182 182
183/** 183/**
184 * MHD_gnutls_dh_params_generate2 - This function will generate new DH parameters 184 * MHD__gnutls_dh_params_generate2 - This function will generate new DH parameters
185 * @params: Is the structure that the DH parameters will be stored 185 * @params: Is the structure that the DH parameters will be stored
186 * @bits: is the prime's number of bits 186 * @bits: is the prime's number of bits
187 * 187 *
188 * This function will generate a new pair of prime and generator for use in 188 * This function will generate a new pair of prime and generator for use in
189 * the Diffie-Hellman key exchange. The new parameters will be allocated using 189 * the Diffie-Hellman key exchange. The new parameters will be allocated using
190 * gnutls_malloc() and will be stored in the appropriate datum. 190 * MHD_gnutls_malloc() and will be stored in the appropriate datum.
191 * This function is normally slow. 191 * This function is normally slow.
192 * 192 *
193 * Note that the bits value should be one of 768, 1024, 2048, 3072 or 4096. 193 * Note that the bits value should be one of 768, 1024, 2048, 3072 or 4096.
@@ -197,16 +197,16 @@ MHD_gnutls_dh_params_deinit (mhd_gtls_dh_params_t dh_params)
197 * 197 *
198 **/ 198 **/
199int 199int
200MHD_gnutls_dh_params_generate2 (mhd_gtls_dh_params_t params, 200MHD__gnutls_dh_params_generate2 (MHD_gtls_dh_params_t params,
201 unsigned int bits) 201 unsigned int bits)
202{ 202{
203 int ret; 203 int ret;
204 204
205 ret = 205 ret =
206 mhd_gtls_dh_generate_prime (&params->params[1], &params->params[0], bits); 206 MHD_gtls_dh_generate_prime (&params->params[1], &params->params[0], bits);
207 if (ret < 0) 207 if (ret < 0)
208 { 208 {
209 gnutls_assert (); 209 MHD_gnutls_assert ();
210 return ret; 210 return ret;
211 } 211 }
212 212
diff --git a/src/daemon/https/tls/gnutls_errors.c b/src/daemon/https/tls/gnutls_errors.c
index c0e42872..51fdb707 100644
--- a/src/daemon/https/tls/gnutls_errors.c
+++ b/src/daemon/https/tls/gnutls_errors.c
@@ -33,21 +33,21 @@
33#define _(String) (String) 33#define _(String) (String)
34#define N_(String) (String) 34#define N_(String) (String)
35 35
36extern LOG_FUNC _gnutls_log_func; 36extern LOG_FUNC MHD__gnutls_log_func;
37 37
38#define ERROR_ENTRY(desc, name, fatal) \ 38#define ERROR_ENTRY(desc, name, fatal) \
39 { desc, #name, name, fatal} 39 { desc, #name, name, fatal}
40 40
41struct gnutls_error_entry 41struct MHD_gnutls_error_entry
42{ 42{
43 const char *desc; 43 const char *desc;
44 const char *_name; 44 const char *_name;
45 int number; 45 int number;
46 int fatal; 46 int fatal;
47}; 47};
48typedef struct gnutls_error_entry gnutls_error_entry; 48typedef struct MHD_gnutls_error_entry MHD_gnutls_error_entry;
49 49
50static const gnutls_error_entry mhd_gtls_error_algorithms[] = { 50static const MHD_gnutls_error_entry MHD_gtls_error_algorithms[] = {
51 /* "Short Description", Error code define, critical (0,1) -- 1 in most cases */ 51 /* "Short Description", Error code define, critical (0,1) -- 1 in most cases */
52 ERROR_ENTRY (N_("Success."), GNUTLS_E_SUCCESS, 0), 52 ERROR_ENTRY (N_("Success."), GNUTLS_E_SUCCESS, 0),
53 ERROR_ENTRY (N_("Could not negotiate a supported cipher suite."), 53 ERROR_ENTRY (N_("Could not negotiate a supported cipher suite."),
@@ -246,8 +246,8 @@ static const gnutls_error_entry mhd_gtls_error_algorithms[] = {
246}; 246};
247 247
248#define GNUTLS_ERROR_LOOP(b) \ 248#define GNUTLS_ERROR_LOOP(b) \
249 const gnutls_error_entry *p; \ 249 const MHD_gnutls_error_entry *p; \
250 for(p = mhd_gtls_error_algorithms; p->desc != NULL; p++) { b ; } 250 for(p = MHD_gtls_error_algorithms; p->desc != NULL; p++) { b ; }
251 251
252#define GNUTLS_ERROR_ALG_LOOP(a) \ 252#define GNUTLS_ERROR_ALG_LOOP(a) \
253 GNUTLS_ERROR_LOOP( if(p->number == error) { a; break; } ) 253 GNUTLS_ERROR_LOOP( if(p->number == error) { a; break; } )
@@ -329,7 +329,7 @@ MHD_gtls_strerror (int error)
329 * given error code. 329 * given error code.
330 */ 330 */
331const char * 331const char *
332_gnutls_strerror (int error) 332MHD__gnutls_strerror (int error)
333{ 333{
334 const char *ret = NULL; 334 const char *ret = NULL;
335 335
@@ -340,7 +340,7 @@ _gnutls_strerror (int error)
340} 340}
341 341
342int 342int
343mhd_gtls_asn2err (int asn_err) 343MHD_gtls_asn2err (int asn_err)
344{ 344{
345 switch (asn_err) 345 switch (asn_err)
346 { 346 {
@@ -382,13 +382,13 @@ mhd_gtls_asn2err (int asn_err)
382 * caller provided function 382 * caller provided function
383 */ 383 */
384void 384void
385mhd_gtls_log (int level, const char *fmt, ...) 385MHD_gtls_log (int level, const char *fmt, ...)
386{ 386{
387 va_list args; 387 va_list args;
388 char str[MAX_LOG_SIZE]; 388 char str[MAX_LOG_SIZE];
389 void (*log_func) (int, const char *) = _gnutls_log_func; 389 void (*log_func) (int, const char *) = MHD__gnutls_log_func;
390 390
391 if (_gnutls_log_func == NULL) 391 if (MHD__gnutls_log_func == NULL)
392 return; 392 return;
393 393
394 va_start (args, fmt); 394 va_start (args, fmt);
@@ -405,7 +405,7 @@ mhd_gtls_log (int level, const char *fmt, ...)
405 * be called. This may affect performance. 405 * be called. This may affect performance.
406 */ 406 */
407void 407void
408_gnutls_null_log (void *x, ...) 408MHD__gnutls_null_log (void *x, ...)
409{ 409{
410 return; 410 return;
411} 411}
diff --git a/src/daemon/https/tls/gnutls_errors.h b/src/daemon/https/tls/gnutls_errors.h
index fcfc4c63..edc89817 100644
--- a/src/daemon/https/tls/gnutls_errors.h
+++ b/src/daemon/https/tls/gnutls_errors.h
@@ -28,46 +28,46 @@
28 28
29#ifdef __FILE__ 29#ifdef __FILE__
30# ifdef __LINE__ 30# ifdef __LINE__
31# define gnutls_assert() _gnutls_debug_log( "ASSERT: %s:%d\n", __FILE__,__LINE__); 31# define MHD_gnutls_assert() MHD__gnutls_debug_log( "ASSERT: %s:%d\n", __FILE__,__LINE__);
32# else 32# else
33# define gnutls_assert() 33# define MHD_gnutls_assert()
34# endif 34# endif
35#else /* __FILE__ not defined */ 35#else /* __FILE__ not defined */
36# define gnutls_assert() 36# define MHD_gnutls_assert()
37#endif 37#endif
38 38
39int mhd_gtls_asn2err (int asn_err); 39int MHD_gtls_asn2err (int asn_err);
40void mhd_gtls_log (int, const char *fmt, ...); 40void MHD_gtls_log (int, const char *fmt, ...);
41 41
42extern int _gnutls_log_level; 42extern int MHD__gnutls_log_level;
43 43
44#ifdef C99_MACROS 44#ifdef C99_MACROS
45#define LEVEL(l, ...) if (_gnutls_log_level >= l || _gnutls_log_level > 9) \ 45#define LEVEL(l, ...) if (MHD__gnutls_log_level >= l || MHD__gnutls_log_level > 9) \
46 mhd_gtls_log( l, __VA_ARGS__) 46 MHD_gtls_log( l, __VA_ARGS__)
47 47
48#define LEVEL_EQ(l, ...) if (_gnutls_log_level == l || _gnutls_log_level > 9) \ 48#define LEVEL_EQ(l, ...) if (MHD__gnutls_log_level == l || MHD__gnutls_log_level > 9) \
49 mhd_gtls_log( l, __VA_ARGS__) 49 MHD_gtls_log( l, __VA_ARGS__)
50 50
51# define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__) 51# define MHD__gnutls_debug_log(...) LEVEL(2, __VA_ARGS__)
52# define _gnutls_handshake_log(...) LEVEL(3, __VA_ARGS__) 52# define MHD__gnutls_handshake_log(...) LEVEL(3, __VA_ARGS__)
53# define _gnutls_io_log(...) LEVEL_EQ(5, __VA_ARGS__) 53# define MHD__gnutls_io_log(...) LEVEL_EQ(5, __VA_ARGS__)
54# define _gnutls_buffers_log(...) LEVEL_EQ(6, __VA_ARGS__) 54# define MHD__gnutls_buffers_log(...) LEVEL_EQ(6, __VA_ARGS__)
55# define _gnutls_hard_log(...) LEVEL(9, __VA_ARGS__) 55# define MHD__gnutls_hard_log(...) LEVEL(9, __VA_ARGS__)
56# define _gnutls_record_log(...) LEVEL(4, __VA_ARGS__) 56# define MHD__gnutls_record_log(...) LEVEL(4, __VA_ARGS__)
57# define _gnutls_read_log(...) LEVEL_EQ(7, __VA_ARGS__) 57# define MHD__gnutls_read_log(...) LEVEL_EQ(7, __VA_ARGS__)
58# define _gnutls_write_log(...) LEVEL_EQ(7, __VA_ARGS__) 58# define MHD__gnutls_write_log(...) LEVEL_EQ(7, __VA_ARGS__)
59# define _gnutls_x509_log(...) LEVEL(1, __VA_ARGS__) 59# define MHD__gnutls_x509_log(...) LEVEL(1, __VA_ARGS__)
60#else 60#else
61# define _gnutls_debug_log _gnutls_null_log 61# define MHD__gnutls_debug_log MHD__gnutls_null_log
62# define _gnutls_handshake_log _gnutls_null_log 62# define MHD__gnutls_handshake_log MHD__gnutls_null_log
63# define _gnutls_io_log _gnutls_null_log 63# define MHD__gnutls_io_log MHD__gnutls_null_log
64# define _gnutls_buffers_log _gnutls_null_log 64# define MHD__gnutls_buffers_log MHD__gnutls_null_log
65# define _gnutls_hard_log _gnutls_null_log 65# define MHD__gnutls_hard_log MHD__gnutls_null_log
66# define _gnutls_record_log _gnutls_null_log 66# define MHD__gnutls_record_log MHD__gnutls_null_log
67# define _gnutls_read_log _gnutls_null_log 67# define MHD__gnutls_read_log MHD__gnutls_null_log
68# define _gnutls_write_log _gnutls_null_log 68# define MHD__gnutls_write_log MHD__gnutls_null_log
69# define _gnutls_x509_log _gnutls_null_log 69# define MHD__gnutls_x509_log MHD__gnutls_null_log
70 70
71void _gnutls_null_log (void *, ...); 71void MHD__gnutls_null_log (void *, ...);
72 72
73#endif /* C99_MACROS */ 73#endif /* C99_MACROS */
diff --git a/src/daemon/https/tls/gnutls_extensions.c b/src/daemon/https/tls/gnutls_extensions.c
index 4c9286d8..1f9cf7d0 100644
--- a/src/daemon/https/tls/gnutls_extensions.c
+++ b/src/daemon/https/tls/gnutls_extensions.c
@@ -43,39 +43,39 @@
43 43
44 44
45#define MAX_EXT_SIZE 10 45#define MAX_EXT_SIZE 10
46const int mhd_gtls_extensions_size = MAX_EXT_SIZE; 46const int MHD_gtls_extensions_size = MAX_EXT_SIZE;
47 47
48mhd_gtls_extension_entry mhd_gtls_extensions[MAX_EXT_SIZE] = { 48MHD_gtls_extension_entry MHD_gtls_extensions[MAX_EXT_SIZE] = {
49 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_MAX_RECORD_SIZE, 49 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_MAX_RECORD_SIZE,
50 EXTENSION_TLS, 50 EXTENSION_TLS,
51 mhd_gtls_max_record_recv_params, 51 MHD_gtls_max_record_recv_params,
52 mhd_gtls_max_record_send_params), 52 MHD_gtls_max_record_send_params),
53 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_CERT_TYPE, 53 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_CERT_TYPE,
54 EXTENSION_TLS, 54 EXTENSION_TLS,
55 mhd_gtls_cert_type_recv_params, 55 MHD_gtls_cert_type_recv_params,
56 mhd_gtls_cert_type_send_params), 56 MHD_gtls_cert_type_send_params),
57 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_SERVER_NAME, 57 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_SERVER_NAME,
58 EXTENSION_APPLICATION, 58 EXTENSION_APPLICATION,
59 mhd_gtls_server_name_recv_params, 59 MHD_gtls_server_name_recv_params,
60 mhd_gtls_server_name_send_params), 60 MHD_gtls_server_name_send_params),
61#ifdef ENABLE_OPRFI 61#ifdef ENABLE_OPRFI
62 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_OPAQUE_PRF_INPUT, 62 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_OPAQUE_PRF_INPUT,
63 EXTENSION_TLS, 63 EXTENSION_TLS,
64 mhd_gtls_oprfi_recv_params, 64 MHD_gtls_oprfi_recv_params,
65 mhd_gtls_oprfi_send_params), 65 MHD_gtls_oprfi_send_params),
66#endif 66#endif
67#ifdef ENABLE_SRP 67#ifdef ENABLE_SRP
68 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_SRP, 68 GNUTLS_EXTENSION_ENTRY (GNUTLS_EXTENSION_SRP,
69 EXTENSION_TLS, 69 EXTENSION_TLS,
70 _gnutls_srp_recv_params, 70 MHD__gnutls_srp_recv_params,
71 _gnutls_srp_send_params), 71 MHD__gnutls_srp_send_params),
72#endif 72#endif
73 {0, 0, 0, 0} 73 {0, 0, 0, 0}
74}; 74};
75 75
76#define GNUTLS_EXTENSION_LOOP2(b) \ 76#define GNUTLS_EXTENSION_LOOP2(b) \
77 mhd_gtls_extension_entry *p; \ 77 MHD_gtls_extension_entry *p; \
78 for(p = mhd_gtls_extensions; p->name != NULL; p++) { b ; } 78 for(p = MHD_gtls_extensions; p->name != NULL; p++) { b ; }
79 79
80#define GNUTLS_EXTENSION_LOOP(a) \ 80#define GNUTLS_EXTENSION_LOOP(a) \
81 GNUTLS_EXTENSION_LOOP2( if(p->type == type) { a; break; } ) 81 GNUTLS_EXTENSION_LOOP2( if(p->type == type) { a; break; } )
@@ -83,29 +83,29 @@ mhd_gtls_extension_entry mhd_gtls_extensions[MAX_EXT_SIZE] = {
83 83
84/* EXTENSION functions */ 84/* EXTENSION functions */
85 85
86mhd_gtls_ext_recv_func 86MHD_gtls_ext_recv_func
87mhd_gtls_ext_func_recv (uint16_t type, mhd_gtls_ext_parse_type_t parse_type) 87MHD_gtls_ext_func_recv (uint16_t type, MHD_gtls_ext_parse_type_t parse_type)
88{ 88{
89 mhd_gtls_ext_recv_func ret = NULL; 89 MHD_gtls_ext_recv_func ret = NULL;
90 GNUTLS_EXTENSION_LOOP (if 90 GNUTLS_EXTENSION_LOOP (if
91 (parse_type == EXTENSION_ANY 91 (parse_type == EXTENSION_ANY
92 || p->parse_type == parse_type) ret = 92 || p->parse_type == parse_type) ret =
93 p->gnutls_ext_func_recv); 93 p->MHD_gnutls_ext_func_recv);
94 return ret; 94 return ret;
95 95
96} 96}
97 97
98mhd_gtls_ext_send_func 98MHD_gtls_ext_send_func
99mhd_gtls_ext_func_send (uint16_t type) 99MHD_gtls_ext_func_send (uint16_t type)
100{ 100{
101 mhd_gtls_ext_send_func ret = NULL; 101 MHD_gtls_ext_send_func ret = NULL;
102 GNUTLS_EXTENSION_LOOP (ret = p->gnutls_ext_func_send); 102 GNUTLS_EXTENSION_LOOP (ret = p->MHD_gnutls_ext_func_send);
103 return ret; 103 return ret;
104 104
105} 105}
106 106
107const char * 107const char *
108mhd_gtls_extension_get_name (uint16_t type) 108MHD_gtls_extension_get_name (uint16_t type)
109{ 109{
110 const char *ret = NULL; 110 const char *ret = NULL;
111 111
@@ -119,7 +119,7 @@ mhd_gtls_extension_get_name (uint16_t type)
119 * requested ones. Otherwise it's a fatal error. 119 * requested ones. Otherwise it's a fatal error.
120 */ 120 */
121static int 121static int
122_gnutls_extension_list_check (mhd_gtls_session_t session, uint16_t type) 122MHD__gnutls_extension_list_check (MHD_gtls_session_t session, uint16_t type)
123{ 123{
124#if MHD_DEBUG_TLS 124#if MHD_DEBUG_TLS
125 if (session->security_parameters.entity == GNUTLS_CLIENT) 125 if (session->security_parameters.entity == GNUTLS_CLIENT)
@@ -137,15 +137,15 @@ _gnutls_extension_list_check (mhd_gtls_session_t session, uint16_t type)
137} 137}
138 138
139int 139int
140mhd_gtls_parse_extensions (mhd_gtls_session_t session, 140MHD_gtls_parse_extensions (MHD_gtls_session_t session,
141 mhd_gtls_ext_parse_type_t parse_type, 141 MHD_gtls_ext_parse_type_t parse_type,
142 const opaque * data, int data_size) 142 const opaque * data, int data_size)
143{ 143{
144 int next, ret; 144 int next, ret;
145 int pos = 0; 145 int pos = 0;
146 uint16_t type; 146 uint16_t type;
147 const opaque *sdata; 147 const opaque *sdata;
148 mhd_gtls_ext_recv_func ext_recv; 148 MHD_gtls_ext_recv_func ext_recv;
149 uint16_t size; 149 uint16_t size;
150 150
151#if MHD_DEBUG_TLS 151#if MHD_DEBUG_TLS
@@ -153,15 +153,15 @@ mhd_gtls_parse_extensions (mhd_gtls_session_t session,
153 if (session->security_parameters.entity == GNUTLS_CLIENT) 153 if (session->security_parameters.entity == GNUTLS_CLIENT)
154 for (i = 0; i < session->internals.extensions_sent_size; i++) 154 for (i = 0; i < session->internals.extensions_sent_size; i++)
155 { 155 {
156 _gnutls_debug_log ("EXT[%d]: expecting extension '%s'\n", 156 MHD__gnutls_debug_log ("EXT[%d]: expecting extension '%s'\n",
157 session, 157 session,
158 mhd_gtls_extension_get_name 158 MHD_gtls_extension_get_name
159 (session->internals.extensions_sent[i])); 159 (session->internals.extensions_sent[i]));
160 } 160 }
161#endif 161#endif
162 162
163 DECR_LENGTH_RET (data_size, 2, 0); 163 DECR_LENGTH_RET (data_size, 2, 0);
164 next = mhd_gtls_read_uint16 (data); 164 next = MHD_gtls_read_uint16 (data);
165 pos += 2; 165 pos += 2;
166 166
167 DECR_LENGTH_RET (data_size, next, 0); 167 DECR_LENGTH_RET (data_size, next, 0);
@@ -169,32 +169,32 @@ mhd_gtls_parse_extensions (mhd_gtls_session_t session,
169 do 169 do
170 { 170 {
171 DECR_LENGTH_RET (next, 2, 0); 171 DECR_LENGTH_RET (next, 2, 0);
172 type = mhd_gtls_read_uint16 (&data[pos]); 172 type = MHD_gtls_read_uint16 (&data[pos]);
173 pos += 2; 173 pos += 2;
174 174
175 _gnutls_debug_log ("EXT[%x]: Received extension '%s/%d'\n", session, 175 MHD__gnutls_debug_log ("EXT[%x]: Received extension '%s/%d'\n", session,
176 mhd_gtls_extension_get_name (type), type); 176 MHD_gtls_extension_get_name (type), type);
177 177
178 if ((ret = _gnutls_extension_list_check (session, type)) < 0) 178 if ((ret = MHD__gnutls_extension_list_check (session, type)) < 0)
179 { 179 {
180 gnutls_assert (); 180 MHD_gnutls_assert ();
181 return ret; 181 return ret;
182 } 182 }
183 183
184 DECR_LENGTH_RET (next, 2, 0); 184 DECR_LENGTH_RET (next, 2, 0);
185 size = mhd_gtls_read_uint16 (&data[pos]); 185 size = MHD_gtls_read_uint16 (&data[pos]);
186 pos += 2; 186 pos += 2;
187 187
188 DECR_LENGTH_RET (next, size, 0); 188 DECR_LENGTH_RET (next, size, 0);
189 sdata = &data[pos]; 189 sdata = &data[pos];
190 pos += size; 190 pos += size;
191 191
192 ext_recv = mhd_gtls_ext_func_recv (type, parse_type); 192 ext_recv = MHD_gtls_ext_func_recv (type, parse_type);
193 if (ext_recv == NULL) 193 if (ext_recv == NULL)
194 continue; 194 continue;
195 if ((ret = ext_recv (session, sdata, size)) < 0) 195 if ((ret = ext_recv (session, sdata, size)) < 0)
196 { 196 {
197 gnutls_assert (); 197 MHD_gnutls_assert ();
198 return ret; 198 return ret;
199 } 199 }
200 200
@@ -210,7 +210,7 @@ mhd_gtls_parse_extensions (mhd_gtls_session_t session,
210 * extensions are the ones we requested. 210 * extensions are the ones we requested.
211 */ 211 */
212static void 212static void
213_gnutls_extension_list_add (mhd_gtls_session_t session, uint16_t type) 213MHD__gnutls_extension_list_add (MHD_gtls_session_t session, uint16_t type)
214{ 214{
215#if MHD_DEBUG_TLS 215#if MHD_DEBUG_TLS
216 if (session->security_parameters.entity == GNUTLS_CLIENT) 216 if (session->security_parameters.entity == GNUTLS_CLIENT)
@@ -223,43 +223,43 @@ _gnutls_extension_list_add (mhd_gtls_session_t session, uint16_t type)
223 } 223 }
224 else 224 else
225 { 225 {
226 _gnutls_debug_log ("extensions: Increase MAX_EXT_TYPES\n"); 226 MHD__gnutls_debug_log ("extensions: Increase MAX_EXT_TYPES\n");
227 } 227 }
228 } 228 }
229#endif 229#endif
230} 230}
231 231
232int 232int
233mhd_gtls_gen_extensions (mhd_gtls_session_t session, opaque * data, 233MHD_gtls_gen_extensions (MHD_gtls_session_t session, opaque * data,
234 size_t data_size) 234 size_t data_size)
235{ 235{
236 int size; 236 int size;
237 uint16_t pos = 0; 237 uint16_t pos = 0;
238 opaque *sdata; 238 opaque *sdata;
239 int sdata_size; 239 int sdata_size;
240 mhd_gtls_ext_send_func ext_send; 240 MHD_gtls_ext_send_func ext_send;
241 mhd_gtls_extension_entry *p; 241 MHD_gtls_extension_entry *p;
242 242
243 if (data_size < 2) 243 if (data_size < 2)
244 { 244 {
245 gnutls_assert (); 245 MHD_gnutls_assert ();
246 return GNUTLS_E_INTERNAL_ERROR; 246 return GNUTLS_E_INTERNAL_ERROR;
247 } 247 }
248 248
249 /* allocate enough data for each extension. 249 /* allocate enough data for each extension.
250 */ 250 */
251 sdata_size = data_size; 251 sdata_size = data_size;
252 sdata = gnutls_malloc (sdata_size); 252 sdata = MHD_gnutls_malloc (sdata_size);
253 if (sdata == NULL) 253 if (sdata == NULL)
254 { 254 {
255 gnutls_assert (); 255 MHD_gnutls_assert ();
256 return GNUTLS_E_MEMORY_ERROR; 256 return GNUTLS_E_MEMORY_ERROR;
257 } 257 }
258 258
259 pos += 2; 259 pos += 2;
260 for (p = mhd_gtls_extensions; p->name != NULL; p++) 260 for (p = MHD_gtls_extensions; p->name != NULL; p++)
261 { 261 {
262 ext_send = mhd_gtls_ext_func_send (p->type); 262 ext_send = MHD_gtls_ext_func_send (p->type);
263 if (ext_send == NULL) 263 if (ext_send == NULL)
264 continue; 264 continue;
265 size = ext_send (session, sdata, sdata_size); 265 size = ext_send (session, sdata, sdata_size);
@@ -267,17 +267,17 @@ mhd_gtls_gen_extensions (mhd_gtls_session_t session, opaque * data,
267 { 267 {
268 if (data_size < pos + (size_t) size + 4) 268 if (data_size < pos + (size_t) size + 4)
269 { 269 {
270 gnutls_assert (); 270 MHD_gnutls_assert ();
271 gnutls_free (sdata); 271 MHD_gnutls_free (sdata);
272 return GNUTLS_E_INTERNAL_ERROR; 272 return GNUTLS_E_INTERNAL_ERROR;
273 } 273 }
274 274
275 /* write extension type */ 275 /* write extension type */
276 mhd_gtls_write_uint16 (p->type, &data[pos]); 276 MHD_gtls_write_uint16 (p->type, &data[pos]);
277 pos += 2; 277 pos += 2;
278 278
279 /* write size */ 279 /* write size */
280 mhd_gtls_write_uint16 (size, &data[pos]); 280 MHD_gtls_write_uint16 (size, &data[pos]);
281 pos += 2; 281 pos += 2;
282 282
283 memcpy (&data[pos], sdata, size); 283 memcpy (&data[pos], sdata, size);
@@ -285,15 +285,15 @@ mhd_gtls_gen_extensions (mhd_gtls_session_t session, opaque * data,
285 285
286 /* add this extension to the extension list 286 /* add this extension to the extension list
287 */ 287 */
288 _gnutls_extension_list_add (session, p->type); 288 MHD__gnutls_extension_list_add (session, p->type);
289 289
290 _gnutls_debug_log ("EXT[%x]: Sending extension %s\n", session, 290 MHD__gnutls_debug_log ("EXT[%x]: Sending extension %s\n", session,
291 mhd_gtls_extension_get_name (p->type)); 291 MHD_gtls_extension_get_name (p->type));
292 } 292 }
293 else if (size < 0) 293 else if (size < 0)
294 { 294 {
295 gnutls_assert (); 295 MHD_gnutls_assert ();
296 gnutls_free (sdata); 296 MHD_gnutls_free (sdata);
297 return size; 297 return size;
298 } 298 }
299 } 299 }
@@ -301,14 +301,14 @@ mhd_gtls_gen_extensions (mhd_gtls_session_t session, opaque * data,
301 size = pos; 301 size = pos;
302 pos -= 2; /* remove the size of the size header! */ 302 pos -= 2; /* remove the size of the size header! */
303 303
304 mhd_gtls_write_uint16 (pos, data); 304 MHD_gtls_write_uint16 (pos, data);
305 305
306 if (size == 2) 306 if (size == 2)
307 { /* empty */ 307 { /* empty */
308 size = 0; 308 size = 0;
309 } 309 }
310 310
311 gnutls_free (sdata); 311 MHD_gnutls_free (sdata);
312 return size; 312 return size;
313 313
314} 314}
diff --git a/src/daemon/https/tls/gnutls_extensions.h b/src/daemon/https/tls/gnutls_extensions.h
index 52604067..9623b39b 100644
--- a/src/daemon/https/tls/gnutls_extensions.h
+++ b/src/daemon/https/tls/gnutls_extensions.h
@@ -24,24 +24,24 @@
24 24
25#include <gnutls_int.h> 25#include <gnutls_int.h>
26 26
27const char *mhd_gtls_extension_get_name (uint16_t type); 27const char *MHD_gtls_extension_get_name (uint16_t type);
28int mhd_gtls_parse_extensions (mhd_gtls_session_t, mhd_gtls_ext_parse_type_t, 28int MHD_gtls_parse_extensions (MHD_gtls_session_t, MHD_gtls_ext_parse_type_t,
29 const opaque *, int); 29 const opaque *, int);
30int mhd_gtls_gen_extensions (mhd_gtls_session_t session, opaque * data, 30int MHD_gtls_gen_extensions (MHD_gtls_session_t session, opaque * data,
31 size_t data_size); 31 size_t data_size);
32 32
33typedef int (*mhd_gtls_ext_recv_func) (mhd_gtls_session_t, const opaque *, size_t); /* recv data */ 33typedef int (*MHD_gtls_ext_recv_func) (MHD_gtls_session_t, const opaque *, size_t); /* recv data */
34typedef int (*mhd_gtls_ext_send_func) (mhd_gtls_session_t, opaque *, size_t); /* send data */ 34typedef int (*MHD_gtls_ext_send_func) (MHD_gtls_session_t, opaque *, size_t); /* send data */
35 35
36mhd_gtls_ext_send_func mhd_gtls_ext_func_send (uint16_t type); 36MHD_gtls_ext_send_func MHD_gtls_ext_func_send (uint16_t type);
37mhd_gtls_ext_recv_func mhd_gtls_ext_func_recv (uint16_t type, 37MHD_gtls_ext_recv_func MHD_gtls_ext_func_recv (uint16_t type,
38 mhd_gtls_ext_parse_type_t); 38 MHD_gtls_ext_parse_type_t);
39 39
40typedef struct 40typedef struct
41{ 41{
42 const char *name; 42 const char *name;
43 uint16_t type; 43 uint16_t type;
44 mhd_gtls_ext_parse_type_t parse_type; 44 MHD_gtls_ext_parse_type_t parse_type;
45 mhd_gtls_ext_recv_func gnutls_ext_func_recv; 45 MHD_gtls_ext_recv_func MHD_gnutls_ext_func_recv;
46 mhd_gtls_ext_send_func gnutls_ext_func_send; 46 MHD_gtls_ext_send_func MHD_gnutls_ext_func_send;
47} mhd_gtls_extension_entry; 47} MHD_gtls_extension_entry;
diff --git a/src/daemon/https/tls/gnutls_global.c b/src/daemon/https/tls/gnutls_global.c
index b252b127..781d12fa 100644
--- a/src/daemon/https/tls/gnutls_global.c
+++ b/src/daemon/https/tls/gnutls_global.c
@@ -44,17 +44,17 @@
44 44
45GCRY_THREAD_OPTION_PTHREAD_IMPL; 45GCRY_THREAD_OPTION_PTHREAD_IMPL;
46 46
47#define gnutls_log_func LOG_FUNC 47#define MHD_gnutls_log_func LOG_FUNC
48 48
49/* created by asn1c */ 49/* created by asn1c */
50extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[]; 50extern const ASN1_ARRAY_TYPE MHD_gnutlsMHD__asn1_tab[];
51extern const ASN1_ARRAY_TYPE pkix_asn1_tab[]; 51extern const ASN1_ARRAY_TYPE MHD_pkix_asn1_tab[];
52 52
53LOG_FUNC _gnutls_log_func; 53LOG_FUNC MHD__gnutls_log_func;
54int _gnutls_log_level = 0; /* default log level */ 54int MHD__gnutls_log_level = 0; /* default log level */
55 55
56ASN1_TYPE _gnutls_pkix1_asn; 56ASN1_TYPE MHD__gnutls_pkix1_asn;
57ASN1_TYPE _gnutls_gnutls_asn; 57ASN1_TYPE MHD__gnutlsMHD__gnutls_asn;
58 58
59/** 59/**
60 * MHD_gtls_global_set_log_function - This function sets the logging function 60 * MHD_gtls_global_set_log_function - This function sets the logging function
@@ -65,13 +65,13 @@ ASN1_TYPE _gnutls_gnutls_asn;
65 * Normally you may not use this function since it is only used 65 * Normally you may not use this function since it is only used
66 * for debugging purposes. 66 * for debugging purposes.
67 * 67 *
68 * gnutls_log_func is of the form, 68 * MHD_gnutls_log_func is of the form,
69 * void (*gnutls_log_func)( int level, const char*); 69 * void (*MHD_gnutls_log_func)( int level, const char*);
70 **/ 70 **/
71void 71void
72MHD_gtls_global_set_log_function (gnutls_log_func log_func) 72MHD_gtls_global_set_log_function (MHD_gnutls_log_func log_func)
73{ 73{
74 _gnutls_log_func = log_func; 74 MHD__gnutls_log_func = log_func;
75} 75}
76 76
77/** 77/**
@@ -89,10 +89,10 @@ MHD_gtls_global_set_log_function (gnutls_log_func log_func)
89void 89void
90MHD_gtls_global_set_log_level (int level) 90MHD_gtls_global_set_log_level (int level)
91{ 91{
92 _gnutls_log_level = level; 92 MHD__gnutls_log_level = level;
93} 93}
94 94
95int _gnutls_is_secure_mem_null (const void *); 95int MHD__gnutls_is_secure_mem_null (const void *);
96 96
97/** 97/**
98 * MHD_gtls_global_set_mem_functions - This function sets the memory allocation functions 98 * MHD_gtls_global_set_mem_functions - This function sets the memory allocation functions
@@ -108,61 +108,61 @@ int _gnutls_is_secure_mem_null (const void *);
108 * This function is provided to set the memory allocation functions to 108 * This function is provided to set the memory allocation functions to
109 * something other than the defaults (ie the gcrypt allocation functions). 109 * something other than the defaults (ie the gcrypt allocation functions).
110 * 110 *
111 * This function must be called before MHD_gnutls_global_init() is called. 111 * This function must be called before MHD__gnutls_global_init() is called.
112 * 112 *
113 **/ 113 **/
114void 114void
115MHD_gtls_global_set_mem_functions (gnutls_alloc_function alloc_func, 115MHD_gtls_global_set_mem_functions (MHD_gnutls_alloc_function alloc_func,
116 gnutls_alloc_function 116 MHD_gnutls_alloc_function
117 secure_alloc_func, 117 secure_alloc_func,
118 gnutls_is_secure_function 118 MHD_gnutls_is_secure_function
119 is_secure_func, 119 is_secure_func,
120 gnutls_realloc_function realloc_func, 120 MHD_gnutls_realloc_function realloc_func,
121 gnutls_free_function free_func) 121 MHD_gnutls_free_function free_func)
122{ 122{
123 gnutls_secure_malloc = secure_alloc_func; 123 MHD_gnutls_secure_malloc = secure_alloc_func;
124 gnutls_malloc = alloc_func; 124 MHD_gnutls_malloc = alloc_func;
125 gnutls_realloc = realloc_func; 125 MHD_gnutls_realloc = realloc_func;
126 gnutls_free = free_func; 126 MHD_gnutls_free = free_func;
127 127
128 if (is_secure_func != NULL) 128 if (is_secure_func != NULL)
129 _gnutls_is_secure_memory = is_secure_func; 129 MHD__gnutls_is_secure_memory = is_secure_func;
130 else 130 else
131 _gnutls_is_secure_memory = _gnutls_is_secure_mem_null; 131 MHD__gnutls_is_secure_memory = MHD__gnutls_is_secure_mem_null;
132 132
133 /* if using the libc's default malloc 133 /* if using the libc's default malloc
134 * use libc's calloc as well. 134 * use libc's calloc as well.
135 */ 135 */
136 if (gnutls_malloc == malloc) 136 if (MHD_gnutls_malloc == malloc)
137 { 137 {
138 gnutls_calloc = calloc; 138 MHD_gnutls_calloc = calloc;
139 } 139 }
140 else 140 else
141 { /* use the included ones */ 141 { /* use the included ones */
142 gnutls_calloc = mhd_gtls_calloc; 142 MHD_gnutls_calloc = MHD_gtls_calloc;
143 } 143 }
144 gnutls_strdup = mhd_gtls_strdup; 144 MHD_gnutls_strdup = MHD_gtls_strdup;
145 145
146} 146}
147 147
148#ifdef DEBUG 148#ifdef DEBUG
149static void 149static void
150_gnutls_gcry_log_handler (void *dummy, int level, 150MHD__gnutls_gcry_log_handler (void *dummy, int level,
151 const char *fmt, va_list list) 151 const char *fmt, va_list list)
152{ 152{
153 mhd_gtls_log (level, fmt, list); 153 MHD_gtls_log (level, fmt, list);
154} 154}
155#endif 155#endif
156 156
157static int _gnutls_init = 0; 157static int MHD__gnutls_init_level = 0;
158 158
159/** 159/**
160 * MHD_gnutls_global_init - This function initializes the global data to defaults. 160 * MHD__gnutls_global_init - This function initializes the global data to defaults.
161 * 161 *
162 * This function initializes the global data to defaults. 162 * This function initializes the global data to defaults.
163 * Every gnutls application has a global data which holds common parameters 163 * Every gnutls application has a global data which holds common parameters
164 * shared by gnutls session structures. 164 * shared by gnutls session structures.
165 * You must call MHD_gnutls_global_deinit() when gnutls usage is no longer needed 165 * You must call MHD__gnutls_global_deinit() when gnutls usage is no longer needed
166 * Returns zero on success. 166 * Returns zero on success.
167 * 167 *
168 * Note that this function will also initialize libgcrypt, if it has not 168 * Note that this function will also initialize libgcrypt, if it has not
@@ -171,8 +171,8 @@ static int _gnutls_init = 0;
171 * want to disable libgcrypt's internal lockings etc. 171 * want to disable libgcrypt's internal lockings etc.
172 * 172 *
173 * This function increment a global counter, so that 173 * This function increment a global counter, so that
174 * MHD_gnutls_global_deinit() only releases resources when it has been 174 * MHD__gnutls_global_deinit() only releases resources when it has been
175 * called as many times as MHD_gnutls_global_init(). This is useful when 175 * called as many times as MHD__gnutls_global_init(). This is useful when
176 * GnuTLS is used by more than one library in an application. This 176 * GnuTLS is used by more than one library in an application. This
177 * function can be called many times, but will only do something the 177 * function can be called many times, but will only do something the
178 * first time. 178 * first time.
@@ -187,13 +187,13 @@ static int _gnutls_init = 0;
187 * 187 *
188 **/ 188 **/
189int 189int
190MHD_gnutls_global_init (void) 190MHD__gnutls_global_init (void)
191{ 191{
192 int result = 0; 192 int result = 0;
193 int res; 193 int res;
194 char c; 194 char c;
195 195
196 if (_gnutls_init++) 196 if (MHD__gnutls_init_level++)
197 return 0; 197 return 0;
198 198
199#if HAVE_WINSOCK 199#if HAVE_WINSOCK
@@ -206,13 +206,13 @@ MHD_gnutls_global_init (void)
206 err = WSAStartup (requested, &data); 206 err = WSAStartup (requested, &data);
207 if (err != 0) 207 if (err != 0)
208 { 208 {
209 _gnutls_debug_log ("WSAStartup failed: %d.\n", err); 209 MHD__gnutls_debug_log ("WSAStartup failed: %d.\n", err);
210 return GNUTLS_E_LIBRARY_VERSION_MISMATCH; 210 return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
211 } 211 }
212 212
213 if (data.wVersion < requested) 213 if (data.wVersion < requested)
214 { 214 {
215 _gnutls_debug_log ("WSAStartup version check failed (%d < %d).\n", 215 MHD__gnutls_debug_log ("WSAStartup version check failed (%d < %d).\n",
216 data.wVersion, requested); 216 data.wVersion, requested);
217 WSACleanup (); 217 WSACleanup ();
218 return GNUTLS_E_LIBRARY_VERSION_MISMATCH; 218 return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
@@ -239,15 +239,15 @@ MHD_gnutls_global_init (void)
239 /* this call initializes libgcrypt */ 239 /* this call initializes libgcrypt */
240 if (gcry_check_version (p) == NULL) 240 if (gcry_check_version (p) == NULL)
241 { 241 {
242 gnutls_assert (); 242 MHD_gnutls_assert ();
243 _gnutls_debug_log ("Checking for libgcrypt failed '%s'\n", p); 243 MHD__gnutls_debug_log ("Checking for libgcrypt failed '%s'\n", p);
244 return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY; 244 return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY;
245 } 245 }
246 246
247 /* for gcrypt in order to be able to allocate memory */ 247 /* for gcrypt in order to be able to allocate memory */
248 gcry_set_allocation_handler (gnutls_malloc, gnutls_secure_malloc, 248 gcry_set_allocation_handler (MHD_gnutls_malloc, MHD_gnutls_secure_malloc,
249 _gnutls_is_secure_memory, gnutls_realloc, 249 MHD__gnutls_is_secure_memory, MHD_gnutls_realloc,
250 gnutls_free); 250 MHD_gnutls_free);
251 251
252 /* gcry_control (GCRYCTL_DISABLE_INTERNAL_LOCKING, NULL, 0); */ 252 /* gcry_control (GCRYCTL_DISABLE_INTERNAL_LOCKING, NULL, 0); */
253 253
@@ -257,14 +257,14 @@ MHD_gnutls_global_init (void)
257 /* applications may want to override that, so we only use 257 /* applications may want to override that, so we only use
258 * it in debugging mode. 258 * it in debugging mode.
259 */ 259 */
260 gcry_set_log_handler (_gnutls_gcry_log_handler, NULL); 260 gcry_set_log_handler (MHD__gnutls_gcry_log_handler, NULL);
261#endif 261#endif
262 } 262 }
263 263
264 if (gc_init () != GC_OK) 264 if (MHD_gc_init () != GC_OK)
265 { 265 {
266 gnutls_assert (); 266 MHD_gnutls_assert ();
267 _gnutls_debug_log ("Initializing crypto backend failed\n"); 267 MHD__gnutls_debug_log ("Initializing crypto backend failed\n");
268 return GNUTLS_E_INCOMPATIBLE_CRYPTO_LIBRARY; 268 return GNUTLS_E_INCOMPATIBLE_CRYPTO_LIBRARY;
269 } 269 }
270 270
@@ -276,50 +276,50 @@ MHD_gnutls_global_init (void)
276 * This should not deal with files in the final 276 * This should not deal with files in the final
277 * version. 277 * version.
278 */ 278 */
279 res = asn1_array2tree (pkix_asn1_tab, &_gnutls_pkix1_asn, NULL); 279 res = MHD__asn1_array2tree (MHD_pkix_asn1_tab, &MHD__gnutls_pkix1_asn, NULL);
280 if (res != ASN1_SUCCESS) 280 if (res != ASN1_SUCCESS)
281 { 281 {
282 result = mhd_gtls_asn2err (res); 282 result = MHD_gtls_asn2err (res);
283 return result; 283 return result;
284 } 284 }
285 285
286 res = asn1_array2tree (gnutls_asn1_tab, &_gnutls_gnutls_asn, NULL); 286 res = MHD__asn1_array2tree (MHD_gnutlsMHD__asn1_tab, &MHD__gnutlsMHD__gnutls_asn, NULL);
287 if (res != ASN1_SUCCESS) 287 if (res != ASN1_SUCCESS)
288 { 288 {
289 asn1_delete_structure (&_gnutls_pkix1_asn); 289 MHD__asn1_delete_structure (&MHD__gnutls_pkix1_asn);
290 result = mhd_gtls_asn2err (res); 290 result = MHD_gtls_asn2err (res);
291 return result; 291 return result;
292 } 292 }
293 293
294 /* Initialize the gcrypt (if used random generator) */ 294 /* Initialize the gcrypt (if used random generator) */
295 gc_pseudo_random (&c, 1); 295 MHD_gc_pseudo_random (&c, 1);
296 296
297 return result; 297 return result;
298} 298}
299 299
300/** 300/**
301 * MHD_gnutls_global_deinit - This function deinitializes the global data 301 * MHD__gnutls_global_deinit - This function deinitializes the global data
302 * 302 *
303 * This function deinitializes the global data, that were initialized 303 * This function deinitializes the global data, that were initialized
304 * using MHD_gnutls_global_init(). 304 * using MHD__gnutls_global_init().
305 * 305 *
306 * Note! This function is not thread safe. See the discussion for 306 * Note! This function is not thread safe. See the discussion for
307 * MHD_gnutls_global_init() for more information. 307 * MHD__gnutls_global_init() for more information.
308 * 308 *
309 **/ 309 **/
310void 310void
311MHD_gnutls_global_deinit (void) 311MHD__gnutls_global_deinit (void)
312{ 312{
313 if (_gnutls_init == 1) 313 if (MHD__gnutls_init_level == 1)
314 { 314 {
315#if HAVE_WINSOCK 315#if HAVE_WINSOCK
316 WSACleanup (); 316 WSACleanup ();
317#endif 317#endif
318 asn1_delete_structure (&_gnutls_gnutls_asn); 318 MHD__asn1_delete_structure (&MHD__gnutlsMHD__gnutls_asn);
319 asn1_delete_structure (&_gnutls_pkix1_asn); 319 MHD__asn1_delete_structure (&MHD__gnutls_pkix1_asn);
320 gc_done (); 320 MHD_gc_done ();
321 } 321 }
322 _gnutls_init--; 322 MHD__gnutls_init_level--;
323} 323}
324 324
325/* These functions should be elsewere. Kept here for 325/* These functions should be elsewere. Kept here for
@@ -327,7 +327,7 @@ MHD_gnutls_global_deinit (void)
327 */ 327 */
328 328
329/** 329/**
330 * MHD_gnutls_transport_set_pull_function - This function sets a read like function 330 * MHD__gnutls_transport_set_pull_function - This function sets a read like function
331 * @pull_func: a callback function similar to read() 331 * @pull_func: a callback function similar to read()
332 * @session: gnutls session 332 * @session: gnutls session
333 * 333 *
@@ -337,17 +337,17 @@ MHD_gnutls_global_deinit (void)
337 * probably be ok. 337 * probably be ok.
338 * 338 *
339 * PULL_FUNC is of the form, 339 * PULL_FUNC is of the form,
340 * ssize_t (*mhd_gtls_pull_func)(gnutls_transport_ptr_t, void*, size_t); 340 * ssize_t (*MHD_gtls_pull_func)(MHD_gnutls_transport_ptr_t, void*, size_t);
341 **/ 341 **/
342void 342void
343MHD_gnutls_transport_set_pull_function (mhd_gtls_session_t session, 343MHD__gnutls_transport_set_pull_function (MHD_gtls_session_t session,
344 mhd_gtls_pull_func pull_func) 344 MHD_gtls_pull_func pull_func)
345{ 345{
346 session->internals._gnutls_pull_func = pull_func; 346 session->internals.MHD__gnutls_pull_func = pull_func;
347} 347}
348 348
349/** 349/**
350 * MHD_gnutls_transport_set_push_function - This function sets the function to send data 350 * MHD__gnutls_transport_set_push_function - This function sets the function to send data
351 * @push_func: a callback function similar to write() 351 * @push_func: a callback function similar to write()
352 * @session: gnutls session 352 * @session: gnutls session
353 * 353 *
@@ -358,11 +358,11 @@ MHD_gnutls_transport_set_pull_function (mhd_gtls_session_t session,
358 * specify this function for gnutls to be able to send data. 358 * specify this function for gnutls to be able to send data.
359 * 359 *
360 * PUSH_FUNC is of the form, 360 * PUSH_FUNC is of the form,
361 * ssize_t (*mhd_gtls_push_func)(gnutls_transport_ptr_t, const void*, size_t); 361 * ssize_t (*MHD_gtls_push_func)(MHD_gnutls_transport_ptr_t, const void*, size_t);
362 **/ 362 **/
363void 363void
364MHD_gnutls_transport_set_push_function (mhd_gtls_session_t session, 364MHD__gnutls_transport_set_push_function (MHD_gtls_session_t session,
365 mhd_gtls_push_func push_func) 365 MHD_gtls_push_func push_func)
366{ 366{
367 session->internals._gnutls_push_func = push_func; 367 session->internals.MHD__gnutls_push_func = push_func;
368} 368}
diff --git a/src/daemon/https/tls/gnutls_global.h b/src/daemon/https/tls/gnutls_global.h
index 7ec40882..8cfaf0ca 100644
--- a/src/daemon/https/tls/gnutls_global.h
+++ b/src/daemon/https/tls/gnutls_global.h
@@ -27,19 +27,19 @@
27 27
28#include <libtasn1.h> 28#include <libtasn1.h>
29 29
30/* this mutex is used to synchronize threads attemting call MHD_gnutls_global_init / MHD_gnutls_global_deinit */ 30/* this mutex is used to synchronize threads attemting call MHD__gnutls_global_init / MHD__gnutls_global_deinit */
31pthread_mutex_t gnutls_init_mutex; 31pthread_mutex_t MHD_gnutls_init_mutex;
32 32
33int gnutls_is_secure_memory (const void *mem); 33int MHD_gnutls_is_secure_memory (const void *mem);
34 34
35extern ASN1_TYPE _gnutls_pkix1_asn; 35extern ASN1_TYPE MHD__gnutls_pkix1_asn;
36extern ASN1_TYPE _gnutls_gnutls_asn; 36extern ASN1_TYPE MHD__gnutlsMHD__gnutls_asn;
37 37
38/* removed const from node_asn* to 38/* removed const from node_asn* to
39 * prevent warnings, since libtasn1 doesn't 39 * prevent warnings, since libtasn1 doesn't
40 * use the const keywork in its functions. 40 * use the const keywork in its functions.
41 */ 41 */
42#define _gnutls_get_gnutls_asn() ((node_asn*) _gnutls_gnutls_asn) 42#define MHD__gnutls_getMHD__gnutls_asn() ((node_asn*) MHD__gnutlsMHD__gnutls_asn)
43#define _gnutls_get_pkix() ((node_asn*) _gnutls_pkix1_asn) 43#define MHD__gnutls_get_pkix() ((node_asn*) MHD__gnutls_pkix1_asn)
44 44
45#endif 45#endif
diff --git a/src/daemon/https/tls/gnutls_handshake.c b/src/daemon/https/tls/gnutls_handshake.c
index e53d6985..31826448 100644
--- a/src/daemon/https/tls/gnutls_handshake.c
+++ b/src/daemon/https/tls/gnutls_handshake.c
@@ -46,12 +46,12 @@
46#include "gnutls_constate.h" 46#include "gnutls_constate.h"
47#include "gnutls_record.h" 47#include "gnutls_record.h"
48#include "gnutls_state.h" 48#include "gnutls_state.h"
49#include "gnutls_rsa_export.h" /* for gnutls_get_rsa_params() */ 49#include "gnutls_rsa_export.h" /* for MHD_gnutls_get_rsa_params() */
50#include "auth_anon.h" /* for mhd_gtls_anon_server_credentials_t */ 50#include "auth_anon.h" /* for MHD_gtls_anon_server_credentials_t */
51#include "gc.h" 51#include "gc.h"
52 52
53#ifdef HANDSHAKE_DEBUG 53#ifdef HANDSHAKE_DEBUG
54#define ERR(x, y) _gnutls_handshake_log( "HSK[%x]: %s (%d)\n", session, x,y) 54#define ERR(x, y) MHD__gnutls_handshake_log( "HSK[%x]: %s (%d)\n", session, x,y)
55#else 55#else
56#define ERR(x, y) 56#define ERR(x, y)
57#endif 57#endif
@@ -59,20 +59,20 @@
59#define TRUE 1 59#define TRUE 1
60#define FALSE 0 60#define FALSE 0
61 61
62static int _gnutls_server_select_comp_method (mhd_gtls_session_t session, 62static int MHD__gnutls_server_select_comp_method (MHD_gtls_session_t session,
63 opaque * data, int datalen); 63 opaque * data, int datalen);
64 64
65 65
66/* Clears the handshake hash buffers and handles. 66/* Clears the handshake hash buffers and handles.
67 */ 67 */
68inline static void 68inline static void
69_gnutls_handshake_hash_buffers_clear (mhd_gtls_session_t session) 69MHD__gnutls_handshake_hash_buffers_clear (MHD_gtls_session_t session)
70{ 70{
71 mhd_gnutls_hash_deinit (session->internals.handshake_mac_handle_md5, NULL); 71 MHD_gnutls_hash_deinit (session->internals.handshake_mac_handle_md5, NULL);
72 mhd_gnutls_hash_deinit (session->internals.handshake_mac_handle_sha, NULL); 72 MHD_gnutls_hash_deinit (session->internals.handshake_mac_handle_sha, NULL);
73 session->internals.handshake_mac_handle_md5 = NULL; 73 session->internals.handshake_mac_handle_md5 = NULL;
74 session->internals.handshake_mac_handle_sha = NULL; 74 session->internals.handshake_mac_handle_sha = NULL;
75 mhd_gtls_handshake_buffer_clear (session); 75 MHD_gtls_handshake_buffer_clear (session);
76} 76}
77 77
78/* this will copy the required values for resuming to 78/* this will copy the required values for resuming to
@@ -80,7 +80,7 @@ _gnutls_handshake_hash_buffers_clear (mhd_gtls_session_t session)
80 * this will keep as less data to security_parameters. 80 * this will keep as less data to security_parameters.
81 */ 81 */
82static void 82static void
83resume_copy_required_values (mhd_gtls_session_t session) 83resume_copy_required_values (MHD_gtls_session_t session)
84{ 84{
85 /* get the new random values */ 85 /* get the new random values */
86 memcpy (session->internals.resumed_security_parameters.server_random, 86 memcpy (session->internals.resumed_security_parameters.server_random,
@@ -105,7 +105,7 @@ resume_copy_required_values (mhd_gtls_session_t session)
105 session->security_parameters.entity = 105 session->security_parameters.entity =
106 session->internals.resumed_security_parameters.entity; 106 session->internals.resumed_security_parameters.entity;
107 107
108 mhd_gtls_set_current_version (session, 108 MHD_gtls_set_current_version (session,
109 session->internals. 109 session->internals.
110 resumed_security_parameters.version); 110 resumed_security_parameters.version);
111 111
@@ -120,13 +120,13 @@ resume_copy_required_values (mhd_gtls_session_t session)
120} 120}
121 121
122void 122void
123mhd_gtls_set_server_random (mhd_gtls_session_t session, uint8_t * rnd) 123MHD_gtls_set_server_random (MHD_gtls_session_t session, uint8_t * rnd)
124{ 124{
125 memcpy (session->security_parameters.server_random, rnd, TLS_RANDOM_SIZE); 125 memcpy (session->security_parameters.server_random, rnd, TLS_RANDOM_SIZE);
126} 126}
127 127
128void 128void
129mhd_gtls_set_client_random (mhd_gtls_session_t session, uint8_t * rnd) 129MHD_gtls_set_client_random (MHD_gtls_session_t session, uint8_t * rnd)
130{ 130{
131 memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE); 131 memcpy (session->security_parameters.client_random, rnd, TLS_RANDOM_SIZE);
132} 132}
@@ -136,25 +136,25 @@ mhd_gtls_set_client_random (mhd_gtls_session_t session, uint8_t * rnd)
136#define SSL3_SERVER_MSG "SRVR" 136#define SSL3_SERVER_MSG "SRVR"
137#define SSL_MSG_LEN 4 137#define SSL_MSG_LEN 4
138static int 138static int
139_gnutls_ssl3_finished (mhd_gtls_session_t session, int type, opaque * ret) 139MHD__gnutls_ssl3_finished (MHD_gtls_session_t session, int type, opaque * ret)
140{ 140{
141 const int siz = SSL_MSG_LEN; 141 const int siz = SSL_MSG_LEN;
142 mac_hd_t td_md5; 142 mac_hd_t td_md5;
143 mac_hd_t td_sha; 143 mac_hd_t td_sha;
144 const char *mesg; 144 const char *mesg;
145 145
146 td_md5 = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_md5); 146 td_md5 = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_md5);
147 if (td_md5 == NULL) 147 if (td_md5 == NULL)
148 { 148 {
149 gnutls_assert (); 149 MHD_gnutls_assert ();
150 return GNUTLS_E_HASH_FAILED; 150 return GNUTLS_E_HASH_FAILED;
151 } 151 }
152 152
153 td_sha = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_sha); 153 td_sha = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_sha);
154 if (td_sha == NULL) 154 if (td_sha == NULL)
155 { 155 {
156 gnutls_assert (); 156 MHD_gnutls_assert ();
157 mhd_gnutls_hash_deinit (td_md5, NULL); 157 MHD_gnutls_hash_deinit (td_md5, NULL);
158 return GNUTLS_E_HASH_FAILED; 158 return GNUTLS_E_HASH_FAILED;
159 } 159 }
160 160
@@ -167,13 +167,13 @@ _gnutls_ssl3_finished (mhd_gtls_session_t session, int type, opaque * ret)
167 mesg = SSL3_CLIENT_MSG; 167 mesg = SSL3_CLIENT_MSG;
168 } 168 }
169 169
170 mhd_gnutls_hash (td_md5, mesg, siz); 170 MHD_gnutls_hash (td_md5, mesg, siz);
171 mhd_gnutls_hash (td_sha, mesg, siz); 171 MHD_gnutls_hash (td_sha, mesg, siz);
172 172
173 mhd_gnutls_mac_deinit_ssl3_handshake (td_md5, ret, 173 MHD_gnutls_mac_deinit_ssl3_handshake (td_md5, ret,
174 session->security_parameters. 174 session->security_parameters.
175 master_secret, TLS_MASTER_SIZE); 175 master_secret, TLS_MASTER_SIZE);
176 mhd_gnutls_mac_deinit_ssl3_handshake (td_sha, &ret[16], 176 MHD_gnutls_mac_deinit_ssl3_handshake (td_sha, &ret[16],
177 session->security_parameters. 177 session->security_parameters.
178 master_secret, TLS_MASTER_SIZE); 178 master_secret, TLS_MASTER_SIZE);
179 179
@@ -185,7 +185,7 @@ _gnutls_ssl3_finished (mhd_gtls_session_t session, int type, opaque * ret)
185#define CLIENT_MSG "client finished" 185#define CLIENT_MSG "client finished"
186#define TLS_MSG_LEN 15 186#define TLS_MSG_LEN 15
187static int 187static int
188_gnutls_finished (mhd_gtls_session_t session, int type, void *ret) 188MHD__gnutls_finished (MHD_gtls_session_t session, int type, void *ret)
189{ 189{
190 const int siz = TLS_MSG_LEN; 190 const int siz = TLS_MSG_LEN;
191 opaque concat[36]; 191 opaque concat[36];
@@ -193,37 +193,37 @@ _gnutls_finished (mhd_gtls_session_t session, int type, void *ret)
193 const char *mesg; 193 const char *mesg;
194 mac_hd_t td_md5 = NULL; 194 mac_hd_t td_md5 = NULL;
195 mac_hd_t td_sha; 195 mac_hd_t td_sha;
196 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 196 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
197 197
198 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2) 198 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2)
199 { 199 {
200 td_md5 = 200 td_md5 =
201 mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_md5); 201 MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_md5);
202 if (td_md5 == NULL) 202 if (td_md5 == NULL)
203 { 203 {
204 gnutls_assert (); 204 MHD_gnutls_assert ();
205 return GNUTLS_E_HASH_FAILED; 205 return GNUTLS_E_HASH_FAILED;
206 } 206 }
207 } 207 }
208 208
209 td_sha = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_sha); 209 td_sha = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_sha);
210 if (td_sha == NULL) 210 if (td_sha == NULL)
211 { 211 {
212 gnutls_assert (); 212 MHD_gnutls_assert ();
213 if (td_md5 != NULL) 213 if (td_md5 != NULL)
214 mhd_gnutls_hash_deinit (td_md5, NULL); 214 MHD_gnutls_hash_deinit (td_md5, NULL);
215 return GNUTLS_E_HASH_FAILED; 215 return GNUTLS_E_HASH_FAILED;
216 } 216 }
217 217
218 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2) 218 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2)
219 { 219 {
220 mhd_gnutls_hash_deinit (td_md5, concat); 220 MHD_gnutls_hash_deinit (td_md5, concat);
221 mhd_gnutls_hash_deinit (td_sha, &concat[16]); 221 MHD_gnutls_hash_deinit (td_sha, &concat[16]);
222 len = 20 + 16; 222 len = 20 + 16;
223 } 223 }
224 else 224 else
225 { 225 {
226 mhd_gnutls_hash_deinit (td_sha, concat); 226 MHD_gnutls_hash_deinit (td_sha, concat);
227 len = 20; 227 len = 20;
228 } 228 }
229 229
@@ -236,7 +236,7 @@ _gnutls_finished (mhd_gtls_session_t session, int type, void *ret)
236 mesg = CLIENT_MSG; 236 mesg = CLIENT_MSG;
237 } 237 }
238 238
239 return mhd_gtls_PRF (session, session->security_parameters.master_secret, 239 return MHD_gtls_PRF (session, session->security_parameters.master_secret,
240 TLS_MASTER_SIZE, mesg, siz, concat, len, 12, ret); 240 TLS_MASTER_SIZE, mesg, siz, concat, len, 12, ret);
241} 241}
242 242
@@ -244,7 +244,7 @@ _gnutls_finished (mhd_gtls_session_t session, int type, void *ret)
244 * and put it to dst. 244 * and put it to dst.
245 */ 245 */
246int 246int
247mhd_gtls_tls_create_random (opaque * dst) 247MHD_gtls_tls_create_random (opaque * dst)
248{ 248{
249 uint32_t tim; 249 uint32_t tim;
250 250
@@ -255,11 +255,11 @@ mhd_gtls_tls_create_random (opaque * dst)
255 255
256 tim = time (NULL); 256 tim = time (NULL);
257 /* generate server random value */ 257 /* generate server random value */
258 mhd_gtls_write_uint32 (tim, dst); 258 MHD_gtls_write_uint32 (tim, dst);
259 259
260 if (gc_nonce (&dst[4], TLS_RANDOM_SIZE - 4) != GC_OK) 260 if (MHD_gc_nonce (&dst[4], TLS_RANDOM_SIZE - 4) != GC_OK)
261 { 261 {
262 gnutls_assert (); 262 MHD_gnutls_assert ();
263 return GNUTLS_E_RANDOM_FAILED; 263 return GNUTLS_E_RANDOM_FAILED;
264 } 264 }
265 265
@@ -269,23 +269,23 @@ mhd_gtls_tls_create_random (opaque * dst)
269/* returns the 0 on success or a negative value. 269/* returns the 0 on success or a negative value.
270 */ 270 */
271int 271int
272mhd_gtls_negotiate_version (mhd_gtls_session_t session, 272MHD_gtls_negotiate_version (MHD_gtls_session_t session,
273 enum MHD_GNUTLS_Protocol adv_version) 273 enum MHD_GNUTLS_Protocol adv_version)
274{ 274{
275 int ret; 275 int ret;
276 276
277 /* if we do not support that version */ 277 /* if we do not support that version */
278 if (mhd_gtls_version_is_supported (session, adv_version) == 0) 278 if (MHD_gtls_version_is_supported (session, adv_version) == 0)
279 { 279 {
280 /* If he requested something we do not support 280 /* If he requested something we do not support
281 * then we send him the highest we support. 281 * then we send him the highest we support.
282 */ 282 */
283 ret = mhd_gtls_version_max (session); 283 ret = MHD_gtls_version_max (session);
284 if (ret == MHD_GNUTLS_PROTOCOL_VERSION_UNKNOWN) 284 if (ret == MHD_GNUTLS_PROTOCOL_VERSION_UNKNOWN)
285 { 285 {
286 /* this check is not really needed. 286 /* this check is not really needed.
287 */ 287 */
288 gnutls_assert (); 288 MHD_gnutls_assert ();
289 return GNUTLS_E_UNKNOWN_CIPHER_SUITE; 289 return GNUTLS_E_UNKNOWN_CIPHER_SUITE;
290 } 290 }
291 } 291 }
@@ -294,13 +294,13 @@ mhd_gtls_negotiate_version (mhd_gtls_session_t session,
294 ret = adv_version; 294 ret = adv_version;
295 } 295 }
296 296
297 mhd_gtls_set_current_version (session, ret); 297 MHD_gtls_set_current_version (session, ret);
298 298
299 return ret; 299 return ret;
300} 300}
301 301
302int 302int
303mhd_gtls_user_hello_func (mhd_gtls_session_t session, 303MHD_gtls_user_hello_func (MHD_gtls_session_t session,
304 enum MHD_GNUTLS_Protocol adv_version) 304 enum MHD_GNUTLS_Protocol adv_version)
305{ 305{
306 int ret; 306 int ret;
@@ -310,16 +310,16 @@ mhd_gtls_user_hello_func (mhd_gtls_session_t session,
310 ret = session->internals.user_hello_func (session); 310 ret = session->internals.user_hello_func (session);
311 if (ret < 0) 311 if (ret < 0)
312 { 312 {
313 gnutls_assert (); 313 MHD_gnutls_assert ();
314 return ret; 314 return ret;
315 } 315 }
316 /* Here we need to renegotiate the version since the callee might 316 /* Here we need to renegotiate the version since the callee might
317 * have disabled some TLS versions. 317 * have disabled some TLS versions.
318 */ 318 */
319 ret = mhd_gtls_negotiate_version (session, adv_version); 319 ret = MHD_gtls_negotiate_version (session, adv_version);
320 if (ret < 0) 320 if (ret < 0)
321 { 321 {
322 gnutls_assert (); 322 MHD_gnutls_assert ();
323 return ret; 323 return ret;
324 } 324 }
325 } 325 }
@@ -332,7 +332,7 @@ mhd_gtls_user_hello_func (mhd_gtls_session_t session,
332 * since SSL version 2.0 is not supported). 332 * since SSL version 2.0 is not supported).
333 */ 333 */
334static int 334static int
335_gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data, 335MHD__gnutls_read_client_hello (MHD_gtls_session_t session, opaque * data,
336 int datalen) 336 int datalen)
337{ 337{
338 uint8_t session_id_len; 338 uint8_t session_id_len;
@@ -345,28 +345,28 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
345 345
346 DECR_LEN (len, 2); 346 DECR_LEN (len, 2);
347 347
348 _gnutls_handshake_log ("HSK[%x]: Client's version: %d.%d\n", session, 348 MHD__gnutls_handshake_log ("HSK[%x]: Client's version: %d.%d\n", session,
349 data[pos], data[pos + 1]); 349 data[pos], data[pos + 1]);
350 350
351 adv_version = mhd_gtls_version_get (data[pos], data[pos + 1]); 351 adv_version = MHD_gtls_version_get (data[pos], data[pos + 1]);
352 set_adv_version (session, data[pos], data[pos + 1]); 352 set_adv_version (session, data[pos], data[pos + 1]);
353 pos += 2; 353 pos += 2;
354 354
355 neg_version = mhd_gtls_negotiate_version (session, adv_version); 355 neg_version = MHD_gtls_negotiate_version (session, adv_version);
356 if (neg_version < 0) 356 if (neg_version < 0)
357 { 357 {
358 gnutls_assert (); 358 MHD_gnutls_assert ();
359 return ret; 359 return ret;
360 } 360 }
361 361
362 /* Read client random value. 362 /* Read client random value.
363 */ 363 */
364 DECR_LEN (len, TLS_RANDOM_SIZE); 364 DECR_LEN (len, TLS_RANDOM_SIZE);
365 mhd_gtls_set_client_random (session, &data[pos]); 365 MHD_gtls_set_client_random (session, &data[pos]);
366 pos += TLS_RANDOM_SIZE; 366 pos += TLS_RANDOM_SIZE;
367 367
368 mhd_gtls_tls_create_random (rnd); 368 MHD_gtls_tls_create_random (rnd);
369 mhd_gtls_set_server_random (session, rnd); 369 MHD_gtls_set_server_random (session, rnd);
370 370
371 session->security_parameters.timestamp = time (NULL); 371 session->security_parameters.timestamp = time (NULL);
372 372
@@ -376,7 +376,7 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
376 /* RESUME SESSION */ 376 /* RESUME SESSION */
377 if (session_id_len > TLS_MAX_SESSION_ID_SIZE) 377 if (session_id_len > TLS_MAX_SESSION_ID_SIZE)
378 { 378 {
379 gnutls_assert (); 379 MHD_gnutls_assert ();
380 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 380 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
381 } 381 }
382 DECR_LEN (len, session_id_len); 382 DECR_LEN (len, session_id_len);
@@ -388,11 +388,11 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
388 { /* resumed! */ 388 { /* resumed! */
389 resume_copy_required_values (session); 389 resume_copy_required_values (session);
390 session->internals.resumed = RESUME_TRUE; 390 session->internals.resumed = RESUME_TRUE;
391 return mhd_gtls_user_hello_func (session, adv_version); 391 return MHD_gtls_user_hello_func (session, adv_version);
392 } 392 }
393 else 393 else
394 { 394 {
395 mhd_gtls_generate_session_id (session->security_parameters.session_id, 395 MHD_gtls_generate_session_id (session->security_parameters.session_id,
396 &session->security_parameters. 396 &session->security_parameters.
397 session_id_size); 397 session_id_size);
398 398
@@ -402,7 +402,7 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
402 /* Remember ciphersuites for later 402 /* Remember ciphersuites for later
403 */ 403 */
404 DECR_LEN (len, 2); 404 DECR_LEN (len, 2);
405 suite_size = mhd_gtls_read_uint16 (&data[pos]); 405 suite_size = MHD_gtls_read_uint16 (&data[pos]);
406 pos += 2; 406 pos += 2;
407 407
408 DECR_LEN (len, suite_size); 408 DECR_LEN (len, suite_size);
@@ -422,45 +422,45 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
422 */ 422 */
423 if (neg_version >= MHD_GNUTLS_PROTOCOL_TLS1_0) 423 if (neg_version >= MHD_GNUTLS_PROTOCOL_TLS1_0)
424 { 424 {
425 ret = mhd_gtls_parse_extensions (session, EXTENSION_APPLICATION, &data[pos], len); /* len is the rest of the parsed length */ 425 ret = MHD_gtls_parse_extensions (session, EXTENSION_APPLICATION, &data[pos], len); /* len is the rest of the parsed length */
426 if (ret < 0) 426 if (ret < 0)
427 { 427 {
428 gnutls_assert (); 428 MHD_gnutls_assert ();
429 return ret; 429 return ret;
430 } 430 }
431 } 431 }
432 432
433 ret = mhd_gtls_user_hello_func (session, adv_version); 433 ret = MHD_gtls_user_hello_func (session, adv_version);
434 if (ret < 0) 434 if (ret < 0)
435 { 435 {
436 gnutls_assert (); 436 MHD_gnutls_assert ();
437 return ret; 437 return ret;
438 } 438 }
439 439
440 if (neg_version >= MHD_GNUTLS_PROTOCOL_TLS1_0) 440 if (neg_version >= MHD_GNUTLS_PROTOCOL_TLS1_0)
441 { 441 {
442 ret = mhd_gtls_parse_extensions (session, EXTENSION_TLS, &data[pos], len); /* len is the rest of the parsed length */ 442 ret = MHD_gtls_parse_extensions (session, EXTENSION_TLS, &data[pos], len); /* len is the rest of the parsed length */
443 if (ret < 0) 443 if (ret < 0)
444 { 444 {
445 gnutls_assert (); 445 MHD_gnutls_assert ();
446 return ret; 446 return ret;
447 } 447 }
448 } 448 }
449 449
450 /* select an appropriate cipher suite 450 /* select an appropriate cipher suite
451 */ 451 */
452 ret = mhd_gtls_server_select_suite (session, suite_ptr, suite_size); 452 ret = MHD_gtls_server_select_suite (session, suite_ptr, suite_size);
453 if (ret < 0) 453 if (ret < 0)
454 { 454 {
455 gnutls_assert (); 455 MHD_gnutls_assert ();
456 return ret; 456 return ret;
457 } 457 }
458 458
459 /* select appropriate compression method */ 459 /* select appropriate compression method */
460 ret = _gnutls_server_select_comp_method (session, comp_ptr, comp_size); 460 ret = MHD__gnutls_server_select_comp_method (session, comp_ptr, comp_size);
461 if (ret < 0) 461 if (ret < 0)
462 { 462 {
463 gnutls_assert (); 463 MHD_gnutls_assert ();
464 return ret; 464 return ret;
465 } 465 }
466 466
@@ -470,7 +470,7 @@ _gnutls_read_client_hello (mhd_gtls_session_t session, opaque * data,
470/* here we hash all pending data. 470/* here we hash all pending data.
471 */ 471 */
472inline static int 472inline static int
473_gnutls_handshake_hash_pending (mhd_gtls_session_t session) 473MHD__gnutls_handshake_hash_pending (MHD_gtls_session_t session)
474{ 474{
475 size_t siz; 475 size_t siz;
476 int ret; 476 int ret;
@@ -479,27 +479,27 @@ _gnutls_handshake_hash_pending (mhd_gtls_session_t session)
479 if (session->internals.handshake_mac_handle_sha == NULL || 479 if (session->internals.handshake_mac_handle_sha == NULL ||
480 session->internals.handshake_mac_handle_md5 == NULL) 480 session->internals.handshake_mac_handle_md5 == NULL)
481 { 481 {
482 gnutls_assert (); 482 MHD_gnutls_assert ();
483 return GNUTLS_E_INTERNAL_ERROR; 483 return GNUTLS_E_INTERNAL_ERROR;
484 } 484 }
485 485
486 /* We check if there are pending data to hash. 486 /* We check if there are pending data to hash.
487 */ 487 */
488 if ((ret = mhd_gtls_handshake_buffer_get_ptr (session, &data, &siz)) < 0) 488 if ((ret = MHD_gtls_handshake_buffer_get_ptr (session, &data, &siz)) < 0)
489 { 489 {
490 gnutls_assert (); 490 MHD_gnutls_assert ();
491 return ret; 491 return ret;
492 } 492 }
493 493
494 if (siz > 0) 494 if (siz > 0)
495 { 495 {
496 mhd_gnutls_hash (session->internals.handshake_mac_handle_sha, data, 496 MHD_gnutls_hash (session->internals.handshake_mac_handle_sha, data,
497 siz); 497 siz);
498 mhd_gnutls_hash (session->internals.handshake_mac_handle_md5, data, 498 MHD_gnutls_hash (session->internals.handshake_mac_handle_md5, data,
499 siz); 499 siz);
500 } 500 }
501 501
502 mhd_gtls_handshake_buffer_empty (session); 502 MHD_gtls_handshake_buffer_empty (session);
503 503
504 return 0; 504 return 0;
505} 505}
@@ -510,7 +510,7 @@ _gnutls_handshake_hash_pending (mhd_gtls_session_t session)
510 * we send. 510 * we send.
511 */ 511 */
512static int 512static int
513_gnutls_send_finished (mhd_gtls_session_t session, int again) 513MHD__gnutls_send_finished (MHD_gtls_session_t session, int again)
514{ 514{
515 uint8_t data[36]; 515 uint8_t data[36];
516 int ret; 516 int ret;
@@ -523,37 +523,37 @@ _gnutls_send_finished (mhd_gtls_session_t session, int again)
523 /* This is needed in order to hash all the required 523 /* This is needed in order to hash all the required
524 * messages. 524 * messages.
525 */ 525 */
526 if ((ret = _gnutls_handshake_hash_pending (session)) < 0) 526 if ((ret = MHD__gnutls_handshake_hash_pending (session)) < 0)
527 { 527 {
528 gnutls_assert (); 528 MHD_gnutls_assert ();
529 return ret; 529 return ret;
530 } 530 }
531 531
532 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 532 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
533 { 533 {
534 ret = 534 ret =
535 _gnutls_ssl3_finished (session, 535 MHD__gnutls_ssl3_finished (session,
536 session->security_parameters.entity, data); 536 session->security_parameters.entity, data);
537 data_size = 36; 537 data_size = 36;
538 } 538 }
539 else 539 else
540 { /* TLS 1.0 */ 540 { /* TLS 1.0 */
541 ret = 541 ret =
542 _gnutls_finished (session, 542 MHD__gnutls_finished (session,
543 session->security_parameters.entity, data); 543 session->security_parameters.entity, data);
544 data_size = 12; 544 data_size = 12;
545 } 545 }
546 546
547 if (ret < 0) 547 if (ret < 0)
548 { 548 {
549 gnutls_assert (); 549 MHD_gnutls_assert ();
550 return ret; 550 return ret;
551 } 551 }
552 552
553 } 553 }
554 554
555 ret = 555 ret =
556 mhd_gtls_send_handshake (session, data, data_size, 556 MHD_gtls_send_handshake (session, data, data_size,
557 GNUTLS_HANDSHAKE_FINISHED); 557 GNUTLS_HANDSHAKE_FINISHED);
558 558
559 return ret; 559 return ret;
@@ -563,7 +563,7 @@ _gnutls_send_finished (mhd_gtls_session_t session, int again)
563 * went fine we have negotiated a secure connection 563 * went fine we have negotiated a secure connection
564 */ 564 */
565static int 565static int
566_gnutls_recv_finished (mhd_gtls_session_t session) 566MHD__gnutls_recv_finished (MHD_gtls_session_t session)
567{ 567{
568 uint8_t data[36], *vrfy; 568 uint8_t data[36], *vrfy;
569 int data_size; 569 int data_size;
@@ -571,17 +571,17 @@ _gnutls_recv_finished (mhd_gtls_session_t session)
571 int vrfysize; 571 int vrfysize;
572 572
573 ret = 573 ret =
574 mhd_gtls_recv_handshake (session, &vrfy, &vrfysize, 574 MHD_gtls_recv_handshake (session, &vrfy, &vrfysize,
575 GNUTLS_HANDSHAKE_FINISHED, MANDATORY_PACKET); 575 GNUTLS_HANDSHAKE_FINISHED, MANDATORY_PACKET);
576 if (ret < 0) 576 if (ret < 0)
577 { 577 {
578 ERR ("recv finished int", ret); 578 ERR ("recv finished int", ret);
579 gnutls_assert (); 579 MHD_gnutls_assert ();
580 return ret; 580 return ret;
581 } 581 }
582 582
583 583
584 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 584 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
585 { 585 {
586 data_size = 36; 586 data_size = 36;
587 } 587 }
@@ -592,39 +592,39 @@ _gnutls_recv_finished (mhd_gtls_session_t session)
592 592
593 if (vrfysize != data_size) 593 if (vrfysize != data_size)
594 { 594 {
595 gnutls_assert (); 595 MHD_gnutls_assert ();
596 gnutls_free (vrfy); 596 MHD_gnutls_free (vrfy);
597 return GNUTLS_E_ERROR_IN_FINISHED_PACKET; 597 return GNUTLS_E_ERROR_IN_FINISHED_PACKET;
598 } 598 }
599 599
600 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 600 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
601 { 601 {
602 ret = 602 ret =
603 _gnutls_ssl3_finished (session, 603 MHD__gnutls_ssl3_finished (session,
604 (session->security_parameters.entity + 1) % 2, 604 (session->security_parameters.entity + 1) % 2,
605 data); 605 data);
606 } 606 }
607 else 607 else
608 { /* TLS 1.0 */ 608 { /* TLS 1.0 */
609 ret = 609 ret =
610 _gnutls_finished (session, 610 MHD__gnutls_finished (session,
611 (session->security_parameters.entity + 611 (session->security_parameters.entity +
612 1) % 2, data); 612 1) % 2, data);
613 } 613 }
614 614
615 if (ret < 0) 615 if (ret < 0)
616 { 616 {
617 gnutls_assert (); 617 MHD_gnutls_assert ();
618 gnutls_free (vrfy); 618 MHD_gnutls_free (vrfy);
619 return ret; 619 return ret;
620 } 620 }
621 621
622 if (memcmp (vrfy, data, data_size) != 0) 622 if (memcmp (vrfy, data, data_size) != 0)
623 { 623 {
624 gnutls_assert (); 624 MHD_gnutls_assert ();
625 ret = GNUTLS_E_ERROR_IN_FINISHED_PACKET; 625 ret = GNUTLS_E_ERROR_IN_FINISHED_PACKET;
626 } 626 }
627 gnutls_free (vrfy); 627 MHD_gnutls_free (vrfy);
628 628
629 return ret; 629 return ret;
630} 630}
@@ -633,7 +633,7 @@ _gnutls_recv_finished (mhd_gtls_session_t session)
633 * RSA algorithms, PK_DSA if DSS, and PK_ANY for both or PK_NONE for none. 633 * RSA algorithms, PK_DSA if DSS, and PK_ANY for both or PK_NONE for none.
634 */ 634 */
635static int 635static int
636_gnutls_server_find_pk_algos_in_ciphersuites (const opaque * 636MHD__gnutls_server_find_pk_algos_in_ciphersuites (const opaque *
637 data, int datalen) 637 data, int datalen)
638{ 638{
639 int j; 639 int j;
@@ -643,18 +643,18 @@ _gnutls_server_find_pk_algos_in_ciphersuites (const opaque *
643 643
644 if (datalen % 2 != 0) 644 if (datalen % 2 != 0)
645 { 645 {
646 gnutls_assert (); 646 MHD_gnutls_assert ();
647 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 647 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
648 } 648 }
649 649
650 for (j = 0; j < datalen; j += 2) 650 for (j = 0; j < datalen; j += 2)
651 { 651 {
652 memcpy (&cs.suite, &data[j], 2); 652 memcpy (&cs.suite, &data[j], 2);
653 kx = mhd_gtls_cipher_suite_get_kx_algo (&cs); 653 kx = MHD_gtls_cipher_suite_get_kx_algo (&cs);
654 654
655 if (mhd_gtls_map_kx_get_cred (kx, 1) == MHD_GNUTLS_CRD_CERTIFICATE) 655 if (MHD_gtls_map_kx_get_cred (kx, 1) == MHD_GNUTLS_CRD_CERTIFICATE)
656 { 656 {
657 algo = mhd_gtls_map_pk_get_pk (kx); 657 algo = MHD_gtls_map_pk_get_pk (kx);
658 658
659 if (algo != prev_algo && prev_algo != 0) 659 if (algo != prev_algo && prev_algo != 0)
660 return GNUTLS_PK_ANY; 660 return GNUTLS_PK_ANY;
@@ -670,7 +670,7 @@ _gnutls_server_find_pk_algos_in_ciphersuites (const opaque *
670 * it adds the suite to the session and performs some checks. 670 * it adds the suite to the session and performs some checks.
671 */ 671 */
672int 672int
673mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data, 673MHD_gtls_server_select_suite (MHD_gtls_session_t session, opaque * data,
674 int datalen) 674 int datalen)
675{ 675{
676 int x, i, j; 676 int x, i, j;
@@ -680,12 +680,12 @@ mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data,
680 * supported by the peer. 680 * supported by the peer.
681 */ 681 */
682 682
683 pk_algo = _gnutls_server_find_pk_algos_in_ciphersuites (data, datalen); 683 pk_algo = MHD__gnutls_server_find_pk_algos_in_ciphersuites (data, datalen);
684 684
685 x = mhd_gtls_supported_ciphersuites (session, &ciphers); 685 x = MHD_gtls_supported_ciphersuites (session, &ciphers);
686 if (x < 0) 686 if (x < 0)
687 { /* the case x==0 is handled within the function. */ 687 { /* the case x==0 is handled within the function. */
688 gnutls_assert (); 688 MHD_gnutls_assert ();
689 return x; 689 return x;
690 } 690 }
691 691
@@ -693,11 +693,11 @@ mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data,
693 * the certificate requested, or to the 693 * the certificate requested, or to the
694 * authentication requested (e.g. SRP). 694 * authentication requested (e.g. SRP).
695 */ 695 */
696 x = mhd_gtls_remove_unwanted_ciphersuites (session, &ciphers, x, pk_algo); 696 x = MHD_gtls_remove_unwanted_ciphersuites (session, &ciphers, x, pk_algo);
697 if (x <= 0) 697 if (x <= 0)
698 { 698 {
699 gnutls_assert (); 699 MHD_gnutls_assert ();
700 gnutls_free (ciphers); 700 MHD_gnutls_free (ciphers);
701 if (x < 0) 701 if (x < 0)
702 return x; 702 return x;
703 else 703 else
@@ -710,21 +710,21 @@ mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data,
710 */ 710 */
711 if (datalen % 2 != 0) 711 if (datalen % 2 != 0)
712 { 712 {
713 gnutls_assert (); 713 MHD_gnutls_assert ();
714 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 714 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
715 } 715 }
716#ifdef HANDSHAKE_DEBUG 716#ifdef HANDSHAKE_DEBUG
717 717
718 _gnutls_handshake_log ("HSK[%x]: Requested cipher suites: \n", session); 718 MHD__gnutls_handshake_log ("HSK[%x]: Requested cipher suites: \n", session);
719 for (j = 0; j < datalen; j += 2) 719 for (j = 0; j < datalen; j += 2)
720 { 720 {
721 memcpy (&cs.suite, &data[j], 2); 721 memcpy (&cs.suite, &data[j], 2);
722 _gnutls_handshake_log ("\t%s\n", mhd_gtls_cipher_suite_get_name (&cs)); 722 MHD__gnutls_handshake_log ("\t%s\n", MHD_gtls_cipher_suite_get_name (&cs));
723 } 723 }
724 _gnutls_handshake_log ("HSK[%x]: Supported cipher suites: \n", session); 724 MHD__gnutls_handshake_log ("HSK[%x]: Supported cipher suites: \n", session);
725 for (j = 0; j < x; j++) 725 for (j = 0; j < x; j++)
726 _gnutls_handshake_log ("\t%s\n", 726 MHD__gnutls_handshake_log ("\t%s\n",
727 mhd_gtls_cipher_suite_get_name (&ciphers[j])); 727 MHD_gtls_cipher_suite_get_name (&ciphers[j]));
728#endif 728#endif
729 memset (session->security_parameters.current_cipher_suite.suite, '\0', 2); 729 memset (session->security_parameters.current_cipher_suite.suite, '\0', 2);
730 730
@@ -738,9 +738,9 @@ mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data,
738 { 738 {
739 memcpy (&cs.suite, &data[j], 2); 739 memcpy (&cs.suite, &data[j], 2);
740 740
741 _gnutls_handshake_log 741 MHD__gnutls_handshake_log
742 ("HSK[%x]: Selected cipher suite: %s\n", session, 742 ("HSK[%x]: Selected cipher suite: %s\n", session,
743 mhd_gtls_cipher_suite_get_name (&cs)); 743 MHD_gtls_cipher_suite_get_name (&cs));
744 memcpy (session->security_parameters.current_cipher_suite.suite, 744 memcpy (session->security_parameters.current_cipher_suite.suite,
745 ciphers[i].suite, 2); 745 ciphers[i].suite, 2);
746 retval = 0; 746 retval = 0;
@@ -750,42 +750,42 @@ mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data,
750 } 750 }
751 751
752finish: 752finish:
753 gnutls_free (ciphers); 753 MHD_gnutls_free (ciphers);
754 754
755 if (retval != 0) 755 if (retval != 0)
756 { 756 {
757 gnutls_assert (); 757 MHD_gnutls_assert ();
758 return retval; 758 return retval;
759 } 759 }
760 760
761 /* check if the credentials (username, public key etc.) are ok 761 /* check if the credentials (username, public key etc.) are ok
762 */ 762 */
763 if (mhd_gtls_get_kx_cred 763 if (MHD_gtls_get_kx_cred
764 (session, 764 (session,
765 mhd_gtls_cipher_suite_get_kx_algo (&session->security_parameters. 765 MHD_gtls_cipher_suite_get_kx_algo (&session->security_parameters.
766 current_cipher_suite), &err) == NULL 766 current_cipher_suite), &err) == NULL
767 && err != 0) 767 && err != 0)
768 { 768 {
769 gnutls_assert (); 769 MHD_gnutls_assert ();
770 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 770 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
771 } 771 }
772 772
773 773
774 /* set the mhd_gtls_mod_auth_st to the appropriate struct 774 /* set the MHD_gtls_mod_auth_st to the appropriate struct
775 * according to the KX algorithm. This is needed since all the 775 * according to the KX algorithm. This is needed since all the
776 * handshake functions are read from there; 776 * handshake functions are read from there;
777 */ 777 */
778 session->internals.auth_struct = 778 session->internals.auth_struct =
779 mhd_gtls_kx_auth_struct (mhd_gtls_cipher_suite_get_kx_algo 779 MHD_gtls_kx_auth_struct (MHD_gtls_cipher_suite_get_kx_algo
780 (&session->security_parameters. 780 (&session->security_parameters.
781 current_cipher_suite)); 781 current_cipher_suite));
782 if (session->internals.auth_struct == NULL) 782 if (session->internals.auth_struct == NULL)
783 { 783 {
784 784
785 _gnutls_handshake_log 785 MHD__gnutls_handshake_log
786 ("HSK[%x]: Cannot find the appropriate handler for the KX algorithm\n", 786 ("HSK[%x]: Cannot find the appropriate handler for the KX algorithm\n",
787 session); 787 session);
788 gnutls_assert (); 788 MHD_gnutls_assert ();
789 return GNUTLS_E_INTERNAL_ERROR; 789 return GNUTLS_E_INTERNAL_ERROR;
790 } 790 }
791 791
@@ -797,16 +797,16 @@ finish:
797/* This selects the best supported compression method from the ones provided 797/* This selects the best supported compression method from the ones provided
798 */ 798 */
799static int 799static int
800_gnutls_server_select_comp_method (mhd_gtls_session_t session, 800MHD__gnutls_server_select_comp_method (MHD_gtls_session_t session,
801 opaque * data, int datalen) 801 opaque * data, int datalen)
802{ 802{
803 int x, i, j; 803 int x, i, j;
804 uint8_t *comps; 804 uint8_t *comps;
805 805
806 x = mhd_gtls_supported_compression_methods (session, &comps); 806 x = MHD_gtls_supported_compression_methods (session, &comps);
807 if (x < 0) 807 if (x < 0)
808 { 808 {
809 gnutls_assert (); 809 MHD_gnutls_assert ();
810 return x; 810 return x;
811 } 811 }
812 812
@@ -820,12 +820,12 @@ _gnutls_server_select_comp_method (mhd_gtls_session_t session,
820 if (comps[i] == data[j]) 820 if (comps[i] == data[j])
821 { 821 {
822 enum MHD_GNUTLS_CompressionMethod method = 822 enum MHD_GNUTLS_CompressionMethod method =
823 mhd_gtls_compression_get_id (comps[i]); 823 MHD_gtls_compression_get_id_from_int (comps[i]);
824 824
825 session->internals.compression_method = method; 825 session->internals.compression_method = method;
826 gnutls_free (comps); 826 MHD_gnutls_free (comps);
827 827
828 _gnutls_handshake_log 828 MHD__gnutls_handshake_log
829 ("HSK[%x]: Selected Compression Method: %s\n", session, 829 ("HSK[%x]: Selected Compression Method: %s\n", session,
830 MHD_gtls_compression_get_name (session->internals. 830 MHD_gtls_compression_get_name (session->internals.
831 compression_method)); 831 compression_method));
@@ -839,20 +839,20 @@ _gnutls_server_select_comp_method (mhd_gtls_session_t session,
839 /* we were not able to find a compatible compression 839 /* we were not able to find a compatible compression
840 * algorithm 840 * algorithm
841 */ 841 */
842 gnutls_free (comps); 842 MHD_gnutls_free (comps);
843 gnutls_assert (); 843 MHD_gnutls_assert ();
844 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 844 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
845 845
846} 846}
847 847
848/* This function sends an empty handshake packet. (like hello request). 848/* This function sends an empty handshake packet. (like hello request).
849 * If the previous _gnutls_send_empty_handshake() returned 849 * If the previous MHD__gnutls_send_empty_handshake() returned
850 * GNUTLS_E_AGAIN or GNUTLS_E_INTERRUPTED, then it must be called again 850 * GNUTLS_E_AGAIN or GNUTLS_E_INTERRUPTED, then it must be called again
851 * (until it returns ok), with NULL parameters. 851 * (until it returns ok), with NULL parameters.
852 */ 852 */
853static int 853static int
854_gnutls_send_empty_handshake (mhd_gtls_session_t session, 854MHD__gnutls_send_empty_handshake (MHD_gtls_session_t session,
855 gnutls_handshake_description_t type, int again) 855 MHD_gnutls_handshake_description_t type, int again)
856{ 856{
857 opaque data = 0; 857 opaque data = 0;
858 opaque *ptr; 858 opaque *ptr;
@@ -862,29 +862,29 @@ _gnutls_send_empty_handshake (mhd_gtls_session_t session,
862 else 862 else
863 ptr = NULL; 863 ptr = NULL;
864 864
865 return mhd_gtls_send_handshake (session, ptr, 0, type); 865 return MHD_gtls_send_handshake (session, ptr, 0, type);
866} 866}
867 867
868 868
869/* This function will hash the handshake message we sent. */ 869/* This function will hash the handshake message we sent. */
870static int 870static int
871_gnutls_handshake_hash_add_sent (mhd_gtls_session_t session, 871MHD__gnutls_handshake_hash_add_sent (MHD_gtls_session_t session,
872 gnutls_handshake_description_t type, 872 MHD_gnutls_handshake_description_t type,
873 opaque * dataptr, uint32_t datalen) 873 opaque * dataptr, uint32_t datalen)
874{ 874{
875 int ret; 875 int ret;
876 876
877 if ((ret = _gnutls_handshake_hash_pending (session)) < 0) 877 if ((ret = MHD__gnutls_handshake_hash_pending (session)) < 0)
878 { 878 {
879 gnutls_assert (); 879 MHD_gnutls_assert ();
880 return ret; 880 return ret;
881 } 881 }
882 882
883 if (type != GNUTLS_HANDSHAKE_HELLO_REQUEST) 883 if (type != GNUTLS_HANDSHAKE_HELLO_REQUEST)
884 { 884 {
885 mhd_gnutls_hash (session->internals.handshake_mac_handle_sha, dataptr, 885 MHD_gnutls_hash (session->internals.handshake_mac_handle_sha, dataptr,
886 datalen); 886 datalen);
887 mhd_gnutls_hash (session->internals.handshake_mac_handle_md5, dataptr, 887 MHD_gnutls_hash (session->internals.handshake_mac_handle_md5, dataptr,
888 datalen); 888 datalen);
889 } 889 }
890 890
@@ -893,14 +893,14 @@ _gnutls_handshake_hash_add_sent (mhd_gtls_session_t session,
893 893
894 894
895/* This function sends a handshake message of type 'type' containing the 895/* This function sends a handshake message of type 'type' containing the
896 * data specified here. If the previous mhd_gtls_send_handshake() returned 896 * data specified here. If the previous MHD_gtls_send_handshake() returned
897 * GNUTLS_E_AGAIN or GNUTLS_E_INTERRUPTED, then it must be called again 897 * GNUTLS_E_AGAIN or GNUTLS_E_INTERRUPTED, then it must be called again
898 * (until it returns ok), with NULL parameters. 898 * (until it returns ok), with NULL parameters.
899 */ 899 */
900int 900int
901mhd_gtls_send_handshake (mhd_gtls_session_t session, void *i_data, 901MHD_gtls_send_handshake (MHD_gtls_session_t session, void *i_data,
902 uint32_t i_datasize, 902 uint32_t i_datasize,
903 gnutls_handshake_description_t type) 903 MHD_gnutls_handshake_description_t type)
904{ 904{
905 int ret; 905 int ret;
906 uint8_t *data; 906 uint8_t *data;
@@ -912,28 +912,28 @@ mhd_gtls_send_handshake (mhd_gtls_session_t session, void *i_data,
912 /* we are resuming a previously interrupted 912 /* we are resuming a previously interrupted
913 * send. 913 * send.
914 */ 914 */
915 ret = mhd_gtls_handshake_io_write_flush (session); 915 ret = MHD_gtls_handshake_io_write_flush (session);
916 return ret; 916 return ret;
917 917
918 } 918 }
919 919
920 if (i_data == NULL && i_datasize > 0) 920 if (i_data == NULL && i_datasize > 0)
921 { 921 {
922 gnutls_assert (); 922 MHD_gnutls_assert ();
923 return GNUTLS_E_INVALID_REQUEST; 923 return GNUTLS_E_INVALID_REQUEST;
924 } 924 }
925 925
926 /* first run */ 926 /* first run */
927 datasize = i_datasize + HANDSHAKE_HEADER_SIZE; 927 datasize = i_datasize + HANDSHAKE_HEADER_SIZE;
928 data = gnutls_alloca (datasize); 928 data = MHD_gnutls_alloca (datasize);
929 if (data == NULL) 929 if (data == NULL)
930 { 930 {
931 gnutls_assert (); 931 MHD_gnutls_assert ();
932 return GNUTLS_E_MEMORY_ERROR; 932 return GNUTLS_E_MEMORY_ERROR;
933 } 933 }
934 934
935 data[pos++] = (uint8_t) type; 935 data[pos++] = (uint8_t) type;
936 mhd_gtls_write_uint24 (i_datasize, &data[pos]); 936 MHD_gtls_write_uint24 (i_datasize, &data[pos]);
937 pos += 3; 937 pos += 3;
938 938
939 if (i_datasize > 0) 939 if (i_datasize > 0)
@@ -943,23 +943,23 @@ mhd_gtls_send_handshake (mhd_gtls_session_t session, void *i_data,
943 */ 943 */
944 if (type != GNUTLS_HANDSHAKE_HELLO_REQUEST) 944 if (type != GNUTLS_HANDSHAKE_HELLO_REQUEST)
945 if ((ret = 945 if ((ret =
946 _gnutls_handshake_hash_add_sent (session, type, data, datasize)) < 0) 946 MHD__gnutls_handshake_hash_add_sent (session, type, data, datasize)) < 0)
947 { 947 {
948 gnutls_assert (); 948 MHD_gnutls_assert ();
949 gnutls_afree (data); 949 MHD_gnutls_afree (data);
950 return ret; 950 return ret;
951 } 951 }
952 952
953 session->internals.last_handshake_out = type; 953 session->internals.last_handshake_out = type;
954 954
955 ret = 955 ret =
956 mhd_gtls_handshake_io_send_int (session, GNUTLS_HANDSHAKE, type, 956 MHD_gtls_handshake_io_send_int (session, GNUTLS_HANDSHAKE, type,
957 data, datasize); 957 data, datasize);
958 958
959 _gnutls_handshake_log ("HSK[%x]: %s was sent [%ld bytes]\n", 959 MHD__gnutls_handshake_log ("HSK[%x]: %s was sent [%ld bytes]\n",
960 session, _gnutls_handshake2str (type), datasize); 960 session, MHD__gnutls_handshake2str (type), datasize);
961 961
962 gnutls_afree (data); 962 MHD_gnutls_afree (data);
963 963
964 return ret; 964 return ret;
965} 965}
@@ -972,9 +972,9 @@ mhd_gtls_send_handshake (mhd_gtls_session_t session, void *i_data,
972 */ 972 */
973#define SSL2_HEADERS 1 973#define SSL2_HEADERS 1
974static int 974static int
975_gnutls_recv_handshake_header (mhd_gtls_session_t session, 975MHD__gnutls_recv_handshake_header (MHD_gtls_session_t session,
976 gnutls_handshake_description_t type, 976 MHD_gnutls_handshake_description_t type,
977 gnutls_handshake_description_t * recv_type) 977 MHD_gnutls_handshake_description_t * recv_type)
978{ 978{
979 int ret; 979 int ret;
980 uint32_t length32 = 0; 980 uint32_t length32 = 0;
@@ -1006,12 +1006,12 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1006 if (session->internals.handshake_header_buffer.header_size < SSL2_HEADERS) 1006 if (session->internals.handshake_header_buffer.header_size < SSL2_HEADERS)
1007 { 1007 {
1008 ret = 1008 ret =
1009 mhd_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE, 1009 MHD_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE,
1010 type, dataptr, SSL2_HEADERS); 1010 type, dataptr, SSL2_HEADERS);
1011 1011
1012 if (ret < 0) 1012 if (ret < 0)
1013 { 1013 {
1014 gnutls_assert (); 1014 MHD_gnutls_assert ();
1015 return ret; 1015 return ret;
1016 } 1016 }
1017 1017
@@ -1019,7 +1019,7 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1019 */ 1019 */
1020 if (ret != SSL2_HEADERS) 1020 if (ret != SSL2_HEADERS)
1021 { 1021 {
1022 gnutls_assert (); 1022 MHD_gnutls_assert ();
1023 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 1023 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
1024 } 1024 }
1025 session->internals.handshake_header_buffer.header_size = SSL2_HEADERS; 1025 session->internals.handshake_header_buffer.header_size = SSL2_HEADERS;
@@ -1029,7 +1029,7 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1029 || type != GNUTLS_HANDSHAKE_CLIENT_HELLO) 1029 || type != GNUTLS_HANDSHAKE_CLIENT_HELLO)
1030 { 1030 {
1031 ret = 1031 ret =
1032 mhd_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE, 1032 MHD_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE,
1033 type, 1033 type,
1034 &dataptr 1034 &dataptr
1035 [session->internals. 1035 [session->internals.
@@ -1039,14 +1039,14 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1039 handshake_header_buffer.header_size); 1039 handshake_header_buffer.header_size);
1040 if (ret <= 0) 1040 if (ret <= 0)
1041 { 1041 {
1042 gnutls_assert (); 1042 MHD_gnutls_assert ();
1043 return (ret < 0) ? ret : GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 1043 return (ret < 0) ? ret : GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
1044 } 1044 }
1045 if ((size_t) ret != 1045 if ((size_t) ret !=
1046 HANDSHAKE_HEADER_SIZE - 1046 HANDSHAKE_HEADER_SIZE -
1047 session->internals.handshake_header_buffer.header_size) 1047 session->internals.handshake_header_buffer.header_size)
1048 { 1048 {
1049 gnutls_assert (); 1049 MHD_gnutls_assert ();
1050 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 1050 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
1051 } 1051 }
1052 *recv_type = dataptr[0]; 1052 *recv_type = dataptr[0];
@@ -1054,11 +1054,11 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1054 /* we do not use DECR_LEN because we know 1054 /* we do not use DECR_LEN because we know
1055 * that the packet has enough data. 1055 * that the packet has enough data.
1056 */ 1056 */
1057 length32 = mhd_gtls_read_uint24 (&dataptr[1]); 1057 length32 = MHD_gtls_read_uint24 (&dataptr[1]);
1058 handshake_header_size = HANDSHAKE_HEADER_SIZE; 1058 handshake_header_size = HANDSHAKE_HEADER_SIZE;
1059 1059
1060 _gnutls_handshake_log ("HSK[%x]: %s was received [%ld bytes]\n", 1060 MHD__gnutls_handshake_log ("HSK[%x]: %s was received [%ld bytes]\n",
1061 session, _gnutls_handshake2str (dataptr[0]), 1061 session, MHD__gnutls_handshake2str (dataptr[0]),
1062 length32 + HANDSHAKE_HEADER_SIZE); 1062 length32 + HANDSHAKE_HEADER_SIZE);
1063 1063
1064 } 1064 }
@@ -1070,13 +1070,13 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1070 1070
1071 *recv_type = dataptr[0]; 1071 *recv_type = dataptr[0];
1072 1072
1073 _gnutls_handshake_log ("HSK[%x]: %s(v2) was received [%ld bytes]\n", 1073 MHD__gnutls_handshake_log ("HSK[%x]: %s(v2) was received [%ld bytes]\n",
1074 session, _gnutls_handshake2str (*recv_type), 1074 session, MHD__gnutls_handshake2str (*recv_type),
1075 length32 + handshake_header_size); 1075 length32 + handshake_header_size);
1076 1076
1077 if (*recv_type != GNUTLS_HANDSHAKE_CLIENT_HELLO) 1077 if (*recv_type != GNUTLS_HANDSHAKE_CLIENT_HELLO)
1078 { /* it should be one or nothing */ 1078 { /* it should be one or nothing */
1079 gnutls_assert (); 1079 MHD_gnutls_assert ();
1080 return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET; 1080 return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
1081 } 1081 }
1082 } 1082 }
@@ -1089,21 +1089,21 @@ _gnutls_recv_handshake_header (mhd_gtls_session_t session,
1089 1089
1090 if (*recv_type != type) 1090 if (*recv_type != type)
1091 { 1091 {
1092 gnutls_assert (); 1092 MHD_gnutls_assert ();
1093 return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET; 1093 return GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
1094 } 1094 }
1095 1095
1096 return length32; 1096 return length32;
1097} 1097}
1098 1098
1099#define _gnutls_handshake_header_buffer_clear( session) session->internals.handshake_header_buffer.header_size = 0 1099#define MHD__gnutls_handshake_header_buffer_clear( session) session->internals.handshake_header_buffer.header_size = 0
1100 1100
1101/* This function will hash the handshake headers and the 1101/* This function will hash the handshake headers and the
1102 * handshake data. 1102 * handshake data.
1103 */ 1103 */
1104static int 1104static int
1105_gnutls_handshake_hash_add_recvd (mhd_gtls_session_t session, 1105MHD__gnutls_handshake_hash_add_recvd (MHD_gtls_session_t session,
1106 gnutls_handshake_description_t recv_type, 1106 MHD_gnutls_handshake_description_t recv_type,
1107 opaque * header, uint16_t header_size, 1107 opaque * header, uint16_t header_size,
1108 opaque * dataptr, uint32_t datalen) 1108 opaque * dataptr, uint32_t datalen)
1109{ 1109{
@@ -1113,9 +1113,9 @@ _gnutls_handshake_hash_add_recvd (mhd_gtls_session_t session,
1113 * and add the one we just received into the handshake_hash_buffer. 1113 * and add the one we just received into the handshake_hash_buffer.
1114 */ 1114 */
1115 1115
1116 if ((ret = _gnutls_handshake_hash_pending (session)) < 0) 1116 if ((ret = MHD__gnutls_handshake_hash_pending (session)) < 0)
1117 { 1117 {
1118 gnutls_assert (); 1118 MHD_gnutls_assert ();
1119 return ret; 1119 return ret;
1120 } 1120 }
1121 1121
@@ -1124,18 +1124,18 @@ _gnutls_handshake_hash_add_recvd (mhd_gtls_session_t session,
1124 { 1124 {
1125 1125
1126 if ((ret = 1126 if ((ret =
1127 mhd_gtls_handshake_buffer_put (session, header, header_size)) < 0) 1127 MHD_gtls_handshake_buffer_put (session, header, header_size)) < 0)
1128 { 1128 {
1129 gnutls_assert (); 1129 MHD_gnutls_assert ();
1130 return ret; 1130 return ret;
1131 } 1131 }
1132 1132
1133 if (datalen > 0) 1133 if (datalen > 0)
1134 { 1134 {
1135 if ((ret = 1135 if ((ret =
1136 mhd_gtls_handshake_buffer_put (session, dataptr, datalen)) < 0) 1136 MHD_gtls_handshake_buffer_put (session, dataptr, datalen)) < 0)
1137 { 1137 {
1138 gnutls_assert (); 1138 MHD_gnutls_assert ();
1139 return ret; 1139 return ret;
1140 } 1140 }
1141 } 1141 }
@@ -1147,19 +1147,19 @@ _gnutls_handshake_hash_add_recvd (mhd_gtls_session_t session,
1147/* This function will receive handshake messages of the given types, 1147/* This function will receive handshake messages of the given types,
1148 * and will pass the message to the right place in order to be processed. 1148 * and will pass the message to the right place in order to be processed.
1149 * E.g. for the SERVER_HELLO message (if it is expected), it will be 1149 * E.g. for the SERVER_HELLO message (if it is expected), it will be
1150 * passed to mhd_gtls_recv_hello(). 1150 * passed to MHD_gtls_recv_hello().
1151 */ 1151 */
1152int 1152int
1153mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data, 1153MHD_gtls_recv_handshake (MHD_gtls_session_t session, uint8_t ** data,
1154 int *datalen, gnutls_handshake_description_t type, 1154 int *datalen, MHD_gnutls_handshake_description_t type,
1155 Optional optional) 1155 Optional optional)
1156{ 1156{
1157 int ret; 1157 int ret;
1158 uint32_t length32 = 0; 1158 uint32_t length32 = 0;
1159 opaque *dataptr = NULL; 1159 opaque *dataptr = NULL;
1160 gnutls_handshake_description_t recv_type; 1160 MHD_gnutls_handshake_description_t recv_type;
1161 1161
1162 ret = _gnutls_recv_handshake_header (session, type, &recv_type); 1162 ret = MHD__gnutls_recv_handshake_header (session, type, &recv_type);
1163 if (ret < 0) 1163 if (ret < 0)
1164 { 1164 {
1165 1165
@@ -1181,16 +1181,16 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1181 length32 = ret; 1181 length32 = ret;
1182 1182
1183 if (length32 > 0) 1183 if (length32 > 0)
1184 dataptr = gnutls_malloc (length32); 1184 dataptr = MHD_gnutls_malloc (length32);
1185 else if (recv_type != GNUTLS_HANDSHAKE_SERVER_HELLO_DONE) 1185 else if (recv_type != GNUTLS_HANDSHAKE_SERVER_HELLO_DONE)
1186 { 1186 {
1187 gnutls_assert (); 1187 MHD_gnutls_assert ();
1188 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 1188 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
1189 } 1189 }
1190 1190
1191 if (dataptr == NULL && length32 > 0) 1191 if (dataptr == NULL && length32 > 0)
1192 { 1192 {
1193 gnutls_assert (); 1193 MHD_gnutls_assert ();
1194 return GNUTLS_E_MEMORY_ERROR; 1194 return GNUTLS_E_MEMORY_ERROR;
1195 } 1195 }
1196 1196
@@ -1200,12 +1200,12 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1200 if (length32 > 0) 1200 if (length32 > 0)
1201 { 1201 {
1202 ret = 1202 ret =
1203 mhd_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE, 1203 MHD_gtls_handshake_io_recv_int (session, GNUTLS_HANDSHAKE,
1204 type, dataptr, length32); 1204 type, dataptr, length32);
1205 if (ret <= 0) 1205 if (ret <= 0)
1206 { 1206 {
1207 gnutls_assert (); 1207 MHD_gnutls_assert ();
1208 gnutls_free (dataptr); 1208 MHD_gnutls_free (dataptr);
1209 return (ret == 0) ? GNUTLS_E_UNEXPECTED_PACKET_LENGTH : ret; 1209 return (ret == 0) ? GNUTLS_E_UNEXPECTED_PACKET_LENGTH : ret;
1210 } 1210 }
1211 } 1211 }
@@ -1214,7 +1214,7 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1214 *data = dataptr; 1214 *data = dataptr;
1215 1215
1216 1216
1217 ret = _gnutls_handshake_hash_add_recvd (session, recv_type, 1217 ret = MHD__gnutls_handshake_hash_add_recvd (session, recv_type,
1218 session->internals. 1218 session->internals.
1219 handshake_header_buffer.header, 1219 handshake_header_buffer.header,
1220 session->internals. 1220 session->internals.
@@ -1222,8 +1222,8 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1222 dataptr, length32); 1222 dataptr, length32);
1223 if (ret < 0) 1223 if (ret < 0)
1224 { 1224 {
1225 gnutls_assert (); 1225 MHD_gnutls_assert ();
1226 _gnutls_handshake_header_buffer_clear (session); 1226 MHD__gnutls_handshake_header_buffer_clear (session);
1227 return ret; 1227 return ret;
1228 } 1228 }
1229 1229
@@ -1231,16 +1231,16 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1231 * have have received above. if we get here the we clear the handshake 1231 * have have received above. if we get here the we clear the handshake
1232 * header we received. 1232 * header we received.
1233 */ 1233 */
1234 _gnutls_handshake_header_buffer_clear (session); 1234 MHD__gnutls_handshake_header_buffer_clear (session);
1235 1235
1236 switch (recv_type) 1236 switch (recv_type)
1237 { 1237 {
1238 case GNUTLS_HANDSHAKE_CLIENT_HELLO: 1238 case GNUTLS_HANDSHAKE_CLIENT_HELLO:
1239 case GNUTLS_HANDSHAKE_SERVER_HELLO: 1239 case GNUTLS_HANDSHAKE_SERVER_HELLO:
1240 ret = mhd_gtls_recv_hello (session, dataptr, length32); 1240 ret = MHD_gtls_recv_hello (session, dataptr, length32);
1241 /* dataptr is freed because the caller does not 1241 /* dataptr is freed because the caller does not
1242 * need it */ 1242 * need it */
1243 gnutls_free (dataptr); 1243 MHD_gnutls_free (dataptr);
1244 if (data != NULL) 1244 if (data != NULL)
1245 *data = NULL; 1245 *data = NULL;
1246 break; 1246 break;
@@ -1260,8 +1260,8 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1260 ret = length32; 1260 ret = length32;
1261 break; 1261 break;
1262 default: 1262 default:
1263 gnutls_assert (); 1263 MHD_gnutls_assert ();
1264 gnutls_free (dataptr); 1264 MHD_gnutls_free (dataptr);
1265 if (data != NULL) 1265 if (data != NULL)
1266 *data = NULL; 1266 *data = NULL;
1267 ret = GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET; 1267 ret = GNUTLS_E_UNEXPECTED_HANDSHAKE_PACKET;
@@ -1274,7 +1274,7 @@ mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t ** data,
1274 * to the session; 1274 * to the session;
1275 */ 1275 */
1276static int 1276static int
1277_gnutls_client_set_ciphersuite (mhd_gtls_session_t session, opaque suite[2]) 1277MHD__gnutls_client_set_ciphersuite (MHD_gtls_session_t session, opaque suite[2])
1278{ 1278{
1279 uint8_t z; 1279 uint8_t z;
1280 cipher_suite_st *cipher_suites; 1280 cipher_suite_st *cipher_suites;
@@ -1283,10 +1283,10 @@ _gnutls_client_set_ciphersuite (mhd_gtls_session_t session, opaque suite[2])
1283 1283
1284 z = 1; 1284 z = 1;
1285 cipher_suite_num = 1285 cipher_suite_num =
1286 mhd_gtls_supported_ciphersuites (session, &cipher_suites); 1286 MHD_gtls_supported_ciphersuites (session, &cipher_suites);
1287 if (cipher_suite_num < 0) 1287 if (cipher_suite_num < 0)
1288 { 1288 {
1289 gnutls_assert (); 1289 MHD_gnutls_assert ();
1290 return cipher_suite_num; 1290 return cipher_suite_num;
1291 } 1291 }
1292 1292
@@ -1299,18 +1299,18 @@ _gnutls_client_set_ciphersuite (mhd_gtls_session_t session, opaque suite[2])
1299 } 1299 }
1300 } 1300 }
1301 1301
1302 gnutls_free (cipher_suites); 1302 MHD_gnutls_free (cipher_suites);
1303 1303
1304 if (z != 0) 1304 if (z != 0)
1305 { 1305 {
1306 gnutls_assert (); 1306 MHD_gnutls_assert ();
1307 return GNUTLS_E_UNKNOWN_CIPHER_SUITE; 1307 return GNUTLS_E_UNKNOWN_CIPHER_SUITE;
1308 } 1308 }
1309 1309
1310 memcpy (session->security_parameters.current_cipher_suite.suite, suite, 2); 1310 memcpy (session->security_parameters.current_cipher_suite.suite, suite, 2);
1311 1311
1312 _gnutls_handshake_log ("HSK[%x]: Selected cipher suite: %s\n", session, 1312 MHD__gnutls_handshake_log ("HSK[%x]: Selected cipher suite: %s\n", session,
1313 mhd_gtls_cipher_suite_get_name 1313 MHD_gtls_cipher_suite_get_name
1314 (&session->security_parameters. 1314 (&session->security_parameters.
1315 current_cipher_suite)); 1315 current_cipher_suite));
1316 1316
@@ -1318,33 +1318,33 @@ _gnutls_client_set_ciphersuite (mhd_gtls_session_t session, opaque suite[2])
1318 /* check if the credentials (username, public key etc.) are ok. 1318 /* check if the credentials (username, public key etc.) are ok.
1319 * Actually checks if they exist. 1319 * Actually checks if they exist.
1320 */ 1320 */
1321 if (mhd_gtls_get_kx_cred 1321 if (MHD_gtls_get_kx_cred
1322 (session, 1322 (session,
1323 mhd_gtls_cipher_suite_get_kx_algo 1323 MHD_gtls_cipher_suite_get_kx_algo
1324 (&session->security_parameters.current_cipher_suite), &err) == NULL 1324 (&session->security_parameters.current_cipher_suite), &err) == NULL
1325 && err != 0) 1325 && err != 0)
1326 { 1326 {
1327 gnutls_assert (); 1327 MHD_gnutls_assert ();
1328 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 1328 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
1329 } 1329 }
1330 1330
1331 1331
1332 /* set the mhd_gtls_mod_auth_st to the appropriate struct 1332 /* set the MHD_gtls_mod_auth_st to the appropriate struct
1333 * according to the KX algorithm. This is needed since all the 1333 * according to the KX algorithm. This is needed since all the
1334 * handshake functions are read from there; 1334 * handshake functions are read from there;
1335 */ 1335 */
1336 session->internals.auth_struct = 1336 session->internals.auth_struct =
1337 mhd_gtls_kx_auth_struct (mhd_gtls_cipher_suite_get_kx_algo 1337 MHD_gtls_kx_auth_struct (MHD_gtls_cipher_suite_get_kx_algo
1338 (&session->security_parameters. 1338 (&session->security_parameters.
1339 current_cipher_suite)); 1339 current_cipher_suite));
1340 1340
1341 if (session->internals.auth_struct == NULL) 1341 if (session->internals.auth_struct == NULL)
1342 { 1342 {
1343 1343
1344 _gnutls_handshake_log 1344 MHD__gnutls_handshake_log
1345 ("HSK[%x]: Cannot find the appropriate handler for the KX algorithm\n", 1345 ("HSK[%x]: Cannot find the appropriate handler for the KX algorithm\n",
1346 session); 1346 session);
1347 gnutls_assert (); 1347 MHD_gnutls_assert ();
1348 return GNUTLS_E_INTERNAL_ERROR; 1348 return GNUTLS_E_INTERNAL_ERROR;
1349 } 1349 }
1350 1350
@@ -1355,18 +1355,18 @@ _gnutls_client_set_ciphersuite (mhd_gtls_session_t session, opaque suite[2])
1355/* This function sets the given comp method to the session. 1355/* This function sets the given comp method to the session.
1356 */ 1356 */
1357static int 1357static int
1358_gnutls_client_set_comp_method (mhd_gtls_session_t session, 1358MHD__gnutls_client_set_comp_method (MHD_gtls_session_t session,
1359 opaque comp_method) 1359 opaque comp_method)
1360{ 1360{
1361 int comp_methods_num; 1361 int comp_methods_num;
1362 uint8_t *compression_methods; 1362 uint8_t *compression_methods;
1363 int i; 1363 int i;
1364 1364
1365 comp_methods_num = mhd_gtls_supported_compression_methods (session, 1365 comp_methods_num = MHD_gtls_supported_compression_methods (session,
1366 &compression_methods); 1366 &compression_methods);
1367 if (comp_methods_num < 0) 1367 if (comp_methods_num < 0)
1368 { 1368 {
1369 gnutls_assert (); 1369 MHD_gnutls_assert ();
1370 return comp_methods_num; 1370 return comp_methods_num;
1371 } 1371 }
1372 1372
@@ -1379,16 +1379,16 @@ _gnutls_client_set_comp_method (mhd_gtls_session_t session,
1379 } 1379 }
1380 } 1380 }
1381 1381
1382 gnutls_free (compression_methods); 1382 MHD_gnutls_free (compression_methods);
1383 1383
1384 if (comp_methods_num != 0) 1384 if (comp_methods_num != 0)
1385 { 1385 {
1386 gnutls_assert (); 1386 MHD_gnutls_assert ();
1387 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 1387 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
1388 } 1388 }
1389 1389
1390 session->internals.compression_method = 1390 session->internals.compression_method =
1391 mhd_gtls_compression_get_id (comp_method); 1391 MHD_gtls_compression_get_id_from_int (comp_method);
1392 1392
1393 1393
1394 return 0; 1394 return 0;
@@ -1399,15 +1399,15 @@ _gnutls_client_set_comp_method (mhd_gtls_session_t session,
1399 * hello. 1399 * hello.
1400 */ 1400 */
1401static int 1401static int
1402_gnutls_client_check_if_resuming (mhd_gtls_session_t session, 1402MHD__gnutls_client_check_if_resuming (MHD_gtls_session_t session,
1403 opaque * session_id, int session_id_len) 1403 opaque * session_id, int session_id_len)
1404{ 1404{
1405 opaque buf[2 * TLS_MAX_SESSION_ID_SIZE + 1]; 1405 opaque buf[2 * TLS_MAX_SESSION_ID_SIZE + 1];
1406 1406
1407 _gnutls_handshake_log ("HSK[%x]: SessionID length: %d\n", session, 1407 MHD__gnutls_handshake_log ("HSK[%x]: SessionID length: %d\n", session,
1408 session_id_len); 1408 session_id_len);
1409 _gnutls_handshake_log ("HSK[%x]: SessionID: %s\n", session, 1409 MHD__gnutls_handshake_log ("HSK[%x]: SessionID: %s\n", session,
1410 mhd_gtls_bin2hex (session_id, session_id_len, buf, 1410 MHD_gtls_bin2hex (session_id, session_id_len, buf,
1411 sizeof (buf))); 1411 sizeof (buf)));
1412 1412
1413 if (session_id_len > 0 && 1413 if (session_id_len > 0 &&
@@ -1444,7 +1444,7 @@ _gnutls_client_check_if_resuming (mhd_gtls_session_t session,
1444 * session. 1444 * session.
1445 */ 1445 */
1446static int 1446static int
1447_gnutls_read_server_hello (mhd_gtls_session_t session, 1447MHD__gnutls_read_server_hello (MHD_gtls_session_t session,
1448 opaque * data, int datalen) 1448 opaque * data, int datalen)
1449{ 1449{
1450 uint8_t session_id_len = 0; 1450 uint8_t session_id_len = 0;
@@ -1455,29 +1455,29 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1455 1455
1456 if (datalen < 38) 1456 if (datalen < 38)
1457 { 1457 {
1458 gnutls_assert (); 1458 MHD_gnutls_assert ();
1459 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 1459 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
1460 } 1460 }
1461 1461
1462 _gnutls_handshake_log ("HSK[%x]: Server's version: %d.%d\n", 1462 MHD__gnutls_handshake_log ("HSK[%x]: Server's version: %d.%d\n",
1463 session, data[pos], data[pos + 1]); 1463 session, data[pos], data[pos + 1]);
1464 1464
1465 DECR_LEN (len, 2); 1465 DECR_LEN (len, 2);
1466 version = mhd_gtls_version_get (data[pos], data[pos + 1]); 1466 version = MHD_gtls_version_get (data[pos], data[pos + 1]);
1467 if (mhd_gtls_version_is_supported (session, version) == 0) 1467 if (MHD_gtls_version_is_supported (session, version) == 0)
1468 { 1468 {
1469 gnutls_assert (); 1469 MHD_gnutls_assert ();
1470 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET; 1470 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
1471 } 1471 }
1472 else 1472 else
1473 { 1473 {
1474 mhd_gtls_set_current_version (session, version); 1474 MHD_gtls_set_current_version (session, version);
1475 } 1475 }
1476 1476
1477 pos += 2; 1477 pos += 2;
1478 1478
1479 DECR_LEN (len, TLS_RANDOM_SIZE); 1479 DECR_LEN (len, TLS_RANDOM_SIZE);
1480 mhd_gtls_set_server_random (session, &data[pos]); 1480 MHD_gtls_set_server_random (session, &data[pos]);
1481 pos += TLS_RANDOM_SIZE; 1481 pos += TLS_RANDOM_SIZE;
1482 1482
1483 1483
@@ -1488,7 +1488,7 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1488 1488
1489 if (len < session_id_len) 1489 if (len < session_id_len)
1490 { 1490 {
1491 gnutls_assert (); 1491 MHD_gnutls_assert ();
1492 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET; 1492 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
1493 } 1493 }
1494 DECR_LEN (len, session_id_len); 1494 DECR_LEN (len, session_id_len);
@@ -1497,7 +1497,7 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1497 /* check if we are resuming and set the appropriate 1497 /* check if we are resuming and set the appropriate
1498 * values; 1498 * values;
1499 */ 1499 */
1500 if (_gnutls_client_check_if_resuming 1500 if (MHD__gnutls_client_check_if_resuming
1501 (session, &data[pos], session_id_len) == 0) 1501 (session, &data[pos], session_id_len) == 0)
1502 return 0; 1502 return 0;
1503 pos += session_id_len; 1503 pos += session_id_len;
@@ -1508,10 +1508,10 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1508 */ 1508 */
1509 1509
1510 DECR_LEN (len, 2); 1510 DECR_LEN (len, 2);
1511 ret = _gnutls_client_set_ciphersuite (session, &data[pos]); 1511 ret = MHD__gnutls_client_set_ciphersuite (session, &data[pos]);
1512 if (ret < 0) 1512 if (ret < 0)
1513 { 1513 {
1514 gnutls_assert (); 1514 MHD_gnutls_assert ();
1515 return ret; 1515 return ret;
1516 } 1516 }
1517 pos += 2; 1517 pos += 2;
@@ -1521,10 +1521,10 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1521 /* move to compression */ 1521 /* move to compression */
1522 DECR_LEN (len, 1); 1522 DECR_LEN (len, 1);
1523 1523
1524 ret = _gnutls_client_set_comp_method (session, data[pos++]); 1524 ret = MHD__gnutls_client_set_comp_method (session, data[pos++]);
1525 if (ret < 0) 1525 if (ret < 0)
1526 { 1526 {
1527 gnutls_assert (); 1527 MHD_gnutls_assert ();
1528 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM; 1528 return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
1529 } 1529 }
1530 1530
@@ -1532,10 +1532,10 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1532 */ 1532 */
1533 if (version >= MHD_GNUTLS_PROTOCOL_TLS1_0) 1533 if (version >= MHD_GNUTLS_PROTOCOL_TLS1_0)
1534 { 1534 {
1535 ret = mhd_gtls_parse_extensions (session, EXTENSION_ANY, &data[pos], len); /* len is the rest of the parsed length */ 1535 ret = MHD_gtls_parse_extensions (session, EXTENSION_ANY, &data[pos], len); /* len is the rest of the parsed length */
1536 if (ret < 0) 1536 if (ret < 0)
1537 { 1537 {
1538 gnutls_assert (); 1538 MHD_gnutls_assert ();
1539 return ret; 1539 return ret;
1540 } 1540 }
1541 } 1541 }
@@ -1547,7 +1547,7 @@ _gnutls_read_server_hello (mhd_gtls_session_t session,
1547 * Needed in client hello messages. Returns the new data length. 1547 * Needed in client hello messages. Returns the new data length.
1548 */ 1548 */
1549static int 1549static int
1550_gnutls_copy_ciphersuites (mhd_gtls_session_t session, 1550MHD__gnutls_copy_ciphersuites (MHD_gtls_session_t session,
1551 opaque * ret_data, size_t ret_data_size) 1551 opaque * ret_data, size_t ret_data_size)
1552{ 1552{
1553 int ret, i; 1553 int ret, i;
@@ -1555,10 +1555,10 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1555 uint16_t cipher_num; 1555 uint16_t cipher_num;
1556 int datalen, pos; 1556 int datalen, pos;
1557 1557
1558 ret = mhd_gtls_supported_ciphersuites_sorted (session, &cipher_suites); 1558 ret = MHD_gtls_supported_ciphersuites_sorted (session, &cipher_suites);
1559 if (ret < 0) 1559 if (ret < 0)
1560 { 1560 {
1561 gnutls_assert (); 1561 MHD_gnutls_assert ();
1562 return ret; 1562 return ret;
1563 } 1563 }
1564 1564
@@ -1567,11 +1567,11 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1567 * authentication requested (eg SRP). 1567 * authentication requested (eg SRP).
1568 */ 1568 */
1569 ret = 1569 ret =
1570 mhd_gtls_remove_unwanted_ciphersuites (session, &cipher_suites, ret, -1); 1570 MHD_gtls_remove_unwanted_ciphersuites (session, &cipher_suites, ret, -1);
1571 if (ret < 0) 1571 if (ret < 0)
1572 { 1572 {
1573 gnutls_assert (); 1573 MHD_gnutls_assert ();
1574 gnutls_free (cipher_suites); 1574 MHD_gnutls_free (cipher_suites);
1575 return ret; 1575 return ret;
1576 } 1576 }
1577 1577
@@ -1579,8 +1579,8 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1579 */ 1579 */
1580 if (ret == 0) 1580 if (ret == 0)
1581 { 1581 {
1582 gnutls_assert (); 1582 MHD_gnutls_assert ();
1583 gnutls_free (cipher_suites); 1583 MHD_gnutls_free (cipher_suites);
1584 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 1584 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
1585 } 1585 }
1586 1586
@@ -1594,11 +1594,11 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1594 1594
1595 if ((size_t) datalen > ret_data_size) 1595 if ((size_t) datalen > ret_data_size)
1596 { 1596 {
1597 gnutls_assert (); 1597 MHD_gnutls_assert ();
1598 return GNUTLS_E_INTERNAL_ERROR; 1598 return GNUTLS_E_INTERNAL_ERROR;
1599 } 1599 }
1600 1600
1601 mhd_gtls_write_uint16 (cipher_num, ret_data); 1601 MHD_gtls_write_uint16 (cipher_num, ret_data);
1602 pos += 2; 1602 pos += 2;
1603 1603
1604 for (i = 0; i < (cipher_num / 2); i++) 1604 for (i = 0; i < (cipher_num / 2); i++)
@@ -1606,7 +1606,7 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1606 memcpy (&ret_data[pos], cipher_suites[i].suite, 2); 1606 memcpy (&ret_data[pos], cipher_suites[i].suite, 2);
1607 pos += 2; 1607 pos += 2;
1608 } 1608 }
1609 gnutls_free (cipher_suites); 1609 MHD_gnutls_free (cipher_suites);
1610 1610
1611 return datalen; 1611 return datalen;
1612} 1612}
@@ -1615,7 +1615,7 @@ _gnutls_copy_ciphersuites (mhd_gtls_session_t session,
1615 * Needed in hello messages. Returns the new data length. 1615 * Needed in hello messages. Returns the new data length.
1616 */ 1616 */
1617static int 1617static int
1618_gnutls_copy_comp_methods (mhd_gtls_session_t session, 1618MHD__gnutls_copy_comp_methods (MHD_gtls_session_t session,
1619 opaque * ret_data, size_t ret_data_size) 1619 opaque * ret_data, size_t ret_data_size)
1620{ 1620{
1621 int ret, i; 1621 int ret, i;
@@ -1623,10 +1623,10 @@ _gnutls_copy_comp_methods (mhd_gtls_session_t session,
1623 int datalen, pos; 1623 int datalen, pos;
1624 1624
1625 ret = 1625 ret =
1626 mhd_gtls_supported_compression_methods (session, &compression_methods); 1626 MHD_gtls_supported_compression_methods (session, &compression_methods);
1627 if (ret < 0) 1627 if (ret < 0)
1628 { 1628 {
1629 gnutls_assert (); 1629 MHD_gnutls_assert ();
1630 return ret; 1630 return ret;
1631 } 1631 }
1632 1632
@@ -1637,7 +1637,7 @@ _gnutls_copy_comp_methods (mhd_gtls_session_t session,
1637 1637
1638 if ((size_t) datalen > ret_data_size) 1638 if ((size_t) datalen > ret_data_size)
1639 { 1639 {
1640 gnutls_assert (); 1640 MHD_gnutls_assert ();
1641 return GNUTLS_E_INTERNAL_ERROR; 1641 return GNUTLS_E_INTERNAL_ERROR;
1642 } 1642 }
1643 1643
@@ -1648,7 +1648,7 @@ _gnutls_copy_comp_methods (mhd_gtls_session_t session,
1648 ret_data[pos++] = compression_methods[i]; 1648 ret_data[pos++] = compression_methods[i];
1649 } 1649 }
1650 1650
1651 gnutls_free (compression_methods); 1651 MHD_gnutls_free (compression_methods);
1652 1652
1653 return datalen; 1653 return datalen;
1654} 1654}
@@ -1662,7 +1662,7 @@ _gnutls_copy_comp_methods (mhd_gtls_session_t session,
1662/* This function sends the client hello handshake message. 1662/* This function sends the client hello handshake message.
1663 */ 1663 */
1664static int 1664static int
1665_gnutls_send_client_hello (mhd_gtls_session_t session, int again) 1665MHD__gnutls_send_client_hello (MHD_gtls_session_t session, int again)
1666{ 1666{
1667 opaque *data = NULL; 1667 opaque *data = NULL;
1668 int extdatalen; 1668 int extdatalen;
@@ -1689,10 +1689,10 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1689 /* 2 for version, (4 for unix time + 28 for random bytes==TLS_RANDOM_SIZE) 1689 /* 2 for version, (4 for unix time + 28 for random bytes==TLS_RANDOM_SIZE)
1690 */ 1690 */
1691 1691
1692 data = gnutls_malloc (datalen); 1692 data = MHD_gnutls_malloc (datalen);
1693 if (data == NULL) 1693 if (data == NULL)
1694 { 1694 {
1695 gnutls_assert (); 1695 MHD_gnutls_assert ();
1696 return GNUTLS_E_MEMORY_ERROR; 1696 return GNUTLS_E_MEMORY_ERROR;
1697 } 1697 }
1698 1698
@@ -1700,7 +1700,7 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1700 * version number to the previously established. 1700 * version number to the previously established.
1701 */ 1701 */
1702 if (SessionID == NULL) 1702 if (SessionID == NULL)
1703 hver = mhd_gtls_version_max (session); 1703 hver = MHD_gtls_version_max (session);
1704 else 1704 else
1705 { /* we are resuming a session */ 1705 { /* we are resuming a session */
1706 hver = session->internals.resumed_security_parameters.version; 1706 hver = session->internals.resumed_security_parameters.version;
@@ -1708,18 +1708,18 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1708 1708
1709 if (hver == MHD_GNUTLS_PROTOCOL_VERSION_UNKNOWN || hver == 0) 1709 if (hver == MHD_GNUTLS_PROTOCOL_VERSION_UNKNOWN || hver == 0)
1710 { 1710 {
1711 gnutls_assert (); 1711 MHD_gnutls_assert ();
1712 gnutls_free (data); 1712 MHD_gnutls_free (data);
1713 return GNUTLS_E_INTERNAL_ERROR; 1713 return GNUTLS_E_INTERNAL_ERROR;
1714 } 1714 }
1715 1715
1716 data[pos++] = mhd_gtls_version_get_major (hver); 1716 data[pos++] = MHD_gtls_version_get_major (hver);
1717 data[pos++] = mhd_gtls_version_get_minor (hver); 1717 data[pos++] = MHD_gtls_version_get_minor (hver);
1718 1718
1719 /* Set the version we advertized as maximum 1719 /* Set the version we advertized as maximum
1720 * (RSA uses it). 1720 * (RSA uses it).
1721 */ 1721 */
1722 mhd_gtls_set_adv_version (session, hver); 1722 MHD_gtls_set_adv_version (session, hver);
1723 1723
1724 /* Some old implementations do not interoperate if we send a 1724 /* Some old implementations do not interoperate if we send a
1725 * different version in the record layer. 1725 * different version in the record layer.
@@ -1729,7 +1729,7 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1729 * handshake packet and ignore the one in the packet's record 1729 * handshake packet and ignore the one in the packet's record
1730 * header. 1730 * header.
1731 */ 1731 */
1732 mhd_gtls_set_current_version (session, hver); 1732 MHD_gtls_set_current_version (session, hver);
1733 1733
1734 /* In order to know when this session was initiated. 1734 /* In order to know when this session was initiated.
1735 */ 1735 */
@@ -1737,8 +1737,8 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1737 1737
1738 /* Generate random data 1738 /* Generate random data
1739 */ 1739 */
1740 mhd_gtls_tls_create_random (rnd); 1740 MHD_gtls_tls_create_random (rnd);
1741 mhd_gtls_set_client_random (session, rnd); 1741 MHD_gtls_set_client_random (session, rnd);
1742 1742
1743 memcpy (&data[pos], rnd, TLS_RANDOM_SIZE); 1743 memcpy (&data[pos], rnd, TLS_RANDOM_SIZE);
1744 pos += TLS_RANDOM_SIZE; 1744 pos += TLS_RANDOM_SIZE;
@@ -1756,14 +1756,14 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1756 /* Copy the ciphersuites. 1756 /* Copy the ciphersuites.
1757 */ 1757 */
1758 extdatalen = 1758 extdatalen =
1759 _gnutls_copy_ciphersuites (session, extdata, sizeof (extdata)); 1759 MHD__gnutls_copy_ciphersuites (session, extdata, sizeof (extdata));
1760 if (extdatalen > 0) 1760 if (extdatalen > 0)
1761 { 1761 {
1762 datalen += extdatalen; 1762 datalen += extdatalen;
1763 data = mhd_gtls_realloc_fast (data, datalen); 1763 data = MHD_gtls_realloc_fast (data, datalen);
1764 if (data == NULL) 1764 if (data == NULL)
1765 { 1765 {
1766 gnutls_assert (); 1766 MHD_gnutls_assert ();
1767 return GNUTLS_E_MEMORY_ERROR; 1767 return GNUTLS_E_MEMORY_ERROR;
1768 } 1768 }
1769 1769
@@ -1775,8 +1775,8 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1775 { 1775 {
1776 if (extdatalen == 0) 1776 if (extdatalen == 0)
1777 extdatalen = GNUTLS_E_INTERNAL_ERROR; 1777 extdatalen = GNUTLS_E_INTERNAL_ERROR;
1778 gnutls_free (data); 1778 MHD_gnutls_free (data);
1779 gnutls_assert (); 1779 MHD_gnutls_assert ();
1780 return extdatalen; 1780 return extdatalen;
1781 } 1781 }
1782 1782
@@ -1784,14 +1784,14 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1784 /* Copy the compression methods. 1784 /* Copy the compression methods.
1785 */ 1785 */
1786 extdatalen = 1786 extdatalen =
1787 _gnutls_copy_comp_methods (session, extdata, sizeof (extdata)); 1787 MHD__gnutls_copy_comp_methods (session, extdata, sizeof (extdata));
1788 if (extdatalen > 0) 1788 if (extdatalen > 0)
1789 { 1789 {
1790 datalen += extdatalen; 1790 datalen += extdatalen;
1791 data = mhd_gtls_realloc_fast (data, datalen); 1791 data = MHD_gtls_realloc_fast (data, datalen);
1792 if (data == NULL) 1792 if (data == NULL)
1793 { 1793 {
1794 gnutls_assert (); 1794 MHD_gnutls_assert ();
1795 return GNUTLS_E_MEMORY_ERROR; 1795 return GNUTLS_E_MEMORY_ERROR;
1796 } 1796 }
1797 1797
@@ -1803,8 +1803,8 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1803 { 1803 {
1804 if (extdatalen == 0) 1804 if (extdatalen == 0)
1805 extdatalen = GNUTLS_E_INTERNAL_ERROR; 1805 extdatalen = GNUTLS_E_INTERNAL_ERROR;
1806 gnutls_free (data); 1806 MHD_gnutls_free (data);
1807 gnutls_assert (); 1807 MHD_gnutls_assert ();
1808 return extdatalen; 1808 return extdatalen;
1809 } 1809 }
1810 1810
@@ -1813,15 +1813,15 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1813 if (hver >= MHD_GNUTLS_PROTOCOL_TLS1_0) 1813 if (hver >= MHD_GNUTLS_PROTOCOL_TLS1_0)
1814 { 1814 {
1815 extdatalen = 1815 extdatalen =
1816 mhd_gtls_gen_extensions (session, extdata, sizeof (extdata)); 1816 MHD_gtls_gen_extensions (session, extdata, sizeof (extdata));
1817 1817
1818 if (extdatalen > 0) 1818 if (extdatalen > 0)
1819 { 1819 {
1820 datalen += extdatalen; 1820 datalen += extdatalen;
1821 data = mhd_gtls_realloc_fast (data, datalen); 1821 data = MHD_gtls_realloc_fast (data, datalen);
1822 if (data == NULL) 1822 if (data == NULL)
1823 { 1823 {
1824 gnutls_assert (); 1824 MHD_gnutls_assert ();
1825 return GNUTLS_E_MEMORY_ERROR; 1825 return GNUTLS_E_MEMORY_ERROR;
1826 } 1826 }
1827 1827
@@ -1829,24 +1829,24 @@ _gnutls_send_client_hello (mhd_gtls_session_t session, int again)
1829 } 1829 }
1830 else if (extdatalen < 0) 1830 else if (extdatalen < 0)
1831 { 1831 {
1832 gnutls_assert (); 1832 MHD_gnutls_assert ();
1833 gnutls_free (data); 1833 MHD_gnutls_free (data);
1834 return extdatalen; 1834 return extdatalen;
1835 } 1835 }
1836 } 1836 }
1837 } 1837 }
1838 1838
1839 ret = 1839 ret =
1840 mhd_gtls_send_handshake (session, data, datalen, 1840 MHD_gtls_send_handshake (session, data, datalen,
1841 GNUTLS_HANDSHAKE_CLIENT_HELLO); 1841 GNUTLS_HANDSHAKE_CLIENT_HELLO);
1842 gnutls_free (data); 1842 MHD_gnutls_free (data);
1843 1843
1844 return ret; 1844 return ret;
1845} 1845}
1846#endif 1846#endif
1847 1847
1848static int 1848static int
1849_gnutls_send_server_hello (mhd_gtls_session_t session, int again) 1849MHD__gnutls_send_server_hello (MHD_gtls_session_t session, int again)
1850{ 1850{
1851 opaque *data = NULL; 1851 opaque *data = NULL;
1852 opaque extdata[MAX_EXT_DATA_LENGTH]; 1852 opaque extdata[MAX_EXT_DATA_LENGTH];
@@ -1865,7 +1865,7 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1865 1865
1866#ifdef ENABLE_SRP 1866#ifdef ENABLE_SRP
1867 if (IS_SRP_KX 1867 if (IS_SRP_KX
1868 (mhd_gtls_cipher_suite_get_kx_algo 1868 (MHD_gtls_cipher_suite_get_kx_algo
1869 (&session->security_parameters.current_cipher_suite))) 1869 (&session->security_parameters.current_cipher_suite)))
1870 { 1870 {
1871 /* While resuming we cannot check the username extension since it is 1871 /* While resuming we cannot check the username extension since it is
@@ -1879,12 +1879,12 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1879 * SRP username. The draft requires that we send a fatal 1879 * SRP username. The draft requires that we send a fatal
1880 * alert and abort. 1880 * alert and abort.
1881 */ 1881 */
1882 gnutls_assert (); 1882 MHD_gnutls_assert ();
1883 ret = MHD_gnutls_alert_send (session, GNUTLS_AL_FATAL, 1883 ret = MHD__gnutls_alert_send (session, GNUTLS_AL_FATAL,
1884 GNUTLS_A_UNKNOWN_PSK_IDENTITY); 1884 GNUTLS_A_UNKNOWN_PSK_IDENTITY);
1885 if (ret < 0) 1885 if (ret < 0)
1886 { 1886 {
1887 gnutls_assert (); 1887 MHD_gnutls_assert ();
1888 return ret; 1888 return ret;
1889 } 1889 }
1890 1890
@@ -1897,25 +1897,25 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1897 { 1897 {
1898 datalen = 2 + session_id_len + 1 + TLS_RANDOM_SIZE + 3; 1898 datalen = 2 + session_id_len + 1 + TLS_RANDOM_SIZE + 3;
1899 extdatalen = 1899 extdatalen =
1900 mhd_gtls_gen_extensions (session, extdata, sizeof (extdata)); 1900 MHD_gtls_gen_extensions (session, extdata, sizeof (extdata));
1901 1901
1902 if (extdatalen < 0) 1902 if (extdatalen < 0)
1903 { 1903 {
1904 gnutls_assert (); 1904 MHD_gnutls_assert ();
1905 return extdatalen; 1905 return extdatalen;
1906 } 1906 }
1907 1907
1908 data = gnutls_alloca (datalen + extdatalen); 1908 data = MHD_gnutls_alloca (datalen + extdatalen);
1909 if (data == NULL) 1909 if (data == NULL)
1910 { 1910 {
1911 gnutls_assert (); 1911 MHD_gnutls_assert ();
1912 return GNUTLS_E_MEMORY_ERROR; 1912 return GNUTLS_E_MEMORY_ERROR;
1913 } 1913 }
1914 1914
1915 data[pos++] = 1915 data[pos++] =
1916 mhd_gtls_version_get_major (session->security_parameters.version); 1916 MHD_gtls_version_get_major (session->security_parameters.version);
1917 data[pos++] = 1917 data[pos++] =
1918 mhd_gtls_version_get_minor (session->security_parameters.version); 1918 MHD_gtls_version_get_minor (session->security_parameters.version);
1919 1919
1920 memcpy (&data[pos], 1920 memcpy (&data[pos],
1921 session->security_parameters.server_random, TLS_RANDOM_SIZE); 1921 session->security_parameters.server_random, TLS_RANDOM_SIZE);
@@ -1928,8 +1928,8 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1928 } 1928 }
1929 pos += session_id_len; 1929 pos += session_id_len;
1930 1930
1931 _gnutls_handshake_log ("HSK[%x]: SessionID: %s\n", session, 1931 MHD__gnutls_handshake_log ("HSK[%x]: SessionID: %s\n", session,
1932 mhd_gtls_bin2hex (SessionID, session_id_len, 1932 MHD_gtls_bin2hex (SessionID, session_id_len,
1933 buf, sizeof (buf))); 1933 buf, sizeof (buf)));
1934 1934
1935 memcpy (&data[pos], 1935 memcpy (&data[pos],
@@ -1937,7 +1937,7 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1937 pos += 2; 1937 pos += 2;
1938 1938
1939 comp = 1939 comp =
1940 (uint8_t) mhd_gtls_compression_get_num (session-> 1940 (uint8_t) MHD_gtls_compression_get_num (session->
1941 internals.compression_method); 1941 internals.compression_method);
1942 data[pos++] = comp; 1942 data[pos++] = comp;
1943 1943
@@ -1951,47 +1951,47 @@ _gnutls_send_server_hello (mhd_gtls_session_t session, int again)
1951 } 1951 }
1952 1952
1953 ret = 1953 ret =
1954 mhd_gtls_send_handshake (session, data, datalen, 1954 MHD_gtls_send_handshake (session, data, datalen,
1955 GNUTLS_HANDSHAKE_SERVER_HELLO); 1955 GNUTLS_HANDSHAKE_SERVER_HELLO);
1956 gnutls_afree (data); 1956 MHD_gnutls_afree (data);
1957 1957
1958 return ret; 1958 return ret;
1959} 1959}
1960 1960
1961int 1961int
1962mhd_gtls_send_hello (mhd_gtls_session_t session, int again) 1962MHD_gtls_send_hello (MHD_gtls_session_t session, int again)
1963{ 1963{
1964 int ret; 1964 int ret;
1965#if MHD_DEBUG_TLS 1965#if MHD_DEBUG_TLS
1966 if (session->security_parameters.entity == GNUTLS_CLIENT) 1966 if (session->security_parameters.entity == GNUTLS_CLIENT)
1967 { 1967 {
1968 ret = _gnutls_send_client_hello (session, again); 1968 ret = MHD__gnutls_send_client_hello (session, again);
1969 1969
1970 } 1970 }
1971 else 1971 else
1972#endif 1972#endif
1973 { /* SERVER */ 1973 { /* SERVER */
1974 ret = _gnutls_send_server_hello (session, again); 1974 ret = MHD__gnutls_send_server_hello (session, again);
1975 } 1975 }
1976 1976
1977 return ret; 1977 return ret;
1978} 1978}
1979 1979
1980/* RECEIVE A HELLO MESSAGE. This should be called from gnutls_recv_handshake_int only if a 1980/* RECEIVE A HELLO MESSAGE. This should be called from MHD_gnutls_recv_handshake_int only if a
1981 * hello message is expected. It uses the security_parameters.current_cipher_suite 1981 * hello message is expected. It uses the security_parameters.current_cipher_suite
1982 * and internals.compression_method. 1982 * and internals.compression_method.
1983 */ 1983 */
1984int 1984int
1985mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen) 1985MHD_gtls_recv_hello (MHD_gtls_session_t session, opaque * data, int datalen)
1986{ 1986{
1987 int ret; 1987 int ret;
1988#if MHD_DEBUG_TLS 1988#if MHD_DEBUG_TLS
1989 if (session->security_parameters.entity == GNUTLS_CLIENT) 1989 if (session->security_parameters.entity == GNUTLS_CLIENT)
1990 { 1990 {
1991 ret = _gnutls_read_server_hello (session, data, datalen); 1991 ret = MHD__gnutls_read_server_hello (session, data, datalen);
1992 if (ret < 0) 1992 if (ret < 0)
1993 { 1993 {
1994 gnutls_assert (); 1994 MHD_gnutls_assert ();
1995 return ret; 1995 return ret;
1996 } 1996 }
1997 } 1997 }
@@ -1999,10 +1999,10 @@ mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen)
1999#endif 1999#endif
2000 { /* Server side reading a client hello */ 2000 { /* Server side reading a client hello */
2001 2001
2002 ret = _gnutls_read_client_hello (session, data, datalen); 2002 ret = MHD__gnutls_read_client_hello (session, data, datalen);
2003 if (ret < 0) 2003 if (ret < 0)
2004 { 2004 {
2005 gnutls_assert (); 2005 MHD_gnutls_assert ();
2006 return ret; 2006 return ret;
2007 } 2007 }
2008 } 2008 }
@@ -2010,7 +2010,7 @@ mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen)
2010 return ret; 2010 return ret;
2011} 2011}
2012 2012
2013/* The packets in MHD_gnutls_handshake (it's more broad than original TLS handshake) 2013/* The packets in MHD__gnutls_handshake (it's more broad than original TLS handshake)
2014 * 2014 *
2015 * Client Server 2015 * Client Server
2016 * 2016 *
@@ -2034,8 +2034,8 @@ mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen)
2034 */ 2034 */
2035 2035
2036/** 2036/**
2037 * MHD_gnutls_rehandshake - This function will renegotiate security parameters 2037 * MHD__gnutls_rehandshake - This function will renegotiate security parameters
2038 * @session: is a #mhd_gtls_session_t structure. 2038 * @session: is a #MHD_gtls_session_t structure.
2039 * 2039 *
2040 * This function will renegotiate security parameters with the 2040 * This function will renegotiate security parameters with the
2041 * client. This should only be called in case of a server. 2041 * client. This should only be called in case of a server.
@@ -2044,7 +2044,7 @@ mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen)
2044 * parameters (perform a handshake). 2044 * parameters (perform a handshake).
2045 * 2045 *
2046 * If this function succeeds (returns 0), you must call the 2046 * If this function succeeds (returns 0), you must call the
2047 * MHD_gnutls_handshake() function in order to negotiate the new 2047 * MHD__gnutls_handshake() function in order to negotiate the new
2048 * parameters. 2048 * parameters.
2049 * 2049 *
2050 * If the client does not wish to renegotiate parameters he will 2050 * If the client does not wish to renegotiate parameters he will
@@ -2057,18 +2057,18 @@ mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, int datalen)
2057 * 2057 *
2058 **/ 2058 **/
2059int 2059int
2060MHD_gnutls_rehandshake (mhd_gtls_session_t session) 2060MHD__gnutls_rehandshake (MHD_gtls_session_t session)
2061{ 2061{
2062 int ret; 2062 int ret;
2063 2063
2064 ret = 2064 ret =
2065 _gnutls_send_empty_handshake (session, GNUTLS_HANDSHAKE_HELLO_REQUEST, 2065 MHD__gnutls_send_empty_handshake (session, GNUTLS_HANDSHAKE_HELLO_REQUEST,
2066 AGAIN (STATE50)); 2066 AGAIN (STATE50));
2067 STATE = STATE50; 2067 STATE = STATE50;
2068 2068
2069 if (ret < 0) 2069 if (ret < 0)
2070 { 2070 {
2071 gnutls_assert (); 2071 MHD_gnutls_assert ();
2072 return ret; 2072 return ret;
2073 } 2073 }
2074 STATE = STATE0; 2074 STATE = STATE0;
@@ -2077,10 +2077,10 @@ MHD_gnutls_rehandshake (mhd_gtls_session_t session)
2077} 2077}
2078 2078
2079inline static int 2079inline static int
2080_gnutls_abort_handshake (mhd_gtls_session_t session, int ret) 2080MHD__gnutls_abort_handshake (MHD_gtls_session_t session, int ret)
2081{ 2081{
2082 if (((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) && 2082 if (((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) &&
2083 (gnutls_alert_get (session) == GNUTLS_A_NO_RENEGOTIATION)) 2083 (MHD_gnutls_alert_get (session) == GNUTLS_A_NO_RENEGOTIATION))
2084 || ret == GNUTLS_E_GOT_APPLICATION_DATA) 2084 || ret == GNUTLS_E_GOT_APPLICATION_DATA)
2085 return 0; 2085 return 0;
2086 2086
@@ -2092,17 +2092,17 @@ _gnutls_abort_handshake (mhd_gtls_session_t session, int ret)
2092 * required for finished messages. 2092 * required for finished messages.
2093 */ 2093 */
2094inline static int 2094inline static int
2095_gnutls_handshake_hash_init (mhd_gtls_session_t session) 2095MHD__gnutls_handshake_hash_init (MHD_gtls_session_t session)
2096{ 2096{
2097 2097
2098 if (session->internals.handshake_mac_handle_md5 == NULL) 2098 if (session->internals.handshake_mac_handle_md5 == NULL)
2099 { 2099 {
2100 session->internals.handshake_mac_handle_md5 = 2100 session->internals.handshake_mac_handle_md5 =
2101 mhd_gtls_hash_init (MHD_GNUTLS_MAC_MD5); 2101 MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
2102 2102
2103 if (session->internals.handshake_mac_handle_md5 == GNUTLS_HASH_FAILED) 2103 if (session->internals.handshake_mac_handle_md5 == GNUTLS_HASH_FAILED)
2104 { 2104 {
2105 gnutls_assert (); 2105 MHD_gnutls_assert ();
2106 return GNUTLS_E_MEMORY_ERROR; 2106 return GNUTLS_E_MEMORY_ERROR;
2107 } 2107 }
2108 } 2108 }
@@ -2110,10 +2110,10 @@ _gnutls_handshake_hash_init (mhd_gtls_session_t session)
2110 if (session->internals.handshake_mac_handle_sha == NULL) 2110 if (session->internals.handshake_mac_handle_sha == NULL)
2111 { 2111 {
2112 session->internals.handshake_mac_handle_sha = 2112 session->internals.handshake_mac_handle_sha =
2113 mhd_gtls_hash_init (MHD_GNUTLS_MAC_SHA1); 2113 MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
2114 if (session->internals.handshake_mac_handle_sha == GNUTLS_HASH_FAILED) 2114 if (session->internals.handshake_mac_handle_sha == GNUTLS_HASH_FAILED)
2115 { 2115 {
2116 gnutls_assert (); 2116 MHD_gnutls_assert ();
2117 return GNUTLS_E_MEMORY_ERROR; 2117 return GNUTLS_E_MEMORY_ERROR;
2118 } 2118 }
2119 } 2119 }
@@ -2122,68 +2122,68 @@ _gnutls_handshake_hash_init (mhd_gtls_session_t session)
2122} 2122}
2123 2123
2124static int 2124static int
2125_gnutls_send_supplemental (mhd_gtls_session_t session, int again) 2125MHD__gnutls_send_supplemental (MHD_gtls_session_t session, int again)
2126{ 2126{
2127 int ret = 0; 2127 int ret = 0;
2128 2128
2129 _gnutls_debug_log ("EXT[%x]: Sending supplemental data\n", session); 2129 MHD__gnutls_debug_log ("EXT[%x]: Sending supplemental data\n", session);
2130 2130
2131 if (again) 2131 if (again)
2132 ret = mhd_gtls_send_handshake (session, NULL, 0, 2132 ret = MHD_gtls_send_handshake (session, NULL, 0,
2133 GNUTLS_HANDSHAKE_SUPPLEMENTAL); 2133 GNUTLS_HANDSHAKE_SUPPLEMENTAL);
2134 else 2134 else
2135 { 2135 {
2136 mhd_gtls_buffer buf; 2136 MHD_gtls_buffer buf;
2137 mhd_gtls_buffer_init (&buf); 2137 MHD_gtls_buffer_init (&buf);
2138 2138
2139 ret = _gnutls_gen_supplemental (session, &buf); 2139 ret = MHD__gnutls_gen_supplemental (session, &buf);
2140 if (ret < 0) 2140 if (ret < 0)
2141 { 2141 {
2142 gnutls_assert (); 2142 MHD_gnutls_assert ();
2143 return ret; 2143 return ret;
2144 } 2144 }
2145 2145
2146 ret = mhd_gtls_send_handshake (session, buf.data, buf.length, 2146 ret = MHD_gtls_send_handshake (session, buf.data, buf.length,
2147 GNUTLS_HANDSHAKE_SUPPLEMENTAL); 2147 GNUTLS_HANDSHAKE_SUPPLEMENTAL);
2148 mhd_gtls_buffer_clear (&buf); 2148 MHD_gtls_buffer_clear (&buf);
2149 } 2149 }
2150 2150
2151 return ret; 2151 return ret;
2152} 2152}
2153 2153
2154static int 2154static int
2155_gnutls_recv_supplemental (mhd_gtls_session_t session) 2155MHD__gnutls_recv_supplemental (MHD_gtls_session_t session)
2156{ 2156{
2157 uint8_t *data = NULL; 2157 uint8_t *data = NULL;
2158 int datalen = 0; 2158 int datalen = 0;
2159 int ret; 2159 int ret;
2160 2160
2161 _gnutls_debug_log ("EXT[%x]: Expecting supplemental data\n", session); 2161 MHD__gnutls_debug_log ("EXT[%x]: Expecting supplemental data\n", session);
2162 2162
2163 ret = mhd_gtls_recv_handshake (session, &data, &datalen, 2163 ret = MHD_gtls_recv_handshake (session, &data, &datalen,
2164 GNUTLS_HANDSHAKE_SUPPLEMENTAL, 2164 GNUTLS_HANDSHAKE_SUPPLEMENTAL,
2165 OPTIONAL_PACKET); 2165 OPTIONAL_PACKET);
2166 if (ret < 0) 2166 if (ret < 0)
2167 { 2167 {
2168 gnutls_assert (); 2168 MHD_gnutls_assert ();
2169 return ret; 2169 return ret;
2170 } 2170 }
2171 2171
2172 ret = _gnutls_parse_supplemental (session, data, datalen); 2172 ret = MHD__gnutls_parse_supplemental (session, data, datalen);
2173 if (ret < 0) 2173 if (ret < 0)
2174 { 2174 {
2175 gnutls_assert (); 2175 MHD_gnutls_assert ();
2176 return ret; 2176 return ret;
2177 } 2177 }
2178 2178
2179 gnutls_free (data); 2179 MHD_gnutls_free (data);
2180 2180
2181 return ret; 2181 return ret;
2182} 2182}
2183 2183
2184/** 2184/**
2185 * MHD_gnutls_handshake - This is the main function in the handshake protocol. 2185 * MHD__gnutls_handshake - This is the main function in the handshake protocol.
2186 * @session: is a #mhd_gtls_session_t structure. 2186 * @session: is a #MHD_gtls_session_t structure.
2187 * 2187 *
2188 * This function does the handshake of the TLS/SSL protocol, and 2188 * This function does the handshake of the TLS/SSL protocol, and
2189 * initializes the TLS connection. 2189 * initializes the TLS connection.
@@ -2196,7 +2196,7 @@ _gnutls_recv_supplemental (mhd_gtls_session_t session)
2196 * The non-fatal errors such as %GNUTLS_E_AGAIN and 2196 * The non-fatal errors such as %GNUTLS_E_AGAIN and
2197 * %GNUTLS_E_INTERRUPTED interrupt the handshake procedure, which 2197 * %GNUTLS_E_INTERRUPTED interrupt the handshake procedure, which
2198 * should be later be resumed. Call this function again, until it 2198 * should be later be resumed. Call this function again, until it
2199 * returns 0; cf. MHD_gnutls_record_get_direction() and 2199 * returns 0; cf. MHD__gnutls_record_get_direction() and
2200 * MHD_gtls_error_is_fatal(). 2200 * MHD_gtls_error_is_fatal().
2201 * 2201 *
2202 * If this function is called by a server after a rehandshake request 2202 * If this function is called by a server after a rehandshake request
@@ -2209,24 +2209,24 @@ _gnutls_recv_supplemental (mhd_gtls_session_t session)
2209 * 2209 *
2210 **/ 2210 **/
2211int 2211int
2212MHD_gnutls_handshake (mhd_gtls_session_t session) 2212MHD__gnutls_handshake (MHD_gtls_session_t session)
2213{ 2213{
2214 int ret; 2214 int ret;
2215 2215
2216 if ((ret = _gnutls_handshake_hash_init (session)) < 0) 2216 if ((ret = MHD__gnutls_handshake_hash_init (session)) < 0)
2217 { 2217 {
2218 gnutls_assert (); 2218 MHD_gnutls_assert ();
2219 return ret; 2219 return ret;
2220 } 2220 }
2221#if MHD_DEBUG_TLS 2221#if MHD_DEBUG_TLS
2222 if (session->security_parameters.entity == GNUTLS_CLIENT) 2222 if (session->security_parameters.entity == GNUTLS_CLIENT)
2223 { 2223 {
2224 ret = mhd_gtls_handshake_client (session); 2224 ret = MHD_gtls_handshake_client (session);
2225 } 2225 }
2226 else 2226 else
2227#endif 2227#endif
2228 { 2228 {
2229 ret = mhd_gtls_handshake_server (session); 2229 ret = MHD_gtls_handshake_server (session);
2230 } 2230 }
2231 2231
2232 if (ret < 0) 2232 if (ret < 0)
@@ -2234,17 +2234,17 @@ MHD_gnutls_handshake (mhd_gtls_session_t session)
2234 /* In the case of a rehandshake abort 2234 /* In the case of a rehandshake abort
2235 * we should reset the handshake's internal state. 2235 * we should reset the handshake's internal state.
2236 */ 2236 */
2237 if (_gnutls_abort_handshake (session, ret) == 0) 2237 if (MHD__gnutls_abort_handshake (session, ret) == 0)
2238 STATE = STATE0; 2238 STATE = STATE0;
2239 2239
2240 return ret; 2240 return ret;
2241 } 2241 }
2242 2242
2243 ret = mhd_gtls_handshake_common (session); 2243 ret = MHD_gtls_handshake_common (session);
2244 2244
2245 if (ret < 0) 2245 if (ret < 0)
2246 { 2246 {
2247 if (_gnutls_abort_handshake (session, ret) == 0) 2247 if (MHD__gnutls_abort_handshake (session, ret) == 0)
2248 STATE = STATE0; 2248 STATE = STATE0;
2249 2249
2250 return ret; 2250 return ret;
@@ -2252,8 +2252,8 @@ MHD_gnutls_handshake (mhd_gtls_session_t session)
2252 2252
2253 STATE = STATE0; 2253 STATE = STATE0;
2254 2254
2255 _gnutls_handshake_io_buffer_clear (session); 2255 MHD__gnutls_handshake_io_buffer_clear (session);
2256 mhd_gtls_handshake_internal_state_clear (session); 2256 MHD_gtls_handshake_internal_state_clear (session);
2257 2257
2258 return 0; 2258 return 0;
2259} 2259}
@@ -2261,20 +2261,20 @@ MHD_gnutls_handshake (mhd_gtls_session_t session)
2261#define IMED_RET( str, ret) do { \ 2261#define IMED_RET( str, ret) do { \
2262 if (ret < 0) { \ 2262 if (ret < 0) { \
2263 if (MHD_gtls_error_is_fatal(ret)==0) return ret; \ 2263 if (MHD_gtls_error_is_fatal(ret)==0) return ret; \
2264 gnutls_assert(); \ 2264 MHD_gnutls_assert(); \
2265 ERR( str, ret); \ 2265 ERR( str, ret); \
2266 _gnutls_handshake_hash_buffers_clear(session); \ 2266 MHD__gnutls_handshake_hash_buffers_clear(session); \
2267 return ret; \ 2267 return ret; \
2268 } } while (0) 2268 } } while (0)
2269 2269
2270 2270
2271#if MHD_DEBUG_TLS 2271#if MHD_DEBUG_TLS
2272/* 2272/*
2273 * mhd_gtls_handshake_client 2273 * MHD_gtls_handshake_client
2274 * This function performs the client side of the handshake of the TLS/SSL protocol. 2274 * This function performs the client side of the handshake of the TLS/SSL protocol.
2275 */ 2275 */
2276int 2276int
2277mhd_gtls_handshake_client (mhd_gtls_session_t session) 2277MHD_gtls_handshake_client (MHD_gtls_session_t session)
2278{ 2278{
2279 int ret = 0; 2279 int ret = 0;
2280 2280
@@ -2282,8 +2282,8 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2282 char buf[64]; 2282 char buf[64];
2283 2283
2284 if (session->internals.resumed_security_parameters.session_id_size > 0) 2284 if (session->internals.resumed_security_parameters.session_id_size > 0)
2285 _gnutls_handshake_log ("HSK[%x]: Ask to resume: %s\n", session, 2285 MHD__gnutls_handshake_log ("HSK[%x]: Ask to resume: %s\n", session,
2286 mhd_gtls_bin2hex (session->internals. 2286 MHD_gtls_bin2hex (session->internals.
2287 resumed_security_parameters. 2287 resumed_security_parameters.
2288 session_id, 2288 session_id,
2289 session->internals. 2289 session->internals.
@@ -2296,14 +2296,14 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2296 { 2296 {
2297 case STATE0: 2297 case STATE0:
2298 case STATE1: 2298 case STATE1:
2299 ret = mhd_gtls_send_hello (session, AGAIN (STATE1)); 2299 ret = MHD_gtls_send_hello (session, AGAIN (STATE1));
2300 STATE = STATE1; 2300 STATE = STATE1;
2301 IMED_RET ("send hello", ret); 2301 IMED_RET ("send hello", ret);
2302 2302
2303 case STATE2: 2303 case STATE2:
2304 /* receive the server hello */ 2304 /* receive the server hello */
2305 ret = 2305 ret =
2306 mhd_gtls_recv_handshake (session, NULL, NULL, 2306 MHD_gtls_recv_handshake (session, NULL, NULL,
2307 GNUTLS_HANDSHAKE_SERVER_HELLO, 2307 GNUTLS_HANDSHAKE_SERVER_HELLO,
2308 MANDATORY_PACKET); 2308 MANDATORY_PACKET);
2309 STATE = STATE2; 2309 STATE = STATE2;
@@ -2312,7 +2312,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2312 case STATE70: 2312 case STATE70:
2313 if (session->security_parameters.extensions.do_recv_supplemental) 2313 if (session->security_parameters.extensions.do_recv_supplemental)
2314 { 2314 {
2315 ret = _gnutls_recv_supplemental (session); 2315 ret = MHD__gnutls_recv_supplemental (session);
2316 STATE = STATE70; 2316 STATE = STATE70;
2317 IMED_RET ("recv supplemental", ret); 2317 IMED_RET ("recv supplemental", ret);
2318 } 2318 }
@@ -2320,14 +2320,14 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2320 case STATE3: 2320 case STATE3:
2321 /* RECV CERTIFICATE */ 2321 /* RECV CERTIFICATE */
2322 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2322 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2323 ret = mhd_gtls_recv_server_certificate (session); 2323 ret = MHD_gtls_recv_server_certificate (session);
2324 STATE = STATE3; 2324 STATE = STATE3;
2325 IMED_RET ("recv server certificate", ret); 2325 IMED_RET ("recv server certificate", ret);
2326 2326
2327 case STATE4: 2327 case STATE4:
2328 /* receive the server key exchange */ 2328 /* receive the server key exchange */
2329 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2329 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2330 ret = mhd_gtls_recv_server_kx_message (session); 2330 ret = MHD_gtls_recv_server_kx_message (session);
2331 STATE = STATE4; 2331 STATE = STATE4;
2332 IMED_RET ("recv server kx message", ret); 2332 IMED_RET ("recv server kx message", ret);
2333 2333
@@ -2336,7 +2336,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2336 */ 2336 */
2337 2337
2338 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2338 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2339 ret = mhd_gtls_recv_server_certificate_request (session); 2339 ret = MHD_gtls_recv_server_certificate_request (session);
2340 STATE = STATE5; 2340 STATE = STATE5;
2341 IMED_RET ("recv server certificate request message", ret); 2341 IMED_RET ("recv server certificate request message", ret);
2342 2342
@@ -2344,7 +2344,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2344 /* receive the server hello done */ 2344 /* receive the server hello done */
2345 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2345 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2346 ret = 2346 ret =
2347 mhd_gtls_recv_handshake (session, NULL, NULL, 2347 MHD_gtls_recv_handshake (session, NULL, NULL,
2348 GNUTLS_HANDSHAKE_SERVER_HELLO_DONE, 2348 GNUTLS_HANDSHAKE_SERVER_HELLO_DONE,
2349 MANDATORY_PACKET); 2349 MANDATORY_PACKET);
2350 STATE = STATE6; 2350 STATE = STATE6;
@@ -2353,7 +2353,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2353 case STATE71: 2353 case STATE71:
2354 if (session->security_parameters.extensions.do_send_supplemental) 2354 if (session->security_parameters.extensions.do_send_supplemental)
2355 { 2355 {
2356 ret = _gnutls_send_supplemental (session, AGAIN (STATE71)); 2356 ret = MHD__gnutls_send_supplemental (session, AGAIN (STATE71));
2357 STATE = STATE71; 2357 STATE = STATE71;
2358 IMED_RET ("send supplemental", ret); 2358 IMED_RET ("send supplemental", ret);
2359 } 2359 }
@@ -2362,13 +2362,13 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2362 /* send our certificate - if any and if requested 2362 /* send our certificate - if any and if requested
2363 */ 2363 */
2364 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2364 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2365 ret = mhd_gtls_send_client_certificate (session, AGAIN (STATE7)); 2365 ret = MHD_gtls_send_client_certificate (session, AGAIN (STATE7));
2366 STATE = STATE7; 2366 STATE = STATE7;
2367 IMED_RET ("send client certificate", ret); 2367 IMED_RET ("send client certificate", ret);
2368 2368
2369 case STATE8: 2369 case STATE8:
2370 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2370 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2371 ret = mhd_gtls_send_client_kx_message (session, AGAIN (STATE8)); 2371 ret = MHD_gtls_send_client_kx_message (session, AGAIN (STATE8));
2372 STATE = STATE8; 2372 STATE = STATE8;
2373 IMED_RET ("send client kx", ret); 2373 IMED_RET ("send client kx", ret);
2374 2374
@@ -2376,7 +2376,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2376 /* send client certificate verify */ 2376 /* send client certificate verify */
2377 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2377 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2378 ret = 2378 ret =
2379 mhd_gtls_send_client_certificate_verify (session, AGAIN (STATE9)); 2379 MHD_gtls_send_client_certificate_verify (session, AGAIN (STATE9));
2380 STATE = STATE9; 2380 STATE = STATE9;
2381 IMED_RET ("send client certificate verify", ret); 2381 IMED_RET ("send client certificate verify", ret);
2382 2382
@@ -2393,7 +2393,7 @@ mhd_gtls_handshake_client (mhd_gtls_session_t session)
2393/* This function sends the final handshake packets and initializes connection 2393/* This function sends the final handshake packets and initializes connection
2394 */ 2394 */
2395static int 2395static int
2396_gnutls_send_handshake_final (mhd_gtls_session_t session, int init) 2396MHD__gnutls_send_handshake_final (MHD_gtls_session_t session, int init)
2397{ 2397{
2398 int ret = 0; 2398 int ret = 0;
2399 2399
@@ -2403,12 +2403,12 @@ _gnutls_send_handshake_final (mhd_gtls_session_t session, int init)
2403 { 2403 {
2404 case STATE0: 2404 case STATE0:
2405 case STATE20: 2405 case STATE20:
2406 ret = mhd_gtls_send_change_cipher_spec (session, AGAIN (STATE20)); 2406 ret = MHD_gtls_send_change_cipher_spec (session, AGAIN (STATE20));
2407 STATE = STATE20; 2407 STATE = STATE20;
2408 if (ret < 0) 2408 if (ret < 0)
2409 { 2409 {
2410 ERR ("send ChangeCipherSpec", ret); 2410 ERR ("send ChangeCipherSpec", ret);
2411 gnutls_assert (); 2411 MHD_gnutls_assert ();
2412 return ret; 2412 return ret;
2413 } 2413 }
2414 2414
@@ -2416,29 +2416,29 @@ _gnutls_send_handshake_final (mhd_gtls_session_t session, int init)
2416 */ 2416 */
2417 if (init == TRUE) 2417 if (init == TRUE)
2418 { 2418 {
2419 ret = mhd_gtls_connection_state_init (session); 2419 ret = MHD_gtls_connection_state_init (session);
2420 if (ret < 0) 2420 if (ret < 0)
2421 { 2421 {
2422 gnutls_assert (); 2422 MHD_gnutls_assert ();
2423 return ret; 2423 return ret;
2424 } 2424 }
2425 } 2425 }
2426 2426
2427 ret = mhd_gtls_write_connection_state_init (session); 2427 ret = MHD_gtls_write_connection_state_init (session);
2428 if (ret < 0) 2428 if (ret < 0)
2429 { 2429 {
2430 gnutls_assert (); 2430 MHD_gnutls_assert ();
2431 return ret; 2431 return ret;
2432 } 2432 }
2433 2433
2434 case STATE21: 2434 case STATE21:
2435 /* send the finished message */ 2435 /* send the finished message */
2436 ret = _gnutls_send_finished (session, AGAIN (STATE21)); 2436 ret = MHD__gnutls_send_finished (session, AGAIN (STATE21));
2437 STATE = STATE21; 2437 STATE = STATE21;
2438 if (ret < 0) 2438 if (ret < 0)
2439 { 2439 {
2440 ERR ("send Finished", ret); 2440 ERR ("send Finished", ret);
2441 gnutls_assert (); 2441 MHD_gnutls_assert ();
2442 return ret; 2442 return ret;
2443 } 2443 }
2444 2444
@@ -2455,7 +2455,7 @@ _gnutls_send_handshake_final (mhd_gtls_session_t session, int init)
2455 * read session. 2455 * read session.
2456 */ 2456 */
2457static int 2457static int
2458_gnutls_recv_handshake_final (mhd_gtls_session_t session, int init) 2458MHD__gnutls_recv_handshake_final (MHD_gtls_session_t session, int init)
2459{ 2459{
2460 int ret = 0; 2460 int ret = 0;
2461 uint8_t ch; 2461 uint8_t ch;
@@ -2465,40 +2465,40 @@ _gnutls_recv_handshake_final (mhd_gtls_session_t session, int init)
2465 case STATE0: 2465 case STATE0:
2466 case STATE30: 2466 case STATE30:
2467 ret = 2467 ret =
2468 mhd_gtls_recv_int (session, GNUTLS_CHANGE_CIPHER_SPEC, -1, &ch, 1); 2468 MHD_gtls_recv_int (session, GNUTLS_CHANGE_CIPHER_SPEC, -1, &ch, 1);
2469 STATE = STATE30; 2469 STATE = STATE30;
2470 if (ret <= 0) 2470 if (ret <= 0)
2471 { 2471 {
2472 ERR ("recv ChangeCipherSpec", ret); 2472 ERR ("recv ChangeCipherSpec", ret);
2473 gnutls_assert (); 2473 MHD_gnutls_assert ();
2474 return (ret < 0) ? ret : GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 2474 return (ret < 0) ? ret : GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
2475 } 2475 }
2476 2476
2477 /* Initialize the connection session (start encryption) - in case of server */ 2477 /* Initialize the connection session (start encryption) - in case of server */
2478 if (init == TRUE) 2478 if (init == TRUE)
2479 { 2479 {
2480 ret = mhd_gtls_connection_state_init (session); 2480 ret = MHD_gtls_connection_state_init (session);
2481 if (ret < 0) 2481 if (ret < 0)
2482 { 2482 {
2483 gnutls_assert (); 2483 MHD_gnutls_assert ();
2484 return ret; 2484 return ret;
2485 } 2485 }
2486 } 2486 }
2487 2487
2488 ret = mhd_gtls_read_connection_state_init (session); 2488 ret = MHD_gtls_read_connection_state_init (session);
2489 if (ret < 0) 2489 if (ret < 0)
2490 { 2490 {
2491 gnutls_assert (); 2491 MHD_gnutls_assert ();
2492 return ret; 2492 return ret;
2493 } 2493 }
2494 2494
2495 case STATE31: 2495 case STATE31:
2496 ret = _gnutls_recv_finished (session); 2496 ret = MHD__gnutls_recv_finished (session);
2497 STATE = STATE31; 2497 STATE = STATE31;
2498 if (ret < 0) 2498 if (ret < 0)
2499 { 2499 {
2500 ERR ("recv finished", ret); 2500 ERR ("recv finished", ret);
2501 gnutls_assert (); 2501 MHD_gnutls_assert ();
2502 return ret; 2502 return ret;
2503 } 2503 }
2504 STATE = STATE0; 2504 STATE = STATE0;
@@ -2511,12 +2511,12 @@ _gnutls_recv_handshake_final (mhd_gtls_session_t session, int init)
2511} 2511}
2512 2512
2513 /* 2513 /*
2514 * mhd_gtls_handshake_server 2514 * MHD_gtls_handshake_server
2515 * This function does the server stuff of the handshake protocol. 2515 * This function does the server stuff of the handshake protocol.
2516 */ 2516 */
2517 2517
2518int 2518int
2519mhd_gtls_handshake_server (mhd_gtls_session_t session) 2519MHD_gtls_handshake_server (MHD_gtls_session_t session)
2520{ 2520{
2521 int ret = 0; 2521 int ret = 0;
2522 2522
@@ -2525,21 +2525,21 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2525 case STATE0: 2525 case STATE0:
2526 case STATE1: 2526 case STATE1:
2527 ret = 2527 ret =
2528 mhd_gtls_recv_handshake (session, NULL, NULL, 2528 MHD_gtls_recv_handshake (session, NULL, NULL,
2529 GNUTLS_HANDSHAKE_CLIENT_HELLO, 2529 GNUTLS_HANDSHAKE_CLIENT_HELLO,
2530 MANDATORY_PACKET); 2530 MANDATORY_PACKET);
2531 STATE = STATE1; 2531 STATE = STATE1;
2532 IMED_RET ("recv hello", ret); 2532 IMED_RET ("recv hello", ret);
2533 2533
2534 case STATE2: 2534 case STATE2:
2535 ret = mhd_gtls_send_hello (session, AGAIN (STATE2)); 2535 ret = MHD_gtls_send_hello (session, AGAIN (STATE2));
2536 STATE = STATE2; 2536 STATE = STATE2;
2537 IMED_RET ("send hello", ret); 2537 IMED_RET ("send hello", ret);
2538 2538
2539 case STATE70: 2539 case STATE70:
2540 if (session->security_parameters.extensions.do_send_supplemental) 2540 if (session->security_parameters.extensions.do_send_supplemental)
2541 { 2541 {
2542 ret = _gnutls_send_supplemental (session, AGAIN (STATE70)); 2542 ret = MHD__gnutls_send_supplemental (session, AGAIN (STATE70));
2543 STATE = STATE70; 2543 STATE = STATE70;
2544 IMED_RET ("send supplemental data", ret); 2544 IMED_RET ("send supplemental data", ret);
2545 } 2545 }
@@ -2549,14 +2549,14 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2549 /* NOTE: these should not be send if we are resuming */ 2549 /* NOTE: these should not be send if we are resuming */
2550 2550
2551 if (session->internals.resumed == RESUME_FALSE) 2551 if (session->internals.resumed == RESUME_FALSE)
2552 ret = mhd_gtls_send_server_certificate (session, AGAIN (STATE3)); 2552 ret = MHD_gtls_send_server_certificate (session, AGAIN (STATE3));
2553 STATE = STATE3; 2553 STATE = STATE3;
2554 IMED_RET ("send server certificate", ret); 2554 IMED_RET ("send server certificate", ret);
2555 2555
2556 case STATE4: 2556 case STATE4:
2557 /* send server key exchange (A) */ 2557 /* send server key exchange (A) */
2558 if (session->internals.resumed == RESUME_FALSE) 2558 if (session->internals.resumed == RESUME_FALSE)
2559 ret = mhd_gtls_send_server_kx_message (session, AGAIN (STATE4)); 2559 ret = MHD_gtls_send_server_kx_message (session, AGAIN (STATE4));
2560 STATE = STATE4; 2560 STATE = STATE4;
2561 IMED_RET ("send server kx", ret); 2561 IMED_RET ("send server kx", ret);
2562 2562
@@ -2564,7 +2564,7 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2564 /* Send certificate request - if requested to */ 2564 /* Send certificate request - if requested to */
2565 if (session->internals.resumed == RESUME_FALSE) 2565 if (session->internals.resumed == RESUME_FALSE)
2566 ret = 2566 ret =
2567 mhd_gtls_send_server_certificate_request (session, AGAIN (STATE5)); 2567 MHD_gtls_send_server_certificate_request (session, AGAIN (STATE5));
2568 STATE = STATE5; 2568 STATE = STATE5;
2569 IMED_RET ("send server cert request", ret); 2569 IMED_RET ("send server cert request", ret);
2570 2570
@@ -2572,7 +2572,7 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2572 /* send the server hello done */ 2572 /* send the server hello done */
2573 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2573 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2574 ret = 2574 ret =
2575 _gnutls_send_empty_handshake (session, 2575 MHD__gnutls_send_empty_handshake (session,
2576 GNUTLS_HANDSHAKE_SERVER_HELLO_DONE, 2576 GNUTLS_HANDSHAKE_SERVER_HELLO_DONE,
2577 AGAIN (STATE6)); 2577 AGAIN (STATE6));
2578 STATE = STATE6; 2578 STATE = STATE6;
@@ -2581,7 +2581,7 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2581 case STATE71: 2581 case STATE71:
2582 if (session->security_parameters.extensions.do_recv_supplemental) 2582 if (session->security_parameters.extensions.do_recv_supplemental)
2583 { 2583 {
2584 ret = _gnutls_recv_supplemental (session); 2584 ret = MHD__gnutls_recv_supplemental (session);
2585 STATE = STATE71; 2585 STATE = STATE71;
2586 IMED_RET ("recv client supplemental", ret); 2586 IMED_RET ("recv client supplemental", ret);
2587 } 2587 }
@@ -2590,21 +2590,21 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2590 case STATE7: 2590 case STATE7:
2591 /* receive the client certificate message */ 2591 /* receive the client certificate message */
2592 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2592 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2593 ret = mhd_gtls_recv_client_certificate (session); 2593 ret = MHD_gtls_recv_client_certificate (session);
2594 STATE = STATE7; 2594 STATE = STATE7;
2595 IMED_RET ("recv client certificate", ret); 2595 IMED_RET ("recv client certificate", ret);
2596 2596
2597 case STATE8: 2597 case STATE8:
2598 /* receive the client key exchange message */ 2598 /* receive the client key exchange message */
2599 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2599 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2600 ret = mhd_gtls_recv_client_kx_message (session); 2600 ret = MHD_gtls_recv_client_kx_message (session);
2601 STATE = STATE8; 2601 STATE = STATE8;
2602 IMED_RET ("recv client kx", ret); 2602 IMED_RET ("recv client kx", ret);
2603 2603
2604 case STATE9: 2604 case STATE9:
2605 /* receive the client certificate verify message */ 2605 /* receive the client certificate verify message */
2606 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */ 2606 if (session->internals.resumed == RESUME_FALSE) /* if we are not resuming */
2607 ret = mhd_gtls_recv_client_certificate_verify_message (session); 2607 ret = MHD_gtls_recv_client_certificate_verify_message (session);
2608 STATE = STATE9; 2608 STATE = STATE9;
2609 IMED_RET ("recv client certificate verify", ret); 2609 IMED_RET ("recv client certificate verify", ret);
2610 2610
@@ -2617,7 +2617,7 @@ mhd_gtls_handshake_server (mhd_gtls_session_t session)
2617} 2617}
2618 2618
2619int 2619int
2620mhd_gtls_handshake_common (mhd_gtls_session_t session) 2620MHD_gtls_handshake_common (MHD_gtls_session_t session)
2621{ 2621{
2622 int ret = 0; 2622 int ret = 0;
2623 2623
@@ -2629,36 +2629,36 @@ mhd_gtls_handshake_common (mhd_gtls_session_t session)
2629 { 2629 {
2630 /* if we are a client resuming - or we are a server not resuming */ 2630 /* if we are a client resuming - or we are a server not resuming */
2631 2631
2632 ret = _gnutls_recv_handshake_final (session, TRUE); 2632 ret = MHD__gnutls_recv_handshake_final (session, TRUE);
2633 IMED_RET ("recv handshake final", ret); 2633 IMED_RET ("recv handshake final", ret);
2634 2634
2635 ret = _gnutls_send_handshake_final (session, FALSE); 2635 ret = MHD__gnutls_send_handshake_final (session, FALSE);
2636 IMED_RET ("send handshake final", ret); 2636 IMED_RET ("send handshake final", ret);
2637 } 2637 }
2638 else 2638 else
2639 { /* if we are a client not resuming - or we are a server resuming */ 2639 { /* if we are a client not resuming - or we are a server resuming */
2640 2640
2641 ret = _gnutls_send_handshake_final (session, TRUE); 2641 ret = MHD__gnutls_send_handshake_final (session, TRUE);
2642 IMED_RET ("send handshake final 2", ret); 2642 IMED_RET ("send handshake final 2", ret);
2643 2643
2644 ret = _gnutls_recv_handshake_final (session, FALSE); 2644 ret = MHD__gnutls_recv_handshake_final (session, FALSE);
2645 IMED_RET ("recv handshake final 2", ret); 2645 IMED_RET ("recv handshake final 2", ret);
2646 } 2646 }
2647 2647
2648 /* clear handshake buffer */ 2648 /* clear handshake buffer */
2649 _gnutls_handshake_hash_buffers_clear (session); 2649 MHD__gnutls_handshake_hash_buffers_clear (session);
2650 return ret; 2650 return ret;
2651 2651
2652} 2652}
2653 2653
2654int 2654int
2655mhd_gtls_generate_session_id (opaque * session_id, uint8_t * len) 2655MHD_gtls_generate_session_id (opaque * session_id, uint8_t * len)
2656{ 2656{
2657 *len = TLS_MAX_SESSION_ID_SIZE; 2657 *len = TLS_MAX_SESSION_ID_SIZE;
2658 2658
2659 if (gc_nonce (session_id, *len) != GC_OK) 2659 if (MHD_gc_nonce (session_id, *len) != GC_OK)
2660 { 2660 {
2661 gnutls_assert (); 2661 MHD_gnutls_assert ();
2662 return GNUTLS_E_RANDOM_FAILED; 2662 return GNUTLS_E_RANDOM_FAILED;
2663 } 2663 }
2664 2664
@@ -2666,19 +2666,19 @@ mhd_gtls_generate_session_id (opaque * session_id, uint8_t * len)
2666} 2666}
2667 2667
2668int 2668int
2669mhd_gtls_recv_hello_request (mhd_gtls_session_t session, void *data, 2669MHD_gtls_recv_hello_request (MHD_gtls_session_t session, void *data,
2670 uint32_t data_size) 2670 uint32_t data_size)
2671{ 2671{
2672 uint8_t type; 2672 uint8_t type;
2673 2673
2674 if (session->security_parameters.entity == GNUTLS_SERVER) 2674 if (session->security_parameters.entity == GNUTLS_SERVER)
2675 { 2675 {
2676 gnutls_assert (); 2676 MHD_gnutls_assert ();
2677 return GNUTLS_E_UNEXPECTED_PACKET; 2677 return GNUTLS_E_UNEXPECTED_PACKET;
2678 } 2678 }
2679 if (data_size < 1) 2679 if (data_size < 1)
2680 { 2680 {
2681 gnutls_assert (); 2681 MHD_gnutls_assert ();
2682 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 2682 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
2683 } 2683 }
2684 type = ((uint8_t *) data)[0]; 2684 type = ((uint8_t *) data)[0];
@@ -2686,7 +2686,7 @@ mhd_gtls_recv_hello_request (mhd_gtls_session_t session, void *data,
2686 return GNUTLS_E_REHANDSHAKE; 2686 return GNUTLS_E_REHANDSHAKE;
2687 else 2687 else
2688 { 2688 {
2689 gnutls_assert (); 2689 MHD_gnutls_assert ();
2690 return GNUTLS_E_UNEXPECTED_PACKET; 2690 return GNUTLS_E_UNEXPECTED_PACKET;
2691 } 2691 }
2692} 2692}
@@ -2695,33 +2695,33 @@ mhd_gtls_recv_hello_request (mhd_gtls_session_t session, void *data,
2695 * (DH or RSA) set up. Otherwise returns 0. 2695 * (DH or RSA) set up. Otherwise returns 0.
2696 */ 2696 */
2697inline static int 2697inline static int
2698check_server_params (mhd_gtls_session_t session, 2698check_server_params (MHD_gtls_session_t session,
2699 enum MHD_GNUTLS_KeyExchangeAlgorithm kx, 2699 enum MHD_GNUTLS_KeyExchangeAlgorithm kx,
2700 enum MHD_GNUTLS_KeyExchangeAlgorithm *alg, int alg_size) 2700 enum MHD_GNUTLS_KeyExchangeAlgorithm *alg, int alg_size)
2701{ 2701{
2702 int cred_type; 2702 int cred_type;
2703 mhd_gtls_dh_params_t dh_params = NULL; 2703 MHD_gtls_dh_params_t dh_params = NULL;
2704 mhd_gtls_rsa_params_t rsa_params = NULL; 2704 MHD_gtls_rsa_params_t rsa_params = NULL;
2705 int j; 2705 int j;
2706 2706
2707 cred_type = mhd_gtls_map_kx_get_cred (kx, 1); 2707 cred_type = MHD_gtls_map_kx_get_cred (kx, 1);
2708 2708
2709 /* Read the Diffie Hellman parameters, if any. 2709 /* Read the Diffie Hellman parameters, if any.
2710 */ 2710 */
2711 if (cred_type == MHD_GNUTLS_CRD_CERTIFICATE) 2711 if (cred_type == MHD_GNUTLS_CRD_CERTIFICATE)
2712 { 2712 {
2713 int delete; 2713 int delete;
2714 mhd_gtls_cert_credentials_t x509_cred = 2714 MHD_gtls_cert_credentials_t x509_cred =
2715 (mhd_gtls_cert_credentials_t) mhd_gtls_get_cred (session->key, 2715 (MHD_gtls_cert_credentials_t) MHD_gtls_get_cred (session->key,
2716 cred_type, NULL); 2716 cred_type, NULL);
2717 2717
2718 if (x509_cred != NULL) 2718 if (x509_cred != NULL)
2719 { 2719 {
2720 dh_params = 2720 dh_params =
2721 mhd_gtls_get_dh_params (x509_cred->dh_params, 2721 MHD_gtls_get_dh_params (x509_cred->dh_params,
2722 x509_cred->params_func, session); 2722 x509_cred->params_func, session);
2723 rsa_params = 2723 rsa_params =
2724 mhd_gtls_certificate_get_rsa_params (x509_cred->rsa_params, 2724 MHD_gtls_certificate_get_rsa_params (x509_cred->rsa_params,
2725 x509_cred->params_func, 2725 x509_cred->params_func,
2726 session); 2726 session);
2727 } 2727 }
@@ -2746,15 +2746,15 @@ check_server_params (mhd_gtls_session_t session,
2746 } 2746 }
2747 else if (cred_type == MHD_GNUTLS_CRD_ANON) 2747 else if (cred_type == MHD_GNUTLS_CRD_ANON)
2748 { 2748 {
2749 mhd_gtls_anon_server_credentials_t anon_cred = 2749 MHD_gtls_anon_server_credentials_t anon_cred =
2750 (mhd_gtls_anon_server_credentials_t) mhd_gtls_get_cred (session->key, 2750 (MHD_gtls_anon_server_credentials_t) MHD_gtls_get_cred (session->key,
2751 cred_type, 2751 cred_type,
2752 NULL); 2752 NULL);
2753 2753
2754 if (anon_cred != NULL) 2754 if (anon_cred != NULL)
2755 { 2755 {
2756 dh_params = 2756 dh_params =
2757 mhd_gtls_get_dh_params (anon_cred->dh_params, 2757 MHD_gtls_get_dh_params (anon_cred->dh_params,
2758 anon_cred->params_func, session); 2758 anon_cred->params_func, session);
2759 } 2759 }
2760#endif 2760#endif
@@ -2762,14 +2762,14 @@ check_server_params (mhd_gtls_session_t session,
2762 } 2762 }
2763 else if (cred_type == MHD_GNUTLS_CRD_PSK) 2763 else if (cred_type == MHD_GNUTLS_CRD_PSK)
2764 { 2764 {
2765 gnutls_psk_server_credentials_t psk_cred = 2765 MHD_gnutls_psk_server_credentials_t psk_cred =
2766 (gnutls_psk_server_credentials_t) mhd_gtls_get_cred (session->key, 2766 (MHD_gnutls_psk_server_credentials_t) MHD_gtls_get_cred (session->key,
2767 cred_type, NULL); 2767 cred_type, NULL);
2768 2768
2769 if (psk_cred != NULL) 2769 if (psk_cred != NULL)
2770 { 2770 {
2771 dh_params = 2771 dh_params =
2772 mhd_gtls_get_dh_params (psk_cred->dh_params, 2772 MHD_gtls_get_dh_params (psk_cred->dh_params,
2773 psk_cred->params_func, session); 2773 psk_cred->params_func, session);
2774 } 2774 }
2775#endif 2775#endif
@@ -2781,22 +2781,22 @@ check_server_params (mhd_gtls_session_t session,
2781 /* If the key exchange method needs RSA or DH params, 2781 /* If the key exchange method needs RSA or DH params,
2782 * but they are not set then remove it. 2782 * but they are not set then remove it.
2783 */ 2783 */
2784 if (mhd_gtls_kx_needs_rsa_params (kx) != 0) 2784 if (MHD_gtls_kx_needs_rsa_params (kx) != 0)
2785 { 2785 {
2786 /* needs rsa params. */ 2786 /* needs rsa params. */
2787 if (_gnutls_rsa_params_to_mpi (rsa_params) == NULL) 2787 if (MHD__gnutls_rsa_params_to_mpi (rsa_params) == NULL)
2788 { 2788 {
2789 gnutls_assert (); 2789 MHD_gnutls_assert ();
2790 return 1; 2790 return 1;
2791 } 2791 }
2792 } 2792 }
2793 2793
2794 if (mhd_gtls_kx_needs_dh_params (kx) != 0) 2794 if (MHD_gtls_kx_needs_dh_params (kx) != 0)
2795 { 2795 {
2796 /* needs DH params. */ 2796 /* needs DH params. */
2797 if (mhd_gtls_dh_params_to_mpi (dh_params) == NULL) 2797 if (MHD_gtls_dh_params_to_mpi (dh_params) == NULL)
2798 { 2798 {
2799 gnutls_assert (); 2799 MHD_gnutls_assert ();
2800 return 1; 2800 return 1;
2801 } 2801 }
2802 } 2802 }
@@ -2808,11 +2808,11 @@ check_server_params (mhd_gtls_session_t session,
2808 * the requested authentication method. We remove an algorithm if 2808 * the requested authentication method. We remove an algorithm if
2809 * we have a certificate with keyUsage bits set. 2809 * we have a certificate with keyUsage bits set.
2810 * 2810 *
2811 * This does a more high level check than gnutls_supported_ciphersuites(), 2811 * This does a more high level check than MHD_gnutls_supported_ciphersuites(),
2812 * by checking certificates etc. 2812 * by checking certificates etc.
2813 */ 2813 */
2814int 2814int
2815mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session, 2815MHD_gtls_remove_unwanted_ciphersuites (MHD_gtls_session_t session,
2816 cipher_suite_st ** cipherSuites, 2816 cipher_suite_st ** cipherSuites,
2817 int numCipherSuites, 2817 int numCipherSuites,
2818 enum MHD_GNUTLS_PublicKeyAlgorithm 2818 enum MHD_GNUTLS_PublicKeyAlgorithm
@@ -2822,7 +2822,7 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2822 int ret = 0; 2822 int ret = 0;
2823 cipher_suite_st *newSuite, cs; 2823 cipher_suite_st *newSuite, cs;
2824 int newSuiteSize = 0, i; 2824 int newSuiteSize = 0, i;
2825 mhd_gtls_cert_credentials_t cert_cred; 2825 MHD_gtls_cert_credentials_t cert_cred;
2826 enum MHD_GNUTLS_KeyExchangeAlgorithm kx; 2826 enum MHD_GNUTLS_KeyExchangeAlgorithm kx;
2827 int server = session->security_parameters.entity == GNUTLS_SERVER ? 1 : 0; 2827 int server = session->security_parameters.entity == GNUTLS_SERVER ? 1 : 0;
2828 enum MHD_GNUTLS_KeyExchangeAlgorithm *alg = NULL; 2828 enum MHD_GNUTLS_KeyExchangeAlgorithm *alg = NULL;
@@ -2835,7 +2835,7 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2835 */ 2835 */
2836 2836
2837 cert_cred = 2837 cert_cred =
2838 (mhd_gtls_cert_credentials_t) mhd_gtls_get_cred (session->key, 2838 (MHD_gtls_cert_credentials_t) MHD_gtls_get_cred (session->key,
2839 MHD_GNUTLS_CRD_CERTIFICATE, 2839 MHD_GNUTLS_CRD_CERTIFICATE,
2840 NULL); 2840 NULL);
2841 2841
@@ -2845,11 +2845,11 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2845 if (session->security_parameters.entity == GNUTLS_SERVER 2845 if (session->security_parameters.entity == GNUTLS_SERVER
2846 && cert_cred != NULL) 2846 && cert_cred != NULL)
2847 { 2847 {
2848 ret = mhd_gtls_server_select_cert (session, requested_pk_algo); 2848 ret = MHD_gtls_server_select_cert (session, requested_pk_algo);
2849 if (ret < 0) 2849 if (ret < 0)
2850 { 2850 {
2851 gnutls_assert (); 2851 MHD_gnutls_assert ();
2852 _gnutls_x509_log ("Could not find an appropriate certificate: %s\n", 2852 MHD__gnutls_x509_log ("Could not find an appropriate certificate: %s\n",
2853 MHD_gtls_strerror (ret)); 2853 MHD_gtls_strerror (ret));
2854 cert_cred = NULL; 2854 cert_cred = NULL;
2855 } 2855 }
@@ -2859,17 +2859,17 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2859 * supported by the X509 certificate parameters. 2859 * supported by the X509 certificate parameters.
2860 */ 2860 */
2861 if ((ret = 2861 if ((ret =
2862 mhd_gtls_selected_cert_supported_kx (session, &alg, &alg_size)) < 0) 2862 MHD_gtls_selected_cert_supported_kx (session, &alg, &alg_size)) < 0)
2863 { 2863 {
2864 gnutls_assert (); 2864 MHD_gnutls_assert ();
2865 return ret; 2865 return ret;
2866 } 2866 }
2867 2867
2868 newSuite = gnutls_malloc (numCipherSuites * sizeof (cipher_suite_st)); 2868 newSuite = MHD_gnutls_malloc (numCipherSuites * sizeof (cipher_suite_st));
2869 if (newSuite == NULL) 2869 if (newSuite == NULL)
2870 { 2870 {
2871 gnutls_assert (); 2871 MHD_gnutls_assert ();
2872 gnutls_free (alg); 2872 MHD_gnutls_free (alg);
2873 return GNUTLS_E_MEMORY_ERROR; 2873 return GNUTLS_E_MEMORY_ERROR;
2874 } 2874 }
2875 2875
@@ -2882,11 +2882,11 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2882 /* finds the key exchange algorithm in 2882 /* finds the key exchange algorithm in
2883 * the ciphersuite 2883 * the ciphersuite
2884 */ 2884 */
2885 kx = mhd_gtls_cipher_suite_get_kx_algo (&(*cipherSuites)[i]); 2885 kx = MHD_gtls_cipher_suite_get_kx_algo (&(*cipherSuites)[i]);
2886 2886
2887 /* if it is defined but had no credentials 2887 /* if it is defined but had no credentials
2888 */ 2888 */
2889 if (mhd_gtls_get_kx_cred (session, kx, NULL) == NULL) 2889 if (MHD_gtls_get_kx_cred (session, kx, NULL) == NULL)
2890 { 2890 {
2891 delete = 1; 2891 delete = 1;
2892 } 2892 }
@@ -2899,12 +2899,12 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2899 } 2899 }
2900 2900
2901 /* These two SRP kx's are marked to require a CRD_CERTIFICATE, 2901 /* These two SRP kx's are marked to require a CRD_CERTIFICATE,
2902 (see cred_mappings in gnutls_algorithms.c), but it also 2902 (see cred_mappings in MHD_gnutls_algorithms.c), but it also
2903 requires a SRP credential. Don't use SRP kx unless we have a 2903 requires a SRP credential. Don't use SRP kx unless we have a
2904 SRP credential too. */ 2904 SRP credential too. */
2905 if (kx == MHD_GNUTLS_KX_SRP_RSA || kx == MHD_GNUTLS_KX_SRP_DSS) 2905 if (kx == MHD_GNUTLS_KX_SRP_RSA || kx == MHD_GNUTLS_KX_SRP_DSS)
2906 { 2906 {
2907 if (!mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_SRP, NULL)) 2907 if (!MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_SRP, NULL))
2908 delete = 1; 2908 delete = 1;
2909 } 2909 }
2910 2910
@@ -2913,24 +2913,24 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2913 if (delete == 0) 2913 if (delete == 0)
2914 { 2914 {
2915 2915
2916 _gnutls_handshake_log ("HSK[%x]: Keeping ciphersuite: %s\n", 2916 MHD__gnutls_handshake_log ("HSK[%x]: Keeping ciphersuite: %s\n",
2917 session, 2917 session,
2918 mhd_gtls_cipher_suite_get_name (&cs)); 2918 MHD_gtls_cipher_suite_get_name (&cs));
2919 2919
2920 memcpy (newSuite[newSuiteSize].suite, (*cipherSuites)[i].suite, 2); 2920 memcpy (newSuite[newSuiteSize].suite, (*cipherSuites)[i].suite, 2);
2921 newSuiteSize++; 2921 newSuiteSize++;
2922 } 2922 }
2923 else 2923 else
2924 { 2924 {
2925 _gnutls_handshake_log ("HSK[%x]: Removing ciphersuite: %s\n", 2925 MHD__gnutls_handshake_log ("HSK[%x]: Removing ciphersuite: %s\n",
2926 session, 2926 session,
2927 mhd_gtls_cipher_suite_get_name (&cs)); 2927 MHD_gtls_cipher_suite_get_name (&cs));
2928 2928
2929 } 2929 }
2930 } 2930 }
2931 2931
2932 gnutls_free (alg); 2932 MHD_gnutls_free (alg);
2933 gnutls_free (*cipherSuites); 2933 MHD_gnutls_free (*cipherSuites);
2934 *cipherSuites = newSuite; 2934 *cipherSuites = newSuite;
2935 2935
2936 ret = newSuiteSize; 2936 ret = newSuiteSize;
@@ -2940,8 +2940,8 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2940} 2940}
2941 2941
2942/** 2942/**
2943 * MHD_gnutls_handshake_set_max_packet_length - This function will set the maximum length of a handshake message 2943 * MHD__gnutls_handshake_set_max_packet_length - This function will set the maximum length of a handshake message
2944 * @session: is a #mhd_gtls_session_t structure. 2944 * @session: is a #MHD_gtls_session_t structure.
2945 * @max: is the maximum number. 2945 * @max: is the maximum number.
2946 * 2946 *
2947 * This function will set the maximum size of a handshake message. 2947 * This function will set the maximum size of a handshake message.
@@ -2951,63 +2951,63 @@ mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session,
2951 * 2951 *
2952 **/ 2952 **/
2953void 2953void
2954MHD_gnutls_handshake_set_max_packet_length (mhd_gtls_session_t session, 2954MHD__gnutls_handshake_set_max_packet_length (MHD_gtls_session_t session,
2955 size_t max) 2955 size_t max)
2956{ 2956{
2957 session->internals.max_handshake_data_buffer_size = max; 2957 session->internals.max_handshake_data_buffer_size = max;
2958} 2958}
2959 2959
2960void 2960void
2961mhd_gtls_set_adv_version (mhd_gtls_session_t session, 2961MHD_gtls_set_adv_version (MHD_gtls_session_t session,
2962 enum MHD_GNUTLS_Protocol ver) 2962 enum MHD_GNUTLS_Protocol ver)
2963{ 2963{
2964 set_adv_version (session, mhd_gtls_version_get_major (ver), 2964 set_adv_version (session, MHD_gtls_version_get_major (ver),
2965 mhd_gtls_version_get_minor (ver)); 2965 MHD_gtls_version_get_minor (ver));
2966} 2966}
2967 2967
2968enum MHD_GNUTLS_Protocol 2968enum MHD_GNUTLS_Protocol
2969mhd_gtls_get_adv_version (mhd_gtls_session_t session) 2969MHD_gtls_get_adv_version (MHD_gtls_session_t session)
2970{ 2970{
2971 return mhd_gtls_version_get (_gnutls_get_adv_version_major (session), 2971 return MHD_gtls_version_get (MHD__gnutls_get_adv_version_major (session),
2972 _gnutls_get_adv_version_minor (session)); 2972 MHD__gnutls_get_adv_version_minor (session));
2973} 2973}
2974 2974
2975/** 2975/**
2976 * MHD_gtls_handshake_get_last_in - Returns the last handshake message received. 2976 * MHD_gtls_handshake_get_last_in - Returns the last handshake message received.
2977 * @session: is a #mhd_gtls_session_t structure. 2977 * @session: is a #MHD_gtls_session_t structure.
2978 * 2978 *
2979 * This function is only useful to check where the last performed 2979 * This function is only useful to check where the last performed
2980 * handshake failed. If the previous handshake succeed or was not 2980 * handshake failed. If the previous handshake succeed or was not
2981 * performed at all then no meaningful value will be returned. 2981 * performed at all then no meaningful value will be returned.
2982 * 2982 *
2983 * Check %gnutls_handshake_description_t in gnutls.h for the 2983 * Check %MHD_gnutls_handshake_description_t in gnutls.h for the
2984 * available handshake descriptions. 2984 * available handshake descriptions.
2985 * 2985 *
2986 * Returns: the last handshake message type received, a 2986 * Returns: the last handshake message type received, a
2987 * %gnutls_handshake_description_t. 2987 * %MHD_gnutls_handshake_description_t.
2988 **/ 2988 **/
2989gnutls_handshake_description_t 2989MHD_gnutls_handshake_description_t
2990MHD_gtls_handshake_get_last_in (mhd_gtls_session_t session) 2990MHD_gtls_handshake_get_last_in (MHD_gtls_session_t session)
2991{ 2991{
2992 return session->internals.last_handshake_in; 2992 return session->internals.last_handshake_in;
2993} 2993}
2994 2994
2995/** 2995/**
2996 * MHD_gtls_handshake_get_last_out - Returns the last handshake message sent. 2996 * MHD_gtls_handshake_get_last_out - Returns the last handshake message sent.
2997 * @session: is a #mhd_gtls_session_t structure. 2997 * @session: is a #MHD_gtls_session_t structure.
2998 * 2998 *
2999 * This function is only useful to check where the last performed 2999 * This function is only useful to check where the last performed
3000 * handshake failed. If the previous handshake succeed or was not 3000 * handshake failed. If the previous handshake succeed or was not
3001 * performed at all then no meaningful value will be returned. 3001 * performed at all then no meaningful value will be returned.
3002 * 3002 *
3003 * Check %gnutls_handshake_description_t in gnutls.h for the 3003 * Check %MHD_gnutls_handshake_description_t in gnutls.h for the
3004 * available handshake descriptions. 3004 * available handshake descriptions.
3005 * 3005 *
3006 * Returns: the last handshake message type sent, a 3006 * Returns: the last handshake message type sent, a
3007 * %gnutls_handshake_description_t. 3007 * %MHD_gnutls_handshake_description_t.
3008 **/ 3008 **/
3009gnutls_handshake_description_t 3009MHD_gnutls_handshake_description_t
3010MHD_gtls_handshake_get_last_out (mhd_gtls_session_t session) 3010MHD_gtls_handshake_get_last_out (MHD_gtls_session_t session)
3011{ 3011{
3012 return session->internals.last_handshake_out; 3012 return session->internals.last_handshake_out;
3013} 3013}
diff --git a/src/daemon/https/tls/gnutls_handshake.h b/src/daemon/https/tls/gnutls_handshake.h
index 7679653f..6514ffc6 100644
--- a/src/daemon/https/tls/gnutls_handshake.h
+++ b/src/daemon/https/tls/gnutls_handshake.h
@@ -25,39 +25,39 @@
25typedef enum Optional 25typedef enum Optional
26{ OPTIONAL_PACKET, MANDATORY_PACKET } Optional; 26{ OPTIONAL_PACKET, MANDATORY_PACKET } Optional;
27 27
28int mhd_gtls_send_handshake (mhd_gtls_session_t session, void *i_data, 28int MHD_gtls_send_handshake (MHD_gtls_session_t session, void *i_data,
29 uint32_t i_datasize, 29 uint32_t i_datasize,
30 gnutls_handshake_description_t type); 30 MHD_gnutls_handshake_description_t type);
31int mhd_gtls_recv_hello_request (mhd_gtls_session_t session, void *data, 31int MHD_gtls_recv_hello_request (MHD_gtls_session_t session, void *data,
32 uint32_t data_size); 32 uint32_t data_size);
33int mhd_gtls_send_hello (mhd_gtls_session_t session, int again); 33int MHD_gtls_send_hello (MHD_gtls_session_t session, int again);
34int mhd_gtls_recv_hello (mhd_gtls_session_t session, opaque * data, 34int MHD_gtls_recv_hello (MHD_gtls_session_t session, opaque * data,
35 int datalen); 35 int datalen);
36int mhd_gtls_recv_handshake (mhd_gtls_session_t session, uint8_t **, int *, 36int MHD_gtls_recv_handshake (MHD_gtls_session_t session, uint8_t **, int *,
37 gnutls_handshake_description_t, 37 MHD_gnutls_handshake_description_t,
38 Optional optional); 38 Optional optional);
39int mhd_gtls_generate_session_id (opaque * session_id, uint8_t * len); 39int MHD_gtls_generate_session_id (opaque * session_id, uint8_t * len);
40int mhd_gtls_handshake_common (mhd_gtls_session_t session); 40int MHD_gtls_handshake_common (MHD_gtls_session_t session);
41int mhd_gtls_handshake_server (mhd_gtls_session_t session); 41int MHD_gtls_handshake_server (MHD_gtls_session_t session);
42void mhd_gtls_set_server_random (mhd_gtls_session_t session, uint8_t * rnd); 42void MHD_gtls_set_server_random (MHD_gtls_session_t session, uint8_t * rnd);
43void mhd_gtls_set_client_random (mhd_gtls_session_t session, uint8_t * rnd); 43void MHD_gtls_set_client_random (MHD_gtls_session_t session, uint8_t * rnd);
44int mhd_gtls_tls_create_random (opaque * dst); 44int MHD_gtls_tls_create_random (opaque * dst);
45int mhd_gtls_remove_unwanted_ciphersuites (mhd_gtls_session_t session, 45int MHD_gtls_remove_unwanted_ciphersuites (MHD_gtls_session_t session,
46 cipher_suite_st ** cipherSuites, 46 cipher_suite_st ** cipherSuites,
47 int numCipherSuites, 47 int numCipherSuites,
48 enum 48 enum
49 MHD_GNUTLS_PublicKeyAlgorithm); 49 MHD_GNUTLS_PublicKeyAlgorithm);
50int mhd_gtls_find_pk_algos_in_ciphersuites (opaque * data, int datalen); 50int MHD_gtls_find_pk_algos_in_ciphersuites (opaque * data, int datalen);
51int mhd_gtls_server_select_suite (mhd_gtls_session_t session, opaque * data, 51int MHD_gtls_server_select_suite (MHD_gtls_session_t session, opaque * data,
52 int datalen); 52 int datalen);
53 53
54int mhd_gtls_negotiate_version (mhd_gtls_session_t session, 54int MHD_gtls_negotiate_version (MHD_gtls_session_t session,
55 enum MHD_GNUTLS_Protocol adv_version); 55 enum MHD_GNUTLS_Protocol adv_version);
56int mhd_gtls_user_hello_func (mhd_gtls_session_t, 56int MHD_gtls_user_hello_func (MHD_gtls_session_t,
57 enum MHD_GNUTLS_Protocol adv_version); 57 enum MHD_GNUTLS_Protocol adv_version);
58 58
59#if MHD_DEBUG_TLS 59#if MHD_DEBUG_TLS
60int mhd_gtls_handshake_client (mhd_gtls_session_t session); 60int MHD_gtls_handshake_client (MHD_gtls_session_t session);
61#endif 61#endif
62 62
63#define STATE session->internals.handshake_state 63#define STATE session->internals.handshake_state
diff --git a/src/daemon/https/tls/gnutls_hash_int.c b/src/daemon/https/tls/gnutls_hash_int.c
index da1880f2..158f0843 100644
--- a/src/daemon/https/tls/gnutls_hash_int.c
+++ b/src/daemon/https/tls/gnutls_hash_int.c
@@ -31,7 +31,7 @@
31#include <gnutls_errors.h> 31#include <gnutls_errors.h>
32 32
33static inline Gc_hash 33static inline Gc_hash
34_gnutls_mac2gc (enum MHD_GNUTLS_HashAlgorithm mac) 34MHD__gnutls_mac2gc (enum MHD_GNUTLS_HashAlgorithm mac)
35{ 35{
36 switch (mac) 36 switch (mac)
37 { 37 {
@@ -48,32 +48,32 @@ _gnutls_mac2gc (enum MHD_GNUTLS_HashAlgorithm mac)
48 return GC_MD5; 48 return GC_MD5;
49 break; 49 break;
50 default: 50 default:
51 gnutls_assert (); 51 MHD_gnutls_assert ();
52 return -1; 52 return -1;
53 } 53 }
54 return -1; 54 return -1;
55} 55}
56 56
57GNUTLS_HASH_HANDLE 57GNUTLS_HASH_HANDLE
58mhd_gtls_hash_init (enum MHD_GNUTLS_HashAlgorithm algorithm) 58MHD_gtls_hash_init (enum MHD_GNUTLS_HashAlgorithm algorithm)
59{ 59{
60 mac_hd_t ret; 60 mac_hd_t ret;
61 int result; 61 int result;
62 62
63 ret = gnutls_malloc (sizeof (mac_hd_st)); 63 ret = MHD_gnutls_malloc (sizeof (mac_hd_st));
64 if (ret == NULL) 64 if (ret == NULL)
65 { 65 {
66 gnutls_assert (); 66 MHD_gnutls_assert ();
67 return GNUTLS_HASH_FAILED; 67 return GNUTLS_HASH_FAILED;
68 } 68 }
69 69
70 ret->algorithm = algorithm; 70 ret->algorithm = algorithm;
71 71
72 result = gc_hash_open (_gnutls_mac2gc (algorithm), 0, &ret->handle); 72 result = MHD_gc_hash_open (MHD__gnutls_mac2gc (algorithm), 0, &ret->handle);
73 if (result) 73 if (result)
74 { 74 {
75 gnutls_assert (); 75 MHD_gnutls_assert ();
76 gnutls_free (ret); 76 MHD_gnutls_free (ret);
77 ret = GNUTLS_HASH_FAILED; 77 ret = GNUTLS_HASH_FAILED;
78 } 78 }
79 79
@@ -81,31 +81,31 @@ mhd_gtls_hash_init (enum MHD_GNUTLS_HashAlgorithm algorithm)
81} 81}
82 82
83int 83int
84mhd_gnutls_hash_get_algo_len (enum MHD_GNUTLS_HashAlgorithm algorithm) 84MHD_gnutls_hash_get_algo_len (enum MHD_GNUTLS_HashAlgorithm algorithm)
85{ 85{
86 int ret; 86 int ret;
87 87
88 ret = gc_hash_digest_length (_gnutls_mac2gc (algorithm)); 88 ret = MHD_gc_hash_digest_length (MHD__gnutls_mac2gc (algorithm));
89 89
90 return ret; 90 return ret;
91 91
92} 92}
93 93
94int 94int
95mhd_gnutls_hash (GNUTLS_HASH_HANDLE handle, const void *text, size_t textlen) 95MHD_gnutls_hash (GNUTLS_HASH_HANDLE handle, const void *text, size_t textlen)
96{ 96{
97 if (textlen > 0) 97 if (textlen > 0)
98 gc_hash_write (handle->handle, textlen, text); 98 MHD_gc_hash_write (handle->handle, textlen, text);
99 return 0; 99 return 0;
100} 100}
101 101
102GNUTLS_HASH_HANDLE 102GNUTLS_HASH_HANDLE
103mhd_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle) 103MHD_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle)
104{ 104{
105 GNUTLS_HASH_HANDLE ret; 105 GNUTLS_HASH_HANDLE ret;
106 int result; 106 int result;
107 107
108 ret = gnutls_malloc (sizeof (mac_hd_st)); 108 ret = MHD_gnutls_malloc (sizeof (mac_hd_st));
109 109
110 if (ret == NULL) 110 if (ret == NULL)
111 return GNUTLS_HASH_FAILED; 111 return GNUTLS_HASH_FAILED;
@@ -114,11 +114,11 @@ mhd_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle)
114 ret->key = NULL; /* it's a hash anyway */ 114 ret->key = NULL; /* it's a hash anyway */
115 ret->keysize = 0; 115 ret->keysize = 0;
116 116
117 result = gc_hash_clone (handle->handle, &ret->handle); 117 result = MHD_gc_hash_clone (handle->handle, &ret->handle);
118 118
119 if (result) 119 if (result)
120 { 120 {
121 gnutls_free (ret); 121 MHD_gnutls_free (ret);
122 return GNUTLS_HASH_FAILED; 122 return GNUTLS_HASH_FAILED;
123 } 123 }
124 124
@@ -126,42 +126,42 @@ mhd_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle)
126} 126}
127 127
128void 128void
129mhd_gnutls_hash_deinit (GNUTLS_HASH_HANDLE handle, void *digest) 129MHD_gnutls_hash_deinit (GNUTLS_HASH_HANDLE handle, void *digest)
130{ 130{
131 const opaque *mac; 131 const opaque *mac;
132 int maclen; 132 int maclen;
133 133
134 maclen = mhd_gnutls_hash_get_algo_len (handle->algorithm); 134 maclen = MHD_gnutls_hash_get_algo_len (handle->algorithm);
135 135
136 mac = gc_hash_read (handle->handle); 136 mac = MHD_gc_hash_read (handle->handle);
137 if (digest != NULL) 137 if (digest != NULL)
138 memcpy (digest, mac, maclen); 138 memcpy (digest, mac, maclen);
139 139
140 gc_hash_close (handle->handle); 140 MHD_gc_hash_close (handle->handle);
141 141
142 gnutls_free (handle); 142 MHD_gnutls_free (handle);
143} 143}
144 144
145 145
146mac_hd_t 146mac_hd_t
147mhd_gtls_hmac_init (enum MHD_GNUTLS_HashAlgorithm algorithm, 147MHD_gtls_MHD_hmac_init (enum MHD_GNUTLS_HashAlgorithm algorithm,
148 const void *key, int keylen) 148 const void *key, int keylen)
149{ 149{
150 mac_hd_t ret; 150 mac_hd_t ret;
151 int result; 151 int result;
152 152
153 ret = gnutls_malloc (sizeof (mac_hd_st)); 153 ret = MHD_gnutls_malloc (sizeof (mac_hd_st));
154 if (ret == NULL) 154 if (ret == NULL)
155 return GNUTLS_MAC_FAILED; 155 return GNUTLS_MAC_FAILED;
156 156
157 result = gc_hash_open (_gnutls_mac2gc (algorithm), GC_HMAC, &ret->handle); 157 result = MHD_gc_hash_open (MHD__gnutls_mac2gc (algorithm), GC_HMAC, &ret->handle);
158 if (result) 158 if (result)
159 { 159 {
160 gnutls_free (ret); 160 MHD_gnutls_free (ret);
161 return GNUTLS_MAC_FAILED; 161 return GNUTLS_MAC_FAILED;
162 } 162 }
163 163
164 gc_hash_hmac_setkey (ret->handle, keylen, key); 164 MHD_gc_hash_MHD_hmac_setkey (ret->handle, keylen, key);
165 165
166 ret->algorithm = algorithm; 166 ret->algorithm = algorithm;
167 ret->key = key; 167 ret->key = key;
@@ -171,21 +171,21 @@ mhd_gtls_hmac_init (enum MHD_GNUTLS_HashAlgorithm algorithm,
171} 171}
172 172
173void 173void
174mhd_gnutls_hmac_deinit (mac_hd_t handle, void *digest) 174MHD_gnutls_MHD_hmac_deinit (mac_hd_t handle, void *digest)
175{ 175{
176 const opaque *mac; 176 const opaque *mac;
177 int maclen; 177 int maclen;
178 178
179 maclen = mhd_gnutls_hash_get_algo_len (handle->algorithm); 179 maclen = MHD_gnutls_hash_get_algo_len (handle->algorithm);
180 180
181 mac = gc_hash_read (handle->handle); 181 mac = MHD_gc_hash_read (handle->handle);
182 182
183 if (digest != NULL) 183 if (digest != NULL)
184 memcpy (digest, mac, maclen); 184 memcpy (digest, mac, maclen);
185 185
186 gc_hash_close (handle->handle); 186 MHD_gc_hash_close (handle->handle);
187 187
188 gnutls_free (handle); 188 MHD_gnutls_free (handle);
189} 189}
190 190
191inline static int 191inline static int
@@ -203,7 +203,7 @@ get_padsize (enum MHD_GNUTLS_HashAlgorithm algorithm)
203} 203}
204 204
205mac_hd_t 205mac_hd_t
206mhd_gnutls_mac_init_ssl3 (enum MHD_GNUTLS_HashAlgorithm algorithm, void *key, 206MHD_gnutls_mac_init_ssl3 (enum MHD_GNUTLS_HashAlgorithm algorithm, void *key,
207 int keylen) 207 int keylen)
208{ 208{
209 mac_hd_t ret; 209 mac_hd_t ret;
@@ -213,28 +213,28 @@ mhd_gnutls_mac_init_ssl3 (enum MHD_GNUTLS_HashAlgorithm algorithm, void *key,
213 padsize = get_padsize (algorithm); 213 padsize = get_padsize (algorithm);
214 if (padsize == 0) 214 if (padsize == 0)
215 { 215 {
216 gnutls_assert (); 216 MHD_gnutls_assert ();
217 return GNUTLS_MAC_FAILED; 217 return GNUTLS_MAC_FAILED;
218 } 218 }
219 219
220 memset (ipad, 0x36, padsize); 220 memset (ipad, 0x36, padsize);
221 221
222 ret = mhd_gtls_hash_init (algorithm); 222 ret = MHD_gtls_hash_init (algorithm);
223 if (ret != GNUTLS_HASH_FAILED) 223 if (ret != GNUTLS_HASH_FAILED)
224 { 224 {
225 ret->key = key; 225 ret->key = key;
226 ret->keysize = keylen; 226 ret->keysize = keylen;
227 227
228 if (keylen > 0) 228 if (keylen > 0)
229 mhd_gnutls_hash (ret, key, keylen); 229 MHD_gnutls_hash (ret, key, keylen);
230 mhd_gnutls_hash (ret, ipad, padsize); 230 MHD_gnutls_hash (ret, ipad, padsize);
231 } 231 }
232 232
233 return ret; 233 return ret;
234} 234}
235 235
236void 236void
237mhd_gnutls_mac_deinit_ssl3 (mac_hd_t handle, void *digest) 237MHD_gnutls_mac_deinit_ssl3 (mac_hd_t handle, void *digest)
238{ 238{
239 opaque ret[MAX_HASH_SIZE]; 239 opaque ret[MAX_HASH_SIZE];
240 mac_hd_t td; 240 mac_hd_t td;
@@ -245,29 +245,29 @@ mhd_gnutls_mac_deinit_ssl3 (mac_hd_t handle, void *digest)
245 padsize = get_padsize (handle->algorithm); 245 padsize = get_padsize (handle->algorithm);
246 if (padsize == 0) 246 if (padsize == 0)
247 { 247 {
248 gnutls_assert (); 248 MHD_gnutls_assert ();
249 return; 249 return;
250 } 250 }
251 251
252 memset (opad, 0x5C, padsize); 252 memset (opad, 0x5C, padsize);
253 253
254 td = mhd_gtls_hash_init (handle->algorithm); 254 td = MHD_gtls_hash_init (handle->algorithm);
255 if (td != GNUTLS_MAC_FAILED) 255 if (td != GNUTLS_MAC_FAILED)
256 { 256 {
257 if (handle->keysize > 0) 257 if (handle->keysize > 0)
258 mhd_gnutls_hash (td, handle->key, handle->keysize); 258 MHD_gnutls_hash (td, handle->key, handle->keysize);
259 259
260 mhd_gnutls_hash (td, opad, padsize); 260 MHD_gnutls_hash (td, opad, padsize);
261 block = mhd_gnutls_hash_get_algo_len (handle->algorithm); 261 block = MHD_gnutls_hash_get_algo_len (handle->algorithm);
262 mhd_gnutls_hash_deinit (handle, ret); /* get the previous hash */ 262 MHD_gnutls_hash_deinit (handle, ret); /* get the previous hash */
263 mhd_gnutls_hash (td, ret, block); 263 MHD_gnutls_hash (td, ret, block);
264 264
265 mhd_gnutls_hash_deinit (td, digest); 265 MHD_gnutls_hash_deinit (td, digest);
266 } 266 }
267} 267}
268 268
269void 269void
270mhd_gnutls_mac_deinit_ssl3_handshake (mac_hd_t handle, 270MHD_gnutls_mac_deinit_ssl3_handshake (mac_hd_t handle,
271 void *digest, opaque * key, 271 void *digest, opaque * key,
272 uint32_t key_size) 272 uint32_t key_size)
273{ 273{
@@ -281,30 +281,30 @@ mhd_gnutls_mac_deinit_ssl3_handshake (mac_hd_t handle,
281 padsize = get_padsize (handle->algorithm); 281 padsize = get_padsize (handle->algorithm);
282 if (padsize == 0) 282 if (padsize == 0)
283 { 283 {
284 gnutls_assert (); 284 MHD_gnutls_assert ();
285 return; 285 return;
286 } 286 }
287 287
288 memset (opad, 0x5C, padsize); 288 memset (opad, 0x5C, padsize);
289 memset (ipad, 0x36, padsize); 289 memset (ipad, 0x36, padsize);
290 290
291 td = mhd_gtls_hash_init (handle->algorithm); 291 td = MHD_gtls_hash_init (handle->algorithm);
292 if (td != GNUTLS_HASH_FAILED) 292 if (td != GNUTLS_HASH_FAILED)
293 { 293 {
294 if (key_size > 0) 294 if (key_size > 0)
295 mhd_gnutls_hash (td, key, key_size); 295 MHD_gnutls_hash (td, key, key_size);
296 296
297 mhd_gnutls_hash (td, opad, padsize); 297 MHD_gnutls_hash (td, opad, padsize);
298 block = mhd_gnutls_hash_get_algo_len (handle->algorithm); 298 block = MHD_gnutls_hash_get_algo_len (handle->algorithm);
299 299
300 if (key_size > 0) 300 if (key_size > 0)
301 mhd_gnutls_hash (handle, key, key_size); 301 MHD_gnutls_hash (handle, key, key_size);
302 mhd_gnutls_hash (handle, ipad, padsize); 302 MHD_gnutls_hash (handle, ipad, padsize);
303 mhd_gnutls_hash_deinit (handle, ret); /* get the previous hash */ 303 MHD_gnutls_hash_deinit (handle, ret); /* get the previous hash */
304 304
305 mhd_gnutls_hash (td, ret, block); 305 MHD_gnutls_hash (td, ret, block);
306 306
307 mhd_gnutls_hash_deinit (td, digest); 307 MHD_gnutls_hash_deinit (td, digest);
308 } 308 }
309} 309}
310 310
@@ -322,18 +322,18 @@ ssl3_sha (int i, opaque * secret, int secret_len,
322 text1[j] = 65 + i; /* A==65 */ 322 text1[j] = 65 + i; /* A==65 */
323 } 323 }
324 324
325 td = mhd_gtls_hash_init (MHD_GNUTLS_MAC_SHA1); 325 td = MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
326 if (td == NULL) 326 if (td == NULL)
327 { 327 {
328 gnutls_assert (); 328 MHD_gnutls_assert ();
329 return GNUTLS_E_HASH_FAILED; 329 return GNUTLS_E_HASH_FAILED;
330 } 330 }
331 331
332 mhd_gnutls_hash (td, text1, i + 1); 332 MHD_gnutls_hash (td, text1, i + 1);
333 mhd_gnutls_hash (td, secret, secret_len); 333 MHD_gnutls_hash (td, secret, secret_len);
334 mhd_gnutls_hash (td, rnd, rnd_len); 334 MHD_gnutls_hash (td, rnd, rnd_len);
335 335
336 mhd_gnutls_hash_deinit (td, digest); 336 MHD_gnutls_hash_deinit (td, digest);
337 return 0; 337 return 0;
338} 338}
339 339
@@ -345,54 +345,54 @@ ssl3_md5 (int i, opaque * secret, int secret_len,
345 mac_hd_t td; 345 mac_hd_t td;
346 int ret; 346 int ret;
347 347
348 td = mhd_gtls_hash_init (MHD_GNUTLS_MAC_MD5); 348 td = MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
349 if (td == NULL) 349 if (td == NULL)
350 { 350 {
351 gnutls_assert (); 351 MHD_gnutls_assert ();
352 return GNUTLS_E_HASH_FAILED; 352 return GNUTLS_E_HASH_FAILED;
353 } 353 }
354 354
355 mhd_gnutls_hash (td, secret, secret_len); 355 MHD_gnutls_hash (td, secret, secret_len);
356 356
357 ret = ssl3_sha (i, secret, secret_len, rnd, rnd_len, tmp); 357 ret = ssl3_sha (i, secret, secret_len, rnd, rnd_len, tmp);
358 if (ret < 0) 358 if (ret < 0)
359 { 359 {
360 gnutls_assert (); 360 MHD_gnutls_assert ();
361 mhd_gnutls_hash_deinit (td, digest); 361 MHD_gnutls_hash_deinit (td, digest);
362 return ret; 362 return ret;
363 } 363 }
364 364
365 mhd_gnutls_hash (td, tmp, 365 MHD_gnutls_hash (td, tmp,
366 mhd_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_SHA1)); 366 MHD_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_SHA1));
367 367
368 mhd_gnutls_hash_deinit (td, digest); 368 MHD_gnutls_hash_deinit (td, digest);
369 return 0; 369 return 0;
370} 370}
371 371
372int 372int
373mhd_gnutls_ssl3_hash_md5 (void *first, int first_len, 373MHD_gnutls_ssl3_hash_md5 (void *first, int first_len,
374 void *second, int second_len, int ret_len, 374 void *second, int second_len, int ret_len,
375 opaque * ret) 375 opaque * ret)
376{ 376{
377 opaque digest[MAX_HASH_SIZE]; 377 opaque digest[MAX_HASH_SIZE];
378 mac_hd_t td; 378 mac_hd_t td;
379 int block = mhd_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_MD5); 379 int block = MHD_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_MD5);
380 380
381 td = mhd_gtls_hash_init (MHD_GNUTLS_MAC_MD5); 381 td = MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
382 if (td == NULL) 382 if (td == NULL)
383 { 383 {
384 gnutls_assert (); 384 MHD_gnutls_assert ();
385 return GNUTLS_E_HASH_FAILED; 385 return GNUTLS_E_HASH_FAILED;
386 } 386 }
387 387
388 mhd_gnutls_hash (td, first, first_len); 388 MHD_gnutls_hash (td, first, first_len);
389 mhd_gnutls_hash (td, second, second_len); 389 MHD_gnutls_hash (td, second, second_len);
390 390
391 mhd_gnutls_hash_deinit (td, digest); 391 MHD_gnutls_hash_deinit (td, digest);
392 392
393 if (ret_len > block) 393 if (ret_len > block)
394 { 394 {
395 gnutls_assert (); 395 MHD_gnutls_assert ();
396 return GNUTLS_E_INTERNAL_ERROR; 396 return GNUTLS_E_INTERNAL_ERROR;
397 } 397 }
398 398
@@ -403,13 +403,13 @@ mhd_gnutls_ssl3_hash_md5 (void *first, int first_len,
403} 403}
404 404
405int 405int
406mhd_gnutls_ssl3_generate_random (void *secret, int secret_len, 406MHD_gnutls_ssl3_generate_random (void *secret, int secret_len,
407 void *rnd, int rnd_len, 407 void *rnd, int rnd_len,
408 int ret_bytes, opaque * ret) 408 int ret_bytes, opaque * ret)
409{ 409{
410 int i = 0, copy, output_bytes; 410 int i = 0, copy, output_bytes;
411 opaque digest[MAX_HASH_SIZE]; 411 opaque digest[MAX_HASH_SIZE];
412 int block = mhd_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_MD5); 412 int block = MHD_gnutls_hash_get_algo_len (MHD_GNUTLS_MAC_MD5);
413 int result, times; 413 int result, times;
414 414
415 output_bytes = 0; 415 output_bytes = 0;
@@ -427,7 +427,7 @@ mhd_gnutls_ssl3_generate_random (void *secret, int secret_len,
427 result = ssl3_md5 (i, secret, secret_len, rnd, rnd_len, digest); 427 result = ssl3_md5 (i, secret, secret_len, rnd, rnd_len, digest);
428 if (result < 0) 428 if (result < 0)
429 { 429 {
430 gnutls_assert (); 430 MHD_gnutls_assert ();
431 return result; 431 return result;
432 } 432 }
433 433
diff --git a/src/daemon/https/tls/gnutls_hash_int.h b/src/daemon/https/tls/gnutls_hash_int.h
index 7cd33a03..72f805ee 100644
--- a/src/daemon/https/tls/gnutls_hash_int.h
+++ b/src/daemon/https/tls/gnutls_hash_int.h
@@ -31,7 +31,7 @@
31 31
32typedef struct 32typedef struct
33{ 33{
34 gc_hash_handle handle; 34 MHD_gc_hash_handle handle;
35 enum MHD_GNUTLS_HashAlgorithm algorithm; 35 enum MHD_GNUTLS_HashAlgorithm algorithm;
36 const void *key; 36 const void *key;
37 int keysize; 37 int keysize;
@@ -42,31 +42,31 @@ typedef mac_hd_t GNUTLS_HASH_HANDLE;
42#define GNUTLS_HASH_FAILED NULL 42#define GNUTLS_HASH_FAILED NULL
43#define GNUTLS_MAC_FAILED NULL 43#define GNUTLS_MAC_FAILED NULL
44 44
45mac_hd_t mhd_gtls_hmac_init (enum MHD_GNUTLS_HashAlgorithm algorithm, 45mac_hd_t MHD_gtls_MHD_hmac_init (enum MHD_GNUTLS_HashAlgorithm algorithm,
46 const void *key, int keylen); 46 const void *key, int keylen);
47 47
48void mhd_gnutls_hmac_deinit (mac_hd_t handle, void *digest); 48void MHD_gnutls_MHD_hmac_deinit (mac_hd_t handle, void *digest);
49 49
50mac_hd_t mhd_gnutls_mac_init_ssl3 (enum MHD_GNUTLS_HashAlgorithm algorithm, 50mac_hd_t MHD_gnutls_mac_init_ssl3 (enum MHD_GNUTLS_HashAlgorithm algorithm,
51 void *key, int keylen); 51 void *key, int keylen);
52void mhd_gnutls_mac_deinit_ssl3 (mac_hd_t handle, void *digest); 52void MHD_gnutls_mac_deinit_ssl3 (mac_hd_t handle, void *digest);
53 53
54GNUTLS_HASH_HANDLE mhd_gtls_hash_init (enum MHD_GNUTLS_HashAlgorithm 54GNUTLS_HASH_HANDLE MHD_gtls_hash_init (enum MHD_GNUTLS_HashAlgorithm
55 algorithm); 55 algorithm);
56int mhd_gnutls_hash_get_algo_len (enum MHD_GNUTLS_HashAlgorithm algorithm); 56int MHD_gnutls_hash_get_algo_len (enum MHD_GNUTLS_HashAlgorithm algorithm);
57int mhd_gnutls_hash (GNUTLS_HASH_HANDLE handle, const void *text, 57int MHD_gnutls_hash (GNUTLS_HASH_HANDLE handle, const void *text,
58 size_t textlen); 58 size_t textlen);
59void mhd_gnutls_hash_deinit (GNUTLS_HASH_HANDLE handle, void *digest); 59void MHD_gnutls_hash_deinit (GNUTLS_HASH_HANDLE handle, void *digest);
60 60
61int mhd_gnutls_ssl3_generate_random (void *secret, int secret_len, 61int MHD_gnutls_ssl3_generate_random (void *secret, int secret_len,
62 void *rnd, int random_len, int bytes, 62 void *rnd, int random_len, int bytes,
63 opaque * ret); 63 opaque * ret);
64int mhd_gnutls_ssl3_hash_md5 (void *first, int first_len, void *second, 64int MHD_gnutls_ssl3_hash_md5 (void *first, int first_len, void *second,
65 int second_len, int ret_len, opaque * ret); 65 int second_len, int ret_len, opaque * ret);
66 66
67void mhd_gnutls_mac_deinit_ssl3_handshake (mac_hd_t handle, void *digest, 67void MHD_gnutls_mac_deinit_ssl3_handshake (mac_hd_t handle, void *digest,
68 opaque * key, uint32_t key_size); 68 opaque * key, uint32_t key_size);
69 69
70GNUTLS_HASH_HANDLE mhd_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle); 70GNUTLS_HASH_HANDLE MHD_gnutls_hash_copy (GNUTLS_HASH_HANDLE handle);
71 71
72#endif /* GNUTLS_HASH_INT_H */ 72#endif /* GNUTLS_HASH_INT_H */
diff --git a/src/daemon/https/tls/gnutls_int.h b/src/daemon/https/tls/gnutls_int.h
index 2ef52933..af2b4499 100644
--- a/src/daemon/https/tls/gnutls_int.h
+++ b/src/daemon/https/tls/gnutls_int.h
@@ -92,9 +92,9 @@
92#define DEFAULT_VERIFY_DEPTH 32 92#define DEFAULT_VERIFY_DEPTH 32
93#define DEFAULT_VERIFY_BITS 16*1024 93#define DEFAULT_VERIFY_BITS 16*1024
94 94
95#define DECR_LEN(len, x) do { len-=x; if (len<0) {gnutls_assert(); return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;} } while (0) 95#define DECR_LEN(len, x) do { len-=x; if (len<0) {MHD_gnutls_assert(); return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;} } while (0)
96#define DECR_LENGTH_RET(len, x, RET) do { len-=x; if (len<0) {gnutls_assert(); return RET;} } while (0) 96#define DECR_LENGTH_RET(len, x, RET) do { len-=x; if (len<0) {MHD_gnutls_assert(); return RET;} } while (0)
97#define DECR_LENGTH_COM(len, x, COM) do { len-=x; if (len<0) {gnutls_assert(); COM;} } while (0) 97#define DECR_LENGTH_COM(len, x, COM) do { len-=x; if (len<0) {MHD_gnutls_assert(); COM;} } while (0)
98 98
99#define HASH2MAC(x) ((enum MHD_GNUTLS_HashAlgorithm)x) 99#define HASH2MAC(x) ((enum MHD_GNUTLS_HashAlgorithm)x)
100 100
@@ -129,11 +129,11 @@ typedef enum handshake_state_t
129 129
130#include <gnutls_str.h> 130#include <gnutls_str.h>
131 131
132typedef mhd_gtls_string mhd_gtls_buffer; 132typedef MHD_gtls_string MHD_gtls_buffer;
133 133
134#define mhd_gtls_buffer_init(buf) mhd_gtls_string_init(buf, gnutls_malloc, gnutls_realloc, gnutls_free); 134#define MHD_gtls_buffer_init(buf) MHD_gtls_string_init(buf, MHD_gnutls_malloc, MHD_gnutls_realloc, MHD_gnutls_free);
135#define mhd_gtls_buffer_clear mhd_gtls_string_clear 135#define MHD_gtls_buffer_clear MHD_gtls_string_clear
136#define mhd_gtls_buffer_append mhd_gtls_string_append_data 136#define MHD_gtls_buffer_append MHD_gtls_string_append_data
137 137
138/* This is the maximum number of algorithms (ciphers or macs etc). 138/* This is the maximum number of algorithms (ciphers or macs etc).
139 * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h 139 * keep it synced with GNUTLS_MAX_ALGORITHM_NUM in gnutls.h
@@ -179,20 +179,20 @@ typedef enum content_type_t
179typedef void (*LOG_FUNC) (int, const char *); 179typedef void (*LOG_FUNC) (int, const char *);
180 180
181/* Store & Retrieve functions defines: */ 181/* Store & Retrieve functions defines: */
182typedef struct mhd_gtls_auth_cred_st 182typedef struct MHD_gtls_auth_cred_st
183{ 183{
184 enum MHD_GNUTLS_CredentialsType algorithm; 184 enum MHD_GNUTLS_CredentialsType algorithm;
185 185
186 /* the type of credentials depends on algorithm 186 /* the type of credentials depends on algorithm
187 */ 187 */
188 void *credentials; 188 void *credentials;
189 struct mhd_gtls_auth_cred_st *next; 189 struct MHD_gtls_auth_cred_st *next;
190} auth_cred_st; 190} auth_cred_st;
191 191
192struct mhd_gtls_key 192struct MHD_gtls_key
193{ 193{
194 /* For DH KX */ 194 /* For DH KX */
195 gnutls_datum_t key; 195 MHD_gnutls_datum_t key;
196 mpi_t KEY; 196 mpi_t KEY;
197 mpi_t client_Y; 197 mpi_t client_Y;
198 mpi_t client_g; 198 mpi_t client_g;
@@ -212,7 +212,7 @@ struct mhd_gtls_key
212 /* this is used to hold the peers authentication data 212 /* this is used to hold the peers authentication data
213 */ 213 */
214 /* auth_info_t structures SHOULD NOT contain malloced 214 /* auth_info_t structures SHOULD NOT contain malloced
215 * elements. Check gnutls_session_pack.c, and gnutls_auth.c. 215 * elements. Check MHD_gnutls_session_pack.c, and MHD_gnutls_auth.c.
216 * Rememember that this should be calloced! 216 * Rememember that this should be calloced!
217 */ 217 */
218 void *auth_info; 218 void *auth_info;
@@ -233,7 +233,7 @@ struct mhd_gtls_key
233 * for a client certificate verify 233 * for a client certificate verify
234 */ 234 */
235}; 235};
236typedef struct mhd_gtls_key *mhd_gtls_key_st; 236typedef struct MHD_gtls_key *MHD_gtls_key_st;
237 237
238/* STATE (cont) */ 238/* STATE (cont) */
239#include <gnutls_hash_int.h> 239#include <gnutls_hash_int.h>
@@ -254,7 +254,7 @@ typedef struct
254{ 254{
255 opaque name[MAX_SERVER_NAME_SIZE]; 255 opaque name[MAX_SERVER_NAME_SIZE];
256 unsigned name_length; 256 unsigned name_length;
257 gnutls_server_name_type_t type; 257 MHD_gnutls_server_name_type_t type;
258} server_name_st; 258} server_name_st;
259 259
260#define MAX_SERVER_NAME_EXTENSIONS 3 260#define MAX_SERVER_NAME_EXTENSIONS 3
@@ -267,20 +267,20 @@ typedef struct
267 opaque srp_username[MAX_SRP_USERNAME + 1]; 267 opaque srp_username[MAX_SRP_USERNAME + 1];
268 268
269 /* TLS/IA data. */ 269 /* TLS/IA data. */
270 int gnutls_ia_enable, gnutls_ia_peer_enable; 270 int MHD_gnutls_ia_enable, MHD_gnutls_ia_peer_enable;
271 int gnutls_ia_allowskip, gnutls_ia_peer_allowskip; 271 int MHD_gnutls_ia_allowskip, MHD_gnutls_ia_peer_allowskip;
272 272
273 /* Used by extensions that enable supplemental data. */ 273 /* Used by extensions that enable supplemental data. */
274 int do_recv_supplemental, do_send_supplemental; 274 int do_recv_supplemental, do_send_supplemental;
275 275
276 /* Opaque PRF input. */ 276 /* Opaque PRF input. */
277 gnutls_oprfi_callback_func oprfi_cb; 277 MHD_gnutls_oprfi_callback_func oprfi_cb;
278 void *oprfi_userdata; 278 void *oprfi_userdata;
279 opaque *oprfi_client; 279 opaque *oprfi_client;
280 uint16_t oprfi_client_len; 280 uint16_t oprfi_client_len;
281 opaque *oprfi_server; 281 opaque *oprfi_server;
282 uint16_t oprfi_server_len; 282 uint16_t oprfi_server_len;
283} mhd_gtls_ext_st; 283} MHD_gtls_ext_st;
284 284
285/* This flag indicates for an extension whether 285/* This flag indicates for an extension whether
286 * it is useful to application level or TLS level only. 286 * it is useful to application level or TLS level only.
@@ -292,7 +292,7 @@ typedef enum tls_ext_parse_type_t
292 EXTENSION_ANY, 292 EXTENSION_ANY,
293 EXTENSION_APPLICATION, 293 EXTENSION_APPLICATION,
294 EXTENSION_TLS 294 EXTENSION_TLS
295} mhd_gtls_ext_parse_type_t; 295} MHD_gtls_ext_parse_type_t;
296 296
297/* auth_info_t structures now MAY contain malloced 297/* auth_info_t structures now MAY contain malloced
298 * elements. 298 * elements.
@@ -305,7 +305,7 @@ typedef enum tls_ext_parse_type_t
305 */ 305 */
306 306
307/* if you add anything in Security_Parameters struct, then 307/* if you add anything in Security_Parameters struct, then
308 * also modify CPY_COMMON in gnutls_constate.c 308 * also modify CPY_COMMON in MHD_gnutls_constate.c
309 */ 309 */
310 310
311/* Note that the security parameters structure is set up after the 311/* Note that the security parameters structure is set up after the
@@ -314,7 +314,7 @@ typedef enum tls_ext_parse_type_t
314 */ 314 */
315typedef struct 315typedef struct
316{ 316{
317 gnutls_connection_end_t entity; 317 MHD_gnutls_connection_end_t entity;
318 enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm; 318 enum MHD_GNUTLS_KeyExchangeAlgorithm kx_algorithm;
319 /* we've got separate write/read bulk/macs because 319 /* we've got separate write/read bulk/macs because
320 * there is a time in handshake where the peer has 320 * there is a time in handshake where the peer has
@@ -339,7 +339,7 @@ typedef struct
339 opaque session_id[TLS_MAX_SESSION_ID_SIZE]; 339 opaque session_id[TLS_MAX_SESSION_ID_SIZE];
340 uint8_t session_id_size; 340 uint8_t session_id_size;
341 time_t timestamp; 341 time_t timestamp;
342 mhd_gtls_ext_st extensions; 342 MHD_gtls_ext_st extensions;
343 343
344 /* The send size is the one requested by the programmer. 344 /* The send size is the one requested by the programmer.
345 * The recv size is the one negotiated with the peer. 345 * The recv size is the one negotiated with the peer.
@@ -351,23 +351,23 @@ typedef struct
351 enum MHD_GNUTLS_Protocol version; /* moved here */ 351 enum MHD_GNUTLS_Protocol version; /* moved here */
352 /* For TLS/IA. XXX: Move to IA credential? */ 352 /* For TLS/IA. XXX: Move to IA credential? */
353 opaque inner_secret[TLS_MASTER_SIZE]; 353 opaque inner_secret[TLS_MASTER_SIZE];
354} mhd_gtls_security_param_st; 354} MHD_gtls_security_param_st;
355 355
356/* This structure holds the generated keys 356/* This structure holds the generated keys
357 */ 357 */
358typedef struct 358typedef struct
359{ 359{
360 gnutls_datum_t server_write_mac_secret; 360 MHD_gnutls_datum_t server_write_mac_secret;
361 gnutls_datum_t client_write_mac_secret; 361 MHD_gnutls_datum_t client_write_mac_secret;
362 gnutls_datum_t server_write_IV; 362 MHD_gnutls_datum_t server_write_IV;
363 gnutls_datum_t client_write_IV; 363 MHD_gnutls_datum_t client_write_IV;
364 gnutls_datum_t server_write_key; 364 MHD_gnutls_datum_t server_write_key;
365 gnutls_datum_t client_write_key; 365 MHD_gnutls_datum_t client_write_key;
366 int generated_keys; /* zero if keys have not 366 int generated_keys; /* zero if keys have not
367 * been generated. Non zero 367 * been generated. Non zero
368 * otherwise. 368 * otherwise.
369 */ 369 */
370} mhd_gtls_cipher_specs_st; 370} MHD_gtls_cipher_specs_st;
371 371
372typedef struct 372typedef struct
373{ 373{
@@ -375,29 +375,29 @@ typedef struct
375 cipher_hd_t read_cipher_state; 375 cipher_hd_t read_cipher_state;
376 comp_hd_t read_compression_state; 376 comp_hd_t read_compression_state;
377 comp_hd_t write_compression_state; 377 comp_hd_t write_compression_state;
378 gnutls_datum_t read_mac_secret; 378 MHD_gnutls_datum_t read_mac_secret;
379 gnutls_datum_t write_mac_secret; 379 MHD_gnutls_datum_t write_mac_secret;
380 uint64 read_sequence_number; 380 uint64 read_sequence_number;
381 uint64 write_sequence_number; 381 uint64 write_sequence_number;
382} mhd_gtls_conn_stat_st; 382} MHD_gtls_conn_stat_st;
383 383
384typedef struct 384typedef struct
385{ 385{
386 unsigned int priority[MAX_ALGOS]; 386 unsigned int priority[MAX_ALGOS];
387 unsigned int num_algorithms; 387 unsigned int num_algorithms;
388} mhd_gtls_priority_st; 388} MHD_gtls_priority_st;
389 389
390/* For the external api */ 390/* For the external api */
391struct MHD_gtls_priority_st 391struct MHD_gtls_priority_st
392{ 392{
393 mhd_gtls_priority_st cipher; 393 MHD_gtls_priority_st cipher;
394 mhd_gtls_priority_st mac; 394 MHD_gtls_priority_st mac;
395 mhd_gtls_priority_st kx; 395 MHD_gtls_priority_st kx;
396 mhd_gtls_priority_st compression; 396 MHD_gtls_priority_st compression;
397 mhd_gtls_priority_st protocol; 397 MHD_gtls_priority_st protocol;
398 398
399 /* certificate type : x509, OpenPGP, etc. */ 399 /* certificate type : x509, OpenPGP, etc. */
400 mhd_gtls_priority_st cert_type; 400 MHD_gtls_priority_st cert_type;
401 401
402 /* to disable record padding */ 402 /* to disable record padding */
403 int no_padding; 403 int no_padding;
@@ -410,15 +410,15 @@ typedef struct MHD_gtls_dh_params_int
410 /* [0] is the prime, [1] is the generator. 410 /* [0] is the prime, [1] is the generator.
411 */ 411 */
412 mpi_t params[2]; 412 mpi_t params[2];
413} mhd_gtls_dh_params_st; 413} MHD_gtls_dh_params_st;
414 414
415typedef struct 415typedef struct
416{ 416{
417 mhd_gtls_dh_params_t dh_params; 417 MHD_gtls_dh_params_t dh_params;
418 int free_dh_params; 418 int free_dh_params;
419 mhd_gtls_rsa_params_t rsa_params; 419 MHD_gtls_rsa_params_t rsa_params;
420 int free_rsa_params; 420 int free_rsa_params;
421} mhd_gtls_internal_params_st; 421} MHD_gtls_internal_params_st;
422 422
423typedef struct 423typedef struct
424{ 424{
@@ -427,19 +427,19 @@ typedef struct
427 size_t header_size; 427 size_t header_size;
428 /* this holds the length of the handshake packet */ 428 /* this holds the length of the handshake packet */
429 size_t packet_length; 429 size_t packet_length;
430 gnutls_handshake_description_t recv_type; 430 MHD_gnutls_handshake_description_t recv_type;
431} mhd_gtls_handshake_header_buffer_st; 431} MHD_gtls_handshake_header_buffer_st;
432 432
433typedef struct 433typedef struct
434{ 434{
435 mhd_gtls_buffer application_data_buffer; /* holds data to be delivered to application layer */ 435 MHD_gtls_buffer application_data_buffer; /* holds data to be delivered to application layer */
436 mhd_gtls_buffer handshake_hash_buffer; /* used to keep the last received handshake 436 MHD_gtls_buffer handshake_hash_buffer; /* used to keep the last received handshake
437 * message */ 437 * message */
438 mac_hd_t handshake_mac_handle_sha; /* hash of the handshake messages */ 438 mac_hd_t handshake_mac_handle_sha; /* hash of the handshake messages */
439 mac_hd_t handshake_mac_handle_md5; /* hash of the handshake messages */ 439 mac_hd_t handshake_mac_handle_md5; /* hash of the handshake messages */
440 440
441 mhd_gtls_buffer handshake_data_buffer; /* this is a buffer that holds the current handshake message */ 441 MHD_gtls_buffer handshake_data_buffer; /* this is a buffer that holds the current handshake message */
442 mhd_gtls_buffer ia_data_buffer; /* holds inner application data (TLS/IA) */ 442 MHD_gtls_buffer ia_data_buffer; /* holds inner application data (TLS/IA) */
443 resumable_session_t resumable; /* TRUE or FALSE - if we can resume that session */ 443 resumable_session_t resumable; /* TRUE or FALSE - if we can resume that session */
444 handshake_state_t handshake_state; /* holds 444 handshake_state_t handshake_state; /* holds
445 * a number which indicates where 445 * a number which indicates where
@@ -471,28 +471,28 @@ typedef struct
471 471
472 /* resumed session */ 472 /* resumed session */
473 resumable_session_t resumed; /* RESUME_TRUE or FALSE - if we are resuming a session */ 473 resumable_session_t resumed; /* RESUME_TRUE or FALSE - if we are resuming a session */
474 mhd_gtls_security_param_st resumed_security_parameters; 474 MHD_gtls_security_param_st resumed_security_parameters;
475 475
476 /* sockets internals */ 476 /* sockets internals */
477 int lowat; 477 int lowat;
478 478
479 /* These buffers are used in the handshake 479 /* These buffers are used in the handshake
480 * protocol only. freed using _gnutls_handshake_io_buffer_clear(); 480 * protocol only. freed using MHD__gnutls_handshake_io_buffer_clear();
481 */ 481 */
482 mhd_gtls_buffer handshake_send_buffer; 482 MHD_gtls_buffer handshake_send_buffer;
483 size_t handshake_send_buffer_prev_size; 483 size_t handshake_send_buffer_prev_size;
484 content_type_t handshake_send_buffer_type; 484 content_type_t handshake_send_buffer_type;
485 gnutls_handshake_description_t handshake_send_buffer_htype; 485 MHD_gnutls_handshake_description_t handshake_send_buffer_htype;
486 content_type_t handshake_recv_buffer_type; 486 content_type_t handshake_recv_buffer_type;
487 gnutls_handshake_description_t handshake_recv_buffer_htype; 487 MHD_gnutls_handshake_description_t handshake_recv_buffer_htype;
488 mhd_gtls_buffer handshake_recv_buffer; 488 MHD_gtls_buffer handshake_recv_buffer;
489 489
490 /* this buffer holds a record packet -mostly used for 490 /* this buffer holds a record packet -mostly used for
491 * non blocking IO. 491 * non blocking IO.
492 */ 492 */
493 mhd_gtls_buffer record_recv_buffer; 493 MHD_gtls_buffer record_recv_buffer;
494 mhd_gtls_buffer record_send_buffer; /* holds cached data 494 MHD_gtls_buffer record_send_buffer; /* holds cached data
495 * for the gnutls_io_write_buffered() 495 * for the MHD_gnutls_io_write_buffered()
496 * function. 496 * function.
497 */ 497 */
498 size_t record_send_buffer_prev_size; /* holds the 498 size_t record_send_buffer_prev_size; /* holds the
@@ -508,7 +508,7 @@ typedef struct
508 int have_peeked_data; 508 int have_peeked_data;
509 509
510 int expire_time; /* after expire_time seconds this session will expire */ 510 int expire_time; /* after expire_time seconds this session will expire */
511 struct mhd_gtls_mod_auth_st_int *auth_struct; /* used in handshake packets and KX algorithms */ 511 struct MHD_gtls_mod_auth_st_int *auth_struct; /* used in handshake packets and KX algorithms */
512 512
513 /* TODO rm */ 513 /* TODO rm */
514 int v2_hello; /* 0 if the client hello is v3+. 514 int v2_hello; /* 0 if the client hello is v3+.
@@ -516,7 +516,7 @@ typedef struct
516 */ 516 */
517 /* keeps the headers of the handshake packet 517 /* keeps the headers of the handshake packet
518 */ 518 */
519 mhd_gtls_handshake_header_buffer_st handshake_header_buffer; 519 MHD_gtls_handshake_header_buffer_st handshake_header_buffer;
520 520
521 /* this is the highest version available 521 /* this is the highest version available
522 * to the peer. (advertized version). 522 * to the peer. (advertized version).
@@ -533,7 +533,7 @@ typedef struct
533 int send_cert_req; 533 int send_cert_req;
534 534
535 /* bits to use for DHE and DHA 535 /* bits to use for DHE and DHA
536 * use _gnutls_dh_get_prime_bits() and MHD_gnutls_dh_set_prime_bits() 536 * use MHD__gnutls_dh_get_prime_bits() and MHD__gnutls_dh_set_prime_bits()
537 * to access it. 537 * to access it.
538 */ 538 */
539 uint16_t dh_prime_bits; 539 uint16_t dh_prime_bits;
@@ -542,17 +542,17 @@ typedef struct
542 542
543 /* PUSH & PULL functions. 543 /* PUSH & PULL functions.
544 */ 544 */
545 mhd_gtls_pull_func _gnutls_pull_func; 545 MHD_gtls_pull_func MHD__gnutls_pull_func;
546 mhd_gtls_push_func _gnutls_push_func; 546 MHD_gtls_push_func MHD__gnutls_push_func;
547 /* Holds the first argument of PUSH and PULL 547 /* Holds the first argument of PUSH and PULL
548 * functions; 548 * functions;
549 */ 549 */
550 gnutls_transport_ptr_t transport_recv_ptr; 550 MHD_gnutls_transport_ptr_t transport_recv_ptr;
551 gnutls_transport_ptr_t transport_send_ptr; 551 MHD_gnutls_transport_ptr_t transport_send_ptr;
552 552
553 /* post client hello callback (server side only) 553 /* post client hello callback (server side only)
554 */ 554 */
555 gnutls_handshake_post_client_hello_func user_hello_func; 555 MHD_gnutls_handshake_post_client_hello_func user_hello_func;
556 556
557 /* Holds the record size requested by the 557 /* Holds the record size requested by the
558 * user. 558 * user.
@@ -560,12 +560,12 @@ typedef struct
560 uint16_t proposed_record_size; 560 uint16_t proposed_record_size;
561 561
562 /* holds the selected certificate and key. 562 /* holds the selected certificate and key.
563 * use mhd_gtls_selected_certs_deinit() and mhd_gtls_selected_certs_set() 563 * use MHD_gtls_selected_certs_deinit() and MHD_gtls_selected_certs_set()
564 * to change them. 564 * to change them.
565 */ 565 */
566 gnutls_cert *selected_cert_list; 566 MHD_gnutls_cert *selected_cert_list;
567 int selected_cert_list_length; 567 int selected_cert_list_length;
568 gnutls_privkey *selected_key; 568 MHD_gnutls_privkey *selected_key;
569 int selected_need_free; 569 int selected_need_free;
570 570
571 /* holds the extensions we sent to the peer 571 /* holds the extensions we sent to the peer
@@ -615,16 +615,16 @@ typedef struct
615 * credentials structure, or from a callback. That is to 615 * credentials structure, or from a callback. That is to
616 * minimize external calls. 616 * minimize external calls.
617 */ 617 */
618 mhd_gtls_internal_params_st params; 618 MHD_gtls_internal_params_st params;
619 619
620 /* This buffer is used by the record recv functions, 620 /* This buffer is used by the record recv functions,
621 * as a temporary store buffer. 621 * as a temporary store buffer.
622 */ 622 */
623 gnutls_datum_t recv_buffer; 623 MHD_gnutls_datum_t recv_buffer;
624 624
625 /* To avoid using global variables, and especially on Windows where 625 /* To avoid using global variables, and especially on Windows where
626 * the application may use a different errno variable than GnuTLS, 626 * the application may use a different errno variable than GnuTLS,
627 * it is possible to use MHD_gnutls_transport_set_errno to set a 627 * it is possible to use MHD__gnutls_transport_set_errno to set a
628 * session-specific errno variable in the user-replaceable push/pull 628 * session-specific errno variable in the user-replaceable push/pull
629 * functions. This value is used by the send/recv functions. (The 629 * functions. This value is used by the send/recv functions. (The
630 * strange name of this variable is because 'errno' is typically 630 * strange name of this variable is because 'errno' is typically
@@ -633,44 +633,44 @@ typedef struct
633 int errnum; 633 int errnum;
634 634
635 /* Function used to perform public-key signing operation during 635 /* Function used to perform public-key signing operation during
636 handshake. Used by gnutls_sig.c:_gnutls_tls_sign(), see also 636 handshake. Used by MHD_gnutls_sig.c:MHD__gnutls_tls_sign(), see also
637 MHD_gtls_sign_callback_set(). */ 637 MHD_gtls_sign_callback_set(). */
638 gnutls_sign_func sign_func; 638 MHD_gnutls_sign_func sign_func;
639 void *sign_func_userdata; 639 void *sign_func_userdata;
640 640
641 /* If you add anything here, check mhd_gtls_handshake_internal_state_clear(). 641 /* If you add anything here, check MHD_gtls_handshake_internal_state_clear().
642 */ 642 */
643} mhd_gtls_internals_st; 643} MHD_gtls_internals_st;
644 644
645struct MHD_gtls_session_int 645struct MHD_gtls_session_int
646{ 646{
647 mhd_gtls_security_param_st security_parameters; 647 MHD_gtls_security_param_st security_parameters;
648 mhd_gtls_cipher_specs_st cipher_specs; 648 MHD_gtls_cipher_specs_st cipher_specs;
649 mhd_gtls_conn_stat_st connection_state; 649 MHD_gtls_conn_stat_st connection_state;
650 mhd_gtls_internals_st internals; 650 MHD_gtls_internals_st internals;
651 mhd_gtls_key_st key; 651 MHD_gtls_key_st key;
652}; 652};
653 653
654/* functions */ 654/* functions */
655void mhd_gtls_set_current_version (mhd_gtls_session_t session, 655void MHD_gtls_set_current_version (MHD_gtls_session_t session,
656 enum MHD_GNUTLS_Protocol version); 656 enum MHD_GNUTLS_Protocol version);
657 657
658void mhd_gtls_free_auth_info (mhd_gtls_session_t session); 658void MHD_gtls_free_auth_info (MHD_gtls_session_t session);
659 659
660/* These two macros return the advertized TLS version of 660/* These two macros return the advertized TLS version of
661 * the peer. 661 * the peer.
662 */ 662 */
663#define _gnutls_get_adv_version_major( session) \ 663#define MHD__gnutls_get_adv_version_major( session) \
664 session->internals.adv_version_major 664 session->internals.adv_version_major
665 665
666#define _gnutls_get_adv_version_minor( session) \ 666#define MHD__gnutls_get_adv_version_minor( session) \
667 session->internals.adv_version_minor 667 session->internals.adv_version_minor
668 668
669#define set_adv_version( session, major, minor) \ 669#define set_adv_version( session, major, minor) \
670 session->internals.adv_version_major = major; \ 670 session->internals.adv_version_major = major; \
671 session->internals.adv_version_minor = minor 671 session->internals.adv_version_minor = minor
672 672
673void mhd_gtls_set_adv_version (mhd_gtls_session_t, enum MHD_GNUTLS_Protocol); 673void MHD_gtls_set_adv_version (MHD_gtls_session_t, enum MHD_GNUTLS_Protocol);
674enum MHD_GNUTLS_Protocol mhd_gtls_get_adv_version (mhd_gtls_session_t); 674enum MHD_GNUTLS_Protocol MHD_gtls_get_adv_version (MHD_gtls_session_t);
675 675
676#endif /* GNUTLS_INT_H */ 676#endif /* GNUTLS_INT_H */
diff --git a/src/daemon/https/tls/gnutls_kx.c b/src/daemon/https/tls/gnutls_kx.c
index 45717b4f..5f0966f8 100644
--- a/src/daemon/https/tls/gnutls_kx.c
+++ b/src/daemon/https/tls/gnutls_kx.c
@@ -23,7 +23,7 @@
23 */ 23 */
24 24
25/* This file contains functions which are wrappers for the key exchange 25/* This file contains functions which are wrappers for the key exchange
26 * part of TLS. They are called by the handshake functions (MHD_gnutls_handshake) 26 * part of TLS. They are called by the handshake functions (MHD__gnutls_handshake)
27 */ 27 */
28 28
29#include "gnutls_int.h" 29#include "gnutls_int.h"
@@ -42,10 +42,10 @@
42 */ 42 */
43 43
44#define MASTER_SECRET "master secret" 44#define MASTER_SECRET "master secret"
45static int generate_normal_master (mhd_gtls_session_t session, int); 45static int generate_normal_master (MHD_gtls_session_t session, int);
46 46
47int 47int
48mhd_gtls_generate_master (mhd_gtls_session_t session, int keep_premaster) 48MHD_gtls_generate_master (MHD_gtls_session_t session, int keep_premaster)
49{ 49{
50 if (session->internals.resumed == RESUME_FALSE) 50 if (session->internals.resumed == RESUME_FALSE)
51 return generate_normal_master (session, keep_premaster); 51 return generate_normal_master (session, keep_premaster);
@@ -56,22 +56,22 @@ mhd_gtls_generate_master (mhd_gtls_session_t session, int keep_premaster)
56 */ 56 */
57#define PREMASTER session->key->key 57#define PREMASTER session->key->key
58static int 58static int
59generate_normal_master (mhd_gtls_session_t session, int keep_premaster) 59generate_normal_master (MHD_gtls_session_t session, int keep_premaster)
60{ 60{
61 int ret = 0; 61 int ret = 0;
62 char buf[512]; 62 char buf[512];
63 63
64 _gnutls_hard_log ("INT: PREMASTER SECRET[%d]: %s\n", PREMASTER.size, 64 MHD__gnutls_hard_log ("INT: PREMASTER SECRET[%d]: %s\n", PREMASTER.size,
65 mhd_gtls_bin2hex (PREMASTER.data, PREMASTER.size, buf, 65 MHD_gtls_bin2hex (PREMASTER.data, PREMASTER.size, buf,
66 sizeof (buf))); 66 sizeof (buf)));
67 _gnutls_hard_log ("INT: CLIENT RANDOM[%d]: %s\n", 32, 67 MHD__gnutls_hard_log ("INT: CLIENT RANDOM[%d]: %s\n", 32,
68 mhd_gtls_bin2hex (session->security_parameters. 68 MHD_gtls_bin2hex (session->security_parameters.
69 client_random, 32, buf, sizeof (buf))); 69 client_random, 32, buf, sizeof (buf)));
70 _gnutls_hard_log ("INT: SERVER RANDOM[%d]: %s\n", 32, 70 MHD__gnutls_hard_log ("INT: SERVER RANDOM[%d]: %s\n", 32,
71 mhd_gtls_bin2hex (session->security_parameters. 71 MHD_gtls_bin2hex (session->security_parameters.
72 server_random, 32, buf, sizeof (buf))); 72 server_random, 32, buf, sizeof (buf)));
73 73
74 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3) 74 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3)
75 { 75 {
76 opaque rnd[2 * TLS_RANDOM_SIZE + 1]; 76 opaque rnd[2 * TLS_RANDOM_SIZE + 1];
77 77
@@ -81,7 +81,7 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
81 session->security_parameters.server_random, TLS_RANDOM_SIZE); 81 session->security_parameters.server_random, TLS_RANDOM_SIZE);
82 82
83 ret = 83 ret =
84 mhd_gnutls_ssl3_generate_random (PREMASTER.data, PREMASTER.size, 84 MHD_gnutls_ssl3_generate_random (PREMASTER.data, PREMASTER.size,
85 rnd, 2 * TLS_RANDOM_SIZE, 85 rnd, 2 * TLS_RANDOM_SIZE,
86 TLS_MASTER_SIZE, 86 TLS_MASTER_SIZE,
87 session->security_parameters. 87 session->security_parameters.
@@ -97,25 +97,25 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
97 rndlen += session->security_parameters.extensions.oprfi_client_len; 97 rndlen += session->security_parameters.extensions.oprfi_client_len;
98 rndlen += session->security_parameters.extensions.oprfi_server_len; 98 rndlen += session->security_parameters.extensions.oprfi_server_len;
99 99
100 rnd = gnutls_malloc (rndlen + 1); 100 rnd = MHD_gnutls_malloc (rndlen + 1);
101 if (!rnd) 101 if (!rnd)
102 { 102 {
103 gnutls_assert (); 103 MHD_gnutls_assert ();
104 return GNUTLS_E_MEMORY_ERROR; 104 return GNUTLS_E_MEMORY_ERROR;
105 } 105 }
106 106
107 _gnutls_hard_log ("INT: CLIENT OPRFI[%d]: %s\n", 107 MHD__gnutls_hard_log ("INT: CLIENT OPRFI[%d]: %s\n",
108 session->security_parameters. 108 session->security_parameters.
109 extensions.oprfi_server_len, 109 extensions.oprfi_server_len,
110 mhd_gtls_bin2hex (session->security_parameters. 110 MHD_gtls_bin2hex (session->security_parameters.
111 extensions.oprfi_client, 111 extensions.oprfi_client,
112 session->security_parameters. 112 session->security_parameters.
113 extensions.oprfi_client_len, buf, 113 extensions.oprfi_client_len, buf,
114 sizeof (buf))); 114 sizeof (buf)));
115 _gnutls_hard_log ("INT: SERVER OPRFI[%d]: %s\n", 115 MHD__gnutls_hard_log ("INT: SERVER OPRFI[%d]: %s\n",
116 session->security_parameters. 116 session->security_parameters.
117 extensions.oprfi_server_len, 117 extensions.oprfi_server_len,
118 mhd_gtls_bin2hex (session->security_parameters. 118 MHD_gtls_bin2hex (session->security_parameters.
119 extensions.oprfi_server, 119 extensions.oprfi_server,
120 session->security_parameters. 120 session->security_parameters.
121 extensions.oprfi_server_len, buf, 121 extensions.oprfi_server_len, buf,
@@ -135,12 +135,12 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
135 session->security_parameters.extensions.oprfi_server, 135 session->security_parameters.extensions.oprfi_server,
136 session->security_parameters.extensions.oprfi_server_len); 136 session->security_parameters.extensions.oprfi_server_len);
137 137
138 ret = mhd_gtls_PRF (session, PREMASTER.data, PREMASTER.size, 138 ret = MHD_gtls_PRF (session, PREMASTER.data, PREMASTER.size,
139 MASTER_SECRET, strlen (MASTER_SECRET), 139 MASTER_SECRET, strlen (MASTER_SECRET),
140 rnd, rndlen, TLS_MASTER_SIZE, 140 rnd, rndlen, TLS_MASTER_SIZE,
141 session->security_parameters.master_secret); 141 session->security_parameters.master_secret);
142 142
143 gnutls_free (rnd); 143 MHD_gnutls_free (rnd);
144 } 144 }
145 else 145 else
146 { 146 {
@@ -152,7 +152,7 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
152 session->security_parameters.server_random, TLS_RANDOM_SIZE); 152 session->security_parameters.server_random, TLS_RANDOM_SIZE);
153 153
154 ret = 154 ret =
155 mhd_gtls_PRF (session, PREMASTER.data, PREMASTER.size, 155 MHD_gtls_PRF (session, PREMASTER.data, PREMASTER.size,
156 MASTER_SECRET, strlen (MASTER_SECRET), 156 MASTER_SECRET, strlen (MASTER_SECRET),
157 rnd, 2 * TLS_RANDOM_SIZE, TLS_MASTER_SIZE, 157 rnd, 2 * TLS_RANDOM_SIZE, TLS_MASTER_SIZE,
158 session->security_parameters.master_secret); 158 session->security_parameters.master_secret);
@@ -163,13 +163,13 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
163 session->security_parameters.master_secret, TLS_MASTER_SIZE); 163 session->security_parameters.master_secret, TLS_MASTER_SIZE);
164 164
165 if (!keep_premaster) 165 if (!keep_premaster)
166 _gnutls_free_datum (&PREMASTER); 166 MHD__gnutls_free_datum (&PREMASTER);
167 167
168 if (ret < 0) 168 if (ret < 0)
169 return ret; 169 return ret;
170 170
171 _gnutls_hard_log ("INT: MASTER SECRET: %s\n", 171 MHD__gnutls_hard_log ("INT: MASTER SECRET: %s\n",
172 mhd_gtls_bin2hex (session->security_parameters. 172 MHD_gtls_bin2hex (session->security_parameters.
173 master_secret, TLS_MASTER_SIZE, buf, 173 master_secret, TLS_MASTER_SIZE, buf,
174 sizeof (buf))); 174 sizeof (buf)));
175 175
@@ -182,13 +182,13 @@ generate_normal_master (mhd_gtls_session_t session, int keep_premaster)
182 * by the selected ciphersuite. 182 * by the selected ciphersuite.
183 */ 183 */
184int 184int
185mhd_gtls_send_server_kx_message (mhd_gtls_session_t session, int again) 185MHD_gtls_send_server_kx_message (MHD_gtls_session_t session, int again)
186{ 186{
187 uint8_t *data = NULL; 187 uint8_t *data = NULL;
188 int data_size = 0; 188 int data_size = 0;
189 int ret = 0; 189 int ret = 0;
190 190
191 if (session->internals.auth_struct->mhd_gtls_gen_server_kx == NULL) 191 if (session->internals.auth_struct->MHD_gtls_gen_server_kx == NULL)
192 return 0; 192 return 0;
193 193
194 data = NULL; 194 data = NULL;
@@ -197,30 +197,30 @@ mhd_gtls_send_server_kx_message (mhd_gtls_session_t session, int again)
197 if (again == 0) 197 if (again == 0)
198 { 198 {
199 data_size = 199 data_size =
200 session->internals.auth_struct->mhd_gtls_gen_server_kx (session, 200 session->internals.auth_struct->MHD_gtls_gen_server_kx (session,
201 &data); 201 &data);
202 202
203 if (data_size == GNUTLS_E_INT_RET_0) 203 if (data_size == GNUTLS_E_INT_RET_0)
204 { 204 {
205 gnutls_assert (); 205 MHD_gnutls_assert ();
206 return 0; 206 return 0;
207 } 207 }
208 208
209 if (data_size < 0) 209 if (data_size < 0)
210 { 210 {
211 gnutls_assert (); 211 MHD_gnutls_assert ();
212 return data_size; 212 return data_size;
213 } 213 }
214 } 214 }
215 215
216 ret = 216 ret =
217 mhd_gtls_send_handshake (session, data, data_size, 217 MHD_gtls_send_handshake (session, data, data_size,
218 GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE); 218 GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE);
219 gnutls_free (data); 219 MHD_gnutls_free (data);
220 220
221 if (ret < 0) 221 if (ret < 0)
222 { 222 {
223 gnutls_assert (); 223 MHD_gnutls_assert ();
224 return ret; 224 return ret;
225 } 225 }
226 return data_size; 226 return data_size;
@@ -230,7 +230,7 @@ mhd_gtls_send_server_kx_message (mhd_gtls_session_t session, int again)
230 * client. 230 * client.
231 */ 231 */
232int 232int
233mhd_gtls_send_server_certificate_request (mhd_gtls_session_t session, 233MHD_gtls_send_server_certificate_request (MHD_gtls_session_t session,
234 int again) 234 int again)
235{ 235{
236 uint8_t *data = NULL; 236 uint8_t *data = NULL;
@@ -238,7 +238,7 @@ mhd_gtls_send_server_certificate_request (mhd_gtls_session_t session,
238 int ret = 0; 238 int ret = 0;
239 239
240 if (session->internals.auth_struct-> 240 if (session->internals.auth_struct->
241 mhd_gtls_gen_server_certificate_request == NULL) 241 MHD_gtls_gen_server_certificate_request == NULL)
242 return 0; 242 return 0;
243 243
244 if (session->internals.send_cert_req <= 0) 244 if (session->internals.send_cert_req <= 0)
@@ -251,22 +251,22 @@ mhd_gtls_send_server_certificate_request (mhd_gtls_session_t session,
251 { 251 {
252 data_size = 252 data_size =
253 session->internals.auth_struct-> 253 session->internals.auth_struct->
254 mhd_gtls_gen_server_certificate_request (session, &data); 254 MHD_gtls_gen_server_certificate_request (session, &data);
255 255
256 if (data_size < 0) 256 if (data_size < 0)
257 { 257 {
258 gnutls_assert (); 258 MHD_gnutls_assert ();
259 return data_size; 259 return data_size;
260 } 260 }
261 } 261 }
262 ret = 262 ret =
263 mhd_gtls_send_handshake (session, data, data_size, 263 MHD_gtls_send_handshake (session, data, data_size,
264 GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST); 264 GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST);
265 gnutls_free (data); 265 MHD_gnutls_free (data);
266 266
267 if (ret < 0) 267 if (ret < 0)
268 { 268 {
269 gnutls_assert (); 269 MHD_gnutls_assert ();
270 return ret; 270 return ret;
271 } 271 }
272 return data_size; 272 return data_size;
@@ -277,13 +277,13 @@ mhd_gtls_send_server_certificate_request (mhd_gtls_session_t session,
277 * exchange message 277 * exchange message
278 */ 278 */
279int 279int
280mhd_gtls_send_client_kx_message (mhd_gtls_session_t session, int again) 280MHD_gtls_send_client_kx_message (MHD_gtls_session_t session, int again)
281{ 281{
282 uint8_t *data; 282 uint8_t *data;
283 int data_size; 283 int data_size;
284 int ret = 0; 284 int ret = 0;
285 285
286 if (session->internals.auth_struct->mhd_gtls_gen_client_kx == NULL) 286 if (session->internals.auth_struct->MHD_gtls_gen_client_kx == NULL)
287 return 0; 287 return 0;
288 288
289 289
@@ -293,22 +293,22 @@ mhd_gtls_send_client_kx_message (mhd_gtls_session_t session, int again)
293 if (again == 0) 293 if (again == 0)
294 { 294 {
295 data_size = 295 data_size =
296 session->internals.auth_struct->mhd_gtls_gen_client_kx (session, 296 session->internals.auth_struct->MHD_gtls_gen_client_kx (session,
297 &data); 297 &data);
298 if (data_size < 0) 298 if (data_size < 0)
299 { 299 {
300 gnutls_assert (); 300 MHD_gnutls_assert ();
301 return data_size; 301 return data_size;
302 } 302 }
303 } 303 }
304 ret = 304 ret =
305 mhd_gtls_send_handshake (session, data, data_size, 305 MHD_gtls_send_handshake (session, data, data_size,
306 GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE); 306 GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE);
307 gnutls_free (data); 307 MHD_gnutls_free (data);
308 308
309 if (ret < 0) 309 if (ret < 0)
310 { 310 {
311 gnutls_assert (); 311 MHD_gnutls_assert ();
312 return ret; 312 return ret;
313 } 313 }
314 314
@@ -320,7 +320,7 @@ mhd_gtls_send_client_kx_message (mhd_gtls_session_t session, int again)
320 * verify message 320 * verify message
321 */ 321 */
322int 322int
323mhd_gtls_send_client_certificate_verify (mhd_gtls_session_t session, 323MHD_gtls_send_client_certificate_verify (MHD_gtls_session_t session,
324 int again) 324 int again)
325{ 325{
326 uint8_t *data; 326 uint8_t *data;
@@ -337,9 +337,9 @@ mhd_gtls_send_client_certificate_verify (mhd_gtls_session_t session,
337 if (session->key->certificate_requested == 0) 337 if (session->key->certificate_requested == 0)
338 return 0; 338 return 0;
339 339
340 if (session->internals.auth_struct->mhd_gtls_gen_client_cert_vrfy == NULL) 340 if (session->internals.auth_struct->MHD_gtls_gen_client_cert_vrfy == NULL)
341 { 341 {
342 gnutls_assert (); 342 MHD_gnutls_assert ();
343 return 0; /* this algorithm does not support cli_cert_vrfy 343 return 0; /* this algorithm does not support cli_cert_vrfy
344 */ 344 */
345 } 345 }
@@ -351,10 +351,10 @@ mhd_gtls_send_client_certificate_verify (mhd_gtls_session_t session,
351 { 351 {
352 data_size = 352 data_size =
353 session->internals.auth_struct-> 353 session->internals.auth_struct->
354 mhd_gtls_gen_client_cert_vrfy (session, &data); 354 MHD_gtls_gen_client_cert_vrfy (session, &data);
355 if (data_size < 0) 355 if (data_size < 0)
356 { 356 {
357 gnutls_assert (); 357 MHD_gnutls_assert ();
358 return data_size; 358 return data_size;
359 } 359 }
360 if (data_size == 0) 360 if (data_size == 0)
@@ -362,53 +362,53 @@ mhd_gtls_send_client_certificate_verify (mhd_gtls_session_t session,
362 362
363 } 363 }
364 ret = 364 ret =
365 mhd_gtls_send_handshake (session, data, 365 MHD_gtls_send_handshake (session, data,
366 data_size, GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY); 366 data_size, GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY);
367 gnutls_free (data); 367 MHD_gnutls_free (data);
368 368
369 return ret; 369 return ret;
370} 370}
371 371
372 372
373int 373int
374mhd_gtls_recv_server_kx_message (mhd_gtls_session_t session) 374MHD_gtls_recv_server_kx_message (MHD_gtls_session_t session)
375{ 375{
376 uint8_t *data = NULL; 376 uint8_t *data = NULL;
377 int datasize; 377 int datasize;
378 int ret = 0; 378 int ret = 0;
379 379
380 if (session->internals.auth_struct->mhd_gtls_process_server_kx != NULL) 380 if (session->internals.auth_struct->MHD_gtls_process_server_kx != NULL)
381 { 381 {
382 382
383 /* EXCEPTION FOR RSA_EXPORT cipher suite 383 /* EXCEPTION FOR RSA_EXPORT cipher suite
384 */ 384 */
385 if (mhd_gtls_session_is_export (session) != 0 && 385 if (MHD_gtls_session_is_export (session) != 0 &&
386 _gnutls_peers_cert_less_512 (session) != 0) 386 MHD__gnutls_peers_cert_less_512 (session) != 0)
387 { 387 {
388 gnutls_assert (); 388 MHD_gnutls_assert ();
389 return 0; 389 return 0;
390 } 390 }
391 391
392 ret = 392 ret =
393 mhd_gtls_recv_handshake (session, &data, 393 MHD_gtls_recv_handshake (session, &data,
394 &datasize, 394 &datasize,
395 GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE, 395 GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE,
396 MANDATORY_PACKET); 396 MANDATORY_PACKET);
397 if (ret < 0) 397 if (ret < 0)
398 { 398 {
399 gnutls_assert (); 399 MHD_gnutls_assert ();
400 return ret; 400 return ret;
401 } 401 }
402 402
403 ret = 403 ret =
404 session->internals.auth_struct->mhd_gtls_process_server_kx (session, 404 session->internals.auth_struct->MHD_gtls_process_server_kx (session,
405 data, 405 data,
406 datasize); 406 datasize);
407 gnutls_free (data); 407 MHD_gnutls_free (data);
408 408
409 if (ret < 0) 409 if (ret < 0)
410 { 410 {
411 gnutls_assert (); 411 MHD_gnutls_assert ();
412 return ret; 412 return ret;
413 } 413 }
414 414
@@ -417,18 +417,18 @@ mhd_gtls_recv_server_kx_message (mhd_gtls_session_t session)
417} 417}
418 418
419int 419int
420mhd_gtls_recv_server_certificate_request (mhd_gtls_session_t session) 420MHD_gtls_recv_server_certificate_request (MHD_gtls_session_t session)
421{ 421{
422 uint8_t *data; 422 uint8_t *data;
423 int datasize; 423 int datasize;
424 int ret = 0; 424 int ret = 0;
425 425
426 if (session->internals.auth_struct-> 426 if (session->internals.auth_struct->
427 mhd_gtls_process_server_certificate_request != NULL) 427 MHD_gtls_process_server_certificate_request != NULL)
428 { 428 {
429 429
430 ret = 430 ret =
431 mhd_gtls_recv_handshake (session, &data, 431 MHD_gtls_recv_handshake (session, &data,
432 &datasize, 432 &datasize,
433 GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST, 433 GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST,
434 OPTIONAL_PACKET); 434 OPTIONAL_PACKET);
@@ -440,8 +440,8 @@ mhd_gtls_recv_server_certificate_request (mhd_gtls_session_t session)
440 440
441 ret = 441 ret =
442 session->internals.auth_struct-> 442 session->internals.auth_struct->
443 mhd_gtls_process_server_certificate_request (session, data, datasize); 443 MHD_gtls_process_server_certificate_request (session, data, datasize);
444 gnutls_free (data); 444 MHD_gnutls_free (data);
445 if (ret < 0) 445 if (ret < 0)
446 return ret; 446 return ret;
447 447
@@ -450,7 +450,7 @@ mhd_gtls_recv_server_certificate_request (mhd_gtls_session_t session)
450} 450}
451 451
452int 452int
453mhd_gtls_recv_client_kx_message (mhd_gtls_session_t session) 453MHD_gtls_recv_client_kx_message (MHD_gtls_session_t session)
454{ 454{
455 uint8_t *data; 455 uint8_t *data;
456 int datasize; 456 int datasize;
@@ -458,11 +458,11 @@ mhd_gtls_recv_client_kx_message (mhd_gtls_session_t session)
458 458
459 459
460 /* Do key exchange only if the algorithm permits it */ 460 /* Do key exchange only if the algorithm permits it */
461 if (session->internals.auth_struct->mhd_gtls_process_client_kx != NULL) 461 if (session->internals.auth_struct->MHD_gtls_process_client_kx != NULL)
462 { 462 {
463 463
464 ret = 464 ret =
465 mhd_gtls_recv_handshake (session, &data, 465 MHD_gtls_recv_handshake (session, &data,
466 &datasize, 466 &datasize,
467 GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE, 467 GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE,
468 MANDATORY_PACKET); 468 MANDATORY_PACKET);
@@ -470,10 +470,10 @@ mhd_gtls_recv_client_kx_message (mhd_gtls_session_t session)
470 return ret; 470 return ret;
471 471
472 ret = 472 ret =
473 session->internals.auth_struct->mhd_gtls_process_client_kx (session, 473 session->internals.auth_struct->MHD_gtls_process_client_kx (session,
474 data, 474 data,
475 datasize); 475 datasize);
476 gnutls_free (data); 476 MHD_gnutls_free (data);
477 if (ret < 0) 477 if (ret < 0)
478 return ret; 478 return ret;
479 479
@@ -486,7 +486,7 @@ mhd_gtls_recv_client_kx_message (mhd_gtls_session_t session)
486/* This is called when we want send our certificate 486/* This is called when we want send our certificate
487 */ 487 */
488int 488int
489mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again) 489MHD_gtls_send_client_certificate (MHD_gtls_session_t session, int again)
490{ 490{
491 uint8_t *data = NULL; 491 uint8_t *data = NULL;
492 int data_size = 0; 492 int data_size = 0;
@@ -496,7 +496,7 @@ mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again)
496 if (session->key->certificate_requested == 0) 496 if (session->key->certificate_requested == 0)
497 return 0; 497 return 0;
498 498
499 if (session->internals.auth_struct->mhd_gtls_gen_client_certificate == NULL) 499 if (session->internals.auth_struct->MHD_gtls_gen_client_certificate == NULL)
500 return 0; 500 return 0;
501 501
502 data = NULL; 502 data = NULL;
@@ -504,18 +504,18 @@ mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again)
504 504
505 if (again == 0) 505 if (again == 0)
506 { 506 {
507 if (MHD_gnutls_protocol_get_version (session) != MHD_GNUTLS_PROTOCOL_SSL3 || 507 if (MHD__gnutls_protocol_get_version (session) != MHD_GNUTLS_PROTOCOL_SSL3 ||
508 session->internals.selected_cert_list_length > 0) 508 session->internals.selected_cert_list_length > 0)
509 { 509 {
510 /* TLS 1.0 or SSL 3.0 with a valid certificate 510 /* TLS 1.0 or SSL 3.0 with a valid certificate
511 */ 511 */
512 data_size = 512 data_size =
513 session->internals.auth_struct-> 513 session->internals.auth_struct->
514 mhd_gtls_gen_client_certificate (session, &data); 514 MHD_gtls_gen_client_certificate (session, &data);
515 515
516 if (data_size < 0) 516 if (data_size < 0)
517 { 517 {
518 gnutls_assert (); 518 MHD_gnutls_assert ();
519 return data_size; 519 return data_size;
520 } 520 }
521 } 521 }
@@ -525,11 +525,11 @@ mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again)
525 * no certificate alert instead of an 525 * no certificate alert instead of an
526 * empty certificate. 526 * empty certificate.
527 */ 527 */
528 if (MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3 && 528 if (MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3 &&
529 session->internals.selected_cert_list_length == 0) 529 session->internals.selected_cert_list_length == 0)
530 { 530 {
531 ret = 531 ret =
532 MHD_gnutls_alert_send (session, GNUTLS_AL_WARNING, 532 MHD__gnutls_alert_send (session, GNUTLS_AL_WARNING,
533 GNUTLS_A_SSL3_NO_CERTIFICATE); 533 GNUTLS_A_SSL3_NO_CERTIFICATE);
534 534
535 } 535 }
@@ -537,14 +537,14 @@ mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again)
537 { /* TLS 1.0 or SSL 3.0 with a valid certificate 537 { /* TLS 1.0 or SSL 3.0 with a valid certificate
538 */ 538 */
539 ret = 539 ret =
540 mhd_gtls_send_handshake (session, data, data_size, 540 MHD_gtls_send_handshake (session, data, data_size,
541 GNUTLS_HANDSHAKE_CERTIFICATE_PKT); 541 GNUTLS_HANDSHAKE_CERTIFICATE_PKT);
542 gnutls_free (data); 542 MHD_gnutls_free (data);
543 } 543 }
544 544
545 if (ret < 0) 545 if (ret < 0)
546 { 546 {
547 gnutls_assert (); 547 MHD_gnutls_assert ();
548 return ret; 548 return ret;
549 } 549 }
550 550
@@ -555,14 +555,14 @@ mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again)
555/* This is called when we want send our certificate 555/* This is called when we want send our certificate
556 */ 556 */
557int 557int
558mhd_gtls_send_server_certificate (mhd_gtls_session_t session, int again) 558MHD_gtls_send_server_certificate (MHD_gtls_session_t session, int again)
559{ 559{
560 uint8_t *data = NULL; 560 uint8_t *data = NULL;
561 int data_size = 0; 561 int data_size = 0;
562 int ret = 0; 562 int ret = 0;
563 563
564 564
565 if (session->internals.auth_struct->mhd_gtls_gen_server_certificate == NULL) 565 if (session->internals.auth_struct->MHD_gtls_gen_server_certificate == NULL)
566 return 0; 566 return 0;
567 567
568 data = NULL; 568 data = NULL;
@@ -572,22 +572,22 @@ mhd_gtls_send_server_certificate (mhd_gtls_session_t session, int again)
572 { 572 {
573 data_size = 573 data_size =
574 session->internals.auth_struct-> 574 session->internals.auth_struct->
575 mhd_gtls_gen_server_certificate (session, &data); 575 MHD_gtls_gen_server_certificate (session, &data);
576 576
577 if (data_size < 0) 577 if (data_size < 0)
578 { 578 {
579 gnutls_assert (); 579 MHD_gnutls_assert ();
580 return data_size; 580 return data_size;
581 } 581 }
582 } 582 }
583 ret = 583 ret =
584 mhd_gtls_send_handshake (session, data, data_size, 584 MHD_gtls_send_handshake (session, data, data_size,
585 GNUTLS_HANDSHAKE_CERTIFICATE_PKT); 585 GNUTLS_HANDSHAKE_CERTIFICATE_PKT);
586 gnutls_free (data); 586 MHD_gnutls_free (data);
587 587
588 if (ret < 0) 588 if (ret < 0)
589 { 589 {
590 gnutls_assert (); 590 MHD_gnutls_assert ();
591 return ret; 591 return ret;
592 } 592 }
593 593
@@ -596,14 +596,14 @@ mhd_gtls_send_server_certificate (mhd_gtls_session_t session, int again)
596 596
597 597
598int 598int
599mhd_gtls_recv_client_certificate (mhd_gtls_session_t session) 599MHD_gtls_recv_client_certificate (MHD_gtls_session_t session)
600{ 600{
601 int datasize; 601 int datasize;
602 opaque *data; 602 opaque *data;
603 int ret = 0; 603 int ret = 0;
604 int optional; 604 int optional;
605 605
606 if (session->internals.auth_struct->mhd_gtls_process_client_certificate != 606 if (session->internals.auth_struct->MHD_gtls_process_client_certificate !=
607 NULL) 607 NULL)
608 { 608 {
609 609
@@ -620,7 +620,7 @@ mhd_gtls_recv_client_certificate (mhd_gtls_session_t session)
620 optional = OPTIONAL_PACKET; 620 optional = OPTIONAL_PACKET;
621 621
622 ret = 622 ret =
623 mhd_gtls_recv_handshake (session, &data, 623 MHD_gtls_recv_handshake (session, &data,
624 &datasize, 624 &datasize,
625 GNUTLS_HANDSHAKE_CERTIFICATE_PKT, optional); 625 GNUTLS_HANDSHAKE_CERTIFICATE_PKT, optional);
626 626
@@ -632,14 +632,14 @@ mhd_gtls_recv_client_certificate (mhd_gtls_session_t session)
632 */ 632 */
633 if (optional == OPTIONAL_PACKET && 633 if (optional == OPTIONAL_PACKET &&
634 ret == GNUTLS_E_WARNING_ALERT_RECEIVED && 634 ret == GNUTLS_E_WARNING_ALERT_RECEIVED &&
635 MHD_gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3 && 635 MHD__gnutls_protocol_get_version (session) == MHD_GNUTLS_PROTOCOL_SSL3 &&
636 gnutls_alert_get (session) == GNUTLS_A_SSL3_NO_CERTIFICATE) 636 MHD_gnutls_alert_get (session) == GNUTLS_A_SSL3_NO_CERTIFICATE)
637 { 637 {
638 638
639 /* SSL3 does not send an empty certificate, 639 /* SSL3 does not send an empty certificate,
640 * but this alert. So we just ignore it. 640 * but this alert. So we just ignore it.
641 */ 641 */
642 gnutls_assert (); 642 MHD_gnutls_assert ();
643 return 0; 643 return 0;
644 } 644 }
645 645
@@ -649,7 +649,7 @@ mhd_gtls_recv_client_certificate (mhd_gtls_session_t session)
649 || ret == GNUTLS_E_FATAL_ALERT_RECEIVED) 649 || ret == GNUTLS_E_FATAL_ALERT_RECEIVED)
650 && optional == MANDATORY_PACKET) 650 && optional == MANDATORY_PACKET)
651 { 651 {
652 gnutls_assert (); 652 MHD_gnutls_assert ();
653 return GNUTLS_E_NO_CERTIFICATE_FOUND; 653 return GNUTLS_E_NO_CERTIFICATE_FOUND;
654 } 654 }
655 655
@@ -662,17 +662,17 @@ mhd_gtls_recv_client_certificate (mhd_gtls_session_t session)
662 * well I'm not sure we should accept this 662 * well I'm not sure we should accept this
663 * behaviour. 663 * behaviour.
664 */ 664 */
665 gnutls_assert (); 665 MHD_gnutls_assert ();
666 return 0; 666 return 0;
667 } 667 }
668 ret = 668 ret =
669 session->internals.auth_struct-> 669 session->internals.auth_struct->
670 mhd_gtls_process_client_certificate (session, data, datasize); 670 MHD_gtls_process_client_certificate (session, data, datasize);
671 671
672 gnutls_free (data); 672 MHD_gnutls_free (data);
673 if (ret < 0 && ret != GNUTLS_E_NO_CERTIFICATE_FOUND) 673 if (ret < 0 && ret != GNUTLS_E_NO_CERTIFICATE_FOUND)
674 { 674 {
675 gnutls_assert (); 675 MHD_gnutls_assert ();
676 return ret; 676 return ret;
677 } 677 }
678 678
@@ -689,34 +689,34 @@ mhd_gtls_recv_client_certificate (mhd_gtls_session_t session)
689} 689}
690 690
691int 691int
692mhd_gtls_recv_server_certificate (mhd_gtls_session_t session) 692MHD_gtls_recv_server_certificate (MHD_gtls_session_t session)
693{ 693{
694 int datasize; 694 int datasize;
695 opaque *data; 695 opaque *data;
696 int ret = 0; 696 int ret = 0;
697 697
698 if (session->internals.auth_struct->mhd_gtls_process_server_certificate != 698 if (session->internals.auth_struct->MHD_gtls_process_server_certificate !=
699 NULL) 699 NULL)
700 { 700 {
701 701
702 ret = 702 ret =
703 mhd_gtls_recv_handshake (session, &data, 703 MHD_gtls_recv_handshake (session, &data,
704 &datasize, 704 &datasize,
705 GNUTLS_HANDSHAKE_CERTIFICATE_PKT, 705 GNUTLS_HANDSHAKE_CERTIFICATE_PKT,
706 MANDATORY_PACKET); 706 MANDATORY_PACKET);
707 if (ret < 0) 707 if (ret < 0)
708 { 708 {
709 gnutls_assert (); 709 MHD_gnutls_assert ();
710 return ret; 710 return ret;
711 } 711 }
712 712
713 ret = 713 ret =
714 session->internals.auth_struct-> 714 session->internals.auth_struct->
715 mhd_gtls_process_server_certificate (session, data, datasize); 715 MHD_gtls_process_server_certificate (session, data, datasize);
716 gnutls_free (data); 716 MHD_gnutls_free (data);
717 if (ret < 0) 717 if (ret < 0)
718 { 718 {
719 gnutls_assert (); 719 MHD_gnutls_assert ();
720 return ret; 720 return ret;
721 } 721 }
722 } 722 }
@@ -729,14 +729,14 @@ mhd_gtls_recv_server_certificate (mhd_gtls_session_t session)
729 * arrive if the peer did not send us a certificate. 729 * arrive if the peer did not send us a certificate.
730 */ 730 */
731int 731int
732mhd_gtls_recv_client_certificate_verify_message (mhd_gtls_session_t session) 732MHD_gtls_recv_client_certificate_verify_message (MHD_gtls_session_t session)
733{ 733{
734 uint8_t *data; 734 uint8_t *data;
735 int datasize; 735 int datasize;
736 int ret = 0; 736 int ret = 0;
737 737
738 738
739 if (session->internals.auth_struct->mhd_gtls_process_client_cert_vrfy != 739 if (session->internals.auth_struct->MHD_gtls_process_client_cert_vrfy !=
740 NULL) 740 NULL)
741 { 741 {
742 742
@@ -747,7 +747,7 @@ mhd_gtls_recv_client_certificate_verify_message (mhd_gtls_session_t session)
747 } 747 }
748 748
749 ret = 749 ret =
750 mhd_gtls_recv_handshake (session, &data, 750 MHD_gtls_recv_handshake (session, &data,
751 &datasize, 751 &datasize,
752 GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY, 752 GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY,
753 OPTIONAL_PACKET); 753 OPTIONAL_PACKET);
@@ -758,14 +758,14 @@ mhd_gtls_recv_client_certificate_verify_message (mhd_gtls_session_t session)
758 && session->internals.send_cert_req == GNUTLS_CERT_REQUIRE) 758 && session->internals.send_cert_req == GNUTLS_CERT_REQUIRE)
759 { 759 {
760 /* certificate was required */ 760 /* certificate was required */
761 gnutls_assert (); 761 MHD_gnutls_assert ();
762 return GNUTLS_E_NO_CERTIFICATE_FOUND; 762 return GNUTLS_E_NO_CERTIFICATE_FOUND;
763 } 763 }
764 764
765 ret = 765 ret =
766 session->internals.auth_struct-> 766 session->internals.auth_struct->
767 mhd_gtls_process_client_cert_vrfy (session, data, datasize); 767 MHD_gtls_process_client_cert_vrfy (session, data, datasize);
768 gnutls_free (data); 768 MHD_gnutls_free (data);
769 if (ret < 0) 769 if (ret < 0)
770 return ret; 770 return ret;
771 771
diff --git a/src/daemon/https/tls/gnutls_kx.h b/src/daemon/https/tls/gnutls_kx.h
index e8bdf199..92144615 100644
--- a/src/daemon/https/tls/gnutls_kx.h
+++ b/src/daemon/https/tls/gnutls_kx.h
@@ -22,19 +22,19 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gtls_send_server_kx_message (mhd_gtls_session_t session, int again); 25int MHD_gtls_send_server_kx_message (MHD_gtls_session_t session, int again);
26int mhd_gtls_send_client_kx_message (mhd_gtls_session_t session, int again); 26int MHD_gtls_send_client_kx_message (MHD_gtls_session_t session, int again);
27int mhd_gtls_recv_server_kx_message (mhd_gtls_session_t session); 27int MHD_gtls_recv_server_kx_message (MHD_gtls_session_t session);
28int mhd_gtls_recv_client_kx_message (mhd_gtls_session_t session); 28int MHD_gtls_recv_client_kx_message (MHD_gtls_session_t session);
29int mhd_gtls_send_client_certificate_verify (mhd_gtls_session_t session, 29int MHD_gtls_send_client_certificate_verify (MHD_gtls_session_t session,
30 int again); 30 int again);
31int mhd_gtls_send_server_certificate (mhd_gtls_session_t session, int again); 31int MHD_gtls_send_server_certificate (MHD_gtls_session_t session, int again);
32int mhd_gtls_generate_master (mhd_gtls_session_t session, int keep_premaster); 32int MHD_gtls_generate_master (MHD_gtls_session_t session, int keep_premaster);
33int mhd_gtls_recv_client_certificate (mhd_gtls_session_t session); 33int MHD_gtls_recv_client_certificate (MHD_gtls_session_t session);
34int mhd_gtls_recv_server_certificate (mhd_gtls_session_t session); 34int MHD_gtls_recv_server_certificate (MHD_gtls_session_t session);
35int mhd_gtls_send_client_certificate (mhd_gtls_session_t session, int again); 35int MHD_gtls_send_client_certificate (MHD_gtls_session_t session, int again);
36int mhd_gtls_recv_server_certificate_request (mhd_gtls_session_t session); 36int MHD_gtls_recv_server_certificate_request (MHD_gtls_session_t session);
37int mhd_gtls_send_server_certificate_request (mhd_gtls_session_t session, 37int MHD_gtls_send_server_certificate_request (MHD_gtls_session_t session,
38 int again); 38 int again);
39int mhd_gtls_recv_client_certificate_verify_message (mhd_gtls_session_t 39int MHD_gtls_recv_client_certificate_verify_message (MHD_gtls_session_t
40 session); 40 session);
diff --git a/src/daemon/https/tls/gnutls_mem.c b/src/daemon/https/tls/gnutls_mem.c
index 2d7537b8..fda4099b 100644
--- a/src/daemon/https/tls/gnutls_mem.c
+++ b/src/daemon/https/tls/gnutls_mem.c
@@ -26,40 +26,40 @@
26#include <gnutls_errors.h> 26#include <gnutls_errors.h>
27#include <gnutls_num.h> 27#include <gnutls_num.h>
28 28
29gnutls_alloc_function gnutls_secure_malloc = malloc; 29MHD_gnutls_alloc_function MHD_gnutls_secure_malloc = malloc;
30gnutls_alloc_function gnutls_malloc = malloc; 30MHD_gnutls_alloc_function MHD_gnutls_malloc = malloc;
31gnutls_free_function gnutls_free = free; 31MHD_gnutls_free_function MHD_gnutls_free = free;
32gnutls_realloc_function gnutls_realloc = realloc; 32MHD_gnutls_realloc_function MHD_gnutls_realloc = realloc;
33 33
34void *(*gnutls_calloc) (size_t, size_t) = calloc; 34void *(*MHD_gnutls_calloc) (size_t, size_t) = calloc;
35char *(*gnutls_strdup) (const char *) = mhd_gtls_strdup; 35char *(*MHD_gnutls_strdup) (const char *) = MHD_gtls_strdup;
36 36
37int 37int
38_gnutls_is_secure_mem_null (const void *ign) 38MHD__gnutls_is_secure_mem_null (const void *ign)
39{ 39{
40 return 0; 40 return 0;
41} 41}
42 42
43int (*_gnutls_is_secure_memory) (const void *) = _gnutls_is_secure_mem_null; 43int (*MHD__gnutls_is_secure_memory) (const void *) = MHD__gnutls_is_secure_mem_null;
44 44
45 45
46void * 46void *
47mhd_gtls_calloc (size_t nmemb, size_t size) 47MHD_gtls_calloc (size_t nmemb, size_t size)
48{ 48{
49 void *ret; 49 void *ret;
50 size *= nmemb; 50 size *= nmemb;
51 ret = gnutls_malloc (size); 51 ret = MHD_gnutls_malloc (size);
52 if (ret != NULL) 52 if (ret != NULL)
53 memset (ret, 0, size); 53 memset (ret, 0, size);
54 return ret; 54 return ret;
55} 55}
56 56
57svoid * 57svoid *
58mhd_gtls_secure_calloc (size_t nmemb, size_t size) 58MHD_gtls_secure_calloc (size_t nmemb, size_t size)
59{ 59{
60 svoid *ret; 60 svoid *ret;
61 size *= nmemb; 61 size *= nmemb;
62 ret = gnutls_secure_malloc (size); 62 ret = MHD_gnutls_secure_malloc (size);
63 if (ret != NULL) 63 if (ret != NULL)
64 memset (ret, 0, size); 64 memset (ret, 0, size);
65 return ret; 65 return ret;
@@ -69,29 +69,29 @@ mhd_gtls_secure_calloc (size_t nmemb, size_t size)
69 * fails. 69 * fails.
70 */ 70 */
71void * 71void *
72mhd_gtls_realloc_fast (void *ptr, size_t size) 72MHD_gtls_realloc_fast (void *ptr, size_t size)
73{ 73{
74 void *ret; 74 void *ret;
75 75
76 if (size == 0) 76 if (size == 0)
77 return ptr; 77 return ptr;
78 78
79 ret = gnutls_realloc (ptr, size); 79 ret = MHD_gnutls_realloc (ptr, size);
80 if (ret == NULL) 80 if (ret == NULL)
81 { 81 {
82 gnutls_free (ptr); 82 MHD_gnutls_free (ptr);
83 } 83 }
84 84
85 return ret; 85 return ret;
86} 86}
87 87
88char * 88char *
89mhd_gtls_strdup (const char *str) 89MHD_gtls_strdup (const char *str)
90{ 90{
91 size_t siz = strlen (str) + 1; 91 size_t siz = strlen (str) + 1;
92 char *ret; 92 char *ret;
93 93
94 ret = gnutls_malloc (siz); 94 ret = MHD_gnutls_malloc (siz);
95 if (ret != NULL) 95 if (ret != NULL)
96 memcpy (ret, str, siz); 96 memcpy (ret, str, siz);
97 return ret; 97 return ret;
@@ -103,7 +103,7 @@ mhd_gtls_strdup (const char *str)
103 */ 103 */
104 104
105/** 105/**
106 * gnutls_malloc - Allocates and returns data 106 * MHD_gnutls_malloc - Allocates and returns data
107 * 107 *
108 * This function will allocate 's' bytes data, and 108 * This function will allocate 's' bytes data, and
109 * return a pointer to memory. This function is supposed 109 * return a pointer to memory. This function is supposed
@@ -113,12 +113,12 @@ mhd_gtls_strdup (const char *str)
113 * 113 *
114 **/ 114 **/
115void * 115void *
116gnutls_malloc (size_t s) 116MHD_gnutls_malloc (size_t s)
117{ 117{
118} 118}
119 119
120/** 120/**
121 * gnutls_free - Returns a free() like function 121 * MHD_gnutls_free - Returns a free() like function
122 * @d: pointer to memory 122 * @d: pointer to memory
123 * 123 *
124 * This function will free data pointed by ptr. 124 * This function will free data pointed by ptr.
@@ -127,7 +127,7 @@ gnutls_malloc (size_t s)
127 * 127 *
128 **/ 128 **/
129void 129void
130gnutls_free (void *ptr) 130MHD_gnutls_free (void *ptr)
131{ 131{
132} 132}
133 133
diff --git a/src/daemon/https/tls/gnutls_mem.h b/src/daemon/https/tls/gnutls_mem.h
index 51b37e32..86cd4abb 100644
--- a/src/daemon/https/tls/gnutls_mem.h
+++ b/src/daemon/https/tls/gnutls_mem.h
@@ -29,42 +29,42 @@
29# include <dmalloc.h> 29# include <dmalloc.h>
30#endif 30#endif
31 31
32typedef void svoid; /* for functions that allocate using gnutls_secure_malloc */ 32typedef void svoid; /* for functions that allocate using MHD_gnutls_secure_malloc */
33 33
34/* Use gnutls_afree() when calling alloca, or 34/* Use MHD_gnutls_afree() when calling alloca, or
35 * memory leaks may occur in systems which do not 35 * memory leaks may occur in systems which do not
36 * support alloca. 36 * support alloca.
37 */ 37 */
38#ifdef USE_EFENCE 38#ifdef USE_EFENCE
39# define gnutls_alloca gnutls_malloc 39# define MHD_gnutls_alloca MHD_gnutls_malloc
40# define gnutls_afree gnutls_free 40# define MHD_gnutls_afree MHD_gnutls_free
41#endif 41#endif
42 42
43#ifdef HAVE_ALLOCA 43#ifdef HAVE_ALLOCA
44# ifdef HAVE_ALLOCA_H 44# ifdef HAVE_ALLOCA_H
45# include <alloca.h> 45# include <alloca.h>
46# endif 46# endif
47# ifndef gnutls_alloca 47# ifndef MHD_gnutls_alloca
48# define gnutls_alloca alloca 48# define MHD_gnutls_alloca alloca
49# define gnutls_afree(x) 49# define MHD_gnutls_afree(x)
50# endif 50# endif
51#else 51#else
52# ifndef gnutls_alloca 52# ifndef MHD_gnutls_alloca
53# define gnutls_alloca gnutls_malloc 53# define MHD_gnutls_alloca MHD_gnutls_malloc
54# define gnutls_afree gnutls_free 54# define MHD_gnutls_afree MHD_gnutls_free
55# endif 55# endif
56#endif /* HAVE_ALLOCA */ 56#endif /* HAVE_ALLOCA */
57 57
58extern int (*_gnutls_is_secure_memory) (const void *); 58extern int (*MHD__gnutls_is_secure_memory) (const void *);
59 59
60/* this realloc function will return ptr if size==0, and 60/* this realloc function will return ptr if size==0, and
61 * will free the ptr if the new allocation failed. 61 * will free the ptr if the new allocation failed.
62 */ 62 */
63void *mhd_gtls_realloc_fast (void *ptr, size_t size); 63void *MHD_gtls_realloc_fast (void *ptr, size_t size);
64 64
65svoid *mhd_gtls_secure_calloc (size_t nmemb, size_t size); 65svoid *MHD_gtls_secure_calloc (size_t nmemb, size_t size);
66 66
67void *mhd_gtls_calloc (size_t nmemb, size_t size); 67void *MHD_gtls_calloc (size_t nmemb, size_t size);
68char *mhd_gtls_strdup (const char *); 68char *MHD_gtls_strdup (const char *);
69 69
70#endif /* GNUTLS_MEM_H */ 70#endif /* GNUTLS_MEM_H */
diff --git a/src/daemon/https/tls/gnutls_mpi.c b/src/daemon/https/tls/gnutls_mpi.c
index 10831b71..034b189f 100644
--- a/src/daemon/https/tls/gnutls_mpi.c
+++ b/src/daemon/https/tls/gnutls_mpi.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37void 37void
38mhd_gtls_mpi_release (mpi_t * x) 38MHD_gtls_mpi_release (mpi_t * x)
39{ 39{
40 if (*x == NULL) 40 if (*x == NULL)
41 return; 41 return;
@@ -46,7 +46,7 @@ mhd_gtls_mpi_release (mpi_t * x)
46/* returns zero on success 46/* returns zero on success
47 */ 47 */
48int 48int
49mhd_gtls_mpi_scan (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes) 49MHD_gtls_mpi_scan (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes)
50{ 50{
51 int ret; 51 int ret;
52 52
@@ -60,7 +60,7 @@ mhd_gtls_mpi_scan (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes)
60/* returns zero on success. Fails if the number is zero. 60/* returns zero on success. Fails if the number is zero.
61 */ 61 */
62int 62int
63mhd_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes) 63MHD_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes)
64{ 64{
65 int ret; 65 int ret;
66 66
@@ -70,9 +70,9 @@ mhd_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes)
70 70
71 /* MPIs with 0 bits are illegal 71 /* MPIs with 0 bits are illegal
72 */ 72 */
73 if (_gnutls_mpi_get_nbits (*ret_mpi) == 0) 73 if (MHD__gnutls_mpi_get_nbits (*ret_mpi) == 0)
74 { 74 {
75 mhd_gtls_mpi_release (ret_mpi); 75 MHD_gtls_mpi_release (ret_mpi);
76 return GNUTLS_E_MPI_SCAN_FAILED; 76 return GNUTLS_E_MPI_SCAN_FAILED;
77 } 77 }
78 78
@@ -80,7 +80,7 @@ mhd_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer, size_t * nbytes)
80} 80}
81 81
82int 82int
83mhd_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer, 83MHD_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer,
84 size_t * nbytes) 84 size_t * nbytes)
85{ 85{
86 int ret; 86 int ret;
@@ -90,9 +90,9 @@ mhd_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer,
90 90
91 /* MPIs with 0 bits are illegal 91 /* MPIs with 0 bits are illegal
92 */ 92 */
93 if (_gnutls_mpi_get_nbits (*ret_mpi) == 0) 93 if (MHD__gnutls_mpi_get_nbits (*ret_mpi) == 0)
94 { 94 {
95 mhd_gtls_mpi_release (ret_mpi); 95 MHD_gtls_mpi_release (ret_mpi);
96 return GNUTLS_E_MPI_SCAN_FAILED; 96 return GNUTLS_E_MPI_SCAN_FAILED;
97 } 97 }
98 98
@@ -100,7 +100,7 @@ mhd_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer,
100} 100}
101 101
102int 102int
103mhd_gtls_mpi_print (void *buffer, size_t * nbytes, const mpi_t a) 103MHD_gtls_mpi_print (void *buffer, size_t * nbytes, const mpi_t a)
104{ 104{
105 int ret; 105 int ret;
106 106
@@ -116,7 +116,7 @@ mhd_gtls_mpi_print (void *buffer, size_t * nbytes, const mpi_t a)
116 116
117/* Always has the first bit zero */ 117/* Always has the first bit zero */
118int 118int
119mhd_gtls_mpi_print_lz (void *buffer, size_t * nbytes, const mpi_t a) 119MHD_gtls_mpi_print_lz (void *buffer, size_t * nbytes, const mpi_t a)
120{ 120{
121 int ret; 121 int ret;
122 122
@@ -132,7 +132,7 @@ mhd_gtls_mpi_print_lz (void *buffer, size_t * nbytes, const mpi_t a)
132 132
133/* Always has the first bit zero */ 133/* Always has the first bit zero */
134int 134int
135mhd_gtls_mpi_dprint_lz (gnutls_datum_t * dest, const mpi_t a) 135MHD_gtls_mpi_dprint_lz (MHD_gnutls_datum_t * dest, const mpi_t a)
136{ 136{
137 int ret; 137 int ret;
138 opaque *buf = NULL; 138 opaque *buf = NULL;
@@ -144,7 +144,7 @@ mhd_gtls_mpi_dprint_lz (gnutls_datum_t * dest, const mpi_t a)
144 gcry_mpi_print (GCRYMPI_FMT_STD, NULL, 0, &bytes, a); 144 gcry_mpi_print (GCRYMPI_FMT_STD, NULL, 0, &bytes, a);
145 145
146 if (bytes != 0) 146 if (bytes != 0)
147 buf = gnutls_malloc (bytes); 147 buf = MHD_gnutls_malloc (bytes);
148 if (buf == NULL) 148 if (buf == NULL)
149 return GNUTLS_E_MEMORY_ERROR; 149 return GNUTLS_E_MEMORY_ERROR;
150 150
@@ -156,12 +156,12 @@ mhd_gtls_mpi_dprint_lz (gnutls_datum_t * dest, const mpi_t a)
156 return 0; 156 return 0;
157 } 157 }
158 158
159 gnutls_free (buf); 159 MHD_gnutls_free (buf);
160 return GNUTLS_E_MPI_PRINT_FAILED; 160 return GNUTLS_E_MPI_PRINT_FAILED;
161} 161}
162 162
163int 163int
164mhd_gtls_mpi_dprint (gnutls_datum_t * dest, const mpi_t a) 164MHD_gtls_mpi_dprint (MHD_gnutls_datum_t * dest, const mpi_t a)
165{ 165{
166 int ret; 166 int ret;
167 opaque *buf = NULL; 167 opaque *buf = NULL;
@@ -173,7 +173,7 @@ mhd_gtls_mpi_dprint (gnutls_datum_t * dest, const mpi_t a)
173 gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &bytes, a); 173 gcry_mpi_print (GCRYMPI_FMT_USG, NULL, 0, &bytes, a);
174 174
175 if (bytes != 0) 175 if (bytes != 0)
176 buf = gnutls_malloc (bytes); 176 buf = MHD_gnutls_malloc (bytes);
177 if (buf == NULL) 177 if (buf == NULL)
178 return GNUTLS_E_MEMORY_ERROR; 178 return GNUTLS_E_MEMORY_ERROR;
179 179
@@ -185,7 +185,7 @@ mhd_gtls_mpi_dprint (gnutls_datum_t * dest, const mpi_t a)
185 return 0; 185 return 0;
186 } 186 }
187 187
188 gnutls_free (buf); 188 MHD_gnutls_free (buf);
189 return GNUTLS_E_MPI_PRINT_FAILED; 189 return GNUTLS_E_MPI_PRINT_FAILED;
190} 190}
191 191
@@ -195,7 +195,7 @@ mhd_gtls_mpi_dprint (gnutls_datum_t * dest, const mpi_t a)
195 * steps. 195 * steps.
196 */ 196 */
197int 197int
198_gnutls_x509_read_int (ASN1_TYPE node, const char *value, mpi_t * ret_mpi) 198MHD__gnutls_x509_read_int (ASN1_TYPE node, const char *value, mpi_t * ret_mpi)
199{ 199{
200 int result; 200 int result;
201 size_t s_len; 201 size_t s_len;
@@ -203,37 +203,37 @@ _gnutls_x509_read_int (ASN1_TYPE node, const char *value, mpi_t * ret_mpi)
203 int tmpstr_size; 203 int tmpstr_size;
204 204
205 tmpstr_size = 0; 205 tmpstr_size = 0;
206 result = asn1_read_value (node, value, NULL, &tmpstr_size); 206 result = MHD__asn1_read_value (node, value, NULL, &tmpstr_size);
207 if (result != ASN1_MEM_ERROR) 207 if (result != ASN1_MEM_ERROR)
208 { 208 {
209 gnutls_assert (); 209 MHD_gnutls_assert ();
210 return mhd_gtls_asn2err (result); 210 return MHD_gtls_asn2err (result);
211 } 211 }
212 212
213 tmpstr = gnutls_alloca (tmpstr_size); 213 tmpstr = MHD_gnutls_alloca (tmpstr_size);
214 if (tmpstr == NULL) 214 if (tmpstr == NULL)
215 { 215 {
216 gnutls_assert (); 216 MHD_gnutls_assert ();
217 return GNUTLS_E_MEMORY_ERROR; 217 return GNUTLS_E_MEMORY_ERROR;
218 } 218 }
219 219
220 result = asn1_read_value (node, value, tmpstr, &tmpstr_size); 220 result = MHD__asn1_read_value (node, value, tmpstr, &tmpstr_size);
221 if (result != ASN1_SUCCESS) 221 if (result != ASN1_SUCCESS)
222 { 222 {
223 gnutls_assert (); 223 MHD_gnutls_assert ();
224 gnutls_afree (tmpstr); 224 MHD_gnutls_afree (tmpstr);
225 return mhd_gtls_asn2err (result); 225 return MHD_gtls_asn2err (result);
226 } 226 }
227 227
228 s_len = tmpstr_size; 228 s_len = tmpstr_size;
229 if (mhd_gtls_mpi_scan (ret_mpi, tmpstr, &s_len) != 0) 229 if (MHD_gtls_mpi_scan (ret_mpi, tmpstr, &s_len) != 0)
230 { 230 {
231 gnutls_assert (); 231 MHD_gnutls_assert ();
232 gnutls_afree (tmpstr); 232 MHD_gnutls_afree (tmpstr);
233 return GNUTLS_E_MPI_SCAN_FAILED; 233 return GNUTLS_E_MPI_SCAN_FAILED;
234 } 234 }
235 235
236 gnutls_afree (tmpstr); 236 MHD_gnutls_afree (tmpstr);
237 237
238 return 0; 238 return 0;
239} 239}
@@ -241,7 +241,7 @@ _gnutls_x509_read_int (ASN1_TYPE node, const char *value, mpi_t * ret_mpi)
241/* Writes the specified integer into the specified node. 241/* Writes the specified integer into the specified node.
242 */ 242 */
243int 243int
244_gnutls_x509_write_int (ASN1_TYPE node, const char *value, mpi_t mpi, int lz) 244MHD__gnutls_x509_write_int (ASN1_TYPE node, const char *value, mpi_t mpi, int lz)
245{ 245{
246 opaque *tmpstr; 246 opaque *tmpstr;
247 size_t s_len; 247 size_t s_len;
@@ -249,37 +249,37 @@ _gnutls_x509_write_int (ASN1_TYPE node, const char *value, mpi_t mpi, int lz)
249 249
250 s_len = 0; 250 s_len = 0;
251 if (lz) 251 if (lz)
252 result = mhd_gtls_mpi_print_lz (NULL, &s_len, mpi); 252 result = MHD_gtls_mpi_print_lz (NULL, &s_len, mpi);
253 else 253 else
254 result = mhd_gtls_mpi_print (NULL, &s_len, mpi); 254 result = MHD_gtls_mpi_print (NULL, &s_len, mpi);
255 255
256 tmpstr = gnutls_alloca (s_len); 256 tmpstr = MHD_gnutls_alloca (s_len);
257 if (tmpstr == NULL) 257 if (tmpstr == NULL)
258 { 258 {
259 gnutls_assert (); 259 MHD_gnutls_assert ();
260 return GNUTLS_E_MEMORY_ERROR; 260 return GNUTLS_E_MEMORY_ERROR;
261 } 261 }
262 262
263 if (lz) 263 if (lz)
264 result = mhd_gtls_mpi_print_lz (tmpstr, &s_len, mpi); 264 result = MHD_gtls_mpi_print_lz (tmpstr, &s_len, mpi);
265 else 265 else
266 result = mhd_gtls_mpi_print (tmpstr, &s_len, mpi); 266 result = MHD_gtls_mpi_print (tmpstr, &s_len, mpi);
267 267
268 if (result != 0) 268 if (result != 0)
269 { 269 {
270 gnutls_assert (); 270 MHD_gnutls_assert ();
271 gnutls_afree (tmpstr); 271 MHD_gnutls_afree (tmpstr);
272 return GNUTLS_E_MPI_PRINT_FAILED; 272 return GNUTLS_E_MPI_PRINT_FAILED;
273 } 273 }
274 274
275 result = asn1_write_value (node, value, tmpstr, s_len); 275 result = MHD__asn1_write_value (node, value, tmpstr, s_len);
276 276
277 gnutls_afree (tmpstr); 277 MHD_gnutls_afree (tmpstr);
278 278
279 if (result != ASN1_SUCCESS) 279 if (result != ASN1_SUCCESS)
280 { 280 {
281 gnutls_assert (); 281 MHD_gnutls_assert ();
282 return mhd_gtls_asn2err (result); 282 return MHD_gtls_asn2err (result);
283 } 283 }
284 284
285 return 0; 285 return 0;
diff --git a/src/daemon/https/tls/gnutls_mpi.h b/src/daemon/https/tls/gnutls_mpi.h
index 24d60c8a..ec633ca0 100644
--- a/src/daemon/https/tls/gnutls_mpi.h
+++ b/src/daemon/https/tls/gnutls_mpi.h
@@ -33,46 +33,46 @@
33 33
34typedef gcry_mpi_t mpi_t; 34typedef gcry_mpi_t mpi_t;
35 35
36#define _gnutls_mpi_cmp gcry_mpi_cmp 36#define MHD__gnutls_mpi_cmp gcry_mpi_cmp
37#define _gnutls_mpi_cmp_ui gcry_mpi_cmp_ui 37#define MHD__gnutls_mpi_cmp_ui gcry_mpi_cmp_ui
38#define _gnutls_mpi_mod gcry_mpi_mod 38#define MHD__gnutls_mpi_mod gcry_mpi_mod
39#define _gnutls_mpi_new gcry_mpi_new 39#define MHD__gnutls_mpi_new gcry_mpi_new
40#define _gnutls_mpi_snew gcry_mpi_snew 40#define MHD__gnutls_mpi_snew gcry_mpi_snew
41#define _gnutls_mpi_copy gcry_mpi_copy 41#define MHD__gnutls_mpi_copy gcry_mpi_copy
42#define _gnutls_mpi_set_ui gcry_mpi_set_ui 42#define MHD__gnutls_mpi_set_ui gcry_mpi_set_ui
43#define _gnutls_mpi_set gcry_mpi_set 43#define MHD__gnutls_mpi_set gcry_mpi_set
44#define _gnutls_mpi_randomize gcry_mpi_randomize 44#define MHD__gnutls_mpi_randomize gcry_mpi_randomize
45#define _gnutls_mpi_get_nbits gcry_mpi_get_nbits 45#define MHD__gnutls_mpi_get_nbits gcry_mpi_get_nbits
46#define _gnutls_mpi_powm gcry_mpi_powm 46#define MHD__gnutls_mpi_powm gcry_mpi_powm
47#define _gnutls_mpi_invm gcry_mpi_invm 47#define MHD__gnutls_mpi_invm gcry_mpi_invm
48#define _gnutls_mpi_addm gcry_mpi_addm 48#define MHD__gnutls_mpi_addm gcry_mpi_addm
49#define _gnutls_mpi_subm gcry_mpi_subm 49#define MHD__gnutls_mpi_subm gcry_mpi_subm
50#define _gnutls_mpi_sub_ui gcry_mpi_sub_ui 50#define MHD__gnutls_mpi_sub_ui gcry_mpi_sub_ui
51#define _gnutls_mpi_mulm gcry_mpi_mulm 51#define MHD__gnutls_mpi_mulm gcry_mpi_mulm
52#define _gnutls_mpi_mul gcry_mpi_mul 52#define MHD__gnutls_mpi_mul gcry_mpi_mul
53#define _gnutls_mpi_add gcry_mpi_add 53#define MHD__gnutls_mpi_add gcry_mpi_add
54#define _gnutls_mpi_add_ui gcry_mpi_add_ui 54#define MHD__gnutls_mpi_add_ui gcry_mpi_add_ui
55#define _gnutls_mpi_sub_ui gcry_mpi_sub_ui 55#define MHD__gnutls_mpi_sub_ui gcry_mpi_sub_ui
56#define _gnutls_mpi_mul_ui gcry_mpi_mul_ui 56#define MHD__gnutls_mpi_mul_ui gcry_mpi_mul_ui
57#define _gnutls_prime_check gcry_prime_check 57#define MHD__gnutls_prime_check gcry_prime_check
58#define _gnutls_mpi_div gcry_mpi_div 58#define MHD__gnutls_mpi_div gcry_mpi_div
59 59
60#define _gnutls_mpi_alloc_like(x) _gnutls_mpi_new(_gnutls_mpi_get_nbits(x)) 60#define MHD__gnutls_mpi_alloc_like(x) MHD__gnutls_mpi_new(MHD__gnutls_mpi_get_nbits(x))
61#define _gnutls_mpi_salloc_like(x) _gnutls_mpi_snew(_gnutls_mpi_get_nbits(x)) 61#define MHD__gnutls_mpi_salloc_like(x) MHD__gnutls_mpi_snew(MHD__gnutls_mpi_get_nbits(x))
62 62
63void mhd_gtls_mpi_release (mpi_t * x); 63void MHD_gtls_mpi_release (mpi_t * x);
64 64
65int mhd_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer, 65int MHD_gtls_mpi_scan_nz (mpi_t * ret_mpi, const opaque * buffer,
66 size_t * nbytes); 66 size_t * nbytes);
67int mhd_gtls_mpi_scan (mpi_t * ret_mpi, const opaque * buffer, 67int MHD_gtls_mpi_scan (mpi_t * ret_mpi, const opaque * buffer,
68 size_t * nbytes); 68 size_t * nbytes);
69int mhd_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer, 69int MHD_gtls_mpi_scan_pgp (mpi_t * ret_mpi, const opaque * buffer,
70 size_t * nbytes); 70 size_t * nbytes);
71 71
72int mhd_gtls_mpi_print (void *buffer, size_t * nbytes, const mpi_t a); 72int MHD_gtls_mpi_print (void *buffer, size_t * nbytes, const mpi_t a);
73int mhd_gtls_mpi_print_lz (void *buffer, size_t * nbytes, const mpi_t a); 73int MHD_gtls_mpi_print_lz (void *buffer, size_t * nbytes, const mpi_t a);
74 74
75int mhd_gtls_mpi_dprint_lz (gnutls_datum_t * dest, const mpi_t a); 75int MHD_gtls_mpi_dprint_lz (MHD_gnutls_datum_t * dest, const mpi_t a);
76int mhd_gtls_mpi_dprint (gnutls_datum_t * dest, const mpi_t a); 76int MHD_gtls_mpi_dprint (MHD_gnutls_datum_t * dest, const mpi_t a);
77 77
78#endif 78#endif
diff --git a/src/daemon/https/tls/gnutls_num.c b/src/daemon/https/tls/gnutls_num.c
index ab5c7196..06d2e4eb 100644
--- a/src/daemon/https/tls/gnutls_num.c
+++ b/src/daemon/https/tls/gnutls_num.c
@@ -35,7 +35,7 @@
35 * has been reached. 35 * has been reached.
36 */ 36 */
37int 37int
38mhd_gtls_uint64pp (uint64 * x) 38MHD_gtls_uint64pp (uint64 * x)
39{ 39{
40 register int i, y = 0; 40 register int i, y = 0;
41 41
@@ -60,7 +60,7 @@ mhd_gtls_uint64pp (uint64 * x)
60} 60}
61 61
62uint32_t 62uint32_t
63mhd_gtls_uint24touint32 (uint24 num) 63MHD_gtls_uint24touint32 (uint24 num)
64{ 64{
65 uint32_t ret = 0; 65 uint32_t ret = 0;
66 66
@@ -71,7 +71,7 @@ mhd_gtls_uint24touint32 (uint24 num)
71} 71}
72 72
73uint24 73uint24
74mhd_gtls_uint32touint24 (uint32_t num) 74MHD_gtls_uint32touint24 (uint32_t num)
75{ 75{
76 uint24 ret; 76 uint24 ret;
77 77
@@ -84,7 +84,7 @@ mhd_gtls_uint32touint24 (uint32_t num)
84 84
85/* data should be at least 3 bytes */ 85/* data should be at least 3 bytes */
86uint32_t 86uint32_t
87mhd_gtls_read_uint24 (const opaque * data) 87MHD_gtls_read_uint24 (const opaque * data)
88{ 88{
89 uint32_t res; 89 uint32_t res;
90 uint24 num; 90 uint24 num;
@@ -93,7 +93,7 @@ mhd_gtls_read_uint24 (const opaque * data)
93 num.pint[1] = data[1]; 93 num.pint[1] = data[1];
94 num.pint[2] = data[2]; 94 num.pint[2] = data[2];
95 95
96 res = mhd_gtls_uint24touint32 (num); 96 res = MHD_gtls_uint24touint32 (num);
97#ifndef WORDS_BIGENDIAN 97#ifndef WORDS_BIGENDIAN
98 res = byteswap32 (res); 98 res = byteswap32 (res);
99#endif 99#endif
@@ -101,14 +101,14 @@ mhd_gtls_read_uint24 (const opaque * data)
101} 101}
102 102
103void 103void
104mhd_gtls_write_uint24 (uint32_t num, opaque * data) 104MHD_gtls_write_uint24 (uint32_t num, opaque * data)
105{ 105{
106 uint24 tmp; 106 uint24 tmp;
107 107
108#ifndef WORDS_BIGENDIAN 108#ifndef WORDS_BIGENDIAN
109 num = byteswap32 (num); 109 num = byteswap32 (num);
110#endif 110#endif
111 tmp = mhd_gtls_uint32touint24 (num); 111 tmp = MHD_gtls_uint32touint24 (num);
112 112
113 data[0] = tmp.pint[0]; 113 data[0] = tmp.pint[0];
114 data[1] = tmp.pint[1]; 114 data[1] = tmp.pint[1];
@@ -116,7 +116,7 @@ mhd_gtls_write_uint24 (uint32_t num, opaque * data)
116} 116}
117 117
118uint32_t 118uint32_t
119mhd_gtls_read_uint32 (const opaque * data) 119MHD_gtls_read_uint32 (const opaque * data)
120{ 120{
121 uint32_t res; 121 uint32_t res;
122 122
@@ -128,7 +128,7 @@ mhd_gtls_read_uint32 (const opaque * data)
128} 128}
129 129
130void 130void
131mhd_gtls_write_uint32 (uint32_t num, opaque * data) 131MHD_gtls_write_uint32 (uint32_t num, opaque * data)
132{ 132{
133 133
134#ifndef WORDS_BIGENDIAN 134#ifndef WORDS_BIGENDIAN
@@ -138,7 +138,7 @@ mhd_gtls_write_uint32 (uint32_t num, opaque * data)
138} 138}
139 139
140uint16_t 140uint16_t
141mhd_gtls_read_uint16 (const opaque * data) 141MHD_gtls_read_uint16 (const opaque * data)
142{ 142{
143 uint16_t res; 143 uint16_t res;
144 memcpy (&res, data, sizeof (uint16_t)); 144 memcpy (&res, data, sizeof (uint16_t));
@@ -149,7 +149,7 @@ mhd_gtls_read_uint16 (const opaque * data)
149} 149}
150 150
151void 151void
152mhd_gtls_write_uint16 (uint16_t num, opaque * data) 152MHD_gtls_write_uint16 (uint16_t num, opaque * data)
153{ 153{
154 154
155#ifndef WORDS_BIGENDIAN 155#ifndef WORDS_BIGENDIAN
@@ -159,7 +159,7 @@ mhd_gtls_write_uint16 (uint16_t num, opaque * data)
159} 159}
160 160
161uint32_t 161uint32_t
162mhd_gtls_conv_uint32 (uint32_t data) 162MHD_gtls_conv_uint32 (uint32_t data)
163{ 163{
164#ifndef WORDS_BIGENDIAN 164#ifndef WORDS_BIGENDIAN
165 return byteswap32 (data); 165 return byteswap32 (data);
@@ -169,7 +169,7 @@ mhd_gtls_conv_uint32 (uint32_t data)
169} 169}
170 170
171uint16_t 171uint16_t
172mhd_gtls_conv_uint16 (uint16_t data) 172MHD_gtls_conv_uint16 (uint16_t data)
173{ 173{
174#ifndef WORDS_BIGENDIAN 174#ifndef WORDS_BIGENDIAN
175 return byteswap16 (data); 175 return byteswap16 (data);
@@ -179,7 +179,7 @@ mhd_gtls_conv_uint16 (uint16_t data)
179} 179}
180 180
181uint32_t 181uint32_t
182mhd_gtls_uint64touint32 (const uint64 * num) 182MHD_gtls_uint64touint32 (const uint64 * num)
183{ 183{
184 uint32_t ret; 184 uint32_t ret;
185 185
diff --git a/src/daemon/https/tls/gnutls_num.h b/src/daemon/https/tls/gnutls_num.h
index 37ce0c6d..13d1e3ae 100644
--- a/src/daemon/https/tls/gnutls_num.h
+++ b/src/daemon/https/tls/gnutls_num.h
@@ -32,18 +32,18 @@
32#define byteswap16(x) ((rotl16(x, 8) & 0x00ff) | (rotr16(x, 8) & 0xff00)) 32#define byteswap16(x) ((rotl16(x, 8) & 0x00ff) | (rotr16(x, 8) & 0xff00))
33#define byteswap32(x) ((rotl32(x, 8) & 0x00ff00ffUL) | (rotr32(x, 8) & 0xff00ff00UL)) 33#define byteswap32(x) ((rotl32(x, 8) & 0x00ff00ffUL) | (rotr32(x, 8) & 0xff00ff00UL))
34 34
35uint32_t mhd_gtls_uint24touint32 (uint24 num); 35uint32_t MHD_gtls_uint24touint32 (uint24 num);
36uint24 mhd_gtls_uint32touint24 (uint32_t num); 36uint24 MHD_gtls_uint32touint24 (uint32_t num);
37uint32_t mhd_gtls_read_uint32 (const opaque * data); 37uint32_t MHD_gtls_read_uint32 (const opaque * data);
38uint16_t mhd_gtls_read_uint16 (const opaque * data); 38uint16_t MHD_gtls_read_uint16 (const opaque * data);
39uint32_t mhd_gtls_conv_uint32 (uint32_t data); 39uint32_t MHD_gtls_conv_uint32 (uint32_t data);
40uint16_t mhd_gtls_conv_uint16 (uint16_t data); 40uint16_t MHD_gtls_conv_uint16 (uint16_t data);
41uint32_t mhd_gtls_read_uint24 (const opaque * data); 41uint32_t MHD_gtls_read_uint24 (const opaque * data);
42void mhd_gtls_write_uint24 (uint32_t num, opaque * data); 42void MHD_gtls_write_uint24 (uint32_t num, opaque * data);
43void mhd_gtls_write_uint32 (uint32_t num, opaque * data); 43void MHD_gtls_write_uint32 (uint32_t num, opaque * data);
44void mhd_gtls_write_uint16 (uint16_t num, opaque * data); 44void MHD_gtls_write_uint16 (uint16_t num, opaque * data);
45uint32_t mhd_gtls_uint64touint32 (const uint64 *); 45uint32_t MHD_gtls_uint64touint32 (const uint64 *);
46 46
47int mhd_gtls_uint64pp (uint64 *); 47int MHD_gtls_uint64pp (uint64 *);
48# define _gnutls_uint64zero(x) x.i[0] = x.i[1] = x.i[2] = x.i[3] = x.i[4] = x.i[5] = x.i[6] = x.i[7] = 0 48# define MHD__gnutls_uint64zero(x) x.i[0] = x.i[1] = x.i[2] = x.i[3] = x.i[4] = x.i[5] = x.i[6] = x.i[7] = 0
49# define UINT64DATA(x) x.i 49# define UINT64DATA(x) x.i
diff --git a/src/daemon/https/tls/gnutls_pk.c b/src/daemon/https/tls/gnutls_pk.c
index 20f17951..53bc6394 100644
--- a/src/daemon/https/tls/gnutls_pk.c
+++ b/src/daemon/https/tls/gnutls_pk.c
@@ -40,13 +40,13 @@
40#include "common.h" 40#include "common.h"
41#include "mpi.h" 41#include "mpi.h"
42 42
43static int _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data, 43static int MHD__gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
44 mpi_t * pkey, int pkey_len); 44 mpi_t * pkey, int pkey_len);
45static int _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, 45static int MHD__gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash,
46 mpi_t * pkey, int); 46 mpi_t * pkey, int);
47static int _gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data, 47static int MHD__gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
48 mpi_t * pkey, int); 48 mpi_t * pkey, int);
49static int _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, 49static int MHD__gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data,
50 mpi_t * pkey, int); 50 mpi_t * pkey, int);
51 51
52 52
@@ -54,8 +54,8 @@ static int _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data,
54 * params is modulus, public exp. 54 * params is modulus, public exp.
55 */ 55 */
56int 56int
57mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext, 57MHD_gtls_pkcs1_rsa_encrypt (MHD_gnutls_datum_t * ciphertext,
58 const gnutls_datum_t * plaintext, 58 const MHD_gnutls_datum_t * plaintext,
59 mpi_t * params, unsigned params_len, 59 mpi_t * params, unsigned params_len,
60 unsigned btype) 60 unsigned btype)
61{ 61{
@@ -66,21 +66,21 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
66 size_t k, psize; 66 size_t k, psize;
67 size_t mod_bits; 67 size_t mod_bits;
68 68
69 mod_bits = _gnutls_mpi_get_nbits (params[0]); 69 mod_bits = MHD__gnutls_mpi_get_nbits (params[0]);
70 k = mod_bits / 8; 70 k = mod_bits / 8;
71 if (mod_bits % 8 != 0) 71 if (mod_bits % 8 != 0)
72 k++; 72 k++;
73 73
74 if (plaintext->size > k - 11) 74 if (plaintext->size > k - 11)
75 { 75 {
76 gnutls_assert (); 76 MHD_gnutls_assert ();
77 return GNUTLS_E_PK_ENCRYPTION_FAILED; 77 return GNUTLS_E_PK_ENCRYPTION_FAILED;
78 } 78 }
79 79
80 edata = gnutls_alloca (k); 80 edata = MHD_gnutls_alloca (k);
81 if (edata == NULL) 81 if (edata == NULL)
82 { 82 {
83 gnutls_assert (); 83 MHD_gnutls_assert ();
84 return GNUTLS_E_MEMORY_ERROR; 84 return GNUTLS_E_MEMORY_ERROR;
85 } 85 }
86 86
@@ -99,24 +99,24 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
99 /* using public key */ 99 /* using public key */
100 if (params_len < RSA_PUBLIC_PARAMS) 100 if (params_len < RSA_PUBLIC_PARAMS)
101 { 101 {
102 gnutls_assert (); 102 MHD_gnutls_assert ();
103 gnutls_afree (edata); 103 MHD_gnutls_afree (edata);
104 return GNUTLS_E_INTERNAL_ERROR; 104 return GNUTLS_E_INTERNAL_ERROR;
105 } 105 }
106 106
107 if (gc_pseudo_random (ps, psize) != GC_OK) 107 if (MHD_gc_pseudo_random (ps, psize) != GC_OK)
108 { 108 {
109 gnutls_assert (); 109 MHD_gnutls_assert ();
110 gnutls_afree (edata); 110 MHD_gnutls_afree (edata);
111 return GNUTLS_E_RANDOM_FAILED; 111 return GNUTLS_E_RANDOM_FAILED;
112 } 112 }
113 for (i = 0; i < psize; i++) 113 for (i = 0; i < psize; i++)
114 while (ps[i] == 0) 114 while (ps[i] == 0)
115 { 115 {
116 if (gc_pseudo_random (&ps[i], 1) != GC_OK) 116 if (MHD_gc_pseudo_random (&ps[i], 1) != GC_OK)
117 { 117 {
118 gnutls_assert (); 118 MHD_gnutls_assert ();
119 gnutls_afree (edata); 119 MHD_gnutls_afree (edata);
120 return GNUTLS_E_RANDOM_FAILED; 120 return GNUTLS_E_RANDOM_FAILED;
121 } 121 }
122 } 122 }
@@ -126,8 +126,8 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
126 126
127 if (params_len < RSA_PRIVATE_PARAMS) 127 if (params_len < RSA_PRIVATE_PARAMS)
128 { 128 {
129 gnutls_assert (); 129 MHD_gnutls_assert ();
130 gnutls_afree (edata); 130 MHD_gnutls_afree (edata);
131 return GNUTLS_E_INTERNAL_ERROR; 131 return GNUTLS_E_INTERNAL_ERROR;
132 } 132 }
133 133
@@ -135,36 +135,36 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
135 ps[i] = 0xff; 135 ps[i] = 0xff;
136 break; 136 break;
137 default: 137 default:
138 gnutls_assert (); 138 MHD_gnutls_assert ();
139 gnutls_afree (edata); 139 MHD_gnutls_afree (edata);
140 return GNUTLS_E_INTERNAL_ERROR; 140 return GNUTLS_E_INTERNAL_ERROR;
141 } 141 }
142 142
143 ps[psize] = 0; 143 ps[psize] = 0;
144 memcpy (&ps[psize + 1], plaintext->data, plaintext->size); 144 memcpy (&ps[psize + 1], plaintext->data, plaintext->size);
145 145
146 if (mhd_gtls_mpi_scan_nz (&m, edata, &k) != 0) 146 if (MHD_gtls_mpi_scan_nz (&m, edata, &k) != 0)
147 { 147 {
148 gnutls_assert (); 148 MHD_gnutls_assert ();
149 gnutls_afree (edata); 149 MHD_gnutls_afree (edata);
150 return GNUTLS_E_MPI_SCAN_FAILED; 150 return GNUTLS_E_MPI_SCAN_FAILED;
151 } 151 }
152 gnutls_afree (edata); 152 MHD_gnutls_afree (edata);
153 153
154 if (btype == 2) /* encrypt */ 154 if (btype == 2) /* encrypt */
155 ret = _gnutls_pk_encrypt (GCRY_PK_RSA, &res, m, params, params_len); 155 ret = MHD__gnutls_pk_encrypt (GCRY_PK_RSA, &res, m, params, params_len);
156 else /* sign */ 156 else /* sign */
157 ret = _gnutls_pk_sign (GCRY_PK_RSA, &res, m, params, params_len); 157 ret = MHD__gnutls_pk_sign (GCRY_PK_RSA, &res, m, params, params_len);
158 158
159 mhd_gtls_mpi_release (&m); 159 MHD_gtls_mpi_release (&m);
160 160
161 if (ret < 0) 161 if (ret < 0)
162 { 162 {
163 gnutls_assert (); 163 MHD_gnutls_assert ();
164 return ret; 164 return ret;
165 } 165 }
166 166
167 mhd_gtls_mpi_print (NULL, &psize, res); 167 MHD_gtls_mpi_print (NULL, &psize, res);
168 168
169 if (psize < k) 169 if (psize < k)
170 { 170 {
@@ -179,25 +179,25 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
179 else 179 else
180 { /* psize > k !!! */ 180 { /* psize > k !!! */
181 /* This is an impossible situation */ 181 /* This is an impossible situation */
182 gnutls_assert (); 182 MHD_gnutls_assert ();
183 mhd_gtls_mpi_release (&res); 183 MHD_gtls_mpi_release (&res);
184 return GNUTLS_E_INTERNAL_ERROR; 184 return GNUTLS_E_INTERNAL_ERROR;
185 } 185 }
186 186
187 ciphertext->data = gnutls_malloc (psize); 187 ciphertext->data = MHD_gnutls_malloc (psize);
188 if (ciphertext->data == NULL) 188 if (ciphertext->data == NULL)
189 { 189 {
190 gnutls_assert (); 190 MHD_gnutls_assert ();
191 mhd_gtls_mpi_release (&res); 191 MHD_gtls_mpi_release (&res);
192 return GNUTLS_E_MEMORY_ERROR; 192 return GNUTLS_E_MEMORY_ERROR;
193 } 193 }
194 mhd_gtls_mpi_print (&ciphertext->data[pad], &psize, res); 194 MHD_gtls_mpi_print (&ciphertext->data[pad], &psize, res);
195 for (i = 0; i < pad; i++) 195 for (i = 0; i < pad; i++)
196 ciphertext->data[i] = 0; 196 ciphertext->data[i] = 0;
197 197
198 ciphertext->size = k; 198 ciphertext->size = k;
199 199
200 mhd_gtls_mpi_release (&res); 200 MHD_gtls_mpi_release (&res);
201 201
202 return 0; 202 return 0;
203} 203}
@@ -208,8 +208,8 @@ mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext,
208 * Can decrypt block type 1 and type 2 packets. 208 * Can decrypt block type 1 and type 2 packets.
209 */ 209 */
210int 210int
211mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext, 211MHD_gtls_pkcs1_rsa_decrypt (MHD_gnutls_datum_t * plaintext,
212 const gnutls_datum_t * ciphertext, 212 const MHD_gnutls_datum_t * ciphertext,
213 mpi_t * params, unsigned params_len, 213 mpi_t * params, unsigned params_len,
214 unsigned btype) 214 unsigned btype)
215{ 215{
@@ -219,7 +219,7 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
219 opaque *edata; 219 opaque *edata;
220 size_t esize, mod_bits; 220 size_t esize, mod_bits;
221 221
222 mod_bits = _gnutls_mpi_get_nbits (params[0]); 222 mod_bits = MHD__gnutls_mpi_get_nbits (params[0]);
223 k = mod_bits / 8; 223 k = mod_bits / 8;
224 if (mod_bits % 8 != 0) 224 if (mod_bits % 8 != 0)
225 k++; 225 k++;
@@ -228,13 +228,13 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
228 228
229 if (esize != k) 229 if (esize != k)
230 { 230 {
231 gnutls_assert (); 231 MHD_gnutls_assert ();
232 return GNUTLS_E_PK_DECRYPTION_FAILED; 232 return GNUTLS_E_PK_DECRYPTION_FAILED;
233 } 233 }
234 234
235 if (mhd_gtls_mpi_scan_nz (&c, ciphertext->data, &esize) != 0) 235 if (MHD_gtls_mpi_scan_nz (&c, ciphertext->data, &esize) != 0)
236 { 236 {
237 gnutls_assert (); 237 MHD_gnutls_assert ();
238 return GNUTLS_E_MPI_SCAN_FAILED; 238 return GNUTLS_E_MPI_SCAN_FAILED;
239 } 239 }
240 240
@@ -242,30 +242,30 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
242 * available. 242 * available.
243 */ 243 */
244 if (btype == 2) 244 if (btype == 2)
245 ret = _gnutls_pk_decrypt (GCRY_PK_RSA, &res, c, params, params_len); 245 ret = MHD__gnutls_pk_decrypt (GCRY_PK_RSA, &res, c, params, params_len);
246 else 246 else
247 { 247 {
248 ret = _gnutls_pk_encrypt (GCRY_PK_RSA, &res, c, params, params_len); 248 ret = MHD__gnutls_pk_encrypt (GCRY_PK_RSA, &res, c, params, params_len);
249 } 249 }
250 mhd_gtls_mpi_release (&c); 250 MHD_gtls_mpi_release (&c);
251 251
252 if (ret < 0) 252 if (ret < 0)
253 { 253 {
254 gnutls_assert (); 254 MHD_gnutls_assert ();
255 return ret; 255 return ret;
256 } 256 }
257 257
258 mhd_gtls_mpi_print (NULL, &esize, res); 258 MHD_gtls_mpi_print (NULL, &esize, res);
259 edata = gnutls_alloca (esize + 1); 259 edata = MHD_gnutls_alloca (esize + 1);
260 if (edata == NULL) 260 if (edata == NULL)
261 { 261 {
262 gnutls_assert (); 262 MHD_gnutls_assert ();
263 mhd_gtls_mpi_release (&res); 263 MHD_gtls_mpi_release (&res);
264 return GNUTLS_E_MEMORY_ERROR; 264 return GNUTLS_E_MEMORY_ERROR;
265 } 265 }
266 mhd_gtls_mpi_print (&edata[1], &esize, res); 266 MHD_gtls_mpi_print (&edata[1], &esize, res);
267 267
268 mhd_gtls_mpi_release (&res); 268 MHD_gtls_mpi_release (&res);
269 269
270 /* EB = 00||BT||PS||00||D 270 /* EB = 00||BT||PS||00||D
271 * (use block type 'btype') 271 * (use block type 'btype')
@@ -282,8 +282,8 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
282 282
283 if (edata[0] != 0 || edata[1] != btype) 283 if (edata[0] != 0 || edata[1] != btype)
284 { 284 {
285 gnutls_assert (); 285 MHD_gnutls_assert ();
286 gnutls_afree (edata); 286 MHD_gnutls_afree (edata);
287 return GNUTLS_E_DECRYPTION_FAILED; 287 return GNUTLS_E_DECRYPTION_FAILED;
288 } 288 }
289 289
@@ -310,7 +310,7 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
310 } 310 }
311 if (edata[i] != 0xff) 311 if (edata[i] != 0xff)
312 { 312 {
313 _gnutls_handshake_log ("PKCS #1 padding error"); 313 MHD__gnutls_handshake_log ("PKCS #1 padding error");
314 /* PKCS #1 padding error. Don't use 314 /* PKCS #1 padding error. Don't use
315 GNUTLS_E_PKCS1_WRONG_PAD here. */ 315 GNUTLS_E_PKCS1_WRONG_PAD here. */
316 break; 316 break;
@@ -318,65 +318,65 @@ mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext,
318 } 318 }
319 break; 319 break;
320 default: 320 default:
321 gnutls_assert (); 321 MHD_gnutls_assert ();
322 gnutls_afree (edata); 322 MHD_gnutls_afree (edata);
323 return GNUTLS_E_DECRYPTION_FAILED; 323 return GNUTLS_E_DECRYPTION_FAILED;
324 } 324 }
325 i++; 325 i++;
326 326
327 if (ret < 0) 327 if (ret < 0)
328 { 328 {
329 gnutls_assert (); 329 MHD_gnutls_assert ();
330 gnutls_afree (edata); 330 MHD_gnutls_afree (edata);
331 return GNUTLS_E_DECRYPTION_FAILED; 331 return GNUTLS_E_DECRYPTION_FAILED;
332 } 332 }
333 333
334 if (_gnutls_sset_datum (plaintext, &edata[i], esize - i) < 0) 334 if (MHD__gnutls_sset_datum (plaintext, &edata[i], esize - i) < 0)
335 { 335 {
336 gnutls_assert (); 336 MHD_gnutls_assert ();
337 gnutls_afree (edata); 337 MHD_gnutls_afree (edata);
338 return GNUTLS_E_MEMORY_ERROR; 338 return GNUTLS_E_MEMORY_ERROR;
339 } 339 }
340 340
341 gnutls_afree (edata); 341 MHD_gnutls_afree (edata);
342 342
343 return 0; 343 return 0;
344} 344}
345 345
346 346
347int 347int
348mhd_gtls_rsa_verify (const gnutls_datum_t * vdata, 348MHD_gtls_rsa_verify (const MHD_gnutls_datum_t * vdata,
349 const gnutls_datum_t * ciphertext, mpi_t * params, 349 const MHD_gnutls_datum_t * ciphertext, mpi_t * params,
350 int params_len, int btype) 350 int params_len, int btype)
351{ 351{
352 352
353 gnutls_datum_t plain; 353 MHD_gnutls_datum_t plain;
354 int ret; 354 int ret;
355 355
356 /* decrypt signature */ 356 /* decrypt signature */
357 if ((ret = 357 if ((ret =
358 mhd_gtls_pkcs1_rsa_decrypt (&plain, ciphertext, params, params_len, 358 MHD_gtls_pkcs1_rsa_decrypt (&plain, ciphertext, params, params_len,
359 btype)) < 0) 359 btype)) < 0)
360 { 360 {
361 gnutls_assert (); 361 MHD_gnutls_assert ();
362 return ret; 362 return ret;
363 } 363 }
364 364
365 if (plain.size != vdata->size) 365 if (plain.size != vdata->size)
366 { 366 {
367 gnutls_assert (); 367 MHD_gnutls_assert ();
368 _gnutls_free_datum (&plain); 368 MHD__gnutls_free_datum (&plain);
369 return GNUTLS_E_PK_SIG_VERIFY_FAILED; 369 return GNUTLS_E_PK_SIG_VERIFY_FAILED;
370 } 370 }
371 371
372 if (memcmp (plain.data, vdata->data, plain.size) != 0) 372 if (memcmp (plain.data, vdata->data, plain.size) != 0)
373 { 373 {
374 gnutls_assert (); 374 MHD_gnutls_assert ();
375 _gnutls_free_datum (&plain); 375 MHD__gnutls_free_datum (&plain);
376 return GNUTLS_E_PK_SIG_VERIFY_FAILED; 376 return GNUTLS_E_PK_SIG_VERIFY_FAILED;
377 } 377 }
378 378
379 _gnutls_free_datum (&plain); 379 MHD__gnutls_free_datum (&plain);
380 380
381 return 0; /* ok */ 381 return 0; /* ok */
382} 382}
@@ -384,45 +384,45 @@ mhd_gtls_rsa_verify (const gnutls_datum_t * vdata,
384/* encodes the Dss-Sig-Value structure 384/* encodes the Dss-Sig-Value structure
385 */ 385 */
386static int 386static int
387encode_ber_rs (gnutls_datum_t * sig_value, mpi_t r, mpi_t s) 387encode_ber_rs (MHD_gnutls_datum_t * sig_value, mpi_t r, mpi_t s)
388{ 388{
389 ASN1_TYPE sig; 389 ASN1_TYPE sig;
390 int result, tot_len; 390 int result, tot_len;
391 391
392 if ((result = 392 if ((result =
393 asn1_create_element (_gnutls_get_gnutls_asn (), 393 MHD__asn1_create_element (MHD__gnutls_getMHD__gnutls_asn (),
394 "GNUTLS.DSASignatureValue", 394 "GNUTLS.DSASignatureValue",
395 &sig)) != ASN1_SUCCESS) 395 &sig)) != ASN1_SUCCESS)
396 { 396 {
397 gnutls_assert (); 397 MHD_gnutls_assert ();
398 return mhd_gtls_asn2err (result); 398 return MHD_gtls_asn2err (result);
399 } 399 }
400 400
401 result = _gnutls_x509_write_int (sig, "r", r, 1); 401 result = MHD__gnutls_x509_write_int (sig, "r", r, 1);
402 if (result < 0) 402 if (result < 0)
403 { 403 {
404 gnutls_assert (); 404 MHD_gnutls_assert ();
405 asn1_delete_structure (&sig); 405 MHD__asn1_delete_structure (&sig);
406 return result; 406 return result;
407 } 407 }
408 408
409 result = _gnutls_x509_write_int (sig, "s", s, 1); 409 result = MHD__gnutls_x509_write_int (sig, "s", s, 1);
410 if (result < 0) 410 if (result < 0)
411 { 411 {
412 gnutls_assert (); 412 MHD_gnutls_assert ();
413 asn1_delete_structure (&sig); 413 MHD__asn1_delete_structure (&sig);
414 return result; 414 return result;
415 } 415 }
416 416
417 tot_len = 0; 417 tot_len = 0;
418 418
419 result = _gnutls_x509_der_encode (sig, "", sig_value, 0); 419 result = MHD__gnutls_x509_der_encode (sig, "", sig_value, 0);
420 420
421 asn1_delete_structure (&sig); 421 MHD__asn1_delete_structure (&sig);
422 422
423 if (result < 0) 423 if (result < 0)
424 { 424 {
425 gnutls_assert (); 425 MHD_gnutls_assert ();
426 return result; 426 return result;
427 } 427 }
428 428
@@ -433,8 +433,8 @@ encode_ber_rs (gnutls_datum_t * sig_value, mpi_t r, mpi_t s)
433/* Do DSA signature calculation. params is p, q, g, y, x in that order. 433/* Do DSA signature calculation. params is p, q, g, y, x in that order.
434 */ 434 */
435int 435int
436mhd_gtls_dsa_sign (gnutls_datum_t * signature, 436MHD_gtls_dsa_sign (MHD_gnutls_datum_t * signature,
437 const gnutls_datum_t * hash, mpi_t * params, 437 const MHD_gnutls_datum_t * hash, mpi_t * params,
438 unsigned params_len) 438 unsigned params_len)
439{ 439{
440 mpi_t rs[2], mdata; 440 mpi_t rs[2], mdata;
@@ -444,35 +444,35 @@ mhd_gtls_dsa_sign (gnutls_datum_t * signature,
444 k = hash->size; 444 k = hash->size;
445 if (k < 20) 445 if (k < 20)
446 { /* SHA1 or better only */ 446 { /* SHA1 or better only */
447 gnutls_assert (); 447 MHD_gnutls_assert ();
448 return GNUTLS_E_PK_SIGN_FAILED; 448 return GNUTLS_E_PK_SIGN_FAILED;
449 } 449 }
450 450
451 if (mhd_gtls_mpi_scan_nz (&mdata, hash->data, &k) != 0) 451 if (MHD_gtls_mpi_scan_nz (&mdata, hash->data, &k) != 0)
452 { 452 {
453 gnutls_assert (); 453 MHD_gnutls_assert ();
454 return GNUTLS_E_MPI_SCAN_FAILED; 454 return GNUTLS_E_MPI_SCAN_FAILED;
455 } 455 }
456 456
457 ret = _gnutls_pk_sign (GCRY_PK_DSA, rs, mdata, params, params_len); 457 ret = MHD__gnutls_pk_sign (GCRY_PK_DSA, rs, mdata, params, params_len);
458 /* rs[0], rs[1] now hold r,s */ 458 /* rs[0], rs[1] now hold r,s */
459 mhd_gtls_mpi_release (&mdata); 459 MHD_gtls_mpi_release (&mdata);
460 460
461 if (ret < 0) 461 if (ret < 0)
462 { 462 {
463 gnutls_assert (); 463 MHD_gnutls_assert ();
464 return ret; 464 return ret;
465 } 465 }
466 466
467 ret = encode_ber_rs (signature, rs[0], rs[1]); 467 ret = encode_ber_rs (signature, rs[0], rs[1]);
468 468
469 /* free r,s */ 469 /* free r,s */
470 mhd_gtls_mpi_release (&rs[0]); 470 MHD_gtls_mpi_release (&rs[0]);
471 mhd_gtls_mpi_release (&rs[1]); 471 MHD_gtls_mpi_release (&rs[1]);
472 472
473 if (ret != 0) 473 if (ret != 0)
474 { 474 {
475 gnutls_assert (); 475 MHD_gnutls_assert ();
476 return GNUTLS_E_MEMORY_ERROR; 476 return GNUTLS_E_MEMORY_ERROR;
477 } 477 }
478 478
@@ -482,46 +482,46 @@ mhd_gtls_dsa_sign (gnutls_datum_t * signature,
482/* decodes the Dss-Sig-Value structure 482/* decodes the Dss-Sig-Value structure
483 */ 483 */
484static int 484static int
485decode_ber_rs (const gnutls_datum_t * sig_value, mpi_t * r, mpi_t * s) 485decode_ber_rs (const MHD_gnutls_datum_t * sig_value, mpi_t * r, mpi_t * s)
486{ 486{
487 ASN1_TYPE sig; 487 ASN1_TYPE sig;
488 int result; 488 int result;
489 489
490 if ((result = 490 if ((result =
491 asn1_create_element (_gnutls_get_gnutls_asn (), 491 MHD__asn1_create_element (MHD__gnutls_getMHD__gnutls_asn (),
492 "GNUTLS.DSASignatureValue", 492 "GNUTLS.DSASignatureValue",
493 &sig)) != ASN1_SUCCESS) 493 &sig)) != ASN1_SUCCESS)
494 { 494 {
495 gnutls_assert (); 495 MHD_gnutls_assert ();
496 return mhd_gtls_asn2err (result); 496 return MHD_gtls_asn2err (result);
497 } 497 }
498 498
499 result = asn1_der_decoding (&sig, sig_value->data, sig_value->size, NULL); 499 result = MHD__asn1_der_decoding (&sig, sig_value->data, sig_value->size, NULL);
500 if (result != ASN1_SUCCESS) 500 if (result != ASN1_SUCCESS)
501 { 501 {
502 gnutls_assert (); 502 MHD_gnutls_assert ();
503 asn1_delete_structure (&sig); 503 MHD__asn1_delete_structure (&sig);
504 return mhd_gtls_asn2err (result); 504 return MHD_gtls_asn2err (result);
505 } 505 }
506 506
507 result = _gnutls_x509_read_int (sig, "r", r); 507 result = MHD__gnutls_x509_read_int (sig, "r", r);
508 if (result < 0) 508 if (result < 0)
509 { 509 {
510 gnutls_assert (); 510 MHD_gnutls_assert ();
511 asn1_delete_structure (&sig); 511 MHD__asn1_delete_structure (&sig);
512 return result; 512 return result;
513 } 513 }
514 514
515 result = _gnutls_x509_read_int (sig, "s", s); 515 result = MHD__gnutls_x509_read_int (sig, "s", s);
516 if (result < 0) 516 if (result < 0)
517 { 517 {
518 gnutls_assert (); 518 MHD_gnutls_assert ();
519 mhd_gtls_mpi_release (s); 519 MHD_gtls_mpi_release (s);
520 asn1_delete_structure (&sig); 520 MHD__asn1_delete_structure (&sig);
521 return result; 521 return result;
522 } 522 }
523 523
524 asn1_delete_structure (&sig); 524 MHD__asn1_delete_structure (&sig);
525 525
526 return 0; 526 return 0;
527} 527}
@@ -529,8 +529,8 @@ decode_ber_rs (const gnutls_datum_t * sig_value, mpi_t * r, mpi_t * s)
529/* params is p, q, g, y in that order 529/* params is p, q, g, y in that order
530 */ 530 */
531int 531int
532mhd_gtls_dsa_verify (const gnutls_datum_t * vdata, 532MHD_gtls_dsa_verify (const MHD_gnutls_datum_t * vdata,
533 const gnutls_datum_t * sig_value, mpi_t * params, 533 const MHD_gnutls_datum_t * sig_value, mpi_t * params,
534 int params_len) 534 int params_len)
535{ 535{
536 536
@@ -541,34 +541,34 @@ mhd_gtls_dsa_verify (const gnutls_datum_t * vdata,
541 541
542 if (vdata->size != 20) 542 if (vdata->size != 20)
543 { /* sha-1 only */ 543 { /* sha-1 only */
544 gnutls_assert (); 544 MHD_gnutls_assert ();
545 return GNUTLS_E_PK_SIG_VERIFY_FAILED; 545 return GNUTLS_E_PK_SIG_VERIFY_FAILED;
546 } 546 }
547 547
548 if (decode_ber_rs (sig_value, &rs[0], &rs[1]) != 0) 548 if (decode_ber_rs (sig_value, &rs[0], &rs[1]) != 0)
549 { 549 {
550 gnutls_assert (); 550 MHD_gnutls_assert ();
551 return GNUTLS_E_MPI_SCAN_FAILED; 551 return GNUTLS_E_MPI_SCAN_FAILED;
552 } 552 }
553 553
554 k = vdata->size; 554 k = vdata->size;
555 if (mhd_gtls_mpi_scan_nz (&mdata, vdata->data, &k) != 0) 555 if (MHD_gtls_mpi_scan_nz (&mdata, vdata->data, &k) != 0)
556 { 556 {
557 gnutls_assert (); 557 MHD_gnutls_assert ();
558 mhd_gtls_mpi_release (&rs[0]); 558 MHD_gtls_mpi_release (&rs[0]);
559 mhd_gtls_mpi_release (&rs[1]); 559 MHD_gtls_mpi_release (&rs[1]);
560 return GNUTLS_E_MPI_SCAN_FAILED; 560 return GNUTLS_E_MPI_SCAN_FAILED;
561 } 561 }
562 562
563 /* decrypt signature */ 563 /* decrypt signature */
564 ret = _gnutls_pk_verify (GCRY_PK_DSA, mdata, rs, params, params_len); 564 ret = MHD__gnutls_pk_verify (GCRY_PK_DSA, mdata, rs, params, params_len);
565 mhd_gtls_mpi_release (&mdata); 565 MHD_gtls_mpi_release (&mdata);
566 mhd_gtls_mpi_release (&rs[0]); 566 MHD_gtls_mpi_release (&rs[0]);
567 mhd_gtls_mpi_release (&rs[1]); 567 MHD_gtls_mpi_release (&rs[1]);
568 568
569 if (ret < 0) 569 if (ret < 0)
570 { 570 {
571 gnutls_assert (); 571 MHD_gnutls_assert ();
572 return ret; 572 return ret;
573 } 573 }
574 574
@@ -584,7 +584,7 @@ mhd_gtls_dsa_verify (const gnutls_datum_t * vdata,
584 * change the internal design to directly fit to libgcrypt. 584 * change the internal design to directly fit to libgcrypt.
585 */ 585 */
586static int 586static int
587_gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data, 587MHD__gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
588 mpi_t * pkey, int pkey_len) 588 mpi_t * pkey, int pkey_len)
589{ 589{
590 gcry_sexp_t s_ciph, s_data, s_pkey; 590 gcry_sexp_t s_ciph, s_data, s_pkey;
@@ -601,20 +601,20 @@ _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
601 break; 601 break;
602 602
603 default: 603 default:
604 gnutls_assert (); 604 MHD_gnutls_assert ();
605 return GNUTLS_E_INTERNAL_ERROR; 605 return GNUTLS_E_INTERNAL_ERROR;
606 } 606 }
607 607
608 if (rc != 0) 608 if (rc != 0)
609 { 609 {
610 gnutls_assert (); 610 MHD_gnutls_assert ();
611 return GNUTLS_E_INTERNAL_ERROR; 611 return GNUTLS_E_INTERNAL_ERROR;
612 } 612 }
613 613
614 /* put the data into a simple list */ 614 /* put the data into a simple list */
615 if (gcry_sexp_build (&s_data, NULL, "%m", data)) 615 if (gcry_sexp_build (&s_data, NULL, "%m", data))
616 { 616 {
617 gnutls_assert (); 617 MHD_gnutls_assert ();
618 gcry_sexp_release (s_pkey); 618 gcry_sexp_release (s_pkey);
619 return GNUTLS_E_INTERNAL_ERROR; 619 return GNUTLS_E_INTERNAL_ERROR;
620 } 620 }
@@ -626,7 +626,7 @@ _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
626 626
627 if (rc != 0) 627 if (rc != 0)
628 { 628 {
629 gnutls_assert (); 629 MHD_gnutls_assert ();
630 return GNUTLS_E_PK_ENCRYPTION_FAILED; 630 return GNUTLS_E_PK_ENCRYPTION_FAILED;
631 631
632 } 632 }
@@ -635,7 +635,7 @@ _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
635 gcry_sexp_t list = gcry_sexp_find_token (s_ciph, "a", 0); 635 gcry_sexp_t list = gcry_sexp_find_token (s_ciph, "a", 0);
636 if (list == NULL) 636 if (list == NULL)
637 { 637 {
638 gnutls_assert (); 638 MHD_gnutls_assert ();
639 gcry_sexp_release (s_ciph); 639 gcry_sexp_release (s_ciph);
640 return GNUTLS_E_INTERNAL_ERROR; 640 return GNUTLS_E_INTERNAL_ERROR;
641 } 641 }
@@ -645,7 +645,7 @@ _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
645 645
646 if (resarr[0] == NULL) 646 if (resarr[0] == NULL)
647 { 647 {
648 gnutls_assert (); 648 MHD_gnutls_assert ();
649 gcry_sexp_release (s_ciph); 649 gcry_sexp_release (s_ciph);
650 return GNUTLS_E_INTERNAL_ERROR; 650 return GNUTLS_E_INTERNAL_ERROR;
651 } 651 }
@@ -656,7 +656,7 @@ _gnutls_pk_encrypt (int algo, mpi_t * resarr, mpi_t data,
656} 656}
657 657
658static int 658static int
659_gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey, 659MHD__gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey,
660 int pkey_len) 660 int pkey_len)
661{ 661{
662 gcry_sexp_t s_plain, s_data, s_pkey; 662 gcry_sexp_t s_plain, s_data, s_pkey;
@@ -674,20 +674,20 @@ _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey,
674 break; 674 break;
675 675
676 default: 676 default:
677 gnutls_assert (); 677 MHD_gnutls_assert ();
678 return GNUTLS_E_INTERNAL_ERROR; 678 return GNUTLS_E_INTERNAL_ERROR;
679 } 679 }
680 680
681 if (rc != 0) 681 if (rc != 0)
682 { 682 {
683 gnutls_assert (); 683 MHD_gnutls_assert ();
684 return GNUTLS_E_INTERNAL_ERROR; 684 return GNUTLS_E_INTERNAL_ERROR;
685 } 685 }
686 686
687 /* put the data into a simple list */ 687 /* put the data into a simple list */
688 if (gcry_sexp_build (&s_data, NULL, "(enc-val(rsa(a%m)))", data)) 688 if (gcry_sexp_build (&s_data, NULL, "(enc-val(rsa(a%m)))", data))
689 { 689 {
690 gnutls_assert (); 690 MHD_gnutls_assert ();
691 gcry_sexp_release (s_pkey); 691 gcry_sexp_release (s_pkey);
692 return GNUTLS_E_INTERNAL_ERROR; 692 return GNUTLS_E_INTERNAL_ERROR;
693 } 693 }
@@ -699,7 +699,7 @@ _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey,
699 699
700 if (rc != 0) 700 if (rc != 0)
701 { 701 {
702 gnutls_assert (); 702 MHD_gnutls_assert ();
703 return GNUTLS_E_PK_DECRYPTION_FAILED; 703 return GNUTLS_E_PK_DECRYPTION_FAILED;
704 704
705 } 705 }
@@ -709,7 +709,7 @@ _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey,
709 709
710 if (resarr[0] == NULL) 710 if (resarr[0] == NULL)
711 { 711 {
712 gnutls_assert (); 712 MHD_gnutls_assert ();
713 gcry_sexp_release (s_plain); 713 gcry_sexp_release (s_plain);
714 return GNUTLS_E_INTERNAL_ERROR; 714 return GNUTLS_E_INTERNAL_ERROR;
715 } 715 }
@@ -723,7 +723,7 @@ _gnutls_pk_decrypt (int algo, mpi_t * resarr, mpi_t data, mpi_t * pkey,
723/* in case of DSA puts into data, r,s 723/* in case of DSA puts into data, r,s
724 */ 724 */
725static int 725static int
726_gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey, 726MHD__gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
727 int pkey_len) 727 int pkey_len)
728{ 728{
729 gcry_sexp_t s_hash, s_key, s_sig; 729 gcry_sexp_t s_hash, s_key, s_sig;
@@ -739,7 +739,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
739 pkey[0], pkey[1], pkey[2], pkey[3], pkey[4]); 739 pkey[0], pkey[1], pkey[2], pkey[3], pkey[4]);
740 else 740 else
741 { 741 {
742 gnutls_assert (); 742 MHD_gnutls_assert ();
743 } 743 }
744 744
745 break; 745 break;
@@ -751,25 +751,25 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
751 pkey[4], pkey[5]); 751 pkey[4], pkey[5]);
752 else 752 else
753 { 753 {
754 gnutls_assert (); 754 MHD_gnutls_assert ();
755 } 755 }
756 break; 756 break;
757 757
758 default: 758 default:
759 gnutls_assert (); 759 MHD_gnutls_assert ();
760 return GNUTLS_E_INTERNAL_ERROR; 760 return GNUTLS_E_INTERNAL_ERROR;
761 } 761 }
762 762
763 if (rc != 0) 763 if (rc != 0)
764 { 764 {
765 gnutls_assert (); 765 MHD_gnutls_assert ();
766 return GNUTLS_E_INTERNAL_ERROR; 766 return GNUTLS_E_INTERNAL_ERROR;
767 } 767 }
768 768
769 /* put the data into a simple list */ 769 /* put the data into a simple list */
770 if (gcry_sexp_build (&s_hash, NULL, "%m", hash)) 770 if (gcry_sexp_build (&s_hash, NULL, "%m", hash))
771 { 771 {
772 gnutls_assert (); 772 MHD_gnutls_assert ();
773 return GNUTLS_E_INTERNAL_ERROR; 773 return GNUTLS_E_INTERNAL_ERROR;
774 } 774 }
775 775
@@ -780,7 +780,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
780 780
781 if (rc != 0) 781 if (rc != 0)
782 { 782 {
783 gnutls_assert (); 783 MHD_gnutls_assert ();
784 return GNUTLS_E_PK_SIGN_FAILED; 784 return GNUTLS_E_PK_SIGN_FAILED;
785 785
786 } 786 }
@@ -793,7 +793,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
793 list = gcry_sexp_find_token (s_sig, "r", 0); 793 list = gcry_sexp_find_token (s_sig, "r", 0);
794 if (list == NULL) 794 if (list == NULL)
795 { 795 {
796 gnutls_assert (); 796 MHD_gnutls_assert ();
797 gcry_sexp_release (s_sig); 797 gcry_sexp_release (s_sig);
798 return GNUTLS_E_INTERNAL_ERROR; 798 return GNUTLS_E_INTERNAL_ERROR;
799 } 799 }
@@ -804,7 +804,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
804 list = gcry_sexp_find_token (s_sig, "s", 0); 804 list = gcry_sexp_find_token (s_sig, "s", 0);
805 if (list == NULL) 805 if (list == NULL)
806 { 806 {
807 gnutls_assert (); 807 MHD_gnutls_assert ();
808 gcry_sexp_release (s_sig); 808 gcry_sexp_release (s_sig);
809 return GNUTLS_E_INTERNAL_ERROR; 809 return GNUTLS_E_INTERNAL_ERROR;
810 } 810 }
@@ -817,7 +817,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
817 list = gcry_sexp_find_token (s_sig, "s", 0); 817 list = gcry_sexp_find_token (s_sig, "s", 0);
818 if (list == NULL) 818 if (list == NULL)
819 { 819 {
820 gnutls_assert (); 820 MHD_gnutls_assert ();
821 gcry_sexp_release (s_sig); 821 gcry_sexp_release (s_sig);
822 return GNUTLS_E_INTERNAL_ERROR; 822 return GNUTLS_E_INTERNAL_ERROR;
823 } 823 }
@@ -833,7 +833,7 @@ _gnutls_pk_sign (int algo, mpi_t * data, mpi_t hash, mpi_t * pkey,
833 833
834 834
835static int 835static int
836_gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data, 836MHD__gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
837 mpi_t * pkey, int pkey_len) 837 mpi_t * pkey, int pkey_len)
838{ 838{
839 gcry_sexp_t s_sig, s_hash, s_pkey; 839 gcry_sexp_t s_sig, s_hash, s_pkey;
@@ -856,20 +856,20 @@ _gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
856 break; 856 break;
857 857
858 default: 858 default:
859 gnutls_assert (); 859 MHD_gnutls_assert ();
860 return GNUTLS_E_INTERNAL_ERROR; 860 return GNUTLS_E_INTERNAL_ERROR;
861 } 861 }
862 862
863 if (rc != 0) 863 if (rc != 0)
864 { 864 {
865 gnutls_assert (); 865 MHD_gnutls_assert ();
866 return GNUTLS_E_INTERNAL_ERROR; 866 return GNUTLS_E_INTERNAL_ERROR;
867 } 867 }
868 868
869 /* put the data into a simple list */ 869 /* put the data into a simple list */
870 if (gcry_sexp_build (&s_hash, NULL, "%m", hash)) 870 if (gcry_sexp_build (&s_hash, NULL, "%m", hash))
871 { 871 {
872 gnutls_assert (); 872 MHD_gnutls_assert ();
873 gcry_sexp_release (s_pkey); 873 gcry_sexp_release (s_pkey);
874 return GNUTLS_E_INTERNAL_ERROR; 874 return GNUTLS_E_INTERNAL_ERROR;
875 } 875 }
@@ -885,7 +885,7 @@ _gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
885 break; 885 break;
886 886
887 default: 887 default:
888 gnutls_assert (); 888 MHD_gnutls_assert ();
889 gcry_sexp_release (s_pkey); 889 gcry_sexp_release (s_pkey);
890 gcry_sexp_release (s_hash); 890 gcry_sexp_release (s_hash);
891 return GNUTLS_E_INTERNAL_ERROR; 891 return GNUTLS_E_INTERNAL_ERROR;
@@ -893,7 +893,7 @@ _gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
893 893
894 if (rc != 0) 894 if (rc != 0)
895 { 895 {
896 gnutls_assert (); 896 MHD_gnutls_assert ();
897 gcry_sexp_release (s_pkey); 897 gcry_sexp_release (s_pkey);
898 gcry_sexp_release (s_hash); 898 gcry_sexp_release (s_hash);
899 return GNUTLS_E_INTERNAL_ERROR; 899 return GNUTLS_E_INTERNAL_ERROR;
@@ -907,7 +907,7 @@ _gnutls_pk_verify (int algo, mpi_t hash, mpi_t * data,
907 907
908 if (rc != 0) 908 if (rc != 0)
909 { 909 {
910 gnutls_assert (); 910 MHD_gnutls_assert ();
911 return GNUTLS_E_PK_SIG_VERIFY_FAILED; 911 return GNUTLS_E_PK_SIG_VERIFY_FAILED;
912 } 912 }
913 913
diff --git a/src/daemon/https/tls/gnutls_pk.h b/src/daemon/https/tls/gnutls_pk.h
index ef4723d4..bd153a45 100644
--- a/src/daemon/https/tls/gnutls_pk.h
+++ b/src/daemon/https/tls/gnutls_pk.h
@@ -25,22 +25,22 @@
25#ifndef GNUTLS_PK_H 25#ifndef GNUTLS_PK_H
26#define GNUTLS_PK_H 26#define GNUTLS_PK_H
27 27
28int mhd_gtls_pkcs1_rsa_encrypt (gnutls_datum_t * ciphertext, 28int MHD_gtls_pkcs1_rsa_encrypt (MHD_gnutls_datum_t * ciphertext,
29 const gnutls_datum_t * plaintext, 29 const MHD_gnutls_datum_t * plaintext,
30 mpi_t * params, unsigned params_len, 30 mpi_t * params, unsigned params_len,
31 unsigned btype); 31 unsigned btype);
32int mhd_gtls_dsa_sign (gnutls_datum_t * signature, 32int MHD_gtls_dsa_sign (MHD_gnutls_datum_t * signature,
33 const gnutls_datum_t * plaintext, mpi_t * params, 33 const MHD_gnutls_datum_t * plaintext, mpi_t * params,
34 unsigned params_len); 34 unsigned params_len);
35int mhd_gtls_pkcs1_rsa_decrypt (gnutls_datum_t * plaintext, 35int MHD_gtls_pkcs1_rsa_decrypt (MHD_gnutls_datum_t * plaintext,
36 const gnutls_datum_t * ciphertext, 36 const MHD_gnutls_datum_t * ciphertext,
37 mpi_t * params, unsigned params_len, 37 mpi_t * params, unsigned params_len,
38 unsigned btype); 38 unsigned btype);
39int mhd_gtls_rsa_verify (const gnutls_datum_t * vdata, 39int MHD_gtls_rsa_verify (const MHD_gnutls_datum_t * vdata,
40 const gnutls_datum_t * ciphertext, mpi_t * params, 40 const MHD_gnutls_datum_t * ciphertext, mpi_t * params,
41 int params_len, int btype); 41 int params_len, int btype);
42int mhd_gtls_dsa_verify (const gnutls_datum_t * vdata, 42int MHD_gtls_dsa_verify (const MHD_gnutls_datum_t * vdata,
43 const gnutls_datum_t * sig_value, mpi_t * params, 43 const MHD_gnutls_datum_t * sig_value, mpi_t * params,
44 int params_len); 44 int params_len);
45 45
46#endif /* GNUTLS_PK_H */ 46#endif /* GNUTLS_PK_H */
diff --git a/src/daemon/https/tls/gnutls_priority.c b/src/daemon/https/tls/gnutls_priority.c
index f0a91bd6..06398e83 100644
--- a/src/daemon/https/tls/gnutls_priority.c
+++ b/src/daemon/https/tls/gnutls_priority.c
@@ -22,7 +22,7 @@
22 * 22 *
23 */ 23 */
24 24
25/* Here lies the code of the gnutls_*_set_priority() functions. 25/* Here lies the code of the MHD_gnutls_*_set_priority() functions.
26 */ 26 */
27 27
28#include "gnutls_int.h" 28#include "gnutls_int.h"
@@ -33,8 +33,8 @@
33#define MAX_ELEMENTS 48 33#define MAX_ELEMENTS 48
34 34
35/** 35/**
36 * MHD_gnutls_cipher_set_priority - Sets the priority on the ciphers supported by gnutls. 36 * MHD__gnutls_cipher_set_priority - Sets the priority on the ciphers supported by gnutls.
37 * @session: is a #mhd_gtls_session_t structure. 37 * @session: is a #MHD_gtls_session_t structure.
38 * @list: is a 0 terminated list of enum MHD_GNUTLS_CipherAlgorithm elements. 38 * @list: is a 0 terminated list of enum MHD_GNUTLS_CipherAlgorithm elements.
39 * 39 *
40 * Sets the priority on the ciphers supported by gnutls. 40 * Sets the priority on the ciphers supported by gnutls.
@@ -48,7 +48,7 @@
48 * 48 *
49 **/ 49 **/
50int 50int
51MHD_gnutls_cipher_set_priority (mhd_gtls_session_t session, const int *list) 51MHD__gnutls_cipher_set_priority (MHD_gtls_session_t session, const int *list)
52{ 52{
53 int num = 0, i; 53 int num = 0, i;
54 54
@@ -67,7 +67,7 @@ MHD_gnutls_cipher_set_priority (mhd_gtls_session_t session, const int *list)
67} 67}
68 68
69static int 69static int
70_set_priority (mhd_gtls_priority_st * st, const int *list) 70_set_priority (MHD_gtls_priority_st * st, const int *list)
71{ 71{
72 int num = 0; 72 int num = 0;
73 73
@@ -80,8 +80,8 @@ _set_priority (mhd_gtls_priority_st * st, const int *list)
80} 80}
81 81
82/** 82/**
83 * MHD_gnutls_kx_set_priority - Sets the priority on the key exchange algorithms supported by gnutls. 83 * MHD__gnutls_kx_set_priority - Sets the priority on the key exchange algorithms supported by gnutls.
84 * @session: is a #mhd_gtls_session_t structure. 84 * @session: is a #MHD_gtls_session_t structure.
85 * @list: is a 0 terminated list of enum MHD_GNUTLS_KeyExchangeAlgorithm elements. 85 * @list: is a 0 terminated list of enum MHD_GNUTLS_KeyExchangeAlgorithm elements.
86 * 86 *
87 * Sets the priority on the key exchange algorithms supported by gnutls. 87 * Sets the priority on the key exchange algorithms supported by gnutls.
@@ -95,14 +95,14 @@ _set_priority (mhd_gtls_priority_st * st, const int *list)
95 * 95 *
96 **/ 96 **/
97int 97int
98MHD_gnutls_kx_set_priority (mhd_gtls_session_t session, const int *list) 98MHD__gnutls_kx_set_priority (MHD_gtls_session_t session, const int *list)
99{ 99{
100 return _set_priority (&session->internals.priorities.kx, list); 100 return _set_priority (&session->internals.priorities.kx, list);
101} 101}
102 102
103/** 103/**
104 * MHD_gnutls_mac_set_priority - Sets the priority on the mac algorithms supported by gnutls. 104 * MHD__gnutls_mac_set_priority - Sets the priority on the mac algorithms supported by gnutls.
105 * @session: is a #mhd_gtls_session_t structure. 105 * @session: is a #MHD_gtls_session_t structure.
106 * @list: is a 0 terminated list of enum MHD_GNUTLS_HashAlgorithm elements. 106 * @list: is a 0 terminated list of enum MHD_GNUTLS_HashAlgorithm elements.
107 * 107 *
108 * Sets the priority on the mac algorithms supported by gnutls. 108 * Sets the priority on the mac algorithms supported by gnutls.
@@ -116,14 +116,14 @@ MHD_gnutls_kx_set_priority (mhd_gtls_session_t session, const int *list)
116 * 116 *
117 **/ 117 **/
118int 118int
119MHD_gnutls_mac_set_priority (mhd_gtls_session_t session, const int *list) 119MHD__gnutls_mac_set_priority (MHD_gtls_session_t session, const int *list)
120{ 120{
121 return _set_priority (&session->internals.priorities.mac, list); 121 return _set_priority (&session->internals.priorities.mac, list);
122} 122}
123 123
124/** 124/**
125 * MHD_gnutls_compression_set_priority - Sets the priority on the compression algorithms supported by gnutls. 125 * MHD__gnutls_compression_set_priority - Sets the priority on the compression algorithms supported by gnutls.
126 * @session: is a #mhd_gtls_session_t structure. 126 * @session: is a #MHD_gtls_session_t structure.
127 * @list: is a 0 terminated list of enum MHD_GNUTLS_CompressionMethod elements. 127 * @list: is a 0 terminated list of enum MHD_GNUTLS_CompressionMethod elements.
128 * 128 *
129 * Sets the priority on the compression algorithms supported by gnutls. 129 * Sets the priority on the compression algorithms supported by gnutls.
@@ -141,15 +141,15 @@ MHD_gnutls_mac_set_priority (mhd_gtls_session_t session, const int *list)
141 * 141 *
142 **/ 142 **/
143int 143int
144MHD_gnutls_compression_set_priority (mhd_gtls_session_t session, 144MHD__gnutls_compression_set_priority (MHD_gtls_session_t session,
145 const int *list) 145 const int *list)
146{ 146{
147 return _set_priority (&session->internals.priorities.compression, list); 147 return _set_priority (&session->internals.priorities.compression, list);
148} 148}
149 149
150/** 150/**
151 * MHD_gnutls_protocol_set_priority - Sets the priority on the protocol versions supported by gnutls. 151 * MHD__gnutls_protocol_set_priority - Sets the priority on the protocol versions supported by gnutls.
152 * @session: is a #mhd_gtls_session_t structure. 152 * @session: is a #MHD_gtls_session_t structure.
153 * @list: is a 0 terminated list of enum MHD_GNUTLS_Protocol elements. 153 * @list: is a 0 terminated list of enum MHD_GNUTLS_Protocol elements.
154 * 154 *
155 * Sets the priority on the protocol versions supported by gnutls. 155 * Sets the priority on the protocol versions supported by gnutls.
@@ -160,7 +160,7 @@ MHD_gnutls_compression_set_priority (mhd_gtls_session_t session,
160 * 160 *
161 **/ 161 **/
162int 162int
163MHD_gnutls_protocol_set_priority (mhd_gtls_session_t session, const int *list) 163MHD__gnutls_protocol_set_priority (MHD_gtls_session_t session, const int *list)
164{ 164{
165 int ret; 165 int ret;
166 166
@@ -168,14 +168,14 @@ MHD_gnutls_protocol_set_priority (mhd_gtls_session_t session, const int *list)
168 /* set the current version to the first in the chain. 168 /* set the current version to the first in the chain.
169 * This will be overridden later. 169 * This will be overridden later.
170 */ 170 */
171 mhd_gtls_set_current_version (session, list[0]); 171 MHD_gtls_set_current_version (session, list[0]);
172 172
173 return ret; 173 return ret;
174} 174}
175 175
176/** 176/**
177 * MHD_gnutls_certificate_type_set_priority - Sets the priority on the certificate types supported by gnutls. 177 * MHD__gnutls_certificate_type_set_priority - Sets the priority on the certificate types supported by gnutls.
178 * @session: is a #mhd_gtls_session_t structure. 178 * @session: is a #MHD_gtls_session_t structure.
179 * @list: is a 0 terminated list of enum MHD_GNUTLS_CertificateType elements. 179 * @list: is a 0 terminated list of enum MHD_GNUTLS_CertificateType elements.
180 * 180 *
181 * Sets the priority on the certificate types supported by gnutls. 181 * Sets the priority on the certificate types supported by gnutls.
@@ -189,7 +189,7 @@ MHD_gnutls_protocol_set_priority (mhd_gtls_session_t session, const int *list)
189 * 189 *
190 **/ 190 **/
191int 191int
192MHD_gnutls_certificate_type_set_priority (mhd_gtls_session_t session, 192MHD__gnutls_certificate_type_set_priority (MHD_gtls_session_t session,
193 const int *list) 193 const int *list)
194{ 194{
195#if ENABLE_OPENPGP 195#if ENABLE_OPENPGP
@@ -201,39 +201,39 @@ MHD_gnutls_certificate_type_set_priority (mhd_gtls_session_t session,
201#endif 201#endif
202} 202}
203 203
204static const int mhd_gtls_protocol_priority[] = { MHD_GNUTLS_PROTOCOL_TLS1_1, 204static const int MHD_gtls_protocol_priority[] = { MHD_GNUTLS_PROTOCOL_TLS1_1,
205 MHD_GNUTLS_PROTOCOL_TLS1_0, 205 MHD_GNUTLS_PROTOCOL_TLS1_0,
206 MHD_GNUTLS_PROTOCOL_SSL3, 206 MHD_GNUTLS_PROTOCOL_SSL3,
207 0 207 0
208}; 208};
209 209
210static const int mhd_gtls_cipher_priority_secure256[] = 210static const int MHD_gtls_cipher_priority_secure256[] =
211 { MHD_GNUTLS_CIPHER_AES_256_CBC, 211 { MHD_GNUTLS_CIPHER_AES_256_CBC,
212 0 212 0
213}; 213};
214 214
215static const int mhd_gtls_kx_priority_secure[] = { MHD_GNUTLS_KX_RSA, 215static const int MHD_gtls_kx_priority_secure[] = { MHD_GNUTLS_KX_RSA,
216 0 216 0
217}; 217};
218 218
219static const int mhd_gtls_mac_priority_secure[] = { MHD_GNUTLS_MAC_SHA1, 219static const int MHD_gtls_mac_priority_secure[] = { MHD_GNUTLS_MAC_SHA1,
220 0 220 0
221}; 221};
222 222
223static int mhd_gtls_cert_type_priority[] = { MHD_GNUTLS_CRT_X509, 223static int MHD_gtls_cert_type_priority[] = { MHD_GNUTLS_CRT_X509,
224 0 224 0
225}; 225};
226 226
227static const int mhd_gtls_comp_priority[] = { MHD_GNUTLS_COMP_NULL, 227static const int MHD_gtls_comp_priority[] = { MHD_GNUTLS_COMP_NULL,
228 0 228 0
229}; 229};
230 230
231typedef void (rmadd_func) (mhd_gtls_priority_st * priority_list, int alg); 231typedef void (rmadd_func) (MHD_gtls_priority_st * priority_list, int alg);
232 232
233/** 233/**
234 * MHD_gnutls_priority_set - Sets priorities for the cipher suites supported by gnutls. 234 * MHD__gnutls_priority_set - Sets priorities for the cipher suites supported by gnutls.
235 * @session: is a #mhd_gtls_session_t structure. 235 * @session: is a #MHD_gtls_session_t structure.
236 * @priority: is a #gnutls_priority_t structure. 236 * @priority: is a #MHD_gnutls_priority_t structure.
237 * 237 *
238 * Sets the priorities to use on the ciphers, key exchange methods, 238 * Sets the priorities to use on the ciphers, key exchange methods,
239 * macs and compression methods. 239 * macs and compression methods.
@@ -242,12 +242,12 @@ typedef void (rmadd_func) (mhd_gtls_priority_st * priority_list, int alg);
242 * 242 *
243 **/ 243 **/
244int 244int
245MHD_gnutls_priority_set (mhd_gtls_session_t session, 245MHD__gnutls_priority_set (MHD_gtls_session_t session,
246 gnutls_priority_t priority) 246 MHD_gnutls_priority_t priority)
247{ 247{
248 if (priority == NULL) 248 if (priority == NULL)
249 { 249 {
250 gnutls_assert (); 250 MHD_gnutls_assert ();
251 return GNUTLS_E_NO_CIPHER_SUITES; 251 return GNUTLS_E_NO_CIPHER_SUITES;
252 } 252 }
253 253
@@ -259,13 +259,13 @@ MHD_gnutls_priority_set (mhd_gtls_session_t session,
259 259
260/** 260/**
261 * MHD_tls_set_default_priority - Sets priorities for the cipher suites supported by gnutls. 261 * MHD_tls_set_default_priority - Sets priorities for the cipher suites supported by gnutls.
262 * @priority_cache: is a #gnutls_prioritity_t structure. 262 * @priority_cache: is a #MHD_gnutls_prioritity_t structure.
263 * @priorities: is a string describing priorities 263 * @priorities: is a string describing priorities
264 * @err_pos: In case of an error this will have the position in the string the error occured 264 * @err_pos: In case of an error this will have the position in the string the error occured
265 * 265 *
266 * Sets priorities for the ciphers, key exchange methods, macs and 266 * Sets priorities for the ciphers, key exchange methods, macs and
267 * compression methods. This is to avoid using the 267 * compression methods. This is to avoid using the
268 * gnutls_*_priority() functions. 268 * MHD_gnutls_*_priority() functions.
269 * 269 *
270 * The #priorities option allows you to specify a semi-colon 270 * The #priorities option allows you to specify a semi-colon
271 * separated list of the cipher priorities to enable. 271 * separated list of the cipher priorities to enable.
@@ -323,45 +323,45 @@ MHD_gnutls_priority_set (mhd_gtls_session_t session,
323 * 0 on success. 323 * 0 on success.
324 **/ 324 **/
325int 325int
326MHD_tls_set_default_priority (gnutls_priority_t * priority_cache, 326MHD_tls_set_default_priority (MHD_gnutls_priority_t * priority_cache,
327 const char *priorities, const char **err_pos) 327 const char *priorities, const char **err_pos)
328{ 328{
329 *priority_cache = gnutls_calloc (1, sizeof (struct MHD_gtls_priority_st)); 329 *priority_cache = MHD_gnutls_calloc (1, sizeof (struct MHD_gtls_priority_st));
330 if (*priority_cache == NULL) 330 if (*priority_cache == NULL)
331 { 331 {
332 gnutls_assert (); 332 MHD_gnutls_assert ();
333 return GNUTLS_E_MEMORY_ERROR; 333 return GNUTLS_E_MEMORY_ERROR;
334 } 334 }
335 335
336 /* set mode to "SECURE256" */ 336 /* set mode to "SECURE256" */
337 _set_priority (&(*priority_cache)->protocol, mhd_gtls_protocol_priority); 337 _set_priority (&(*priority_cache)->protocol, MHD_gtls_protocol_priority);
338 _set_priority (&(*priority_cache)->cipher, 338 _set_priority (&(*priority_cache)->cipher,
339 mhd_gtls_cipher_priority_secure256); 339 MHD_gtls_cipher_priority_secure256);
340 _set_priority (&(*priority_cache)->kx, mhd_gtls_kx_priority_secure); 340 _set_priority (&(*priority_cache)->kx, MHD_gtls_kx_priority_secure);
341 _set_priority (&(*priority_cache)->mac, mhd_gtls_mac_priority_secure); 341 _set_priority (&(*priority_cache)->mac, MHD_gtls_mac_priority_secure);
342 _set_priority (&(*priority_cache)->cert_type, mhd_gtls_cert_type_priority); 342 _set_priority (&(*priority_cache)->cert_type, MHD_gtls_cert_type_priority);
343 _set_priority (&(*priority_cache)->compression, mhd_gtls_comp_priority); 343 _set_priority (&(*priority_cache)->compression, MHD_gtls_comp_priority);
344 344
345 (*priority_cache)->no_padding = 0; 345 (*priority_cache)->no_padding = 0;
346 return 0; 346 return 0;
347} 347}
348 348
349/** 349/**
350 * MHD_gnutls_priority_deinit - Deinitialize the priorities cache for the cipher suites supported by gnutls. 350 * MHD__gnutls_priority_deinit - Deinitialize the priorities cache for the cipher suites supported by gnutls.
351 * @priority_cache: is a #gnutls_prioritity_t structure. 351 * @priority_cache: is a #MHD_gnutls_prioritity_t structure.
352 * 352 *
353 * Deinitializes the priority cache. 353 * Deinitializes the priority cache.
354 * 354 *
355 **/ 355 **/
356void 356void
357MHD_gnutls_priority_deinit (gnutls_priority_t priority_cache) 357MHD__gnutls_priority_deinit (MHD_gnutls_priority_t priority_cache)
358{ 358{
359 gnutls_free (priority_cache); 359 MHD_gnutls_free (priority_cache);
360} 360}
361 361
362/** 362/**
363 * MHD_gnutls_priority_set_direct - Sets priorities for the cipher suites supported by gnutls. 363 * MHD__gnutls_priority_set_direct - Sets priorities for the cipher suites supported by gnutls.
364 * @session: is a #mhd_gtls_session_t structure. 364 * @session: is a #MHD_gtls_session_t structure.
365 * @priorities: is a string describing priorities 365 * @priorities: is a string describing priorities
366 * @err_pos: In case of an error this will have the position in the string the error occured 366 * @err_pos: In case of an error this will have the position in the string the error occured
367 * 367 *
@@ -374,27 +374,27 @@ MHD_gnutls_priority_deinit (gnutls_priority_t priority_cache)
374 * 374 *
375 **/ 375 **/
376int 376int
377MHD_gnutls_priority_set_direct (mhd_gtls_session_t session, 377MHD__gnutls_priority_set_direct (MHD_gtls_session_t session,
378 const char *priorities, const char **err_pos) 378 const char *priorities, const char **err_pos)
379{ 379{
380 gnutls_priority_t prio; 380 MHD_gnutls_priority_t prio;
381 int ret; 381 int ret;
382 382
383 ret = MHD_tls_set_default_priority (&prio, priorities, err_pos); 383 ret = MHD_tls_set_default_priority (&prio, priorities, err_pos);
384 if (ret < 0) 384 if (ret < 0)
385 { 385 {
386 gnutls_assert (); 386 MHD_gnutls_assert ();
387 return ret; 387 return ret;
388 } 388 }
389 389
390 ret = MHD_gnutls_priority_set (session, prio); 390 ret = MHD__gnutls_priority_set (session, prio);
391 if (ret < 0) 391 if (ret < 0)
392 { 392 {
393 gnutls_assert (); 393 MHD_gnutls_assert ();
394 return ret; 394 return ret;
395 } 395 }
396 396
397 MHD_gnutls_priority_deinit (prio); 397 MHD__gnutls_priority_deinit (prio);
398 398
399 return 0; 399 return 0;
400} 400}
diff --git a/src/daemon/https/tls/gnutls_record.c b/src/daemon/https/tls/gnutls_record.c
index a9422c76..9ccdb1e3 100644
--- a/src/daemon/https/tls/gnutls_record.c
+++ b/src/daemon/https/tls/gnutls_record.c
@@ -44,27 +44,27 @@
44#include <gnutls_dh.h> 44#include <gnutls_dh.h>
45 45
46/** 46/**
47 * MHD_gnutls_protocol_get_version - Returns the version of the currently used protocol 47 * MHD__gnutls_protocol_get_version - Returns the version of the currently used protocol
48 * @session: is a #mhd_gtls_session_t structure. 48 * @session: is a #MHD_gtls_session_t structure.
49 * 49 *
50 * Returns: the version of the currently used protocol. 50 * Returns: the version of the currently used protocol.
51 **/ 51 **/
52enum MHD_GNUTLS_Protocol 52enum MHD_GNUTLS_Protocol
53MHD_gnutls_protocol_get_version (mhd_gtls_session_t session) 53MHD__gnutls_protocol_get_version (MHD_gtls_session_t session)
54{ 54{
55 return session->security_parameters.version; 55 return session->security_parameters.version;
56} 56}
57 57
58void 58void
59mhd_gtls_set_current_version (mhd_gtls_session_t session, 59MHD_gtls_set_current_version (MHD_gtls_session_t session,
60 enum MHD_GNUTLS_Protocol version) 60 enum MHD_GNUTLS_Protocol version)
61{ 61{
62 session->security_parameters.version = version; 62 session->security_parameters.version = version;
63} 63}
64 64
65/** 65/**
66 * MHD_gnutls_transport_set_lowat - Used to set the lowat value in order for select to check for pending data. 66 * MHD__gnutls_transport_set_lowat - Used to set the lowat value in order for select to check for pending data.
67 * @session: is a #mhd_gtls_session_t structure. 67 * @session: is a #MHD_gtls_session_t structure.
68 * @num: is the low water value. 68 * @num: is the low water value.
69 * 69 *
70 * Used to set the lowat value in order for select to check if there 70 * Used to set the lowat value in order for select to check if there
@@ -75,14 +75,14 @@ mhd_gtls_set_current_version (mhd_gtls_session_t session,
75 * to zero. 75 * to zero.
76 **/ 76 **/
77void 77void
78MHD_gnutls_transport_set_lowat (mhd_gtls_session_t session, int num) 78MHD__gnutls_transport_set_lowat (MHD_gtls_session_t session, int num)
79{ 79{
80 session->internals.lowat = num; 80 session->internals.lowat = num;
81} 81}
82 82
83/** 83/**
84 * MHD_gtls_record_disable_padding - Used to disabled padding in TLS 1.0 and above 84 * MHD_gtls_record_disable_padding - Used to disabled padding in TLS 1.0 and above
85 * @session: is a #mhd_gtls_session_t structure. 85 * @session: is a #MHD_gtls_session_t structure.
86 * 86 *
87 * Used to disabled padding in TLS 1.0 and above. Normally you do 87 * Used to disabled padding in TLS 1.0 and above. Normally you do
88 * not need to use this function, but there are buggy clients that 88 * not need to use this function, but there are buggy clients that
@@ -93,14 +93,14 @@ MHD_gnutls_transport_set_lowat (mhd_gtls_session_t session, int num)
93 * out there, need to call this function. 93 * out there, need to call this function.
94 **/ 94 **/
95void 95void
96MHD_gtls_record_disable_padding (mhd_gtls_session_t session) 96MHD_gtls_record_disable_padding (MHD_gtls_session_t session)
97{ 97{
98 session->internals.priorities.no_padding = 1; 98 session->internals.priorities.no_padding = 1;
99} 99}
100 100
101/** 101/**
102 * MHD_gnutls_transport_set_ptr - Used to set first argument of the transport functions 102 * MHD__gnutls_transport_set_ptr - Used to set first argument of the transport functions
103 * @session: is a #mhd_gtls_session_t structure. 103 * @session: is a #MHD_gtls_session_t structure.
104 * @ptr: is the value. 104 * @ptr: is the value.
105 * 105 *
106 * Used to set the first argument of the transport function (like 106 * Used to set the first argument of the transport function (like
@@ -108,16 +108,16 @@ MHD_gtls_record_disable_padding (mhd_gtls_session_t session)
108 * the connection handle. 108 * the connection handle.
109 **/ 109 **/
110void 110void
111MHD_gnutls_transport_set_ptr (mhd_gtls_session_t session, 111MHD__gnutls_transport_set_ptr (MHD_gtls_session_t session,
112 gnutls_transport_ptr_t ptr) 112 MHD_gnutls_transport_ptr_t ptr)
113{ 113{
114 session->internals.transport_recv_ptr = ptr; 114 session->internals.transport_recv_ptr = ptr;
115 session->internals.transport_send_ptr = ptr; 115 session->internals.transport_send_ptr = ptr;
116} 116}
117 117
118/** 118/**
119 * MHD_gnutls_transport_set_ptr2 - Used to set first argument of the transport functions 119 * MHD__gnutls_transport_set_ptr2 - Used to set first argument of the transport functions
120 * @session: is a #mhd_gtls_session_t structure. 120 * @session: is a #MHD_gtls_session_t structure.
121 * @recv_ptr: is the value for the pull function 121 * @recv_ptr: is the value for the pull function
122 * @send_ptr: is the value for the push function 122 * @send_ptr: is the value for the push function
123 * 123 *
@@ -127,21 +127,21 @@ MHD_gnutls_transport_set_ptr (mhd_gtls_session_t session,
127 * different pointers for receiving and sending. 127 * different pointers for receiving and sending.
128 **/ 128 **/
129void 129void
130MHD_gnutls_transport_set_ptr2 (mhd_gtls_session_t session, 130MHD__gnutls_transport_set_ptr2 (MHD_gtls_session_t session,
131 gnutls_transport_ptr_t recv_ptr, 131 MHD_gnutls_transport_ptr_t recv_ptr,
132 gnutls_transport_ptr_t send_ptr) 132 MHD_gnutls_transport_ptr_t send_ptr)
133{ 133{
134 session->internals.transport_send_ptr = send_ptr; 134 session->internals.transport_send_ptr = send_ptr;
135 session->internals.transport_recv_ptr = recv_ptr; 135 session->internals.transport_recv_ptr = recv_ptr;
136} 136}
137 137
138/** 138/**
139 * MHD_gnutls_bye - This function terminates the current TLS/SSL connection. 139 * MHD__gnutls_bye - This function terminates the current TLS/SSL connection.
140 * @session: is a #mhd_gtls_session_t structure. 140 * @session: is a #MHD_gtls_session_t structure.
141 * @how: is an integer 141 * @how: is an integer
142 * 142 *
143 * Terminates the current TLS/SSL connection. The connection should 143 * Terminates the current TLS/SSL connection. The connection should
144 * have been initiated using MHD_gnutls_handshake(). @how should be one 144 * have been initiated using MHD__gnutls_handshake(). @how should be one
145 * of %GNUTLS_SHUT_RDWR, %GNUTLS_SHUT_WR. 145 * of %GNUTLS_SHUT_RDWR, %GNUTLS_SHUT_WR.
146 * 146 *
147 * In case of %GNUTLS_SHUT_RDWR then the TLS connection gets 147 * In case of %GNUTLS_SHUT_RDWR then the TLS connection gets
@@ -163,13 +163,13 @@ MHD_gnutls_transport_set_ptr2 (mhd_gtls_session_t session,
163 * session, thus this behavior is not recommended. 163 * session, thus this behavior is not recommended.
164 * 164 *
165 * This function may also return %GNUTLS_E_AGAIN or 165 * This function may also return %GNUTLS_E_AGAIN or
166 * %GNUTLS_E_INTERRUPTED; cf. MHD_gnutls_record_get_direction(). 166 * %GNUTLS_E_INTERRUPTED; cf. MHD__gnutls_record_get_direction().
167 * 167 *
168 * Returns: %GNUTLS_E_SUCCESS on success, or an error code, see 168 * Returns: %GNUTLS_E_SUCCESS on success, or an error code, see
169 * function documentation for entire semantics. 169 * function documentation for entire semantics.
170 **/ 170 **/
171int 171int
172MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how) 172MHD__gnutls_bye (MHD_gtls_session_t session, MHD_gnutls_close_request_t how)
173{ 173{
174 int ret = 0; 174 int ret = 0;
175 175
@@ -177,22 +177,22 @@ MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how)
177 { 177 {
178 case STATE0: 178 case STATE0:
179 case STATE60: 179 case STATE60:
180 ret = mhd_gtls_io_write_flush (session); 180 ret = MHD_gtls_io_write_flush (session);
181 STATE = STATE60; 181 STATE = STATE60;
182 if (ret < 0) 182 if (ret < 0)
183 { 183 {
184 gnutls_assert (); 184 MHD_gnutls_assert ();
185 return ret; 185 return ret;
186 } 186 }
187 187
188 case STATE61: 188 case STATE61:
189 ret = 189 ret =
190 MHD_gnutls_alert_send (session, GNUTLS_AL_WARNING, 190 MHD__gnutls_alert_send (session, GNUTLS_AL_WARNING,
191 GNUTLS_A_CLOSE_NOTIFY); 191 GNUTLS_A_CLOSE_NOTIFY);
192 STATE = STATE61; 192 STATE = STATE61;
193 if (ret < 0) 193 if (ret < 0)
194 { 194 {
195 gnutls_assert (); 195 MHD_gnutls_assert ();
196 return ret; 196 return ret;
197 } 197 }
198 198
@@ -202,8 +202,8 @@ MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how)
202 { 202 {
203 do 203 do
204 { 204 {
205 mhd_gtls_io_clear_peeked_data (session); 205 MHD_gtls_io_clear_peeked_data (session);
206 ret = mhd_gtls_recv_int (session, GNUTLS_ALERT, -1, NULL, 0); 206 ret = MHD_gtls_recv_int (session, GNUTLS_ALERT, -1, NULL, 0);
207 } 207 }
208 while (ret == GNUTLS_E_GOT_APPLICATION_DATA); 208 while (ret == GNUTLS_E_GOT_APPLICATION_DATA);
209 209
@@ -212,7 +212,7 @@ MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how)
212 212
213 if (ret < 0) 213 if (ret < 0)
214 { 214 {
215 gnutls_assert (); 215 MHD_gnutls_assert ();
216 return ret; 216 return ret;
217 } 217 }
218 } 218 }
@@ -220,7 +220,7 @@ MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how)
220 220
221 break; 221 break;
222 default: 222 default:
223 gnutls_assert (); 223 MHD_gnutls_assert ();
224 return GNUTLS_E_INTERNAL_ERROR; 224 return GNUTLS_E_INTERNAL_ERROR;
225 } 225 }
226 226
@@ -231,13 +231,13 @@ MHD_gnutls_bye (mhd_gtls_session_t session, gnutls_close_request_t how)
231} 231}
232 232
233inline static void 233inline static void
234session_invalidate (mhd_gtls_session_t session) 234session_invalidate (MHD_gtls_session_t session)
235{ 235{
236 session->internals.valid_connection = VALID_FALSE; 236 session->internals.valid_connection = VALID_FALSE;
237} 237}
238 238
239inline static void 239inline static void
240session_unresumable (mhd_gtls_session_t session) 240session_unresumable (MHD_gtls_session_t session)
241{ 241{
242 session->internals.resumable = RESUME_FALSE; 242 session->internals.resumable = RESUME_FALSE;
243} 243}
@@ -245,7 +245,7 @@ session_unresumable (mhd_gtls_session_t session)
245/* returns 0 if session is valid 245/* returns 0 if session is valid
246 */ 246 */
247inline static int 247inline static int
248session_is_valid (mhd_gtls_session_t session) 248session_is_valid (MHD_gtls_session_t session)
249{ 249{
250 if (session->internals.valid_connection == VALID_FALSE) 250 if (session->internals.valid_connection == VALID_FALSE)
251 return GNUTLS_E_INVALID_SESSION; 251 return GNUTLS_E_INVALID_SESSION;
@@ -257,18 +257,18 @@ session_is_valid (mhd_gtls_session_t session)
257 * version must have 2 bytes at least. 257 * version must have 2 bytes at least.
258 */ 258 */
259inline static void 259inline static void
260copy_record_version (mhd_gtls_session_t session, 260copy_record_version (MHD_gtls_session_t session,
261 gnutls_handshake_description_t htype, opaque version[2]) 261 MHD_gnutls_handshake_description_t htype, opaque version[2])
262{ 262{
263 enum MHD_GNUTLS_Protocol lver; 263 enum MHD_GNUTLS_Protocol lver;
264 264
265 if (htype != GNUTLS_HANDSHAKE_CLIENT_HELLO 265 if (htype != GNUTLS_HANDSHAKE_CLIENT_HELLO
266 || session->internals.default_record_version[0] == 0) 266 || session->internals.default_record_version[0] == 0)
267 { 267 {
268 lver = MHD_gnutls_protocol_get_version (session); 268 lver = MHD__gnutls_protocol_get_version (session);
269 269
270 version[0] = mhd_gtls_version_get_major (lver); 270 version[0] = MHD_gtls_version_get_major (lver);
271 version[1] = mhd_gtls_version_get_minor (lver); 271 version[1] = MHD_gtls_version_get_minor (lver);
272 } 272 }
273 else 273 else
274 { 274 {
@@ -278,7 +278,7 @@ copy_record_version (mhd_gtls_session_t session,
278} 278}
279 279
280/* This function behaves exactly like write(). The only difference is 280/* This function behaves exactly like write(). The only difference is
281 * that it accepts, the mhd_gtls_session_t and the content_type_t of data to 281 * that it accepts, the MHD_gtls_session_t and the content_type_t of data to
282 * send (if called by the user the Content is specific) 282 * send (if called by the user the Content is specific)
283 * It is intended to transfer data, under the current session. 283 * It is intended to transfer data, under the current session.
284 * 284 *
@@ -292,9 +292,9 @@ copy_record_version (mhd_gtls_session_t session,
292 * 292 *
293 */ 293 */
294ssize_t 294ssize_t
295mhd_gtls_send_int (mhd_gtls_session_t session, 295MHD_gtls_send_int (MHD_gtls_session_t session,
296 content_type_t type, 296 content_type_t type,
297 gnutls_handshake_description_t htype, 297 MHD_gnutls_handshake_description_t htype,
298 const void *_data, size_t sizeofdata) 298 const void *_data, size_t sizeofdata)
299{ 299{
300 uint8_t *cipher; 300 uint8_t *cipher;
@@ -311,14 +311,14 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
311 if (session->internals.record_send_buffer.length == 0 && (sizeofdata == 0 311 if (session->internals.record_send_buffer.length == 0 && (sizeofdata == 0
312 && _data == NULL)) 312 && _data == NULL))
313 { 313 {
314 gnutls_assert (); 314 MHD_gnutls_assert ();
315 return GNUTLS_E_INVALID_REQUEST; 315 return GNUTLS_E_INVALID_REQUEST;
316 } 316 }
317 317
318 if (type != GNUTLS_ALERT) /* alert messages are sent anyway */ 318 if (type != GNUTLS_ALERT) /* alert messages are sent anyway */
319 if (session_is_valid (session) || session->internals.may_not_write != 0) 319 if (session_is_valid (session) || session->internals.may_not_write != 0)
320 { 320 {
321 gnutls_assert (); 321 MHD_gnutls_assert ();
322 return GNUTLS_E_INVALID_SESSION; 322 return GNUTLS_E_INVALID_SESSION;
323 } 323 }
324 324
@@ -329,11 +329,11 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
329 */ 329 */
330 copy_record_version (session, htype, &headers[1]); 330 copy_record_version (session, htype, &headers[1]);
331 331
332 _gnutls_record_log 332 MHD__gnutls_record_log
333 ("REC[%x]: Sending Packet[%d] %s(%d) with length: %d\n", session, 333 ("REC[%x]: Sending Packet[%d] %s(%d) with length: %d\n", session,
334 (int) mhd_gtls_uint64touint32 (&session->connection_state. 334 (int) MHD_gtls_uint64touint32 (&session->connection_state.
335 write_sequence_number), 335 write_sequence_number),
336 _gnutls_packet2str (type), type, sizeofdata); 336 MHD__gnutls_packet2str (type), type, sizeofdata);
337 337
338 if (sizeofdata > MAX_RECORD_SEND_SIZE) 338 if (sizeofdata > MAX_RECORD_SEND_SIZE)
339 data2send_size = MAX_RECORD_SEND_SIZE; 339 data2send_size = MAX_RECORD_SEND_SIZE;
@@ -345,7 +345,7 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
345 */ 345 */
346 if (session->internals.record_send_buffer.length > 0) 346 if (session->internals.record_send_buffer.length > 0)
347 { 347 {
348 ret = mhd_gtls_io_write_flush (session); 348 ret = MHD_gtls_io_write_flush (session);
349 if (ret > 0) 349 if (ret > 0)
350 cipher_size = ret; 350 cipher_size = ret;
351 else 351 else
@@ -360,24 +360,24 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
360 /* now proceed to packet encryption 360 /* now proceed to packet encryption
361 */ 361 */
362 cipher_size = data2send_size + MAX_RECORD_OVERHEAD; 362 cipher_size = data2send_size + MAX_RECORD_OVERHEAD;
363 cipher = gnutls_malloc (cipher_size); 363 cipher = MHD_gnutls_malloc (cipher_size);
364 if (cipher == NULL) 364 if (cipher == NULL)
365 { 365 {
366 gnutls_assert (); 366 MHD_gnutls_assert ();
367 return GNUTLS_E_MEMORY_ERROR; 367 return GNUTLS_E_MEMORY_ERROR;
368 } 368 }
369 369
370 cipher_size = 370 cipher_size =
371 mhd_gtls_encrypt (session, headers, RECORD_HEADER_SIZE, data, 371 MHD_gtls_encrypt (session, headers, RECORD_HEADER_SIZE, data,
372 data2send_size, cipher, cipher_size, type, 372 data2send_size, cipher, cipher_size, type,
373 (session->internals.priorities.no_padding == 373 (session->internals.priorities.no_padding ==
374 0) ? 1 : 0); 374 0) ? 1 : 0);
375 if (cipher_size <= 0) 375 if (cipher_size <= 0)
376 { 376 {
377 gnutls_assert (); 377 MHD_gnutls_assert ();
378 if (cipher_size == 0) 378 if (cipher_size == 0)
379 cipher_size = GNUTLS_E_ENCRYPTION_FAILED; 379 cipher_size = GNUTLS_E_ENCRYPTION_FAILED;
380 gnutls_free (cipher); 380 MHD_gnutls_free (cipher);
381 return cipher_size; /* error */ 381 return cipher_size; /* error */
382 } 382 }
383 383
@@ -386,17 +386,17 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
386 386
387 /* increase sequence number 387 /* increase sequence number
388 */ 388 */
389 if (mhd_gtls_uint64pp 389 if (MHD_gtls_uint64pp
390 (&session->connection_state.write_sequence_number) != 0) 390 (&session->connection_state.write_sequence_number) != 0)
391 { 391 {
392 session_invalidate (session); 392 session_invalidate (session);
393 gnutls_assert (); 393 MHD_gnutls_assert ();
394 gnutls_free (cipher); 394 MHD_gnutls_free (cipher);
395 return GNUTLS_E_RECORD_LIMIT_REACHED; 395 return GNUTLS_E_RECORD_LIMIT_REACHED;
396 } 396 }
397 397
398 ret = mhd_gtls_io_write_buffered (session, cipher, cipher_size); 398 ret = MHD_gtls_io_write_buffered (session, cipher, cipher_size);
399 gnutls_free (cipher); 399 MHD_gnutls_free (cipher);
400 } 400 }
401 401
402 if (ret != cipher_size) 402 if (ret != cipher_size)
@@ -406,29 +406,29 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
406 /* If we have sent any data then just return 406 /* If we have sent any data then just return
407 * the error value. Do not invalidate the session. 407 * the error value. Do not invalidate the session.
408 */ 408 */
409 gnutls_assert (); 409 MHD_gnutls_assert ();
410 return ret; 410 return ret;
411 } 411 }
412 412
413 if (ret > 0) 413 if (ret > 0)
414 { 414 {
415 gnutls_assert (); 415 MHD_gnutls_assert ();
416 ret = GNUTLS_E_INTERNAL_ERROR; 416 ret = GNUTLS_E_INTERNAL_ERROR;
417 } 417 }
418 session_unresumable (session); 418 session_unresumable (session);
419 session->internals.may_not_write = 1; 419 session->internals.may_not_write = 1;
420 gnutls_assert (); 420 MHD_gnutls_assert ();
421 return ret; 421 return ret;
422 } 422 }
423 423
424 session->internals.record_send_buffer_user_size = 0; 424 session->internals.record_send_buffer_user_size = 0;
425 425
426 _gnutls_record_log ("REC[%x]: Sent Packet[%d] %s(%d) with length: %d\n", 426 MHD__gnutls_record_log ("REC[%x]: Sent Packet[%d] %s(%d) with length: %d\n",
427 session, 427 session,
428 (int) 428 (int)
429 mhd_gtls_uint64touint32 429 MHD_gtls_uint64touint32
430 (&session->connection_state.write_sequence_number), 430 (&session->connection_state.write_sequence_number),
431 _gnutls_packet2str (type), type, cipher_size); 431 MHD__gnutls_packet2str (type), type, cipher_size);
432 432
433 return retval; 433 return retval;
434} 434}
@@ -437,20 +437,20 @@ mhd_gtls_send_int (mhd_gtls_session_t session,
437 * completed. This sends a Change Cipher Spec packet to the peer. 437 * completed. This sends a Change Cipher Spec packet to the peer.
438 */ 438 */
439ssize_t 439ssize_t
440mhd_gtls_send_change_cipher_spec (mhd_gtls_session_t session, int again) 440MHD_gtls_send_change_cipher_spec (MHD_gtls_session_t session, int again)
441{ 441{
442 static const opaque data[1] = { 442 static const opaque data[1] = {
443 GNUTLS_TYPE_CHANGE_CIPHER_SPEC 443 GNUTLS_TYPE_CHANGE_CIPHER_SPEC
444 }; 444 };
445 445
446 _gnutls_handshake_log ("REC[%x]: Sent ChangeCipherSpec\n", session); 446 MHD__gnutls_handshake_log ("REC[%x]: Sent ChangeCipherSpec\n", session);
447 447
448 if (again == 0) 448 if (again == 0)
449 return mhd_gtls_send_int (session, GNUTLS_CHANGE_CIPHER_SPEC, -1, data, 449 return MHD_gtls_send_int (session, GNUTLS_CHANGE_CIPHER_SPEC, -1, data,
450 1); 450 1);
451 else 451 else
452 { 452 {
453 return mhd_gtls_io_write_flush (session); 453 return MHD_gtls_io_write_flush (session);
454 } 454 }
455} 455}
456 456
@@ -466,7 +466,7 @@ check_recv_type (content_type_t recv_type)
466 case GNUTLS_INNER_APPLICATION: 466 case GNUTLS_INNER_APPLICATION:
467 return 0; 467 return 0;
468 default: 468 default:
469 gnutls_assert (); 469 MHD_gnutls_assert ();
470 return GNUTLS_A_UNEXPECTED_MESSAGE; 470 return GNUTLS_A_UNEXPECTED_MESSAGE;
471 } 471 }
472 472
@@ -476,27 +476,27 @@ check_recv_type (content_type_t recv_type)
476 * then it copies the data. 476 * then it copies the data.
477 */ 477 */
478static int 478static int
479check_buffers (mhd_gtls_session_t session, 479check_buffers (MHD_gtls_session_t session,
480 content_type_t type, opaque * data, int sizeofdata) 480 content_type_t type, opaque * data, int sizeofdata)
481{ 481{
482 if ((type == GNUTLS_APPLICATION_DATA || type == GNUTLS_HANDSHAKE || type 482 if ((type == GNUTLS_APPLICATION_DATA || type == GNUTLS_HANDSHAKE || type
483 == GNUTLS_INNER_APPLICATION) 483 == GNUTLS_INNER_APPLICATION)
484 && mhd_gnutls_record_buffer_get_size (type, session) > 0) 484 && MHD_gnutls_record_buffer_get_size (type, session) > 0)
485 { 485 {
486 int ret, ret2; 486 int ret, ret2;
487 ret = mhd_gtls_record_buffer_get (type, session, data, sizeofdata); 487 ret = MHD_gtls_record_buffer_get (type, session, data, sizeofdata);
488 if (ret < 0) 488 if (ret < 0)
489 { 489 {
490 gnutls_assert (); 490 MHD_gnutls_assert ();
491 return ret; 491 return ret;
492 } 492 }
493 493
494 /* if the buffer just got empty */ 494 /* if the buffer just got empty */
495 if (mhd_gnutls_record_buffer_get_size (type, session) == 0) 495 if (MHD_gnutls_record_buffer_get_size (type, session) == 0)
496 { 496 {
497 if ((ret2 = mhd_gtls_io_clear_peeked_data (session)) < 0) 497 if ((ret2 = MHD_gtls_io_clear_peeked_data (session)) < 0)
498 { 498 {
499 gnutls_assert (); 499 MHD_gnutls_assert ();
500 return ret2; 500 return ret2;
501 } 501 }
502 } 502 }
@@ -511,10 +511,10 @@ check_buffers (mhd_gtls_session_t session,
511 * content type. 511 * content type.
512 */ 512 */
513static int 513static int
514record_check_headers (mhd_gtls_session_t session, 514record_check_headers (MHD_gtls_session_t session,
515 uint8_t headers[RECORD_HEADER_SIZE], 515 uint8_t headers[RECORD_HEADER_SIZE],
516 content_type_t type, 516 content_type_t type,
517 gnutls_handshake_description_t htype, 517 MHD_gnutls_handshake_description_t htype,
518 /*output */ content_type_t * recv_type, 518 /*output */ content_type_t * recv_type,
519 opaque version[2], 519 opaque version[2],
520 uint16_t * length, uint16_t * header_size) 520 uint16_t * length, uint16_t * header_size)
@@ -546,7 +546,7 @@ record_check_headers (mhd_gtls_session_t session,
546 */ 546 */
547 session->internals.v2_hello = *length; 547 session->internals.v2_hello = *length;
548 548
549 _gnutls_record_log ("REC[%x]: V2 packet received. Length: %d\n", 549 MHD__gnutls_record_log ("REC[%x]: V2 packet received. Length: %d\n",
550 session, *length); 550 session, *length);
551 551
552 } 552 }
@@ -559,7 +559,7 @@ record_check_headers (mhd_gtls_session_t session,
559 559
560 /* No DECR_LEN, since headers has enough size. 560 /* No DECR_LEN, since headers has enough size.
561 */ 561 */
562 *length = mhd_gtls_read_uint16 (&headers[3]); 562 *length = MHD_gtls_read_uint16 (&headers[3]);
563 } 563 }
564 564
565 return 0; 565 return 0;
@@ -569,8 +569,8 @@ record_check_headers (mhd_gtls_session_t session,
569 * negotiated in the handshake. 569 * negotiated in the handshake.
570 */ 570 */
571inline static int 571inline static int
572record_check_version (mhd_gtls_session_t session, 572record_check_version (MHD_gtls_session_t session,
573 gnutls_handshake_description_t htype, opaque version[2]) 573 MHD_gnutls_handshake_description_t htype, opaque version[2])
574{ 574{
575 if (htype == GNUTLS_HANDSHAKE_CLIENT_HELLO) 575 if (htype == GNUTLS_HANDSHAKE_CLIENT_HELLO)
576 { 576 {
@@ -578,23 +578,23 @@ record_check_version (mhd_gtls_session_t session,
578 */ 578 */
579 if (version[0] > 3) 579 if (version[0] > 3)
580 { 580 {
581 gnutls_assert (); 581 MHD_gnutls_assert ();
582 _gnutls_record_log 582 MHD__gnutls_record_log
583 ("REC[%x]: INVALID VERSION PACKET: (%d) %d.%d\n", session, 583 ("REC[%x]: INVALID VERSION PACKET: (%d) %d.%d\n", session,
584 htype, version[0], version[1]); 584 htype, version[0], version[1]);
585 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET; 585 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
586 } 586 }
587 } 587 }
588 else if (htype != GNUTLS_HANDSHAKE_SERVER_HELLO 588 else if (htype != GNUTLS_HANDSHAKE_SERVER_HELLO
589 && MHD_gnutls_protocol_get_version (session) 589 && MHD__gnutls_protocol_get_version (session)
590 != mhd_gtls_version_get (version[0], version[1])) 590 != MHD_gtls_version_get (version[0], version[1]))
591 { 591 {
592 /* Reject record packets that have a different version than the 592 /* Reject record packets that have a different version than the
593 * one negotiated. Note that this version is not protected by any 593 * one negotiated. Note that this version is not protected by any
594 * mac. I don't really think that this check serves any purpose. 594 * mac. I don't really think that this check serves any purpose.
595 */ 595 */
596 gnutls_assert (); 596 MHD_gnutls_assert ();
597 _gnutls_record_log ("REC[%x]: INVALID VERSION PACKET: (%d) %d.%d\n", 597 MHD__gnutls_record_log ("REC[%x]: INVALID VERSION PACKET: (%d) %d.%d\n",
598 session, htype, version[0], version[1]); 598 session, htype, version[0], version[1]);
599 599
600 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET; 600 return GNUTLS_E_UNSUPPORTED_VERSION_PACKET;
@@ -607,10 +607,10 @@ record_check_version (mhd_gtls_session_t session,
607 * the one we actually expect. 607 * the one we actually expect.
608 */ 608 */
609static int 609static int
610record_check_type (mhd_gtls_session_t session, 610record_check_type (MHD_gtls_session_t session,
611 content_type_t recv_type, 611 content_type_t recv_type,
612 content_type_t type, 612 content_type_t type,
613 gnutls_handshake_description_t htype, 613 MHD_gnutls_handshake_description_t htype,
614 opaque * data, int data_size) 614 opaque * data, int data_size)
615{ 615{
616 616
@@ -620,7 +620,7 @@ record_check_type (mhd_gtls_session_t session,
620 == GNUTLS_HANDSHAKE 620 == GNUTLS_HANDSHAKE
621 || type == GNUTLS_INNER_APPLICATION)) 621 || type == GNUTLS_INNER_APPLICATION))
622 { 622 {
623 mhd_gnutls_record_buffer_put (type, session, (void *) data, data_size); 623 MHD_gnutls_record_buffer_put (type, session, (void *) data, data_size);
624 } 624 }
625 else 625 else
626 { 626 {
@@ -628,9 +628,9 @@ record_check_type (mhd_gtls_session_t session,
628 { 628 {
629 case GNUTLS_ALERT: 629 case GNUTLS_ALERT:
630 630
631 _gnutls_record_log 631 MHD__gnutls_record_log
632 ("REC[%x]: Alert[%d|%d] - %s - was received\n", session, 632 ("REC[%x]: Alert[%d|%d] - %s - was received\n", session,
633 data[0], data[1], MHD_gnutls_alert_get_name ((int) data[1])); 633 data[0], data[1], MHD__gnutls_alert_get_name ((int) data[1]));
634 634
635 session->internals.last_alert = data[1]; 635 session->internals.last_alert = data[1];
636 session->internals.last_alert_level = data[0]; 636 session->internals.last_alert_level = data[0];
@@ -651,7 +651,7 @@ record_check_type (mhd_gtls_session_t session,
651 /* if the alert is FATAL or WARNING 651 /* if the alert is FATAL or WARNING
652 * return the apropriate message 652 * return the apropriate message
653 */ 653 */
654 gnutls_assert (); 654 MHD_gnutls_assert ();
655 ret = GNUTLS_E_WARNING_ALERT_RECEIVED; 655 ret = GNUTLS_E_WARNING_ALERT_RECEIVED;
656 if (data[0] == GNUTLS_AL_FATAL) 656 if (data[0] == GNUTLS_AL_FATAL)
657 { 657 {
@@ -668,17 +668,17 @@ record_check_type (mhd_gtls_session_t session,
668 /* this packet is now handled in the recv_int() 668 /* this packet is now handled in the recv_int()
669 * function 669 * function
670 */ 670 */
671 gnutls_assert (); 671 MHD_gnutls_assert ();
672 672
673 return GNUTLS_E_UNEXPECTED_PACKET; 673 return GNUTLS_E_UNEXPECTED_PACKET;
674 674
675 case GNUTLS_APPLICATION_DATA: 675 case GNUTLS_APPLICATION_DATA:
676 /* even if data is unexpected put it into the buffer */ 676 /* even if data is unexpected put it into the buffer */
677 if ((ret = 677 if ((ret =
678 mhd_gnutls_record_buffer_put (recv_type, session, 678 MHD_gnutls_record_buffer_put (recv_type, session,
679 (void *) data, data_size)) < 0) 679 (void *) data, data_size)) < 0)
680 { 680 {
681 gnutls_assert (); 681 MHD_gnutls_assert ();
682 return ret; 682 return ret;
683 } 683 }
684 684
@@ -691,7 +691,7 @@ record_check_type (mhd_gtls_session_t session,
691 return GNUTLS_E_GOT_APPLICATION_DATA; 691 return GNUTLS_E_GOT_APPLICATION_DATA;
692 else 692 else
693 { 693 {
694 gnutls_assert (); 694 MHD_gnutls_assert ();
695 return GNUTLS_E_UNEXPECTED_PACKET; 695 return GNUTLS_E_UNEXPECTED_PACKET;
696 } 696 }
697 697
@@ -702,7 +702,7 @@ record_check_type (mhd_gtls_session_t session,
702 */ 702 */
703 if (session->security_parameters.entity == GNUTLS_SERVER) 703 if (session->security_parameters.entity == GNUTLS_SERVER)
704 { 704 {
705 gnutls_assert (); 705 MHD_gnutls_assert ();
706 return GNUTLS_E_REHANDSHAKE; 706 return GNUTLS_E_REHANDSHAKE;
707 } 707 }
708 708
@@ -712,28 +712,28 @@ record_check_type (mhd_gtls_session_t session,
712 */ 712 */
713 713
714 /* So we accept it */ 714 /* So we accept it */
715 return mhd_gtls_recv_hello_request (session, data, data_size); 715 return MHD_gtls_recv_hello_request (session, data, data_size);
716 716
717 break; 717 break;
718 case GNUTLS_INNER_APPLICATION: 718 case GNUTLS_INNER_APPLICATION:
719 /* even if data is unexpected put it into the buffer */ 719 /* even if data is unexpected put it into the buffer */
720 if ((ret = 720 if ((ret =
721 mhd_gnutls_record_buffer_put (recv_type, session, 721 MHD_gnutls_record_buffer_put (recv_type, session,
722 (void *) data, data_size)) < 0) 722 (void *) data, data_size)) < 0)
723 { 723 {
724 gnutls_assert (); 724 MHD_gnutls_assert ();
725 return ret; 725 return ret;
726 } 726 }
727 gnutls_assert (); 727 MHD_gnutls_assert ();
728 return GNUTLS_E_UNEXPECTED_PACKET; 728 return GNUTLS_E_UNEXPECTED_PACKET;
729 break; 729 break;
730 default: 730 default:
731 731
732 _gnutls_record_log 732 MHD__gnutls_record_log
733 ("REC[%x]: Received Unknown packet %d expecting %d\n", 733 ("REC[%x]: Received Unknown packet %d expecting %d\n",
734 session, recv_type, type); 734 session, recv_type, type);
735 735
736 gnutls_assert (); 736 MHD_gnutls_assert ();
737 return GNUTLS_E_INTERNAL_ERROR; 737 return GNUTLS_E_INTERNAL_ERROR;
738 } 738 }
739 } 739 }
@@ -747,7 +747,7 @@ record_check_type (mhd_gtls_session_t session,
747 * also initialize it. 747 * also initialize it.
748 */ 748 */
749inline static int 749inline static int
750get_temp_recv_buffer (mhd_gtls_session_t session, gnutls_datum_t * tmp) 750get_temp_recv_buffer (MHD_gtls_session_t session, MHD_gnutls_datum_t * tmp)
751{ 751{
752 size_t max_record_size; 752 size_t max_record_size;
753 753
@@ -769,11 +769,11 @@ get_temp_recv_buffer (mhd_gtls_session_t session, gnutls_datum_t * tmp)
769 */ 769 */
770 session->internals.recv_buffer.data 770 session->internals.recv_buffer.data
771 = 771 =
772 gnutls_realloc (session->internals.recv_buffer.data, max_record_size); 772 MHD_gnutls_realloc (session->internals.recv_buffer.data, max_record_size);
773 773
774 if (session->internals.recv_buffer.data == NULL) 774 if (session->internals.recv_buffer.data == NULL)
775 { 775 {
776 gnutls_assert (); 776 MHD_gnutls_assert ();
777 return GNUTLS_E_MEMORY_ERROR; 777 return GNUTLS_E_MEMORY_ERROR;
778 } 778 }
779 779
@@ -789,19 +789,19 @@ get_temp_recv_buffer (mhd_gtls_session_t session, gnutls_datum_t * tmp)
789#define MAX_EMPTY_PACKETS_SEQUENCE 4 789#define MAX_EMPTY_PACKETS_SEQUENCE 4
790 790
791/* This function behaves exactly like read(). The only difference is 791/* This function behaves exactly like read(). The only difference is
792 * that it accepts the mhd_gtls_session_t and the content_type_t of data to 792 * that it accepts the MHD_gtls_session_t and the content_type_t of data to
793 * receive (if called by the user the Content is Userdata only) 793 * receive (if called by the user the Content is Userdata only)
794 * It is intended to receive data, under the current session. 794 * It is intended to receive data, under the current session.
795 * 795 *
796 * The gnutls_handshake_description_t was introduced to support SSL V2.0 client hellos. 796 * The MHD_gnutls_handshake_description_t was introduced to support SSL V2.0 client hellos.
797 */ 797 */
798ssize_t 798ssize_t
799mhd_gtls_recv_int (mhd_gtls_session_t session, 799MHD_gtls_recv_int (MHD_gtls_session_t session,
800 content_type_t type, 800 content_type_t type,
801 gnutls_handshake_description_t htype, 801 MHD_gnutls_handshake_description_t htype,
802 opaque * data, size_t sizeofdata) 802 opaque * data, size_t sizeofdata)
803{ 803{
804 gnutls_datum_t tmp; 804 MHD_gnutls_datum_t tmp;
805 int decrypted_length; 805 int decrypted_length;
806 opaque version[2]; 806 opaque version[2];
807 uint8_t *headers; 807 uint8_t *headers;
@@ -822,7 +822,7 @@ begin:
822 822
823 if (empty_packet > MAX_EMPTY_PACKETS_SEQUENCE) 823 if (empty_packet > MAX_EMPTY_PACKETS_SEQUENCE)
824 { 824 {
825 gnutls_assert (); 825 MHD_gnutls_assert ();
826 return GNUTLS_E_TOO_MANY_EMPTY_PACKETS; 826 return GNUTLS_E_TOO_MANY_EMPTY_PACKETS;
827 } 827 }
828 828
@@ -835,7 +835,7 @@ begin:
835 else if (session_is_valid (session) != 0 || session->internals.may_not_read 835 else if (session_is_valid (session) != 0 || session->internals.may_not_read
836 != 0) 836 != 0)
837 { 837 {
838 gnutls_assert (); 838 MHD_gnutls_assert ();
839 return GNUTLS_E_INVALID_SESSION; 839 return GNUTLS_E_INVALID_SESSION;
840 } 840 }
841 841
@@ -850,7 +850,7 @@ begin:
850 */ 850 */
851 header_size = RECORD_HEADER_SIZE; 851 header_size = RECORD_HEADER_SIZE;
852 852
853 if ((ret = mhd_gtls_io_read_buffered (session, &headers, header_size, -1)) 853 if ((ret = MHD_gtls_io_read_buffered (session, &headers, header_size, -1))
854 != header_size) 854 != header_size)
855 { 855 {
856 if (ret < 0 && MHD_gtls_error_is_fatal (ret) == 0) 856 if (ret < 0 && MHD_gtls_error_is_fatal (ret) == 0)
@@ -859,18 +859,18 @@ begin:
859 session_invalidate (session); 859 session_invalidate (session);
860 if (type == GNUTLS_ALERT) 860 if (type == GNUTLS_ALERT)
861 { 861 {
862 gnutls_assert (); 862 MHD_gnutls_assert ();
863 return 0; /* we were expecting close notify */ 863 return 0; /* we were expecting close notify */
864 } 864 }
865 session_unresumable (session); 865 session_unresumable (session);
866 gnutls_assert (); 866 MHD_gnutls_assert ();
867 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 867 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
868 } 868 }
869 869
870 if ((ret = record_check_headers (session, headers, type, htype, &recv_type, 870 if ((ret = record_check_headers (session, headers, type, htype, &recv_type,
871 version, &length, &header_size)) < 0) 871 version, &length, &header_size)) < 0)
872 { 872 {
873 gnutls_assert (); 873 MHD_gnutls_assert ();
874 return ret; 874 return ret;
875 } 875 }
876 876
@@ -879,7 +879,7 @@ begin:
879 */ 879 */
880 if ((ret = check_recv_type (recv_type)) < 0) 880 if ((ret = check_recv_type (recv_type)) < 0)
881 { 881 {
882 gnutls_assert (); 882 MHD_gnutls_assert ();
883 return ret; 883 return ret;
884 } 884 }
885 885
@@ -888,38 +888,38 @@ begin:
888 */ 888 */
889 if ((ret = record_check_version (session, htype, version)) < 0) 889 if ((ret = record_check_version (session, htype, version)) < 0)
890 { 890 {
891 gnutls_assert (); 891 MHD_gnutls_assert ();
892 session_invalidate (session); 892 session_invalidate (session);
893 return ret; 893 return ret;
894 } 894 }
895 895
896 _gnutls_record_log 896 MHD__gnutls_record_log
897 ("REC[%x]: Expected Packet[%d] %s(%d) with length: %d\n", session, 897 ("REC[%x]: Expected Packet[%d] %s(%d) with length: %d\n", session,
898 (int) mhd_gtls_uint64touint32 (&session->connection_state. 898 (int) MHD_gtls_uint64touint32 (&session->connection_state.
899 read_sequence_number), 899 read_sequence_number),
900 _gnutls_packet2str (type), type, sizeofdata); 900 MHD__gnutls_packet2str (type), type, sizeofdata);
901 _gnutls_record_log ("REC[%x]: Received Packet[%d] %s(%d) with length: %d\n", 901 MHD__gnutls_record_log ("REC[%x]: Received Packet[%d] %s(%d) with length: %d\n",
902 session, 902 session,
903 (int) 903 (int)
904 mhd_gtls_uint64touint32 (&session->connection_state. 904 MHD_gtls_uint64touint32 (&session->connection_state.
905 read_sequence_number), 905 read_sequence_number),
906 _gnutls_packet2str (recv_type), recv_type, length); 906 MHD__gnutls_packet2str (recv_type), recv_type, length);
907 907
908 if (length > MAX_RECV_SIZE) 908 if (length > MAX_RECV_SIZE)
909 { 909 {
910 _gnutls_record_log 910 MHD__gnutls_record_log
911 ("REC[%x]: FATAL ERROR: Received packet with length: %d\n", 911 ("REC[%x]: FATAL ERROR: Received packet with length: %d\n",
912 session, length); 912 session, length);
913 913
914 session_unresumable (session); 914 session_unresumable (session);
915 session_invalidate (session); 915 session_invalidate (session);
916 gnutls_assert (); 916 MHD_gnutls_assert ();
917 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 917 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
918 } 918 }
919 919
920 /* check if we have that data into buffer. 920 /* check if we have that data into buffer.
921 */ 921 */
922 if ((ret = mhd_gtls_io_read_buffered (session, &recv_data, 922 if ((ret = MHD_gtls_io_read_buffered (session, &recv_data,
923 header_size + length, recv_type)) 923 header_size + length, recv_type))
924 != header_size + length) 924 != header_size + length)
925 { 925 {
@@ -928,31 +928,31 @@ begin:
928 928
929 session_unresumable (session); 929 session_unresumable (session);
930 session_invalidate (session); 930 session_invalidate (session);
931 gnutls_assert (); 931 MHD_gnutls_assert ();
932 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 932 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
933 } 933 }
934 934
935 /* ok now we are sure that we can read all the data - so 935 /* ok now we are sure that we can read all the data - so
936 * move on ! 936 * move on !
937 */ 937 */
938 mhd_gtls_io_clear_read_buffer (session); 938 MHD_gtls_io_clear_read_buffer (session);
939 ciphertext = &recv_data[header_size]; 939 ciphertext = &recv_data[header_size];
940 940
941 ret = get_temp_recv_buffer (session, &tmp); 941 ret = get_temp_recv_buffer (session, &tmp);
942 if (ret < 0) 942 if (ret < 0)
943 { 943 {
944 gnutls_assert (); 944 MHD_gnutls_assert ();
945 return ret; 945 return ret;
946 } 946 }
947 947
948 /* decrypt the data we got. */ 948 /* decrypt the data we got. */
949 ret = mhd_gtls_decrypt (session, ciphertext, length, tmp.data, tmp.size, 949 ret = MHD_gtls_decrypt (session, ciphertext, length, tmp.data, tmp.size,
950 recv_type); 950 recv_type);
951 if (ret < 0) 951 if (ret < 0)
952 { 952 {
953 session_unresumable (session); 953 session_unresumable (session);
954 session_invalidate (session); 954 session_invalidate (session);
955 gnutls_assert (); 955 MHD_gnutls_assert ();
956 return ret; 956 return ret;
957 } 957 }
958 decrypted_length = ret; 958 decrypted_length = ret;
@@ -963,12 +963,12 @@ begin:
963 == GNUTLS_CHANGE_CIPHER_SPEC) 963 == GNUTLS_CHANGE_CIPHER_SPEC)
964 { 964 {
965 965
966 _gnutls_record_log 966 MHD__gnutls_record_log
967 ("REC[%x]: ChangeCipherSpec Packet was received\n", session); 967 ("REC[%x]: ChangeCipherSpec Packet was received\n", session);
968 968
969 if ((size_t) ret != sizeofdata) 969 if ((size_t) ret != sizeofdata)
970 { /* sizeofdata should be 1 */ 970 { /* sizeofdata should be 1 */
971 gnutls_assert (); 971 MHD_gnutls_assert ();
972 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH; 972 return GNUTLS_E_UNEXPECTED_PACKET_LENGTH;
973 } 973 }
974 memcpy (data, tmp.data, sizeofdata); 974 memcpy (data, tmp.data, sizeofdata);
@@ -976,19 +976,19 @@ begin:
976 return ret; 976 return ret;
977 } 977 }
978 978
979 _gnutls_record_log 979 MHD__gnutls_record_log
980 ("REC[%x]: Decrypted Packet[%d] %s(%d) with length: %d\n", session, 980 ("REC[%x]: Decrypted Packet[%d] %s(%d) with length: %d\n", session,
981 (int) mhd_gtls_uint64touint32 (&session->connection_state. 981 (int) MHD_gtls_uint64touint32 (&session->connection_state.
982 read_sequence_number), 982 read_sequence_number),
983 _gnutls_packet2str (recv_type), recv_type, decrypted_length); 983 MHD__gnutls_packet2str (recv_type), recv_type, decrypted_length);
984 984
985 /* increase sequence number 985 /* increase sequence number
986 */ 986 */
987 if (mhd_gtls_uint64pp (&session->connection_state.read_sequence_number) != 987 if (MHD_gtls_uint64pp (&session->connection_state.read_sequence_number) !=
988 0) 988 0)
989 { 989 {
990 session_invalidate (session); 990 session_invalidate (session);
991 gnutls_assert (); 991 MHD_gnutls_assert ();
992 return GNUTLS_E_RECORD_LIMIT_REACHED; 992 return GNUTLS_E_RECORD_LIMIT_REACHED;
993 } 993 }
994 994
@@ -999,7 +999,7 @@ begin:
999 { 999 {
1000 if (ret == GNUTLS_E_INT_RET_0) 1000 if (ret == GNUTLS_E_INT_RET_0)
1001 return 0; 1001 return 0;
1002 gnutls_assert (); 1002 MHD_gnutls_assert ();
1003 return ret; 1003 return ret;
1004 } 1004 }
1005 1005
@@ -1010,27 +1010,27 @@ begin:
1010 || type == GNUTLS_INNER_APPLICATION)) 1010 || type == GNUTLS_INNER_APPLICATION))
1011 { 1011 {
1012 1012
1013 ret = mhd_gtls_record_buffer_get (type, session, data, sizeofdata); 1013 ret = MHD_gtls_record_buffer_get (type, session, data, sizeofdata);
1014 if (ret < 0) 1014 if (ret < 0)
1015 { 1015 {
1016 gnutls_assert (); 1016 MHD_gnutls_assert ();
1017 return ret; 1017 return ret;
1018 } 1018 }
1019 1019
1020 /* if the buffer just got empty 1020 /* if the buffer just got empty
1021 */ 1021 */
1022 if (mhd_gnutls_record_buffer_get_size (type, session) == 0) 1022 if (MHD_gnutls_record_buffer_get_size (type, session) == 0)
1023 { 1023 {
1024 if ((ret2 = mhd_gtls_io_clear_peeked_data (session)) < 0) 1024 if ((ret2 = MHD_gtls_io_clear_peeked_data (session)) < 0)
1025 { 1025 {
1026 gnutls_assert (); 1026 MHD_gnutls_assert ();
1027 return ret2; 1027 return ret2;
1028 } 1028 }
1029 } 1029 }
1030 } 1030 }
1031 else 1031 else
1032 { 1032 {
1033 gnutls_assert (); 1033 MHD_gnutls_assert ();
1034 return GNUTLS_E_UNEXPECTED_PACKET; 1034 return GNUTLS_E_UNEXPECTED_PACKET;
1035 /* we didn't get what we wanted to 1035 /* we didn't get what we wanted to
1036 */ 1036 */
@@ -1053,8 +1053,8 @@ begin:
1053} 1053}
1054 1054
1055/** 1055/**
1056 * MHD_gnutls_record_send - sends to the peer the specified data 1056 * MHD__gnutls_record_send - sends to the peer the specified data
1057 * @session: is a #mhd_gtls_session_t structure. 1057 * @session: is a #MHD_gtls_session_t structure.
1058 * @data: contains the data to send 1058 * @data: contains the data to send
1059 * @sizeofdata: is the length of the data 1059 * @sizeofdata: is the length of the data
1060 * 1060 *
@@ -1065,7 +1065,7 @@ begin:
1065 * Note that if the send buffer is full, send() will block this 1065 * Note that if the send buffer is full, send() will block this
1066 * function. See the send() documentation for full information. You 1066 * function. See the send() documentation for full information. You
1067 * can replace the default push function by using 1067 * can replace the default push function by using
1068 * MHD_gnutls_transport_set_ptr2() with a call to send() with a 1068 * MHD__gnutls_transport_set_ptr2() with a call to send() with a
1069 * MSG_DONTWAIT flag if blocking is a problem. 1069 * MSG_DONTWAIT flag if blocking is a problem.
1070 * 1070 *
1071 * If the EINTR is returned by the internal push function (the 1071 * If the EINTR is returned by the internal push function (the
@@ -1073,7 +1073,7 @@ begin:
1073 * %GNUTLS_E_INTERRUPTED or %GNUTLS_E_AGAIN is returned, you must 1073 * %GNUTLS_E_INTERRUPTED or %GNUTLS_E_AGAIN is returned, you must
1074 * call this function again, with the same parameters; alternatively 1074 * call this function again, with the same parameters; alternatively
1075 * you could provide a %NULL pointer for data, and 0 for 1075 * you could provide a %NULL pointer for data, and 0 for
1076 * size. cf. MHD_gnutls_record_get_direction(). 1076 * size. cf. MHD__gnutls_record_get_direction().
1077 * 1077 *
1078 * Returns: the number of bytes sent, or a negative error code. The 1078 * Returns: the number of bytes sent, or a negative error code. The
1079 * number of bytes sent might be less than @sizeofdata. The maximum 1079 * number of bytes sent might be less than @sizeofdata. The maximum
@@ -1081,16 +1081,16 @@ begin:
1081 * the negotiated maximum record size. 1081 * the negotiated maximum record size.
1082 **/ 1082 **/
1083ssize_t 1083ssize_t
1084MHD_gnutls_record_send (mhd_gtls_session_t session, 1084MHD__gnutls_record_send (MHD_gtls_session_t session,
1085 const void *data, size_t sizeofdata) 1085 const void *data, size_t sizeofdata)
1086{ 1086{
1087 return mhd_gtls_send_int (session, GNUTLS_APPLICATION_DATA, -1, data, 1087 return MHD_gtls_send_int (session, GNUTLS_APPLICATION_DATA, -1, data,
1088 sizeofdata); 1088 sizeofdata);
1089} 1089}
1090 1090
1091/** 1091/**
1092 * MHD_gnutls_record_recv - reads data from the TLS record protocol 1092 * MHD__gnutls_record_recv - reads data from the TLS record protocol
1093 * @session: is a #mhd_gtls_session_t structure. 1093 * @session: is a #MHD_gtls_session_t structure.
1094 * @data: the buffer that the data will be read into 1094 * @data: the buffer that the data will be read into
1095 * @sizeofdata: the number of requested bytes 1095 * @sizeofdata: the number of requested bytes
1096 * 1096 *
@@ -1108,7 +1108,7 @@ MHD_gnutls_record_send (mhd_gtls_session_t session,
1108 * is recv()) then %GNUTLS_E_INTERRUPTED will be returned. If 1108 * is recv()) then %GNUTLS_E_INTERRUPTED will be returned. If
1109 * %GNUTLS_E_INTERRUPTED or %GNUTLS_E_AGAIN is returned, you must 1109 * %GNUTLS_E_INTERRUPTED or %GNUTLS_E_AGAIN is returned, you must
1110 * call this function again to get the data. See also 1110 * call this function again to get the data. See also
1111 * MHD_gnutls_record_get_direction(). 1111 * MHD__gnutls_record_get_direction().
1112 * 1112 *
1113 * A server may also receive %GNUTLS_E_REHANDSHAKE when a client has 1113 * A server may also receive %GNUTLS_E_REHANDSHAKE when a client has
1114 * initiated a handshake. In that case the server can only initiate a 1114 * initiated a handshake. In that case the server can only initiate a
@@ -1119,23 +1119,23 @@ MHD_gnutls_record_send (mhd_gtls_session_t session,
1119 * received might be less than @sizeofdata. 1119 * received might be less than @sizeofdata.
1120 **/ 1120 **/
1121ssize_t 1121ssize_t
1122MHD_gnutls_record_recv (mhd_gtls_session_t session, void *data, 1122MHD__gnutls_record_recv (MHD_gtls_session_t session, void *data,
1123 size_t sizeofdata) 1123 size_t sizeofdata)
1124{ 1124{
1125 return mhd_gtls_recv_int (session, GNUTLS_APPLICATION_DATA, -1, data, 1125 return MHD_gtls_recv_int (session, GNUTLS_APPLICATION_DATA, -1, data,
1126 sizeofdata); 1126 sizeofdata);
1127} 1127}
1128 1128
1129/** 1129/**
1130 * MHD_gnutls_record_get_max_size - returns the maximum record size 1130 * MHD__gnutls_record_get_max_size - returns the maximum record size
1131 * @session: is a #mhd_gtls_session_t structure. 1131 * @session: is a #MHD_gtls_session_t structure.
1132 * 1132 *
1133 * This function returns the maximum record packet size in this 1133 * This function returns the maximum record packet size in this
1134 * connection. The maximum record size is negotiated by the client 1134 * connection. The maximum record size is negotiated by the client
1135 * after the first handshake message. 1135 * after the first handshake message.
1136 **/ 1136 **/
1137size_t 1137size_t
1138MHD_gnutls_record_get_max_size (mhd_gtls_session_t session) 1138MHD__gnutls_record_get_max_size (MHD_gtls_session_t session)
1139{ 1139{
1140 /* Recv will hold the negotiated max record size 1140 /* Recv will hold the negotiated max record size
1141 * always. 1141 * always.
@@ -1144,8 +1144,8 @@ MHD_gnutls_record_get_max_size (mhd_gtls_session_t session)
1144} 1144}
1145 1145
1146/** 1146/**
1147 * MHD_gnutls_record_set_max_size - sets the maximum record size 1147 * MHD__gnutls_record_set_max_size - sets the maximum record size
1148 * @session: is a #mhd_gtls_session_t structure. 1148 * @session: is a #MHD_gtls_session_t structure.
1149 * @size: is the new size 1149 * @size: is the new size
1150 * 1150 *
1151 * This function sets the maximum record packet size in this 1151 * This function sets the maximum record packet size in this
@@ -1161,18 +1161,18 @@ MHD_gnutls_record_get_max_size (mhd_gtls_session_t session)
1161 * all TLS implementations use or even understand this extension. 1161 * all TLS implementations use or even understand this extension.
1162 **/ 1162 **/
1163ssize_t 1163ssize_t
1164MHD_gnutls_record_set_max_size (mhd_gtls_session_t session, size_t size) 1164MHD__gnutls_record_set_max_size (MHD_gtls_session_t session, size_t size)
1165{ 1165{
1166 ssize_t new_size; 1166 ssize_t new_size;
1167 1167
1168 if (session->security_parameters.entity == GNUTLS_SERVER) 1168 if (session->security_parameters.entity == GNUTLS_SERVER)
1169 return GNUTLS_E_INVALID_REQUEST; 1169 return GNUTLS_E_INVALID_REQUEST;
1170 1170
1171 new_size = mhd_gtls_mre_record2num (size); 1171 new_size = MHD_gtls_mre_record2num (size);
1172 1172
1173 if (new_size < 0) 1173 if (new_size < 0)
1174 { 1174 {
1175 gnutls_assert (); 1175 MHD_gnutls_assert ();
1176 return new_size; 1176 return new_size;
1177 } 1177 }
1178 1178
diff --git a/src/daemon/https/tls/gnutls_record.h b/src/daemon/https/tls/gnutls_record.h
index e1fea3f2..fe7300b6 100644
--- a/src/daemon/https/tls/gnutls_record.h
+++ b/src/daemon/https/tls/gnutls_record.h
@@ -22,12 +22,12 @@
22 * 22 *
23 */ 23 */
24 24
25ssize_t mhd_gtls_send_int (mhd_gtls_session_t session, content_type_t type, 25ssize_t MHD_gtls_send_int (MHD_gtls_session_t session, content_type_t type,
26 gnutls_handshake_description_t htype, 26 MHD_gnutls_handshake_description_t htype,
27 const void *data, size_t sizeofdata); 27 const void *data, size_t sizeofdata);
28ssize_t mhd_gtls_recv_int (mhd_gtls_session_t session, content_type_t type, 28ssize_t MHD_gtls_recv_int (MHD_gtls_session_t session, content_type_t type,
29 gnutls_handshake_description_t, opaque * data, 29 MHD_gnutls_handshake_description_t, opaque * data,
30 size_t sizeofdata); 30 size_t sizeofdata);
31ssize_t mhd_gtls_send_change_cipher_spec (mhd_gtls_session_t session, 31ssize_t MHD_gtls_send_change_cipher_spec (MHD_gtls_session_t session,
32 int again); 32 int again);
33void MHD_gnutls_transport_set_lowat (mhd_gtls_session_t session, int num); 33void MHD__gnutls_transport_set_lowat (MHD_gtls_session_t session, int num);
diff --git a/src/daemon/https/tls/gnutls_rsa_export.c b/src/daemon/https/tls/gnutls_rsa_export.c
index ce06e47e..64834a98 100644
--- a/src/daemon/https/tls/gnutls_rsa_export.c
+++ b/src/daemon/https/tls/gnutls_rsa_export.c
@@ -46,7 +46,7 @@
46 * We only support limited key sizes. 46 * We only support limited key sizes.
47 */ 47 */
48const mpi_t * 48const mpi_t *
49_gnutls_rsa_params_to_mpi (mhd_gtls_rsa_params_t rsa_params) 49MHD__gnutls_rsa_params_to_mpi (MHD_gtls_rsa_params_t rsa_params)
50{ 50{
51 if (rsa_params == NULL) 51 if (rsa_params == NULL)
52 { 52 {
@@ -61,7 +61,7 @@ _gnutls_rsa_params_to_mpi (mhd_gtls_rsa_params_t rsa_params)
61 * prime1 - p (3), prime2 - q(4), u (5). 61 * prime1 - p (3), prime2 - q(4), u (5).
62 */ 62 */
63int 63int
64_gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits) 64MHD__gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
65{ 65{
66 66
67 int ret; 67 int ret;
@@ -70,7 +70,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
70 ret = gcry_sexp_build (&parms, NULL, "(genkey(rsa(nbits %d)))", bits); 70 ret = gcry_sexp_build (&parms, NULL, "(genkey(rsa(nbits %d)))", bits);
71 if (ret != 0) 71 if (ret != 0)
72 { 72 {
73 gnutls_assert (); 73 MHD_gnutls_assert ();
74 return GNUTLS_E_INTERNAL_ERROR; 74 return GNUTLS_E_INTERNAL_ERROR;
75 } 75 }
76 76
@@ -80,14 +80,14 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
80 80
81 if (ret != 0) 81 if (ret != 0)
82 { 82 {
83 gnutls_assert (); 83 MHD_gnutls_assert ();
84 return GNUTLS_E_INTERNAL_ERROR; 84 return GNUTLS_E_INTERNAL_ERROR;
85 } 85 }
86 86
87 list = gcry_sexp_find_token (key, "n", 0); 87 list = gcry_sexp_find_token (key, "n", 0);
88 if (list == NULL) 88 if (list == NULL)
89 { 89 {
90 gnutls_assert (); 90 MHD_gnutls_assert ();
91 gcry_sexp_release (key); 91 gcry_sexp_release (key);
92 return GNUTLS_E_INTERNAL_ERROR; 92 return GNUTLS_E_INTERNAL_ERROR;
93 } 93 }
@@ -98,7 +98,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
98 list = gcry_sexp_find_token (key, "e", 0); 98 list = gcry_sexp_find_token (key, "e", 0);
99 if (list == NULL) 99 if (list == NULL)
100 { 100 {
101 gnutls_assert (); 101 MHD_gnutls_assert ();
102 gcry_sexp_release (key); 102 gcry_sexp_release (key);
103 return GNUTLS_E_INTERNAL_ERROR; 103 return GNUTLS_E_INTERNAL_ERROR;
104 } 104 }
@@ -109,7 +109,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
109 list = gcry_sexp_find_token (key, "d", 0); 109 list = gcry_sexp_find_token (key, "d", 0);
110 if (list == NULL) 110 if (list == NULL)
111 { 111 {
112 gnutls_assert (); 112 MHD_gnutls_assert ();
113 gcry_sexp_release (key); 113 gcry_sexp_release (key);
114 return GNUTLS_E_INTERNAL_ERROR; 114 return GNUTLS_E_INTERNAL_ERROR;
115 } 115 }
@@ -120,7 +120,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
120 list = gcry_sexp_find_token (key, "p", 0); 120 list = gcry_sexp_find_token (key, "p", 0);
121 if (list == NULL) 121 if (list == NULL)
122 { 122 {
123 gnutls_assert (); 123 MHD_gnutls_assert ();
124 gcry_sexp_release (key); 124 gcry_sexp_release (key);
125 return GNUTLS_E_INTERNAL_ERROR; 125 return GNUTLS_E_INTERNAL_ERROR;
126 } 126 }
@@ -132,7 +132,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
132 list = gcry_sexp_find_token (key, "q", 0); 132 list = gcry_sexp_find_token (key, "q", 0);
133 if (list == NULL) 133 if (list == NULL)
134 { 134 {
135 gnutls_assert (); 135 MHD_gnutls_assert ();
136 gcry_sexp_release (key); 136 gcry_sexp_release (key);
137 return GNUTLS_E_INTERNAL_ERROR; 137 return GNUTLS_E_INTERNAL_ERROR;
138 } 138 }
@@ -144,7 +144,7 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
144 list = gcry_sexp_find_token (key, "u", 0); 144 list = gcry_sexp_find_token (key, "u", 0);
145 if (list == NULL) 145 if (list == NULL)
146 { 146 {
147 gnutls_assert (); 147 MHD_gnutls_assert ();
148 gcry_sexp_release (key); 148 gcry_sexp_release (key);
149 return GNUTLS_E_INTERNAL_ERROR; 149 return GNUTLS_E_INTERNAL_ERROR;
150 } 150 }
@@ -154,12 +154,12 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
154 154
155 gcry_sexp_release (key); 155 gcry_sexp_release (key);
156 156
157 _gnutls_dump_mpi ("n: ", resarr[0]); 157 MHD__gnutls_dump_mpi ("n: ", resarr[0]);
158 _gnutls_dump_mpi ("e: ", resarr[1]); 158 MHD__gnutls_dump_mpi ("e: ", resarr[1]);
159 _gnutls_dump_mpi ("d: ", resarr[2]); 159 MHD__gnutls_dump_mpi ("d: ", resarr[2]);
160 _gnutls_dump_mpi ("p: ", resarr[3]); 160 MHD__gnutls_dump_mpi ("p: ", resarr[3]);
161 _gnutls_dump_mpi ("q: ", resarr[4]); 161 MHD__gnutls_dump_mpi ("q: ", resarr[4]);
162 _gnutls_dump_mpi ("u: ", resarr[5]); 162 MHD__gnutls_dump_mpi ("u: ", resarr[5]);
163 163
164 *resarr_len = 6; 164 *resarr_len = 6;
165 165
@@ -168,21 +168,21 @@ _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits)
168} 168}
169 169
170/** 170/**
171 * MHD_gnutls_rsa_params_init - This function will initialize the temporary RSA parameters 171 * MHD__gnutls_rsa_params_init - This function will initialize the temporary RSA parameters
172 * @rsa_params: Is a structure that will hold the parameters 172 * @rsa_params: Is a structure that will hold the parameters
173 * 173 *
174 * This function will initialize the temporary RSA parameters structure. 174 * This function will initialize the temporary RSA parameters structure.
175 * 175 *
176 **/ 176 **/
177int 177int
178MHD_gnutls_rsa_params_init (mhd_gtls_rsa_params_t * rsa_params) 178MHD__gnutls_rsa_params_init (MHD_gtls_rsa_params_t * rsa_params)
179{ 179{
180 int ret; 180 int ret;
181 181
182 ret = gnutls_x509_privkey_init (rsa_params); 182 ret = MHD_gnutls_x509_privkey_init (rsa_params);
183 if (ret < 0) 183 if (ret < 0)
184 { 184 {
185 gnutls_assert (); 185 MHD_gnutls_assert ();
186 return ret; 186 return ret;
187 } 187 }
188 188
@@ -192,20 +192,20 @@ MHD_gnutls_rsa_params_init (mhd_gtls_rsa_params_t * rsa_params)
192} 192}
193 193
194/** 194/**
195 * MHD_gnutls_rsa_params_deinit - This function will deinitialize the RSA parameters 195 * MHD__gnutls_rsa_params_deinit - This function will deinitialize the RSA parameters
196 * @rsa_params: Is a structure that holds the parameters 196 * @rsa_params: Is a structure that holds the parameters
197 * 197 *
198 * This function will deinitialize the RSA parameters structure. 198 * This function will deinitialize the RSA parameters structure.
199 * 199 *
200 **/ 200 **/
201void 201void
202MHD_gnutls_rsa_params_deinit (mhd_gtls_rsa_params_t rsa_params) 202MHD__gnutls_rsa_params_deinit (MHD_gtls_rsa_params_t rsa_params)
203{ 203{
204 gnutls_x509_privkey_deinit (rsa_params); 204 MHD_gnutls_x509_privkey_deinit (rsa_params);
205} 205}
206 206
207/** 207/**
208 * MHD_gnutls_rsa_params_generate2 - This function will generate temporary RSA parameters 208 * MHD__gnutls_rsa_params_generate2 - This function will generate temporary RSA parameters
209 * @params: The structure where the parameters will be stored 209 * @params: The structure where the parameters will be stored
210 * @bits: is the prime's number of bits 210 * @bits: is the prime's number of bits
211 * 211 *
@@ -220,8 +220,8 @@ MHD_gnutls_rsa_params_deinit (mhd_gtls_rsa_params_t rsa_params)
220 * 220 *
221 **/ 221 **/
222int 222int
223MHD_gnutls_rsa_params_generate2 (mhd_gtls_rsa_params_t params, 223MHD__gnutls_rsa_params_generate2 (MHD_gtls_rsa_params_t params,
224 unsigned int bits) 224 unsigned int bits)
225{ 225{
226 return gnutls_x509_privkey_generate (params, MHD_GNUTLS_PK_RSA, bits, 0); 226 return MHD_gnutls_x509_privkey_generate (params, MHD_GNUTLS_PK_RSA, bits, 0);
227} 227}
diff --git a/src/daemon/https/tls/gnutls_rsa_export.h b/src/daemon/https/tls/gnutls_rsa_export.h
index 8e21ed59..61cfdd97 100644
--- a/src/daemon/https/tls/gnutls_rsa_export.h
+++ b/src/daemon/https/tls/gnutls_rsa_export.h
@@ -22,6 +22,6 @@
22 * 22 *
23 */ 23 */
24 24
25const mpi_t *_gnutls_rsa_params_to_mpi (mhd_gtls_rsa_params_t); 25const mpi_t *MHD__gnutls_rsa_params_to_mpi (MHD_gtls_rsa_params_t);
26int _gnutls_peers_cert_less_512 (mhd_gtls_session_t session); 26int MHD__gnutls_peers_cert_less_512 (MHD_gtls_session_t session);
27int _gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits); 27int MHD__gnutls_rsa_generate_params (mpi_t * resarr, int *resarr_len, int bits);
diff --git a/src/daemon/https/tls/gnutls_session.c b/src/daemon/https/tls/gnutls_session.c
index 95758817..81a56d5c 100644
--- a/src/daemon/https/tls/gnutls_session.c
+++ b/src/daemon/https/tls/gnutls_session.c
@@ -31,7 +31,7 @@
31 31
32/** 32/**
33 * MHD_gtls_session_get_id - Returns session id. 33 * MHD_gtls_session_get_id - Returns session id.
34 * @session: is a #mhd_gtls_session_t structure. 34 * @session: is a #MHD_gtls_session_t structure.
35 * @session_id: is a pointer to space to hold the session id. 35 * @session_id: is a pointer to space to hold the session id.
36 * @session_id_size: is the session id's size, or it will be set by the function. 36 * @session_id_size: is the session id's size, or it will be set by the function.
37 * 37 *
@@ -46,7 +46,7 @@
46 * Returns zero on success. 46 * Returns zero on success.
47 **/ 47 **/
48int 48int
49MHD_gtls_session_get_id (mhd_gtls_session_t session, 49MHD_gtls_session_get_id (MHD_gtls_session_t session,
50 void *session_id, size_t * session_id_size) 50 void *session_id, size_t * session_id_size)
51{ 51{
52 size_t given_session_id_size = *session_id_size; 52 size_t given_session_id_size = *session_id_size;
diff --git a/src/daemon/https/tls/gnutls_session_pack.c b/src/daemon/https/tls/gnutls_session_pack.c
index 85bebc8c..258cd9c2 100644
--- a/src/daemon/https/tls/gnutls_session_pack.c
+++ b/src/daemon/https/tls/gnutls_session_pack.c
@@ -43,16 +43,16 @@
43 43
44#define PACK_HEADER_SIZE 1 44#define PACK_HEADER_SIZE 1
45#define MAX_SEC_PARAMS 7+MAX_SRP_USERNAME+MAX_SERVER_NAME_EXTENSIONS*(3+MAX_SERVER_NAME_SIZE)+165 45#define MAX_SEC_PARAMS 7+MAX_SRP_USERNAME+MAX_SERVER_NAME_EXTENSIONS*(3+MAX_SERVER_NAME_SIZE)+165
46static int pack_certificate_auth_info (mhd_gtls_session_t, 46static int pack_certificate_auth_info (MHD_gtls_session_t,
47 gnutls_datum_t * packed_session); 47 MHD_gnutls_datum_t * packed_session);
48static int unpack_certificate_auth_info (mhd_gtls_session_t, 48static int unpack_certificate_auth_info (MHD_gtls_session_t,
49 const gnutls_datum_t * 49 const MHD_gnutls_datum_t *
50 packed_session); 50 packed_session);
51 51
52static int unpack_security_parameters (mhd_gtls_session_t session, 52static int unpack_security_parameters (MHD_gtls_session_t session,
53 const gnutls_datum_t * packed_session); 53 const MHD_gnutls_datum_t * packed_session);
54static int pack_security_parameters (mhd_gtls_session_t session, 54static int pack_security_parameters (MHD_gtls_session_t session,
55 gnutls_datum_t * packed_session); 55 MHD_gnutls_datum_t * packed_session);
56 56
57/* Packs the ANON session authentication data. */ 57/* Packs the ANON session authentication data. */
58#ifdef ENABLE_ANON 58#ifdef ENABLE_ANON
@@ -69,10 +69,10 @@ static int pack_security_parameters (mhd_gtls_session_t session,
69 * x bytes the public key 69 * x bytes the public key
70 */ 70 */
71static int 71static int
72pack_anon_auth_info (mhd_gtls_session_t session, 72pack_anon_auth_info (MHD_gtls_session_t session,
73 gnutls_datum_t * packed_session) 73 MHD_gnutls_datum_t * packed_session)
74{ 74{
75 mhd_anon_auth_info_t info = mhd_gtls_get_auth_info (session); 75 mhd_anon_auth_info_t info = MHD_gtls_get_auth_info (session);
76 int pos = 0; 76 int pos = 0;
77 size_t pack_size; 77 size_t pack_size;
78 78
@@ -87,29 +87,29 @@ pack_anon_auth_info (mhd_gtls_session_t session,
87 /* calculate the size and allocate the data. 87 /* calculate the size and allocate the data.
88 */ 88 */
89 packed_session->data = 89 packed_session->data =
90 gnutls_malloc (packed_session->size + MAX_SEC_PARAMS); 90 MHD_gnutls_malloc (packed_session->size + MAX_SEC_PARAMS);
91 91
92 if (packed_session->data == NULL) 92 if (packed_session->data == NULL)
93 { 93 {
94 gnutls_assert (); 94 MHD_gnutls_assert ();
95 return GNUTLS_E_MEMORY_ERROR; 95 return GNUTLS_E_MEMORY_ERROR;
96 } 96 }
97 97
98 packed_session->data[0] = MHD_GNUTLS_CRD_ANON; 98 packed_session->data[0] = MHD_GNUTLS_CRD_ANON;
99 mhd_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]); 99 MHD_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]);
100 pos += 4 + PACK_HEADER_SIZE; 100 pos += 4 + PACK_HEADER_SIZE;
101 101
102 if (pack_size > 0) 102 if (pack_size > 0)
103 { 103 {
104 mhd_gtls_write_uint16 (info->dh.secret_bits, 104 MHD_gtls_write_uint16 (info->dh.secret_bits,
105 &packed_session->data[pos]); 105 &packed_session->data[pos]);
106 pos += 2; 106 pos += 2;
107 107
108 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime); 108 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime);
109 pos += 4 + info->dh.prime.size; 109 pos += 4 + info->dh.prime.size;
110 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator); 110 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator);
111 pos += 4 + info->dh.generator.size; 111 pos += 4 + info->dh.generator.size;
112 mhd_gtls_write_datum32 (&packed_session->data[pos], 112 MHD_gtls_write_datum32 (&packed_session->data[pos],
113 info->dh.public_key); 113 info->dh.public_key);
114 pos += 4 + info->dh.public_key.size; 114 pos += 4 + info->dh.public_key.size;
115 115
@@ -130,8 +130,8 @@ pack_anon_auth_info (mhd_gtls_session_t session,
130 * x bytes the public key 130 * x bytes the public key
131 */ 131 */
132static int 132static int
133unpack_anon_auth_info (mhd_gtls_session_t session, 133unpack_anon_auth_info (MHD_gtls_session_t session,
134 const gnutls_datum_t * packed_session) 134 const MHD_gnutls_datum_t * packed_session)
135{ 135{
136 size_t pack_size; 136 size_t pack_size;
137 int pos = 0, size, ret; 137 int pos = 0, size, ret;
@@ -139,11 +139,11 @@ unpack_anon_auth_info (mhd_gtls_session_t session,
139 139
140 if (packed_session->data[0] != MHD_GNUTLS_CRD_ANON) 140 if (packed_session->data[0] != MHD_GNUTLS_CRD_ANON)
141 { 141 {
142 gnutls_assert (); 142 MHD_gnutls_assert ();
143 return GNUTLS_E_INVALID_REQUEST; 143 return GNUTLS_E_INVALID_REQUEST;
144 } 144 }
145 145
146 pack_size = mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]); 146 pack_size = MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]);
147 pos += PACK_HEADER_SIZE + 4; 147 pos += PACK_HEADER_SIZE + 4;
148 148
149 149
@@ -153,60 +153,60 @@ unpack_anon_auth_info (mhd_gtls_session_t session,
153 /* a simple check for integrity */ 153 /* a simple check for integrity */
154 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size) 154 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size)
155 { 155 {
156 gnutls_assert (); 156 MHD_gnutls_assert ();
157 return GNUTLS_E_INVALID_REQUEST; 157 return GNUTLS_E_INVALID_REQUEST;
158 } 158 }
159 159
160 /* client and serer have the same auth_info here 160 /* client and serer have the same auth_info here
161 */ 161 */
162 ret = 162 ret =
163 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON, 163 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_ANON,
164 sizeof (anon_auth_info_st), 1); 164 sizeof (anon_auth_info_st), 1);
165 if (ret < 0) 165 if (ret < 0)
166 { 166 {
167 gnutls_assert (); 167 MHD_gnutls_assert ();
168 return ret; 168 return ret;
169 } 169 }
170 170
171 info = mhd_gtls_get_auth_info (session); 171 info = MHD_gtls_get_auth_info (session);
172 if (info == NULL) 172 if (info == NULL)
173 { 173 {
174 gnutls_assert (); 174 MHD_gnutls_assert ();
175 return GNUTLS_E_INTERNAL_ERROR; 175 return GNUTLS_E_INTERNAL_ERROR;
176 } 176 }
177 177
178 info->dh.secret_bits = mhd_gtls_read_uint16 (&packed_session->data[pos]); 178 info->dh.secret_bits = MHD_gtls_read_uint16 (&packed_session->data[pos]);
179 pos += 2; 179 pos += 2;
180 180
181 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 181 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
182 pos += 4; 182 pos += 4;
183 ret = _gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size); 183 ret = MHD__gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size);
184 if (ret < 0) 184 if (ret < 0)
185 { 185 {
186 gnutls_assert (); 186 MHD_gnutls_assert ();
187 goto error; 187 goto error;
188 } 188 }
189 pos += size; 189 pos += size;
190 190
191 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 191 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
192 pos += 4; 192 pos += 4;
193 ret = 193 ret =
194 _gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size); 194 MHD__gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size);
195 if (ret < 0) 195 if (ret < 0)
196 { 196 {
197 gnutls_assert (); 197 MHD_gnutls_assert ();
198 goto error; 198 goto error;
199 } 199 }
200 pos += size; 200 pos += size;
201 201
202 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 202 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
203 pos += 4; 203 pos += 4;
204 ret = 204 ret =
205 _gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos], 205 MHD__gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos],
206 size); 206 size);
207 if (ret < 0) 207 if (ret < 0)
208 { 208 {
209 gnutls_assert (); 209 MHD_gnutls_assert ();
210 goto error; 210 goto error;
211 } 211 }
212 pos += size; 212 pos += size;
@@ -214,9 +214,9 @@ unpack_anon_auth_info (mhd_gtls_session_t session,
214 return 0; 214 return 0;
215 215
216error: 216error:
217 _gnutls_free_datum (&info->dh.prime); 217 MHD__gnutls_free_datum (&info->dh.prime);
218 _gnutls_free_datum (&info->dh.generator); 218 MHD__gnutls_free_datum (&info->dh.generator);
219 _gnutls_free_datum (&info->dh.public_key); 219 MHD__gnutls_free_datum (&info->dh.public_key);
220 return ret; 220 return ret;
221} 221}
222#endif /* ANON */ 222#endif /* ANON */
@@ -230,14 +230,14 @@ error:
230 * The data will be in a platform independent format. 230 * The data will be in a platform independent format.
231 */ 231 */
232int 232int
233mhd_gtls_session_pack (mhd_gtls_session_t session, 233MHD_gtls_session_pack (MHD_gtls_session_t session,
234 gnutls_datum_t * packed_session) 234 MHD_gnutls_datum_t * packed_session)
235{ 235{
236 int ret; 236 int ret;
237 237
238 if (packed_session == NULL) 238 if (packed_session == NULL)
239 { 239 {
240 gnutls_assert (); 240 MHD_gnutls_assert ();
241 return GNUTLS_E_INTERNAL_ERROR; 241 return GNUTLS_E_INTERNAL_ERROR;
242 } 242 }
243 243
@@ -249,7 +249,7 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
249 ret = pack_srp_auth_info (session, packed_session); 249 ret = pack_srp_auth_info (session, packed_session);
250 if (ret < 0) 250 if (ret < 0)
251 { 251 {
252 gnutls_assert (); 252 MHD_gnutls_assert ();
253 return ret; 253 return ret;
254 } 254 }
255 break; 255 break;
@@ -259,7 +259,7 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
259 ret = pack_psk_auth_info (session, packed_session); 259 ret = pack_psk_auth_info (session, packed_session);
260 if (ret < 0) 260 if (ret < 0)
261 { 261 {
262 gnutls_assert (); 262 MHD_gnutls_assert ();
263 return ret; 263 return ret;
264 } 264 }
265 break; 265 break;
@@ -269,7 +269,7 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
269 ret = pack_anon_auth_info (session, packed_session); 269 ret = pack_anon_auth_info (session, packed_session);
270 if (ret < 0) 270 if (ret < 0)
271 { 271 {
272 gnutls_assert (); 272 MHD_gnutls_assert ();
273 return ret; 273 return ret;
274 } 274 }
275 break; 275 break;
@@ -278,7 +278,7 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
278 ret = pack_certificate_auth_info (session, packed_session); 278 ret = pack_certificate_auth_info (session, packed_session);
279 if (ret < 0) 279 if (ret < 0)
280 { 280 {
281 gnutls_assert (); 281 MHD_gnutls_assert ();
282 return ret; 282 return ret;
283 } 283 }
284 break; 284 break;
@@ -287,14 +287,14 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
287 287
288 } 288 }
289 289
290 /* Auth_info structures copied. Now copy mhd_gtls_security_param_st. 290 /* Auth_info structures copied. Now copy MHD_gtls_security_param_st.
291 * packed_session must have allocated space for the security parameters. 291 * packed_session must have allocated space for the security parameters.
292 */ 292 */
293 ret = pack_security_parameters (session, packed_session); 293 ret = pack_security_parameters (session, packed_session);
294 if (ret < 0) 294 if (ret < 0)
295 { 295 {
296 gnutls_assert (); 296 MHD_gnutls_assert ();
297 _gnutls_free_datum (packed_session); 297 MHD__gnutls_free_datum (packed_session);
298 return ret; 298 return ret;
299 } 299 }
300 300
@@ -305,20 +305,20 @@ mhd_gtls_session_pack (mhd_gtls_session_t session,
305/* Load session data from a buffer. 305/* Load session data from a buffer.
306 */ 306 */
307int 307int
308mhd_gtls_session_unpack (mhd_gtls_session_t session, 308MHD_gtls_session_unpack (MHD_gtls_session_t session,
309 const gnutls_datum_t * packed_session) 309 const MHD_gnutls_datum_t * packed_session)
310{ 310{
311 int ret; 311 int ret;
312 312
313 if (packed_session == NULL || packed_session->size == 0) 313 if (packed_session == NULL || packed_session->size == 0)
314 { 314 {
315 gnutls_assert (); 315 MHD_gnutls_assert ();
316 return GNUTLS_E_INTERNAL_ERROR; 316 return GNUTLS_E_INTERNAL_ERROR;
317 } 317 }
318 318
319 if (mhd_gtls_get_auth_info (session) != NULL) 319 if (MHD_gtls_get_auth_info (session) != NULL)
320 { 320 {
321 mhd_gtls_free_auth_info (session); 321 MHD_gtls_free_auth_info (session);
322 } 322 }
323 323
324 switch (packed_session->data[0]) 324 switch (packed_session->data[0])
@@ -328,7 +328,7 @@ mhd_gtls_session_unpack (mhd_gtls_session_t session,
328 ret = unpack_srp_auth_info (session, packed_session); 328 ret = unpack_srp_auth_info (session, packed_session);
329 if (ret < 0) 329 if (ret < 0)
330 { 330 {
331 gnutls_assert (); 331 MHD_gnutls_assert ();
332 return ret; 332 return ret;
333 } 333 }
334 break; 334 break;
@@ -338,7 +338,7 @@ mhd_gtls_session_unpack (mhd_gtls_session_t session,
338 ret = unpack_psk_auth_info (session, packed_session); 338 ret = unpack_psk_auth_info (session, packed_session);
339 if (ret < 0) 339 if (ret < 0)
340 { 340 {
341 gnutls_assert (); 341 MHD_gnutls_assert ();
342 return ret; 342 return ret;
343 } 343 }
344 break; 344 break;
@@ -348,7 +348,7 @@ mhd_gtls_session_unpack (mhd_gtls_session_t session,
348 ret = unpack_anon_auth_info (session, packed_session); 348 ret = unpack_anon_auth_info (session, packed_session);
349 if (ret < 0) 349 if (ret < 0)
350 { 350 {
351 gnutls_assert (); 351 MHD_gnutls_assert ();
352 return ret; 352 return ret;
353 } 353 }
354 break; 354 break;
@@ -357,23 +357,23 @@ mhd_gtls_session_unpack (mhd_gtls_session_t session,
357 ret = unpack_certificate_auth_info (session, packed_session); 357 ret = unpack_certificate_auth_info (session, packed_session);
358 if (ret < 0) 358 if (ret < 0)
359 { 359 {
360 gnutls_assert (); 360 MHD_gnutls_assert ();
361 return ret; 361 return ret;
362 } 362 }
363 break; 363 break;
364 default: 364 default:
365 gnutls_assert (); 365 MHD_gnutls_assert ();
366 return GNUTLS_E_INTERNAL_ERROR; 366 return GNUTLS_E_INTERNAL_ERROR;
367 367
368 } 368 }
369 369
370 /* Auth_info structures copied. Now copy mhd_gtls_security_param_st. 370 /* Auth_info structures copied. Now copy MHD_gtls_security_param_st.
371 * packed_session must have allocated space for the security parameters. 371 * packed_session must have allocated space for the security parameters.
372 */ 372 */
373 ret = unpack_security_parameters (session, packed_session); 373 ret = unpack_security_parameters (session, packed_session);
374 if (ret < 0) 374 if (ret < 0)
375 { 375 {
376 gnutls_assert (); 376 MHD_gnutls_assert ();
377 return ret; 377 return ret;
378 } 378 }
379 379
@@ -404,12 +404,12 @@ mhd_gtls_session_unpack (mhd_gtls_session_t session,
404 * and so on... 404 * and so on...
405 */ 405 */
406static int 406static int
407pack_certificate_auth_info (mhd_gtls_session_t session, 407pack_certificate_auth_info (MHD_gtls_session_t session,
408 gnutls_datum_t * packed_session) 408 MHD_gnutls_datum_t * packed_session)
409{ 409{
410 unsigned int pos = 0, i; 410 unsigned int pos = 0, i;
411 int cert_size, pack_size; 411 int cert_size, pack_size;
412 cert_auth_info_t info = mhd_gtls_get_auth_info (session); 412 cert_auth_info_t info = MHD_gtls_get_auth_info (session);
413 413
414 if (info) 414 if (info)
415 { 415 {
@@ -431,47 +431,47 @@ pack_certificate_auth_info (mhd_gtls_session_t session,
431 /* calculate the size and allocate the data. 431 /* calculate the size and allocate the data.
432 */ 432 */
433 packed_session->data = 433 packed_session->data =
434 gnutls_malloc (packed_session->size + MAX_SEC_PARAMS); 434 MHD_gnutls_malloc (packed_session->size + MAX_SEC_PARAMS);
435 435
436 if (packed_session->data == NULL) 436 if (packed_session->data == NULL)
437 { 437 {
438 gnutls_assert (); 438 MHD_gnutls_assert ();
439 return GNUTLS_E_MEMORY_ERROR; 439 return GNUTLS_E_MEMORY_ERROR;
440 } 440 }
441 441
442 packed_session->data[0] = MHD_GNUTLS_CRD_CERTIFICATE; 442 packed_session->data[0] = MHD_GNUTLS_CRD_CERTIFICATE;
443 mhd_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]); 443 MHD_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]);
444 pos += 4 + PACK_HEADER_SIZE; 444 pos += 4 + PACK_HEADER_SIZE;
445 445
446 446
447 if (pack_size > 0) 447 if (pack_size > 0)
448 { 448 {
449 449
450 mhd_gtls_write_uint16 (info->dh.secret_bits, 450 MHD_gtls_write_uint16 (info->dh.secret_bits,
451 &packed_session->data[pos]); 451 &packed_session->data[pos]);
452 pos += 2; 452 pos += 2;
453 453
454 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime); 454 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime);
455 pos += 4 + info->dh.prime.size; 455 pos += 4 + info->dh.prime.size;
456 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator); 456 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator);
457 pos += 4 + info->dh.generator.size; 457 pos += 4 + info->dh.generator.size;
458 mhd_gtls_write_datum32 (&packed_session->data[pos], 458 MHD_gtls_write_datum32 (&packed_session->data[pos],
459 info->dh.public_key); 459 info->dh.public_key);
460 pos += 4 + info->dh.public_key.size; 460 pos += 4 + info->dh.public_key.size;
461 461
462 mhd_gtls_write_datum32 (&packed_session->data[pos], 462 MHD_gtls_write_datum32 (&packed_session->data[pos],
463 info->rsa_export.modulus); 463 info->rsa_export.modulus);
464 pos += 4 + info->rsa_export.modulus.size; 464 pos += 4 + info->rsa_export.modulus.size;
465 mhd_gtls_write_datum32 (&packed_session->data[pos], 465 MHD_gtls_write_datum32 (&packed_session->data[pos],
466 info->rsa_export.exponent); 466 info->rsa_export.exponent);
467 pos += 4 + info->rsa_export.exponent.size; 467 pos += 4 + info->rsa_export.exponent.size;
468 468
469 mhd_gtls_write_uint32 (info->ncerts, &packed_session->data[pos]); 469 MHD_gtls_write_uint32 (info->ncerts, &packed_session->data[pos]);
470 pos += 4; 470 pos += 4;
471 471
472 for (i = 0; i < info->ncerts; i++) 472 for (i = 0; i < info->ncerts; i++)
473 { 473 {
474 mhd_gtls_write_datum32 (&packed_session->data[pos], 474 MHD_gtls_write_datum32 (&packed_session->data[pos],
475 info->raw_certificate_list[i]); 475 info->raw_certificate_list[i]);
476 pos += sizeof (uint32_t) + info->raw_certificate_list[i].size; 476 pos += sizeof (uint32_t) + info->raw_certificate_list[i].size;
477 } 477 }
@@ -484,8 +484,8 @@ pack_certificate_auth_info (mhd_gtls_session_t session,
484/* Upack certificate info. 484/* Upack certificate info.
485 */ 485 */
486static int 486static int
487unpack_certificate_auth_info (mhd_gtls_session_t session, 487unpack_certificate_auth_info (MHD_gtls_session_t session,
488 const gnutls_datum_t * packed_session) 488 const MHD_gnutls_datum_t * packed_session)
489{ 489{
490 int pos = 0, size, ret; 490 int pos = 0, size, ret;
491 unsigned int i = 0, j; 491 unsigned int i = 0, j;
@@ -494,11 +494,11 @@ unpack_certificate_auth_info (mhd_gtls_session_t session,
494 494
495 if (packed_session->data[0] != MHD_GNUTLS_CRD_CERTIFICATE) 495 if (packed_session->data[0] != MHD_GNUTLS_CRD_CERTIFICATE)
496 { 496 {
497 gnutls_assert (); 497 MHD_gnutls_assert ();
498 return GNUTLS_E_INVALID_REQUEST; 498 return GNUTLS_E_INVALID_REQUEST;
499 } 499 }
500 500
501 pack_size = mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]); 501 pack_size = MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]);
502 pos += PACK_HEADER_SIZE + 4; 502 pos += PACK_HEADER_SIZE + 4;
503 503
504 if (pack_size == 0) 504 if (pack_size == 0)
@@ -507,98 +507,98 @@ unpack_certificate_auth_info (mhd_gtls_session_t session,
507 /* a simple check for integrity */ 507 /* a simple check for integrity */
508 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size) 508 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size)
509 { 509 {
510 gnutls_assert (); 510 MHD_gnutls_assert ();
511 return GNUTLS_E_INVALID_REQUEST; 511 return GNUTLS_E_INVALID_REQUEST;
512 } 512 }
513 513
514 /* client and server have the same auth_info here 514 /* client and server have the same auth_info here
515 */ 515 */
516 ret = 516 ret =
517 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE, 517 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_CERTIFICATE,
518 sizeof (cert_auth_info_st), 1); 518 sizeof (cert_auth_info_st), 1);
519 if (ret < 0) 519 if (ret < 0)
520 { 520 {
521 gnutls_assert (); 521 MHD_gnutls_assert ();
522 return ret; 522 return ret;
523 } 523 }
524 524
525 info = mhd_gtls_get_auth_info (session); 525 info = MHD_gtls_get_auth_info (session);
526 if (info == NULL) 526 if (info == NULL)
527 { 527 {
528 gnutls_assert (); 528 MHD_gnutls_assert ();
529 return GNUTLS_E_INTERNAL_ERROR; 529 return GNUTLS_E_INTERNAL_ERROR;
530 } 530 }
531 531
532 info->dh.secret_bits = mhd_gtls_read_uint16 (&packed_session->data[pos]); 532 info->dh.secret_bits = MHD_gtls_read_uint16 (&packed_session->data[pos]);
533 pos += 2; 533 pos += 2;
534 534
535 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 535 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
536 pos += 4; 536 pos += 4;
537 ret = _gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size); 537 ret = MHD__gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size);
538 if (ret < 0) 538 if (ret < 0)
539 { 539 {
540 gnutls_assert (); 540 MHD_gnutls_assert ();
541 goto error; 541 goto error;
542 } 542 }
543 pos += size; 543 pos += size;
544 544
545 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 545 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
546 pos += 4; 546 pos += 4;
547 ret = 547 ret =
548 _gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size); 548 MHD__gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size);
549 if (ret < 0) 549 if (ret < 0)
550 { 550 {
551 gnutls_assert (); 551 MHD_gnutls_assert ();
552 goto error; 552 goto error;
553 } 553 }
554 pos += size; 554 pos += size;
555 555
556 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 556 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
557 pos += 4; 557 pos += 4;
558 ret = 558 ret =
559 _gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos], 559 MHD__gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos],
560 size); 560 size);
561 if (ret < 0) 561 if (ret < 0)
562 { 562 {
563 gnutls_assert (); 563 MHD_gnutls_assert ();
564 goto error; 564 goto error;
565 } 565 }
566 pos += size; 566 pos += size;
567 567
568 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 568 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
569 pos += 4; 569 pos += 4;
570 ret = 570 ret =
571 _gnutls_set_datum (&info->rsa_export.modulus, 571 MHD__gnutls_set_datum (&info->rsa_export.modulus,
572 &packed_session->data[pos], size); 572 &packed_session->data[pos], size);
573 if (ret < 0) 573 if (ret < 0)
574 { 574 {
575 gnutls_assert (); 575 MHD_gnutls_assert ();
576 goto error; 576 goto error;
577 } 577 }
578 pos += size; 578 pos += size;
579 579
580 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 580 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
581 pos += 4; 581 pos += 4;
582 ret = 582 ret =
583 _gnutls_set_datum (&info->rsa_export.exponent, 583 MHD__gnutls_set_datum (&info->rsa_export.exponent,
584 &packed_session->data[pos], size); 584 &packed_session->data[pos], size);
585 if (ret < 0) 585 if (ret < 0)
586 { 586 {
587 gnutls_assert (); 587 MHD_gnutls_assert ();
588 goto error; 588 goto error;
589 } 589 }
590 pos += size; 590 pos += size;
591 591
592 info->ncerts = mhd_gtls_read_uint32 (&packed_session->data[pos]); 592 info->ncerts = MHD_gtls_read_uint32 (&packed_session->data[pos]);
593 pos += 4; 593 pos += 4;
594 594
595 if (info->ncerts > 0) 595 if (info->ncerts > 0)
596 { 596 {
597 info->raw_certificate_list = 597 info->raw_certificate_list =
598 gnutls_calloc (1, sizeof (gnutls_datum_t) * info->ncerts); 598 MHD_gnutls_calloc (1, sizeof (MHD_gnutls_datum_t) * info->ncerts);
599 if (info->raw_certificate_list == NULL) 599 if (info->raw_certificate_list == NULL)
600 { 600 {
601 gnutls_assert (); 601 MHD_gnutls_assert ();
602 ret = GNUTLS_E_MEMORY_ERROR; 602 ret = GNUTLS_E_MEMORY_ERROR;
603 goto error; 603 goto error;
604 } 604 }
@@ -606,17 +606,17 @@ unpack_certificate_auth_info (mhd_gtls_session_t session,
606 606
607 for (i = 0; i < info->ncerts; i++) 607 for (i = 0; i < info->ncerts; i++)
608 { 608 {
609 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 609 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
610 pos += sizeof (uint32_t); 610 pos += sizeof (uint32_t);
611 611
612 ret = 612 ret =
613 _gnutls_set_datum (&info->raw_certificate_list[i], 613 MHD__gnutls_set_datum (&info->raw_certificate_list[i],
614 &packed_session->data[pos], size); 614 &packed_session->data[pos], size);
615 pos += size; 615 pos += size;
616 616
617 if (ret < 0) 617 if (ret < 0)
618 { 618 {
619 gnutls_assert (); 619 MHD_gnutls_assert ();
620 goto error; 620 goto error;
621 } 621 }
622 } 622 }
@@ -625,17 +625,17 @@ unpack_certificate_auth_info (mhd_gtls_session_t session,
625 return 0; 625 return 0;
626 626
627error: 627error:
628 _gnutls_free_datum (&info->dh.prime); 628 MHD__gnutls_free_datum (&info->dh.prime);
629 _gnutls_free_datum (&info->dh.generator); 629 MHD__gnutls_free_datum (&info->dh.generator);
630 _gnutls_free_datum (&info->dh.public_key); 630 MHD__gnutls_free_datum (&info->dh.public_key);
631 631
632 _gnutls_free_datum (&info->rsa_export.modulus); 632 MHD__gnutls_free_datum (&info->rsa_export.modulus);
633 _gnutls_free_datum (&info->rsa_export.exponent); 633 MHD__gnutls_free_datum (&info->rsa_export.exponent);
634 634
635 for (j = 0; j < i; j++) 635 for (j = 0; j < i; j++)
636 _gnutls_free_datum (&info->raw_certificate_list[j]); 636 MHD__gnutls_free_datum (&info->raw_certificate_list[j]);
637 637
638 gnutls_free (info->raw_certificate_list); 638 MHD_gnutls_free (info->raw_certificate_list);
639 639
640 return ret; 640 return ret;
641 641
@@ -651,10 +651,10 @@ error:
651 * x bytes the SRP username 651 * x bytes the SRP username
652 */ 652 */
653static int 653static int
654pack_srp_auth_info (mhd_gtls_session_t session, 654pack_srp_auth_info (MHD_gtls_session_t session,
655 gnutls_datum_t * packed_session) 655 MHD_gnutls_datum_t * packed_session)
656{ 656{
657 srp_server_auth_info_t info = mhd_gtls_get_auth_info (session); 657 srp_server_auth_info_t info = MHD_gtls_get_auth_info (session);
658 int pack_size; 658 int pack_size;
659 659
660 if (info && info->username) 660 if (info && info->username)
@@ -667,16 +667,16 @@ pack_srp_auth_info (mhd_gtls_session_t session,
667 /* calculate the size and allocate the data. 667 /* calculate the size and allocate the data.
668 */ 668 */
669 packed_session->data = 669 packed_session->data =
670 gnutls_malloc (packed_session->size + MAX_SEC_PARAMS); 670 MHD_gnutls_malloc (packed_session->size + MAX_SEC_PARAMS);
671 671
672 if (packed_session->data == NULL) 672 if (packed_session->data == NULL)
673 { 673 {
674 gnutls_assert (); 674 MHD_gnutls_assert ();
675 return GNUTLS_E_MEMORY_ERROR; 675 return GNUTLS_E_MEMORY_ERROR;
676 } 676 }
677 677
678 packed_session->data[0] = MHD_GNUTLS_CRD_SRP; 678 packed_session->data[0] = MHD_GNUTLS_CRD_SRP;
679 mhd_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]); 679 MHD_gtls_write_uint32 (pack_size, &packed_session->data[PACK_HEADER_SIZE]);
680 680
681 if (pack_size > 0) 681 if (pack_size > 0)
682 memcpy (&packed_session->data[PACK_HEADER_SIZE + sizeof (uint32_t)], 682 memcpy (&packed_session->data[PACK_HEADER_SIZE + sizeof (uint32_t)],
@@ -687,8 +687,8 @@ pack_srp_auth_info (mhd_gtls_session_t session,
687 687
688 688
689static int 689static int
690unpack_srp_auth_info (mhd_gtls_session_t session, 690unpack_srp_auth_info (MHD_gtls_session_t session,
691 const gnutls_datum_t * packed_session) 691 const MHD_gnutls_datum_t * packed_session)
692{ 692{
693 size_t username_size; 693 size_t username_size;
694 int ret; 694 int ret;
@@ -696,12 +696,12 @@ unpack_srp_auth_info (mhd_gtls_session_t session,
696 696
697 if (packed_session->data[0] != MHD_GNUTLS_CRD_SRP) 697 if (packed_session->data[0] != MHD_GNUTLS_CRD_SRP)
698 { 698 {
699 gnutls_assert (); 699 MHD_gnutls_assert ();
700 return GNUTLS_E_INVALID_REQUEST; 700 return GNUTLS_E_INVALID_REQUEST;
701 } 701 }
702 702
703 username_size = 703 username_size =
704 mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]); 704 MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]);
705 705
706 if (username_size == 0) 706 if (username_size == 0)
707 return 0; /* nothing to be done */ 707 return 0; /* nothing to be done */
@@ -709,23 +709,23 @@ unpack_srp_auth_info (mhd_gtls_session_t session,
709 /* a simple check for integrity */ 709 /* a simple check for integrity */
710 if (username_size + 4 + PACK_HEADER_SIZE > packed_session->size) 710 if (username_size + 4 + PACK_HEADER_SIZE > packed_session->size)
711 { 711 {
712 gnutls_assert (); 712 MHD_gnutls_assert ();
713 return GNUTLS_E_INVALID_REQUEST; 713 return GNUTLS_E_INVALID_REQUEST;
714 } 714 }
715 715
716 ret = 716 ret =
717 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_SRP, 717 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_SRP,
718 sizeof (srp_server_auth_info_st), 1); 718 sizeof (srp_server_auth_info_st), 1);
719 if (ret < 0) 719 if (ret < 0)
720 { 720 {
721 gnutls_assert (); 721 MHD_gnutls_assert ();
722 return ret; 722 return ret;
723 } 723 }
724 724
725 info = mhd_gtls_get_auth_info (session); 725 info = MHD_gtls_get_auth_info (session);
726 if (info == NULL) 726 if (info == NULL)
727 { 727 {
728 gnutls_assert (); 728 MHD_gnutls_assert ();
729 return GNUTLS_E_INTERNAL_ERROR; 729 return GNUTLS_E_INTERNAL_ERROR;
730 } 730 }
731 731
@@ -757,13 +757,13 @@ unpack_srp_auth_info (mhd_gtls_session_t session,
757 * x bytes the public key 757 * x bytes the public key
758 */ 758 */
759static int 759static int
760pack_psk_auth_info (mhd_gtls_session_t session, 760pack_psk_auth_info (MHD_gtls_session_t session,
761 gnutls_datum_t * packed_session) 761 MHD_gnutls_datum_t * packed_session)
762{ 762{
763 psk_auth_info_t info; 763 psk_auth_info_t info;
764 int pack_size, username_size = 0, pos; 764 int pack_size, username_size = 0, pos;
765 765
766 info = mhd_gtls_get_auth_info (session); 766 info = MHD_gtls_get_auth_info (session);
767 767
768 if (info) 768 if (info)
769 { 769 {
@@ -780,11 +780,11 @@ pack_psk_auth_info (mhd_gtls_session_t session,
780 /* calculate the size and allocate the data. 780 /* calculate the size and allocate the data.
781 */ 781 */
782 packed_session->data = 782 packed_session->data =
783 gnutls_malloc (packed_session->size + MAX_SEC_PARAMS); 783 MHD_gnutls_malloc (packed_session->size + MAX_SEC_PARAMS);
784 784
785 if (packed_session->data == NULL) 785 if (packed_session->data == NULL)
786 { 786 {
787 gnutls_assert (); 787 MHD_gnutls_assert ();
788 return GNUTLS_E_MEMORY_ERROR; 788 return GNUTLS_E_MEMORY_ERROR;
789 } 789 }
790 790
@@ -793,27 +793,27 @@ pack_psk_auth_info (mhd_gtls_session_t session,
793 packed_session->data[pos] = MHD_GNUTLS_CRD_PSK; 793 packed_session->data[pos] = MHD_GNUTLS_CRD_PSK;
794 pos++; 794 pos++;
795 795
796 mhd_gtls_write_uint32 (pack_size, &packed_session->data[pos]); 796 MHD_gtls_write_uint32 (pack_size, &packed_session->data[pos]);
797 pos += 4; 797 pos += 4;
798 798
799 799
800 if (pack_size > 0) 800 if (pack_size > 0)
801 { 801 {
802 mhd_gtls_write_uint32 (username_size, &packed_session->data[pos]); 802 MHD_gtls_write_uint32 (username_size, &packed_session->data[pos]);
803 pos += 4; 803 pos += 4;
804 804
805 memcpy (&packed_session->data[pos], info->username, username_size); 805 memcpy (&packed_session->data[pos], info->username, username_size);
806 pos += username_size; 806 pos += username_size;
807 807
808 mhd_gtls_write_uint16 (info->dh.secret_bits, 808 MHD_gtls_write_uint16 (info->dh.secret_bits,
809 &packed_session->data[pos]); 809 &packed_session->data[pos]);
810 pos += 2; 810 pos += 2;
811 811
812 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime); 812 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.prime);
813 pos += 4 + info->dh.prime.size; 813 pos += 4 + info->dh.prime.size;
814 mhd_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator); 814 MHD_gtls_write_datum32 (&packed_session->data[pos], info->dh.generator);
815 pos += 4 + info->dh.generator.size; 815 pos += 4 + info->dh.generator.size;
816 mhd_gtls_write_datum32 (&packed_session->data[pos], 816 MHD_gtls_write_datum32 (&packed_session->data[pos],
817 info->dh.public_key); 817 info->dh.public_key);
818 pos += 4 + info->dh.public_key.size; 818 pos += 4 + info->dh.public_key.size;
819 819
@@ -824,8 +824,8 @@ pack_psk_auth_info (mhd_gtls_session_t session,
824} 824}
825 825
826static int 826static int
827unpack_psk_auth_info (mhd_gtls_session_t session, 827unpack_psk_auth_info (MHD_gtls_session_t session,
828 const gnutls_datum_t * packed_session) 828 const MHD_gnutls_datum_t * packed_session)
829{ 829{
830 size_t username_size; 830 size_t username_size;
831 size_t pack_size; 831 size_t pack_size;
@@ -834,11 +834,11 @@ unpack_psk_auth_info (mhd_gtls_session_t session,
834 834
835 if (packed_session->data[0] != MHD_GNUTLS_CRD_PSK) 835 if (packed_session->data[0] != MHD_GNUTLS_CRD_PSK)
836 { 836 {
837 gnutls_assert (); 837 MHD_gnutls_assert ();
838 return GNUTLS_E_INVALID_REQUEST; 838 return GNUTLS_E_INVALID_REQUEST;
839 } 839 }
840 840
841 pack_size = mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]); 841 pack_size = MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]);
842 pos += PACK_HEADER_SIZE + 4; 842 pos += PACK_HEADER_SIZE + 4;
843 843
844 844
@@ -848,66 +848,66 @@ unpack_psk_auth_info (mhd_gtls_session_t session,
848 /* a simple check for integrity */ 848 /* a simple check for integrity */
849 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size) 849 if (pack_size + PACK_HEADER_SIZE + 4 > packed_session->size)
850 { 850 {
851 gnutls_assert (); 851 MHD_gnutls_assert ();
852 return GNUTLS_E_INVALID_REQUEST; 852 return GNUTLS_E_INVALID_REQUEST;
853 } 853 }
854 854
855 /* client and serer have the same auth_info here 855 /* client and serer have the same auth_info here
856 */ 856 */
857 ret = 857 ret =
858 mhd_gtls_auth_info_set (session, MHD_GNUTLS_CRD_PSK, 858 MHD_gtls_auth_info_set (session, MHD_GNUTLS_CRD_PSK,
859 sizeof (psk_auth_info_st), 1); 859 sizeof (psk_auth_info_st), 1);
860 if (ret < 0) 860 if (ret < 0)
861 { 861 {
862 gnutls_assert (); 862 MHD_gnutls_assert ();
863 return ret; 863 return ret;
864 } 864 }
865 865
866 info = mhd_gtls_get_auth_info (session); 866 info = MHD_gtls_get_auth_info (session);
867 if (info == NULL) 867 if (info == NULL)
868 { 868 {
869 gnutls_assert (); 869 MHD_gnutls_assert ();
870 return GNUTLS_E_INTERNAL_ERROR; 870 return GNUTLS_E_INTERNAL_ERROR;
871 } 871 }
872 872
873 username_size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 873 username_size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
874 pos += 4; 874 pos += 4;
875 875
876 memcpy (info->username, &packed_session->data[pos], username_size); 876 memcpy (info->username, &packed_session->data[pos], username_size);
877 pos += username_size; 877 pos += username_size;
878 878
879 info->dh.secret_bits = mhd_gtls_read_uint16 (&packed_session->data[pos]); 879 info->dh.secret_bits = MHD_gtls_read_uint16 (&packed_session->data[pos]);
880 pos += 2; 880 pos += 2;
881 881
882 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 882 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
883 pos += 4; 883 pos += 4;
884 ret = _gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size); 884 ret = MHD__gnutls_set_datum (&info->dh.prime, &packed_session->data[pos], size);
885 if (ret < 0) 885 if (ret < 0)
886 { 886 {
887 gnutls_assert (); 887 MHD_gnutls_assert ();
888 goto error; 888 goto error;
889 } 889 }
890 pos += size; 890 pos += size;
891 891
892 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 892 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
893 pos += 4; 893 pos += 4;
894 ret = 894 ret =
895 _gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size); 895 MHD__gnutls_set_datum (&info->dh.generator, &packed_session->data[pos], size);
896 if (ret < 0) 896 if (ret < 0)
897 { 897 {
898 gnutls_assert (); 898 MHD_gnutls_assert ();
899 goto error; 899 goto error;
900 } 900 }
901 pos += size; 901 pos += size;
902 902
903 size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 903 size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
904 pos += 4; 904 pos += 4;
905 ret = 905 ret =
906 _gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos], 906 MHD__gnutls_set_datum (&info->dh.public_key, &packed_session->data[pos],
907 size); 907 size);
908 if (ret < 0) 908 if (ret < 0)
909 { 909 {
910 gnutls_assert (); 910 MHD_gnutls_assert ();
911 goto error; 911 goto error;
912 } 912 }
913 pos += size; 913 pos += size;
@@ -915,9 +915,9 @@ unpack_psk_auth_info (mhd_gtls_session_t session,
915 return 0; 915 return 0;
916 916
917error: 917error:
918 _gnutls_free_datum (&info->dh.prime); 918 MHD__gnutls_free_datum (&info->dh.prime);
919 _gnutls_free_datum (&info->dh.generator); 919 MHD__gnutls_free_datum (&info->dh.generator);
920 _gnutls_free_datum (&info->dh.public_key); 920 MHD__gnutls_free_datum (&info->dh.public_key);
921 return ret; 921 return ret;
922} 922}
923#endif 923#endif
@@ -972,8 +972,8 @@ error:
972 * MAX: 7+MAX_SRP_USERNAME+MAX_SERVER_NAME_EXTENSIONS*(3+MAX_SERVER_NAME_SIZE) 972 * MAX: 7+MAX_SRP_USERNAME+MAX_SERVER_NAME_EXTENSIONS*(3+MAX_SERVER_NAME_SIZE)
973 */ 973 */
974static int 974static int
975pack_security_parameters (mhd_gtls_session_t session, 975pack_security_parameters (MHD_gtls_session_t session,
976 gnutls_datum_t * packed_session) 976 MHD_gnutls_datum_t * packed_session)
977{ 977{
978 int pos = 0; 978 int pos = 0;
979 size_t len, init, i; 979 size_t len, init, i;
@@ -981,7 +981,7 @@ pack_security_parameters (mhd_gtls_session_t session,
981 /* move after the auth info stuff. 981 /* move after the auth info stuff.
982 */ 982 */
983 init = 983 init =
984 mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]) + 4 + 984 MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]) + 4 +
985 PACK_HEADER_SIZE; 985 PACK_HEADER_SIZE;
986 986
987 pos = init + 4; /* make some space to write later the size */ 987 pos = init + 4; /* make some space to write later the size */
@@ -1024,16 +1024,16 @@ pack_security_parameters (mhd_gtls_session_t session,
1024 session->security_parameters.session_id_size); 1024 session->security_parameters.session_id_size);
1025 pos += session->security_parameters.session_id_size; 1025 pos += session->security_parameters.session_id_size;
1026 1026
1027 mhd_gtls_write_uint32 (session->security_parameters.timestamp, 1027 MHD_gtls_write_uint32 (session->security_parameters.timestamp,
1028 &packed_session->data[pos]); 1028 &packed_session->data[pos]);
1029 pos += 4; 1029 pos += 4;
1030 1030
1031 /* Extensions */ 1031 /* Extensions */
1032 mhd_gtls_write_uint16 (session->security_parameters.max_record_send_size, 1032 MHD_gtls_write_uint16 (session->security_parameters.max_record_send_size,
1033 &packed_session->data[pos]); 1033 &packed_session->data[pos]);
1034 pos += 2; 1034 pos += 2;
1035 1035
1036 mhd_gtls_write_uint16 (session->security_parameters.max_record_recv_size, 1036 MHD_gtls_write_uint16 (session->security_parameters.max_record_recv_size,
1037 &packed_session->data[pos]); 1037 &packed_session->data[pos]);
1038 pos += 2; 1038 pos += 2;
1039 1039
@@ -1045,7 +1045,7 @@ pack_security_parameters (mhd_gtls_session_t session,
1045 session->security_parameters.extensions.srp_username, len); 1045 session->security_parameters.extensions.srp_username, len);
1046 pos += len; 1046 pos += len;
1047 1047
1048 mhd_gtls_write_uint16 (session->security_parameters.extensions. 1048 MHD_gtls_write_uint16 (session->security_parameters.extensions.
1049 server_names_size, &packed_session->data[pos]); 1049 server_names_size, &packed_session->data[pos]);
1050 pos += 2; 1050 pos += 2;
1051 1051
@@ -1054,7 +1054,7 @@ pack_security_parameters (mhd_gtls_session_t session,
1054 { 1054 {
1055 packed_session->data[pos++] = 1055 packed_session->data[pos++] =
1056 session->security_parameters.extensions.server_names[i].type; 1056 session->security_parameters.extensions.server_names[i].type;
1057 mhd_gtls_write_uint16 (session->security_parameters.extensions. 1057 MHD_gtls_write_uint16 (session->security_parameters.extensions.
1058 server_names[i].name_length, 1058 server_names[i].name_length,
1059 &packed_session->data[pos]); 1059 &packed_session->data[pos]);
1060 pos += 2; 1060 pos += 2;
@@ -1068,7 +1068,7 @@ pack_security_parameters (mhd_gtls_session_t session,
1068 } 1068 }
1069 1069
1070 /* write the total size */ 1070 /* write the total size */
1071 mhd_gtls_write_uint32 (pos - init - 4, &packed_session->data[init]); 1071 MHD_gtls_write_uint32 (pos - init - 4, &packed_session->data[init]);
1072 packed_session->size += pos - init; 1072 packed_session->size += pos - init;
1073 1073
1074 return 0; 1074 return 0;
@@ -1076,8 +1076,8 @@ pack_security_parameters (mhd_gtls_session_t session,
1076 1076
1077 1077
1078static int 1078static int
1079unpack_security_parameters (mhd_gtls_session_t session, 1079unpack_security_parameters (MHD_gtls_session_t session,
1080 const gnutls_datum_t * packed_session) 1080 const MHD_gnutls_datum_t * packed_session)
1081{ 1081{
1082 size_t pack_size, init, i; 1082 size_t pack_size, init, i;
1083 int pos = 0, len; 1083 int pos = 0, len;
@@ -1086,12 +1086,12 @@ unpack_security_parameters (mhd_gtls_session_t session,
1086 1086
1087 /* skip the auth info stuff */ 1087 /* skip the auth info stuff */
1088 init = 1088 init =
1089 mhd_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]) + 4 + 1089 MHD_gtls_read_uint32 (&packed_session->data[PACK_HEADER_SIZE]) + 4 +
1090 PACK_HEADER_SIZE; 1090 PACK_HEADER_SIZE;
1091 1091
1092 pos = init; 1092 pos = init;
1093 1093
1094 pack_size = mhd_gtls_read_uint32 (&packed_session->data[pos]); 1094 pack_size = MHD_gtls_read_uint32 (&packed_session->data[pos]);
1095 pos += 4; 1095 pos += 4;
1096 1096
1097 1097
@@ -1101,7 +1101,7 @@ unpack_security_parameters (mhd_gtls_session_t session,
1101 /* a simple check for integrity */ 1101 /* a simple check for integrity */
1102 if (pack_size > MAX_SEC_PARAMS) 1102 if (pack_size > MAX_SEC_PARAMS)
1103 { 1103 {
1104 gnutls_assert (); 1104 MHD_gnutls_assert ();
1105 return GNUTLS_E_INVALID_REQUEST; 1105 return GNUTLS_E_INVALID_REQUEST;
1106 } 1106 }
1107 1107
@@ -1150,24 +1150,24 @@ unpack_security_parameters (mhd_gtls_session_t session,
1150 pos += session->internals.resumed_security_parameters.session_id_size; 1150 pos += session->internals.resumed_security_parameters.session_id_size;
1151 1151
1152 session->internals.resumed_security_parameters.timestamp = 1152 session->internals.resumed_security_parameters.timestamp =
1153 mhd_gtls_read_uint32 (&packed_session->data[pos]); 1153 MHD_gtls_read_uint32 (&packed_session->data[pos]);
1154 pos += 4; 1154 pos += 4;
1155 1155
1156 if (timestamp - session->internals.resumed_security_parameters.timestamp > 1156 if (timestamp - session->internals.resumed_security_parameters.timestamp >
1157 session->internals.expire_time 1157 session->internals.expire_time
1158 || session->internals.resumed_security_parameters.timestamp > timestamp) 1158 || session->internals.resumed_security_parameters.timestamp > timestamp)
1159 { 1159 {
1160 gnutls_assert (); 1160 MHD_gnutls_assert ();
1161 return GNUTLS_E_EXPIRED; 1161 return GNUTLS_E_EXPIRED;
1162 } 1162 }
1163 1163
1164 /* Extensions */ 1164 /* Extensions */
1165 session->internals.resumed_security_parameters.max_record_send_size = 1165 session->internals.resumed_security_parameters.max_record_send_size =
1166 mhd_gtls_read_uint16 (&packed_session->data[pos]); 1166 MHD_gtls_read_uint16 (&packed_session->data[pos]);
1167 pos += 2; 1167 pos += 2;
1168 1168
1169 session->internals.resumed_security_parameters.max_record_recv_size = 1169 session->internals.resumed_security_parameters.max_record_recv_size =
1170 mhd_gtls_read_uint16 (&packed_session->data[pos]); 1170 MHD_gtls_read_uint16 (&packed_session->data[pos]);
1171 pos += 2; 1171 pos += 2;
1172 1172
1173 1173
@@ -1180,7 +1180,7 @@ unpack_security_parameters (mhd_gtls_session_t session,
1180 pos += len; 1180 pos += len;
1181 1181
1182 session->internals.resumed_security_parameters.extensions. 1182 session->internals.resumed_security_parameters.extensions.
1183 server_names_size = mhd_gtls_read_uint16 (&packed_session->data[pos]); 1183 server_names_size = MHD_gtls_read_uint16 (&packed_session->data[pos]);
1184 pos += 2; 1184 pos += 2;
1185 for (i = 0; 1185 for (i = 0;
1186 i < 1186 i <
@@ -1191,7 +1191,7 @@ unpack_security_parameters (mhd_gtls_session_t session,
1191 server_names[i].type = packed_session->data[pos++]; 1191 server_names[i].type = packed_session->data[pos++];
1192 session->internals.resumed_security_parameters.extensions. 1192 session->internals.resumed_security_parameters.extensions.
1193 server_names[i].name_length = 1193 server_names[i].name_length =
1194 mhd_gtls_read_uint16 (&packed_session->data[pos]); 1194 MHD_gtls_read_uint16 (&packed_session->data[pos]);
1195 pos += 2; 1195 pos += 2;
1196 1196
1197 memcpy (session->internals.resumed_security_parameters.extensions. 1197 memcpy (session->internals.resumed_security_parameters.extensions.
diff --git a/src/daemon/https/tls/gnutls_session_pack.h b/src/daemon/https/tls/gnutls_session_pack.h
index e93d9d28..e327f71f 100644
--- a/src/daemon/https/tls/gnutls_session_pack.h
+++ b/src/daemon/https/tls/gnutls_session_pack.h
@@ -22,7 +22,7 @@
22 * 22 *
23 */ 23 */
24 24
25int mhd_gtls_session_pack (mhd_gtls_session_t session, 25int MHD_gtls_session_pack (MHD_gtls_session_t session,
26 gnutls_datum_t * packed_session); 26 MHD_gnutls_datum_t * packed_session);
27int mhd_gtls_session_unpack (mhd_gtls_session_t session, 27int MHD_gtls_session_unpack (MHD_gtls_session_t session,
28 const gnutls_datum_t * packed_session); 28 const MHD_gnutls_datum_t * packed_session);
diff --git a/src/daemon/https/tls/gnutls_sig.c b/src/daemon/https/tls/gnutls_sig.c
index 3a41999d..0309e588 100644
--- a/src/daemon/https/tls/gnutls_sig.c
+++ b/src/daemon/https/tls/gnutls_sig.c
@@ -37,79 +37,79 @@
37#include <gnutls_sig.h> 37#include <gnutls_sig.h>
38#include <gnutls_kx.h> 38#include <gnutls_kx.h>
39 39
40static int _gnutls_tls_sign (mhd_gtls_session_t session, 40static int MHD__gnutls_tls_sign (MHD_gtls_session_t session,
41 gnutls_cert * cert, 41 MHD_gnutls_cert * cert,
42 gnutls_privkey * pkey, 42 MHD_gnutls_privkey * pkey,
43 const gnutls_datum_t * hash_concat, 43 const MHD_gnutls_datum_t * hash_concat,
44 gnutls_datum_t * signature); 44 MHD_gnutls_datum_t * signature);
45 45
46/* Generates a signature of all the previous sent packets in the 46/* Generates a signature of all the previous sent packets in the
47 * handshake procedure. (20040227: now it works for SSL 3.0 as well) 47 * handshake procedure. (20040227: now it works for SSL 3.0 as well)
48 */ 48 */
49int 49int
50mhd_gtls_tls_sign_hdata (mhd_gtls_session_t session, 50MHD_gtls_tls_sign_hdata (MHD_gtls_session_t session,
51 gnutls_cert * cert, 51 MHD_gnutls_cert * cert,
52 gnutls_privkey * pkey, gnutls_datum_t * signature) 52 MHD_gnutls_privkey * pkey, MHD_gnutls_datum_t * signature)
53{ 53{
54 gnutls_datum_t dconcat; 54 MHD_gnutls_datum_t dconcat;
55 int ret; 55 int ret;
56 opaque concat[36]; 56 opaque concat[36];
57 mac_hd_t td_md5; 57 mac_hd_t td_md5;
58 mac_hd_t td_sha; 58 mac_hd_t td_sha;
59 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 59 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
60 60
61 td_sha = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_sha); 61 td_sha = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_sha);
62 if (td_sha == NULL) 62 if (td_sha == NULL)
63 { 63 {
64 gnutls_assert (); 64 MHD_gnutls_assert ();
65 return GNUTLS_E_HASH_FAILED; 65 return GNUTLS_E_HASH_FAILED;
66 } 66 }
67 67
68 if (ver == MHD_GNUTLS_PROTOCOL_SSL3) 68 if (ver == MHD_GNUTLS_PROTOCOL_SSL3)
69 { 69 {
70 ret = mhd_gtls_generate_master (session, 1); 70 ret = MHD_gtls_generate_master (session, 1);
71 if (ret < 0) 71 if (ret < 0)
72 { 72 {
73 gnutls_assert (); 73 MHD_gnutls_assert ();
74 return ret; 74 return ret;
75 } 75 }
76 76
77 mhd_gnutls_mac_deinit_ssl3_handshake (td_sha, &concat[16], 77 MHD_gnutls_mac_deinit_ssl3_handshake (td_sha, &concat[16],
78 session->security_parameters. 78 session->security_parameters.
79 master_secret, TLS_MASTER_SIZE); 79 master_secret, TLS_MASTER_SIZE);
80 } 80 }
81 else 81 else
82 mhd_gnutls_hash_deinit (td_sha, &concat[16]); 82 MHD_gnutls_hash_deinit (td_sha, &concat[16]);
83 83
84 switch (cert->subject_pk_algorithm) 84 switch (cert->subject_pk_algorithm)
85 { 85 {
86 case MHD_GNUTLS_PK_RSA: 86 case MHD_GNUTLS_PK_RSA:
87 td_md5 = 87 td_md5 =
88 mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_md5); 88 MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_md5);
89 if (td_md5 == NULL) 89 if (td_md5 == NULL)
90 { 90 {
91 gnutls_assert (); 91 MHD_gnutls_assert ();
92 return GNUTLS_E_HASH_FAILED; 92 return GNUTLS_E_HASH_FAILED;
93 } 93 }
94 94
95 if (ver == MHD_GNUTLS_PROTOCOL_SSL3) 95 if (ver == MHD_GNUTLS_PROTOCOL_SSL3)
96 mhd_gnutls_mac_deinit_ssl3_handshake (td_md5, concat, 96 MHD_gnutls_mac_deinit_ssl3_handshake (td_md5, concat,
97 session->security_parameters. 97 session->security_parameters.
98 master_secret, TLS_MASTER_SIZE); 98 master_secret, TLS_MASTER_SIZE);
99 else 99 else
100 mhd_gnutls_hash_deinit (td_md5, concat); 100 MHD_gnutls_hash_deinit (td_md5, concat);
101 101
102 dconcat.data = concat; 102 dconcat.data = concat;
103 dconcat.size = 36; 103 dconcat.size = 36;
104 break; 104 break;
105 default: 105 default:
106 gnutls_assert (); 106 MHD_gnutls_assert ();
107 return GNUTLS_E_INTERNAL_ERROR; 107 return GNUTLS_E_INTERNAL_ERROR;
108 } 108 }
109 ret = _gnutls_tls_sign (session, cert, pkey, &dconcat, signature); 109 ret = MHD__gnutls_tls_sign (session, cert, pkey, &dconcat, signature);
110 if (ret < 0) 110 if (ret < 0)
111 { 111 {
112 gnutls_assert (); 112 MHD_gnutls_assert ();
113 } 113 }
114 114
115 return ret; 115 return ret;
@@ -119,50 +119,50 @@ mhd_gtls_tls_sign_hdata (mhd_gtls_session_t session,
119 * Used in DHE_* ciphersuites. 119 * Used in DHE_* ciphersuites.
120 */ 120 */
121int 121int
122mhd_gtls_tls_sign_params (mhd_gtls_session_t session, 122MHD_gtls_tls_sign_params (MHD_gtls_session_t session,
123 gnutls_cert * cert, 123 MHD_gnutls_cert * cert,
124 gnutls_privkey * pkey, 124 MHD_gnutls_privkey * pkey,
125 gnutls_datum_t * params, gnutls_datum_t * signature) 125 MHD_gnutls_datum_t * params, MHD_gnutls_datum_t * signature)
126{ 126{
127 gnutls_datum_t dconcat; 127 MHD_gnutls_datum_t dconcat;
128 int ret; 128 int ret;
129 mac_hd_t td_sha; 129 mac_hd_t td_sha;
130 opaque concat[36]; 130 opaque concat[36];
131 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 131 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
132 132
133 td_sha = mhd_gtls_hash_init (MHD_GNUTLS_MAC_SHA1); 133 td_sha = MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
134 if (td_sha == NULL) 134 if (td_sha == NULL)
135 { 135 {
136 gnutls_assert (); 136 MHD_gnutls_assert ();
137 return GNUTLS_E_HASH_FAILED; 137 return GNUTLS_E_HASH_FAILED;
138 } 138 }
139 139
140 mhd_gnutls_hash (td_sha, session->security_parameters.client_random, 140 MHD_gnutls_hash (td_sha, session->security_parameters.client_random,
141 TLS_RANDOM_SIZE); 141 TLS_RANDOM_SIZE);
142 mhd_gnutls_hash (td_sha, session->security_parameters.server_random, 142 MHD_gnutls_hash (td_sha, session->security_parameters.server_random,
143 TLS_RANDOM_SIZE); 143 TLS_RANDOM_SIZE);
144 mhd_gnutls_hash (td_sha, params->data, params->size); 144 MHD_gnutls_hash (td_sha, params->data, params->size);
145 145
146 switch (cert->subject_pk_algorithm) 146 switch (cert->subject_pk_algorithm)
147 { 147 {
148 case MHD_GNUTLS_PK_RSA: 148 case MHD_GNUTLS_PK_RSA:
149 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2) 149 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2)
150 { 150 {
151 mac_hd_t td_md5 = mhd_gtls_hash_init (MHD_GNUTLS_MAC_MD5); 151 mac_hd_t td_md5 = MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
152 if (td_md5 == NULL) 152 if (td_md5 == NULL)
153 { 153 {
154 gnutls_assert (); 154 MHD_gnutls_assert ();
155 return GNUTLS_E_HASH_FAILED; 155 return GNUTLS_E_HASH_FAILED;
156 } 156 }
157 157
158 mhd_gnutls_hash (td_md5, session->security_parameters.client_random, 158 MHD_gnutls_hash (td_md5, session->security_parameters.client_random,
159 TLS_RANDOM_SIZE); 159 TLS_RANDOM_SIZE);
160 mhd_gnutls_hash (td_md5, session->security_parameters.server_random, 160 MHD_gnutls_hash (td_md5, session->security_parameters.server_random,
161 TLS_RANDOM_SIZE); 161 TLS_RANDOM_SIZE);
162 mhd_gnutls_hash (td_md5, params->data, params->size); 162 MHD_gnutls_hash (td_md5, params->data, params->size);
163 163
164 mhd_gnutls_hash_deinit (td_md5, concat); 164 MHD_gnutls_hash_deinit (td_md5, concat);
165 mhd_gnutls_hash_deinit (td_sha, &concat[16]); 165 MHD_gnutls_hash_deinit (td_sha, &concat[16]);
166 166
167 dconcat.size = 36; 167 dconcat.size = 36;
168 } 168 }
@@ -173,27 +173,27 @@ mhd_gtls_tls_sign_params (mhd_gtls_session_t session,
173 memcpy (concat, 173 memcpy (concat,
174 "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14", 174 "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14",
175 15); 175 15);
176 mhd_gnutls_hash_deinit (td_sha, &concat[15]); 176 MHD_gnutls_hash_deinit (td_sha, &concat[15]);
177 dconcat.size = 35; 177 dconcat.size = 35;
178#else 178#else
179 /* No parameters field. */ 179 /* No parameters field. */
180 memcpy (concat, 180 memcpy (concat,
181 "\x30\x1f\x30\x07\x06\x05\x2b\x0e\x03\x02\x1a\x04\x14", 13); 181 "\x30\x1f\x30\x07\x06\x05\x2b\x0e\x03\x02\x1a\x04\x14", 13);
182 mhd_gnutls_hash_deinit (td_sha, &concat[13]); 182 MHD_gnutls_hash_deinit (td_sha, &concat[13]);
183 dconcat.size = 33; 183 dconcat.size = 33;
184#endif 184#endif
185 } 185 }
186 dconcat.data = concat; 186 dconcat.data = concat;
187 break; 187 break;
188 default: 188 default:
189 gnutls_assert (); 189 MHD_gnutls_assert ();
190 mhd_gnutls_hash_deinit (td_sha, NULL); 190 MHD_gnutls_hash_deinit (td_sha, NULL);
191 return GNUTLS_E_INTERNAL_ERROR; 191 return GNUTLS_E_INTERNAL_ERROR;
192 } 192 }
193 ret = _gnutls_tls_sign (session, cert, pkey, &dconcat, signature); 193 ret = MHD__gnutls_tls_sign (session, cert, pkey, &dconcat, signature);
194 if (ret < 0) 194 if (ret < 0)
195 { 195 {
196 gnutls_assert (); 196 MHD_gnutls_assert ();
197 } 197 }
198 198
199 return ret; 199 return ret;
@@ -204,10 +204,10 @@ mhd_gtls_tls_sign_params (mhd_gtls_session_t session,
204 * given data. The output will be allocated and be put in signature. 204 * given data. The output will be allocated and be put in signature.
205 */ 205 */
206int 206int
207mhd_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo, 207MHD_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo,
208 mpi_t * params, 208 mpi_t * params,
209 int params_size, 209 int params_size,
210 const gnutls_datum_t * data, gnutls_datum_t * signature) 210 const MHD_gnutls_datum_t * data, MHD_gnutls_datum_t * signature)
211{ 211{
212 int ret; 212 int ret;
213 213
@@ -216,16 +216,16 @@ mhd_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo,
216 case MHD_GNUTLS_PK_RSA: 216 case MHD_GNUTLS_PK_RSA:
217 /* encrypt */ 217 /* encrypt */
218 if ((ret = 218 if ((ret =
219 mhd_gtls_pkcs1_rsa_encrypt (signature, data, params, params_size, 219 MHD_gtls_pkcs1_rsa_encrypt (signature, data, params, params_size,
220 1)) < 0) 220 1)) < 0)
221 { 221 {
222 gnutls_assert (); 222 MHD_gnutls_assert ();
223 return ret; 223 return ret;
224 } 224 }
225 225
226 break; 226 break;
227 default: 227 default:
228 gnutls_assert (); 228 MHD_gnutls_assert ();
229 return GNUTLS_E_INTERNAL_ERROR; 229 return GNUTLS_E_INTERNAL_ERROR;
230 break; 230 break;
231 } 231 }
@@ -238,11 +238,11 @@ mhd_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo,
238 * it supports signing. 238 * it supports signing.
239 */ 239 */
240static int 240static int
241_gnutls_tls_sign (mhd_gtls_session_t session, 241MHD__gnutls_tls_sign (MHD_gtls_session_t session,
242 gnutls_cert * cert, 242 MHD_gnutls_cert * cert,
243 gnutls_privkey * pkey, 243 MHD_gnutls_privkey * pkey,
244 const gnutls_datum_t * hash_concat, 244 const MHD_gnutls_datum_t * hash_concat,
245 gnutls_datum_t * signature) 245 MHD_gnutls_datum_t * signature)
246{ 246{
247 247
248 /* If our certificate supports signing 248 /* If our certificate supports signing
@@ -252,7 +252,7 @@ _gnutls_tls_sign (mhd_gtls_session_t session,
252 if (cert->key_usage != 0) 252 if (cert->key_usage != 0)
253 if (!(cert->key_usage & KEY_DIGITAL_SIGNATURE)) 253 if (!(cert->key_usage & KEY_DIGITAL_SIGNATURE))
254 { 254 {
255 gnutls_assert (); 255 MHD_gnutls_assert ();
256 return GNUTLS_E_KEY_USAGE_VIOLATION; 256 return GNUTLS_E_KEY_USAGE_VIOLATION;
257 } 257 }
258 258
@@ -269,23 +269,23 @@ _gnutls_tls_sign (mhd_gtls_session_t session,
269 hash_concat, signature); 269 hash_concat, signature);
270 } 270 }
271 271
272 return mhd_gtls_sign (pkey->pk_algorithm, pkey->params, pkey->params_size, 272 return MHD_gtls_sign (pkey->pk_algorithm, pkey->params, pkey->params_size,
273 hash_concat, signature); 273 hash_concat, signature);
274} 274}
275 275
276static int 276static int
277_gnutls_verify_sig (gnutls_cert * cert, 277MHD__gnutls_verify_sig (MHD_gnutls_cert * cert,
278 const gnutls_datum_t * hash_concat, 278 const MHD_gnutls_datum_t * hash_concat,
279 gnutls_datum_t * signature, size_t sha1pos) 279 MHD_gnutls_datum_t * signature, size_t sha1pos)
280{ 280{
281 int ret; 281 int ret;
282 gnutls_datum_t vdata; 282 MHD_gnutls_datum_t vdata;
283 283
284 if ( (cert == NULL) || (cert->version == 0) ) 284 if ( (cert == NULL) || (cert->version == 0) )
285 { /* this is the only way to check 285 { /* this is the only way to check
286 * if it is initialized 286 * if it is initialized
287 */ 287 */
288 gnutls_assert (); 288 MHD_gnutls_assert ();
289 return GNUTLS_E_CERTIFICATE_ERROR; 289 return GNUTLS_E_CERTIFICATE_ERROR;
290 } 290 }
291 291
@@ -295,7 +295,7 @@ _gnutls_verify_sig (gnutls_cert * cert,
295 if (cert->key_usage != 0) 295 if (cert->key_usage != 0)
296 if (!(cert->key_usage & KEY_DIGITAL_SIGNATURE)) 296 if (!(cert->key_usage & KEY_DIGITAL_SIGNATURE))
297 { 297 {
298 gnutls_assert (); 298 MHD_gnutls_assert ();
299 return GNUTLS_E_KEY_USAGE_VIOLATION; 299 return GNUTLS_E_KEY_USAGE_VIOLATION;
300 } 300 }
301 301
@@ -307,16 +307,16 @@ _gnutls_verify_sig (gnutls_cert * cert,
307 vdata.size = hash_concat->size; 307 vdata.size = hash_concat->size;
308 308
309 /* verify signature */ 309 /* verify signature */
310 if ((ret = mhd_gtls_rsa_verify (&vdata, signature, cert->params, 310 if ((ret = MHD_gtls_rsa_verify (&vdata, signature, cert->params,
311 cert->params_size, 1)) < 0) 311 cert->params_size, 1)) < 0)
312 { 312 {
313 gnutls_assert (); 313 MHD_gnutls_assert ();
314 return ret; 314 return ret;
315 } 315 }
316 316
317 break; 317 break;
318 default: 318 default:
319 gnutls_assert (); 319 MHD_gnutls_assert ();
320 return GNUTLS_E_INTERNAL_ERROR; 320 return GNUTLS_E_INTERNAL_ERROR;
321 } 321 }
322 322
@@ -327,60 +327,60 @@ _gnutls_verify_sig (gnutls_cert * cert,
327 * verify message). 327 * verify message).
328 */ 328 */
329int 329int
330mhd_gtls_verify_sig_hdata (mhd_gtls_session_t session, 330MHD_gtls_verify_sig_hdata (MHD_gtls_session_t session,
331 gnutls_cert * cert, gnutls_datum_t * signature) 331 MHD_gnutls_cert * cert, MHD_gnutls_datum_t * signature)
332{ 332{
333 int ret; 333 int ret;
334 opaque concat[36]; 334 opaque concat[36];
335 mac_hd_t td_md5; 335 mac_hd_t td_md5;
336 mac_hd_t td_sha; 336 mac_hd_t td_sha;
337 gnutls_datum_t dconcat; 337 MHD_gnutls_datum_t dconcat;
338 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 338 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
339 339
340 td_md5 = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_md5); 340 td_md5 = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_md5);
341 if (td_md5 == NULL) 341 if (td_md5 == NULL)
342 { 342 {
343 gnutls_assert (); 343 MHD_gnutls_assert ();
344 return GNUTLS_E_HASH_FAILED; 344 return GNUTLS_E_HASH_FAILED;
345 } 345 }
346 346
347 td_sha = mhd_gnutls_hash_copy (session->internals.handshake_mac_handle_sha); 347 td_sha = MHD_gnutls_hash_copy (session->internals.handshake_mac_handle_sha);
348 if (td_sha == NULL) 348 if (td_sha == NULL)
349 { 349 {
350 gnutls_assert (); 350 MHD_gnutls_assert ();
351 mhd_gnutls_hash_deinit (td_md5, NULL); 351 MHD_gnutls_hash_deinit (td_md5, NULL);
352 return GNUTLS_E_HASH_FAILED; 352 return GNUTLS_E_HASH_FAILED;
353 } 353 }
354 354
355 if (ver == MHD_GNUTLS_PROTOCOL_SSL3) 355 if (ver == MHD_GNUTLS_PROTOCOL_SSL3)
356 { 356 {
357 ret = mhd_gtls_generate_master (session, 1); 357 ret = MHD_gtls_generate_master (session, 1);
358 if (ret < 0) 358 if (ret < 0)
359 { 359 {
360 gnutls_assert (); 360 MHD_gnutls_assert ();
361 return ret; 361 return ret;
362 } 362 }
363 363
364 mhd_gnutls_mac_deinit_ssl3_handshake (td_md5, concat, 364 MHD_gnutls_mac_deinit_ssl3_handshake (td_md5, concat,
365 session->security_parameters. 365 session->security_parameters.
366 master_secret, TLS_MASTER_SIZE); 366 master_secret, TLS_MASTER_SIZE);
367 mhd_gnutls_mac_deinit_ssl3_handshake (td_sha, &concat[16], 367 MHD_gnutls_mac_deinit_ssl3_handshake (td_sha, &concat[16],
368 session->security_parameters. 368 session->security_parameters.
369 master_secret, TLS_MASTER_SIZE); 369 master_secret, TLS_MASTER_SIZE);
370 } 370 }
371 else 371 else
372 { 372 {
373 mhd_gnutls_hash_deinit (td_md5, concat); 373 MHD_gnutls_hash_deinit (td_md5, concat);
374 mhd_gnutls_hash_deinit (td_sha, &concat[16]); 374 MHD_gnutls_hash_deinit (td_sha, &concat[16]);
375 } 375 }
376 376
377 dconcat.data = concat; 377 dconcat.data = concat;
378 dconcat.size = 20 + 16; /* md5+ sha */ 378 dconcat.size = 20 + 16; /* md5+ sha */
379 379
380 ret = _gnutls_verify_sig (cert, &dconcat, signature, 16); 380 ret = MHD__gnutls_verify_sig (cert, &dconcat, signature, 16);
381 if (ret < 0) 381 if (ret < 0)
382 { 382 {
383 gnutls_assert (); 383 MHD_gnutls_assert ();
384 return ret; 384 return ret;
385 } 385 }
386 386
@@ -392,53 +392,53 @@ mhd_gtls_verify_sig_hdata (mhd_gtls_session_t session,
392 * Used in DHE_* ciphersuites. 392 * Used in DHE_* ciphersuites.
393 */ 393 */
394int 394int
395mhd_gtls_verify_sig_params (mhd_gtls_session_t session, 395MHD_gtls_verify_sig_params (MHD_gtls_session_t session,
396 gnutls_cert * cert, 396 MHD_gnutls_cert * cert,
397 const gnutls_datum_t * params, 397 const MHD_gnutls_datum_t * params,
398 gnutls_datum_t * signature) 398 MHD_gnutls_datum_t * signature)
399{ 399{
400 gnutls_datum_t dconcat; 400 MHD_gnutls_datum_t dconcat;
401 int ret; 401 int ret;
402 mac_hd_t td_md5 = NULL; 402 mac_hd_t td_md5 = NULL;
403 mac_hd_t td_sha; 403 mac_hd_t td_sha;
404 opaque concat[36]; 404 opaque concat[36];
405 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 405 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
406 406
407 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2) 407 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2)
408 { 408 {
409 td_md5 = mhd_gtls_hash_init (MHD_GNUTLS_MAC_MD5); 409 td_md5 = MHD_gtls_hash_init (MHD_GNUTLS_MAC_MD5);
410 if (td_md5 == NULL) 410 if (td_md5 == NULL)
411 { 411 {
412 gnutls_assert (); 412 MHD_gnutls_assert ();
413 return GNUTLS_E_HASH_FAILED; 413 return GNUTLS_E_HASH_FAILED;
414 } 414 }
415 415
416 mhd_gnutls_hash (td_md5, session->security_parameters.client_random, 416 MHD_gnutls_hash (td_md5, session->security_parameters.client_random,
417 TLS_RANDOM_SIZE); 417 TLS_RANDOM_SIZE);
418 mhd_gnutls_hash (td_md5, session->security_parameters.server_random, 418 MHD_gnutls_hash (td_md5, session->security_parameters.server_random,
419 TLS_RANDOM_SIZE); 419 TLS_RANDOM_SIZE);
420 mhd_gnutls_hash (td_md5, params->data, params->size); 420 MHD_gnutls_hash (td_md5, params->data, params->size);
421 } 421 }
422 422
423 td_sha = mhd_gtls_hash_init (MHD_GNUTLS_MAC_SHA1); 423 td_sha = MHD_gtls_hash_init (MHD_GNUTLS_MAC_SHA1);
424 if (td_sha == NULL) 424 if (td_sha == NULL)
425 { 425 {
426 gnutls_assert (); 426 MHD_gnutls_assert ();
427 if (td_md5) 427 if (td_md5)
428 mhd_gnutls_hash_deinit (td_md5, NULL); 428 MHD_gnutls_hash_deinit (td_md5, NULL);
429 return GNUTLS_E_HASH_FAILED; 429 return GNUTLS_E_HASH_FAILED;
430 } 430 }
431 431
432 mhd_gnutls_hash (td_sha, session->security_parameters.client_random, 432 MHD_gnutls_hash (td_sha, session->security_parameters.client_random,
433 TLS_RANDOM_SIZE); 433 TLS_RANDOM_SIZE);
434 mhd_gnutls_hash (td_sha, session->security_parameters.server_random, 434 MHD_gnutls_hash (td_sha, session->security_parameters.server_random,
435 TLS_RANDOM_SIZE); 435 TLS_RANDOM_SIZE);
436 mhd_gnutls_hash (td_sha, params->data, params->size); 436 MHD_gnutls_hash (td_sha, params->data, params->size);
437 437
438 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2) 438 if (ver < MHD_GNUTLS_PROTOCOL_TLS1_2)
439 { 439 {
440 mhd_gnutls_hash_deinit (td_md5, concat); 440 MHD_gnutls_hash_deinit (td_md5, concat);
441 mhd_gnutls_hash_deinit (td_sha, &concat[16]); 441 MHD_gnutls_hash_deinit (td_sha, &concat[16]);
442 dconcat.size = 36; 442 dconcat.size = 36;
443 } 443 }
444 else 444 else
@@ -448,23 +448,23 @@ mhd_gtls_verify_sig_params (mhd_gtls_session_t session,
448 memcpy (concat, 448 memcpy (concat,
449 "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14", 449 "\x30\x21\x30\x09\x06\x05\x2b\x0e\x03\x02\x1a\x05\x00\x04\x14",
450 15); 450 15);
451 mhd_gnutls_hash_deinit (td_sha, &concat[15]); 451 MHD_gnutls_hash_deinit (td_sha, &concat[15]);
452 dconcat.size = 35; 452 dconcat.size = 35;
453#else 453#else
454 /* No parameters field. */ 454 /* No parameters field. */
455 memcpy (concat, 455 memcpy (concat,
456 "\x30\x1f\x30\x07\x06\x05\x2b\x0e\x03\x02\x1a\x04\x14", 13); 456 "\x30\x1f\x30\x07\x06\x05\x2b\x0e\x03\x02\x1a\x04\x14", 13);
457 mhd_gnutls_hash_deinit (td_sha, &concat[13]); 457 MHD_gnutls_hash_deinit (td_sha, &concat[13]);
458 dconcat.size = 33; 458 dconcat.size = 33;
459#endif 459#endif
460 } 460 }
461 461
462 dconcat.data = concat; 462 dconcat.data = concat;
463 463
464 ret = _gnutls_verify_sig (cert, &dconcat, signature, dconcat.size - 20); 464 ret = MHD__gnutls_verify_sig (cert, &dconcat, signature, dconcat.size - 20);
465 if (ret < 0) 465 if (ret < 0)
466 { 466 {
467 gnutls_assert (); 467 MHD_gnutls_assert ();
468 return ret; 468 return ret;
469 } 469 }
470 470
diff --git a/src/daemon/https/tls/gnutls_sig.h b/src/daemon/https/tls/gnutls_sig.h
index eaef5226..6259191d 100644
--- a/src/daemon/https/tls/gnutls_sig.h
+++ b/src/daemon/https/tls/gnutls_sig.h
@@ -25,28 +25,28 @@
25#ifndef GNUTLS_SIG_H 25#ifndef GNUTLS_SIG_H
26# define GNUTLS_SIG_H 26# define GNUTLS_SIG_H
27 27
28int mhd_gtls_tls_sign_hdata (mhd_gtls_session_t session, 28int MHD_gtls_tls_sign_hdata (MHD_gtls_session_t session,
29 gnutls_cert * cert, 29 MHD_gnutls_cert * cert,
30 gnutls_privkey * pkey, 30 MHD_gnutls_privkey * pkey,
31 gnutls_datum_t * signature); 31 MHD_gnutls_datum_t * signature);
32 32
33int mhd_gtls_tls_sign_params (mhd_gtls_session_t session, 33int MHD_gtls_tls_sign_params (MHD_gtls_session_t session,
34 gnutls_cert * cert, 34 MHD_gnutls_cert * cert,
35 gnutls_privkey * pkey, 35 MHD_gnutls_privkey * pkey,
36 gnutls_datum_t * params, 36 MHD_gnutls_datum_t * params,
37 gnutls_datum_t * signature); 37 MHD_gnutls_datum_t * signature);
38 38
39int mhd_gtls_verify_sig_hdata (mhd_gtls_session_t session, 39int MHD_gtls_verify_sig_hdata (MHD_gtls_session_t session,
40 gnutls_cert * cert, 40 MHD_gnutls_cert * cert,
41 gnutls_datum_t * signature); 41 MHD_gnutls_datum_t * signature);
42 42
43int mhd_gtls_verify_sig_params (mhd_gtls_session_t session, 43int MHD_gtls_verify_sig_params (MHD_gtls_session_t session,
44 gnutls_cert * cert, 44 MHD_gnutls_cert * cert,
45 const gnutls_datum_t * params, 45 const MHD_gnutls_datum_t * params,
46 gnutls_datum_t * signature); 46 MHD_gnutls_datum_t * signature);
47 47
48int mhd_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo, 48int MHD_gtls_sign (enum MHD_GNUTLS_PublicKeyAlgorithm algo,
49 mpi_t * params, int params_size, 49 mpi_t * params, int params_size,
50 const gnutls_datum_t * data, gnutls_datum_t * signature); 50 const MHD_gnutls_datum_t * data, MHD_gnutls_datum_t * signature);
51 51
52#endif 52#endif
diff --git a/src/daemon/https/tls/gnutls_state.c b/src/daemon/https/tls/gnutls_state.c
index ae793ee0..49802b2e 100644
--- a/src/daemon/https/tls/gnutls_state.c
+++ b/src/daemon/https/tls/gnutls_state.c
@@ -22,8 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25/* Functions to manipulate the session (gnutls_int.h), and some other stuff 25/* Functions to manipulate the session (MHD_gnutls_int.h), and some other stuff
26 * are included here. The file's name is traditionally gnutls_state even if the 26 * are included here. The file's name is traditionally MHD_gnutls_state even if the
27 * state has been renamed to session. 27 * state has been renamed to session.
28 */ 28 */
29 29
@@ -43,27 +43,27 @@
43#include <gnutls_rsa_export.h> 43#include <gnutls_rsa_export.h>
44 44
45void 45void
46_gnutls_session_cert_type_set (mhd_gtls_session_t session, 46MHD__gnutls_session_cert_type_set (MHD_gtls_session_t session,
47 enum MHD_GNUTLS_CertificateType ct) 47 enum MHD_GNUTLS_CertificateType ct)
48{ 48{
49 session->security_parameters.cert_type = ct; 49 session->security_parameters.cert_type = ct;
50} 50}
51 51
52/** 52/**
53 * gnutls_cipher_get - Returns the currently used cipher. 53 * MHD_gnutls_cipher_get - Returns the currently used cipher.
54 * @session: is a #mhd_gtls_session_t structure. 54 * @session: is a #MHD_gtls_session_t structure.
55 * 55 *
56 * Returns: the currently used cipher. 56 * Returns: the currently used cipher.
57 **/ 57 **/
58enum MHD_GNUTLS_CipherAlgorithm 58enum MHD_GNUTLS_CipherAlgorithm
59gnutls_cipher_get (mhd_gtls_session_t session) 59MHD_gnutls_cipher_get (MHD_gtls_session_t session)
60{ 60{
61 return session->security_parameters.read_bulk_cipher_algorithm; 61 return session->security_parameters.read_bulk_cipher_algorithm;
62} 62}
63 63
64/** 64/**
65 * gnutls_certificate_type_get - Returns the currently used certificate type. 65 * MHD_gnutls_certificate_type_get - Returns the currently used certificate type.
66 * @session: is a #mhd_gtls_session_t structure. 66 * @session: is a #MHD_gtls_session_t structure.
67 * 67 *
68 * The certificate type is by default X.509, unless it is negotiated 68 * The certificate type is by default X.509, unless it is negotiated
69 * as a TLS extension. 69 * as a TLS extension.
@@ -72,43 +72,43 @@ gnutls_cipher_get (mhd_gtls_session_t session)
72 * type. 72 * type.
73 **/ 73 **/
74enum MHD_GNUTLS_CertificateType 74enum MHD_GNUTLS_CertificateType
75gnutls_certificate_type_get (mhd_gtls_session_t session) 75MHD_gnutls_certificate_type_get (MHD_gtls_session_t session)
76{ 76{
77 return session->security_parameters.cert_type; 77 return session->security_parameters.cert_type;
78} 78}
79 79
80/** 80/**
81 * gnutls_kx_get - Returns the key exchange algorithm. 81 * MHD_gnutls_kx_get - Returns the key exchange algorithm.
82 * @session: is a #mhd_gtls_session_t structure. 82 * @session: is a #MHD_gtls_session_t structure.
83 * 83 *
84 * Returns: the key exchange algorithm used in the last handshake. 84 * Returns: the key exchange algorithm used in the last handshake.
85 **/ 85 **/
86enum MHD_GNUTLS_KeyExchangeAlgorithm 86enum MHD_GNUTLS_KeyExchangeAlgorithm
87gnutls_kx_get (mhd_gtls_session_t session) 87MHD_gnutls_kx_get (MHD_gtls_session_t session)
88{ 88{
89 return session->security_parameters.kx_algorithm; 89 return session->security_parameters.kx_algorithm;
90} 90}
91 91
92/** 92/**
93 * gnutls_mac_get - Returns the currently used mac algorithm. 93 * MHD_gnutls_mac_get - Returns the currently used mac algorithm.
94 * @session: is a #mhd_gtls_session_t structure. 94 * @session: is a #MHD_gtls_session_t structure.
95 * 95 *
96 * Returns: the currently used mac algorithm. 96 * Returns: the currently used mac algorithm.
97 **/ 97 **/
98enum MHD_GNUTLS_HashAlgorithm 98enum MHD_GNUTLS_HashAlgorithm
99gnutls_mac_get (mhd_gtls_session_t session) 99MHD_gnutls_mac_get (MHD_gtls_session_t session)
100{ 100{
101 return session->security_parameters.read_mac_algorithm; 101 return session->security_parameters.read_mac_algorithm;
102} 102}
103 103
104/** 104/**
105 * gnutls_compression_get - Returns the currently used compression algorithm. 105 * MHD_gnutls_compression_get - Returns the currently used compression algorithm.
106 * @session: is a #mhd_gtls_session_t structure. 106 * @session: is a #MHD_gtls_session_t structure.
107 * 107 *
108 * Returns: the currently used compression method. 108 * Returns: the currently used compression method.
109 **/ 109 **/
110enum MHD_GNUTLS_CompressionMethod 110enum MHD_GNUTLS_CompressionMethod
111MHD_gtls_compression_get (mhd_gtls_session_t session) 111MHD_gtls_compression_get (MHD_gtls_session_t session)
112{ 112{
113 return session->security_parameters.read_compression_algorithm; 113 return session->security_parameters.read_compression_algorithm;
114} 114}
@@ -118,18 +118,18 @@ MHD_gtls_compression_get (mhd_gtls_session_t session)
118 * and a matching certificate exists. 118 * and a matching certificate exists.
119 */ 119 */
120int 120int
121mhd_gtls_session_cert_type_supported (mhd_gtls_session_t session, 121MHD_gtls_session_cert_type_supported (MHD_gtls_session_t session,
122 enum MHD_GNUTLS_CertificateType 122 enum MHD_GNUTLS_CertificateType
123 cert_type) 123 cert_type)
124{ 124{
125 unsigned i; 125 unsigned i;
126 unsigned cert_found = 0; 126 unsigned cert_found = 0;
127 mhd_gtls_cert_credentials_t cred; 127 MHD_gtls_cert_credentials_t cred;
128 128
129 if (session->security_parameters.entity == GNUTLS_SERVER) 129 if (session->security_parameters.entity == GNUTLS_SERVER)
130 { 130 {
131 cred 131 cred
132 = (mhd_gtls_cert_credentials_t) mhd_gtls_get_cred (session->key, 132 = (MHD_gtls_cert_credentials_t) MHD_gtls_get_cred (session->key,
133 MHD_GNUTLS_CRD_CERTIFICATE, 133 MHD_GNUTLS_CRD_CERTIFICATE,
134 NULL); 134 NULL);
135 135
@@ -173,13 +173,13 @@ mhd_gtls_session_cert_type_supported (mhd_gtls_session_t session,
173 * in a session struct. 173 * in a session struct.
174 */ 174 */
175inline static void 175inline static void
176deinit_internal_params (mhd_gtls_session_t session) 176deinit_internal_params (MHD_gtls_session_t session)
177{ 177{
178 if (session->internals.params.free_dh_params) 178 if (session->internals.params.free_dh_params)
179 MHD_gnutls_dh_params_deinit (session->internals.params.dh_params); 179 MHD__gnutls_dh_params_deinit (session->internals.params.dh_params);
180 180
181 if (session->internals.params.free_rsa_params) 181 if (session->internals.params.free_rsa_params)
182 MHD_gnutls_rsa_params_deinit (session->internals.params.rsa_params); 182 MHD__gnutls_rsa_params_deinit (session->internals.params.rsa_params);
183 183
184 memset (&session->internals.params, 0, sizeof (session->internals.params)); 184 memset (&session->internals.params, 0, sizeof (session->internals.params));
185} 185}
@@ -189,7 +189,7 @@ deinit_internal_params (mhd_gtls_session_t session)
189 * This is used to allow further handshakes. 189 * This is used to allow further handshakes.
190 */ 190 */
191void 191void
192mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t session) 192MHD_gtls_handshake_internal_state_clear (MHD_gtls_session_t session)
193{ 193{
194 session->internals.extensions_sent_size = 0; 194 session->internals.extensions_sent_size = 0;
195 195
@@ -199,7 +199,7 @@ mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t session)
199 session->internals.adv_version_minor = 0; 199 session->internals.adv_version_minor = 0;
200 session->internals.v2_hello = 0; 200 session->internals.v2_hello = 0;
201 memset (&session->internals.handshake_header_buffer, 0, 201 memset (&session->internals.handshake_header_buffer, 0,
202 sizeof (mhd_gtls_handshake_header_buffer_st)); 202 sizeof (MHD_gtls_handshake_header_buffer_st));
203 session->internals.adv_version_minor = 0; 203 session->internals.adv_version_minor = 0;
204 session->internals.adv_version_minor = 0; 204 session->internals.adv_version_minor = 0;
205 session->internals.direction = 0; 205 session->internals.direction = 0;
@@ -211,7 +211,7 @@ mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t session)
211 session->internals.last_handshake_out = -1; 211 session->internals.last_handshake_out = -1;
212 212
213 session->internals.resumable = RESUME_TRUE; 213 session->internals.resumable = RESUME_TRUE;
214 _gnutls_free_datum (&session->internals.recv_buffer); 214 MHD__gnutls_free_datum (&session->internals.recv_buffer);
215 215
216 deinit_internal_params (session); 216 deinit_internal_params (session);
217 217
@@ -219,14 +219,14 @@ mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t session)
219 219
220#define MIN_DH_BITS 727 220#define MIN_DH_BITS 727
221/** 221/**
222 * MHD_gnutls_init - This function initializes the session to null (null encryption etc...). 222 * MHD__gnutls_init - This function initializes the session to null (null encryption etc...).
223 * @con_end: indicate if this session is to be used for server or client. 223 * @con_end: indicate if this session is to be used for server or client.
224 * @session: is a pointer to a #mhd_gtls_session_t structure. 224 * @session: is a pointer to a #MHD_gtls_session_t structure.
225 * 225 *
226 * This function initializes the current session to null. Every 226 * This function initializes the current session to null. Every
227 * session must be initialized before use, so internal structures can 227 * session must be initialized before use, so internal structures can
228 * be allocated. This function allocates structures which can only 228 * be allocated. This function allocates structures which can only
229 * be free'd by calling MHD_gnutls_deinit(). Returns zero on success. 229 * be free'd by calling MHD__gnutls_deinit(). Returns zero on success.
230 * 230 *
231 * @con_end can be one of %GNUTLS_CLIENT and %GNUTLS_SERVER. 231 * @con_end can be one of %GNUTLS_CLIENT and %GNUTLS_SERVER.
232 * 232 *
@@ -235,10 +235,10 @@ mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t session)
235 235
236/* TODO rm redundent pointer ref */ 236/* TODO rm redundent pointer ref */
237int 237int
238MHD_gnutls_init (mhd_gtls_session_t * session, 238MHD__gnutls_init (MHD_gtls_session_t * session,
239 gnutls_connection_end_t con_end) 239 MHD_gnutls_connection_end_t con_end)
240{ 240{
241 *session = gnutls_calloc (1, sizeof (struct MHD_gtls_session_int)); 241 *session = MHD_gnutls_calloc (1, sizeof (struct MHD_gtls_session_int));
242 if (*session == NULL) 242 if (*session == NULL)
243 return GNUTLS_E_MEMORY_ERROR; 243 return GNUTLS_E_MEMORY_ERROR;
244 244
@@ -263,32 +263,32 @@ MHD_gnutls_init (mhd_gtls_session_t * session,
263 (*session)->internals.enable_private = 0; 263 (*session)->internals.enable_private = 0;
264 264
265 /* Initialize buffers */ 265 /* Initialize buffers */
266 mhd_gtls_buffer_init (&(*session)->internals.application_data_buffer); 266 MHD_gtls_buffer_init (&(*session)->internals.application_data_buffer);
267 mhd_gtls_buffer_init (&(*session)->internals.handshake_data_buffer); 267 MHD_gtls_buffer_init (&(*session)->internals.handshake_data_buffer);
268 mhd_gtls_buffer_init (&(*session)->internals.handshake_hash_buffer); 268 MHD_gtls_buffer_init (&(*session)->internals.handshake_hash_buffer);
269 mhd_gtls_buffer_init (&(*session)->internals.ia_data_buffer); 269 MHD_gtls_buffer_init (&(*session)->internals.ia_data_buffer);
270 270
271 mhd_gtls_buffer_init (&(*session)->internals.record_send_buffer); 271 MHD_gtls_buffer_init (&(*session)->internals.record_send_buffer);
272 mhd_gtls_buffer_init (&(*session)->internals.record_recv_buffer); 272 MHD_gtls_buffer_init (&(*session)->internals.record_recv_buffer);
273 273
274 mhd_gtls_buffer_init (&(*session)->internals.handshake_send_buffer); 274 MHD_gtls_buffer_init (&(*session)->internals.handshake_send_buffer);
275 mhd_gtls_buffer_init (&(*session)->internals.handshake_recv_buffer); 275 MHD_gtls_buffer_init (&(*session)->internals.handshake_recv_buffer);
276 276
277 (*session)->key = gnutls_calloc (1, sizeof (struct mhd_gtls_key)); 277 (*session)->key = MHD_gnutls_calloc (1, sizeof (struct MHD_gtls_key));
278 if ((*session)->key == NULL) 278 if ((*session)->key == NULL)
279 { 279 {
280 cleanup_session:gnutls_free (*session); 280 cleanup_session:MHD_gnutls_free (*session);
281 *session = NULL; 281 *session = NULL;
282 return GNUTLS_E_MEMORY_ERROR; 282 return GNUTLS_E_MEMORY_ERROR;
283 } 283 }
284 284
285 (*session)->internals.expire_time = DEFAULT_EXPIRE_TIME; /* one hour default */ 285 (*session)->internals.expire_time = DEFAULT_EXPIRE_TIME; /* one hour default */
286 286
287 MHD_gnutls_dh_set_prime_bits ((*session), MIN_DH_BITS); 287 MHD__gnutls_dh_set_prime_bits ((*session), MIN_DH_BITS);
288 288
289 MHD_gnutls_transport_set_lowat ((*session), DEFAULT_LOWAT); /* the default for tcp */ 289 MHD__gnutls_transport_set_lowat ((*session), DEFAULT_LOWAT); /* the default for tcp */
290 290
291 MHD_gnutls_handshake_set_max_packet_length ((*session), 291 MHD__gnutls_handshake_set_max_packet_length ((*session),
292 MAX_HANDSHAKE_PACKET_SIZE); 292 MAX_HANDSHAKE_PACKET_SIZE);
293 293
294 /* Allocate a minimum size for recv_data 294 /* Allocate a minimum size for recv_data
@@ -296,16 +296,16 @@ MHD_gnutls_init (mhd_gtls_session_t * session,
296 * the receive procedure slow. 296 * the receive procedure slow.
297 */ 297 */
298 (*session)->internals.record_recv_buffer.data 298 (*session)->internals.record_recv_buffer.data
299 = gnutls_malloc (INITIAL_RECV_BUFFER_SIZE); 299 = MHD_gnutls_malloc (INITIAL_RECV_BUFFER_SIZE);
300 if ((*session)->internals.record_recv_buffer.data == NULL) 300 if ((*session)->internals.record_recv_buffer.data == NULL)
301 { 301 {
302 gnutls_free ((*session)->key); 302 MHD_gnutls_free ((*session)->key);
303 goto cleanup_session; 303 goto cleanup_session;
304 } 304 }
305 305
306 /* set the socket pointers to -1; */ 306 /* set the socket pointers to -1; */
307 (*session)->internals.transport_recv_ptr = (gnutls_transport_ptr_t) - 1; 307 (*session)->internals.transport_recv_ptr = (MHD_gnutls_transport_ptr_t) - 1;
308 (*session)->internals.transport_send_ptr = (gnutls_transport_ptr_t) - 1; 308 (*session)->internals.transport_send_ptr = (MHD_gnutls_transport_ptr_t) - 1;
309 309
310 /* set the default maximum record size for TLS 310 /* set the default maximum record size for TLS
311 */ 311 */
@@ -318,7 +318,7 @@ MHD_gnutls_init (mhd_gtls_session_t * session,
318 * as NULL or 0. This is why calloc is used. 318 * as NULL or 0. This is why calloc is used.
319 */ 319 */
320 320
321 mhd_gtls_handshake_internal_state_clear (*session); 321 MHD_gtls_handshake_internal_state_clear (*session);
322 322
323 return 0; 323 return 0;
324} 324}
@@ -326,113 +326,113 @@ MHD_gnutls_init (mhd_gtls_session_t * session,
326/* returns RESUME_FALSE or RESUME_TRUE. 326/* returns RESUME_FALSE or RESUME_TRUE.
327 */ 327 */
328int 328int
329mhd_gtls_session_is_resumable (mhd_gtls_session_t session) 329MHD_gtls_session_is_resumable (MHD_gtls_session_t session)
330{ 330{
331 return session->internals.resumable; 331 return session->internals.resumable;
332} 332}
333 333
334/** 334/**
335 * MHD_gnutls_deinit - This function clears all buffers associated with a session 335 * MHD__gnutls_deinit - This function clears all buffers associated with a session
336 * @session: is a #mhd_gtls_session_t structure. 336 * @session: is a #MHD_gtls_session_t structure.
337 * 337 *
338 * This function clears all buffers associated with the @session. 338 * This function clears all buffers associated with the @session.
339 * This function will also remove session data from the session 339 * This function will also remove session data from the session
340 * database if the session was terminated abnormally. 340 * database if the session was terminated abnormally.
341 **/ 341 **/
342void 342void
343MHD_gnutls_deinit (mhd_gtls_session_t session) 343MHD__gnutls_deinit (MHD_gtls_session_t session)
344{ 344{
345 345
346 if (session == NULL) 346 if (session == NULL)
347 return; 347 return;
348 348
349 /* remove auth info firstly */ 349 /* remove auth info firstly */
350 mhd_gtls_free_auth_info (session); 350 MHD_gtls_free_auth_info (session);
351 351
352 mhd_gtls_handshake_internal_state_clear (session); 352 MHD_gtls_handshake_internal_state_clear (session);
353 _gnutls_handshake_io_buffer_clear (session); 353 MHD__gnutls_handshake_io_buffer_clear (session);
354 354
355 _gnutls_free_datum (&session->connection_state.read_mac_secret); 355 MHD__gnutls_free_datum (&session->connection_state.read_mac_secret);
356 _gnutls_free_datum (&session->connection_state.write_mac_secret); 356 MHD__gnutls_free_datum (&session->connection_state.write_mac_secret);
357 357
358 mhd_gtls_buffer_clear (&session->internals.ia_data_buffer); 358 MHD_gtls_buffer_clear (&session->internals.ia_data_buffer);
359 mhd_gtls_buffer_clear (&session->internals.handshake_hash_buffer); 359 MHD_gtls_buffer_clear (&session->internals.handshake_hash_buffer);
360 mhd_gtls_buffer_clear (&session->internals.handshake_data_buffer); 360 MHD_gtls_buffer_clear (&session->internals.handshake_data_buffer);
361 mhd_gtls_buffer_clear (&session->internals.application_data_buffer); 361 MHD_gtls_buffer_clear (&session->internals.application_data_buffer);
362 mhd_gtls_buffer_clear (&session->internals.record_recv_buffer); 362 MHD_gtls_buffer_clear (&session->internals.record_recv_buffer);
363 mhd_gtls_buffer_clear (&session->internals.record_send_buffer); 363 MHD_gtls_buffer_clear (&session->internals.record_send_buffer);
364 364
365 MHD_gnutls_credentials_clear (session); 365 MHD__gnutls_credentials_clear (session);
366 mhd_gtls_selected_certs_deinit (session); 366 MHD_gtls_selected_certs_deinit (session);
367 367
368 if (session->connection_state.read_cipher_state != NULL) 368 if (session->connection_state.read_cipher_state != NULL)
369 mhd_gnutls_cipher_deinit (session->connection_state.read_cipher_state); 369 MHD_gnutls_cipher_deinit (session->connection_state.read_cipher_state);
370 if (session->connection_state.write_cipher_state != NULL) 370 if (session->connection_state.write_cipher_state != NULL)
371 mhd_gnutls_cipher_deinit (session->connection_state.write_cipher_state); 371 MHD_gnutls_cipher_deinit (session->connection_state.write_cipher_state);
372 372
373 if (session->connection_state.read_compression_state != NULL) 373 if (session->connection_state.read_compression_state != NULL)
374 mhd_gtls_comp_deinit (session->connection_state.read_compression_state, 374 MHD_gtls_comp_deinit (session->connection_state.read_compression_state,
375 1); 375 1);
376 if (session->connection_state.write_compression_state != NULL) 376 if (session->connection_state.write_compression_state != NULL)
377 mhd_gtls_comp_deinit (session->connection_state.write_compression_state, 377 MHD_gtls_comp_deinit (session->connection_state.write_compression_state,
378 0); 378 0);
379 379
380 _gnutls_free_datum (&session->cipher_specs.server_write_mac_secret); 380 MHD__gnutls_free_datum (&session->cipher_specs.server_write_mac_secret);
381 _gnutls_free_datum (&session->cipher_specs.client_write_mac_secret); 381 MHD__gnutls_free_datum (&session->cipher_specs.client_write_mac_secret);
382 _gnutls_free_datum (&session->cipher_specs.server_write_IV); 382 MHD__gnutls_free_datum (&session->cipher_specs.server_write_IV);
383 _gnutls_free_datum (&session->cipher_specs.client_write_IV); 383 MHD__gnutls_free_datum (&session->cipher_specs.client_write_IV);
384 _gnutls_free_datum (&session->cipher_specs.server_write_key); 384 MHD__gnutls_free_datum (&session->cipher_specs.server_write_key);
385 _gnutls_free_datum (&session->cipher_specs.client_write_key); 385 MHD__gnutls_free_datum (&session->cipher_specs.client_write_key);
386 386
387 if (session->key != NULL) 387 if (session->key != NULL)
388 { 388 {
389 mhd_gtls_mpi_release (&session->key->KEY); 389 MHD_gtls_mpi_release (&session->key->KEY);
390 mhd_gtls_mpi_release (&session->key->client_Y); 390 MHD_gtls_mpi_release (&session->key->client_Y);
391 mhd_gtls_mpi_release (&session->key->client_p); 391 MHD_gtls_mpi_release (&session->key->client_p);
392 mhd_gtls_mpi_release (&session->key->client_g); 392 MHD_gtls_mpi_release (&session->key->client_g);
393 393
394 mhd_gtls_mpi_release (&session->key->u); 394 MHD_gtls_mpi_release (&session->key->u);
395 mhd_gtls_mpi_release (&session->key->a); 395 MHD_gtls_mpi_release (&session->key->a);
396 mhd_gtls_mpi_release (&session->key->x); 396 MHD_gtls_mpi_release (&session->key->x);
397 mhd_gtls_mpi_release (&session->key->A); 397 MHD_gtls_mpi_release (&session->key->A);
398 mhd_gtls_mpi_release (&session->key->B); 398 MHD_gtls_mpi_release (&session->key->B);
399 mhd_gtls_mpi_release (&session->key->b); 399 MHD_gtls_mpi_release (&session->key->b);
400 400
401 /* RSA */ 401 /* RSA */
402 mhd_gtls_mpi_release (&session->key->rsa[0]); 402 MHD_gtls_mpi_release (&session->key->rsa[0]);
403 mhd_gtls_mpi_release (&session->key->rsa[1]); 403 MHD_gtls_mpi_release (&session->key->rsa[1]);
404 404
405 mhd_gtls_mpi_release (&session->key->dh_secret); 405 MHD_gtls_mpi_release (&session->key->dh_secret);
406 gnutls_free (session->key); 406 MHD_gnutls_free (session->key);
407 407
408 session->key = NULL; 408 session->key = NULL;
409 } 409 }
410 410
411 gnutls_free (session->internals.srp_username); 411 MHD_gnutls_free (session->internals.srp_username);
412 412
413 if (session->internals.srp_password) 413 if (session->internals.srp_password)
414 { 414 {
415 memset (session->internals.srp_password, 0, 415 memset (session->internals.srp_password, 0,
416 strlen (session->internals.srp_password)); 416 strlen (session->internals.srp_password));
417 gnutls_free (session->internals.srp_password); 417 MHD_gnutls_free (session->internals.srp_password);
418 } 418 }
419 419
420 memset (session, 0, sizeof (struct MHD_gtls_session_int)); 420 memset (session, 0, sizeof (struct MHD_gtls_session_int));
421 gnutls_free (session); 421 MHD_gnutls_free (session);
422} 422}
423 423
424/* Returns the minimum prime bits that are acceptable. 424/* Returns the minimum prime bits that are acceptable.
425 */ 425 */
426int 426int
427mhd_gtls_dh_get_allowed_prime_bits (mhd_gtls_session_t session) 427MHD_gtls_dh_get_allowed_prime_bits (MHD_gtls_session_t session)
428{ 428{
429 return session->internals.dh_prime_bits; 429 return session->internals.dh_prime_bits;
430} 430}
431 431
432int 432int
433mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public) 433MHD_gtls_dh_set_peer_public (MHD_gtls_session_t session, mpi_t public)
434{ 434{
435 mhd_gtls_dh_info_st *dh; 435 MHD_gtls_dh_info_st *dh;
436 int ret; 436 int ret;
437 437
438 switch (MHD_gtls_auth_get_type (session)) 438 switch (MHD_gtls_auth_get_type (session))
@@ -440,7 +440,7 @@ mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public)
440 case MHD_GNUTLS_CRD_ANON: 440 case MHD_GNUTLS_CRD_ANON:
441 { 441 {
442 mhd_anon_auth_info_t info; 442 mhd_anon_auth_info_t info;
443 info = mhd_gtls_get_auth_info (session); 443 info = MHD_gtls_get_auth_info (session);
444 if (info == NULL) 444 if (info == NULL)
445 return GNUTLS_E_INTERNAL_ERROR; 445 return GNUTLS_E_INTERNAL_ERROR;
446 446
@@ -451,7 +451,7 @@ mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public)
451 { 451 {
452 cert_auth_info_t info; 452 cert_auth_info_t info;
453 453
454 info = mhd_gtls_get_auth_info (session); 454 info = MHD_gtls_get_auth_info (session);
455 if (info == NULL) 455 if (info == NULL)
456 return GNUTLS_E_INTERNAL_ERROR; 456 return GNUTLS_E_INTERNAL_ERROR;
457 457
@@ -459,14 +459,14 @@ mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public)
459 break; 459 break;
460 } 460 }
461 default: 461 default:
462 gnutls_assert (); 462 MHD_gnutls_assert ();
463 return GNUTLS_E_INTERNAL_ERROR; 463 return GNUTLS_E_INTERNAL_ERROR;
464 } 464 }
465 465
466 ret = mhd_gtls_mpi_dprint_lz (&dh->public_key, public); 466 ret = MHD_gtls_mpi_dprint_lz (&dh->public_key, public);
467 if (ret < 0) 467 if (ret < 0)
468 { 468 {
469 gnutls_assert (); 469 MHD_gnutls_assert ();
470 return ret; 470 return ret;
471 } 471 }
472 472
@@ -474,14 +474,14 @@ mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public)
474} 474}
475 475
476int 476int
477mhd_gtls_dh_set_secret_bits (mhd_gtls_session_t session, unsigned bits) 477MHD_gtls_dh_set_secret_bits (MHD_gtls_session_t session, unsigned bits)
478{ 478{
479 switch (MHD_gtls_auth_get_type (session)) 479 switch (MHD_gtls_auth_get_type (session))
480 { 480 {
481 case MHD_GNUTLS_CRD_ANON: 481 case MHD_GNUTLS_CRD_ANON:
482 { 482 {
483 mhd_anon_auth_info_t info; 483 mhd_anon_auth_info_t info;
484 info = mhd_gtls_get_auth_info (session); 484 info = MHD_gtls_get_auth_info (session);
485 if (info == NULL) 485 if (info == NULL)
486 return GNUTLS_E_INTERNAL_ERROR; 486 return GNUTLS_E_INTERNAL_ERROR;
487 info->dh.secret_bits = bits; 487 info->dh.secret_bits = bits;
@@ -491,14 +491,14 @@ mhd_gtls_dh_set_secret_bits (mhd_gtls_session_t session, unsigned bits)
491 { 491 {
492 cert_auth_info_t info; 492 cert_auth_info_t info;
493 493
494 info = mhd_gtls_get_auth_info (session); 494 info = MHD_gtls_get_auth_info (session);
495 if (info == NULL) 495 if (info == NULL)
496 return GNUTLS_E_INTERNAL_ERROR; 496 return GNUTLS_E_INTERNAL_ERROR;
497 497
498 info->dh.secret_bits = bits; 498 info->dh.secret_bits = bits;
499 break; 499 break;
500 default: 500 default:
501 gnutls_assert (); 501 MHD_gnutls_assert ();
502 return GNUTLS_E_INTERNAL_ERROR; 502 return GNUTLS_E_INTERNAL_ERROR;
503 } 503 }
504 } 504 }
@@ -510,28 +510,28 @@ mhd_gtls_dh_set_secret_bits (mhd_gtls_session_t session, unsigned bits)
510 * RSA exponent and the modulus. 510 * RSA exponent and the modulus.
511 */ 511 */
512int 512int
513mhd_gtls_rsa_export_set_pubkey (mhd_gtls_session_t session, 513MHD_gtls_rsa_export_set_pubkey (MHD_gtls_session_t session,
514 mpi_t exponent, mpi_t modulus) 514 mpi_t exponent, mpi_t modulus)
515{ 515{
516 cert_auth_info_t info; 516 cert_auth_info_t info;
517 int ret; 517 int ret;
518 518
519 info = mhd_gtls_get_auth_info (session); 519 info = MHD_gtls_get_auth_info (session);
520 if (info == NULL) 520 if (info == NULL)
521 return GNUTLS_E_INTERNAL_ERROR; 521 return GNUTLS_E_INTERNAL_ERROR;
522 522
523 ret = mhd_gtls_mpi_dprint_lz (&info->rsa_export.modulus, modulus); 523 ret = MHD_gtls_mpi_dprint_lz (&info->rsa_export.modulus, modulus);
524 if (ret < 0) 524 if (ret < 0)
525 { 525 {
526 gnutls_assert (); 526 MHD_gnutls_assert ();
527 return ret; 527 return ret;
528 } 528 }
529 529
530 ret = mhd_gtls_mpi_dprint_lz (&info->rsa_export.exponent, exponent); 530 ret = MHD_gtls_mpi_dprint_lz (&info->rsa_export.exponent, exponent);
531 if (ret < 0) 531 if (ret < 0)
532 { 532 {
533 gnutls_assert (); 533 MHD_gnutls_assert ();
534 _gnutls_free_datum (&info->rsa_export.modulus); 534 MHD__gnutls_free_datum (&info->rsa_export.modulus);
535 return ret; 535 return ret;
536 } 536 }
537 537
@@ -541,9 +541,9 @@ mhd_gtls_rsa_export_set_pubkey (mhd_gtls_session_t session,
541/* Sets the prime and the generator in the auth info structure. 541/* Sets the prime and the generator in the auth info structure.
542 */ 542 */
543int 543int
544mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime) 544MHD_gtls_dh_set_group (MHD_gtls_session_t session, mpi_t gen, mpi_t prime)
545{ 545{
546 mhd_gtls_dh_info_st *dh; 546 MHD_gtls_dh_info_st *dh;
547 int ret; 547 int ret;
548 548
549 switch (MHD_gtls_auth_get_type (session)) 549 switch (MHD_gtls_auth_get_type (session))
@@ -551,7 +551,7 @@ mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime)
551 case MHD_GNUTLS_CRD_ANON: 551 case MHD_GNUTLS_CRD_ANON:
552 { 552 {
553 mhd_anon_auth_info_t info; 553 mhd_anon_auth_info_t info;
554 info = mhd_gtls_get_auth_info (session); 554 info = MHD_gtls_get_auth_info (session);
555 if (info == NULL) 555 if (info == NULL)
556 return GNUTLS_E_INTERNAL_ERROR; 556 return GNUTLS_E_INTERNAL_ERROR;
557 557
@@ -562,7 +562,7 @@ mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime)
562 { 562 {
563 cert_auth_info_t info; 563 cert_auth_info_t info;
564 564
565 info = mhd_gtls_get_auth_info (session); 565 info = MHD_gtls_get_auth_info (session);
566 if (info == NULL) 566 if (info == NULL)
567 return GNUTLS_E_INTERNAL_ERROR; 567 return GNUTLS_E_INTERNAL_ERROR;
568 568
@@ -570,26 +570,26 @@ mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime)
570 break; 570 break;
571 } 571 }
572 default: 572 default:
573 gnutls_assert (); 573 MHD_gnutls_assert ();
574 return GNUTLS_E_INTERNAL_ERROR; 574 return GNUTLS_E_INTERNAL_ERROR;
575 } 575 }
576 576
577 /* prime 577 /* prime
578 */ 578 */
579 ret = mhd_gtls_mpi_dprint_lz (&dh->prime, prime); 579 ret = MHD_gtls_mpi_dprint_lz (&dh->prime, prime);
580 if (ret < 0) 580 if (ret < 0)
581 { 581 {
582 gnutls_assert (); 582 MHD_gnutls_assert ();
583 return ret; 583 return ret;
584 } 584 }
585 585
586 /* generator 586 /* generator
587 */ 587 */
588 ret = mhd_gtls_mpi_dprint_lz (&dh->generator, gen); 588 ret = MHD_gtls_mpi_dprint_lz (&dh->generator, gen);
589 if (ret < 0) 589 if (ret < 0)
590 { 590 {
591 gnutls_assert (); 591 MHD_gnutls_assert ();
592 _gnutls_free_datum (&dh->prime); 592 MHD__gnutls_free_datum (&dh->prime);
593 return ret; 593 return ret;
594 } 594 }
595 595
@@ -597,8 +597,8 @@ mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime)
597} 597}
598 598
599/** 599/**
600 * MHD_gnutls_certificate_send_x509_rdn_sequence - This function will order gnutls to send or not the x.509 rdn sequence 600 * MHD__gnutls_certificate_send_x509_rdn_sequence - This function will order gnutls to send or not the x.509 rdn sequence
601 * @session: is a pointer to a #mhd_gtls_session_t structure. 601 * @session: is a pointer to a #MHD_gtls_session_t structure.
602 * @status: is 0 or 1 602 * @status: is 0 or 1
603 * 603 *
604 * If status is non zero, this function will order gnutls not to send 604 * If status is non zero, this function will order gnutls not to send
@@ -611,15 +611,15 @@ mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, mpi_t prime)
611 * methods other than certificate with X.509 certificates. 611 * methods other than certificate with X.509 certificates.
612 **/ 612 **/
613void 613void
614MHD_gnutls_certificate_send_x509_rdn_sequence (mhd_gtls_session_t session, 614MHD__gnutls_certificate_send_x509_rdn_sequence (MHD_gtls_session_t session,
615 int status) 615 int status)
616{ 616{
617 session->internals.ignore_rdn_sequence = status; 617 session->internals.ignore_rdn_sequence = status;
618} 618}
619 619
620/*- 620/*-
621 * _gnutls_record_set_default_version - Used to set the default version for the first record packet 621 * MHD__gnutls_record_set_default_version - Used to set the default version for the first record packet
622 * @session: is a #mhd_gtls_session_t structure. 622 * @session: is a #MHD_gtls_session_t structure.
623 * @major: is a tls major version 623 * @major: is a tls major version
624 * @minor: is a tls minor version 624 * @minor: is a tls minor version
625 * 625 *
@@ -629,7 +629,7 @@ MHD_gnutls_certificate_send_x509_rdn_sequence (mhd_gtls_session_t session,
629 * 629 *
630 -*/ 630 -*/
631void 631void
632_gnutls_record_set_default_version (mhd_gtls_session_t session, 632MHD__gnutls_record_set_default_version (MHD_gtls_session_t session,
633 unsigned char major, unsigned char minor) 633 unsigned char major, unsigned char minor)
634{ 634{
635 session->internals.default_record_version[0] = major; 635 session->internals.default_record_version[0] = major;
@@ -638,7 +638,7 @@ _gnutls_record_set_default_version (mhd_gtls_session_t session,
638 638
639/** 639/**
640 * MHD_gtls_handshake_set_private_extensions - Used to enable the private cipher suites 640 * MHD_gtls_handshake_set_private_extensions - Used to enable the private cipher suites
641 * @session: is a #mhd_gtls_session_t structure. 641 * @session: is a #MHD_gtls_session_t structure.
642 * @allow: is an integer (0 or 1) 642 * @allow: is an integer (0 or 1)
643 * 643 *
644 * This function will enable or disable the use of private cipher 644 * This function will enable or disable the use of private cipher
@@ -653,29 +653,29 @@ _gnutls_record_set_default_version (mhd_gtls_session_t session,
653 * gnutls servers and clients may cause interoperability problems. 653 * gnutls servers and clients may cause interoperability problems.
654 **/ 654 **/
655void 655void
656MHD_gtls_handshake_set_private_extensions (mhd_gtls_session_t session, 656MHD_gtls_handshake_set_private_extensions (MHD_gtls_session_t session,
657 int allow) 657 int allow)
658{ 658{
659 session->internals.enable_private = allow; 659 session->internals.enable_private = allow;
660} 660}
661 661
662inline static int 662inline static int
663_gnutls_cal_PRF_A (enum MHD_GNUTLS_HashAlgorithm algorithm, 663MHD__gnutls_cal_PRF_A (enum MHD_GNUTLS_HashAlgorithm algorithm,
664 const void *secret, 664 const void *secret,
665 int secret_size, 665 int secret_size,
666 const void *seed, int seed_size, void *result) 666 const void *seed, int seed_size, void *result)
667{ 667{
668 mac_hd_t td1; 668 mac_hd_t td1;
669 669
670 td1 = mhd_gtls_hmac_init (algorithm, secret, secret_size); 670 td1 = MHD_gtls_MHD_hmac_init (algorithm, secret, secret_size);
671 if (td1 == GNUTLS_MAC_FAILED) 671 if (td1 == GNUTLS_MAC_FAILED)
672 { 672 {
673 gnutls_assert (); 673 MHD_gnutls_assert ();
674 return GNUTLS_E_INTERNAL_ERROR; 674 return GNUTLS_E_INTERNAL_ERROR;
675 } 675 }
676 676
677 mhd_gnutls_hash (td1, seed, seed_size); 677 MHD_gnutls_hash (td1, seed, seed_size);
678 mhd_gnutls_hmac_deinit (td1, result); 678 MHD_gnutls_MHD_hmac_deinit (td1, result);
679 679
680 return 0; 680 return 0;
681} 681}
@@ -686,7 +686,7 @@ _gnutls_cal_PRF_A (enum MHD_GNUTLS_HashAlgorithm algorithm,
686 * (used in the PRF function) 686 * (used in the PRF function)
687 */ 687 */
688static int 688static int
689_gnutls_P_hash (enum MHD_GNUTLS_HashAlgorithm algorithm, 689MHD__gnutls_P_hash (enum MHD_GNUTLS_HashAlgorithm algorithm,
690 const opaque * secret, 690 const opaque * secret,
691 int secret_size, 691 int secret_size,
692 const opaque * seed, 692 const opaque * seed,
@@ -700,11 +700,11 @@ _gnutls_P_hash (enum MHD_GNUTLS_HashAlgorithm algorithm,
700 700
701 if (seed_size > MAX_SEED_SIZE || total_bytes <= 0) 701 if (seed_size > MAX_SEED_SIZE || total_bytes <= 0)
702 { 702 {
703 gnutls_assert (); 703 MHD_gnutls_assert ();
704 return GNUTLS_E_INTERNAL_ERROR; 704 return GNUTLS_E_INTERNAL_ERROR;
705 } 705 }
706 706
707 blocksize = mhd_gnutls_hash_get_algo_len (algorithm); 707 blocksize = MHD_gnutls_hash_get_algo_len (algorithm);
708 708
709 output_bytes = 0; 709 output_bytes = 0;
710 do 710 do
@@ -722,27 +722,27 @@ _gnutls_P_hash (enum MHD_GNUTLS_HashAlgorithm algorithm,
722 722
723 for (i = 0; i < times; i++) 723 for (i = 0; i < times; i++)
724 { 724 {
725 td2 = mhd_gtls_hmac_init (algorithm, secret, secret_size); 725 td2 = MHD_gtls_MHD_hmac_init (algorithm, secret, secret_size);
726 if (td2 == GNUTLS_MAC_FAILED) 726 if (td2 == GNUTLS_MAC_FAILED)
727 { 727 {
728 gnutls_assert (); 728 MHD_gnutls_assert ();
729 return GNUTLS_E_INTERNAL_ERROR; 729 return GNUTLS_E_INTERNAL_ERROR;
730 } 730 }
731 731
732 /* here we calculate A(i+1) */ 732 /* here we calculate A(i+1) */
733 if ((result = _gnutls_cal_PRF_A (algorithm, secret, secret_size, Atmp, 733 if ((result = MHD__gnutls_cal_PRF_A (algorithm, secret, secret_size, Atmp,
734 A_size, Atmp)) < 0) 734 A_size, Atmp)) < 0)
735 { 735 {
736 gnutls_assert (); 736 MHD_gnutls_assert ();
737 mhd_gnutls_hmac_deinit (td2, final); 737 MHD_gnutls_MHD_hmac_deinit (td2, final);
738 return result; 738 return result;
739 } 739 }
740 740
741 A_size = blocksize; 741 A_size = blocksize;
742 742
743 mhd_gnutls_hash (td2, Atmp, A_size); 743 MHD_gnutls_hash (td2, Atmp, A_size);
744 mhd_gnutls_hash (td2, seed, seed_size); 744 MHD_gnutls_hash (td2, seed, seed_size);
745 mhd_gnutls_hmac_deinit (td2, final); 745 MHD_gnutls_MHD_hmac_deinit (td2, final);
746 746
747 if ((1 + i) * blocksize < total_bytes) 747 if ((1 + i) * blocksize < total_bytes)
748 { 748 {
@@ -765,7 +765,7 @@ _gnutls_P_hash (enum MHD_GNUTLS_HashAlgorithm algorithm,
765/* Xor's two buffers and puts the output in the first one. 765/* Xor's two buffers and puts the output in the first one.
766 */ 766 */
767inline static void 767inline static void
768_gnutls_xor (opaque * o1, opaque * o2, int length) 768MHD__gnutls_xor (opaque * o1, opaque * o2, int length)
769{ 769{
770 int i; 770 int i;
771 for (i = 0; i < length; i++) 771 for (i = 0; i < length; i++)
@@ -781,7 +781,7 @@ _gnutls_xor (opaque * o1, opaque * o2, int length)
781 * available. 781 * available.
782 */ 782 */
783int 783int
784mhd_gtls_PRF (mhd_gtls_session_t session, 784MHD_gtls_PRF (MHD_gtls_session_t session,
785 const opaque * secret, 785 const opaque * secret,
786 int secret_size, 786 int secret_size,
787 const char *label, 787 const char *label,
@@ -793,11 +793,11 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
793 opaque s_seed[MAX_SEED_SIZE]; 793 opaque s_seed[MAX_SEED_SIZE];
794 opaque o1[MAX_PRF_BYTES], o2[MAX_PRF_BYTES]; 794 opaque o1[MAX_PRF_BYTES], o2[MAX_PRF_BYTES];
795 int result; 795 int result;
796 enum MHD_GNUTLS_Protocol ver = MHD_gnutls_protocol_get_version (session); 796 enum MHD_GNUTLS_Protocol ver = MHD__gnutls_protocol_get_version (session);
797 797
798 if (total_bytes > MAX_PRF_BYTES) 798 if (total_bytes > MAX_PRF_BYTES)
799 { 799 {
800 gnutls_assert (); 800 MHD_gnutls_assert ();
801 return GNUTLS_E_INTERNAL_ERROR; 801 return GNUTLS_E_INTERNAL_ERROR;
802 } 802 }
803 /* label+seed = s_seed */ 803 /* label+seed = s_seed */
@@ -805,7 +805,7 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
805 805
806 if (s_seed_size > MAX_SEED_SIZE) 806 if (s_seed_size > MAX_SEED_SIZE)
807 { 807 {
808 gnutls_assert (); 808 MHD_gnutls_assert ();
809 return GNUTLS_E_INTERNAL_ERROR; 809 return GNUTLS_E_INTERNAL_ERROR;
810 } 810 }
811 811
@@ -815,11 +815,11 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
815 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_2) 815 if (ver >= MHD_GNUTLS_PROTOCOL_TLS1_2)
816 { 816 {
817 result = 817 result =
818 _gnutls_P_hash (MHD_GNUTLS_MAC_SHA1, secret, secret_size, s_seed, 818 MHD__gnutls_P_hash (MHD_GNUTLS_MAC_SHA1, secret, secret_size, s_seed,
819 s_seed_size, total_bytes, ret); 819 s_seed_size, total_bytes, ret);
820 if (result < 0) 820 if (result < 0)
821 { 821 {
822 gnutls_assert (); 822 MHD_gnutls_assert ();
823 return result; 823 return result;
824 } 824 }
825 } 825 }
@@ -836,24 +836,24 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
836 } 836 }
837 837
838 result = 838 result =
839 _gnutls_P_hash (MHD_GNUTLS_MAC_MD5, s1, l_s, s_seed, s_seed_size, 839 MHD__gnutls_P_hash (MHD_GNUTLS_MAC_MD5, s1, l_s, s_seed, s_seed_size,
840 total_bytes, o1); 840 total_bytes, o1);
841 if (result < 0) 841 if (result < 0)
842 { 842 {
843 gnutls_assert (); 843 MHD_gnutls_assert ();
844 return result; 844 return result;
845 } 845 }
846 846
847 result = 847 result =
848 _gnutls_P_hash (MHD_GNUTLS_MAC_SHA1, s2, l_s, s_seed, s_seed_size, 848 MHD__gnutls_P_hash (MHD_GNUTLS_MAC_SHA1, s2, l_s, s_seed, s_seed_size,
849 total_bytes, o2); 849 total_bytes, o2);
850 if (result < 0) 850 if (result < 0)
851 { 851 {
852 gnutls_assert (); 852 MHD_gnutls_assert ();
853 return result; 853 return result;
854 } 854 }
855 855
856 _gnutls_xor (o1, o2, total_bytes); 856 MHD__gnutls_xor (o1, o2, total_bytes);
857 857
858 memcpy (ret, o1, total_bytes); 858 memcpy (ret, o1, total_bytes);
859 } 859 }
@@ -863,8 +863,8 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
863} 863}
864 864
865/** 865/**
866 * MHD_gnutls_prf_raw - access the TLS PRF directly 866 * MHD__gnutls_prf_raw - access the TLS PRF directly
867 * @session: is a #mhd_gtls_session_t structure. 867 * @session: is a #MHD_gtls_session_t structure.
868 * @label_size: length of the @label variable. 868 * @label_size: length of the @label variable.
869 * @label: label used in PRF computation, typically a short string. 869 * @label: label used in PRF computation, typically a short string.
870 * @seed_size: length of the @seed variable. 870 * @seed_size: length of the @seed variable.
@@ -885,14 +885,14 @@ mhd_gtls_PRF (mhd_gtls_session_t session,
885 * session unless @seed include the client random and server random 885 * session unless @seed include the client random and server random
886 * fields (the PRF would output the same data on another connection 886 * fields (the PRF would output the same data on another connection
887 * resumed from the first one), it is not recommended to use this 887 * resumed from the first one), it is not recommended to use this
888 * function directly. The MHD_gnutls_prf() function seed the PRF with the 888 * function directly. The MHD__gnutls_prf() function seed the PRF with the
889 * client and server random fields directly, and is recommended if you 889 * client and server random fields directly, and is recommended if you
890 * want to generate pseudo random data unique for each session. 890 * want to generate pseudo random data unique for each session.
891 * 891 *
892 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 892 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
893 **/ 893 **/
894int 894int
895MHD_gnutls_prf_raw (mhd_gtls_session_t session, 895MHD__gnutls_prf_raw (MHD_gtls_session_t session,
896 size_t label_size, 896 size_t label_size,
897 const char *label, 897 const char *label,
898 size_t seed_size, const char *seed, size_t outsize, 898 size_t seed_size, const char *seed, size_t outsize,
@@ -900,7 +900,7 @@ MHD_gnutls_prf_raw (mhd_gtls_session_t session,
900{ 900{
901 int ret; 901 int ret;
902 902
903 ret = mhd_gtls_PRF (session, session->security_parameters.master_secret, 903 ret = MHD_gtls_PRF (session, session->security_parameters.master_secret,
904 TLS_MASTER_SIZE, label, label_size, (opaque *) seed, 904 TLS_MASTER_SIZE, label, label_size, (opaque *) seed,
905 seed_size, outsize, out); 905 seed_size, outsize, out);
906 906
@@ -908,8 +908,8 @@ MHD_gnutls_prf_raw (mhd_gtls_session_t session,
908} 908}
909 909
910/** 910/**
911 * MHD_gnutls_prf - derive pseudo-random data using the TLS PRF 911 * MHD__gnutls_prf - derive pseudo-random data using the TLS PRF
912 * @session: is a #mhd_gtls_session_t structure. 912 * @session: is a #MHD_gtls_session_t structure.
913 * @label_size: length of the @label variable. 913 * @label_size: length of the @label variable.
914 * @label: label used in PRF computation, typically a short string. 914 * @label: label used in PRF computation, typically a short string.
915 * @server_random_first: non-0 if server random field should be first in seed 915 * @server_random_first: non-0 if server random field should be first in seed
@@ -937,7 +937,7 @@ MHD_gnutls_prf_raw (mhd_gtls_session_t session,
937 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 937 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
938 **/ 938 **/
939int 939int
940MHD_gnutls_prf (mhd_gtls_session_t session, 940MHD__gnutls_prf (MHD_gtls_session_t session,
941 size_t label_size, 941 size_t label_size,
942 const char *label, 942 const char *label,
943 int server_random_first, 943 int server_random_first,
@@ -948,10 +948,10 @@ MHD_gnutls_prf (mhd_gtls_session_t session,
948 opaque *seed; 948 opaque *seed;
949 size_t seedsize = 2 * TLS_RANDOM_SIZE + extra_size; 949 size_t seedsize = 2 * TLS_RANDOM_SIZE + extra_size;
950 950
951 seed = gnutls_malloc (seedsize); 951 seed = MHD_gnutls_malloc (seedsize);
952 if (!seed) 952 if (!seed)
953 { 953 {
954 gnutls_assert (); 954 MHD_gnutls_assert ();
955 return GNUTLS_E_MEMORY_ERROR; 955 return GNUTLS_E_MEMORY_ERROR;
956 } 956 }
957 957
@@ -964,18 +964,18 @@ MHD_gnutls_prf (mhd_gtls_session_t session,
964 964
965 memcpy (seed + 2 * TLS_RANDOM_SIZE, extra, extra_size); 965 memcpy (seed + 2 * TLS_RANDOM_SIZE, extra, extra_size);
966 966
967 ret = mhd_gtls_PRF (session, session->security_parameters.master_secret, 967 ret = MHD_gtls_PRF (session, session->security_parameters.master_secret,
968 TLS_MASTER_SIZE, label, label_size, seed, seedsize, 968 TLS_MASTER_SIZE, label, label_size, seed, seedsize,
969 outsize, out); 969 outsize, out);
970 970
971 gnutls_free (seed); 971 MHD_gnutls_free (seed);
972 972
973 return ret; 973 return ret;
974} 974}
975 975
976/** 976/**
977 * MHD_gtls_session_get_client_random - get the session's client random value 977 * MHD_gtls_session_get_client_random - get the session's client random value
978 * @session: is a #mhd_gtls_session_t structure. 978 * @session: is a #MHD_gtls_session_t structure.
979 * 979 *
980 * Return a pointer to the 32-byte client random field used in the 980 * Return a pointer to the 32-byte client random field used in the
981 * session. The pointer must not be modified or deallocated. 981 * session. The pointer must not be modified or deallocated.
@@ -987,14 +987,14 @@ MHD_gnutls_prf (mhd_gtls_session_t session,
987 * Returns: pointer to client random data. 987 * Returns: pointer to client random data.
988 **/ 988 **/
989const void * 989const void *
990MHD_gtls_session_get_client_random (mhd_gtls_session_t session) 990MHD_gtls_session_get_client_random (MHD_gtls_session_t session)
991{ 991{
992 return (char *) session->security_parameters.client_random; 992 return (char *) session->security_parameters.client_random;
993} 993}
994 994
995/** 995/**
996 * MHD_gtls_session_get_server_random - get the session's server random value 996 * MHD_gtls_session_get_server_random - get the session's server random value
997 * @session: is a #mhd_gtls_session_t structure. 997 * @session: is a #MHD_gtls_session_t structure.
998 * 998 *
999 * Return a pointer to the 32-byte server random field used in the 999 * Return a pointer to the 32-byte server random field used in the
1000 * session. The pointer must not be modified or deallocated. 1000 * session. The pointer must not be modified or deallocated.
@@ -1006,14 +1006,14 @@ MHD_gtls_session_get_client_random (mhd_gtls_session_t session)
1006 * Returns: pointer to server random data. 1006 * Returns: pointer to server random data.
1007 **/ 1007 **/
1008const void * 1008const void *
1009MHD_gtls_session_get_server_random (mhd_gtls_session_t session) 1009MHD_gtls_session_get_server_random (MHD_gtls_session_t session)
1010{ 1010{
1011 return (char *) session->security_parameters.server_random; 1011 return (char *) session->security_parameters.server_random;
1012} 1012}
1013 1013
1014/** 1014/**
1015 * MHD_gtls_session_get_master_secret - get the session's master secret value 1015 * MHD_gtls_session_get_master_secret - get the session's master secret value
1016 * @session: is a #mhd_gtls_session_t structure. 1016 * @session: is a #MHD_gtls_session_t structure.
1017 * 1017 *
1018 * Return a pointer to the 48-byte master secret in the session. The 1018 * Return a pointer to the 48-byte master secret in the session. The
1019 * pointer must not be modified or deallocated. 1019 * pointer must not be modified or deallocated.
@@ -1022,26 +1022,26 @@ MHD_gtls_session_get_server_random (mhd_gtls_session_t session)
1022 * will be garbage; in particular, a %NULL return value should not be 1022 * will be garbage; in particular, a %NULL return value should not be
1023 * expected. 1023 * expected.
1024 * 1024 *
1025 * Consider using MHD_gnutls_prf() rather than extracting the master 1025 * Consider using MHD__gnutls_prf() rather than extracting the master
1026 * secret and use it to derive further data. 1026 * secret and use it to derive further data.
1027 * 1027 *
1028 * Returns: pointer to master secret data. 1028 * Returns: pointer to master secret data.
1029 **/ 1029 **/
1030const void * 1030const void *
1031MHD_gtls_session_get_master_secret (mhd_gtls_session_t session) 1031MHD_gtls_session_get_master_secret (MHD_gtls_session_t session)
1032{ 1032{
1033 return (char *) session->security_parameters.master_secret; 1033 return (char *) session->security_parameters.master_secret;
1034} 1034}
1035 1035
1036/** 1036/**
1037 * MHD_gtls_session_is_resumed - Used to check whether this session is a resumed one 1037 * MHD_gtls_session_is_resumed - Used to check whether this session is a resumed one
1038 * @session: is a #mhd_gtls_session_t structure. 1038 * @session: is a #MHD_gtls_session_t structure.
1039 * 1039 *
1040 * Returns: non zero if this session is resumed, or a zero if this is 1040 * Returns: non zero if this session is resumed, or a zero if this is
1041 * a new session. 1041 * a new session.
1042 **/ 1042 **/
1043int 1043int
1044MHD_gtls_session_is_resumed (mhd_gtls_session_t session) 1044MHD_gtls_session_is_resumed (MHD_gtls_session_t session)
1045{ 1045{
1046#if MHD_DEBUG_TLS 1046#if MHD_DEBUG_TLS
1047 if (session->security_parameters.entity == GNUTLS_CLIENT) 1047 if (session->security_parameters.entity == GNUTLS_CLIENT)
@@ -1066,22 +1066,22 @@ MHD_gtls_session_is_resumed (mhd_gtls_session_t session)
1066} 1066}
1067 1067
1068/*- 1068/*-
1069 * mhd_gtls_session_is_export - Used to check whether this session is of export grade 1069 * MHD_gtls_session_is_export - Used to check whether this session is of export grade
1070 * @session: is a #mhd_gtls_session_t structure. 1070 * @session: is a #MHD_gtls_session_t structure.
1071 * 1071 *
1072 * This function will return non zero if this session is of export grade. 1072 * This function will return non zero if this session is of export grade.
1073 * 1073 *
1074 -*/ 1074 -*/
1075int 1075int
1076mhd_gtls_session_is_export (mhd_gtls_session_t session) 1076MHD_gtls_session_is_export (MHD_gtls_session_t session)
1077{ 1077{
1078 enum MHD_GNUTLS_CipherAlgorithm cipher; 1078 enum MHD_GNUTLS_CipherAlgorithm cipher;
1079 1079
1080 cipher = 1080 cipher =
1081 mhd_gtls_cipher_suite_get_cipher_algo (&session->security_parameters. 1081 MHD_gtls_cipher_suite_get_cipher_algo (&session->security_parameters.
1082 current_cipher_suite); 1082 current_cipher_suite);
1083 1083
1084 if (mhd_gtls_cipher_get_export_flag (cipher) != 0) 1084 if (MHD_gtls_cipher_get_export_flag (cipher) != 0)
1085 return 1; 1085 return 1;
1086 1086
1087 return 0; 1087 return 0;
@@ -1089,20 +1089,20 @@ mhd_gtls_session_is_export (mhd_gtls_session_t session)
1089 1089
1090/** 1090/**
1091 * MHD_gtls_session_get_ptr - Used to get the user pointer from the session structure 1091 * MHD_gtls_session_get_ptr - Used to get the user pointer from the session structure
1092 * @session: is a #mhd_gtls_session_t structure. 1092 * @session: is a #MHD_gtls_session_t structure.
1093 * 1093 *
1094 * Returns: the user given pointer from the session structure. This 1094 * Returns: the user given pointer from the session structure. This
1095 * is the pointer set with MHD_gnutls_session_set_ptr(). 1095 * is the pointer set with MHD__gnutls_session_set_ptr().
1096 **/ 1096 **/
1097void * 1097void *
1098MHD_gtls_session_get_ptr (mhd_gtls_session_t session) 1098MHD_gtls_session_get_ptr (MHD_gtls_session_t session)
1099{ 1099{
1100 return session->internals.user_ptr; 1100 return session->internals.user_ptr;
1101} 1101}
1102 1102
1103/** 1103/**
1104 * MHD_gnutls_session_set_ptr - Used to set the user pointer to the session structure 1104 * MHD__gnutls_session_set_ptr - Used to set the user pointer to the session structure
1105 * @session: is a #mhd_gtls_session_t structure. 1105 * @session: is a #MHD_gtls_session_t structure.
1106 * @ptr: is the user pointer 1106 * @ptr: is the user pointer
1107 * 1107 *
1108 * This function will set (associate) the user given pointer to the 1108 * This function will set (associate) the user given pointer to the
@@ -1110,37 +1110,37 @@ MHD_gtls_session_get_ptr (mhd_gtls_session_t session)
1110 * MHD_gtls_session_get_ptr(). 1110 * MHD_gtls_session_get_ptr().
1111 **/ 1111 **/
1112void 1112void
1113MHD_gnutls_session_set_ptr (mhd_gtls_session_t session, void *ptr) 1113MHD__gnutls_session_set_ptr (MHD_gtls_session_t session, void *ptr)
1114{ 1114{
1115 session->internals.user_ptr = ptr; 1115 session->internals.user_ptr = ptr;
1116} 1116}
1117 1117
1118/** 1118/**
1119 * MHD_gnutls_record_get_direction - This function will return the direction of the last interrupted function call 1119 * MHD__gnutls_record_get_direction - This function will return the direction of the last interrupted function call
1120 * @session: is a #mhd_gtls_session_t structure. 1120 * @session: is a #MHD_gtls_session_t structure.
1121 * 1121 *
1122 * This function provides information about the internals of the 1122 * This function provides information about the internals of the
1123 * record protocol and is only useful if a prior gnutls function call 1123 * record protocol and is only useful if a prior gnutls function call
1124 * (e.g. MHD_gnutls_handshake()) was interrupted for some reason, that 1124 * (e.g. MHD__gnutls_handshake()) was interrupted for some reason, that
1125 * is, if a function returned %GNUTLS_E_INTERRUPTED or 1125 * is, if a function returned %GNUTLS_E_INTERRUPTED or
1126 * %GNUTLS_E_AGAIN. In such a case, you might want to call select() 1126 * %GNUTLS_E_AGAIN. In such a case, you might want to call select()
1127 * or poll() before calling the interrupted gnutls function again. 1127 * or poll() before calling the interrupted gnutls function again.
1128 * To tell you whether a file descriptor should be selected for 1128 * To tell you whether a file descriptor should be selected for
1129 * either reading or writing, MHD_gnutls_record_get_direction() returns 0 1129 * either reading or writing, MHD__gnutls_record_get_direction() returns 0
1130 * if the interrupted function was trying to read data, and 1 if it 1130 * if the interrupted function was trying to read data, and 1 if it
1131 * was trying to write data. 1131 * was trying to write data.
1132 * 1132 *
1133 * Returns: 0 if trying to read data, 1 if trying to write data. 1133 * Returns: 0 if trying to read data, 1 if trying to write data.
1134 **/ 1134 **/
1135int 1135int
1136MHD_gnutls_record_get_direction (mhd_gtls_session_t session) 1136MHD__gnutls_record_get_direction (MHD_gtls_session_t session)
1137{ 1137{
1138 return session->internals.direction; 1138 return session->internals.direction;
1139} 1139}
1140 1140
1141/*- 1141/*-
1142 * _gnutls_rsa_pms_set_version - Sets a version to be used at the RSA PMS 1142 * MHD__gnutls_rsa_pms_set_version - Sets a version to be used at the RSA PMS
1143 * @session: is a #mhd_gtls_session_t structure. 1143 * @session: is a #MHD_gtls_session_t structure.
1144 * @major: is the major version to use 1144 * @major: is the major version to use
1145 * @minor: is the minor version to use 1145 * @minor: is the minor version to use
1146 * 1146 *
@@ -1150,7 +1150,7 @@ MHD_gnutls_record_get_direction (mhd_gtls_session_t session)
1150 * 1150 *
1151 -*/ 1151 -*/
1152void 1152void
1153_gnutls_rsa_pms_set_version (mhd_gtls_session_t session, 1153MHD__gnutls_rsa_pms_set_version (MHD_gtls_session_t session,
1154 unsigned char major, unsigned char minor) 1154 unsigned char major, unsigned char minor)
1155{ 1155{
1156 session->internals.rsa_pms_version[0] = major; 1156 session->internals.rsa_pms_version[0] = major;
@@ -1158,8 +1158,8 @@ _gnutls_rsa_pms_set_version (mhd_gtls_session_t session,
1158} 1158}
1159 1159
1160/** 1160/**
1161 * MHD_gnutls_handshake_set_post_client_hello_function - This function will a callback to be called after the client hello is received 1161 * MHD__gnutls_handshake_set_post_client_hello_function - This function will a callback to be called after the client hello is received
1162 * @res: is a mhd_gtls_anon_server_credentials_t structure 1162 * @res: is a MHD_gtls_anon_server_credentials_t structure
1163 * @func: is the function to be called 1163 * @func: is the function to be called
1164 * 1164 *
1165 * This function will set a callback to be called after the client 1165 * This function will set a callback to be called after the client
@@ -1180,9 +1180,9 @@ _gnutls_rsa_pms_set_version (mhd_gtls_session_t session,
1180 * 1180 *
1181 **/ 1181 **/
1182void 1182void
1183MHD_gnutls_handshake_set_post_client_hello_function (mhd_gtls_session_t 1183MHD__gnutls_handshake_set_post_client_hello_function (MHD_gtls_session_t
1184 session, 1184 session,
1185 gnutls_handshake_post_client_hello_func 1185 MHD_gnutls_handshake_post_client_hello_func
1186 func) 1186 func)
1187{ 1187{
1188 session->internals.user_hello_func = func; 1188 session->internals.user_hello_func = func;
diff --git a/src/daemon/https/tls/gnutls_state.h b/src/daemon/https/tls/gnutls_state.h
index e5d1877a..34aeda93 100644
--- a/src/daemon/https/tls/gnutls_state.h
+++ b/src/daemon/https/tls/gnutls_state.h
@@ -27,51 +27,51 @@
27 27
28#include <gnutls_int.h> 28#include <gnutls_int.h>
29 29
30void _gnutls_session_cert_type_set (mhd_gtls_session_t session, 30void MHD__gnutls_session_cert_type_set (MHD_gtls_session_t session,
31 enum MHD_GNUTLS_CertificateType); 31 enum MHD_GNUTLS_CertificateType);
32enum MHD_GNUTLS_KeyExchangeAlgorithm gnutls_kx_get (mhd_gtls_session_t 32enum MHD_GNUTLS_KeyExchangeAlgorithm MHD_gnutls_kx_get (MHD_gtls_session_t
33 session); 33 session);
34enum MHD_GNUTLS_CipherAlgorithm gnutls_cipher_get (mhd_gtls_session_t 34enum MHD_GNUTLS_CipherAlgorithm MHD_gnutls_cipher_get (MHD_gtls_session_t
35 session); 35 session);
36enum MHD_GNUTLS_CertificateType 36enum MHD_GNUTLS_CertificateType
37gnutls_certificate_type_get (mhd_gtls_session_t); 37MHD_gnutls_certificate_type_get (MHD_gtls_session_t);
38 38
39#include <gnutls_auth_int.h> 39#include <gnutls_auth_int.h>
40 40
41#define CHECK_AUTH(auth, ret) if (MHD_gtls_auth_get_type(session) != auth) { \ 41#define CHECK_AUTH(auth, ret) if (MHD_gtls_auth_get_type(session) != auth) { \
42 gnutls_assert(); \ 42 MHD_gnutls_assert(); \
43 return ret; \ 43 return ret; \
44 } 44 }
45 45
46#endif 46#endif
47 47
48int mhd_gtls_session_cert_type_supported (mhd_gtls_session_t, 48int MHD_gtls_session_cert_type_supported (MHD_gtls_session_t,
49 enum MHD_GNUTLS_CertificateType); 49 enum MHD_GNUTLS_CertificateType);
50 50
51int mhd_gtls_dh_set_secret_bits (mhd_gtls_session_t session, unsigned bits); 51int MHD_gtls_dh_set_secret_bits (MHD_gtls_session_t session, unsigned bits);
52 52
53int mhd_gtls_dh_set_peer_public (mhd_gtls_session_t session, mpi_t public); 53int MHD_gtls_dh_set_peer_public (MHD_gtls_session_t session, mpi_t public);
54int mhd_gtls_dh_set_group (mhd_gtls_session_t session, mpi_t gen, 54int MHD_gtls_dh_set_group (MHD_gtls_session_t session, mpi_t gen,
55 mpi_t prime); 55 mpi_t prime);
56 56
57int mhd_gtls_dh_get_allowed_prime_bits (mhd_gtls_session_t session); 57int MHD_gtls_dh_get_allowed_prime_bits (MHD_gtls_session_t session);
58void mhd_gtls_handshake_internal_state_clear (mhd_gtls_session_t); 58void MHD_gtls_handshake_internal_state_clear (MHD_gtls_session_t);
59 59
60int mhd_gtls_rsa_export_set_pubkey (mhd_gtls_session_t session, 60int MHD_gtls_rsa_export_set_pubkey (MHD_gtls_session_t session,
61 mpi_t exponent, mpi_t modulus); 61 mpi_t exponent, mpi_t modulus);
62 62
63int mhd_gtls_session_is_resumable (mhd_gtls_session_t session); 63int MHD_gtls_session_is_resumable (MHD_gtls_session_t session);
64int mhd_gtls_session_is_export (mhd_gtls_session_t session); 64int MHD_gtls_session_is_export (MHD_gtls_session_t session);
65 65
66int mhd_gtls_openpgp_send_fingerprint (mhd_gtls_session_t session); 66int MHD_gtls_openpgp_send_fingerprint (MHD_gtls_session_t session);
67 67
68int mhd_gtls_PRF (mhd_gtls_session_t session, 68int MHD_gtls_PRF (MHD_gtls_session_t session,
69 const opaque * secret, int secret_size, 69 const opaque * secret, int secret_size,
70 const char *label, int label_size, 70 const char *label, int label_size,
71 const opaque * seed, int seed_size, 71 const opaque * seed, int seed_size,
72 int total_bytes, void *ret); 72 int total_bytes, void *ret);
73 73
74int MHD_gnutls_init (mhd_gtls_session_t * session, 74int MHD__gnutls_init (MHD_gtls_session_t * session,
75 gnutls_connection_end_t con_end); 75 MHD_gnutls_connection_end_t con_end);
76 76
77#define DEFAULT_CERT_TYPE MHD_GNUTLS_CRT_X509 77#define DEFAULT_CERT_TYPE MHD_GNUTLS_CRT_X509
diff --git a/src/daemon/https/tls/gnutls_str.c b/src/daemon/https/tls/gnutls_str.c
index 38f04738..4fc4174b 100644
--- a/src/daemon/https/tls/gnutls_str.c
+++ b/src/daemon/https/tls/gnutls_str.c
@@ -34,7 +34,7 @@
34 * They should be used only with null terminated strings. 34 * They should be used only with null terminated strings.
35 */ 35 */
36void 36void
37mhd_gtls_str_cat (char *dest, size_t dest_tot_size, const char *src) 37MHD_gtls_str_cat (char *dest, size_t dest_tot_size, const char *src)
38{ 38{
39 size_t str_size = strlen (src); 39 size_t str_size = strlen (src);
40 size_t dest_size = strlen (dest); 40 size_t dest_size = strlen (dest);
@@ -54,7 +54,7 @@ mhd_gtls_str_cat (char *dest, size_t dest_tot_size, const char *src)
54} 54}
55 55
56void 56void
57mhd_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src) 57MHD_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src)
58{ 58{
59 size_t str_size = strlen (src); 59 size_t str_size = strlen (src);
60 60
@@ -73,7 +73,7 @@ mhd_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src)
73} 73}
74 74
75void 75void
76mhd_gtls_mem_cpy (char *dest, 76MHD_gtls_mem_cpy (char *dest,
77 size_t dest_tot_size, const char *src, size_t src_size) 77 size_t dest_tot_size, const char *src, size_t src_size)
78{ 78{
79 79
@@ -91,10 +91,10 @@ mhd_gtls_mem_cpy (char *dest,
91} 91}
92 92
93void 93void
94mhd_gtls_string_init (mhd_gtls_string * str, 94MHD_gtls_string_init (MHD_gtls_string * str,
95 gnutls_alloc_function alloc_func, 95 MHD_gnutls_alloc_function alloc_func,
96 gnutls_realloc_function realloc_func, 96 MHD_gnutls_realloc_function realloc_func,
97 gnutls_free_function free_func) 97 MHD_gnutls_free_function free_func)
98{ 98{
99 str->data = NULL; 99 str->data = NULL;
100 str->max_length = 0; 100 str->max_length = 0;
@@ -106,7 +106,7 @@ mhd_gtls_string_init (mhd_gtls_string * str,
106} 106}
107 107
108void 108void
109mhd_gtls_string_clear (mhd_gtls_string * str) 109MHD_gtls_string_clear (MHD_gtls_string * str)
110{ 110{
111 if (str == NULL || str->data == NULL) 111 if (str == NULL || str->data == NULL)
112 return; 112 return;
@@ -119,10 +119,10 @@ mhd_gtls_string_clear (mhd_gtls_string * str)
119 119
120/* This one does not copy the string. 120/* This one does not copy the string.
121 */ 121 */
122gnutls_datum_t 122MHD_gnutls_datum_t
123mhd_gtls_string2datum (mhd_gtls_string * str) 123MHD_gtls_string2datum (MHD_gtls_string * str)
124{ 124{
125 gnutls_datum_t ret; 125 MHD_gnutls_datum_t ret;
126 126
127 ret.data = str->data; 127 ret.data = str->data;
128 ret.size = str->length; 128 ret.size = str->length;
@@ -133,7 +133,7 @@ mhd_gtls_string2datum (mhd_gtls_string * str)
133#define MIN_CHUNK 256 133#define MIN_CHUNK 256
134 134
135int 135int
136mhd_gtls_string_copy_str (mhd_gtls_string * dest, const char *src) 136MHD_gtls_string_copy_str (MHD_gtls_string * dest, const char *src)
137{ 137{
138 size_t src_len = strlen (src); 138 size_t src_len = strlen (src);
139 size_t max; 139 size_t max;
@@ -150,7 +150,7 @@ mhd_gtls_string_copy_str (mhd_gtls_string * dest, const char *src)
150 dest->data = dest->realloc_func (dest->data, max); 150 dest->data = dest->realloc_func (dest->data, max);
151 if (dest->data == NULL) 151 if (dest->data == NULL)
152 { 152 {
153 gnutls_assert (); 153 MHD_gnutls_assert ();
154 return GNUTLS_E_MEMORY_ERROR; 154 return GNUTLS_E_MEMORY_ERROR;
155 } 155 }
156 dest->max_length = MAX (MIN_CHUNK, src_len); 156 dest->max_length = MAX (MIN_CHUNK, src_len);
@@ -163,7 +163,7 @@ mhd_gtls_string_copy_str (mhd_gtls_string * dest, const char *src)
163} 163}
164 164
165int 165int
166mhd_gtls_string_append_str (mhd_gtls_string * dest, const char *src) 166MHD_gtls_string_append_str (MHD_gtls_string * dest, const char *src)
167{ 167{
168 size_t src_len = strlen (src); 168 size_t src_len = strlen (src);
169 size_t tot_len = src_len + dest->length; 169 size_t tot_len = src_len + dest->length;
@@ -183,7 +183,7 @@ mhd_gtls_string_append_str (mhd_gtls_string * dest, const char *src)
183 dest->data = dest->realloc_func (dest->data, new_len); 183 dest->data = dest->realloc_func (dest->data, new_len);
184 if (dest->data == NULL) 184 if (dest->data == NULL)
185 { 185 {
186 gnutls_assert (); 186 MHD_gnutls_assert ();
187 return GNUTLS_E_MEMORY_ERROR; 187 return GNUTLS_E_MEMORY_ERROR;
188 } 188 }
189 dest->max_length = new_len; 189 dest->max_length = new_len;
@@ -196,7 +196,7 @@ mhd_gtls_string_append_str (mhd_gtls_string * dest, const char *src)
196} 196}
197 197
198int 198int
199mhd_gtls_string_append_data (mhd_gtls_string * dest, 199MHD_gtls_string_append_data (MHD_gtls_string * dest,
200 const void *data, size_t data_size) 200 const void *data, size_t data_size)
201{ 201{
202 size_t tot_len = data_size + dest->length; 202 size_t tot_len = data_size + dest->length;
@@ -215,7 +215,7 @@ mhd_gtls_string_append_data (mhd_gtls_string * dest,
215 dest->data = dest->realloc_func (dest->data, new_len); 215 dest->data = dest->realloc_func (dest->data, new_len);
216 if (dest->data == NULL) 216 if (dest->data == NULL)
217 { 217 {
218 gnutls_assert (); 218 MHD_gnutls_assert ();
219 return GNUTLS_E_MEMORY_ERROR; 219 return GNUTLS_E_MEMORY_ERROR;
220 } 220 }
221 dest->max_length = new_len; 221 dest->max_length = new_len;
@@ -233,7 +233,7 @@ mhd_gtls_string_append_data (mhd_gtls_string * dest,
233 * truncated hex string is returned (always null terminated). 233 * truncated hex string is returned (always null terminated).
234 */ 234 */
235char * 235char *
236mhd_gtls_bin2hex (const void *_old, 236MHD_gtls_bin2hex (const void *_old,
237 size_t oldlen, char *buffer, size_t buffer_size) 237 size_t oldlen, char *buffer, size_t buffer_size)
238{ 238{
239 unsigned int i, j; 239 unsigned int i, j;
@@ -252,7 +252,7 @@ mhd_gtls_bin2hex (const void *_old,
252/* just a hex2bin function. 252/* just a hex2bin function.
253 */ 253 */
254int 254int
255mhd_gtls_hex2bin (const opaque * hex_data, 255MHD_gtls_hex2bin (const opaque * hex_data,
256 int hex_size, opaque * bin_data, size_t * bin_size) 256 int hex_size, opaque * bin_data, size_t * bin_size)
257{ 257{
258 int i, j; 258 int i, j;
@@ -265,7 +265,7 @@ mhd_gtls_hex2bin (const opaque * hex_data,
265 265
266 if (*bin_size < (size_t) hex_size) 266 if (*bin_size < (size_t) hex_size)
267 { 267 {
268 gnutls_assert (); 268 MHD_gnutls_assert ();
269 return GNUTLS_E_SHORT_MEMORY_BUFFER; 269 return GNUTLS_E_SHORT_MEMORY_BUFFER;
270 } 270 }
271 271
@@ -277,7 +277,7 @@ mhd_gtls_hex2bin (const opaque * hex_data,
277 val = strtoul ((char *) hex2_data, NULL, 16); 277 val = strtoul ((char *) hex2_data, NULL, 16);
278 if (val == ULONG_MAX) 278 if (val == ULONG_MAX)
279 { 279 {
280 gnutls_assert (); 280 MHD_gnutls_assert ();
281 return GNUTLS_E_SRP_PWD_PARSING_ERROR; 281 return GNUTLS_E_SRP_PWD_PARSING_ERROR;
282 } 282 }
283 bin_data[j] = val; 283 bin_data[j] = val;
diff --git a/src/daemon/https/tls/gnutls_str.h b/src/daemon/https/tls/gnutls_str.h
index ead7ba2a..bedee1df 100644
--- a/src/daemon/https/tls/gnutls_str.h
+++ b/src/daemon/https/tls/gnutls_str.h
@@ -27,37 +27,37 @@
27 27
28#include <gnutls_int.h> 28#include <gnutls_int.h>
29 29
30void mhd_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src); 30void MHD_gtls_str_cpy (char *dest, size_t dest_tot_size, const char *src);
31void mhd_gtls_mem_cpy (char *dest, size_t dest_tot_size, const char *src, 31void MHD_gtls_mem_cpy (char *dest, size_t dest_tot_size, const char *src,
32 size_t src_size); 32 size_t src_size);
33void mhd_gtls_str_cat (char *dest, size_t dest_tot_size, const char *src); 33void MHD_gtls_str_cat (char *dest, size_t dest_tot_size, const char *src);
34 34
35typedef struct 35typedef struct
36{ 36{
37 opaque *data; 37 opaque *data;
38 size_t max_length; 38 size_t max_length;
39 size_t length; 39 size_t length;
40 gnutls_realloc_function realloc_func; 40 MHD_gnutls_realloc_function realloc_func;
41 gnutls_alloc_function alloc_func; 41 MHD_gnutls_alloc_function alloc_func;
42 gnutls_free_function free_func; 42 MHD_gnutls_free_function free_func;
43} mhd_gtls_string; 43} MHD_gtls_string;
44 44
45void mhd_gtls_string_init (mhd_gtls_string *, gnutls_alloc_function, 45void MHD_gtls_string_init (MHD_gtls_string *, MHD_gnutls_alloc_function,
46 gnutls_realloc_function, gnutls_free_function); 46 MHD_gnutls_realloc_function, MHD_gnutls_free_function);
47void mhd_gtls_string_clear (mhd_gtls_string *); 47void MHD_gtls_string_clear (MHD_gtls_string *);
48 48
49/* Beware, do not clear the string, after calling this 49/* Beware, do not clear the string, after calling this
50 * function 50 * function
51 */ 51 */
52gnutls_datum_t mhd_gtls_string2datum (mhd_gtls_string * str); 52MHD_gnutls_datum_t MHD_gtls_string2datum (MHD_gtls_string * str);
53 53
54int mhd_gtls_string_copy_str (mhd_gtls_string * dest, const char *src); 54int MHD_gtls_string_copy_str (MHD_gtls_string * dest, const char *src);
55int mhd_gtls_string_append_str (mhd_gtls_string *, const char *str); 55int MHD_gtls_string_append_str (MHD_gtls_string *, const char *str);
56int mhd_gtls_string_append_data (mhd_gtls_string *, const void *data, 56int MHD_gtls_string_append_data (MHD_gtls_string *, const void *data,
57 size_t data_size); 57 size_t data_size);
58char *mhd_gtls_bin2hex (const void *old, size_t oldlen, char *buffer, 58char *MHD_gtls_bin2hex (const void *old, size_t oldlen, char *buffer,
59 size_t buffer_size); 59 size_t buffer_size);
60int mhd_gtls_hex2bin (const opaque * hex_data, int hex_size, 60int MHD_gtls_hex2bin (const opaque * hex_data, int hex_size,
61 opaque * bin_data, size_t * bin_size); 61 opaque * bin_data, size_t * bin_size);
62 62
63#endif 63#endif
diff --git a/src/daemon/https/tls/gnutls_supplemental.c b/src/daemon/https/tls/gnutls_supplemental.c
index 997da8a1..7b265031 100644
--- a/src/daemon/https/tls/gnutls_supplemental.c
+++ b/src/daemon/https/tls/gnutls_supplemental.c
@@ -25,13 +25,13 @@
25/* This file contains support functions for 'TLS Handshake Message for 25/* This file contains support functions for 'TLS Handshake Message for
26 * Supplemental Data' (RFC 4680). 26 * Supplemental Data' (RFC 4680).
27 * 27 *
28 * The idea here is simple. MHD_gnutls_handshake() in gnuts_handshake.c 28 * The idea here is simple. MHD__gnutls_handshake() in gnuts_handshake.c
29 * will call _gnutls_gen_supplemental and _gnutls_parse_supplemental 29 * will call MHD__gnutls_gen_supplemental and MHD__gnutls_parse_supplemental
30 * when some extension requested that supplemental data be sent or 30 * when some extension requested that supplemental data be sent or
31 * received. Extension request this by setting the flags 31 * received. Extension request this by setting the flags
32 * do_recv_supplemental or do_send_supplemental in the session. 32 * do_recv_supplemental or do_send_supplemental in the session.
33 * 33 *
34 * The functions in this file iterate through the _gnutls_supplemental 34 * The functions in this file iterate through the MHD__gnutls_supplemental
35 * array, and calls the send/recv functions for each respective data 35 * array, and calls the send/recv functions for each respective data
36 * type. 36 * type.
37 * 37 *
@@ -50,29 +50,29 @@
50#include "gnutls_errors.h" 50#include "gnutls_errors.h"
51#include "gnutls_num.h" 51#include "gnutls_num.h"
52 52
53typedef int (*supp_recv_func) (mhd_gtls_session_t session, 53typedef int (*supp_recv_func) (MHD_gtls_session_t session,
54 const opaque * data, size_t data_size); 54 const opaque * data, size_t data_size);
55typedef int (*supp_send_func) (mhd_gtls_session_t session, 55typedef int (*supp_send_func) (MHD_gtls_session_t session,
56 mhd_gtls_buffer * buf); 56 MHD_gtls_buffer * buf);
57 57
58typedef struct 58typedef struct
59{ 59{
60 const char *name; 60 const char *name;
61 gnutls_supplemental_data_format_type_t type; 61 MHD_gnutls_supplemental_data_format_type_t type;
62 supp_recv_func supp_recv_func; 62 supp_recv_func supp_recv_func;
63 supp_send_func supp_send_func; 63 supp_send_func supp_send_func;
64} gnutls_supplemental_entry; 64} MHD_gnutls_supplemental_entry;
65 65
66gnutls_supplemental_entry _gnutls_supplemental[] = { 66MHD_gnutls_supplemental_entry MHD__gnutls_supplemental[] = {
67 {0, 0, 0, 0} 67 {0, 0, 0, 0}
68}; 68};
69 69
70const char * 70const char *
71MHD_gtls_supplemental_get_name (gnutls_supplemental_data_format_type_t type) 71MHD_gtls_supplemental_get_name (MHD_gnutls_supplemental_data_format_type_t type)
72{ 72{
73 gnutls_supplemental_entry *p; 73 MHD_gnutls_supplemental_entry *p;
74 74
75 for (p = _gnutls_supplemental; p->name != NULL; p++) 75 for (p = MHD__gnutls_supplemental; p->name != NULL; p++)
76 if (p->type == type) 76 if (p->type == type)
77 return p->name; 77 return p->name;
78 78
@@ -80,11 +80,11 @@ MHD_gtls_supplemental_get_name (gnutls_supplemental_data_format_type_t type)
80} 80}
81 81
82static supp_recv_func 82static supp_recv_func
83get_supp_func_recv (gnutls_supplemental_data_format_type_t type) 83get_supp_func_recv (MHD_gnutls_supplemental_data_format_type_t type)
84{ 84{
85 gnutls_supplemental_entry *p; 85 MHD_gnutls_supplemental_entry *p;
86 86
87 for (p = _gnutls_supplemental; p->name != NULL; p++) 87 for (p = MHD__gnutls_supplemental; p->name != NULL; p++)
88 if (p->type == type) 88 if (p->type == type)
89 return p->supp_recv_func; 89 return p->supp_recv_func;
90 90
@@ -92,37 +92,37 @@ get_supp_func_recv (gnutls_supplemental_data_format_type_t type)
92} 92}
93 93
94int 94int
95_gnutls_gen_supplemental (mhd_gtls_session_t session, mhd_gtls_buffer * buf) 95MHD__gnutls_gen_supplemental (MHD_gtls_session_t session, MHD_gtls_buffer * buf)
96{ 96{
97 gnutls_supplemental_entry *p; 97 MHD_gnutls_supplemental_entry *p;
98 int ret; 98 int ret;
99 99
100 /* Make room for 3 byte length field. */ 100 /* Make room for 3 byte length field. */
101 ret = mhd_gtls_buffer_append (buf, "\0\0\0", 3); 101 ret = MHD_gtls_buffer_append (buf, "\0\0\0", 3);
102 if (ret < 0) 102 if (ret < 0)
103 { 103 {
104 gnutls_assert (); 104 MHD_gnutls_assert ();
105 return ret; 105 return ret;
106 } 106 }
107 107
108 for (p = _gnutls_supplemental; p->name; p++) 108 for (p = MHD__gnutls_supplemental; p->name; p++)
109 { 109 {
110 supp_send_func supp_send = p->supp_send_func; 110 supp_send_func supp_send = p->supp_send_func;
111 size_t sizepos = buf->length; 111 size_t sizepos = buf->length;
112 int ret; 112 int ret;
113 113
114 /* Make room for supplement type and length byte length field. */ 114 /* Make room for supplement type and length byte length field. */
115 ret = mhd_gtls_buffer_append (buf, "\0\0\0\0", 4); 115 ret = MHD_gtls_buffer_append (buf, "\0\0\0\0", 4);
116 if (ret < 0) 116 if (ret < 0)
117 { 117 {
118 gnutls_assert (); 118 MHD_gnutls_assert ();
119 return ret; 119 return ret;
120 } 120 }
121 121
122 ret = supp_send (session, buf); 122 ret = supp_send (session, buf);
123 if (ret < 0) 123 if (ret < 0)
124 { 124 {
125 gnutls_assert (); 125 MHD_gnutls_assert ();
126 return ret; 126 return ret;
127 } 127 }
128 128
@@ -142,14 +142,14 @@ _gnutls_gen_supplemental (mhd_gtls_session_t session, mhd_gtls_buffer * buf)
142 buf->data[1] = ((buf->length - 3) >> 8) & 0xFF; 142 buf->data[1] = ((buf->length - 3) >> 8) & 0xFF;
143 buf->data[2] = (buf->length - 3) & 0xFF; 143 buf->data[2] = (buf->length - 3) & 0xFF;
144 144
145 _gnutls_debug_log ("EXT[%x]: Sending %d bytes of supplemental data\n", 145 MHD__gnutls_debug_log ("EXT[%x]: Sending %d bytes of supplemental data\n",
146 session, buf->length); 146 session, buf->length);
147 147
148 return buf->length; 148 return buf->length;
149} 149}
150 150
151int 151int
152_gnutls_parse_supplemental (mhd_gtls_session_t session, 152MHD__gnutls_parse_supplemental (MHD_gtls_session_t session,
153 const uint8_t * data, int datalen) 153 const uint8_t * data, int datalen)
154{ 154{
155 const opaque *p = data; 155 const opaque *p = data;
@@ -157,12 +157,12 @@ _gnutls_parse_supplemental (mhd_gtls_session_t session,
157 size_t total_size; 157 size_t total_size;
158 158
159 DECR_LEN (dsize, 3); 159 DECR_LEN (dsize, 3);
160 total_size = mhd_gtls_read_uint24 (p); 160 total_size = MHD_gtls_read_uint24 (p);
161 p += 3; 161 p += 3;
162 162
163 if (dsize != total_size) 163 if (dsize != total_size)
164 { 164 {
165 gnutls_assert (); 165 MHD_gnutls_assert ();
166 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; 166 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
167 } 167 }
168 168
@@ -173,14 +173,14 @@ _gnutls_parse_supplemental (mhd_gtls_session_t session,
173 supp_recv_func recv_func; 173 supp_recv_func recv_func;
174 174
175 DECR_LEN (dsize, 2); 175 DECR_LEN (dsize, 2);
176 supp_data_type = mhd_gtls_read_uint16 (p); 176 supp_data_type = MHD_gtls_read_uint16 (p);
177 p += 2; 177 p += 2;
178 178
179 DECR_LEN (dsize, 2); 179 DECR_LEN (dsize, 2);
180 supp_data_length = mhd_gtls_read_uint16 (p); 180 supp_data_length = MHD_gtls_read_uint16 (p);
181 p += 2; 181 p += 2;
182 182
183 _gnutls_debug_log ("EXT[%x]: Got supplemental type=%02x length=%d\n", 183 MHD__gnutls_debug_log ("EXT[%x]: Got supplemental type=%02x length=%d\n",
184 session, supp_data_type, supp_data_length); 184 session, supp_data_type, supp_data_length);
185 185
186 recv_func = get_supp_func_recv (supp_data_type); 186 recv_func = get_supp_func_recv (supp_data_type);
@@ -189,13 +189,13 @@ _gnutls_parse_supplemental (mhd_gtls_session_t session,
189 int ret = recv_func (session, p, supp_data_length); 189 int ret = recv_func (session, p, supp_data_length);
190 if (ret < 0) 190 if (ret < 0)
191 { 191 {
192 gnutls_assert (); 192 MHD_gnutls_assert ();
193 return ret; 193 return ret;
194 } 194 }
195 } 195 }
196 else 196 else
197 { 197 {
198 gnutls_assert (); 198 MHD_gnutls_assert ();
199 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; 199 return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER;
200 } 200 }
201 201
diff --git a/src/daemon/https/tls/gnutls_supplemental.h b/src/daemon/https/tls/gnutls_supplemental.h
index eaccfe74..a215ab56 100644
--- a/src/daemon/https/tls/gnutls_supplemental.h
+++ b/src/daemon/https/tls/gnutls_supplemental.h
@@ -24,7 +24,7 @@
24 24
25#include <gnutls_int.h> 25#include <gnutls_int.h>
26 26
27int _gnutls_parse_supplemental (mhd_gtls_session_t session, 27int MHD__gnutls_parse_supplemental (MHD_gtls_session_t session,
28 const uint8_t * data, int data_size); 28 const uint8_t * data, int data_size);
29int _gnutls_gen_supplemental (mhd_gtls_session_t session, 29int MHD__gnutls_gen_supplemental (MHD_gtls_session_t session,
30 mhd_gtls_buffer * buf); 30 MHD_gtls_buffer * buf);
diff --git a/src/daemon/https/tls/gnutls_ui.c b/src/daemon/https/tls/gnutls_ui.c
index b211a175..7709b2b7 100644
--- a/src/daemon/https/tls/gnutls_ui.c
+++ b/src/daemon/https/tls/gnutls_ui.c
@@ -37,8 +37,8 @@
37/* ANON & DHE */ 37/* ANON & DHE */
38 38
39/** 39/**
40 * MHD_gnutls_dh_set_prime_bits - Used to set the bits for a DH ciphersuite 40 * MHD__gnutls_dh_set_prime_bits - Used to set the bits for a DH ciphersuite
41 * @session: is a #mhd_gtls_session_t structure. 41 * @session: is a #MHD_gtls_session_t structure.
42 * @bits: is the number of bits 42 * @bits: is the number of bits
43 * 43 *
44 * This function sets the number of bits, for use in an 44 * This function sets the number of bits, for use in an
@@ -53,13 +53,13 @@
53 * 53 *
54 **/ 54 **/
55void 55void
56MHD_gnutls_dh_set_prime_bits (mhd_gtls_session_t session, unsigned int bits) 56MHD__gnutls_dh_set_prime_bits (MHD_gtls_session_t session, unsigned int bits)
57{ 57{
58 session->internals.dh_prime_bits = bits; 58 session->internals.dh_prime_bits = bits;
59} 59}
60 60
61/** 61/**
62 * MHD_gnutls_dh_get_group - This function returns the group of the DH authentication 62 * MHD__gnutls_dh_get_group - This function returns the group of the DH authentication
63 * @session: is a gnutls session 63 * @session: is a gnutls session
64 * @raw_gen: will hold the generator. 64 * @raw_gen: will hold the generator.
65 * @raw_prime: will hold the prime. 65 * @raw_prime: will hold the prime.
@@ -67,16 +67,16 @@ MHD_gnutls_dh_set_prime_bits (mhd_gtls_session_t session, unsigned int bits)
67 * This function will return the group parameters used in the last Diffie Hellman 67 * This function will return the group parameters used in the last Diffie Hellman
68 * authentication with the peer. These are the prime and the generator used. 68 * authentication with the peer. These are the prime and the generator used.
69 * This function should be used for both anonymous and ephemeral diffie Hellman. 69 * This function should be used for both anonymous and ephemeral diffie Hellman.
70 * The output parameters must be freed with gnutls_free(). 70 * The output parameters must be freed with MHD_gnutls_free().
71 * 71 *
72 * Returns a negative value in case of an error. 72 * Returns a negative value in case of an error.
73 * 73 *
74 **/ 74 **/
75int 75int
76MHD_gnutls_dh_get_group (mhd_gtls_session_t session, 76MHD__gnutls_dh_get_group (MHD_gtls_session_t session,
77 gnutls_datum_t * raw_gen, gnutls_datum_t * raw_prime) 77 MHD_gnutls_datum_t * raw_gen, MHD_gnutls_datum_t * raw_prime)
78{ 78{
79 mhd_gtls_dh_info_st *dh; 79 MHD_gtls_dh_info_st *dh;
80 int ret; 80 int ret;
81 mhd_anon_auth_info_t anon_info; 81 mhd_anon_auth_info_t anon_info;
82 cert_auth_info_t cert_info; 82 cert_auth_info_t cert_info;
@@ -84,34 +84,34 @@ MHD_gnutls_dh_get_group (mhd_gtls_session_t session,
84 switch (MHD_gtls_auth_get_type (session)) 84 switch (MHD_gtls_auth_get_type (session))
85 { 85 {
86 case MHD_GNUTLS_CRD_ANON: 86 case MHD_GNUTLS_CRD_ANON:
87 anon_info = mhd_gtls_get_auth_info (session); 87 anon_info = MHD_gtls_get_auth_info (session);
88 if (anon_info == NULL) 88 if (anon_info == NULL)
89 return GNUTLS_E_INTERNAL_ERROR; 89 return GNUTLS_E_INTERNAL_ERROR;
90 dh = &anon_info->dh; 90 dh = &anon_info->dh;
91 break; 91 break;
92 case MHD_GNUTLS_CRD_CERTIFICATE: 92 case MHD_GNUTLS_CRD_CERTIFICATE:
93 cert_info = mhd_gtls_get_auth_info (session); 93 cert_info = MHD_gtls_get_auth_info (session);
94 if (cert_info == NULL) 94 if (cert_info == NULL)
95 return GNUTLS_E_INTERNAL_ERROR; 95 return GNUTLS_E_INTERNAL_ERROR;
96 dh = &cert_info->dh; 96 dh = &cert_info->dh;
97 break; 97 break;
98 default: 98 default:
99 gnutls_assert (); 99 MHD_gnutls_assert ();
100 return GNUTLS_E_INVALID_REQUEST; 100 return GNUTLS_E_INVALID_REQUEST;
101 } 101 }
102 102
103 ret = _gnutls_set_datum (raw_prime, dh->prime.data, dh->prime.size); 103 ret = MHD__gnutls_set_datum (raw_prime, dh->prime.data, dh->prime.size);
104 if (ret < 0) 104 if (ret < 0)
105 { 105 {
106 gnutls_assert (); 106 MHD_gnutls_assert ();
107 return ret; 107 return ret;
108 } 108 }
109 109
110 ret = _gnutls_set_datum (raw_gen, dh->generator.data, dh->generator.size); 110 ret = MHD__gnutls_set_datum (raw_gen, dh->generator.data, dh->generator.size);
111 if (ret < 0) 111 if (ret < 0)
112 { 112 {
113 gnutls_assert (); 113 MHD_gnutls_assert ();
114 _gnutls_free_datum (raw_prime); 114 MHD__gnutls_free_datum (raw_prime);
115 return ret; 115 return ret;
116 } 116 }
117 117
@@ -119,22 +119,22 @@ MHD_gnutls_dh_get_group (mhd_gtls_session_t session,
119} 119}
120 120
121/** 121/**
122 * MHD_gnutls_dh_get_pubkey - This function returns the peer's public key used in DH authentication 122 * MHD__gnutls_dh_get_pubkey - This function returns the peer's public key used in DH authentication
123 * @session: is a gnutls session 123 * @session: is a gnutls session
124 * @raw_key: will hold the public key. 124 * @raw_key: will hold the public key.
125 * 125 *
126 * This function will return the peer's public key used in the last Diffie Hellman authentication. 126 * This function will return the peer's public key used in the last Diffie Hellman authentication.
127 * This function should be used for both anonymous and ephemeral diffie Hellman. 127 * This function should be used for both anonymous and ephemeral diffie Hellman.
128 * The output parameters must be freed with gnutls_free(). 128 * The output parameters must be freed with MHD_gnutls_free().
129 * 129 *
130 * Returns a negative value in case of an error. 130 * Returns a negative value in case of an error.
131 * 131 *
132 **/ 132 **/
133int 133int
134MHD_gnutls_dh_get_pubkey (mhd_gtls_session_t session, 134MHD__gnutls_dh_get_pubkey (MHD_gtls_session_t session,
135 gnutls_datum_t * raw_key) 135 MHD_gnutls_datum_t * raw_key)
136{ 136{
137 mhd_gtls_dh_info_st *dh; 137 MHD_gtls_dh_info_st *dh;
138 mhd_anon_auth_info_t anon_info; 138 mhd_anon_auth_info_t anon_info;
139 cert_auth_info_t cert_info; 139 cert_auth_info_t cert_info;
140 cert_auth_info_t psk_info; 140 cert_auth_info_t psk_info;
@@ -143,7 +143,7 @@ MHD_gnutls_dh_get_pubkey (mhd_gtls_session_t session,
143 { 143 {
144 case MHD_GNUTLS_CRD_ANON: 144 case MHD_GNUTLS_CRD_ANON:
145 { 145 {
146 anon_info = mhd_gtls_get_auth_info (session); 146 anon_info = MHD_gtls_get_auth_info (session);
147 if (anon_info == NULL) 147 if (anon_info == NULL)
148 return GNUTLS_E_INTERNAL_ERROR; 148 return GNUTLS_E_INTERNAL_ERROR;
149 dh = &anon_info->dh; 149 dh = &anon_info->dh;
@@ -151,7 +151,7 @@ MHD_gnutls_dh_get_pubkey (mhd_gtls_session_t session,
151 } 151 }
152 case MHD_GNUTLS_CRD_PSK: 152 case MHD_GNUTLS_CRD_PSK:
153 { 153 {
154 psk_info = mhd_gtls_get_auth_info (session); 154 psk_info = MHD_gtls_get_auth_info (session);
155 if (psk_info == NULL) 155 if (psk_info == NULL)
156 return GNUTLS_E_INTERNAL_ERROR; 156 return GNUTLS_E_INTERNAL_ERROR;
157 dh = &psk_info->dh; 157 dh = &psk_info->dh;
@@ -160,18 +160,18 @@ MHD_gnutls_dh_get_pubkey (mhd_gtls_session_t session,
160 case MHD_GNUTLS_CRD_CERTIFICATE: 160 case MHD_GNUTLS_CRD_CERTIFICATE:
161 { 161 {
162 162
163 cert_info = mhd_gtls_get_auth_info (session); 163 cert_info = MHD_gtls_get_auth_info (session);
164 if (cert_info == NULL) 164 if (cert_info == NULL)
165 return GNUTLS_E_INTERNAL_ERROR; 165 return GNUTLS_E_INTERNAL_ERROR;
166 dh = &cert_info->dh; 166 dh = &cert_info->dh;
167 break; 167 break;
168 } 168 }
169 default: 169 default:
170 gnutls_assert (); 170 MHD_gnutls_assert ();
171 return GNUTLS_E_INVALID_REQUEST; 171 return GNUTLS_E_INVALID_REQUEST;
172 } 172 }
173 173
174 return _gnutls_set_datum (raw_key, dh->public_key.data, 174 return MHD__gnutls_set_datum (raw_key, dh->public_key.data,
175 dh->public_key.size); 175 dh->public_key.size);
176} 176}
177 177
@@ -183,39 +183,39 @@ MHD_gnutls_dh_get_pubkey (mhd_gtls_session_t session,
183 * 183 *
184 * This function will return the peer's public key exponent and 184 * This function will return the peer's public key exponent and
185 * modulus used in the last RSA-EXPORT authentication. The output 185 * modulus used in the last RSA-EXPORT authentication. The output
186 * parameters must be freed with gnutls_free(). 186 * parameters must be freed with MHD_gnutls_free().
187 * 187 *
188 * Returns a negative value in case of an error. 188 * Returns a negative value in case of an error.
189 * 189 *
190 **/ 190 **/
191int 191int
192MHD_gtls_rsa_export_get_pubkey (mhd_gtls_session_t session, 192MHD_gtls_rsa_export_get_pubkey (MHD_gtls_session_t session,
193 gnutls_datum_t * exponent, 193 MHD_gnutls_datum_t * exponent,
194 gnutls_datum_t * modulus) 194 MHD_gnutls_datum_t * modulus)
195{ 195{
196 cert_auth_info_t info; 196 cert_auth_info_t info;
197 int ret; 197 int ret;
198 198
199 if (MHD_gtls_auth_get_type (session) == MHD_GNUTLS_CRD_CERTIFICATE) 199 if (MHD_gtls_auth_get_type (session) == MHD_GNUTLS_CRD_CERTIFICATE)
200 { 200 {
201 info = mhd_gtls_get_auth_info (session); 201 info = MHD_gtls_get_auth_info (session);
202 if (info == NULL) 202 if (info == NULL)
203 return GNUTLS_E_INTERNAL_ERROR; 203 return GNUTLS_E_INTERNAL_ERROR;
204 204
205 ret = _gnutls_set_datum (modulus, info->rsa_export.modulus.data, 205 ret = MHD__gnutls_set_datum (modulus, info->rsa_export.modulus.data,
206 info->rsa_export.modulus.size); 206 info->rsa_export.modulus.size);
207 if (ret < 0) 207 if (ret < 0)
208 { 208 {
209 gnutls_assert (); 209 MHD_gnutls_assert ();
210 return ret; 210 return ret;
211 } 211 }
212 212
213 ret = _gnutls_set_datum (exponent, info->rsa_export.exponent.data, 213 ret = MHD__gnutls_set_datum (exponent, info->rsa_export.exponent.data,
214 info->rsa_export.exponent.size); 214 info->rsa_export.exponent.size);
215 if (ret < 0) 215 if (ret < 0)
216 { 216 {
217 gnutls_assert (); 217 MHD_gnutls_assert ();
218 _gnutls_free_datum (modulus); 218 MHD__gnutls_free_datum (modulus);
219 return ret; 219 return ret;
220 } 220 }
221 221
@@ -226,7 +226,7 @@ MHD_gtls_rsa_export_get_pubkey (mhd_gtls_session_t session,
226} 226}
227 227
228/** 228/**
229 * MHD_gnutls_dh_get_secret_bits - This function returns the bits used in DH authentication 229 * MHD__gnutls_dh_get_secret_bits - This function returns the bits used in DH authentication
230 * @session: is a gnutls session 230 * @session: is a gnutls session
231 * 231 *
232 * This function will return the bits used in the last Diffie Hellman authentication 232 * This function will return the bits used in the last Diffie Hellman authentication
@@ -235,7 +235,7 @@ MHD_gtls_rsa_export_get_pubkey (mhd_gtls_session_t session,
235 * 235 *
236 **/ 236 **/
237int 237int
238MHD_gnutls_dh_get_secret_bits (mhd_gtls_session_t session) 238MHD__gnutls_dh_get_secret_bits (MHD_gtls_session_t session)
239{ 239{
240 switch (MHD_gtls_auth_get_type (session)) 240 switch (MHD_gtls_auth_get_type (session))
241 { 241 {
@@ -243,7 +243,7 @@ MHD_gnutls_dh_get_secret_bits (mhd_gtls_session_t session)
243 { 243 {
244 mhd_anon_auth_info_t info; 244 mhd_anon_auth_info_t info;
245 245
246 info = mhd_gtls_get_auth_info (session); 246 info = MHD_gtls_get_auth_info (session);
247 if (info == NULL) 247 if (info == NULL)
248 return GNUTLS_E_INTERNAL_ERROR; 248 return GNUTLS_E_INTERNAL_ERROR;
249 return info->dh.secret_bits; 249 return info->dh.secret_bits;
@@ -252,20 +252,20 @@ MHD_gnutls_dh_get_secret_bits (mhd_gtls_session_t session)
252 { 252 {
253 cert_auth_info_t info; 253 cert_auth_info_t info;
254 254
255 info = mhd_gtls_get_auth_info (session); 255 info = MHD_gtls_get_auth_info (session);
256 if (info == NULL) 256 if (info == NULL)
257 return GNUTLS_E_INTERNAL_ERROR; 257 return GNUTLS_E_INTERNAL_ERROR;
258 258
259 return info->dh.secret_bits; 259 return info->dh.secret_bits;
260 } 260 }
261 default: 261 default:
262 gnutls_assert (); 262 MHD_gnutls_assert ();
263 return GNUTLS_E_INVALID_REQUEST; 263 return GNUTLS_E_INVALID_REQUEST;
264 } 264 }
265} 265}
266 266
267/** 267/**
268 * MHD_gnutls_dh_get_prime_bits - This function returns the bits used in DH authentication 268 * MHD__gnutls_dh_get_prime_bits - This function returns the bits used in DH authentication
269 * @session: is a gnutls session 269 * @session: is a gnutls session
270 * 270 *
271 * This function will return the bits of the prime used in the last Diffie Hellman authentication 271 * This function will return the bits of the prime used in the last Diffie Hellman authentication
@@ -274,9 +274,9 @@ MHD_gnutls_dh_get_secret_bits (mhd_gtls_session_t session)
274 * 274 *
275 **/ 275 **/
276int 276int
277MHD_gnutls_dh_get_prime_bits (mhd_gtls_session_t session) 277MHD__gnutls_dh_get_prime_bits (MHD_gtls_session_t session)
278{ 278{
279 mhd_gtls_dh_info_st *dh; 279 MHD_gtls_dh_info_st *dh;
280 280
281 switch (MHD_gtls_auth_get_type (session)) 281 switch (MHD_gtls_auth_get_type (session))
282 { 282 {
@@ -284,7 +284,7 @@ MHD_gnutls_dh_get_prime_bits (mhd_gtls_session_t session)
284 { 284 {
285 mhd_anon_auth_info_t info; 285 mhd_anon_auth_info_t info;
286 286
287 info = mhd_gtls_get_auth_info (session); 287 info = MHD_gtls_get_auth_info (session);
288 if (info == NULL) 288 if (info == NULL)
289 return GNUTLS_E_INTERNAL_ERROR; 289 return GNUTLS_E_INTERNAL_ERROR;
290 dh = &info->dh; 290 dh = &info->dh;
@@ -294,7 +294,7 @@ MHD_gnutls_dh_get_prime_bits (mhd_gtls_session_t session)
294 { 294 {
295 cert_auth_info_t info; 295 cert_auth_info_t info;
296 296
297 info = mhd_gtls_get_auth_info (session); 297 info = MHD_gtls_get_auth_info (session);
298 if (info == NULL) 298 if (info == NULL)
299 return GNUTLS_E_INTERNAL_ERROR; 299 return GNUTLS_E_INTERNAL_ERROR;
300 300
@@ -302,7 +302,7 @@ MHD_gnutls_dh_get_prime_bits (mhd_gtls_session_t session)
302 break; 302 break;
303 } 303 }
304 default: 304 default:
305 gnutls_assert (); 305 MHD_gnutls_assert ();
306 return GNUTLS_E_INVALID_REQUEST; 306 return GNUTLS_E_INVALID_REQUEST;
307 } 307 }
308 308
@@ -320,11 +320,11 @@ MHD_gnutls_dh_get_prime_bits (mhd_gtls_session_t session)
320 * 320 *
321 **/ 321 **/
322int 322int
323MHD_gtls_rsa_export_get_modulus_bits (mhd_gtls_session_t session) 323MHD_gtls_rsa_export_get_modulus_bits (MHD_gtls_session_t session)
324{ 324{
325 cert_auth_info_t info; 325 cert_auth_info_t info;
326 326
327 info = mhd_gtls_get_auth_info (session); 327 info = MHD_gtls_get_auth_info (session);
328 if (info == NULL) 328 if (info == NULL)
329 return GNUTLS_E_INTERNAL_ERROR; 329 return GNUTLS_E_INTERNAL_ERROR;
330 330
@@ -332,7 +332,7 @@ MHD_gtls_rsa_export_get_modulus_bits (mhd_gtls_session_t session)
332} 332}
333 333
334/** 334/**
335 * MHD_gnutls_dh_get_peers_public_bits - This function returns the bits used in DH authentication 335 * MHD__gnutls_dh_get_peers_public_bits - This function returns the bits used in DH authentication
336 * @session: is a gnutls session 336 * @session: is a gnutls session
337 * 337 *
338 * This function will return the bits used in the last Diffie Hellman authentication 338 * This function will return the bits used in the last Diffie Hellman authentication
@@ -341,9 +341,9 @@ MHD_gtls_rsa_export_get_modulus_bits (mhd_gtls_session_t session)
341 * 341 *
342 **/ 342 **/
343int 343int
344MHD_gnutls_dh_get_peers_public_bits (mhd_gtls_session_t session) 344MHD__gnutls_dh_get_peers_public_bits (MHD_gtls_session_t session)
345{ 345{
346 mhd_gtls_dh_info_st *dh; 346 MHD_gtls_dh_info_st *dh;
347 347
348 switch (MHD_gtls_auth_get_type (session)) 348 switch (MHD_gtls_auth_get_type (session))
349 { 349 {
@@ -351,7 +351,7 @@ MHD_gnutls_dh_get_peers_public_bits (mhd_gtls_session_t session)
351 { 351 {
352 mhd_anon_auth_info_t info; 352 mhd_anon_auth_info_t info;
353 353
354 info = mhd_gtls_get_auth_info (session); 354 info = MHD_gtls_get_auth_info (session);
355 if (info == NULL) 355 if (info == NULL)
356 return GNUTLS_E_INTERNAL_ERROR; 356 return GNUTLS_E_INTERNAL_ERROR;
357 357
@@ -362,7 +362,7 @@ MHD_gnutls_dh_get_peers_public_bits (mhd_gtls_session_t session)
362 { 362 {
363 cert_auth_info_t info; 363 cert_auth_info_t info;
364 364
365 info = mhd_gtls_get_auth_info (session); 365 info = MHD_gtls_get_auth_info (session);
366 if (info == NULL) 366 if (info == NULL)
367 return GNUTLS_E_INTERNAL_ERROR; 367 return GNUTLS_E_INTERNAL_ERROR;
368 368
@@ -370,7 +370,7 @@ MHD_gnutls_dh_get_peers_public_bits (mhd_gtls_session_t session)
370 break; 370 break;
371 } 371 }
372 default: 372 default:
373 gnutls_assert (); 373 MHD_gnutls_assert ();
374 return GNUTLS_E_INVALID_REQUEST; 374 return GNUTLS_E_INVALID_REQUEST;
375 } 375 }
376 376
@@ -391,20 +391,20 @@ MHD_gnutls_dh_get_peers_public_bits (mhd_gtls_session_t session)
391 * Returns NULL in case of an error, or if no certificate was used. 391 * Returns NULL in case of an error, or if no certificate was used.
392 * 392 *
393 **/ 393 **/
394const gnutls_datum_t * 394const MHD_gnutls_datum_t *
395MHD_gtls_certificate_get_ours (mhd_gtls_session_t session) 395MHD_gtls_certificate_get_ours (MHD_gtls_session_t session)
396{ 396{
397 mhd_gtls_cert_credentials_t cred; 397 MHD_gtls_cert_credentials_t cred;
398 398
399 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, NULL); 399 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, NULL);
400 400
401 cred 401 cred
402 = (mhd_gtls_cert_credentials_t) mhd_gtls_get_cred (session->key, 402 = (MHD_gtls_cert_credentials_t) MHD_gtls_get_cred (session->key,
403 MHD_GNUTLS_CRD_CERTIFICATE, 403 MHD_GNUTLS_CRD_CERTIFICATE,
404 NULL); 404 NULL);
405 if (cred == NULL || cred->cert_list == NULL) 405 if (cred == NULL || cred->cert_list == NULL)
406 { 406 {
407 gnutls_assert (); 407 MHD_gnutls_assert ();
408 return NULL; 408 return NULL;
409 } 409 }
410 410
@@ -431,15 +431,15 @@ MHD_gtls_certificate_get_ours (mhd_gtls_session_t session)
431 * Returns NULL in case of an error, or if no certificate was sent. 431 * Returns NULL in case of an error, or if no certificate was sent.
432 * 432 *
433 **/ 433 **/
434const gnutls_datum_t * 434const MHD_gnutls_datum_t *
435MHD_gtls_certificate_get_peers (mhd_gtls_session_t 435MHD_gtls_certificate_get_peers (MHD_gtls_session_t
436 session, unsigned int *list_size) 436 session, unsigned int *list_size)
437{ 437{
438 cert_auth_info_t info; 438 cert_auth_info_t info;
439 439
440 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, NULL); 440 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, NULL);
441 441
442 info = mhd_gtls_get_auth_info (session); 442 info = MHD_gtls_get_auth_info (session);
443 if (info == NULL) 443 if (info == NULL)
444 return NULL; 444 return NULL;
445 445
@@ -457,20 +457,20 @@ MHD_gtls_certificate_get_peers (mhd_gtls_session_t
457 * 457 *
458 **/ 458 **/
459int 459int
460MHD_gtls_certificate_client_get_request_status (mhd_gtls_session_t session) 460MHD_gtls_certificate_client_get_request_status (MHD_gtls_session_t session)
461{ 461{
462 cert_auth_info_t info; 462 cert_auth_info_t info;
463 463
464 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, 0); 464 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, 0);
465 465
466 info = mhd_gtls_get_auth_info (session); 466 info = MHD_gtls_get_auth_info (session);
467 if (info == NULL) 467 if (info == NULL)
468 return GNUTLS_E_INTERNAL_ERROR; 468 return GNUTLS_E_INTERNAL_ERROR;
469 return info->certificate_requested; 469 return info->certificate_requested;
470} 470}
471 471
472/** 472/**
473 * MHD_gnutls_fingerprint - This function calculates the fingerprint of the given data 473 * MHD__gnutls_fingerprint - This function calculates the fingerprint of the given data
474 * @algo: is a digest algorithm 474 * @algo: is a digest algorithm
475 * @data: is the data 475 * @data: is the data
476 * @result: is the place where the result will be copied (may be null). 476 * @result: is the place where the result will be copied (may be null).
@@ -490,12 +490,12 @@ MHD_gtls_certificate_client_get_request_status (mhd_gtls_session_t session)
490 * 490 *
491 **/ 491 **/
492int 492int
493MHD_gnutls_fingerprint (enum MHD_GNUTLS_HashAlgorithm algo, 493MHD__gnutls_fingerprint (enum MHD_GNUTLS_HashAlgorithm algo,
494 const gnutls_datum_t * data, 494 const MHD_gnutls_datum_t * data,
495 void *result, size_t * result_size) 495 void *result, size_t * result_size)
496{ 496{
497 GNUTLS_HASH_HANDLE td; 497 GNUTLS_HASH_HANDLE td;
498 int hash_len = mhd_gnutls_hash_get_algo_len (HASH2MAC (algo)); 498 int hash_len = MHD_gnutls_hash_get_algo_len (HASH2MAC (algo));
499 499
500 if (hash_len < 0 || (unsigned) hash_len > *result_size || result == NULL) 500 if (hash_len < 0 || (unsigned) hash_len > *result_size || result == NULL)
501 { 501 {
@@ -506,21 +506,21 @@ MHD_gnutls_fingerprint (enum MHD_GNUTLS_HashAlgorithm algo,
506 506
507 if (result) 507 if (result)
508 { 508 {
509 td = mhd_gtls_hash_init (HASH2MAC (algo)); 509 td = MHD_gtls_hash_init (HASH2MAC (algo));
510 if (td == NULL) 510 if (td == NULL)
511 return GNUTLS_E_HASH_FAILED; 511 return GNUTLS_E_HASH_FAILED;
512 512
513 mhd_gnutls_hash (td, data->data, data->size); 513 MHD_gnutls_hash (td, data->data, data->size);
514 514
515 mhd_gnutls_hash_deinit (td, result); 515 MHD_gnutls_hash_deinit (td, result);
516 } 516 }
517 517
518 return 0; 518 return 0;
519} 519}
520 520
521/** 521/**
522 * MHD_gnutls_certificate_set_dh_params - This function will set the DH parameters for a server to use 522 * MHD__gnutls_certificate_set_dh_params - This function will set the DH parameters for a server to use
523 * @res: is a mhd_gtls_cert_credentials_t structure 523 * @res: is a MHD_gtls_cert_credentials_t structure
524 * @dh_params: is a structure that holds diffie hellman parameters. 524 * @dh_params: is a structure that holds diffie hellman parameters.
525 * 525 *
526 * This function will set the diffie hellman parameters for a 526 * This function will set the diffie hellman parameters for a
@@ -532,15 +532,15 @@ MHD_gnutls_fingerprint (enum MHD_GNUTLS_HashAlgorithm algo,
532 * 532 *
533 **/ 533 **/
534void 534void
535MHD_gnutls_certificate_set_dh_params (mhd_gtls_cert_credentials_t res, 535MHD__gnutls_certificate_set_dh_params (MHD_gtls_cert_credentials_t res,
536 mhd_gtls_dh_params_t dh_params) 536 MHD_gtls_dh_params_t dh_params)
537{ 537{
538 res->dh_params = dh_params; 538 res->dh_params = dh_params;
539} 539}
540 540
541/** 541/**
542 * gnutls_certificate_set_params_function - This function will set the DH or RSA parameters callback 542 * MHD_gnutls_certificate_set_params_function - This function will set the DH or RSA parameters callback
543 * @res: is a mhd_gtls_cert_credentials_t structure 543 * @res: is a MHD_gtls_cert_credentials_t structure
544 * @func: is the function to be called 544 * @func: is the function to be called
545 * 545 *
546 * This function will set a callback in order for the server to get the 546 * This function will set a callback in order for the server to get the
@@ -549,32 +549,32 @@ MHD_gnutls_certificate_set_dh_params (mhd_gtls_cert_credentials_t res,
549 * 549 *
550 **/ 550 **/
551void 551void
552gnutls_certificate_set_params_function (mhd_gtls_cert_credentials_t res, 552MHD_gnutls_certificate_set_params_function (MHD_gtls_cert_credentials_t res,
553 gnutls_params_function * func) 553 MHD_gnutls_params_function * func)
554{ 554{
555 res->params_func = func; 555 res->params_func = func;
556} 556}
557 557
558/** 558/**
559 * MHD_gnutls_certificate_set_verify_flags - This function will set the flags to be used at certificate verification 559 * MHD__gnutls_certificate_set_verify_flags - This function will set the flags to be used at certificate verification
560 * @res: is a mhd_gtls_cert_credentials_t structure 560 * @res: is a MHD_gtls_cert_credentials_t structure
561 * @flags: are the flags 561 * @flags: are the flags
562 * 562 *
563 * This function will set the flags to be used at verification of the 563 * This function will set the flags to be used at verification of the
564 * certificates. Flags must be OR of the 564 * certificates. Flags must be OR of the
565 * #gnutls_certificate_verify_flags enumerations. 565 * #MHD_gnutls_certificate_verify_flags enumerations.
566 * 566 *
567 **/ 567 **/
568void 568void
569MHD_gnutls_certificate_set_verify_flags (mhd_gtls_cert_credentials_t 569MHD__gnutls_certificate_set_verify_flags (MHD_gtls_cert_credentials_t
570 res, unsigned int flags) 570 res, unsigned int flags)
571{ 571{
572 res->verify_flags = flags; 572 res->verify_flags = flags;
573} 573}
574 574
575/** 575/**
576 * MHD_gnutls_certificate_set_verify_limits - This function will set the upper limits to be used at certificate verification 576 * MHD__gnutls_certificate_set_verify_limits - This function will set the upper limits to be used at certificate verification
577 * @res: is a gnutls_certificate_credentials structure 577 * @res: is a MHD_gnutls_certificate_credentials structure
578 * @max_bits: is the number of bits of an acceptable certificate (default 8200) 578 * @max_bits: is the number of bits of an acceptable certificate (default 8200)
579 * @max_depth: is maximum depth of the verification of a certificate chain (default 5) 579 * @max_depth: is maximum depth of the verification of a certificate chain (default 5)
580 * 580 *
@@ -584,7 +584,7 @@ MHD_gnutls_certificate_set_verify_flags (mhd_gtls_cert_credentials_t
584 * 584 *
585 **/ 585 **/
586void 586void
587MHD_gnutls_certificate_set_verify_limits (mhd_gtls_cert_credentials_t 587MHD__gnutls_certificate_set_verify_limits (MHD_gtls_cert_credentials_t
588 res, 588 res,
589 unsigned int max_bits, 589 unsigned int max_bits,
590 unsigned int max_depth) 590 unsigned int max_depth)
@@ -594,8 +594,8 @@ MHD_gnutls_certificate_set_verify_limits (mhd_gtls_cert_credentials_t
594} 594}
595 595
596/** 596/**
597 * MHD_gnutls_certificate_set_rsa_export_params - This function will set the RSA parameters for a server to use 597 * MHD__gnutls_certificate_set_rsa_export_params - This function will set the RSA parameters for a server to use
598 * @res: is a mhd_gtls_cert_credentials_t structure 598 * @res: is a MHD_gtls_cert_credentials_t structure
599 * @rsa_params: is a structure that holds temporary RSA parameters. 599 * @rsa_params: is a structure that holds temporary RSA parameters.
600 * 600 *
601 * This function will set the temporary RSA parameters for a certificate 601 * This function will set the temporary RSA parameters for a certificate
@@ -604,17 +604,17 @@ MHD_gnutls_certificate_set_verify_limits (mhd_gtls_cert_credentials_t
604 * 604 *
605 **/ 605 **/
606void 606void
607MHD_gnutls_certificate_set_rsa_export_params (mhd_gtls_cert_credentials_t 607MHD__gnutls_certificate_set_rsa_export_params (MHD_gtls_cert_credentials_t
608 res, 608 res,
609 mhd_gtls_rsa_params_t 609 MHD_gtls_rsa_params_t
610 rsa_params) 610 rsa_params)
611{ 611{
612 res->rsa_params = rsa_params; 612 res->rsa_params = rsa_params;
613} 613}
614 614
615/** 615/**
616 * gnutls_anon_set_params_function - This function will set the DH or RSA parameters callback 616 * MHD_gnutls_anon_set_params_function - This function will set the DH or RSA parameters callback
617 * @res: is a mhd_gtls_anon_server_credentials_t structure 617 * @res: is a MHD_gtls_anon_server_credentials_t structure
618 * @func: is the function to be called 618 * @func: is the function to be called
619 * 619 *
620 * This function will set a callback in order for the server to get the 620 * This function will set a callback in order for the server to get the
@@ -623,8 +623,8 @@ MHD_gnutls_certificate_set_rsa_export_params (mhd_gtls_cert_credentials_t
623 * 623 *
624 **/ 624 **/
625void 625void
626gnutls_anon_set_params_function (mhd_gtls_anon_server_credentials_t res, 626MHD_gnutls_anon_set_params_function (MHD_gtls_anon_server_credentials_t res,
627 gnutls_params_function * func) 627 MHD_gnutls_params_function * func)
628{ 628{
629 res->params_func = func; 629 res->params_func = func;
630} 630}
diff --git a/src/daemon/https/tls/gnutls_x509.c b/src/daemon/https/tls/gnutls_x509.c
index f854b710..811f5dbe 100644
--- a/src/daemon/https/tls/gnutls_x509.c
+++ b/src/daemon/https/tls/gnutls_x509.c
@@ -64,21 +64,21 @@
64 * is unacceptable. 64 * is unacceptable.
65 */ 65 */
66inline static int 66inline static int
67check_bits (gnutls_x509_crt_t crt, unsigned int max_bits) 67check_bits (MHD_gnutls_x509_crt_t crt, unsigned int max_bits)
68{ 68{
69 int ret; 69 int ret;
70 unsigned int bits; 70 unsigned int bits;
71 71
72 ret = gnutls_x509_crt_get_pk_algorithm (crt, &bits); 72 ret = MHD_gnutls_x509_crt_get_pk_algorithm (crt, &bits);
73 if (ret < 0) 73 if (ret < 0)
74 { 74 {
75 gnutls_assert (); 75 MHD_gnutls_assert ();
76 return ret; 76 return ret;
77 } 77 }
78 78
79 if (bits > max_bits && max_bits > 0) 79 if (bits > max_bits && max_bits > 0)
80 { 80 {
81 gnutls_assert (); 81 MHD_gnutls_assert ();
82 return GNUTLS_E_CONSTRAINT_ERROR; 82 return GNUTLS_E_CONSTRAINT_ERROR;
83 } 83 }
84 84
@@ -88,43 +88,43 @@ check_bits (gnutls_x509_crt_t crt, unsigned int max_bits)
88 88
89#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) { \ 89#define CLEAR_CERTS for(x=0;x<peer_certificate_list_size;x++) { \
90 if (peer_certificate_list[x]) \ 90 if (peer_certificate_list[x]) \
91 gnutls_x509_crt_deinit(peer_certificate_list[x]); \ 91 MHD_gnutls_x509_crt_deinit(peer_certificate_list[x]); \
92 } \ 92 } \
93 gnutls_free( peer_certificate_list) 93 MHD_gnutls_free( peer_certificate_list)
94 94
95/*- 95/*-
96 * _gnutls_x509_cert_verify_peers - This function returns the peer's certificate status 96 * MHD__gnutls_x509_cert_verify_peers - This function returns the peer's certificate status
97 * @session: is a gnutls session 97 * @session: is a gnutls session
98 * 98 *
99 * This function will try to verify the peer's certificate and return its status (TRUSTED, REVOKED etc.). 99 * This function will try to verify the peer's certificate and return its status (TRUSTED, REVOKED etc.).
100 * The return value (status) should be one of the gnutls_certificate_status_t enumerated elements. 100 * The return value (status) should be one of the MHD_gnutls_certificate_status_t enumerated elements.
101 * However you must also check the peer's name in order to check if the verified certificate belongs to the 101 * However you must also check the peer's name in order to check if the verified certificate belongs to the
102 * actual peer. Returns a negative error code in case of an error, or GNUTLS_E_NO_CERTIFICATE_FOUND if no certificate was sent. 102 * actual peer. Returns a negative error code in case of an error, or GNUTLS_E_NO_CERTIFICATE_FOUND if no certificate was sent.
103 * 103 *
104 -*/ 104 -*/
105int 105int
106_gnutls_x509_cert_verify_peers (mhd_gtls_session_t session, 106MHD__gnutls_x509_cert_verify_peers (MHD_gtls_session_t session,
107 unsigned int *status) 107 unsigned int *status)
108{ 108{
109 cert_auth_info_t info; 109 cert_auth_info_t info;
110 mhd_gtls_cert_credentials_t cred; 110 MHD_gtls_cert_credentials_t cred;
111 gnutls_x509_crt_t *peer_certificate_list; 111 MHD_gnutls_x509_crt_t *peer_certificate_list;
112 int peer_certificate_list_size, i, x, ret; 112 int peer_certificate_list_size, i, x, ret;
113 113
114 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST); 114 CHECK_AUTH (MHD_GNUTLS_CRD_CERTIFICATE, GNUTLS_E_INVALID_REQUEST);
115 115
116 info = mhd_gtls_get_auth_info (session); 116 info = MHD_gtls_get_auth_info (session);
117 if (info == NULL) 117 if (info == NULL)
118 { 118 {
119 gnutls_assert (); 119 MHD_gnutls_assert ();
120 return GNUTLS_E_INVALID_REQUEST; 120 return GNUTLS_E_INVALID_REQUEST;
121 } 121 }
122 122
123 cred = (mhd_gtls_cert_credentials_t) 123 cred = (MHD_gtls_cert_credentials_t)
124 mhd_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL); 124 MHD_gtls_get_cred (session->key, MHD_GNUTLS_CRD_CERTIFICATE, NULL);
125 if (cred == NULL) 125 if (cred == NULL)
126 { 126 {
127 gnutls_assert (); 127 MHD_gnutls_assert ();
128 return GNUTLS_E_INSUFFICIENT_CREDENTIALS; 128 return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
129 } 129 }
130 130
@@ -133,40 +133,40 @@ _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
133 133
134 if (info->ncerts > cred->verify_depth && cred->verify_depth > 0) 134 if (info->ncerts > cred->verify_depth && cred->verify_depth > 0)
135 { 135 {
136 gnutls_assert (); 136 MHD_gnutls_assert ();
137 return GNUTLS_E_CONSTRAINT_ERROR; 137 return GNUTLS_E_CONSTRAINT_ERROR;
138 } 138 }
139 139
140 /* generate a list of gnutls_certs based on the auth info 140 /* generate a list of MHD_gnutls_certs based on the auth info
141 * raw certs. 141 * raw certs.
142 */ 142 */
143 peer_certificate_list_size = info->ncerts; 143 peer_certificate_list_size = info->ncerts;
144 peer_certificate_list = 144 peer_certificate_list =
145 gnutls_calloc (1, 145 MHD_gnutls_calloc (1,
146 peer_certificate_list_size * sizeof (gnutls_x509_crt_t)); 146 peer_certificate_list_size * sizeof (MHD_gnutls_x509_crt_t));
147 if (peer_certificate_list == NULL) 147 if (peer_certificate_list == NULL)
148 { 148 {
149 gnutls_assert (); 149 MHD_gnutls_assert ();
150 return GNUTLS_E_MEMORY_ERROR; 150 return GNUTLS_E_MEMORY_ERROR;
151 } 151 }
152 152
153 for (i = 0; i < peer_certificate_list_size; i++) 153 for (i = 0; i < peer_certificate_list_size; i++)
154 { 154 {
155 ret = gnutls_x509_crt_init (&peer_certificate_list[i]); 155 ret = MHD_gnutls_x509_crt_init (&peer_certificate_list[i]);
156 if (ret < 0) 156 if (ret < 0)
157 { 157 {
158 gnutls_assert (); 158 MHD_gnutls_assert ();
159 CLEAR_CERTS; 159 CLEAR_CERTS;
160 return ret; 160 return ret;
161 } 161 }
162 162
163 ret = 163 ret =
164 gnutls_x509_crt_import (peer_certificate_list[i], 164 MHD_gnutls_x509_crt_import (peer_certificate_list[i],
165 &info->raw_certificate_list[i], 165 &info->raw_certificate_list[i],
166 GNUTLS_X509_FMT_DER); 166 GNUTLS_X509_FMT_DER);
167 if (ret < 0) 167 if (ret < 0)
168 { 168 {
169 gnutls_assert (); 169 MHD_gnutls_assert ();
170 CLEAR_CERTS; 170 CLEAR_CERTS;
171 return ret; 171 return ret;
172 } 172 }
@@ -174,7 +174,7 @@ _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
174 ret = check_bits (peer_certificate_list[i], cred->verify_bits); 174 ret = check_bits (peer_certificate_list[i], cred->verify_bits);
175 if (ret < 0) 175 if (ret < 0)
176 { 176 {
177 gnutls_assert (); 177 MHD_gnutls_assert ();
178 CLEAR_CERTS; 178 CLEAR_CERTS;
179 return ret; 179 return ret;
180 } 180 }
@@ -184,7 +184,7 @@ _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
184 /* Verify certificate 184 /* Verify certificate
185 */ 185 */
186 ret = 186 ret =
187 gnutls_x509_crt_list_verify (peer_certificate_list, 187 MHD_gnutls_x509_crt_list_verify (peer_certificate_list,
188 peer_certificate_list_size, 188 peer_certificate_list_size,
189 cred->x509_ca_list, cred->x509_ncas, 189 cred->x509_ca_list, cred->x509_ncas,
190 cred->x509_crl_list, cred->x509_ncrls, 190 cred->x509_crl_list, cred->x509_ncrls,
@@ -194,7 +194,7 @@ _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
194 194
195 if (ret < 0) 195 if (ret < 0)
196 { 196 {
197 gnutls_assert (); 197 MHD_gnutls_assert ();
198 return ret; 198 return ret;
199 } 199 }
200 200
@@ -209,55 +209,55 @@ _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
209 * the given key parameters. 209 * the given key parameters.
210 */ 210 */
211static int 211static int
212_gnutls_check_key_cert_match (mhd_gtls_cert_credentials_t res) 212MHD__gnutls_check_key_cert_match (MHD_gtls_cert_credentials_t res)
213{ 213{
214 gnutls_datum_t cid; 214 MHD_gnutls_datum_t cid;
215 gnutls_datum_t kid; 215 MHD_gnutls_datum_t kid;
216 unsigned pk = res->cert_list[res->ncerts - 1][0].subject_pk_algorithm; 216 unsigned pk = res->cert_list[res->ncerts - 1][0].subject_pk_algorithm;
217 217
218 if (res->pkey[res->ncerts - 1].pk_algorithm != pk) 218 if (res->pkey[res->ncerts - 1].pk_algorithm != pk)
219 { 219 {
220 gnutls_assert (); 220 MHD_gnutls_assert ();
221 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH; 221 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
222 } 222 }
223 223
224 _gnutls_x509_write_rsa_params (res->pkey[res->ncerts - 1].params, 224 MHD__gnutls_x509_write_rsa_params (res->pkey[res->ncerts - 1].params,
225 res->pkey[res->ncerts - 225 res->pkey[res->ncerts -
226 1].params_size, &kid); 226 1].params_size, &kid);
227 227
228 228
229 _gnutls_x509_write_rsa_params (res->cert_list[res->ncerts - 1][0].params, 229 MHD__gnutls_x509_write_rsa_params (res->cert_list[res->ncerts - 1][0].params,
230 res->cert_list[res->ncerts - 230 res->cert_list[res->ncerts -
231 1][0].params_size, &cid); 231 1][0].params_size, &cid);
232 232
233 if (cid.size != kid.size) 233 if (cid.size != kid.size)
234 { 234 {
235 gnutls_assert (); 235 MHD_gnutls_assert ();
236 _gnutls_free_datum (&kid); 236 MHD__gnutls_free_datum (&kid);
237 _gnutls_free_datum (&cid); 237 MHD__gnutls_free_datum (&cid);
238 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH; 238 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
239 } 239 }
240 240
241 if (memcmp (kid.data, cid.data, kid.size) != 0) 241 if (memcmp (kid.data, cid.data, kid.size) != 0)
242 { 242 {
243 gnutls_assert (); 243 MHD_gnutls_assert ();
244 _gnutls_free_datum (&kid); 244 MHD__gnutls_free_datum (&kid);
245 _gnutls_free_datum (&cid); 245 MHD__gnutls_free_datum (&cid);
246 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH; 246 return GNUTLS_E_CERTIFICATE_KEY_MISMATCH;
247 } 247 }
248 248
249 _gnutls_free_datum (&kid); 249 MHD__gnutls_free_datum (&kid);
250 _gnutls_free_datum (&cid); 250 MHD__gnutls_free_datum (&cid);
251 return 0; 251 return 0;
252} 252}
253 253
254/* Reads a DER encoded certificate list from memory and stores it to 254/* Reads a DER encoded certificate list from memory and stores it to
255 * a gnutls_cert structure. 255 * a MHD_gnutls_cert structure.
256 * Returns the number of certificates parsed. 256 * Returns the number of certificates parsed.
257 */ 257 */
258static int 258static int
259parse_crt_mem (gnutls_cert ** cert_list, unsigned *ncerts, 259parse_crt_mem (MHD_gnutls_cert ** cert_list, unsigned *ncerts,
260 gnutls_x509_crt_t cert) 260 MHD_gnutls_x509_crt_t cert)
261{ 261{
262 int i; 262 int i;
263 int ret; 263 int ret;
@@ -265,19 +265,19 @@ parse_crt_mem (gnutls_cert ** cert_list, unsigned *ncerts,
265 i = *ncerts + 1; 265 i = *ncerts + 1;
266 266
267 *cert_list = 267 *cert_list =
268 (gnutls_cert *) mhd_gtls_realloc_fast (*cert_list, 268 (MHD_gnutls_cert *) MHD_gtls_realloc_fast (*cert_list,
269 i * sizeof (gnutls_cert)); 269 i * sizeof (MHD_gnutls_cert));
270 270
271 if (*cert_list == NULL) 271 if (*cert_list == NULL)
272 { 272 {
273 gnutls_assert (); 273 MHD_gnutls_assert ();
274 return GNUTLS_E_MEMORY_ERROR; 274 return GNUTLS_E_MEMORY_ERROR;
275 } 275 }
276 276
277 ret = mhd_gtls_x509_crt_to_gcert (&cert_list[0][i - 1], cert, 0); 277 ret = MHD_gtls_x509_crt_to_gcert (&cert_list[0][i - 1], cert, 0);
278 if (ret < 0) 278 if (ret < 0)
279 { 279 {
280 gnutls_assert (); 280 MHD_gnutls_assert ();
281 return ret; 281 return ret;
282 } 282 }
283 283
@@ -287,65 +287,65 @@ parse_crt_mem (gnutls_cert ** cert_list, unsigned *ncerts,
287} 287}
288 288
289/* Reads a DER encoded certificate list from memory and stores it to 289/* Reads a DER encoded certificate list from memory and stores it to
290 * a gnutls_cert structure. 290 * a MHD_gnutls_cert structure.
291 * Returns the number of certificates parsed. 291 * Returns the number of certificates parsed.
292 */ 292 */
293static int 293static int
294parse_der_cert_mem (gnutls_cert ** cert_list, unsigned *ncerts, 294parse_der_cert_mem (MHD_gnutls_cert ** cert_list, unsigned *ncerts,
295 const void *input_cert, int input_cert_size) 295 const void *input_cert, int input_cert_size)
296{ 296{
297 gnutls_datum_t tmp; 297 MHD_gnutls_datum_t tmp;
298 gnutls_x509_crt_t cert; 298 MHD_gnutls_x509_crt_t cert;
299 int ret; 299 int ret;
300 300
301 ret = gnutls_x509_crt_init (&cert); 301 ret = MHD_gnutls_x509_crt_init (&cert);
302 if (ret < 0) 302 if (ret < 0)
303 { 303 {
304 gnutls_assert (); 304 MHD_gnutls_assert ();
305 return ret; 305 return ret;
306 } 306 }
307 307
308 tmp.data = (opaque *) input_cert; 308 tmp.data = (opaque *) input_cert;
309 tmp.size = input_cert_size; 309 tmp.size = input_cert_size;
310 310
311 ret = gnutls_x509_crt_import (cert, &tmp, GNUTLS_X509_FMT_DER); 311 ret = MHD_gnutls_x509_crt_import (cert, &tmp, GNUTLS_X509_FMT_DER);
312 if (ret < 0) 312 if (ret < 0)
313 { 313 {
314 gnutls_assert (); 314 MHD_gnutls_assert ();
315 gnutls_x509_crt_deinit (cert); 315 MHD_gnutls_x509_crt_deinit (cert);
316 return ret; 316 return ret;
317 } 317 }
318 318
319 ret = parse_crt_mem (cert_list, ncerts, cert); 319 ret = parse_crt_mem (cert_list, ncerts, cert);
320 gnutls_x509_crt_deinit (cert); 320 MHD_gnutls_x509_crt_deinit (cert);
321 321
322 return ret; 322 return ret;
323} 323}
324 324
325/* Reads a base64 encoded certificate list from memory and stores it to 325/* Reads a base64 encoded certificate list from memory and stores it to
326 * a gnutls_cert structure. Returns the number of certificate parsed. 326 * a MHD_gnutls_cert structure. Returns the number of certificate parsed.
327 */ 327 */
328static int 328static int
329parse_pem_cert_mem (gnutls_cert ** cert_list, unsigned *ncerts, 329parse_pem_cert_mem (MHD_gnutls_cert ** cert_list, unsigned *ncerts,
330 const char *input_cert, int input_cert_size) 330 const char *input_cert, int input_cert_size)
331{ 331{
332 int size, siz2, i; 332 int size, siz2, i;
333 const char *ptr; 333 const char *ptr;
334 opaque *ptr2; 334 opaque *ptr2;
335 gnutls_datum_t tmp; 335 MHD_gnutls_datum_t tmp;
336 int ret, count; 336 int ret, count;
337 337
338 /* move to the certificate 338 /* move to the certificate
339 */ 339 */
340 ptr = memmem (input_cert, input_cert_size, 340 ptr = MHD_memmem (input_cert, input_cert_size,
341 PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); 341 PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
342 if (ptr == NULL) 342 if (ptr == NULL)
343 ptr = memmem (input_cert, input_cert_size, 343 ptr = MHD_memmem (input_cert, input_cert_size,
344 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); 344 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
345 345
346 if (ptr == NULL) 346 if (ptr == NULL)
347 { 347 {
348 gnutls_assert (); 348 MHD_gnutls_assert ();
349 return GNUTLS_E_BASE64_DECODING_ERROR; 349 return GNUTLS_E_BASE64_DECODING_ERROR;
350 } 350 }
351 size = input_cert_size - (ptr - input_cert); 351 size = input_cert_size - (ptr - input_cert);
@@ -356,34 +356,34 @@ parse_pem_cert_mem (gnutls_cert ** cert_list, unsigned *ncerts,
356 do 356 do
357 { 357 {
358 358
359 siz2 = _gnutls_fbase64_decode (NULL, (const unsigned char*) ptr, size, &ptr2); 359 siz2 = MHD__gnutls_fbase64_decode (NULL, (const unsigned char*) ptr, size, &ptr2);
360 360
361 if (siz2 < 0) 361 if (siz2 < 0)
362 { 362 {
363 gnutls_assert (); 363 MHD_gnutls_assert ();
364 return GNUTLS_E_BASE64_DECODING_ERROR; 364 return GNUTLS_E_BASE64_DECODING_ERROR;
365 } 365 }
366 366
367 *cert_list = 367 *cert_list =
368 (gnutls_cert *) mhd_gtls_realloc_fast (*cert_list, 368 (MHD_gnutls_cert *) MHD_gtls_realloc_fast (*cert_list,
369 i * sizeof (gnutls_cert)); 369 i * sizeof (MHD_gnutls_cert));
370 370
371 if (*cert_list == NULL) 371 if (*cert_list == NULL)
372 { 372 {
373 gnutls_assert (); 373 MHD_gnutls_assert ();
374 return GNUTLS_E_MEMORY_ERROR; 374 return GNUTLS_E_MEMORY_ERROR;
375 } 375 }
376 376
377 tmp.data = ptr2; 377 tmp.data = ptr2;
378 tmp.size = siz2; 378 tmp.size = siz2;
379 379
380 ret = mhd_gtls_x509_raw_cert_to_gcert (&cert_list[0][i - 1], &tmp, 0); 380 ret = MHD_gtls_x509_raw_cert_to_gcert (&cert_list[0][i - 1], &tmp, 0);
381 if (ret < 0) 381 if (ret < 0)
382 { 382 {
383 gnutls_assert (); 383 MHD_gnutls_assert ();
384 return ret; 384 return ret;
385 } 385 }
386 _gnutls_free_datum (&tmp); /* free ptr2 */ 386 MHD__gnutls_free_datum (&tmp); /* free ptr2 */
387 387
388 /* now we move ptr after the pem header 388 /* now we move ptr after the pem header
389 */ 389 */
@@ -396,9 +396,9 @@ parse_pem_cert_mem (gnutls_cert ** cert_list, unsigned *ncerts,
396 { 396 {
397 char *ptr3; 397 char *ptr3;
398 398
399 ptr3 = memmem (ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); 399 ptr3 = MHD_memmem (ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
400 if (ptr3 == NULL) 400 if (ptr3 == NULL)
401 ptr3 = memmem (ptr, size, PEM_CERT_SEP2, 401 ptr3 = MHD_memmem (ptr, size, PEM_CERT_SEP2,
402 sizeof (PEM_CERT_SEP2) - 1); 402 sizeof (PEM_CERT_SEP2) - 1);
403 403
404 ptr = ptr3; 404 ptr = ptr3;
@@ -422,30 +422,30 @@ parse_pem_cert_mem (gnutls_cert ** cert_list, unsigned *ncerts,
422/* Reads a DER or PEM certificate from memory 422/* Reads a DER or PEM certificate from memory
423 */ 423 */
424static int 424static int
425read_cert_mem (mhd_gtls_cert_credentials_t res, const void *cert, 425read_cert_mem (MHD_gtls_cert_credentials_t res, const void *cert,
426 int cert_size, gnutls_x509_crt_fmt_t type) 426 int cert_size, MHD_gnutls_x509_crt_fmt_t type)
427{ 427{
428 int ret; 428 int ret;
429 429
430 /* allocate space for the certificate to add 430 /* allocate space for the certificate to add
431 */ 431 */
432 res->cert_list = mhd_gtls_realloc_fast (res->cert_list, 432 res->cert_list = MHD_gtls_realloc_fast (res->cert_list,
433 (1 + 433 (1 +
434 res->ncerts) * 434 res->ncerts) *
435 sizeof (gnutls_cert *)); 435 sizeof (MHD_gnutls_cert *));
436 if (res->cert_list == NULL) 436 if (res->cert_list == NULL)
437 { 437 {
438 gnutls_assert (); 438 MHD_gnutls_assert ();
439 return GNUTLS_E_MEMORY_ERROR; 439 return GNUTLS_E_MEMORY_ERROR;
440 } 440 }
441 441
442 res->cert_list_length = mhd_gtls_realloc_fast (res->cert_list_length, 442 res->cert_list_length = MHD_gtls_realloc_fast (res->cert_list_length,
443 (1 + 443 (1 +
444 res->ncerts) * 444 res->ncerts) *
445 sizeof (int)); 445 sizeof (int));
446 if (res->cert_list_length == NULL) 446 if (res->cert_list_length == NULL)
447 { 447 {
448 gnutls_assert (); 448 MHD_gnutls_assert ();
449 return GNUTLS_E_MEMORY_ERROR; 449 return GNUTLS_E_MEMORY_ERROR;
450 } 450 }
451 451
@@ -464,7 +464,7 @@ read_cert_mem (mhd_gtls_cert_credentials_t res, const void *cert,
464 464
465 if (ret < 0) 465 if (ret < 0)
466 { 466 {
467 gnutls_assert (); 467 MHD_gnutls_assert ();
468 return ret; 468 return ret;
469 } 469 }
470 470
@@ -473,19 +473,19 @@ read_cert_mem (mhd_gtls_cert_credentials_t res, const void *cert,
473 473
474 474
475int 475int
476_gnutls_x509_privkey_to_gkey (gnutls_privkey * dest, 476MHD__gnutls_x509_privkey_to_gkey (MHD_gnutls_privkey * dest,
477 gnutls_x509_privkey_t src) 477 MHD_gnutls_x509_privkey_t src)
478{ 478{
479 int i, ret; 479 int i, ret;
480 480
481 memset (dest, 0, sizeof (gnutls_privkey)); 481 memset (dest, 0, sizeof (MHD_gnutls_privkey));
482 482
483 for (i = 0; i < src->params_size; i++) 483 for (i = 0; i < src->params_size; i++)
484 { 484 {
485 dest->params[i] = _gnutls_mpi_copy (src->params[i]); 485 dest->params[i] = MHD__gnutls_mpi_copy (src->params[i]);
486 if (dest->params[i] == NULL) 486 if (dest->params[i] == NULL)
487 { 487 {
488 gnutls_assert (); 488 MHD_gnutls_assert ();
489 ret = GNUTLS_E_MEMORY_ERROR; 489 ret = GNUTLS_E_MEMORY_ERROR;
490 goto cleanup; 490 goto cleanup;
491 } 491 }
@@ -500,13 +500,13 @@ cleanup:
500 500
501 for (i = 0; i < src->params_size; i++) 501 for (i = 0; i < src->params_size; i++)
502 { 502 {
503 mhd_gtls_mpi_release (&dest->params[i]); 503 MHD_gtls_mpi_release (&dest->params[i]);
504 } 504 }
505 return ret; 505 return ret;
506} 506}
507 507
508void 508void
509mhd_gtls_gkey_deinit (gnutls_privkey * key) 509MHD_gtls_gkey_deinit (MHD_gnutls_privkey * key)
510{ 510{
511 int i; 511 int i;
512 if (key == NULL) 512 if (key == NULL)
@@ -514,51 +514,51 @@ mhd_gtls_gkey_deinit (gnutls_privkey * key)
514 514
515 for (i = 0; i < key->params_size; i++) 515 for (i = 0; i < key->params_size; i++)
516 { 516 {
517 mhd_gtls_mpi_release (&key->params[i]); 517 MHD_gtls_mpi_release (&key->params[i]);
518 } 518 }
519} 519}
520 520
521int 521int
522_gnutls_x509_raw_privkey_to_gkey (gnutls_privkey * privkey, 522MHD__gnutls_x509_raw_privkey_to_gkey (MHD_gnutls_privkey * privkey,
523 const gnutls_datum_t * raw_key, 523 const MHD_gnutls_datum_t * raw_key,
524 gnutls_x509_crt_fmt_t type) 524 MHD_gnutls_x509_crt_fmt_t type)
525{ 525{
526 gnutls_x509_privkey_t tmpkey; 526 MHD_gnutls_x509_privkey_t tmpkey;
527 int ret; 527 int ret;
528 528
529 ret = gnutls_x509_privkey_init (&tmpkey); 529 ret = MHD_gnutls_x509_privkey_init (&tmpkey);
530 if (ret < 0) 530 if (ret < 0)
531 { 531 {
532 gnutls_assert (); 532 MHD_gnutls_assert ();
533 return ret; 533 return ret;
534 } 534 }
535 535
536 ret = gnutls_x509_privkey_import (tmpkey, raw_key, type); 536 ret = MHD_gnutls_x509_privkey_import (tmpkey, raw_key, type);
537 537
538#ifdef ENABLE_PKI 538#ifdef ENABLE_PKI
539 /* If normal key decoding doesn't work try decoding a plain PKCS #8 key */ 539 /* If normal key decoding doesn't work try decoding a plain PKCS #8 key */
540 if (ret < 0) 540 if (ret < 0)
541 ret = 541 ret =
542 gnutls_x509_privkey_import_pkcs8 (tmpkey, raw_key, type, NULL, 542 MHD_gnutls_x509_privkey_import_pkcs8 (tmpkey, raw_key, type, NULL,
543 GNUTLS_PKCS_PLAIN); 543 GNUTLS_PKCS_PLAIN);
544#endif 544#endif
545 545
546 if (ret < 0) 546 if (ret < 0)
547 { 547 {
548 gnutls_assert (); 548 MHD_gnutls_assert ();
549 gnutls_x509_privkey_deinit (tmpkey); 549 MHD_gnutls_x509_privkey_deinit (tmpkey);
550 return ret; 550 return ret;
551 } 551 }
552 552
553 ret = _gnutls_x509_privkey_to_gkey (privkey, tmpkey); 553 ret = MHD__gnutls_x509_privkey_to_gkey (privkey, tmpkey);
554 if (ret < 0) 554 if (ret < 0)
555 { 555 {
556 gnutls_assert (); 556 MHD_gnutls_assert ();
557 gnutls_x509_privkey_deinit (tmpkey); 557 MHD_gnutls_x509_privkey_deinit (tmpkey);
558 return ret; 558 return ret;
559 } 559 }
560 560
561 gnutls_x509_privkey_deinit (tmpkey); 561 MHD_gnutls_x509_privkey_deinit (tmpkey);
562 562
563 return 0; 563 return 0;
564} 564}
@@ -568,20 +568,20 @@ _gnutls_x509_raw_privkey_to_gkey (gnutls_privkey * privkey,
568 * that GnuTLS doesn't know the private key. 568 * that GnuTLS doesn't know the private key.
569 */ 569 */
570static int 570static int
571read_key_mem (mhd_gtls_cert_credentials_t res, 571read_key_mem (MHD_gtls_cert_credentials_t res,
572 const void *key, int key_size, gnutls_x509_crt_fmt_t type) 572 const void *key, int key_size, MHD_gnutls_x509_crt_fmt_t type)
573{ 573{
574 int ret; 574 int ret;
575 gnutls_datum_t tmp; 575 MHD_gnutls_datum_t tmp;
576 576
577 /* allocate space for the pkey list 577 /* allocate space for the pkey list
578 */ 578 */
579 res->pkey = 579 res->pkey =
580 mhd_gtls_realloc_fast (res->pkey, 580 MHD_gtls_realloc_fast (res->pkey,
581 (res->ncerts + 1) * sizeof (gnutls_privkey)); 581 (res->ncerts + 1) * sizeof (MHD_gnutls_privkey));
582 if (res->pkey == NULL) 582 if (res->pkey == NULL)
583 { 583 {
584 gnutls_assert (); 584 MHD_gnutls_assert ();
585 return GNUTLS_E_MEMORY_ERROR; 585 return GNUTLS_E_MEMORY_ERROR;
586 } 586 }
587 587
@@ -591,29 +591,29 @@ read_key_mem (mhd_gtls_cert_credentials_t res,
591 tmp.size = key_size; 591 tmp.size = key_size;
592 592
593 ret = 593 ret =
594 _gnutls_x509_raw_privkey_to_gkey (&res->pkey[res->ncerts], &tmp, 594 MHD__gnutls_x509_raw_privkey_to_gkey (&res->pkey[res->ncerts], &tmp,
595 type); 595 type);
596 if (ret < 0) 596 if (ret < 0)
597 { 597 {
598 gnutls_assert (); 598 MHD_gnutls_assert ();
599 return ret; 599 return ret;
600 } 600 }
601 } 601 }
602 else 602 else
603 memset (&res->pkey[res->ncerts], 0, sizeof (gnutls_privkey)); 603 memset (&res->pkey[res->ncerts], 0, sizeof (MHD_gnutls_privkey));
604 604
605 return 0; 605 return 0;
606} 606}
607 607
608/** 608/**
609 * MHD_gnutls_certificate_set_x509_key_mem - Used to set keys in a mhd_gtls_cert_credentials_t structure 609 * MHD__gnutls_certificate_set_x509_key_mem - Used to set keys in a MHD_gtls_cert_credentials_t structure
610 * @res: is an #mhd_gtls_cert_credentials_t structure. 610 * @res: is an #MHD_gtls_cert_credentials_t structure.
611 * @cert: contains a certificate list (path) for the specified private key 611 * @cert: contains a certificate list (path) for the specified private key
612 * @key: is the private key, or %NULL 612 * @key: is the private key, or %NULL
613 * @type: is PEM or DER 613 * @type: is PEM or DER
614 * 614 *
615 * This function sets a certificate/private key pair in the 615 * This function sets a certificate/private key pair in the
616 * mhd_gtls_cert_credentials_t structure. This function may be called 616 * MHD_gtls_cert_credentials_t structure. This function may be called
617 * more than once (in case multiple keys/certificates exist for the 617 * more than once (in case multiple keys/certificates exist for the
618 * server). 618 * server).
619 * 619 *
@@ -636,10 +636,10 @@ read_key_mem (mhd_gtls_cert_credentials_t res,
636 * Returns: %GNUTLS_E_SUCCESS on success, or an error code. 636 * Returns: %GNUTLS_E_SUCCESS on success, or an error code.
637 **/ 637 **/
638int 638int
639MHD_gnutls_certificate_set_x509_key_mem (mhd_gtls_cert_credentials_t 639MHD__gnutls_certificate_set_x509_key_mem (MHD_gtls_cert_credentials_t
640 res, const gnutls_datum_t * cert, 640 res, const MHD_gnutls_datum_t * cert,
641 const gnutls_datum_t * key, 641 const MHD_gnutls_datum_t * key,
642 gnutls_x509_crt_fmt_t type) 642 MHD_gnutls_x509_crt_fmt_t type)
643{ 643{
644 int ret; 644 int ret;
645 645
@@ -654,9 +654,9 @@ MHD_gnutls_certificate_set_x509_key_mem (mhd_gtls_cert_credentials_t
654 654
655 res->ncerts++; 655 res->ncerts++;
656 656
657 if (key && (ret = _gnutls_check_key_cert_match (res)) < 0) 657 if (key && (ret = MHD__gnutls_check_key_cert_match (res)) < 0)
658 { 658 {
659 gnutls_assert (); 659 MHD_gnutls_assert ();
660 return ret; 660 return ret;
661 } 661 }
662 662
@@ -664,9 +664,9 @@ MHD_gnutls_certificate_set_x509_key_mem (mhd_gtls_cert_credentials_t
664} 664}
665 665
666static int 666static int
667generate_rdn_seq (mhd_gtls_cert_credentials_t res) 667generate_rdn_seq (MHD_gtls_cert_credentials_t res)
668{ 668{
669 gnutls_datum_t tmp; 669 MHD_gnutls_datum_t tmp;
670 int ret; 670 int ret;
671 unsigned size, i; 671 unsigned size, i;
672 opaque *pdata; 672 opaque *pdata;
@@ -685,22 +685,22 @@ generate_rdn_seq (mhd_gtls_cert_credentials_t res)
685 size = 0; 685 size = 0;
686 for (i = 0; i < res->x509_ncas; i++) 686 for (i = 0; i < res->x509_ncas; i++)
687 { 687 {
688 if ((ret = gnutls_x509_crt_get_raw_dn (res->x509_ca_list[i], &tmp)) < 0) 688 if ((ret = MHD_gnutls_x509_crt_get_raw_dn (res->x509_ca_list[i], &tmp)) < 0)
689 { 689 {
690 gnutls_assert (); 690 MHD_gnutls_assert ();
691 return ret; 691 return ret;
692 } 692 }
693 size += (2 + tmp.size); 693 size += (2 + tmp.size);
694 _gnutls_free_datum (&tmp); 694 MHD__gnutls_free_datum (&tmp);
695 } 695 }
696 696
697 if (res->x509_rdn_sequence.data != NULL) 697 if (res->x509_rdn_sequence.data != NULL)
698 gnutls_free (res->x509_rdn_sequence.data); 698 MHD_gnutls_free (res->x509_rdn_sequence.data);
699 699
700 res->x509_rdn_sequence.data = gnutls_malloc (size); 700 res->x509_rdn_sequence.data = MHD_gnutls_malloc (size);
701 if (res->x509_rdn_sequence.data == NULL) 701 if (res->x509_rdn_sequence.data == NULL)
702 { 702 {
703 gnutls_assert (); 703 MHD_gnutls_assert ();
704 return GNUTLS_E_MEMORY_ERROR; 704 return GNUTLS_E_MEMORY_ERROR;
705 } 705 }
706 res->x509_rdn_sequence.size = size; 706 res->x509_rdn_sequence.size = size;
@@ -709,16 +709,16 @@ generate_rdn_seq (mhd_gtls_cert_credentials_t res)
709 709
710 for (i = 0; i < res->x509_ncas; i++) 710 for (i = 0; i < res->x509_ncas; i++)
711 { 711 {
712 if ((ret = gnutls_x509_crt_get_raw_dn (res->x509_ca_list[i], &tmp)) < 0) 712 if ((ret = MHD_gnutls_x509_crt_get_raw_dn (res->x509_ca_list[i], &tmp)) < 0)
713 { 713 {
714 _gnutls_free_datum (&res->x509_rdn_sequence); 714 MHD__gnutls_free_datum (&res->x509_rdn_sequence);
715 gnutls_assert (); 715 MHD_gnutls_assert ();
716 return ret; 716 return ret;
717 } 717 }
718 718
719 mhd_gtls_write_datum16 (pdata, tmp); 719 MHD_gtls_write_datum16 (pdata, tmp);
720 pdata += (2 + tmp.size); 720 pdata += (2 + tmp.size);
721 _gnutls_free_datum (&tmp); 721 MHD__gnutls_free_datum (&tmp);
722 } 722 }
723 723
724 return 0; 724 return 0;
@@ -728,7 +728,7 @@ generate_rdn_seq (mhd_gtls_cert_credentials_t res)
728 * certificate (uses the KeyUsage field). 728 * certificate (uses the KeyUsage field).
729 */ 729 */
730int 730int
731_gnutls_check_key_usage (const gnutls_cert * cert, 731MHD__gnutls_check_key_usage (const MHD_gnutls_cert * cert,
732 enum MHD_GNUTLS_KeyExchangeAlgorithm alg) 732 enum MHD_GNUTLS_KeyExchangeAlgorithm alg)
733{ 733{
734 unsigned int key_usage = 0; 734 unsigned int key_usage = 0;
@@ -736,17 +736,17 @@ _gnutls_check_key_usage (const gnutls_cert * cert,
736 736
737 if (cert == NULL) 737 if (cert == NULL)
738 { 738 {
739 gnutls_assert (); 739 MHD_gnutls_assert ();
740 return GNUTLS_E_INTERNAL_ERROR; 740 return GNUTLS_E_INTERNAL_ERROR;
741 } 741 }
742 742
743 if (mhd_gtls_map_kx_get_cred (alg, 1) == MHD_GNUTLS_CRD_CERTIFICATE || 743 if (MHD_gtls_map_kx_get_cred (alg, 1) == MHD_GNUTLS_CRD_CERTIFICATE ||
744 mhd_gtls_map_kx_get_cred (alg, 0) == MHD_GNUTLS_CRD_CERTIFICATE) 744 MHD_gtls_map_kx_get_cred (alg, 0) == MHD_GNUTLS_CRD_CERTIFICATE)
745 { 745 {
746 746
747 key_usage = cert->key_usage; 747 key_usage = cert->key_usage;
748 748
749 encipher_type = mhd_gtls_kx_encipher_type (alg); 749 encipher_type = MHD_gtls_kx_encipher_type (alg);
750 750
751 if (key_usage != 0 && encipher_type != CIPHER_IGN) 751 if (key_usage != 0 && encipher_type != CIPHER_IGN)
752 { 752 {
@@ -761,7 +761,7 @@ _gnutls_check_key_usage (const gnutls_cert * cert,
761 */ 761 */
762 if (!(key_usage & KEY_KEY_ENCIPHERMENT)) 762 if (!(key_usage & KEY_KEY_ENCIPHERMENT))
763 { 763 {
764 gnutls_assert (); 764 MHD_gnutls_assert ();
765 return GNUTLS_E_KEY_USAGE_VIOLATION; 765 return GNUTLS_E_KEY_USAGE_VIOLATION;
766 } 766 }
767 } 767 }
@@ -772,7 +772,7 @@ _gnutls_check_key_usage (const gnutls_cert * cert,
772 */ 772 */
773 if (!(key_usage & KEY_DIGITAL_SIGNATURE)) 773 if (!(key_usage & KEY_DIGITAL_SIGNATURE))
774 { 774 {
775 gnutls_assert (); 775 MHD_gnutls_assert ();
776 return GNUTLS_E_KEY_USAGE_VIOLATION; 776 return GNUTLS_E_KEY_USAGE_VIOLATION;
777 } 777 }
778 } 778 }
@@ -784,25 +784,25 @@ _gnutls_check_key_usage (const gnutls_cert * cert,
784 784
785 785
786static int 786static int
787parse_pem_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts, 787parse_pem_ca_mem (MHD_gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
788 const opaque * input_cert, int input_cert_size) 788 const opaque * input_cert, int input_cert_size)
789{ 789{
790 int i, size; 790 int i, size;
791 const opaque *ptr; 791 const opaque *ptr;
792 gnutls_datum_t tmp; 792 MHD_gnutls_datum_t tmp;
793 int ret, count; 793 int ret, count;
794 794
795 /* move to the certificate 795 /* move to the certificate
796 */ 796 */
797 ptr = memmem (input_cert, input_cert_size, 797 ptr = MHD_memmem (input_cert, input_cert_size,
798 PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); 798 PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
799 if (ptr == NULL) 799 if (ptr == NULL)
800 ptr = memmem (input_cert, input_cert_size, 800 ptr = MHD_memmem (input_cert, input_cert_size,
801 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); 801 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
802 802
803 if (ptr == NULL) 803 if (ptr == NULL)
804 { 804 {
805 gnutls_assert (); 805 MHD_gnutls_assert ();
806 return GNUTLS_E_BASE64_DECODING_ERROR; 806 return GNUTLS_E_BASE64_DECODING_ERROR;
807 } 807 }
808 size = input_cert_size - (ptr - input_cert); 808 size = input_cert_size - (ptr - input_cert);
@@ -814,21 +814,21 @@ parse_pem_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
814 { 814 {
815 815
816 *cert_list = 816 *cert_list =
817 (gnutls_x509_crt_t *) mhd_gtls_realloc_fast (*cert_list, 817 (MHD_gnutls_x509_crt_t *) MHD_gtls_realloc_fast (*cert_list,
818 i * 818 i *
819 sizeof 819 sizeof
820 (gnutls_x509_crt_t)); 820 (MHD_gnutls_x509_crt_t));
821 821
822 if (*cert_list == NULL) 822 if (*cert_list == NULL)
823 { 823 {
824 gnutls_assert (); 824 MHD_gnutls_assert ();
825 return GNUTLS_E_MEMORY_ERROR; 825 return GNUTLS_E_MEMORY_ERROR;
826 } 826 }
827 827
828 ret = gnutls_x509_crt_init (&cert_list[0][i - 1]); 828 ret = MHD_gnutls_x509_crt_init (&cert_list[0][i - 1]);
829 if (ret < 0) 829 if (ret < 0)
830 { 830 {
831 gnutls_assert (); 831 MHD_gnutls_assert ();
832 return ret; 832 return ret;
833 } 833 }
834 834
@@ -836,11 +836,11 @@ parse_pem_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
836 tmp.size = size; 836 tmp.size = size;
837 837
838 ret = 838 ret =
839 gnutls_x509_crt_import (cert_list[0][i - 1], 839 MHD_gnutls_x509_crt_import (cert_list[0][i - 1],
840 &tmp, GNUTLS_X509_FMT_PEM); 840 &tmp, GNUTLS_X509_FMT_PEM);
841 if (ret < 0) 841 if (ret < 0)
842 { 842 {
843 gnutls_assert (); 843 MHD_gnutls_assert ();
844 return ret; 844 return ret;
845 } 845 }
846 846
@@ -855,9 +855,9 @@ parse_pem_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
855 { 855 {
856 char *ptr3; 856 char *ptr3;
857 857
858 ptr3 = memmem (ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1); 858 ptr3 = MHD_memmem (ptr, size, PEM_CERT_SEP, sizeof (PEM_CERT_SEP) - 1);
859 if (ptr3 == NULL) 859 if (ptr3 == NULL)
860 ptr3 = memmem (ptr, size, 860 ptr3 = MHD_memmem (ptr, size,
861 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1); 861 PEM_CERT_SEP2, sizeof (PEM_CERT_SEP2) - 1);
862 862
863 ptr = (const opaque *) ptr3; 863 ptr = (const opaque *) ptr3;
@@ -878,45 +878,45 @@ parse_pem_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
878} 878}
879 879
880/* Reads a DER encoded certificate list from memory and stores it to 880/* Reads a DER encoded certificate list from memory and stores it to
881 * a gnutls_cert structure. 881 * a MHD_gnutls_cert structure.
882 * returns the number of certificates parsed. 882 * returns the number of certificates parsed.
883 */ 883 */
884static int 884static int
885parse_der_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts, 885parse_der_ca_mem (MHD_gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
886 const void *input_cert, int input_cert_size) 886 const void *input_cert, int input_cert_size)
887{ 887{
888 int i; 888 int i;
889 gnutls_datum_t tmp; 889 MHD_gnutls_datum_t tmp;
890 int ret; 890 int ret;
891 891
892 i = *ncerts + 1; 892 i = *ncerts + 1;
893 893
894 *cert_list = 894 *cert_list =
895 (gnutls_x509_crt_t *) mhd_gtls_realloc_fast (*cert_list, 895 (MHD_gnutls_x509_crt_t *) MHD_gtls_realloc_fast (*cert_list,
896 i * 896 i *
897 sizeof (gnutls_x509_crt_t)); 897 sizeof (MHD_gnutls_x509_crt_t));
898 898
899 if (*cert_list == NULL) 899 if (*cert_list == NULL)
900 { 900 {
901 gnutls_assert (); 901 MHD_gnutls_assert ();
902 return GNUTLS_E_MEMORY_ERROR; 902 return GNUTLS_E_MEMORY_ERROR;
903 } 903 }
904 904
905 tmp.data = (opaque *) input_cert; 905 tmp.data = (opaque *) input_cert;
906 tmp.size = input_cert_size; 906 tmp.size = input_cert_size;
907 907
908 ret = gnutls_x509_crt_init (&cert_list[0][i - 1]); 908 ret = MHD_gnutls_x509_crt_init (&cert_list[0][i - 1]);
909 if (ret < 0) 909 if (ret < 0)
910 { 910 {
911 gnutls_assert (); 911 MHD_gnutls_assert ();
912 return ret; 912 return ret;
913 } 913 }
914 914
915 ret = 915 ret =
916 gnutls_x509_crt_import (cert_list[0][i - 1], &tmp, GNUTLS_X509_FMT_DER); 916 MHD_gnutls_x509_crt_import (cert_list[0][i - 1], &tmp, GNUTLS_X509_FMT_DER);
917 if (ret < 0) 917 if (ret < 0)
918 { 918 {
919 gnutls_assert (); 919 MHD_gnutls_assert ();
920 return ret; 920 return ret;
921 } 921 }
922 922
@@ -926,8 +926,8 @@ parse_der_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
926} 926}
927 927
928/** 928/**
929 * MHD_gnutls_certificate_set_x509_trust_mem - Used to add trusted CAs in a mhd_gtls_cert_credentials_t structure 929 * MHD__gnutls_certificate_set_x509_trust_mem - Used to add trusted CAs in a MHD_gtls_cert_credentials_t structure
930 * @res: is an #mhd_gtls_cert_credentials_t structure. 930 * @res: is an #MHD_gtls_cert_credentials_t structure.
931 * @ca: is a list of trusted CAs or a DER certificate 931 * @ca: is a list of trusted CAs or a DER certificate
932 * @type: is DER or PEM 932 * @type: is DER or PEM
933 * 933 *
@@ -939,15 +939,15 @@ parse_der_ca_mem (gnutls_x509_crt_t ** cert_list, unsigned *ncerts,
939 * 939 *
940 * In case of a server the CAs set here will be sent to the client if 940 * In case of a server the CAs set here will be sent to the client if
941 * a certificate request is sent. This can be disabled using 941 * a certificate request is sent. This can be disabled using
942 * MHD_gnutls_certificate_send_x509_rdn_sequence(). 942 * MHD__gnutls_certificate_send_x509_rdn_sequence().
943 * 943 *
944 * Returns: the number of certificates processed or a negative value 944 * Returns: the number of certificates processed or a negative value
945 * on error. 945 * on error.
946 **/ 946 **/
947int 947int
948MHD_gnutls_certificate_set_x509_trust_mem (mhd_gtls_cert_credentials_t 948MHD__gnutls_certificate_set_x509_trust_mem (MHD_gtls_cert_credentials_t
949 res, const gnutls_datum_t * ca, 949 res, const MHD_gnutls_datum_t * ca,
950 gnutls_x509_crt_fmt_t type) 950 MHD_gnutls_x509_crt_fmt_t type)
951{ 951{
952 int ret, ret2; 952 int ret, ret2;
953 953
@@ -967,21 +967,21 @@ MHD_gnutls_certificate_set_x509_trust_mem (mhd_gtls_cert_credentials_t
967#ifdef ENABLE_PKI 967#ifdef ENABLE_PKI
968 968
969static int 969static int
970parse_pem_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls, 970parse_pem_crl_mem (MHD_gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
971 const opaque * input_crl, int input_crl_size) 971 const opaque * input_crl, int input_crl_size)
972{ 972{
973 int size, i; 973 int size, i;
974 const opaque *ptr; 974 const opaque *ptr;
975 gnutls_datum_t tmp; 975 MHD_gnutls_datum_t tmp;
976 int ret, count; 976 int ret, count;
977 977
978 /* move to the certificate 978 /* move to the certificate
979 */ 979 */
980 ptr = memmem (input_crl, input_crl_size, 980 ptr = MHD_memmem (input_crl, input_crl_size,
981 PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1); 981 PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1);
982 if (ptr == NULL) 982 if (ptr == NULL)
983 { 983 {
984 gnutls_assert (); 984 MHD_gnutls_assert ();
985 return GNUTLS_E_BASE64_DECODING_ERROR; 985 return GNUTLS_E_BASE64_DECODING_ERROR;
986 } 986 }
987 987
@@ -994,21 +994,21 @@ parse_pem_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
994 { 994 {
995 995
996 *crl_list = 996 *crl_list =
997 (gnutls_x509_crl_t *) mhd_gtls_realloc_fast (*crl_list, 997 (MHD_gnutls_x509_crl_t *) MHD_gtls_realloc_fast (*crl_list,
998 i * 998 i *
999 sizeof 999 sizeof
1000 (gnutls_x509_crl_t)); 1000 (MHD_gnutls_x509_crl_t));
1001 1001
1002 if (*crl_list == NULL) 1002 if (*crl_list == NULL)
1003 { 1003 {
1004 gnutls_assert (); 1004 MHD_gnutls_assert ();
1005 return GNUTLS_E_MEMORY_ERROR; 1005 return GNUTLS_E_MEMORY_ERROR;
1006 } 1006 }
1007 1007
1008 ret = gnutls_x509_crl_init (&crl_list[0][i - 1]); 1008 ret = MHD_gnutls_x509_crl_init (&crl_list[0][i - 1]);
1009 if (ret < 0) 1009 if (ret < 0)
1010 { 1010 {
1011 gnutls_assert (); 1011 MHD_gnutls_assert ();
1012 return ret; 1012 return ret;
1013 } 1013 }
1014 1014
@@ -1016,11 +1016,11 @@ parse_pem_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
1016 tmp.size = size; 1016 tmp.size = size;
1017 1017
1018 ret = 1018 ret =
1019 gnutls_x509_crl_import (crl_list[0][i - 1], 1019 MHD_gnutls_x509_crl_import (crl_list[0][i - 1],
1020 &tmp, GNUTLS_X509_FMT_PEM); 1020 &tmp, GNUTLS_X509_FMT_PEM);
1021 if (ret < 0) 1021 if (ret < 0)
1022 { 1022 {
1023 gnutls_assert (); 1023 MHD_gnutls_assert ();
1024 return ret; 1024 return ret;
1025 } 1025 }
1026 1026
@@ -1033,7 +1033,7 @@ parse_pem_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
1033 size = input_crl_size - (ptr - input_crl); 1033 size = input_crl_size - (ptr - input_crl);
1034 1034
1035 if (size > 0) 1035 if (size > 0)
1036 ptr = memmem (ptr, size, PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1); 1036 ptr = MHD_memmem (ptr, size, PEM_CRL_SEP, sizeof (PEM_CRL_SEP) - 1);
1037 else 1037 else
1038 ptr = NULL; 1038 ptr = NULL;
1039 i++; 1039 i++;
@@ -1048,45 +1048,45 @@ parse_pem_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
1048} 1048}
1049 1049
1050/* Reads a DER encoded certificate list from memory and stores it to 1050/* Reads a DER encoded certificate list from memory and stores it to
1051 * a gnutls_cert structure. 1051 * a MHD_gnutls_cert structure.
1052 * returns the number of certificates parsed. 1052 * returns the number of certificates parsed.
1053 */ 1053 */
1054static int 1054static int
1055parse_der_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls, 1055parse_der_crl_mem (MHD_gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
1056 const void *input_crl, int input_crl_size) 1056 const void *input_crl, int input_crl_size)
1057{ 1057{
1058 int i; 1058 int i;
1059 gnutls_datum_t tmp; 1059 MHD_gnutls_datum_t tmp;
1060 int ret; 1060 int ret;
1061 1061
1062 i = *ncrls + 1; 1062 i = *ncrls + 1;
1063 1063
1064 *crl_list = 1064 *crl_list =
1065 (gnutls_x509_crl_t *) mhd_gtls_realloc_fast (*crl_list, 1065 (MHD_gnutls_x509_crl_t *) MHD_gtls_realloc_fast (*crl_list,
1066 i * 1066 i *
1067 sizeof (gnutls_x509_crl_t)); 1067 sizeof (MHD_gnutls_x509_crl_t));
1068 1068
1069 if (*crl_list == NULL) 1069 if (*crl_list == NULL)
1070 { 1070 {
1071 gnutls_assert (); 1071 MHD_gnutls_assert ();
1072 return GNUTLS_E_MEMORY_ERROR; 1072 return GNUTLS_E_MEMORY_ERROR;
1073 } 1073 }
1074 1074
1075 tmp.data = (opaque *) input_crl; 1075 tmp.data = (opaque *) input_crl;
1076 tmp.size = input_crl_size; 1076 tmp.size = input_crl_size;
1077 1077
1078 ret = gnutls_x509_crl_init (&crl_list[0][i - 1]); 1078 ret = MHD_gnutls_x509_crl_init (&crl_list[0][i - 1]);
1079 if (ret < 0) 1079 if (ret < 0)
1080 { 1080 {
1081 gnutls_assert (); 1081 MHD_gnutls_assert ();
1082 return ret; 1082 return ret;
1083 } 1083 }
1084 1084
1085 ret = 1085 ret =
1086 gnutls_x509_crl_import (crl_list[0][i - 1], &tmp, GNUTLS_X509_FMT_DER); 1086 MHD_gnutls_x509_crl_import (crl_list[0][i - 1], &tmp, GNUTLS_X509_FMT_DER);
1087 if (ret < 0) 1087 if (ret < 0)
1088 { 1088 {
1089 gnutls_assert (); 1089 MHD_gnutls_assert ();
1090 return ret; 1090 return ret;
1091 } 1091 }
1092 1092
@@ -1099,20 +1099,20 @@ parse_der_crl_mem (gnutls_x509_crl_t ** crl_list, unsigned *ncrls,
1099/* Reads a DER or PEM CRL from memory 1099/* Reads a DER or PEM CRL from memory
1100 */ 1100 */
1101static int 1101static int
1102read_crl_mem (mhd_gtls_cert_credentials_t res, const void *crl, 1102read_crl_mem (MHD_gtls_cert_credentials_t res, const void *crl,
1103 int crl_size, gnutls_x509_crt_fmt_t type) 1103 int crl_size, MHD_gnutls_x509_crt_fmt_t type)
1104{ 1104{
1105 int ret; 1105 int ret;
1106 1106
1107 /* allocate space for the certificate to add 1107 /* allocate space for the certificate to add
1108 */ 1108 */
1109 res->x509_crl_list = mhd_gtls_realloc_fast (res->x509_crl_list, 1109 res->x509_crl_list = MHD_gtls_realloc_fast (res->x509_crl_list,
1110 (1 + 1110 (1 +
1111 res->x509_ncrls) * 1111 res->x509_ncrls) *
1112 sizeof (gnutls_x509_crl_t)); 1112 sizeof (MHD_gnutls_x509_crl_t));
1113 if (res->x509_crl_list == NULL) 1113 if (res->x509_crl_list == NULL)
1114 { 1114 {
1115 gnutls_assert (); 1115 MHD_gnutls_assert ();
1116 return GNUTLS_E_MEMORY_ERROR; 1116 return GNUTLS_E_MEMORY_ERROR;
1117 } 1117 }
1118 1118
@@ -1125,7 +1125,7 @@ read_crl_mem (mhd_gtls_cert_credentials_t res, const void *crl,
1125 1125
1126 if (ret < 0) 1126 if (ret < 0)
1127 { 1127 {
1128 gnutls_assert (); 1128 MHD_gnutls_assert ();
1129 return ret; 1129 return ret;
1130 } 1130 }
1131 1131
@@ -1133,8 +1133,8 @@ read_crl_mem (mhd_gtls_cert_credentials_t res, const void *crl,
1133} 1133}
1134 1134
1135/** 1135/**
1136 * MHD_gnutls_certificate_set_x509_crl_mem - Used to add CRLs in a mhd_gtls_cert_credentials_t structure 1136 * MHD__gnutls_certificate_set_x509_crl_mem - Used to add CRLs in a MHD_gtls_cert_credentials_t structure
1137 * @res: is an #mhd_gtls_cert_credentials_t structure. 1137 * @res: is an #MHD_gtls_cert_credentials_t structure.
1138 * @CRL: is a list of trusted CRLs. They should have been verified before. 1138 * @CRL: is a list of trusted CRLs. They should have been verified before.
1139 * @type: is DER or PEM 1139 * @type: is DER or PEM
1140 * 1140 *
@@ -1147,9 +1147,9 @@ read_crl_mem (mhd_gtls_cert_credentials_t res, const void *crl,
1147 * Returns: number of CRLs processed, or a negative value on error. 1147 * Returns: number of CRLs processed, or a negative value on error.
1148 **/ 1148 **/
1149int 1149int
1150MHD_gnutls_certificate_set_x509_crl_mem (mhd_gtls_cert_credentials_t 1150MHD__gnutls_certificate_set_x509_crl_mem (MHD_gtls_cert_credentials_t
1151 res, const gnutls_datum_t * CRL, 1151 res, const MHD_gnutls_datum_t * CRL,
1152 gnutls_x509_crt_fmt_t type) 1152 MHD_gnutls_x509_crt_fmt_t type)
1153{ 1153{
1154 int ret; 1154 int ret;
1155 1155
@@ -1162,26 +1162,26 @@ MHD_gnutls_certificate_set_x509_crl_mem (mhd_gtls_cert_credentials_t
1162#include <pkcs12.h> 1162#include <pkcs12.h>
1163 1163
1164/** 1164/**
1165 * MHD_gnutls_certificate_free_crls - Used to free all the CRLs from a mhd_gtls_cert_credentials_t structure 1165 * MHD__gnutls_certificate_free_crls - Used to free all the CRLs from a MHD_gtls_cert_credentials_t structure
1166 * @sc: is an #mhd_gtls_cert_credentials_t structure. 1166 * @sc: is an #MHD_gtls_cert_credentials_t structure.
1167 * 1167 *
1168 * This function will delete all the CRLs associated 1168 * This function will delete all the CRLs associated
1169 * with the given credentials. 1169 * with the given credentials.
1170 * 1170 *
1171 **/ 1171 **/
1172void 1172void
1173MHD_gnutls_certificate_free_crls (mhd_gtls_cert_credentials_t sc) 1173MHD__gnutls_certificate_free_crls (MHD_gtls_cert_credentials_t sc)
1174{ 1174{
1175 unsigned j; 1175 unsigned j;
1176 1176
1177 for (j = 0; j < sc->x509_ncrls; j++) 1177 for (j = 0; j < sc->x509_ncrls; j++)
1178 { 1178 {
1179 gnutls_x509_crl_deinit (sc->x509_crl_list[j]); 1179 MHD_gnutls_x509_crl_deinit (sc->x509_crl_list[j]);
1180 } 1180 }
1181 1181
1182 sc->x509_ncrls = 0; 1182 sc->x509_ncrls = 0;
1183 1183
1184 gnutls_free (sc->x509_crl_list); 1184 MHD_gnutls_free (sc->x509_crl_list);
1185 sc->x509_crl_list = NULL; 1185 sc->x509_crl_list = NULL;
1186} 1186}
1187 1187
diff --git a/src/daemon/https/tls/gnutls_x509.h b/src/daemon/https/tls/gnutls_x509.h
index b0135d95..b2d92603 100644
--- a/src/daemon/https/tls/gnutls_x509.h
+++ b/src/daemon/https/tls/gnutls_x509.h
@@ -24,7 +24,7 @@
24 24
25#include <libtasn1.h> 25#include <libtasn1.h>
26 26
27int _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session, 27int MHD__gnutls_x509_cert_verify_peers (MHD_gtls_session_t session,
28 unsigned int *status); 28 unsigned int *status);
29 29
30#define PEM_CERT_SEP2 "-----BEGIN X509 CERTIFICATE" 30#define PEM_CERT_SEP2 "-----BEGIN X509 CERTIFICATE"
@@ -35,14 +35,14 @@ int _gnutls_x509_cert_verify_peers (mhd_gtls_session_t session,
35#define PEM_KEY_RSA_SEP "-----BEGIN RSA" 35#define PEM_KEY_RSA_SEP "-----BEGIN RSA"
36#define PEM_KEY_DSA_SEP "-----BEGIN DSA" 36#define PEM_KEY_DSA_SEP "-----BEGIN DSA"
37 37
38int _gnutls_check_key_usage (const gnutls_cert * cert, 38int MHD__gnutls_check_key_usage (const MHD_gnutls_cert * cert,
39 enum MHD_GNUTLS_KeyExchangeAlgorithm alg); 39 enum MHD_GNUTLS_KeyExchangeAlgorithm alg);
40 40
41int _gnutls_x509_read_rsa_params (opaque * der, int dersize, mpi_t * params); 41int MHD__gnutls_x509_read_rsa_params (opaque * der, int dersize, mpi_t * params);
42int _gnutls_x509_read_dsa_pubkey (opaque * der, int dersize, mpi_t * params); 42int MHD__gnutls_x509_read_dsa_pubkey (opaque * der, int dersize, mpi_t * params);
43 43
44int _gnutls_x509_raw_privkey_to_gkey (gnutls_privkey * privkey, 44int MHD__gnutls_x509_raw_privkey_to_gkey (MHD_gnutls_privkey * privkey,
45 const gnutls_datum_t * raw_key, 45 const MHD_gnutls_datum_t * raw_key,
46 gnutls_x509_crt_fmt_t type); 46 MHD_gnutls_x509_crt_fmt_t type);
47int _gnutls_x509_privkey_to_gkey (gnutls_privkey * privkey, 47int MHD__gnutls_x509_privkey_to_gkey (MHD_gnutls_privkey * privkey,
48 gnutls_x509_privkey_t); 48 MHD_gnutls_x509_privkey_t);
diff --git a/src/daemon/https/tls/pkix_asn1_tab.c b/src/daemon/https/tls/pkix_asn1_tab.c
index e8471bfd..30b5ddd1 100644
--- a/src/daemon/https/tls/pkix_asn1_tab.c
+++ b/src/daemon/https/tls/pkix_asn1_tab.c
@@ -4,7 +4,7 @@
4 4
5#include <libtasn1.h> 5#include <libtasn1.h>
6 6
7const ASN1_ARRAY_TYPE pkix_asn1_tab[] = { 7const ASN1_ARRAY_TYPE MHD_pkix_asn1_tab[] = {
8 {"PKIX1", 536875024, 0}, 8 {"PKIX1", 536875024, 0},
9 {0, 1073741836, 0}, 9 {0, 1073741836, 0},
10 {"id-ce", 1879048204, 0}, 10 {"id-ce", 1879048204, 0},
diff --git a/src/daemon/https/tls/x509_b64.c b/src/daemon/https/tls/x509_b64.c
index d4100bc9..b19e301f 100644
--- a/src/daemon/https/tls/x509_b64.c
+++ b/src/daemon/https/tls/x509_b64.c
@@ -142,7 +142,7 @@ decode (uint8_t * result, const opaque * data)
142 * The result_size is the return value 142 * The result_size is the return value
143 */ 143 */
144int 144int
145_gnutls_base64_encode (const uint8_t * data, size_t data_size, 145MHD__gnutls_base64_encode (const uint8_t * data, size_t data_size,
146 uint8_t ** result) 146 uint8_t ** result)
147{ 147{
148 unsigned int i, j; 148 unsigned int i, j;
@@ -151,7 +151,7 @@ _gnutls_base64_encode (const uint8_t * data, size_t data_size,
151 151
152 ret = B64SIZE (data_size); 152 ret = B64SIZE (data_size);
153 153
154 (*result) = gnutls_malloc (ret + 1); 154 (*result) = MHD_gnutls_malloc (ret + 1);
155 if ((*result) == NULL) 155 if ((*result) == NULL)
156 return GNUTLS_E_MEMORY_ERROR; 156 return GNUTLS_E_MEMORY_ERROR;
157 157
@@ -160,7 +160,7 @@ _gnutls_base64_encode (const uint8_t * data, size_t data_size,
160 tmp = encode (tmpres, &data[i], data_size - i); 160 tmp = encode (tmpres, &data[i], data_size - i);
161 if (tmp == -1) 161 if (tmp == -1)
162 { 162 {
163 gnutls_free ((*result)); 163 MHD_gnutls_free ((*result));
164 return GNUTLS_E_MEMORY_ERROR; 164 return GNUTLS_E_MEMORY_ERROR;
165 } 165 }
166 memcpy (&(*result)[j], tmpres, tmp); 166 memcpy (&(*result)[j], tmpres, tmp);
@@ -174,8 +174,8 @@ _gnutls_base64_encode (const uint8_t * data, size_t data_size,
174 do { \ 174 do { \
175 what+=size; \ 175 what+=size; \
176 if (what > ret) { \ 176 if (what > ret) { \
177 gnutls_assert(); \ 177 MHD_gnutls_assert(); \
178 gnutls_free( (*result)); *result = NULL; \ 178 MHD_gnutls_free( (*result)); *result = NULL; \
179 return GNUTLS_E_INTERNAL_ERROR; \ 179 return GNUTLS_E_INTERNAL_ERROR; \
180 } \ 180 } \
181 } while(0) 181 } while(0)
@@ -184,7 +184,7 @@ _gnutls_base64_encode (const uint8_t * data, size_t data_size,
184 * The result_size (including the null terminator) is the return value. 184 * The result_size (including the null terminator) is the return value.
185 */ 185 */
186int 186int
187_gnutls_fbase64_encode (const char *msg, const uint8_t * data, 187MHD__gnutls_fbase64_encode (const char *msg, const uint8_t * data,
188 int data_size, uint8_t ** result) 188 int data_size, uint8_t ** result)
189{ 189{
190 int i, ret, tmp, j; 190 int i, ret, tmp, j;
@@ -197,7 +197,7 @@ _gnutls_fbase64_encode (const char *msg, const uint8_t * data,
197 197
198 if (msglen > 50) 198 if (msglen > 50)
199 { 199 {
200 gnutls_assert (); 200 MHD_gnutls_assert ();
201 return GNUTLS_E_BASE64_ENCODING_ERROR; 201 return GNUTLS_E_BASE64_ENCODING_ERROR;
202 } 202 }
203 203
@@ -217,10 +217,10 @@ _gnutls_fbase64_encode (const char *msg, const uint8_t * data,
217 217
218 ret = B64FSIZE (msglen, data_size); 218 ret = B64FSIZE (msglen, data_size);
219 219
220 (*result) = gnutls_calloc (1, ret + 1); 220 (*result) = MHD_gnutls_calloc (1, ret + 1);
221 if ((*result) == NULL) 221 if ((*result) == NULL)
222 { 222 {
223 gnutls_assert (); 223 MHD_gnutls_assert ();
224 return GNUTLS_E_MEMORY_ERROR; 224 return GNUTLS_E_MEMORY_ERROR;
225 } 225 }
226 226
@@ -236,8 +236,8 @@ _gnutls_fbase64_encode (const char *msg, const uint8_t * data,
236 tmp = encode (tmpres, &data[i], data_size - i); 236 tmp = encode (tmpres, &data[i], data_size - i);
237 if (tmp == -1) 237 if (tmp == -1)
238 { 238 {
239 gnutls_assert (); 239 MHD_gnutls_assert ();
240 gnutls_free ((*result)); 240 MHD_gnutls_free ((*result));
241 *result = NULL; 241 *result = NULL;
242 return GNUTLS_E_BASE64_ENCODING_ERROR; 242 return GNUTLS_E_BASE64_ENCODING_ERROR;
243 } 243 }
@@ -302,26 +302,26 @@ _gnutls_fbase64_encode (const char *msg, const uint8_t * data,
302 * 302 *
303 **/ 303 **/
304int 304int
305MHD_gtls_pem_base64_encode (const char *msg, const gnutls_datum_t * data, 305MHD_gtls_pem_base64_encode (const char *msg, const MHD_gnutls_datum_t * data,
306 char *result, size_t * result_size) 306 char *result, size_t * result_size)
307{ 307{
308 opaque *ret; 308 opaque *ret;
309 int size; 309 int size;
310 310
311 size = _gnutls_fbase64_encode (msg, data->data, data->size, &ret); 311 size = MHD__gnutls_fbase64_encode (msg, data->data, data->size, &ret);
312 if (size < 0) 312 if (size < 0)
313 return size; 313 return size;
314 314
315 if (result == NULL || *result_size < (unsigned) size) 315 if (result == NULL || *result_size < (unsigned) size)
316 { 316 {
317 gnutls_free (ret); 317 MHD_gnutls_free (ret);
318 *result_size = size; 318 *result_size = size;
319 return GNUTLS_E_SHORT_MEMORY_BUFFER; 319 return GNUTLS_E_SHORT_MEMORY_BUFFER;
320 } 320 }
321 else 321 else
322 { 322 {
323 memcpy (result, ret, size); 323 memcpy (result, ret, size);
324 gnutls_free (ret); 324 MHD_gnutls_free (ret);
325 *result_size = size - 1; 325 *result_size = size - 1;
326 } 326 }
327 327
@@ -338,13 +338,13 @@ MHD_gtls_pem_base64_encode (const char *msg, const gnutls_datum_t * data,
338 * encoding. This is the encoding used in PEM messages. This function will 338 * encoding. This is the encoding used in PEM messages. This function will
339 * allocate the required memory to hold the encoded data. 339 * allocate the required memory to hold the encoded data.
340 * 340 *
341 * You should use gnutls_free() to free the returned data. 341 * You should use MHD_gnutls_free() to free the returned data.
342 * 342 *
343 **/ 343 **/
344int 344int
345MHD_gtls_pem_base64_encode_alloc (const char *msg, 345MHD_gtls_pem_base64_encode_alloc (const char *msg,
346 const gnutls_datum_t * data, 346 const MHD_gnutls_datum_t * data,
347 gnutls_datum_t * result) 347 MHD_gnutls_datum_t * result)
348{ 348{
349 opaque *ret; 349 opaque *ret;
350 int size; 350 int size;
@@ -352,7 +352,7 @@ MHD_gtls_pem_base64_encode_alloc (const char *msg,
352 if (result == NULL) 352 if (result == NULL)
353 return GNUTLS_E_INVALID_REQUEST; 353 return GNUTLS_E_INVALID_REQUEST;
354 354
355 size = _gnutls_fbase64_encode (msg, data->data, data->size, &ret); 355 size = MHD__gnutls_fbase64_encode (msg, data->data, data->size, &ret);
356 if (size < 0) 356 if (size < 0)
357 return size; 357 return size;
358 358
@@ -366,7 +366,7 @@ MHD_gtls_pem_base64_encode_alloc (const char *msg,
366 * The result_size is the return value 366 * The result_size is the return value
367 */ 367 */
368int 368int
369_gnutls_base64_decode (const uint8_t * data, size_t data_size, 369MHD__gnutls_base64_decode (const uint8_t * data, size_t data_size,
370 uint8_t ** result) 370 uint8_t ** result)
371{ 371{
372 unsigned int i, j; 372 unsigned int i, j;
@@ -374,7 +374,7 @@ _gnutls_base64_decode (const uint8_t * data, size_t data_size,
374 uint8_t tmpres[3]; 374 uint8_t tmpres[3];
375 375
376 est = ((data_size * 3) / 4) + 1; 376 est = ((data_size * 3) / 4) + 1;
377 (*result) = gnutls_malloc (est); 377 (*result) = MHD_gnutls_malloc (est);
378 if ((*result) == NULL) 378 if ((*result) == NULL)
379 return GNUTLS_E_MEMORY_ERROR; 379 return GNUTLS_E_MEMORY_ERROR;
380 380
@@ -384,7 +384,7 @@ _gnutls_base64_decode (const uint8_t * data, size_t data_size,
384 tmp = decode (tmpres, &data[i]); 384 tmp = decode (tmpres, &data[i]);
385 if (tmp < 0) 385 if (tmp < 0)
386 { 386 {
387 gnutls_free (*result); 387 MHD_gnutls_free (*result);
388 *result = NULL; 388 *result = NULL;
389 return tmp; 389 return tmp;
390 } 390 }
@@ -402,7 +402,7 @@ cpydata (const uint8_t * data, int data_size, uint8_t ** result)
402{ 402{
403 int i, j; 403 int i, j;
404 404
405 (*result) = gnutls_malloc (data_size); 405 (*result) = MHD_gnutls_malloc (data_size);
406 if (*result == NULL) 406 if (*result == NULL)
407 return GNUTLS_E_MEMORY_ERROR; 407 return GNUTLS_E_MEMORY_ERROR;
408 408
@@ -424,7 +424,7 @@ cpydata (const uint8_t * data, int data_size, uint8_t ** result)
424#define ENDSTR "-----\n" 424#define ENDSTR "-----\n"
425#define ENDSTR2 "-----\r" 425#define ENDSTR2 "-----\r"
426int 426int
427_gnutls_fbase64_decode (const char *header, const opaque * data, 427MHD__gnutls_fbase64_decode (const char *header, const opaque * data,
428 size_t data_size, uint8_t ** result) 428 size_t data_size, uint8_t ** result)
429{ 429{
430 int ret; 430 int ret;
@@ -436,16 +436,16 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
436 int kdata_size; 436 int kdata_size;
437 char pem_header[128]; 437 char pem_header[128];
438 438
439 mhd_gtls_str_cpy (pem_header, sizeof (pem_header), top); 439 MHD_gtls_str_cpy (pem_header, sizeof (pem_header), top);
440 if (header != NULL) 440 if (header != NULL)
441 mhd_gtls_str_cat (pem_header, sizeof (pem_header), header); 441 MHD_gtls_str_cat (pem_header, sizeof (pem_header), header);
442 442
443 rdata = memmem (data, data_size, pem_header, strlen (pem_header)); 443 rdata = MHD_memmem (data, data_size, pem_header, strlen (pem_header));
444 444
445 if (rdata == NULL) 445 if (rdata == NULL)
446 { 446 {
447 gnutls_assert (); 447 MHD_gnutls_assert ();
448 _gnutls_debug_log ("Could not find '%s'\n", pem_header); 448 MHD__gnutls_debug_log ("Could not find '%s'\n", pem_header);
449 return GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR; 449 return GNUTLS_E_BASE64_UNEXPECTED_HEADER_ERROR;
450 } 450 }
451 451
@@ -453,20 +453,20 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
453 453
454 if (data_size < 4 + strlen (bottom)) 454 if (data_size < 4 + strlen (bottom))
455 { 455 {
456 gnutls_assert (); 456 MHD_gnutls_assert ();
457 return GNUTLS_E_BASE64_DECODING_ERROR; 457 return GNUTLS_E_BASE64_DECODING_ERROR;
458 } 458 }
459 459
460 kdata = memmem (rdata, data_size, ENDSTR, sizeof (ENDSTR) - 1); 460 kdata = MHD_memmem (rdata, data_size, ENDSTR, sizeof (ENDSTR) - 1);
461 /* allow CR as well. 461 /* allow CR as well.
462 */ 462 */
463 if (kdata == NULL) 463 if (kdata == NULL)
464 kdata = memmem (rdata, data_size, ENDSTR2, sizeof (ENDSTR2) - 1); 464 kdata = MHD_memmem (rdata, data_size, ENDSTR2, sizeof (ENDSTR2) - 1);
465 465
466 if (kdata == NULL) 466 if (kdata == NULL)
467 { 467 {
468 gnutls_assert (); 468 MHD_gnutls_assert ();
469 _gnutls_x509_log ("Could not find '%s'\n", ENDSTR); 469 MHD__gnutls_x509_log ("Could not find '%s'\n", ENDSTR);
470 return GNUTLS_E_BASE64_DECODING_ERROR; 470 return GNUTLS_E_BASE64_DECODING_ERROR;
471 } 471 }
472 data_size -= strlen (ENDSTR); 472 data_size -= strlen (ENDSTR);
@@ -476,10 +476,10 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
476 476
477 /* position is now after the ---BEGIN--- headers */ 477 /* position is now after the ---BEGIN--- headers */
478 478
479 kdata = memmem (rdata, data_size, bottom, strlen (bottom)); 479 kdata = MHD_memmem (rdata, data_size, bottom, strlen (bottom));
480 if (kdata == NULL) 480 if (kdata == NULL)
481 { 481 {
482 gnutls_assert (); 482 MHD_gnutls_assert ();
483 return GNUTLS_E_BASE64_DECODING_ERROR; 483 return GNUTLS_E_BASE64_DECODING_ERROR;
484 } 484 }
485 485
@@ -489,7 +489,7 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
489 489
490 if (rdata_size < 4) 490 if (rdata_size < 4)
491 { 491 {
492 gnutls_assert (); 492 MHD_gnutls_assert ();
493 return GNUTLS_E_BASE64_DECODING_ERROR; 493 return GNUTLS_E_BASE64_DECODING_ERROR;
494 } 494 }
495 495
@@ -497,24 +497,24 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
497 497
498 if (kdata_size < 0) 498 if (kdata_size < 0)
499 { 499 {
500 gnutls_assert (); 500 MHD_gnutls_assert ();
501 return kdata_size; 501 return kdata_size;
502 } 502 }
503 503
504 if (kdata_size < 4) 504 if (kdata_size < 4)
505 { 505 {
506 gnutls_assert (); 506 MHD_gnutls_assert ();
507 gnutls_free (kdata); 507 MHD_gnutls_free (kdata);
508 return GNUTLS_E_BASE64_DECODING_ERROR; 508 return GNUTLS_E_BASE64_DECODING_ERROR;
509 } 509 }
510 510
511 if ((ret = _gnutls_base64_decode (kdata, kdata_size, result)) < 0) 511 if ((ret = MHD__gnutls_base64_decode (kdata, kdata_size, result)) < 0)
512 { 512 {
513 gnutls_free (kdata); 513 MHD_gnutls_free (kdata);
514 gnutls_assert (); 514 MHD_gnutls_assert ();
515 return GNUTLS_E_BASE64_DECODING_ERROR; 515 return GNUTLS_E_BASE64_DECODING_ERROR;
516 } 516 }
517 gnutls_free (kdata); 517 MHD_gnutls_free (kdata);
518 518
519 return ret; 519 return ret;
520} 520}
@@ -535,27 +535,27 @@ _gnutls_fbase64_decode (const char *header, const opaque * data,
535 **/ 535 **/
536int 536int
537MHD_gtls_pem_base64_decode (const char *header, 537MHD_gtls_pem_base64_decode (const char *header,
538 const gnutls_datum_t * b64_data, 538 const MHD_gnutls_datum_t * b64_data,
539 unsigned char *result, size_t * result_size) 539 unsigned char *result, size_t * result_size)
540{ 540{
541 opaque *ret; 541 opaque *ret;
542 int size; 542 int size;
543 543
544 size = 544 size =
545 _gnutls_fbase64_decode (header, b64_data->data, b64_data->size, &ret); 545 MHD__gnutls_fbase64_decode (header, b64_data->data, b64_data->size, &ret);
546 if (size < 0) 546 if (size < 0)
547 return size; 547 return size;
548 548
549 if (result == NULL || *result_size < (unsigned) size) 549 if (result == NULL || *result_size < (unsigned) size)
550 { 550 {
551 gnutls_free (ret); 551 MHD_gnutls_free (ret);
552 *result_size = size; 552 *result_size = size;
553 return GNUTLS_E_SHORT_MEMORY_BUFFER; 553 return GNUTLS_E_SHORT_MEMORY_BUFFER;
554 } 554 }
555 else 555 else
556 { 556 {
557 memcpy (result, ret, size); 557 memcpy (result, ret, size);
558 gnutls_free (ret); 558 MHD_gnutls_free (ret);
559 *result_size = size; 559 *result_size = size;
560 } 560 }
561 561
@@ -574,13 +574,13 @@ MHD_gtls_pem_base64_decode (const char *header,
574 * "-----BEGIN header" and decode only this part. Otherwise it will decode the 574 * "-----BEGIN header" and decode only this part. Otherwise it will decode the
575 * first PEM packet found. 575 * first PEM packet found.
576 * 576 *
577 * You should use gnutls_free() to free the returned data. 577 * You should use MHD_gnutls_free() to free the returned data.
578 * 578 *
579 **/ 579 **/
580int 580int
581MHD_gtls_pem_base64_decode_alloc (const char *header, 581MHD_gtls_pem_base64_decode_alloc (const char *header,
582 const gnutls_datum_t * b64_data, 582 const MHD_gnutls_datum_t * b64_data,
583 gnutls_datum_t * result) 583 MHD_gnutls_datum_t * result)
584{ 584{
585 opaque *ret; 585 opaque *ret;
586 int size; 586 int size;
@@ -589,7 +589,7 @@ MHD_gtls_pem_base64_decode_alloc (const char *header,
589 return GNUTLS_E_INVALID_REQUEST; 589 return GNUTLS_E_INVALID_REQUEST;
590 590
591 size = 591 size =
592 _gnutls_fbase64_decode (header, b64_data->data, b64_data->size, &ret); 592 MHD__gnutls_fbase64_decode (header, b64_data->data, b64_data->size, &ret);
593 if (size < 0) 593 if (size < 0)
594 return size; 594 return size;
595 595
diff --git a/src/daemon/https/tls/x509_b64.h b/src/daemon/https/tls/x509_b64.h
index d079ebc6..8638420b 100644
--- a/src/daemon/https/tls/x509_b64.h
+++ b/src/daemon/https/tls/x509_b64.h
@@ -22,13 +22,13 @@
22 * 22 *
23 */ 23 */
24 24
25int _gnutls_base64_encode (const uint8_t * data, size_t data_size, 25int MHD__gnutls_base64_encode (const uint8_t * data, size_t data_size,
26 uint8_t ** result); 26 uint8_t ** result);
27int _gnutls_fbase64_encode (const char *msg, const uint8_t * data, 27int MHD__gnutls_fbase64_encode (const char *msg, const uint8_t * data,
28 int data_size, uint8_t ** result); 28 int data_size, uint8_t ** result);
29int _gnutls_base64_decode (const uint8_t * data, size_t data_size, 29int MHD__gnutls_base64_decode (const uint8_t * data, size_t data_size,
30 uint8_t ** result); 30 uint8_t ** result);
31int _gnutls_fbase64_decode (const char *header, const uint8_t * data, 31int MHD__gnutls_fbase64_decode (const char *header, const uint8_t * data,
32 size_t data_size, uint8_t ** result); 32 size_t data_size, uint8_t ** result);
33 33
34#define B64SIZE( data_size) ((data_size%3==0)?((data_size*4)/3):(4+((data_size/3)*4))) 34#define B64SIZE( data_size) ((data_size%3==0)?((data_size*4)/3):(4+((data_size/3)*4)))