1 /*
2  * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _BOOT_IMAGES_VERIFIER_PARSER_H
8 #define _BOOT_IMAGES_VERIFIER_PARSER_H
9 
10 
11 #ifdef __cplusplus
12 extern "C"
13 {
14 #endif
15 
16 #include "secureboot_defs.h"
17 #include "cc_crypto_boot_defs.h"
18 #include "secureboot_parser_gen_defs.h"
19 #include "secdebug_defs.h"
20 
21 /* Definitions used by the functions */
22 /*-----------------------------------*/
23 
24 /* mask to location of Offset to signature bits in the header cert size parameter */
25 #define CERT_LEN_SIGNATURE_OFFSET_BIT_MASK         0x0000FFFFUL
26 
27 /* certificate version Major offset */
28 #define CERT_VERSION_MAJOR_BIT_SHIFT    16
29 
30 /* Structures used inside the parser code */
31 /*----------------------------------------*/
32 
33 /* RSA data (united to one structure) for RSA_PSS_3072 */
34 typedef struct {
35     /* Pointer to N */
36     uint32_t  *N_ptr;
37 
38     /* Pointer to Np OR H according to algorithm used */
39     uint32_t  *NDer_ptr;
40 
41     /* Pointer to RSA signature */
42     uint32_t *signature;
43 
44     /* Size of cert for HASH computation (offset to signature) */
45     uint32_t   certSizeInWordsForHash;
46 
47 }CCSbCertParserRSAData_t;
48 
49 
50 /*----------------------------
51       PUBLIC FUNCTIONS
52 -----------------------------------*/
53 
54 /*!
55    @brief This function start to load the certificate from flash to RAM,
56    including the signed data and the signature.
57    It does not include the unsigned data in case of content certificate.
58 
59 @return CC_OK   On success.
60 @return A non-zero value from bsv_error.h on failure.
61  */
62 uint32_t CCCertLoadCertificate(CCSbFlashReadFunc flashRead_func,    /*!< [in] Pointer to the flash read function. */
63                                void *userContext,           /*!< [in] An additional pointer for flashRead usage. May be NULL. */
64                                CCAddr_t certAddress,            /*!< [in] The address where the certificate is located. This address is provided to flashReadFunc. */
65                                uint32_t *pCert,             /*!< [in] Buffer for the function's internal use. */
66                                uint32_t *pCertBufferWordSize);      /*!< [in/out] Set the maximum certificate size, and get back the actual certificate size. */
67 
68 /*!
69    @brief This function calculates the certificate size that includes the signed data and the signature.
70 
71 @return CC_OK   On success.
72 @return A non-zero value from bsv_error.h on failure.
73  */
74 uint32_t CCCertGetUnsignedDataOffset(uint32_t *pCert,           /*!< [in] Buffer for the function's internal use. */
75                      uint32_t *pUnsignedDataOffset);    /*!< [out] Get the actual certificate size of the signed data and the signature (in words). */
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif
82 
83 
84