Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(743)

Side by Side Diff: src/shared/platform/nacl_global_secure_random.c

Issue 6937003: modified nacl_sync.h to have NACL_WUR for all functions that return a (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/shared/platform/nacl.scons ('k') | src/shared/platform/nacl_interruptible_condvar.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can 3 * Use of this source code is governed by a BSD-style license that can be
4 * be found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl Service Runtime. Secure RNG abstraction. 8 * NaCl Service Runtime. Secure RNG abstraction.
9 */ 9 */
10 10
11 #include "native_client/src/shared/platform/nacl_global_secure_random.h" 11 #include "native_client/src/shared/platform/nacl_global_secure_random.h"
12 #include "native_client/src/shared/platform/nacl_log.h" 12 #include "native_client/src/shared/platform/nacl_log.h"
13 #include "native_client/src/shared/platform/nacl_secure_random.h" 13 #include "native_client/src/shared/platform/nacl_secure_random.h"
14 #include "native_client/src/shared/platform/nacl_sync.h" 14 #include "native_client/src/shared/platform/nacl_sync.h"
15 #include "native_client/src/shared/platform/nacl_sync_checked.h" 15 #include "native_client/src/shared/platform/nacl_sync_checked.h"
16 16
17 static struct NaClMutex nacl_global_rng_mu; 17 static struct NaClMutex nacl_global_rng_mu;
18 static struct NaClSecureRng nacl_global_rng; 18 static struct NaClSecureRng nacl_global_rng;
19 19
20 static struct NaClSecureRng *nacl_grngp = &nacl_global_rng; 20 static struct NaClSecureRng *nacl_grngp = &nacl_global_rng;
21 21
22 void NaClGlobalSecureRngInit(void) { 22 void NaClGlobalSecureRngInit(void) {
23 NaClMutexCtor(&nacl_global_rng_mu); 23 NaClXMutexCtor(&nacl_global_rng_mu);
24 if (!NaClSecureRngCtor(nacl_grngp)) { 24 if (!NaClSecureRngCtor(nacl_grngp)) {
25 NaClLog(LOG_FATAL, 25 NaClLog(LOG_FATAL,
26 "Could not construct global random number generator.\n"); 26 "Could not construct global random number generator.\n");
27 } 27 }
28 } 28 }
29 29
30 void NaClGlobalSecureRngFini(void) { 30 void NaClGlobalSecureRngFini(void) {
31 (*nacl_grngp->base.vtbl->Dtor)(&nacl_grngp->base); 31 (*nacl_grngp->base.vtbl->Dtor)(&nacl_grngp->base);
32 NaClMutexDtor(&nacl_global_rng_mu); 32 NaClMutexDtor(&nacl_global_rng_mu);
33 } 33 }
34 34
35 void NaClGlobalSecureRngSwitchRngForTesting(struct NaClSecureRng *rng) { 35 void NaClGlobalSecureRngSwitchRngForTesting(struct NaClSecureRng *rng) {
36 NaClMutexLock(&nacl_global_rng_mu); 36 NaClXMutexLock(&nacl_global_rng_mu);
37 nacl_grngp = rng; 37 nacl_grngp = rng;
38 NaClMutexUnlock(&nacl_global_rng_mu); 38 NaClXMutexUnlock(&nacl_global_rng_mu);
39 } 39 }
40 40
41 int32_t NaClGlobalSecureRngUniform(int32_t range_max) { 41 int32_t NaClGlobalSecureRngUniform(int32_t range_max) {
42 int32_t rv; 42 int32_t rv;
43 43
44 NaClXMutexLock(&nacl_global_rng_mu); 44 NaClXMutexLock(&nacl_global_rng_mu);
45 rv = (*nacl_grngp->base.vtbl->Uniform)(&nacl_grngp->base, range_max); 45 rv = (*nacl_grngp->base.vtbl->Uniform)(&nacl_grngp->base, range_max);
46 NaClXMutexUnlock(&nacl_global_rng_mu); 46 NaClXMutexUnlock(&nacl_global_rng_mu);
47 return rv; 47 return rv;
48 } 48 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 int i; 110 int i;
111 int r; 111 int r;
112 112
113 for (i = 0; i < length-1; ++i) { 113 for (i = 0; i < length-1; ++i) {
114 r = NaClGlobalSecureRngUniform(alphabet_size); 114 r = NaClGlobalSecureRngUniform(alphabet_size);
115 path[i] = alphabet[r]; 115 path[i] = alphabet[r];
116 } 116 }
117 path[length-1] = '\0'; 117 path[length-1] = '\0';
118 } 118 }
OLDNEW
« no previous file with comments | « src/shared/platform/nacl.scons ('k') | src/shared/platform/nacl_interruptible_condvar.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698