xref: /openbmc/u-boot/drivers/crypto/fsl/fsl_rsa.c (revision baefb63a)
1 /*
2  * (C) Copyright 2014 Freescale Semiconductor, Inc.
3  * Author: Ruchika Gupta <ruchika.gupta@freescale.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <config.h>
9 #include <common.h>
10 #include <dm.h>
11 #include <asm/types.h>
12 #include <malloc.h>
13 #include "jobdesc.h"
14 #include "desc.h"
15 #include "jr.h"
16 #include "rsa_caam.h"
17 #include <u-boot/rsa-mod-exp.h>
18 
19 int fsl_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
20 		struct key_prop *prop, uint8_t *out)
21 {
22 	uint32_t keylen;
23 	struct pk_in_params pkin;
24 	uint32_t desc[MAX_CAAM_DESCSIZE];
25 	int ret;
26 
27 	/* Length in bytes */
28 	keylen = prop->num_bits / 8;
29 
30 	pkin.a = sig;
31 	pkin.a_siz = sig_len;
32 	pkin.n = prop->modulus;
33 	pkin.n_siz = keylen;
34 	pkin.e = prop->public_exponent;
35 	pkin.e_siz = prop->exp_len;
36 
37 	inline_cnstr_jobdesc_pkha_rsaexp(desc, &pkin, out, sig_len);
38 
39 	ret = run_descriptor_jr(desc);
40 	if (ret) {
41 		debug("%s: RSA failed to verify: %d\n", __func__, ret);
42 		return -EFAULT;
43 	}
44 
45 	return 0;
46 }
47 
48 static const struct mod_exp_ops fsl_mod_exp_ops = {
49 	.mod_exp	= fsl_mod_exp,
50 };
51 
52 U_BOOT_DRIVER(fsl_rsa_mod_exp) = {
53 	.name	= "fsl_rsa_mod_exp",
54 	.id	= UCLASS_MOD_EXP,
55 	.ops	= &fsl_mod_exp_ops,
56 	.flags  = DM_FLAG_PRE_RELOC,
57 };
58 
59 U_BOOT_DEVICE(fsl_rsa) = {
60 	.name = "fsl_rsa_mod_exp",
61 };
62