Skip to content

Commit

Permalink
Verification now working
Browse files Browse the repository at this point in the history
  • Loading branch information
bremoran committed Jun 5, 2018
1 parent f204892 commit 46cba9a
Showing 1 changed file with 15 additions and 51 deletions.
66 changes: 15 additions & 51 deletions suit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@

#include "cose/test.h"

// #include "CUnit/CUnit.h"
// #include "CUnit/Basic.h"
// #include "CUnit/Automated.h"

// #ifdef HAVE_ALGO_EDDSA
static uint8_t buf[2048];

#define CU_ASSERT(A)
#define CU_ASSERT_EQUAL(A,B)
#define CU_ASSERT_EQUAL_FATAL(A,B)
#define CU_ASSERT(A) A
#define CU_ASSERT_EQUAL(A,B) CU_ASSERT(A)
#define CU_ASSERT_EQUAL_FATAL(A,B) CU_ASSERT(A)

static const unsigned char cose_suite[] = {
0xd8, 0x62, 0x84, 0x44, 0xa1, 0x03, 0x18, 0x2a, 0xa0, 0x58, 0xcd, 0x8a,
Expand Down Expand Up @@ -57,40 +52,24 @@ static const unsigned char cose_suite[] = {
0xce, 0x54, 0x43, 0xb4, 0x4d, 0x55, 0x8f, 0xa5, 0xc8, 0xbc, 0xf4, 0xc4,
0x76, 0x38, 0x89, 0x67, 0xc7, 0x88, 0x79, 0x7f
};
unsigned int test_out_signed_cose_len = 311;

static const uint8_t keyid[] = "Something@somewhere";


// static unsigned char pk_x[] = {
// 0x5b, 0x69, 0xb5, 0x30, 0x6d, 0xf5, 0x5c, 0xf8, 0xa, 0xd0, 0xa9, 0x8c,
// 0xa5, 0x76, 0x1c, 0xdc, 0x10, 0x48, 0x3f, 0x29, 0x86, 0xaf, 0xec, 0x56,
// 0x7c, 0xf9, 0xbf, 0xb1, 0xa8, 0x5e, 0x66, 0x92,
// };
// static unsigned char pk_y[] = {
// 0x2e, 0xbf, 0xef, 0xa9, 0xd3, 0x57, 0x75, 0x72, 0xb4, 0x90, 0x25, 0xcc,
// 0x44, 0x76, 0xee, 0xc9, 0xdd, 0xc5, 0x16, 0xb0, 0x49, 0x5f, 0xdd, 0x4e,
// 0x7c, 0xa0, 0x65, 0x21, 0x26, 0x71, 0xba, 0x5e
// };

// static unsigned char pk [] = {
// 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x5b, 0x69, 0xb5, 0x30, 0x6d, 0xf5, 0x5c, 0xf8, 0x0a, 0xd0, 0xa9, 0x8c, 0xa5, 0x76, 0x1c, 0xdc, 0x10, 0x48, 0x3f, 0x29, 0x86, 0xaf, 0xec, 0x56, 0x7c, 0xf9, 0xbf, 0xb1, 0xa8, 0x5e, 0x66, 0x92, 0x2e, 0xbf, 0xef, 0xa9, 0xd3, 0x57, 0x75, 0x72, 0xb4, 0x90, 0x25, 0xcc, 0x44, 0x76, 0xee, 0xc9, 0xdd, 0xc5, 0x16, 0xb0, 0x49, 0x5f, 0xdd, 0x4e, 0x7c, 0xa0, 0x65, 0x21, 0x26, 0x71, 0xba, 0x5e
// };

static unsigned char pk [] = {
0x30, 0x44,
0x02, 0x20,
0x5b, 0x69, 0xb5, 0x30, 0x6d, 0xf5, 0x5c, 0xf8, 0xa, 0xd0, 0xa9, 0x8c,
static unsigned char pk_x[MBEDTLS_ECP_MAX_BYTES] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5b, 0x69, 0xb5, 0x30, 0x6d, 0xf5, 0x5c, 0xf8, 0x0a, 0xd0, 0xa9, 0x8c,
0xa5, 0x76, 0x1c, 0xdc, 0x10, 0x48, 0x3f, 0x29, 0x86, 0xaf, 0xec, 0x56,
0x7c, 0xf9, 0xbf, 0xb1, 0xa8, 0x5e, 0x66, 0x92,
0x02, 0x20,
};
static unsigned char pk_y[MBEDTLS_ECP_MAX_BYTES] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x2e, 0xbf, 0xef, 0xa9, 0xd3, 0x57, 0x75, 0x72, 0xb4, 0x90, 0x25, 0xcc,
0x44, 0x76, 0xee, 0xc9, 0xdd, 0xc5, 0x16, 0xb0, 0x49, 0x5f, 0xdd, 0x4e,
0x7c, 0xa0, 0x65, 0x21, 0x26, 0x71, 0xba, 0x5e

};


static void print_bytestr(const uint8_t *bytes, size_t len)
{
for(unsigned int idx=0; idx < len; idx++)
Expand All @@ -110,8 +89,7 @@ int main(void)

/* First signer */
cose_key_init(&signer);
// cose_key_set_keys(&signer, COSE_EC_CURVE_P256, COSE_ALGO_ES256, pk_x, pk_y, NULL);
cose_key_set_keys(&signer, COSE_EC_CURVE_P256, COSE_ALGO_ES256, pk, NULL, NULL);
cose_key_set_keys(&signer, COSE_EC_CURVE_P256, COSE_ALGO_ES256, pk_x, pk_y, NULL);

printf("COSE bytestream: \n");
print_bytestr(cose_suite, sizeof(cose_suite));
Expand All @@ -125,7 +103,7 @@ int main(void)
cose_sign_iter_t iter;
cose_sign_iter_init(&verify, &iter);
CU_ASSERT(cose_sign_iter(&iter, &signature));

int verification = cose_sign_verify(&verify, &signature, &signer, buf, sizeof(buf));
printf("Verification: %d\n", verification);
CU_ASSERT_EQUAL(verification, 0);
Expand All @@ -137,17 +115,3 @@ int main(void)
CU_ASSERT_EQUAL(memcmp(kid, keyid, sizeof(keyid) - 1), 0);
printf("Verify Result: %d\n", res);
}
// #endif

// const test_t tests_suit[] = {
// // #ifdef HAVE_ALGO_EDDSA
// {
// .f = test_suit1,
// .n = "Verify with known signed",
// },
// // #endif
// {
// .f = NULL,
// .n = NULL,
// }
// };

0 comments on commit 46cba9a

Please sign in to comment.