diff mbox series

[Bluez,v3,2/3] unit/test-crypto: test for bt_crypto_verify_att_sign

Message ID 20200406194749.Bluez.v3.2.Ieda68013af7fbafbf53fbf7c8fd85ea295153e5e@changeid (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series Check the signature of att packets | expand

Commit Message

Archie Pusaka April 6, 2020, 11:48 a.m. UTC
From: Archie Pusaka <apusaka@chromium.org>

Adding tests for verifying att signature

---

Changes in v3:
- Add unit test

Changes in v2: None

 unit/test-crypto.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

Comments

Luiz Augusto von Dentz April 6, 2020, 9:14 p.m. UTC | #1
Hi Archie,

On Mon, Apr 6, 2020 at 4:49 AM Archie Pusaka <apusaka@google.com> wrote:
>
> From: Archie Pusaka <apusaka@chromium.org>
>
> Adding tests for verifying att signature
>
> ---
>
> Changes in v3:
> - Add unit test
>
> Changes in v2: None
>
>  unit/test-crypto.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 59 insertions(+)
>
> diff --git a/unit/test-crypto.c b/unit/test-crypto.c
> index e20b2fa66..3bc944be8 100644
> --- a/unit/test-crypto.c
> +++ b/unit/test-crypto.c
> @@ -272,6 +272,58 @@ static void test_gatt_hash(gconstpointer data)
>         tester_test_passed();
>  }
>
> +struct verify_sign_test_data {
> +       const uint8_t *msg;
> +       uint16_t msg_len;
> +       const uint8_t *key;
> +       bool match;
> +};
> +
> +static const uint8_t msg_to_verify_pass[] = {
> +       0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
> +       0x93, 0x3C, 0x90, 0x0F, 0xf2
> +};
> +
> +static const struct verify_sign_test_data verify_sign_pass_data = {
> +       .msg = msg_to_verify_pass,
> +       .msg_len = sizeof(msg_to_verify_pass),
> +       .key = key_5,
> +       .match = true,
> +};
> +
> +static const uint8_t msg_to_verify_bad_sign[] = {
> +       0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
> +       0x93, 0x3C, 0x90, 0x0F, 0xf1
> +};
> +
> +static const struct verify_sign_test_data verify_sign_bad_sign_data = {
> +       .msg = msg_to_verify_bad_sign,
> +       .msg_len = sizeof(msg_to_verify_bad_sign),
> +       .key = key_5,
> +       .match = false,
> +};
> +
> +static const uint8_t msg_to_verify_too_short[] = {
> +       0xd2, 0x12, 0x00, 0x13, 0x37
> +};
> +
> +static const struct verify_sign_test_data verify_sign_too_short_data = {

These should be msg_to_verify_too_short.

> +       .msg = msg_to_verify_bad_sign,
> +       .msg_len = sizeof(msg_to_verify_bad_sign),
> +       .key = key_5,
> +       .match = false,
> +};
> +
> +static void test_verify_sign(gconstpointer data)
> +{
> +       const struct verify_sign_test_data *d = data;
> +       bool result = bt_crypto_verify_att_sign(crypto, d->key, d->msg,
> +                                               d->msg_len);
> +       g_assert(result == d->match);
> +
> +       tester_test_passed();
> +}
> +
>  int main(int argc, char *argv[])
>  {
>         int exit_status;
> @@ -292,6 +344,13 @@ int main(int argc, char *argv[])
>
>         tester_add("/crypto/gatt_hash", NULL, NULL, test_gatt_hash, NULL);
>
> +       tester_add("/crypto/verify_sign_pass", &verify_sign_pass_data,
> +                                               NULL, test_verify_sign, NULL);
> +       tester_add("/crypto/verify_sign_bad_sign", &verify_sign_bad_sign_data,
> +                                               NULL, test_verify_sign, NULL);
> +       tester_add("/crypto/verify_sign_too_short", &verify_sign_too_short_data,
> +                                               NULL, test_verify_sign, NULL);
> +
>         exit_status = tester_run();
>
>         bt_crypto_unref(crypto);
> --
> 2.26.0.292.g33ef6b2f38-goog
>
Archie Pusaka April 7, 2020, 7:59 a.m. UTC | #2
Hi Luiz,

Thanks, you're correct.

On Tue, 7 Apr 2020 at 05:14, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> Hi Archie,
>
> On Mon, Apr 6, 2020 at 4:49 AM Archie Pusaka <apusaka@google.com> wrote:
> >
> > From: Archie Pusaka <apusaka@chromium.org>
> >
> > Adding tests for verifying att signature
> >
> > ---
> >
> > Changes in v3:
> > - Add unit test
> >
> > Changes in v2: None
> >
> >  unit/test-crypto.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 59 insertions(+)
> >
> > diff --git a/unit/test-crypto.c b/unit/test-crypto.c
> > index e20b2fa66..3bc944be8 100644
> > --- a/unit/test-crypto.c
> > +++ b/unit/test-crypto.c
> > @@ -272,6 +272,58 @@ static void test_gatt_hash(gconstpointer data)
> >         tester_test_passed();
> >  }
> >
> > +struct verify_sign_test_data {
> > +       const uint8_t *msg;
> > +       uint16_t msg_len;
> > +       const uint8_t *key;
> > +       bool match;
> > +};
> > +
> > +static const uint8_t msg_to_verify_pass[] = {
> > +       0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
> > +       0x93, 0x3C, 0x90, 0x0F, 0xf2
> > +};
> > +
> > +static const struct verify_sign_test_data verify_sign_pass_data = {
> > +       .msg = msg_to_verify_pass,
> > +       .msg_len = sizeof(msg_to_verify_pass),
> > +       .key = key_5,
> > +       .match = true,
> > +};
> > +
> > +static const uint8_t msg_to_verify_bad_sign[] = {
> > +       0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
> > +       0x93, 0x3C, 0x90, 0x0F, 0xf1
> > +};
> > +
> > +static const struct verify_sign_test_data verify_sign_bad_sign_data = {
> > +       .msg = msg_to_verify_bad_sign,
> > +       .msg_len = sizeof(msg_to_verify_bad_sign),
> > +       .key = key_5,
> > +       .match = false,
> > +};
> > +
> > +static const uint8_t msg_to_verify_too_short[] = {
> > +       0xd2, 0x12, 0x00, 0x13, 0x37
> > +};
> > +
> > +static const struct verify_sign_test_data verify_sign_too_short_data = {
>
> These should be msg_to_verify_too_short.
>
> > +       .msg = msg_to_verify_bad_sign,
> > +       .msg_len = sizeof(msg_to_verify_bad_sign),
> > +       .key = key_5,
> > +       .match = false,
> > +};
> > +
> > +static void test_verify_sign(gconstpointer data)
> > +{
> > +       const struct verify_sign_test_data *d = data;
> > +       bool result = bt_crypto_verify_att_sign(crypto, d->key, d->msg,
> > +                                               d->msg_len);
> > +       g_assert(result == d->match);
> > +
> > +       tester_test_passed();
> > +}
> > +
> >  int main(int argc, char *argv[])
> >  {
> >         int exit_status;
> > @@ -292,6 +344,13 @@ int main(int argc, char *argv[])
> >
> >         tester_add("/crypto/gatt_hash", NULL, NULL, test_gatt_hash, NULL);
> >
> > +       tester_add("/crypto/verify_sign_pass", &verify_sign_pass_data,
> > +                                               NULL, test_verify_sign, NULL);
> > +       tester_add("/crypto/verify_sign_bad_sign", &verify_sign_bad_sign_data,
> > +                                               NULL, test_verify_sign, NULL);
> > +       tester_add("/crypto/verify_sign_too_short", &verify_sign_too_short_data,
> > +                                               NULL, test_verify_sign, NULL);
> > +
> >         exit_status = tester_run();
> >
> >         bt_crypto_unref(crypto);
> > --
> > 2.26.0.292.g33ef6b2f38-goog
> >
>
>
> --
> Luiz Augusto von Dentz
diff mbox series

Patch

diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index e20b2fa66..3bc944be8 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -272,6 +272,58 @@  static void test_gatt_hash(gconstpointer data)
 	tester_test_passed();
 }
 
+struct verify_sign_test_data {
+	const uint8_t *msg;
+	uint16_t msg_len;
+	const uint8_t *key;
+	bool match;
+};
+
+static const uint8_t msg_to_verify_pass[] = {
+	0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
+	0x93, 0x3C, 0x90, 0x0F, 0xf2
+};
+
+static const struct verify_sign_test_data verify_sign_pass_data = {
+	.msg = msg_to_verify_pass,
+	.msg_len = sizeof(msg_to_verify_pass),
+	.key = key_5,
+	.match = true,
+};
+
+static const uint8_t msg_to_verify_bad_sign[] = {
+	0xd2, 0x12, 0x00, 0x13, 0x37, 0x01, 0x00, 0x00, 0x00, 0xF1, 0x87, 0x1E,
+	0x93, 0x3C, 0x90, 0x0F, 0xf1
+};
+
+static const struct verify_sign_test_data verify_sign_bad_sign_data = {
+	.msg = msg_to_verify_bad_sign,
+	.msg_len = sizeof(msg_to_verify_bad_sign),
+	.key = key_5,
+	.match = false,
+};
+
+static const uint8_t msg_to_verify_too_short[] = {
+	0xd2, 0x12, 0x00, 0x13, 0x37
+};
+
+static const struct verify_sign_test_data verify_sign_too_short_data = {
+	.msg = msg_to_verify_bad_sign,
+	.msg_len = sizeof(msg_to_verify_bad_sign),
+	.key = key_5,
+	.match = false,
+};
+
+static void test_verify_sign(gconstpointer data)
+{
+	const struct verify_sign_test_data *d = data;
+	bool result = bt_crypto_verify_att_sign(crypto, d->key, d->msg,
+						d->msg_len);
+	g_assert(result == d->match);
+
+	tester_test_passed();
+}
+
 int main(int argc, char *argv[])
 {
 	int exit_status;
@@ -292,6 +344,13 @@  int main(int argc, char *argv[])
 
 	tester_add("/crypto/gatt_hash", NULL, NULL, test_gatt_hash, NULL);
 
+	tester_add("/crypto/verify_sign_pass", &verify_sign_pass_data,
+						NULL, test_verify_sign, NULL);
+	tester_add("/crypto/verify_sign_bad_sign", &verify_sign_bad_sign_data,
+						NULL, test_verify_sign, NULL);
+	tester_add("/crypto/verify_sign_too_short", &verify_sign_too_short_data,
+						NULL, test_verify_sign, NULL);
+
 	exit_status = tester_run();
 
 	bt_crypto_unref(crypto);