1
2
3
4
5
6
7#include <config.h>
8#include <common.h>
9#include <cpu_func.h>
10#include <dm.h>
11#include <log.h>
12#include <asm/types.h>
13#include <malloc.h>
14#include "jobdesc.h"
15#include "desc.h"
16#include "jr.h"
17#include "rsa_caam.h"
18#include <u-boot/rsa-mod-exp.h>
19
20int fsl_mod_exp(struct udevice *dev, const uint8_t *sig, uint32_t sig_len,
21 struct key_prop *prop, uint8_t *out)
22{
23 uint32_t keylen;
24 struct pk_in_params pkin;
25 uint32_t desc[MAX_CAAM_DESCSIZE];
26 int ret;
27
28
29 keylen = prop->num_bits / 8;
30
31 pkin.a = sig;
32 pkin.a_siz = sig_len;
33 pkin.n = prop->modulus;
34 pkin.n_siz = keylen;
35 pkin.e = prop->public_exponent;
36 pkin.e_siz = prop->exp_len;
37
38 inline_cnstr_jobdesc_pkha_rsaexp(desc, &pkin, out, sig_len);
39
40 flush_dcache_range((ulong)sig, (ulong)sig + sig_len);
41 flush_dcache_range((ulong)prop->modulus, (ulong)(prop->modulus) + keylen);
42 flush_dcache_range((ulong)prop->public_exponent,
43 (ulong)(prop->public_exponent) + prop->exp_len);
44 flush_dcache_range((ulong)desc, (ulong)desc + (sizeof(uint32_t) * MAX_CAAM_DESCSIZE));
45 flush_dcache_range((ulong)out, (ulong)out + sig_len);
46
47 ret = run_descriptor_jr(desc);
48 if (ret) {
49 debug("%s: RSA failed to verify: %d\n", __func__, ret);
50 return -EFAULT;
51 }
52
53 invalidate_dcache_range((ulong)out, (ulong)out + sig_len);
54
55 return 0;
56}
57
58static const struct mod_exp_ops fsl_mod_exp_ops = {
59 .mod_exp = fsl_mod_exp,
60};
61
62U_BOOT_DRIVER(fsl_rsa_mod_exp) = {
63 .name = "fsl_rsa_mod_exp",
64 .id = UCLASS_MOD_EXP,
65 .ops = &fsl_mod_exp_ops,
66};
67
68U_BOOT_DRVINFO(fsl_rsa) = {
69 .name = "fsl_rsa_mod_exp",
70};
71