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"
16 #define KEY_BLOB_SIZE 32
19 void inline_cnstr_jobdesc_hash(uint32_t *desc,
20 const uint8_t *msg, uint32_t msgsz, uint8_t *digest,
21 u32 alg_type, uint32_t alg_size, int sg_tbl)
23 /* SHA 256 , output is of length 32 words */
24 uint32_t storelen = alg_size;
26 dma_addr_t dma_addr_in, dma_addr_out;
28 dma_addr_in = virt_to_phys((void *)msg);
29 dma_addr_out = virt_to_phys((void *)digest);
31 init_job_desc(desc, 0);
32 append_operation(desc, OP_TYPE_CLASS2_ALG |
33 OP_ALG_AAI_HASH | OP_ALG_AS_INITFINAL |
34 OP_ALG_ENCRYPT | OP_ALG_ICV_OFF | alg_type);
36 options = LDST_CLASS_2_CCB | FIFOLD_TYPE_MSG | FIFOLD_TYPE_LAST2;
38 options |= FIFOLDST_SGF;
40 options |= FIFOLDST_EXT;
41 append_fifo_load(desc, dma_addr_in, 0, options);
42 append_cmd(desc, msgsz);
44 append_fifo_load(desc, dma_addr_in, msgsz, options);
47 append_store(desc, dma_addr_out, storelen,
48 LDST_CLASS_2_CCB | LDST_SRCDST_BYTE_CONTEXT);
51 void inline_cnstr_jobdesc_blob_encap(uint32_t *desc, uint8_t *key_idnfr,
52 uint8_t *plain_txt, uint8_t *enc_blob,
55 dma_addr_t dma_addr_key_idnfr, dma_addr_in, dma_addr_out;
56 uint32_t key_sz = KEY_IDNFR_SZ_BYTES;
57 /* output blob will have 32 bytes key blob in beginning and
58 * 16 byte HMAC identifier at end of data blob */
59 uint32_t out_sz = in_sz + KEY_BLOB_SIZE + MAC_SIZE;
61 dma_addr_key_idnfr = virt_to_phys((void *)key_idnfr);
62 dma_addr_in = virt_to_phys((void *)plain_txt);
63 dma_addr_out = virt_to_phys((void *)enc_blob);
65 init_job_desc(desc, 0);
67 append_key(desc, dma_addr_key_idnfr, key_sz, CLASS_2);
69 append_seq_in_ptr(desc, dma_addr_in, in_sz, 0);
71 append_seq_out_ptr(desc, dma_addr_out, out_sz, 0);
73 append_operation(desc, OP_TYPE_ENCAP_PROTOCOL | OP_PCLID_BLOB);
76 void inline_cnstr_jobdesc_blob_decap(uint32_t *desc, uint8_t *key_idnfr,
77 uint8_t *enc_blob, uint8_t *plain_txt,
80 dma_addr_t dma_addr_key_idnfr, dma_addr_in, dma_addr_out;
81 uint32_t key_sz = KEY_IDNFR_SZ_BYTES;
82 uint32_t in_sz = out_sz + KEY_BLOB_SIZE + MAC_SIZE;
84 dma_addr_key_idnfr = virt_to_phys((void *)key_idnfr);
85 dma_addr_in = virt_to_phys((void *)enc_blob);
86 dma_addr_out = virt_to_phys((void *)plain_txt);
88 init_job_desc(desc, 0);
90 append_key(desc, dma_addr_key_idnfr, key_sz, CLASS_2);
92 append_seq_in_ptr(desc, dma_addr_in, in_sz, 0);
94 append_seq_out_ptr(desc, dma_addr_out, out_sz, 0);
96 append_operation(desc, OP_TYPE_DECAP_PROTOCOL | OP_PCLID_BLOB);
100 * Descriptor to instantiate RNG State Handle 0 in normal mode and
101 * load the JDKEK, TDKEK and TDSK registers
103 void inline_cnstr_jobdesc_rng_instantiation(uint32_t *desc)
107 init_job_desc(desc, 0);
109 /* INIT RNG in non-test mode */
110 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
114 jump_cmd = append_jump(desc, JUMP_CLASS_CLASS1);
115 set_jump_tgt_here(desc, jump_cmd);
118 * load 1 to clear written reg:
119 * resets the done interrrupt and returns the RNG to idle.
121 append_load_imm_u32(desc, 1, LDST_SRCDST_WORD_CLRW);
123 /* generate secure keys (non-test) */
124 append_operation(desc, OP_TYPE_CLASS1_ALG | OP_ALG_ALGSEL_RNG |
128 /* Change key size to bytes form bits in calling function*/
129 void inline_cnstr_jobdesc_pkha_rsaexp(uint32_t *desc,
130 struct pk_in_params *pkin, uint8_t *out,
133 dma_addr_t dma_addr_e, dma_addr_a, dma_addr_n, dma_addr_out;
135 dma_addr_e = virt_to_phys((void *)pkin->e);
136 dma_addr_a = virt_to_phys((void *)pkin->a);
137 dma_addr_n = virt_to_phys((void *)pkin->n);
138 dma_addr_out = virt_to_phys((void *)out);
140 init_job_desc(desc, 0);
141 append_key(desc, dma_addr_e, pkin->e_siz, KEY_DEST_PKHA_E | CLASS_1);
143 append_fifo_load(desc, dma_addr_a,
144 pkin->a_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_A);
146 append_fifo_load(desc, dma_addr_n,
147 pkin->n_siz, LDST_CLASS_1_CCB | FIFOLD_TYPE_PK_N);
149 append_operation(desc, OP_TYPE_PK | OP_ALG_PK | OP_ALG_PKMODE_MOD_EXPO);
151 append_fifo_store(desc, dma_addr_out, out_siz,
152 LDST_CLASS_1_CCB | FIFOST_TYPE_PKHA_B);