diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-04-28 18:14:48 +0200 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-04-28 18:14:48 +0200 |
commit | d9dc2a9f8771bcbf6ec239cbcd92c144006e6587 (patch) | |
tree | 5afa7aac183c25dda4b4286677108b27bcd5dcd8 | |
parent | 02393bd4ef0c2ee7864c356f70623f3950f372f0 (diff) | |
parent | 0024cce1f30126e690c1a37a09202486910fd1b1 (diff) | |
download | gnutls-d9dc2a9f8771bcbf6ec239cbcd92c144006e6587.tar.gz |
Merge branch 'master' of ssh://jas@git.sv.gnu.org/srv/git/gnutls
-rw-r--r-- | lib/crypto.c | 11 | ||||
-rw-r--r-- | lib/random.c | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/crypto_rng.c | 64 |
4 files changed, 76 insertions, 4 deletions
diff --git a/lib/crypto.c b/lib/crypto.c index 89bed4724b..92b999bca8 100644 --- a/lib/crypto.c +++ b/lib/crypto.c @@ -77,7 +77,6 @@ algo_list* last_cl = al; cl->next = NULL; last_cl->next = cl; - return 0; } @@ -88,7 +87,7 @@ cipher_list* cl; /* look if there is any cipher with lowest priority. In that case do not add. */ - cl = al; + cl = al->next; while( cl && cl->alg_data) { if (cl->algorithm == algo) { return cl->alg_data; @@ -140,6 +139,8 @@ void _gnutls_crypto_deregister(void) * algorithms have priority of 90. The algorithm with the lowest * priority will be used by gnutls. * + * This function should be called before gnutls_global_init(). + * * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error. * **/ @@ -164,6 +165,8 @@ gnutls_crypto_cipher_st *_gnutls_get_crypto_cipher( gnutls_cipher_algorithm_t al * generators have priority of 90. The generator with the lowest * priority will be used by gnutls. * + * This function should be called before gnutls_global_init(). + * * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error. * **/ @@ -189,6 +192,8 @@ gnutls_crypto_rnd_st *_gnutls_get_crypto_rnd() * algorithms have priority of 90. The algorithm with the lowest * priority will be used by gnutls. * + * This function should be called before gnutls_global_init(). + * * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error. * **/ @@ -214,6 +219,8 @@ gnutls_crypto_mac_st *_gnutls_get_crypto_mac( gnutls_mac_algorithm_t algo) * algorithms have priority of 90. The algorithm with the lowest * priority will be used by gnutls. * + * This function should be called before gnutls_global_init(). + * * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error. * **/ diff --git a/lib/random.c b/lib/random.c index 25353cabac..82340c60b7 100644 --- a/lib/random.c +++ b/lib/random.c @@ -40,6 +40,7 @@ _gnutls_rnd_init () /* check if a digest has been registered */ cc = _gnutls_get_crypto_rnd(); + if (cc != NULL) { if (cc->init(& rnd_ctx) < 0) { gnutls_assert(); @@ -69,6 +70,7 @@ _gnutls_rnd (int level, void *data, int len) int ret = GC_OK; if (len > 0) { + if (cc != NULL) { return cc->rnd( rnd_ctx, level, data, len); } @@ -77,7 +79,6 @@ int ret = GC_OK; ret = gc_nonce (data, len); else ret = gc_pseudo_random( data, len); - } if (ret == GC_OK) return 0; diff --git a/tests/Makefile.am b/tests/Makefile.am index 7fb1fff02c..b2ccc4ede1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -37,7 +37,7 @@ noinst_LTLIBRARIES = libutils.la libutils_la_SOURCES = utils.h utils.c ctests = simple openssl gc set_pkcs12_cred certder \ - certificate_set_x509_crl dn parse_ca moredn + certificate_set_x509_crl dn parse_ca moredn crypto_rng openssl_LDADD = $(LDADD) ../libextra/libgnutls-openssl.la if HAVE_FORK ctests += openpgpself x509self x509signself x509dn anonself pskself dhepskself tlsia resume diff --git a/tests/crypto_rng.c b/tests/crypto_rng.c new file mode 100644 index 0000000000..2667178a06 --- /dev/null +++ b/tests/crypto_rng.c @@ -0,0 +1,64 @@ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdio.h> + +#include "utils.h" + +#include <gnutls/gnutls.h> +#include <gnutls/crypto.h> +#include "../lib/random.h" + +void mylogfn( int level, const char*ptr) +{ + printf ("Got Logs: "); + if (ptr) + printf ("%s", ptr); +} + +int rng_init( void** ctx) +{ + return 0; +} + +int rng_rnd ( void* ctx, int level, void* data, int datasize) +{ + memset(data, 1,datasize); + return 0; +} + +void rng_deinit( void* ctx) +{ +} + +void +doit (void) +{ + int rc; + char buf1[32]; + char buf2[32]; + int failed = 0; + gnutls_crypto_rnd_st rng = { rng_init, rng_rnd, rng_deinit }; + + + rc = gnutls_crypto_rnd_register (0, &rng); + + gnutls_global_init (); + + memset(buf2, 1, sizeof(buf2)); + + _gnutls_rnd(GNUTLS_RND_KEY, buf1, sizeof(buf1)); + + if (memcmp( buf1, buf2, sizeof(buf1))!=0) + failed = 1; + + gnutls_global_deinit (); + + if (failed == 0) { + success("rng registered ok\n"); + } else { + fail ("rng register test failed: %d\n", rc); + } +} |