Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2014 Freescale Semiconductor, Inc. |
| 4 | * Author: Ruchika Gupta <ruchika.gupta@freescale.com> |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <config.h> |
| 8 | #include <common.h> |
Ye Li | eda25c1 | 2022-09-28 15:49:02 +0530 | [diff] [blame] | 9 | #include <cpu_func.h> |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 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 | |
| 20 | int 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 | /* Length in bytes */ |
| 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 | |
Ye Li | eda25c1 | 2022-09-28 15:49:02 +0530 | [diff] [blame] | 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 | |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 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 | |
Ye Li | eda25c1 | 2022-09-28 15:49:02 +0530 | [diff] [blame] | 53 | invalidate_dcache_range((ulong)out, (ulong)out + sig_len); |
| 54 | |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | static const struct mod_exp_ops fsl_mod_exp_ops = { |
| 59 | .mod_exp = fsl_mod_exp, |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DRIVER(fsl_rsa_mod_exp) = { |
| 63 | .name = "fsl_rsa_mod_exp", |
| 64 | .id = UCLASS_MOD_EXP, |
| 65 | .ops = &fsl_mod_exp_ops, |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 66 | }; |
| 67 | |
Simon Glass | 20e442a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 68 | U_BOOT_DRVINFO(fsl_rsa) = { |
Ruchika Gupta | 3427647 | 2015-01-23 16:01:55 +0530 | [diff] [blame] | 69 | .name = "fsl_rsa_mod_exp", |
| 70 | }; |