All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 6/6] test: add rsa_verify() unit test
Date: Wed, 20 Nov 2019 14:58:37 +0900	[thread overview]
Message-ID: <20191120055836.GC22427@linaro.org> (raw)
In-Reply-To: <CAPnjgZ0j67t=nhnoQWRfLcOUGnNyhyvPdTpS7ueiq0zAkgz12A@mail.gmail.com>

Simon,

On Tue, Nov 19, 2019 at 06:59:57PM -0800, Simon Glass wrote:
> Hi Takahiro,
> 
> On Tue, 12 Nov 2019 at 16:47, AKASHI Takahiro
> <takahiro.akashi@linaro.org> wrote:
> >
> > In this patch, a very simple test is added to verify that rsa_verify()
> > using rsa_verify_with_pkey() work correctly.
> >
> > To keep the code simple, all the test data, either public key and
> > verified binary data, are embedded in the source.
> >
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >  test/Kconfig      |  12 +++
> >  test/lib/Makefile |   1 +
> >  test/lib/rsa.c    | 207 ++++++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 220 insertions(+)
> >  create mode 100644 test/lib/rsa.c
> >
> > diff --git a/test/Kconfig b/test/Kconfig
> > index cb7954041eda..64d76c3b20a5 100644
> > --- a/test/Kconfig
> > +++ b/test/Kconfig
> > @@ -28,6 +28,18 @@ config UT_LIB_ASN1
> >           Enables a test which exercises asn1 compiler and decoder function
> >           via various parsers.
> >
> > +config UT_LIB_RSA
> > +       bool "Unit test for rsa_verify() function"
> > +       imply RSA
> > +       imply ASYMMETRIC_KEY_TYPE
> > +       imply ASYMMETRIC_PUBLIC_KEY_SUBTYPE
> > +       imply RSA_PUBLIC_KEY_PARSER
> > +       imply RSA_VERIFY_WITH_PKEY
> > +       default y
> > +       help
> > +         Enables rsa_verify() test, currently rsa_verify_with_pkey only()
> > +         only, at the 'ut lib' command.
> > +
> >  endif
> >
> >  config UT_TIME
> > diff --git a/test/lib/Makefile b/test/lib/Makefile
> > index 72d2ec74b5f4..2bf6ef3935bb 100644
> > --- a/test/lib/Makefile
> > +++ b/test/lib/Makefile
> > @@ -8,3 +8,4 @@ obj-y += lmb.o
> >  obj-y += string.o
> >  obj-$(CONFIG_ERRNO_STR) += test_errno_str.o
> >  obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
> > +obj-$(CONFIG_UT_LIB_RSA) += rsa.o
> > diff --git a/test/lib/rsa.c b/test/lib/rsa.c
> > new file mode 100644
> > index 000000000000..ef3860b59a2b
> > --- /dev/null
> > +++ b/test/lib/rsa.c
> > @@ -0,0 +1,207 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/*
> > + * Copyright (c) 2019 Linaro Limited
> > + * Author: AKASHI Takahiro
> > + *
> > + * Unit test for rsa_verify() function
> > + */
> > +
> > +#include <common.h>
> > +#include <command.h>
> > +#include <test/lib.h>
> > +#include <test/test.h>
> > +#include <test/ut.h>
> > +
> > +#include <image.h>
> 
> This should go below command.h above

Okay.

> [..]
> 
> > +/**
> > + * lib_rsa_verify_valid() - unit test for rsa_verify()
> > + *
> > + * Test rsa_verify() with valid hash
> > + *
> > + * @uts:       unit test state
> > + * Return:     0 = success, 1 = failure
> > + */
> > +static int lib_rsa_verify_valid(struct unit_test_state *uts)
> > +{
> > +       struct image_sign_info info;
> > +       struct image_region reg;
> > +       int ret;
> > +
> > +       memset(&info, '\0', sizeof(info));
> > +       info.name = "sha256,rsa2048";
> > +       info.padding = image_get_padding_algo("pkcs-1.5");
> > +       info.checksum = image_get_checksum_algo("sha256,rsa2048");
> > +       info.crypto = image_get_crypto_algo(info.name);
> > +
> > +       info.key = public_key;
> > +       info.keylen = public_key_len;
> > +
> > +       reg.data = data_raw;
> > +       reg.size = data_raw_len;
> > +       ret = rsa_verify(&info, &reg, 1, data_enc, data_enc_len);
> > +       ut_assertf(ret == 0, "verification unexpectedly failed (%d)\n", ret);
> 
> Should there not be a test for success as well?

I'm not quite sure what you meant here.
I think that lib_rsa_verify_invalid() covers a test case for your request.

Thanks,
-Takahiro Akashi


> > +
> > +       return CMD_RET_SUCCESS;
> > +}
> > +
> > +LIB_TEST(lib_rsa_verify_valid, 0);

      reply	other threads:[~2019-11-20  5:58 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13  0:47 [U-Boot] [PATCH v3 0/6] rsa: extend rsa_verify() for UEFI secure boot AKASHI Takahiro
2019-11-13  0:47 ` [U-Boot] [PATCH v3 1/6] lib: rsa: decouple rsa from FIT image verification AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-13  0:47 ` [U-Boot] [PATCH v3 2/6] rsa: add CONFIG_RSA_VERIFY_WITH_PKEY config AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-13  0:47 ` [U-Boot] [PATCH v3 3/6] include: image.h: add key info to image_sign_info AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-20  5:47     ` AKASHI Takahiro
2019-11-13  0:47 ` [U-Boot] [PATCH v3 4/6] lib: rsa: generate additional parameters for public key AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-20  5:53     ` AKASHI Takahiro
2019-11-13  0:47 ` [U-Boot] [PATCH v3 5/6] lib: rsa: add rsa_verify_with_pkey() AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-20  5:54     ` AKASHI Takahiro
2019-11-13  0:47 ` [U-Boot] [PATCH v3 6/6] test: add rsa_verify() unit test AKASHI Takahiro
2019-11-20  2:59   ` Simon Glass
2019-11-20  5:58     ` AKASHI Takahiro [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191120055836.GC22427@linaro.org \
    --to=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.