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

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

Issue 537543003: Add a get_random_bytes() syscall to replace the SRPC-based implementation (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Fix glibc tests Created 6 years, 3 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_global_secure_random.h ('k') | src/trusted/service_runtime/BUILD.gn » ('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 (c) 2011 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 be 3 * Use of this source code is governed by a BSD-style license that can be
4 * 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
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 uint32_t NaClGlobalSecureRngUint32(void) { 50 uint32_t NaClGlobalSecureRngUint32(void) {
51 uint32_t rv; 51 uint32_t rv;
52 NaClXMutexLock(&nacl_global_rng_mu); 52 NaClXMutexLock(&nacl_global_rng_mu);
53 rv = (*nacl_grngp->base.vtbl->GenUint32)(&nacl_grngp->base); 53 rv = (*nacl_grngp->base.vtbl->GenUint32)(&nacl_grngp->base);
54 NaClXMutexUnlock(&nacl_global_rng_mu); 54 NaClXMutexUnlock(&nacl_global_rng_mu);
55 return rv; 55 return rv;
56 } 56 }
57 57
58 void NaClGlobalSecureRngGenerateBytes(uint8_t *buf, size_t buf_size) {
59 NaClXMutexLock(&nacl_global_rng_mu);
60 (*nacl_grngp->base.vtbl->GenBytes)(&nacl_grngp->base, buf, buf_size);
61 NaClXMutexUnlock(&nacl_global_rng_mu);
62 }
63
58 void NaClGenerateRandomPath(char *path, int length) { 64 void NaClGenerateRandomPath(char *path, int length) {
59 /* 65 /*
60 * This function is used for generating random paths and names, 66 * This function is used for generating random paths and names,
61 * e.g. for IMC sockets and semaphores. 67 * e.g. for IMC sockets and semaphores.
62 * 68 *
63 * IMC sockets note: the IMC header file omits some important 69 * IMC sockets note: the IMC header file omits some important
64 * details. The alphabet cannot include backslash for Windows. For 70 * details. The alphabet cannot include backslash for Windows. For
65 * Linux, it uses the abstract namespace (see unix(7)), and can 71 * Linux, it uses the abstract namespace (see unix(7)), and can
66 * contain arbitrary characters. The limitations for OSX are the 72 * contain arbitrary characters. The limitations for OSX are the
67 * same as for pathname components, since the IMC library uses 73 * same as for pathname components, since the IMC library uses
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 123
118 int i; 124 int i;
119 int r; 125 int r;
120 126
121 for (i = 0; i < length-1; ++i) { 127 for (i = 0; i < length-1; ++i) {
122 r = NaClGlobalSecureRngUniform(alphabet_size); 128 r = NaClGlobalSecureRngUniform(alphabet_size);
123 path[i] = alphabet[r]; 129 path[i] = alphabet[r];
124 } 130 }
125 path[length-1] = '\0'; 131 path[length-1] = '\0';
126 } 132 }
OLDNEW
« no previous file with comments | « src/shared/platform/nacl_global_secure_random.h ('k') | src/trusted/service_runtime/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698