1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 8 9 #ifndef UTIL_ASN1_PARSER_H 10 #define UTIL_ASN1_PARSER_H 11 12 #ifdef __cplusplus 13 extern "C" 14 { 15 #endif 16 17 /* ASN1 data structure */ 18 typedef struct 19 { 20 uint8_t tagId; 21 uint32_t itemSize; 22 uint8_t index; 23 24 }CCSbCertAsn1Data_t; 25 26 #define UTILS_ASN1_CERT_VERIFY_PTR_RET(address, startAddress, endAddress){ \ 27 /* If current address is bigger than endAddress, or if there was a wrapAround and the address is smaller than the address we started with */ \ 28 if ((address > endAddress) || (address < startAddress)){ \ 29 CC_PAL_LOG_ERR("Certificate pointer is beyond the allowed limit: addr 0x%lx, start 0x%lx, end 0x%lx\n", address, startAddress, endAddress);\ 30 return CC_SB_X509_CERT_PARSE_ILLEGAL_VAL;\ 31 }\ 32 }\ 33 34 35 #define UTIL_ASN1_GET_NEXT_ITEM_RET(pAsn1buff, size, startAddress, endAddress){ \ 36 (pAsn1buff += size); \ 37 UTILS_ASN1_CERT_VERIFY_PTR_RET((unsigned long)pAsn1buff, startAddress, endAddress); \ 38 }\ 39 40 /** 41 * @brief This function reads ASN1 string and verify its tag 42 * 43 * 44 * @param[in] pInStr - the ASN1 string to read from 45 * @param[in] pAsn1Data - output the asn1 fields 46 * @param[in] tag - tag to comapre to 47 * 48 * @return CCError_t - On success the value CC_OK is returned, 49 * on failure - a value from bootimagesverifierx509_error.h 50 */ 51 CCError_t UTIL_Asn1ReadItemVerifyTag(uint8_t *pInStr, CCSbCertAsn1Data_t *pAsn1Data, uint8_t tag); 52 53 /** 54 * @brief This function reads ASN1 string, verify its tag and fw the str pointer 55 * 56 * 57 * @param[in] ppInStr - the ASN1 string to read from 58 * @param[in] pAsn1Data - output the asn1 fields 59 * @param[in] tag - tag to comapre to 60 * 61 * @return CCError_t - On success the value CC_OK is returned, 62 * on failure - a value from bootimagesverifierx509_error.h 63 */ 64 CCError_t UTIL_Asn1ReadItemVerifyTagFW(uint8_t **ppInStr, CCSbCertAsn1Data_t *pAsn1Data, uint8_t tag, 65 unsigned long startAddress, unsigned long endAddress); 66 67 #ifdef __cplusplus 68 } 69 #endif 70 71 #endif 72 73 74 75