| OLD | NEW |
| 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 #include "native_client/src/trusted/service_runtime/name_service/default_name_se
rvice.h" | 7 #include "native_client/src/trusted/service_runtime/name_service/default_name_se
rvice.h" |
| 8 | 8 |
| 9 #include "native_client/src/shared/platform/nacl_log.h" |
| 10 #include "native_client/src/trusted/desc/nacl_desc_rng.h" |
| 11 #include "native_client/src/trusted/manifest_name_service_proxy/manifest_proxy.h
" |
| 9 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 12 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 10 #include "native_client/src/trusted/desc/nacl_desc_rng.h" | 13 #include "native_client/src/trusted/service_runtime/sel_ldr_thread_interface.h" |
| 11 | 14 |
| 12 int NaClDefaultNameServiceInit(struct NaClNameService *ns) { | 15 int NaClDefaultNameServiceInit(struct NaClNameService *ns) { |
| 13 /* | 16 /* |
| 14 * Create an CSPRNG and enter it into the name server. | 17 * Create an CSPRNG and enter it into the name server. |
| 15 */ | 18 */ |
| 16 struct NaClDescRng *rng = NULL; | 19 struct NaClDescRng *rng = NULL; |
| 17 | 20 |
| 18 rng = (struct NaClDescRng *) malloc(sizeof *rng); | 21 rng = (struct NaClDescRng *) malloc(sizeof *rng); |
| 19 if (NULL == rng) { | 22 if (NULL == rng) { |
| 20 goto malloc_failed; | 23 goto malloc_failed; |
| 21 } | 24 } |
| 22 if (!NaClDescRngCtor(rng)) { | 25 if (!NaClDescRngCtor(rng)) { |
| 23 goto rng_ctor_failed; | 26 goto rng_ctor_failed; |
| 24 } | 27 } |
| 25 | 28 |
| 26 /* | 29 /* |
| 27 * It may appear desirable to insert a factory for rng, so there can | 30 * It may appear desirable to insert a factory for rng, so there can |
| 28 * be per-thread secure rng access. However, note that the only way | 31 * be per-thread secure rng access. However, note that the only way |
| 29 * we "transfer" a RNG is to create a new (but indistinguishable) | 32 * we "transfer" a RNG is to create a new (but indistinguishable) |
| 30 * RNG at the recipient, so each lookup results in a new generator | 33 * RNG at the recipient, so each lookup results in a new generator |
| 31 * anyway. | 34 * anyway. |
| 32 */ | 35 */ |
| 33 (*NACL_VTBL(NaClNameService, ns)-> | 36 (*NACL_VTBL(NaClNameService, ns)-> |
| 34 CreateDescEntry)(ns, | 37 CreateDescEntry)(ns, |
| 35 "SecureRandom", NACL_ABI_O_RDWR, | 38 "SecureRandom", NACL_ABI_O_RDWR, |
| 36 (struct NaClDesc *) rng); | 39 (struct NaClDesc *) rng); |
| 37 NaClDescUnref((struct NaClDesc *) rng); | 40 rng = NULL; |
| 38 | 41 |
| 39 return 1; | 42 return 1; |
| 40 | 43 |
| 41 rng_ctor_failed: | 44 rng_ctor_failed: |
| 42 free(rng); | 45 free(rng); |
| 43 malloc_failed: | 46 malloc_failed: |
| 44 return 0; | 47 return 0; |
| 45 } | 48 } |
| OLD | NEW |