summaryrefslogtreecommitdiff
path: root/lib/psk.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/psk.c')
-rw-r--r--lib/psk.c138
1 files changed, 60 insertions, 78 deletions
diff --git a/lib/psk.c b/lib/psk.c
index 2524a8ecb2..ac8c7751ce 100644
--- a/lib/psk.c
+++ b/lib/psk.c
@@ -30,12 +30,12 @@
#ifdef ENABLE_PSK
-# include <auth/psk_passwd.h>
-# include <num.h>
-# include <file.h>
-# include <datum.h>
-# include "debug.h"
-# include "dh.h"
+#include <auth/psk_passwd.h>
+#include <num.h>
+#include <file.h>
+#include <datum.h>
+#include "debug.h"
+#include "dh.h"
/**
* gnutls_psk_free_client_credentials:
@@ -59,7 +59,7 @@ void gnutls_psk_free_client_credentials(gnutls_psk_client_credentials_t sc)
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
**/
-int gnutls_psk_allocate_client_credentials(gnutls_psk_client_credentials_t * sc)
+int gnutls_psk_allocate_client_credentials(gnutls_psk_client_credentials_t *sc)
{
*sc = gnutls_calloc(1, sizeof(psk_client_credentials_st));
@@ -89,11 +89,10 @@ int gnutls_psk_allocate_client_credentials(gnutls_psk_client_credentials_t * sc)
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
**/
-int
-gnutls_psk_set_client_credentials(gnutls_psk_client_credentials_t res,
- const char *username,
- const gnutls_datum_t * key,
- gnutls_psk_key_flags flags)
+int gnutls_psk_set_client_credentials(gnutls_psk_client_credentials_t res,
+ const char *username,
+ const gnutls_datum_t *key,
+ gnutls_psk_key_flags flags)
{
gnutls_datum_t dat;
@@ -120,16 +119,15 @@ gnutls_psk_set_client_credentials(gnutls_psk_client_credentials_t res,
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
*/
-int
-gnutls_psk_set_client_credentials2(gnutls_psk_client_credentials_t res,
- const gnutls_datum_t * username,
- const gnutls_datum_t * key,
- gnutls_psk_key_flags flags)
+int gnutls_psk_set_client_credentials2(gnutls_psk_client_credentials_t res,
+ const gnutls_datum_t *username,
+ const gnutls_datum_t *key,
+ gnutls_psk_key_flags flags)
{
int ret;
- if (username == NULL || username->data == NULL || key == NULL
- || key->data == NULL) {
+ if (username == NULL || username->data == NULL || key == NULL ||
+ key->data == NULL) {
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
}
@@ -144,7 +142,7 @@ gnutls_psk_set_client_credentials2(gnutls_psk_client_credentials_t res,
ret = GNUTLS_E_MEMORY_ERROR;
goto error;
}
- } else { /* HEX key */
+ } else { /* HEX key */
size_t size;
size = res->key.size = key->size / 2;
res->key.data = gnutls_malloc(size);
@@ -157,7 +155,6 @@ gnutls_psk_set_client_credentials2(gnutls_psk_client_credentials_t res,
ret = gnutls_hex_decode(key, (char *)res->key.data, &size);
res->key.size = (unsigned int)size;
if (ret < 0) {
-
gnutls_assert();
goto error;
}
@@ -171,7 +168,7 @@ gnutls_psk_set_client_credentials2(gnutls_psk_client_credentials_t res,
return 0;
- error:
+error:
_gnutls_free_datum(&res->username);
_gnutls_free_datum(&res->key);
@@ -204,7 +201,7 @@ void gnutls_psk_free_server_credentials(gnutls_psk_server_credentials_t sc)
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
**/
-int gnutls_psk_allocate_server_credentials(gnutls_psk_server_credentials_t * sc)
+int gnutls_psk_allocate_server_credentials(gnutls_psk_server_credentials_t *sc)
{
*sc = gnutls_calloc(1, sizeof(psk_server_cred_st));
@@ -233,11 +230,9 @@ int gnutls_psk_allocate_server_credentials(gnutls_psk_server_credentials_t * sc)
* Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise
* an error code is returned.
**/
-int
-gnutls_psk_set_server_credentials_file(gnutls_psk_server_credentials_t
- res, const char *password_file)
+int gnutls_psk_set_server_credentials_file(gnutls_psk_server_credentials_t res,
+ const char *password_file)
{
-
if (password_file == NULL) {
gnutls_assert();
return GNUTLS_E_INVALID_REQUEST;
@@ -273,9 +268,8 @@ gnutls_psk_set_server_credentials_file(gnutls_psk_server_credentials_t
*
* Since: 2.4.0
**/
-int
-gnutls_psk_set_server_credentials_hint(gnutls_psk_server_credentials_t res,
- const char *hint)
+int gnutls_psk_set_server_credentials_hint(gnutls_psk_server_credentials_t res,
+ const char *hint)
{
res->hint = gnutls_strdup(hint);
if (res->hint == NULL) {
@@ -287,11 +281,12 @@ gnutls_psk_set_server_credentials_hint(gnutls_psk_server_credentials_t res,
}
static int call_server_callback_legacy(gnutls_session_t session,
- const gnutls_datum_t * username,
- gnutls_datum_t * key)
+ const gnutls_datum_t *username,
+ gnutls_datum_t *key)
{
- gnutls_psk_server_credentials_t cred = (gnutls_psk_server_credentials_t)
- _gnutls_get_cred(session, GNUTLS_CRD_PSK);
+ gnutls_psk_server_credentials_t cred =
+ (gnutls_psk_server_credentials_t)_gnutls_get_cred(
+ session, GNUTLS_CRD_PSK);
if (unlikely(cred == NULL))
return gnutls_assert_val(-1);
@@ -319,11 +314,9 @@ static int call_server_callback_legacy(gnutls_session_t session,
* callback function should return 0 on success, while -1 indicates
* an error.
**/
-void
-gnutls_psk_set_server_credentials_function(gnutls_psk_server_credentials_t
- cred,
- gnutls_psk_server_credentials_function
- * func)
+void gnutls_psk_set_server_credentials_function(
+ gnutls_psk_server_credentials_t cred,
+ gnutls_psk_server_credentials_function *func)
{
cred->pwd_callback_legacy = func;
cred->pwd_callback = call_server_callback_legacy;
@@ -352,24 +345,23 @@ gnutls_psk_set_server_credentials_function(gnutls_psk_server_credentials_t
* callback function should return 0 on success, while -1 indicates
* an error.
**/
-void
-gnutls_psk_set_server_credentials_function2(gnutls_psk_server_credentials_t
- cred,
- gnutls_psk_server_credentials_function2
- func)
+void gnutls_psk_set_server_credentials_function2(
+ gnutls_psk_server_credentials_t cred,
+ gnutls_psk_server_credentials_function2 func)
{
cred->pwd_callback = func;
cred->pwd_callback_legacy = NULL;
}
static int call_client_callback_legacy(gnutls_session_t session,
- gnutls_datum_t * username,
- gnutls_datum_t * key)
+ gnutls_datum_t *username,
+ gnutls_datum_t *key)
{
int ret;
char *user_p;
- gnutls_psk_client_credentials_t cred = (gnutls_psk_client_credentials_t)
- _gnutls_get_cred(session, GNUTLS_CRD_PSK);
+ gnutls_psk_client_credentials_t cred =
+ (gnutls_psk_client_credentials_t)_gnutls_get_cred(
+ session, GNUTLS_CRD_PSK);
if (unlikely(cred == NULL))
return gnutls_assert_val(-1);
@@ -378,10 +370,10 @@ static int call_client_callback_legacy(gnutls_session_t session,
if (ret)
goto end;
- username->data = (uint8_t *) user_p;
+ username->data = (uint8_t *)user_p;
username->size = strlen(user_p);
- end:
+end:
return ret;
}
@@ -406,11 +398,9 @@ static int call_client_callback_legacy(gnutls_session_t session,
* The callback function should return 0 on success.
* -1 indicates an error.
**/
-void
-gnutls_psk_set_client_credentials_function(gnutls_psk_client_credentials_t
- cred,
- gnutls_psk_client_credentials_function
- * func)
+void gnutls_psk_set_client_credentials_function(
+ gnutls_psk_client_credentials_t cred,
+ gnutls_psk_client_credentials_function *func)
{
cred->get_function = call_client_callback_legacy;
cred->get_function_legacy = func;
@@ -440,11 +430,9 @@ gnutls_psk_set_client_credentials_function(gnutls_psk_client_credentials_t
* The callback function should return 0 on success.
* -1 indicates an error.
**/
-void
-gnutls_psk_set_client_credentials_function2(gnutls_psk_client_credentials_t
- cred,
- gnutls_psk_client_credentials_function2
- * func)
+void gnutls_psk_set_client_credentials_function2(
+ gnutls_psk_client_credentials_t cred,
+ gnutls_psk_client_credentials_function2 *func)
{
cred->get_function = func;
cred->get_function_legacy = NULL;
@@ -499,7 +487,7 @@ const char *gnutls_psk_server_get_username(gnutls_session_t session)
* Returns: %GNUTLS_E_SUCCESS, or a negative value in case of an error.
**/
int gnutls_psk_server_get_username2(gnutls_session_t session,
- gnutls_datum_t * username)
+ gnutls_datum_t *username)
{
psk_auth_info_t info;
@@ -557,9 +545,8 @@ const char *gnutls_psk_client_get_hint(gnutls_session_t session)
* following RFC7919.
*
**/
-void
-gnutls_psk_set_server_dh_params(gnutls_psk_server_credentials_t res,
- gnutls_dh_params_t dh_params)
+void gnutls_psk_set_server_dh_params(gnutls_psk_server_credentials_t res,
+ gnutls_dh_params_t dh_params)
{
if (res->deinit_dh_params) {
res->deinit_dh_params = 0;
@@ -568,10 +555,8 @@ gnutls_psk_set_server_dh_params(gnutls_psk_server_credentials_t res,
}
res->dh_params = dh_params;
- res->dh_sec_param =
- gnutls_pk_bits_to_sec_param(GNUTLS_PK_DH,
- _gnutls_mpi_get_nbits(dh_params->params
- [0]));
+ res->dh_sec_param = gnutls_pk_bits_to_sec_param(
+ GNUTLS_PK_DH, _gnutls_mpi_get_nbits(dh_params->params[0]));
}
/**
@@ -593,9 +578,8 @@ gnutls_psk_set_server_dh_params(gnutls_psk_server_credentials_t res,
*
* Since: 3.5.6
**/
-int
-gnutls_psk_set_server_known_dh_params(gnutls_psk_server_credentials_t res,
- gnutls_sec_param_t sec_param)
+int gnutls_psk_set_server_known_dh_params(gnutls_psk_server_credentials_t res,
+ gnutls_sec_param_t sec_param)
{
res->dh_sec_param = sec_param;
@@ -616,9 +600,8 @@ gnutls_psk_set_server_known_dh_params(gnutls_psk_server_credentials_t res,
* following RFC7919.
*
**/
-void
-gnutls_psk_set_server_params_function(gnutls_psk_server_credentials_t res,
- gnutls_params_function * func)
+void gnutls_psk_set_server_params_function(gnutls_psk_server_credentials_t res,
+ gnutls_params_function *func)
{
res->params_func = func;
}
@@ -637,11 +620,10 @@ gnutls_psk_set_server_params_function(gnutls_psk_server_credentials_t res,
* following RFC7919.
*
**/
-void
-gnutls_psk_set_params_function(gnutls_psk_server_credentials_t res,
- gnutls_params_function * func)
+void gnutls_psk_set_params_function(gnutls_psk_server_credentials_t res,
+ gnutls_params_function *func)
{
res->params_func = func;
}
-#endif /* ENABLE_PSK */
+#endif /* ENABLE_PSK */