static int instantiate_rng(void) { struct result op; u32 *desc; u32 rdsta_val; int ret = 0; ccsr_sec_t __iomem *sec = (ccsr_sec_t __iomem *)CONFIG_SYS_FSL_SEC_ADDR; struct rng4tst __iomem *rng = (struct rng4tst __iomem *)&sec->rng; memset(&op, 0, sizeof(struct result)); desc = malloc(sizeof(int) * 6); if (!desc) { printf("cannot allocate RNG init descriptor memory\n"); return -1; } inline_cnstr_jobdesc_rng_instantiation(desc); ret = run_descriptor_jr(desc); if (ret) printf("RNG: Instantiation failed with error %x\n", ret); rdsta_val = sec_in32(&rng->rdsta); if (op.status || !(rdsta_val & RNG_STATE0_HANDLE_INSTANTIATED)) return -1; return ret; }
int fsl_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len, struct key_prop *prop, uint8_t *out) { uint32_t keylen; struct pk_in_params pkin; uint32_t desc[MAX_CAAM_DESCSIZE]; int ret; /* Length in bytes */ keylen = prop->num_bits / 8; pkin.a = sig; pkin.a_siz = sig_len; pkin.n = prop->modulus; pkin.n_siz = keylen; pkin.e = prop->public_exponent; pkin.e_siz = prop->exp_len; inline_cnstr_jobdesc_pkha_rsaexp(desc, &pkin, out, sig_len); ret = run_descriptor_jr(desc); if (ret) { debug("%s: RSA failed to verify: %d\n", __func__, ret); return -EFAULT; } return 0; }
static int instantiate_rng(void) { struct result op; u32 *desc; u32 rdsta_val; int ret = 0; ccsr_sec_t __iomem *sec = (ccsr_sec_t __iomem *)CONFIG_SYS_FSL_SEC_ADDR; struct rng4tst __iomem *rng = (struct rng4tst __iomem *)&sec->rng; memset(&op, 0, sizeof(struct result)); desc = memalign(ARCH_DMA_MINALIGN, sizeof(uint32_t) * 6); if (!desc) { printf("cannot allocate RNG init descriptor memory\n"); return -1; } inline_cnstr_jobdesc_rng_instantiation(desc); int size = roundup(sizeof(uint32_t) * 6, ARCH_DMA_MINALIGN); flush_dcache_range((unsigned long)desc, (unsigned long)desc + size); ret = run_descriptor_jr(desc); if (ret) printf("RNG: Instantiation failed with error %x\n", ret); rdsta_val = sec_in32(&rng->rdsta); if (op.status || !(rdsta_val & RNG_STATE0_HANDLE_INSTANTIATED)) return -1; return ret; }