blob: c4605349a67170e939441784882536e33b9799f1 [file] [log] [blame]
gaurav rana47151e42015-02-27 09:45:35 +05301/*
2 * Copyright 2015 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#ifndef _FSL_VALIDATE_H_
8#define _FSL_VALIDATE_H_
9
10#include <fsl_sec.h>
11#include <fsl_sec_mon.h>
12#include <command.h>
13#include <linux/types.h>
14
15#define WORD_SIZE 4
16
17/* Minimum and maximum size of RSA signature length in bits */
18#define KEY_SIZE 4096
19#define KEY_SIZE_BYTES (KEY_SIZE/8)
20#define KEY_SIZE_WORDS (KEY_SIZE_BYTES/(WORD_SIZE))
21
22extern struct jobring jr;
23
24#ifdef CONFIG_KEY_REVOCATION
25/* Srk table and key revocation check */
26#define SRK_FLAG 0x01
27#define UNREVOCABLE_KEY 4
28#define ALIGN_REVOC_KEY 3
29#define MAX_KEY_ENTRIES 4
30#endif
31
32/* Barker code size in bytes */
33#define ESBC_BARKER_LEN 4 /* barker code length in ESBC uboot client */
34 /* header */
35
36/* No-error return values */
37#define ESBC_VALID_HDR 0 /* header is valid */
38
39/* Maximum number of SG entries allowed */
40#define MAX_SG_ENTRIES 8
41
42/*
43 * ESBC uboot client header structure.
44 * The struct contain the following fields
45 * barker code
46 * public key offset
47 * pub key length
48 * signature offset
49 * length of the signature
50 * ptr to SG table
51 * no of entries in SG table
52 * esbc ptr
53 * size of esbc
54 * esbc entry point
55 * Scatter gather flag
56 * UID flag
57 * FSL UID
58 * OEM UID
59 * Here, pub key is modulus concatenated with exponent
60 * of equal length
61 */
62struct fsl_secboot_img_hdr {
63 u8 barker[ESBC_BARKER_LEN]; /* barker code */
64 union {
65 u32 pkey; /* public key offset */
66#ifdef CONFIG_KEY_REVOCATION
67 u32 srk_tbl_off;
68#endif
69 };
70
71 union {
72 u32 key_len; /* pub key length in bytes */
73#ifdef CONFIG_KEY_REVOCATION
74 struct {
75 u32 srk_table_flag:8;
76 u32 srk_sel:8;
77 u32 num_srk:16;
78 } len_kr;
79#endif
80 };
81
82 u32 psign; /* signature offset */
83 u32 sign_len; /* length of the signature in bytes */
84 union {
85 struct fsl_secboot_sg_table *psgtable; /* ptr to SG table */
86 u8 *pimg; /* ptr to ESBC client image */
87 };
88 union {
89 u32 sg_entries; /* no of entries in SG table */
90 u32 img_size; /* ESBC client image size in bytes */
91 };
92 ulong img_start; /* ESBC client entry point */
93 u32 sg_flag; /* Scatter gather flag */
94 u32 uid_flag;
95 u32 fsl_uid_0;
96 u32 oem_uid_0;
97 u32 reserved1[2];
98 u32 fsl_uid_1;
99 u32 oem_uid_1;
100 u32 reserved2[2];
101 u32 ie_flag;
102 u32 ie_key_sel;
103};
104
105#if defined(CONFIG_FSL_ISBC_KEY_EXT)
106struct ie_key_table {
107 u32 key_len;
108 u8 pkey[2 * KEY_SIZE_BYTES];
109};
110
111struct ie_key_info {
112 uint32_t key_revok;
113 uint32_t num_keys;
114 struct ie_key_table ie_key_tbl[32];
115};
116#endif
117
118#ifdef CONFIG_KEY_REVOCATION
119struct srk_table {
120 u32 key_len;
121 u8 pkey[2 * KEY_SIZE_BYTES];
122};
123#endif
124
125/*
126 * SG table.
127 */
128#if defined(CONFIG_FSL_TRUST_ARCH_v1) && defined(CONFIG_FSL_CORENET)
129/*
130 * This struct contains the following fields
131 * length of the segment
132 * source address
133 */
134struct fsl_secboot_sg_table {
135 u32 len; /* length of the segment in bytes */
136 ulong src_addr; /* ptr to the data segment */
137};
138#else
139/*
140 * This struct contains the following fields
141 * length of the segment
142 * Destination Target ID
143 * source address
144 * destination address
145 */
146struct fsl_secboot_sg_table {
147 u32 len;
148 u32 trgt_id;
149 ulong src_addr;
150 ulong dst_addr;
151};
152#endif
153
154/*
155 * ESBC private structure.
156 * Private structure used by ESBC to store following fields
157 * ESBC client key
158 * ESBC client key hash
159 * ESBC client Signature
160 * Encoded hash recovered from signature
161 * Encoded hash of ESBC client header plus ESBC client image
162 */
163struct fsl_secboot_img_priv {
164 uint32_t hdr_location;
165 ulong ie_addr;
166 u32 key_len;
167 struct fsl_secboot_img_hdr hdr;
168
169 u8 img_key[2 * KEY_SIZE_BYTES]; /* ESBC client key */
170 u8 img_key_hash[32]; /* ESBC client key hash */
171
172#ifdef CONFIG_KEY_REVOCATION
173 struct srk_table srk_tbl[MAX_KEY_ENTRIES];
174#endif
175 u8 img_sign[KEY_SIZE_BYTES]; /* ESBC client signature */
176
177 u8 img_encoded_hash[KEY_SIZE_BYTES]; /* EM wrt RSA PKCSv1.5 */
178 /* Includes hash recovered after
179 * signature verification
180 */
181
182 u8 img_encoded_hash_second[KEY_SIZE_BYTES];/* EM' wrt RSA PKCSv1.5 */
183 /* Includes hash of
184 * ESBC client header plus
185 * ESBC client image
186 */
187
188 struct fsl_secboot_sg_table sgtbl[MAX_SG_ENTRIES]; /* SG table */
189 u32 ehdrloc; /* ESBC client location */
190};
191
192int fsl_secboot_validate(cmd_tbl_t *cmdtp, int flag, int argc,
193 char * const argv[]);
194int fsl_secboot_blob_encap(cmd_tbl_t *cmdtp, int flag, int argc,
195 char * const argv[]);
196int fsl_secboot_blob_decap(cmd_tbl_t *cmdtp, int flag, int argc,
197 char * const argv[]);
198
199#endif