2 * SEC Descriptor Construction Library
3 * Basic job descriptor construction
5 * Copyright 2014 Freescale Semiconductor, Inc.
7 * SPDX-License-Identifier: GPL-2.0+
12 #include "desc_constr.h"
15 #define KEY_BLOB_SIZE 32
18 void inline_cnstr_jobdesc_hash(uint32_t *desc
,
19 const uint8_t *msg
, uint32_t msgsz
, uint8_t *digest
,
20 u32 alg_type
, uint32_t alg_size
, int sg_tbl
)
22 /* SHA 256 , output is of length 32 words */
23 uint32_t storelen
= alg_size
;
25 dma_addr_t dma_addr_in
, dma_addr_out
;
27 dma_addr_in
= virt_to_phys((void *)msg
);
28 dma_addr_out
= virt_to_phys((void *)digest
);
30 init_job_desc(desc
, 0);
31 append_operation(desc
, OP_TYPE_CLASS2_ALG
|
32 OP_ALG_AAI_HASH
| OP_ALG_AS_INITFINAL
|
33 OP_ALG_ENCRYPT
| OP_ALG_ICV_OFF
| alg_type
);
35 options
= LDST_CLASS_2_CCB
| FIFOLD_TYPE_MSG
| FIFOLD_TYPE_LAST2
;
37 options
|= FIFOLDST_SGF
;
39 options
|= FIFOLDST_EXT
;
40 append_fifo_load(desc
, dma_addr_in
, 0, options
);
41 append_cmd(desc
, msgsz
);
43 append_fifo_load(desc
, dma_addr_in
, msgsz
, options
);
46 append_store(desc
, dma_addr_out
, storelen
,
47 LDST_CLASS_2_CCB
| LDST_SRCDST_BYTE_CONTEXT
);
50 void inline_cnstr_jobdesc_blob_encap(uint32_t *desc
, uint8_t *key_idnfr
,
51 uint8_t *plain_txt
, uint8_t *enc_blob
,
54 dma_addr_t dma_addr_key_idnfr
, dma_addr_in
, dma_addr_out
;
55 uint32_t key_sz
= KEY_IDNFR_SZ_BYTES
;
56 /* output blob will have 32 bytes key blob in beginning and
57 * 16 byte HMAC identifier at end of data blob */
58 uint32_t out_sz
= in_sz
+ KEY_BLOB_SIZE
+ MAC_SIZE
;
60 dma_addr_key_idnfr
= virt_to_phys((void *)key_idnfr
);
61 dma_addr_in
= virt_to_phys((void *)plain_txt
);
62 dma_addr_out
= virt_to_phys((void *)enc_blob
);
64 init_job_desc(desc
, 0);
66 append_key(desc
, dma_addr_key_idnfr
, key_sz
, CLASS_2
);
68 append_seq_in_ptr(desc
, dma_addr_in
, in_sz
, 0);
70 append_seq_out_ptr(desc
, dma_addr_out
, out_sz
, 0);
72 append_operation(desc
, OP_TYPE_ENCAP_PROTOCOL
| OP_PCLID_BLOB
);
75 void inline_cnstr_jobdesc_blob_decap(uint32_t *desc
, uint8_t *key_idnfr
,
76 uint8_t *enc_blob
, uint8_t *plain_txt
,
79 dma_addr_t dma_addr_key_idnfr
, dma_addr_in
, dma_addr_out
;
80 uint32_t key_sz
= KEY_IDNFR_SZ_BYTES
;
81 uint32_t in_sz
= out_sz
+ KEY_BLOB_SIZE
+ MAC_SIZE
;
83 dma_addr_key_idnfr
= virt_to_phys((void *)key_idnfr
);
84 dma_addr_in
= virt_to_phys((void *)enc_blob
);
85 dma_addr_out
= virt_to_phys((void *)plain_txt
);
87 init_job_desc(desc
, 0);
89 append_key(desc
, dma_addr_key_idnfr
, key_sz
, CLASS_2
);
91 append_seq_in_ptr(desc
, dma_addr_in
, in_sz
, 0);
93 append_seq_out_ptr(desc
, dma_addr_out
, out_sz
, 0);
95 append_operation(desc
, OP_TYPE_DECAP_PROTOCOL
| OP_PCLID_BLOB
);
99 * Descriptor to instantiate RNG State Handle 0 in normal mode and
100 * load the JDKEK, TDKEK and TDSK registers
102 void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc
)
106 init_job_desc(desc
, 0);
108 /* INIT RNG in non-test mode */
109 append_operation(desc
, OP_TYPE_CLASS1_ALG
| OP_ALG_ALGSEL_RNG
|
113 jump_cmd
= append_jump(desc
, JUMP_CLASS_CLASS1
);
114 set_jump_tgt_here(desc
, jump_cmd
);
117 * load 1 to clear written reg:
118 * resets the done interrrupt and returns the RNG to idle.
120 append_load_imm_u32(desc
, 1, LDST_SRCDST_WORD_CLRW
);
122 /* generate secure keys (non-test) */
123 append_operation(desc
, OP_TYPE_CLASS1_ALG
| OP_ALG_ALGSEL_RNG
|