summaryrefslogtreecommitdiff
path: root/libextra/gnutls_extra.c
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2004-06-07 10:05:43 +0000
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2004-06-07 10:05:43 +0000
commit802e1ede038010ddab31225f4b8a7e8d74f3b987 (patch)
treef9f07d2fb57da9843ac6b79e06e9266301b7e8b7 /libextra/gnutls_extra.c
parente0781d87ea58ff1ac1b6439d60510a8a26ea9f54 (diff)
downloadgnutls-802e1ede038010ddab31225f4b8a7e8d74f3b987.tar.gz
changed indentation to 4 spaces instead of tabs.
Diffstat (limited to 'libextra/gnutls_extra.c')
-rw-r--r--libextra/gnutls_extra.c373
1 files changed, 194 insertions, 179 deletions
diff --git a/libextra/gnutls_extra.c b/libextra/gnutls_extra.c
index d32ba12264..4c44e91e4c 100644
--- a/libextra/gnutls_extra.c
+++ b/libextra/gnutls_extra.c
@@ -39,26 +39,31 @@ extern gnutls_kx_algo_entry _gnutls_kx_algorithms[];
#define TOSTR(x) #x
#ifdef ENABLE_SRP
-static int _gnutls_add_srp_extension(void) {
-int i;
-
- /* find the last element */
- for(i=0;i<_gnutls_extensions_size;i++) {
- if (_gnutls_extensions[i].name==NULL) break;
- }
-
- if (_gnutls_extensions[i].name==NULL && (i < _gnutls_extensions_size-1)) {
- _gnutls_extensions[i].name = TOSTR(GNUTLS_EXTENSION_SRP);
- _gnutls_extensions[i].type = GNUTLS_EXTENSION_SRP;
- _gnutls_extensions[i].gnutls_ext_func_recv = _gnutls_srp_recv_params;
- _gnutls_extensions[i].gnutls_ext_func_send = _gnutls_srp_send_params;
-
- _gnutls_extensions[i+1].name = 0;
-
- return 0; /* ok */
- }
-
- return GNUTLS_E_MEMORY_ERROR;
+static int _gnutls_add_srp_extension(void)
+{
+ int i;
+
+ /* find the last element */
+ for (i = 0; i < _gnutls_extensions_size; i++) {
+ if (_gnutls_extensions[i].name == NULL)
+ break;
+ }
+
+ if (_gnutls_extensions[i].name == NULL
+ && (i < _gnutls_extensions_size - 1)) {
+ _gnutls_extensions[i].name = TOSTR(GNUTLS_EXTENSION_SRP);
+ _gnutls_extensions[i].type = GNUTLS_EXTENSION_SRP;
+ _gnutls_extensions[i].gnutls_ext_func_recv =
+ _gnutls_srp_recv_params;
+ _gnutls_extensions[i].gnutls_ext_func_send =
+ _gnutls_srp_send_params;
+
+ _gnutls_extensions[i + 1].name = 0;
+
+ return 0; /* ok */
+ }
+
+ return GNUTLS_E_MEMORY_ERROR;
}
extern mod_auth_st srp_auth_struct;
@@ -66,46 +71,51 @@ extern mod_auth_st srp_rsa_auth_struct;
extern mod_auth_st srp_dss_auth_struct;
-static int _gnutls_add_srp_auth_struct(void) {
-int i;
-
- /* find the last element */
- for(i=0;i<_gnutls_kx_algorithms_size;i++) {
- if (_gnutls_kx_algorithms[i].name==NULL) break;
- }
-
- if (_gnutls_kx_algorithms[i].name==NULL && (i < _gnutls_kx_algorithms_size-1)) {
- _gnutls_kx_algorithms[i].name = "SRP";
- _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP;
- _gnutls_kx_algorithms[i].auth_struct = &srp_auth_struct;
- _gnutls_kx_algorithms[i].needs_dh_params = 0;
- _gnutls_kx_algorithms[i].needs_rsa_params = 0;
- _gnutls_kx_algorithms[i+1].name = 0;
- }
- i++;
-
- if (_gnutls_kx_algorithms[i].name==NULL && (i < _gnutls_kx_algorithms_size-1)) {
- _gnutls_kx_algorithms[i].name = "SRP RSA";
- _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP_RSA;
- _gnutls_kx_algorithms[i].auth_struct = &srp_rsa_auth_struct;
- _gnutls_kx_algorithms[i].needs_dh_params = 0;
- _gnutls_kx_algorithms[i].needs_rsa_params = 0;
- _gnutls_kx_algorithms[i+1].name = 0;
- }
- i++;
-
- if (_gnutls_kx_algorithms[i].name==NULL && (i < _gnutls_kx_algorithms_size-1)) {
- _gnutls_kx_algorithms[i].name = "SRP DSS";
- _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP_DSS;
- _gnutls_kx_algorithms[i].auth_struct = &srp_dss_auth_struct;
- _gnutls_kx_algorithms[i].needs_dh_params = 0;
- _gnutls_kx_algorithms[i].needs_rsa_params = 0;
- _gnutls_kx_algorithms[i+1].name = 0;
-
- return 0; /* ok */
- }
-
- return GNUTLS_E_MEMORY_ERROR;
+static int _gnutls_add_srp_auth_struct(void)
+{
+ int i;
+
+ /* find the last element */
+ for (i = 0; i < _gnutls_kx_algorithms_size; i++) {
+ if (_gnutls_kx_algorithms[i].name == NULL)
+ break;
+ }
+
+ if (_gnutls_kx_algorithms[i].name == NULL
+ && (i < _gnutls_kx_algorithms_size - 1)) {
+ _gnutls_kx_algorithms[i].name = "SRP";
+ _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP;
+ _gnutls_kx_algorithms[i].auth_struct = &srp_auth_struct;
+ _gnutls_kx_algorithms[i].needs_dh_params = 0;
+ _gnutls_kx_algorithms[i].needs_rsa_params = 0;
+ _gnutls_kx_algorithms[i + 1].name = 0;
+ }
+ i++;
+
+ if (_gnutls_kx_algorithms[i].name == NULL
+ && (i < _gnutls_kx_algorithms_size - 1)) {
+ _gnutls_kx_algorithms[i].name = "SRP RSA";
+ _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP_RSA;
+ _gnutls_kx_algorithms[i].auth_struct = &srp_rsa_auth_struct;
+ _gnutls_kx_algorithms[i].needs_dh_params = 0;
+ _gnutls_kx_algorithms[i].needs_rsa_params = 0;
+ _gnutls_kx_algorithms[i + 1].name = 0;
+ }
+ i++;
+
+ if (_gnutls_kx_algorithms[i].name == NULL
+ && (i < _gnutls_kx_algorithms_size - 1)) {
+ _gnutls_kx_algorithms[i].name = "SRP DSS";
+ _gnutls_kx_algorithms[i].algorithm = GNUTLS_KX_SRP_DSS;
+ _gnutls_kx_algorithms[i].auth_struct = &srp_dss_auth_struct;
+ _gnutls_kx_algorithms[i].needs_dh_params = 0;
+ _gnutls_kx_algorithms[i].needs_rsa_params = 0;
+ _gnutls_kx_algorithms[i + 1].name = 0;
+
+ return 0; /* ok */
+ }
+
+ return GNUTLS_E_MEMORY_ERROR;
}
#endif
@@ -119,42 +129,46 @@ extern int _gnutls_comp_algorithms_size;
/* Functions in gnutls that have not been initialized.
*/
#ifdef USE_LZO
-typedef int (*LZO_FUNC)();
+typedef int (*LZO_FUNC) ();
extern LZO_FUNC _gnutls_lzo1x_decompress_safe;
extern LZO_FUNC _gnutls_lzo1x_1_compress;
extern gnutls_compression_entry _gnutls_compression_algorithms[];
-static int _gnutls_add_lzo_comp(void)
+static int _gnutls_add_lzo_comp(void)
{
-int i;
+ int i;
+
+ /* find the last element */
+ for (i = 0; i < _gnutls_comp_algorithms_size; i++) {
+ if (_gnutls_compression_algorithms[i].name == NULL)
+ break;
+ }
- /* find the last element */
- for(i=0;i<_gnutls_comp_algorithms_size;i++) {
- if (_gnutls_compression_algorithms[i].name==NULL) break;
- }
+ if (_gnutls_compression_algorithms[i].name == NULL
+ && (i < _gnutls_comp_algorithms_size - 1)) {
+ _gnutls_compression_algorithms[i].name = "GNUTLS_COMP_LZO";
+ _gnutls_compression_algorithms[i].id = GNUTLS_COMP_LZO;
+ _gnutls_compression_algorithms[i].num = 0xf2;
- if (_gnutls_compression_algorithms[i].name==NULL && (i < _gnutls_comp_algorithms_size-1)) {
- _gnutls_compression_algorithms[i].name = "GNUTLS_COMP_LZO";
- _gnutls_compression_algorithms[i].id = GNUTLS_COMP_LZO;
- _gnutls_compression_algorithms[i].num = 0xf2;
+ _gnutls_compression_algorithms[i + 1].name = 0;
- _gnutls_compression_algorithms[i+1].name = 0;
+ /* Now enable the lzo functions: */
+ _gnutls_lzo1x_decompress_safe = lzo1x_decompress_safe;
+ _gnutls_lzo1x_1_compress = lzo1x_1_compress;
+
+ return 0; /* ok */
+ }
- /* Now enable the lzo functions: */
- _gnutls_lzo1x_decompress_safe = lzo1x_decompress_safe;
- _gnutls_lzo1x_1_compress = lzo1x_1_compress;
-
- return 0; /* ok */
- }
-
- return GNUTLS_E_MEMORY_ERROR;
+ return GNUTLS_E_MEMORY_ERROR;
}
#endif
-extern OPENPGP_KEY_CREATION_TIME_FUNC _E_gnutls_openpgp_get_raw_key_creation_time;
-extern OPENPGP_KEY_EXPIRATION_TIME_FUNC _E_gnutls_openpgp_get_raw_key_expiration_time;
+extern OPENPGP_KEY_CREATION_TIME_FUNC
+ _E_gnutls_openpgp_get_raw_key_creation_time;
+extern OPENPGP_KEY_EXPIRATION_TIME_FUNC
+ _E_gnutls_openpgp_get_raw_key_expiration_time;
extern OPENPGP_VERIFY_KEY_FUNC _E_gnutls_openpgp_verify_key;
extern OPENPGP_FINGERPRINT _E_gnutls_openpgp_fingerprint;
extern OPENPGP_KEY_REQUEST _E_gnutls_openpgp_request_key;
@@ -167,25 +181,29 @@ extern OPENPGP_PRIVKEY_TO_GKEY _E_gnutls_openpgp_privkey_to_gkey;
extern OPENPGP_KEY_DEINIT _E_gnutls_openpgp_key_deinit;
extern OPENPGP_PRIVKEY_DEINIT _E_gnutls_openpgp_privkey_deinit;
-static void _gnutls_add_openpgp_functions(void) {
+static void _gnutls_add_openpgp_functions(void)
+{
#ifdef USE_OPENPGP
- _E_gnutls_openpgp_verify_key = _gnutls_openpgp_verify_key;
- _E_gnutls_openpgp_get_raw_key_expiration_time = _gnutls_openpgp_get_raw_key_expiration_time;
- _E_gnutls_openpgp_get_raw_key_creation_time = _gnutls_openpgp_get_raw_key_creation_time;
- _E_gnutls_openpgp_fingerprint = _gnutls_openpgp_fingerprint;
- _E_gnutls_openpgp_request_key = _gnutls_openpgp_request_key;
-
- _E_gnutls_openpgp_raw_key_to_gcert = _gnutls_openpgp_raw_key_to_gcert;
- _E_gnutls_openpgp_raw_privkey_to_gkey = _gnutls_openpgp_raw_privkey_to_gkey;
-
- _E_gnutls_openpgp_key_to_gcert = _gnutls_openpgp_key_to_gcert;
- _E_gnutls_openpgp_privkey_to_gkey = _gnutls_openpgp_privkey_to_gkey;
- _E_gnutls_openpgp_key_deinit = gnutls_openpgp_key_deinit;
- _E_gnutls_openpgp_privkey_deinit = gnutls_openpgp_privkey_deinit;
+ _E_gnutls_openpgp_verify_key = _gnutls_openpgp_verify_key;
+ _E_gnutls_openpgp_get_raw_key_expiration_time =
+ _gnutls_openpgp_get_raw_key_expiration_time;
+ _E_gnutls_openpgp_get_raw_key_creation_time =
+ _gnutls_openpgp_get_raw_key_creation_time;
+ _E_gnutls_openpgp_fingerprint = _gnutls_openpgp_fingerprint;
+ _E_gnutls_openpgp_request_key = _gnutls_openpgp_request_key;
+
+ _E_gnutls_openpgp_raw_key_to_gcert = _gnutls_openpgp_raw_key_to_gcert;
+ _E_gnutls_openpgp_raw_privkey_to_gkey =
+ _gnutls_openpgp_raw_privkey_to_gkey;
+
+ _E_gnutls_openpgp_key_to_gcert = _gnutls_openpgp_key_to_gcert;
+ _E_gnutls_openpgp_privkey_to_gkey = _gnutls_openpgp_privkey_to_gkey;
+ _E_gnutls_openpgp_key_deinit = gnutls_openpgp_key_deinit;
+ _E_gnutls_openpgp_privkey_deinit = gnutls_openpgp_privkey_deinit;
#endif
}
-extern const char* gnutls_check_version( const char*);
+extern const char *gnutls_check_version(const char *);
static int _gnutls_init_extra = 0;
/**
@@ -199,102 +217,102 @@ static int _gnutls_init_extra = 0;
* be usable.
*
**/
-int gnutls_global_init_extra(void) {
-int ret;
-
- /* If the version of libgnutls != version of
- * libextra, then do not initialize the library.
- * This is because it may break things.
- */
- if (strcmp( gnutls_check_version(NULL), GNUTLS_VERSION)!=0) {
- return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
- }
-
- _gnutls_init_extra++;
-
- if (_gnutls_init_extra!=1) {
- return 0;
- }
-
- /* Initialize the LZO library
- */
+int gnutls_global_init_extra(void)
+{
+ int ret;
+
+ /* If the version of libgnutls != version of
+ * libextra, then do not initialize the library.
+ * This is because it may break things.
+ */
+ if (strcmp(gnutls_check_version(NULL), GNUTLS_VERSION) != 0) {
+ return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
+ }
+
+ _gnutls_init_extra++;
+
+ if (_gnutls_init_extra != 1) {
+ return 0;
+ }
+
+ /* Initialize the LZO library
+ */
#ifdef USE_LZO
- if (lzo_init() != LZO_E_OK) {
- return GNUTLS_E_LZO_INIT_FAILED;
- }
-
- /* Add the LZO compression method in the list of compression
- * methods.
- */
- ret = _gnutls_add_lzo_comp();
- if (ret < 0) {
- gnutls_assert();
- return ret;
- }
+ if (lzo_init() != LZO_E_OK) {
+ return GNUTLS_E_LZO_INIT_FAILED;
+ }
+
+ /* Add the LZO compression method in the list of compression
+ * methods.
+ */
+ ret = _gnutls_add_lzo_comp();
+ if (ret < 0) {
+ gnutls_assert();
+ return ret;
+ }
#endif
#ifdef ENABLE_SRP
- /* Add the SRP authentication to the list of authentication
- * methods.
- */
- ret = _gnutls_add_srp_auth_struct();
- if (ret < 0) {
- gnutls_assert();
- return ret;
- }
-
- /* Do the same of the extension
- */
- ret = _gnutls_add_srp_extension();
- if (ret < 0) {
- gnutls_assert();
- return ret;
- }
+ /* Add the SRP authentication to the list of authentication
+ * methods.
+ */
+ ret = _gnutls_add_srp_auth_struct();
+ if (ret < 0) {
+ gnutls_assert();
+ return ret;
+ }
+
+ /* Do the same of the extension
+ */
+ ret = _gnutls_add_srp_extension();
+ if (ret < 0) {
+ gnutls_assert();
+ return ret;
+ }
#endif
- /* Register the openpgp functions. This is because some
- * of them are defined to be NULL in the main library.
- */
- _gnutls_add_openpgp_functions();
+ /* Register the openpgp functions. This is because some
+ * of them are defined to be NULL in the main library.
+ */
+ _gnutls_add_openpgp_functions();
- return 0;
+ return 0;
}
/* Taken from libgcrypt. Needed to configure scripts.
*/
-static const char*
-parse_version_number( const char *s, int *number )
+static const char *parse_version_number(const char *s, int *number)
{
int val = 0;
- if( *s == '0' && isdigit(s[1]) )
- return NULL; /* leading zeros are not allowed */
- for ( ; isdigit(*s); s++ ) {
+ if (*s == '0' && isdigit(s[1]))
+ return NULL; /* leading zeros are not allowed */
+ for (; isdigit(*s); s++) {
val *= 10;
val += *s - '0';
}
*number = val;
- return val < 0? NULL : s;
+ return val < 0 ? NULL : s;
}
/* The parse version functions were copied from libgcrypt.
*/
-static const char *
-parse_version_string( const char *s, int *major, int *minor, int *micro )
+static const char *parse_version_string(const char *s, int *major,
+ int *minor, int *micro)
{
- s = parse_version_number( s, major );
- if( !s || *s != '.' )
+ s = parse_version_number(s, major);
+ if (!s || *s != '.')
return NULL;
s++;
- s = parse_version_number( s, minor );
- if( !s || *s != '.' )
+ s = parse_version_number(s, minor);
+ if (!s || *s != '.')
return NULL;
s++;
- s = parse_version_number( s, micro );
- if( !s )
+ s = parse_version_number(s, micro);
+ if (!s)
return NULL;
- return s; /* patchlevel */
+ return s; /* patchlevel */
}
/****************
@@ -303,34 +321,31 @@ parse_version_string( const char *s, int *major, int *minor, int *micro )
* satisfied. If a NULL is passed to this function, no check is done,
* but the version string is simply returned.
*/
-const char *
-gnutls_extra_check_version( const char *req_version )
+const char *gnutls_extra_check_version(const char *req_version)
{
const char *ver = GNUTLS_VERSION;
int my_major, my_minor, my_micro;
int rq_major, rq_minor, rq_micro;
const char *my_plvl, *rq_plvl;
- if ( !req_version )
+ if (!req_version)
return ver;
- my_plvl = parse_version_string( ver, &my_major, &my_minor, &my_micro );
- if ( !my_plvl )
- return NULL; /* very strange our own version is bogus */
- rq_plvl = parse_version_string( req_version, &rq_major, &rq_minor,
- &rq_micro );
- if ( !rq_plvl )
- return NULL; /* req version string is invalid */
+ my_plvl = parse_version_string(ver, &my_major, &my_minor, &my_micro);
+ if (!my_plvl)
+ return NULL; /* very strange our own version is bogus */
+ rq_plvl = parse_version_string(req_version, &rq_major, &rq_minor,
+ &rq_micro);
+ if (!rq_plvl)
+ return NULL; /* req version string is invalid */
- if ( my_major > rq_major
+ if (my_major > rq_major
|| (my_major == rq_major && my_minor > rq_minor)
|| (my_major == rq_major && my_minor == rq_minor
- && my_micro > rq_micro)
+ && my_micro > rq_micro)
|| (my_major == rq_major && my_minor == rq_minor
- && my_micro == rq_micro
- && strcmp( my_plvl, rq_plvl ) >= 0) ) {
+ && my_micro == rq_micro && strcmp(my_plvl, rq_plvl) >= 0)) {
return ver;
}
return NULL;
}
-