Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created January 9, 2024 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamaury/4bd281d05fc56552433ddc67dfaa8569 to your computer and use it in GitHub Desktop.
Save pamaury/4bd281d05fc56552433ddc67dfaa8569 to your computer and use it in GitHub Desktop.
// Copyright lowRISC contributors.
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
// SPDX-License-Identifier: Apache-2.0
// This file was automatically generated using opentitantool from:
// sw/device/silicon_creator/lib/cert/cdi_1.hjson
extern "C" {
#include "cdi_1.h"
}
#include "gtest/gtest.h"
uint8_t g_cert_signature_s[] = {0x5b, 0x21, 0x4a, 0x6a, 0x1, 0x1d, 0xbe, 0x5e,
0x65, 0xe1, 0xa6, 0x56, 0xfb, 0x7a, 0xc1, 0x33,
0xba, 0x65, 0x40, 0x8e, 0x59, 0x5f, 0xbe, 0x99,
0xa7, 0xcd, 0x4f, 0xc4, 0xe8, 0x4d, 0x18, 0xbf};
uint8_t g_owner_pub_key_ec_x[] = {
0x57, 0xa8, 0xc5, 0x69, 0xab, 0x2a, 0xcf, 0x0, 0x55, 0xa0, 0x46,
0x46, 0x2c, 0xc7, 0x5e, 0x51, 0xb3, 0xf1, 0x12, 0x1d, 0x4c, 0x51,
0x79, 0x9e, 0x10, 0xad, 0x52, 0xa6, 0xd0, 0x5d, 0x44, 0x3d};
uint8_t g_cert_signature_r[] = {0x79, 0x43, 0xaf, 0x71, 0xca, 0x8b, 0x9d, 0xc8,
0x93, 0x91, 0x99, 0xb6, 0x7d, 0x4d, 0x12, 0x29,
0x7, 0x17, 0x93, 0x23, 0xb0, 0x38, 0x76, 0x9c,
0x35, 0x29, 0x3b, 0xb5, 0xa6, 0xea, 0x56, 0xe1};
uint8_t g_owner_firmware_hash[] = {0xa1, 0xa6, 0xbd, 0x3, 0x1d, 0x17, 0xe0,
0x5f, 0x3f, 0x8a, 0x7, 0x6a, 0x3c, 0x56,
0xe8, 0x2d, 0xd6, 0x9c, 0x76, 0x83};
uint32_t g_owner_security_version = 31008;
uint8_t g_owner_intermediate_pub_key_id[] = {
0x75, 0x36, 0x52, 0xcb, 0x15, 0x15, 0x38, 0x21, 0x5d, 0x41,
0x8d, 0xf9, 0xc7, 0x42, 0x28, 0x75, 0x26, 0x33, 0xc3, 0x4};
uint8_t g_owner_pub_key_ec_y[] = {
0xea, 0xd7, 0xdc, 0x32, 0x8f, 0x2e, 0x52, 0xe4, 0xf7, 0x48, 0x30,
0xfa, 0x31, 0xf, 0xf7, 0xf1, 0xc5, 0x81, 0xb6, 0x59, 0xf8, 0x5e,
0xa4, 0x9b, 0x28, 0xc4, 0x98, 0x86, 0x3f, 0x4f, 0x10, 0x78};
uint8_t g_owner_pub_key_id[] = {0x42, 0xcd, 0xeb, 0x0, 0xbb, 0x9e, 0x48,
0xe9, 0x26, 0x58, 0x8b, 0xcb, 0xac, 0x89,
0x60, 0x5c, 0xc4, 0x69, 0xbb, 0x8b};
cdi_1_tbs_values_t g_tbs_values = {
.owner_security_version = g_owner_security_version,
.owner_pub_key_ec_x = g_owner_pub_key_ec_x,
.owner_pub_key_ec_x_size = sizeof(g_owner_pub_key_ec_x),
.owner_pub_key_id = g_owner_pub_key_id,
.owner_pub_key_id_size = sizeof(g_owner_pub_key_id),
.owner_firmware_hash = g_owner_firmware_hash,
.owner_firmware_hash_size = sizeof(g_owner_firmware_hash),
.owner_intermediate_pub_key_id = g_owner_intermediate_pub_key_id,
.owner_intermediate_pub_key_id_size =
sizeof(g_owner_intermediate_pub_key_id),
.owner_pub_key_ec_y = g_owner_pub_key_ec_y,
.owner_pub_key_ec_y_size = sizeof(g_owner_pub_key_ec_y),
};
uint8_t g_tbs[477];
cdi_1_sig_values_t g_sig_values = {
.cert_signature_s = g_cert_signature_s,
.cert_signature_s_size = sizeof(g_cert_signature_s),
.tbs = g_tbs,
.tbs_size = sizeof(g_tbs),
.cert_signature_r = g_cert_signature_r,
.cert_signature_r_size = sizeof(g_cert_signature_r),
};
uint8_t g_cert_data[568];
const uint8_t kExpectedCert[560] = {
0x30, 0x82, 0x2, 0x2c, 0x30, 0x82, 0x1, 0xd3, 0xa0, 0x3, 0x2, 0x1,
0x2, 0x2, 0x14, 0x42, 0xcd, 0xeb, 0x0, 0xbb, 0x9e, 0x48, 0xe9, 0x26,
0x58, 0x8b, 0xcb, 0xac, 0x89, 0x60, 0x5c, 0xc4, 0x69, 0xbb, 0x8b, 0x30,
0xa, 0x6, 0x8, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x4, 0x3, 0x2, 0x30,
0x33, 0x31, 0x31, 0x30, 0x2f, 0x6, 0x3, 0x55, 0x4, 0x5, 0x13, 0x28,
0x37, 0x35, 0x33, 0x36, 0x35, 0x32, 0x63, 0x62, 0x31, 0x35, 0x31, 0x35,
0x33, 0x38, 0x32, 0x31, 0x35, 0x64, 0x34, 0x31, 0x38, 0x64, 0x66, 0x39,
0x63, 0x37, 0x34, 0x32, 0x32, 0x38, 0x37, 0x35, 0x32, 0x36, 0x33, 0x33,
0x63, 0x33, 0x30, 0x34, 0x30, 0x22, 0x18, 0xf, 0x32, 0x30, 0x32, 0x33,
0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a, 0x18,
0xf, 0x39, 0x39, 0x39, 0x39, 0x31, 0x32, 0x33, 0x31, 0x32, 0x33, 0x35,
0x39, 0x35, 0x39, 0x5a, 0x30, 0x33, 0x31, 0x31, 0x30, 0x2f, 0x6, 0x3,
0x55, 0x4, 0x5, 0x13, 0x28, 0x34, 0x32, 0x63, 0x64, 0x65, 0x62, 0x30,
0x30, 0x62, 0x62, 0x39, 0x65, 0x34, 0x38, 0x65, 0x39, 0x32, 0x36, 0x35,
0x38, 0x38, 0x62, 0x63, 0x62, 0x61, 0x63, 0x38, 0x39, 0x36, 0x30, 0x35,
0x63, 0x63, 0x34, 0x36, 0x39, 0x62, 0x62, 0x38, 0x62, 0x30, 0x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cb,
0xac, 0x89, 0x60, 0x5c, 0xc4, 0x69, 0xbb, 0x8b, 0x30, 0x51, 0x6, 0x6,
0x67, 0x81, 0x5, 0x5, 0x4, 0x1, 0x1, 0x1, 0x0, 0x4, 0x44, 0x30,
0x42, 0x80, 0x9, 0x4f, 0x70, 0x65, 0x6e, 0x54, 0x69, 0x74, 0x61, 0x6e,
0x81, 0x5, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x83, 0x2, 0x79, 0x20, 0x84,
0x1, 0x2, 0xa6, 0x23, 0x30, 0x21, 0x6, 0x9, 0x60, 0x86, 0x48, 0x1,
0x65, 0x3, 0x4, 0x2, 0x1, 0x4, 0x14, 0xa1, 0xa6, 0xbd, 0x3, 0x1d,
0x17, 0xe0, 0x5f, 0x3f, 0x8a, 0x7, 0x6a, 0x3c, 0x56, 0xe8, 0x2d, 0xd6,
0x9c, 0x76, 0x83, 0x87, 0x2, 0x4, 0x0, 0x30, 0xa, 0x6, 0x8, 0x2a,
0x86, 0x48, 0xce, 0x3d, 0x4, 0x3, 0x2, 0x3, 0x47, 0x0, 0x30, 0x44,
0x2, 0x20, 0x79, 0x43, 0xaf, 0x71, 0xca, 0x8b, 0x9d, 0xc8, 0x93, 0x91,
0x99, 0xb6, 0x7d, 0x4d, 0x12, 0x29, 0x7, 0x17, 0x93, 0x23, 0xb0, 0x38,
0x76, 0x9c, 0x35, 0x29, 0x3b, 0xb5, 0xa6, 0xea, 0x56, 0xe1, 0x2, 0x20,
0x5b, 0x21, 0x4a, 0x6a, 0x1, 0x1d, 0xbe, 0x5e, 0x65, 0xe1, 0xa6, 0x56,
0xfb, 0x7a, 0xc1, 0x33, 0xba, 0x65, 0x40, 0x8e, 0x59, 0x5f, 0xbe, 0x99,
0xa7, 0xcd, 0x4f, 0xc4, 0xe8, 0x4d, 0x18, 0xbf};
TEST(Cdi1, Verify) {
EXPECT_EQ(kErrorOk,
cdi_1_build_tbs(&g_tbs_values, g_tbs, &g_sig_values.tbs_size));
size_t cert_size = sizeof(g_cert_data);
EXPECT_EQ(kErrorOk, cdi_1_build_cert(&g_sig_values, g_cert_data, &cert_size));
EXPECT_EQ(cert_size, sizeof(kExpectedCert));
EXPECT_EQ(0, memcmp(g_cert_data, kExpectedCert, cert_size));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment