On 5/15/21 10:20 AM, Simon Glass wrote:
Hi Alexandru,

On Fri, 14 May 2021 at 13:46, Alexandru Gagniuc <mr.nuke...@gmail.com> wrote:

image-sig.c is used to map a hash or crypto algorithm name to a
handler of that algorithm. There is some similarity between the host
and target variants, with the differences worked out by #ifdefs. The
purpose of this change is to remove those ifdefs.

First, copy the file to a host-only version, and remove target
specific code. Although it looks like we are duplicating code,
subsequent patches will change the way target algorithms are searched.
Besides we are only duplicating three string to struct mapping
functions. This isn't something to fuss about.
---
  common/image-sig-host.c | 134 ++++++++++++++++++++++++++++++++++++++++
  tools/Makefile          |   2 +-
  2 files changed, 135 insertions(+), 1 deletion(-)
  create mode 100644 common/image-sig-host.c

Will we never support signing in the board code? So far it is true,
but I wonder if it will remain so, as things get more and more
complicated. For example, we may want to sign the devicetree (somehow)
after fix-ups. The current code structure makes it possible to add
signing if needed. If we decided we wanted to sign on the board, how
would we refactor things with this approach?

We'd have the logistics of keeping private keys available to firmware and only to firmware, but those are orthogonal to the problem. Assuming we implemented a device-side *_sign(), then we would add it to the linker list, via the proposed U_BOOT_CRYPTO_ALGO():


int rsa_device_side_sign(...)
{
        if (!CONFIG_IS_ENABLED(RSA_SIGN_ON_DEVICE))
                return -EIEIO;
        
        return do_rsa_device_side_sign(...);
}

 U_BOOT_CRYPTO_ALGO(rsa2048) = {
        .name = "rsa2048",
        .key_len = RSA2048_BYTES,
        .verify = rsa_verify,
        .sign = rsa_device_side_sign,
 };

If this is host code, can we move it to tools/ ?

Definitely!

Reply via email to