1 /* 2 * Copyright (C) 2016 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 17 #define TLOG_TAG "hwrng_fake_srv" 18 19 #include <stdio.h> 20 #include <stdlib.h> 21 #include <string.h> 22 #include <uapi/err.h> 23 24 #include <hwcrypto/hwrng_dev.h> 25 #include <trusty_log.h> 26 27 #pragma message "Compiling FAKE HWRNG provider" 28 hwrng_dev_init(void)29int hwrng_dev_init(void) { 30 TLOGE("Init FAKE!!!! HWRNG service provider\n"); 31 TLOGE("FAKE HWRNG service provider MUST be replaced with the REAL one\n"); 32 return NO_ERROR; 33 } 34 35 static size_t counter = 1; 36 37 __attribute__((no_sanitize("unsigned-integer-overflow"))) int hwrng_dev_get_rng_data(uint8_t * buf,size_t buf_len)38hwrng_dev_get_rng_data(uint8_t* buf, size_t buf_len) { 39 for (uint8_t* end = buf + buf_len; buf < end; ++buf) { 40 *buf = counter++ & 0xff; 41 } 42 return NO_ERROR; 43 } 44