Navigation Menu

Skip to content

Commit

Permalink
Bug 1376494 - don't initialise the deterministic rng twice, r=ttaubert
Browse files Browse the repository at this point in the history
Differential Revision: https://nss-review.dev.mozaws.net/D348

--HG--
extra : rebase_source : 4b126fd1e560d26ccc8043aa25c0b8db31833f4e
extra : amend_source : 890f3b8505ae92045c61ad1785c58ee15a04a056
  • Loading branch information
franziskuskiefer committed Aug 21, 2017
1 parent e7099fb commit 6753697
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions lib/freebl/det_rng.c
Expand Up @@ -8,26 +8,40 @@
#include "nssilock.h"
#include "seccomon.h"
#include "secerr.h"
#include "prinit.h"

#define GLOBAL_BYTES_SIZE 100
static PRUint8 globalBytes[GLOBAL_BYTES_SIZE];
static unsigned long globalNumCalls = 0;
static PZLock *rng_lock = NULL;
static PRCallOnceType coRNGInit;
static const PRCallOnceType pristineCallOnce;

SECStatus
RNG_RNGInit(void)
static PRStatus
rng_init(void)
{
rng_lock = PZ_NewLock(nssILockOther);
if (!rng_lock) {
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
return SECFailure;
return PR_FAILURE;
}
/* --- LOCKED --- */
PZ_Lock(rng_lock);
memset(globalBytes, 0, GLOBAL_BYTES_SIZE);
PZ_Unlock(rng_lock);
/* --- UNLOCKED --- */

return PR_SUCCESS;
}

SECStatus
RNG_RNGInit(void)
{
/* Allow only one call to initialize the context */
if (PR_CallOnce(&coRNGInit, rng_init) != PR_SUCCESS) {
return SECFailure;
}

return SECSuccess;
}

Expand Down Expand Up @@ -97,8 +111,11 @@ RNG_GenerateGlobalRandomBytes(void *dest, size_t len)
void
RNG_RNGShutdown(void)
{
PZ_DestroyLock(rng_lock);
rng_lock = NULL;
if (rng_lock) {
PZ_DestroyLock(rng_lock);
rng_lock = NULL;
}
coRNGInit = pristineCallOnce;
}

/* Test functions are not implemented! */
Expand Down

0 comments on commit 6753697

Please sign in to comment.