1 /* 2 * Copyright (c) 2019, Rockchip Technology Co., Ltd. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * usage: decrypt cipher text with AES CTS mode, 30 * key is auto derived from hardware key in TEE. 31 * params: cipher, input data 32 * cipher_len, input data length 33 * plain, output data 34 * plain_len, output data length 35 * return: 0 success, others fail 36 */ 37 int rk_decrypt_data(unsigned char *cipher, unsigned int cipher_len, 38 unsigned char *plain, unsigned int *plain_len); 39 /* 40 * usage: encrypt plain text with AES CTS mode, 41 * key is auto derived from hardware key in TEE. 42 * params: plain, input data 43 * plain_len, input data length 44 * cipher, output data 45 * cipher_len, output data length 46 * return: 0 success, others fail 47 */ 48 int rk_encrypt_data(unsigned char *plain, unsigned int plain_len, 49 unsigned char *cipher, unsigned int *cipher_len); 50 /* 51 * usage: read secure boot enable flag. 52 * params: flag, output data 53 * flag = 0 means disable, flag = 1 means enabled 54 * return: 0 success, others fail 55 */ 56 int rk_read_secure_boot_enable_flag(uint8_t *flag); 57 /* 58 * usage: read vboot key hash. 59 * params: buf, output data 60 * length, output data length, it should be 32 or 64 bytes 61 * return: 0 success, others fail 62 */ 63 int rk_read_vbootkey_hash(uint8_t *buf, uint32_t length); 64