You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2021/09/12 14:15:34 UTC
svn commit: r1893280 - in /apr/apr-util/branches/1.7.x: ./ test/testcrypto.c
Author: ylavic
Date: Sun Sep 12 14:15:34 2021
New Revision: 1893280
URL: http://svn.apache.org/viewvc?rev=1893280&view=rev
Log:
Merge r1893274, r1893275 from trunk:
testcrypto: run non-threaded cprng tests without APR_CRYPTO_PRNG_PER_THREAD.
testcrypto: really change one bit of the seed (only) in test_crypto_prng().
Submitted by: ylavic
Modified:
apr/apr-util/branches/1.7.x/ (props changed)
apr/apr-util/branches/1.7.x/test/testcrypto.c
Propchange: apr/apr-util/branches/1.7.x/
------------------------------------------------------------------------------
Merged /apr/apr/trunk:r1893274-1893275
Modified: apr/apr-util/branches/1.7.x/test/testcrypto.c
URL: http://svn.apache.org/viewvc/apr/apr-util/branches/1.7.x/test/testcrypto.c?rev=1893280&r1=1893279&r2=1893280&view=diff
==============================================================================
--- apr/apr-util/branches/1.7.x/test/testcrypto.c (original)
+++ apr/apr-util/branches/1.7.x/test/testcrypto.c Sun Sep 12 14:15:34 2021
@@ -2432,27 +2432,20 @@ static void test_crypto_prng(abts_case *
apr_pool_t *pool = NULL;
apr_status_t rv;
int i;
- int flags = 0;
rv = apr_pool_create(&pool, NULL);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
ABTS_PTR_NOTNULL(tc, pool);
-#if APR_HAS_THREADS
- flags = APR_CRYPTO_PRNG_PER_THREAD;
-#endif
- rv = apr_crypto_prng_init(pool, NULL, cipher, 0, NULL, flags);
-
- if (APR_ENOCIPHER == rv) {
+ rv = apr_crypto_prng_init(pool, NULL, cipher, 0, NULL, 0);
+ ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_EREINIT", rv != APR_EREINIT);
+ ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_ENOTIMPL", rv != APR_ENOTIMPL);
+ ABTS_ASSERT(tc, "apr_crypto_prng_init failed", rv == APR_SUCCESS || rv == APR_ENOCIPHER);
+ if (rv != APR_SUCCESS) {
apr_pool_destroy(pool);
return;
}
- ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_EREINIT", rv != APR_EREINIT);
- ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_ENOTIMPL", rv != APR_ENOTIMPL);
- ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_ENOCIPHER", rv != APR_ENOCIPHER);
- ABTS_ASSERT(tc, "apr_crypto_prng_init failed", rv == APR_SUCCESS);
-
for (i = 0; i < 10; ++i) {
/* Initial seed full of zeros (deterministic) */
memset(seed, 0, sizeof(seed));
@@ -2464,18 +2457,18 @@ static void test_crypto_prng(abts_case *
ABTS_ASSERT(tc, "apr_crypto_prng_create returned APR_ENOCIPHER", rv != APR_ENOCIPHER);
ABTS_ASSERT(tc, "apr_crypto_prng_create returned APR_EDSOOPEN", rv != APR_EDSOOPEN);
ABTS_ASSERT(tc, "apr_crypto_prng_create failed", rv == APR_SUCCESS);
- if (!cprng) {
+ if (rv != APR_SUCCESS) {
break;
}
- /* Second time and more, change one bit of the seed */
+ /* Second time and more, set one random bit of the seed */
if (i != 0) {
- unsigned char pos = 0;
- rv = apr_generate_random_bytes(&pos, sizeof pos);
+ unsigned char rnd;
+ rv = apr_generate_random_bytes(&rnd, sizeof rnd);
ABTS_ASSERT(tc, "apr_generate_random_bytes failed",
rv == APR_SUCCESS);
+ seed[rnd % APR_CRYPTO_PRNG_SEED_SIZE] = (unsigned char)(1u << (rnd % 8));
- seed[pos % APR_CRYPTO_PRNG_SEED_SIZE] = 1;
rv = apr_crypto_prng_reseed(cprng, seed);
ABTS_ASSERT(tc, "apr_crypto_prng_reseed failed",
rv == APR_SUCCESS);
@@ -2527,16 +2520,12 @@ static void test_crypto_fork_random(abts
apr_size_t nbytes;
apr_proc_t proc;
apr_status_t rv;
- int flags = 0;
rv = apr_pool_create(&pool, NULL);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
ABTS_PTR_NOTNULL(tc, pool);
-#if APR_HAS_THREADS
- flags = APR_CRYPTO_PRNG_PER_THREAD;
-#endif
- rv = apr_crypto_prng_init(pool, NULL, APR_CRYPTO_CIPHER_AUTO, 0, NULL, flags);
+ rv = apr_crypto_prng_init(pool, NULL, APR_CRYPTO_CIPHER_AUTO, 0, NULL, 0);
ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_EREINIT", rv != APR_EREINIT);
ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_ENOTIMPL", rv != APR_ENOTIMPL);
ABTS_ASSERT(tc, "apr_crypto_prng_init failed", rv == APR_SUCCESS);
@@ -2616,18 +2605,15 @@ static void test_crypto_thread_random(ab
static unsigned char zerobytes[800];
unsigned char *randbytes[NUM_THREADS];
apr_thread_t *threads[NUM_THREADS];
+ int flags = APR_CRYPTO_PRNG_PER_THREAD;
apr_pool_t *pool = NULL;
apr_status_t rv, ret;
int i, j;
- int flags = 0;
rv = apr_pool_create(&pool, NULL);
ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
ABTS_PTR_NOTNULL(tc, pool);
-#if APR_HAS_THREADS
- flags = APR_CRYPTO_PRNG_PER_THREAD;
-#endif
rv = apr_crypto_prng_init(pool, NULL, APR_CRYPTO_CIPHER_AUTO, 0, NULL, flags);
ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_EREINIT", rv != APR_EREINIT);
ABTS_ASSERT(tc, "apr_crypto_prng_init returned APR_ENOTIMPL", rv != APR_ENOTIMPL);
@@ -2656,8 +2642,8 @@ static void test_crypto_thread_random(ab
apr_pool_destroy(pool);
}
-#endif
-#endif
+#endif /* APR_HAS_THREADS */
+#endif /* APU_HAVE_CRYPTO_PRNG */
abts_suite *testcrypto(abts_suite *suite)
{