Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 1 | /* |
| 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 Munoz | 0413737 | 2022-08-03 17:05:09 -0400 | [diff] [blame] | 17 | #if defined(TRUSTY_USERSPACE) |
Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 18 | #include <openssl/rand.h> |
Ayrton Munoz | 0413737 | 2022-08-03 17:05:09 -0400 | [diff] [blame] | 19 | #else |
| 20 | #include <lib/rand/rand.h> |
| 21 | #endif |
Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 22 | |
| 23 | #include "../OS.h" |
| 24 | |
| 25 | using android::base::Result; |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | Result<void> setNonBlocking(android::base::borrowed_fd fd) { |
| 30 | // Trusty IPC syscalls are all non-blocking by default. |
| 31 | return {}; |
| 32 | } |
| 33 | |
| 34 | status_t getRandomBytes(uint8_t* data, size_t size) { |
Ayrton Munoz | 0413737 | 2022-08-03 17:05:09 -0400 | [diff] [blame] | 35 | #if defined(TRUSTY_USERSPACE) |
Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 36 | int res = RAND_bytes(data, size); |
| 37 | return res == 1 ? OK : UNKNOWN_ERROR; |
Ayrton Munoz | 0413737 | 2022-08-03 17:05:09 -0400 | [diff] [blame] | 38 | #else |
| 39 | int res = rand_get_bytes(data, size); |
| 40 | return res == 0 ? OK : UNKNOWN_ERROR; |
| 41 | #endif // TRUSTY_USERSPACE |
Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Andrei Homescu | 24ad36e | 2022-08-04 01:33:33 +0000 | [diff] [blame] | 44 | status_t dupFileDescriptor(int oldFd, int* newFd) { |
| 45 | // TODO: implement separately |
| 46 | return INVALID_OPERATION; |
| 47 | } |
| 48 | |
Andrei Homescu | 74a5445 | 2021-12-10 05:30:21 +0000 | [diff] [blame] | 49 | } // namespace android |