blob: b21fe6acf5ad4499ed78f3b5b5abb97899870950 [file] [log] [blame]
Andrei Homescu74a54452021-12-10 05:30:21 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ayrton Munoz04137372022-08-03 17:05:09 -040017#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000018#include <openssl/rand.h>
Ayrton Munoz04137372022-08-03 17:05:09 -040019#else
20#include <lib/rand/rand.h>
21#endif
Andrei Homescu74a54452021-12-10 05:30:21 +000022
23#include "../OS.h"
24
25using android::base::Result;
26
27namespace android {
28
29Result<void> setNonBlocking(android::base::borrowed_fd fd) {
30 // Trusty IPC syscalls are all non-blocking by default.
31 return {};
32}
33
34status_t getRandomBytes(uint8_t* data, size_t size) {
Ayrton Munoz04137372022-08-03 17:05:09 -040035#if defined(TRUSTY_USERSPACE)
Andrei Homescu74a54452021-12-10 05:30:21 +000036 int res = RAND_bytes(data, size);
37 return res == 1 ? OK : UNKNOWN_ERROR;
Ayrton Munoz04137372022-08-03 17:05:09 -040038#else
39 int res = rand_get_bytes(data, size);
40 return res == 0 ? OK : UNKNOWN_ERROR;
41#endif // TRUSTY_USERSPACE
Andrei Homescu74a54452021-12-10 05:30:21 +000042}
43
Andrei Homescu24ad36e2022-08-04 01:33:33 +000044status_t dupFileDescriptor(int oldFd, int* newFd) {
45 // TODO: implement separately
46 return INVALID_OPERATION;
47}
48
Andrei Homescu74a54452021-12-10 05:30:21 +000049} // namespace android