1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
4  */
5 
6 #ifndef MEASUREMENT_H
7 #define MEASUREMENT_H
8 
9 #include <assert.h>
10 #include <attest_app.h>
11 #include <smc-rmi.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 
15 /*
16  * Types of measurement headers as specified in RMM Spec. section C1.1.2
17  */
18 #define MEASUREMENT_REALM_HEADER	(1U)
19 #define MEASUREMENT_DATA_HEADER		(2U)
20 #define MEASUREMENT_REC_HEADER		(3U)
21 
22 #define MEASURE_DESC_TYPE_DATA		0x0
23 #define MEASURE_DESC_TYPE_REC		0x1
24 #define MEASURE_DESC_TYPE_RIPAS		0x2
25 
26 /*
27  * Calculate the hash of data with algorithm hash_algo to the buffer `out`.
28  */
29 void measurement_hash_compute(enum hash_algo algorithm,
30 			      void *data,
31 			      size_t size, unsigned char *out);
32 
33 /* Extend a measurement with algorithm hash_algo. */
34 void measurement_extend(void *app_data_cfg,
35 			enum hash_algo algorithm,
36 			void *current_measurement,
37 			void *extend_measurement,
38 			size_t extend_measurement_size,
39 			unsigned char *out,
40 			size_t out_size);
41 
42 /*
43  * Measure a data granule
44  *
45  * Arguments:
46  *	- rim_measurement:	The buffer where the RIM to be updated is found.
47  *	- algorithm:		Algorithm to use for measurement.
48  *	- data:			Content of the granule.
49  *	- ipa:			IPA of the data granule.
50  *	- flags:		Flags according to the specification.
51  */
52 void measurement_data_granule_measure(unsigned char rim_measurement[],
53 				      enum hash_algo algorithm,
54 				      void *data,
55 				      unsigned long ipa,
56 				      unsigned long flags);
57 
58 /*
59  * Measure realm params
60  *
61  * Arguments:
62  *	- rim_measurement:	The buffer where the RIM to be updated is found.
63  *	- algorithm:		Algorithm to use for measurement.
64  *	- realm_params:		The parameters of the realm.
65  */
66 void measurement_realm_params_measure(unsigned char rim_measurement[],
67 				      enum hash_algo algorithm,
68 				      struct rmi_realm_params *realm_params);
69 
70 /*
71  * Measure REC params
72  *
73  * Arguments:
74  *	- rim_measurement:	The buffer where the RIM to be updated is found.
75  *	- algorithm:		Algorithm to use for measurement.
76  *	- rec_params:		The rec params to measure.
77  */
78 void measurement_rec_params_measure(unsigned char rim_measurement[],
79 				    enum hash_algo algorithm,
80 				    struct rmi_rec_params *rec_params);
81 
82 
83 /*
84  * Measure a RIPAS granule
85  *
86  * Arguments:
87  *	- rim_measurement:	The buffer where the RIM to be updated is found.
88  *	- algorithm:		Algorithm to use for measurement.
89  *	- base:			Base of target IPA region.
90  *	- top:			Top of target IPA region.
91  */
92 void measurement_init_ripas_measure(unsigned char rim_measurement[],
93 				    enum hash_algo algorithm,
94 				    unsigned long base,
95 				    unsigned long top);
96 
97 #endif /* MEASUREMENT_H */
98