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