| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright 2008 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 |
| 4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * NaCl Service Runtime. Secure RNG implementation. | 8 * NaCl Service Runtime. Secure RNG implementation. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 #else | 119 #else |
| 120 | 120 |
| 121 # include <sys/types.h> | 121 # include <sys/types.h> |
| 122 # include <sys/stat.h> | 122 # include <sys/stat.h> |
| 123 # include <fcntl.h> | 123 # include <fcntl.h> |
| 124 | 124 |
| 125 static int rng_d = -1; /* open descriptor for /dev/urandom */ | 125 static int rng_d = -1; /* open descriptor for /dev/urandom */ |
| 126 | 126 |
| 127 # ifdef CHROMIUM_BUILD |
| 128 |
| 129 # include "base/rand_util_c.h" |
| 130 |
| 131 void NaClSecureRngModuleInit(void) { |
| 132 rng_d = GetUrandomFD(); |
| 133 } |
| 134 |
| 135 void NaClSecureRngModuleFini(void) { |
| 136 } |
| 137 |
| 138 # else |
| 139 |
| 127 void NaClSecureRngModuleInit(void) { | 140 void NaClSecureRngModuleInit(void) { |
| 128 rng_d = open(NACL_SECURE_RANDOM_SYSTEM_RANDOM_SOURCE, O_RDONLY, 0); | 141 rng_d = open(NACL_SECURE_RANDOM_SYSTEM_RANDOM_SOURCE, O_RDONLY, 0); |
| 129 if (-1 == rng_d) { | 142 if (-1 == rng_d) { |
| 130 NaClLog(LOG_FATAL, "Cannot open system random source %s\n", | 143 NaClLog(LOG_FATAL, "Cannot open system random source %s\n", |
| 131 NACL_SECURE_RANDOM_SYSTEM_RANDOM_SOURCE); | 144 NACL_SECURE_RANDOM_SYSTEM_RANDOM_SOURCE); |
| 132 } | 145 } |
| 133 } | 146 } |
| 134 | 147 |
| 135 void NaClSecureRngModuleFini(void) { | 148 void NaClSecureRngModuleFini(void) { |
| 136 (void) close(rng_d); | 149 (void) close(rng_d); |
| 137 } | 150 } |
| 138 | 151 |
| 152 # endif /* CHROMIUM_BUILD */ |
| 153 |
| 139 int NaClSecureRngCtor(struct NaClSecureRng *self) { | 154 int NaClSecureRngCtor(struct NaClSecureRng *self) { |
| 140 self->base.vtbl = &kNaClSecureRngVtbl; | 155 self->base.vtbl = &kNaClSecureRngVtbl; |
| 141 self->nvalid = 0; | 156 self->nvalid = 0; |
| 142 return 1; | 157 return 1; |
| 143 } | 158 } |
| 144 | 159 |
| 145 int NaClSecureRngTestingCtor(struct NaClSecureRng *self, | 160 int NaClSecureRngTestingCtor(struct NaClSecureRng *self, |
| 146 uint8_t *seed_material, | 161 uint8_t *seed_material, |
| 147 size_t seed_bytes) { | 162 size_t seed_bytes) { |
| 148 return 0; | 163 return 0; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 178 | 193 |
| 179 #endif | 194 #endif |
| 180 | 195 |
| 181 static struct NaClSecureRngVtbl const kNaClSecureRngVtbl = { | 196 static struct NaClSecureRngVtbl const kNaClSecureRngVtbl = { |
| 182 NaClSecureRngDtor, | 197 NaClSecureRngDtor, |
| 183 NaClSecureRngGenByte, | 198 NaClSecureRngGenByte, |
| 184 NaClSecureRngDefaultGenUint32, | 199 NaClSecureRngDefaultGenUint32, |
| 185 NaClSecureRngDefaultGenBytes, | 200 NaClSecureRngDefaultGenBytes, |
| 186 NaClSecureRngDefaultUniform, | 201 NaClSecureRngDefaultUniform, |
| 187 }; | 202 }; |
| OLD | NEW |