mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-12 02:45:33 +00:00
Previously, we had a mix of sig_algorithm and sig_alg member names, and it was hard to remember which struct used which variant. Prefer sig_alg because of the 80-column limit. Same with hash_alg vs. hash_algorithm BUG=chromium:423882 BRANCH=none TEST=VBOOT2=1 make runtests Change-Id: Ifbb60f3172549e29efc0fb1f7f693efa51eb7cc3 Signed-off-by: Randall Spangler <rspangler@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226943 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
59 lines
1.7 KiB
C
59 lines
1.7 KiB
C
/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*
|
|
* Convert structs from vboot1 data format to new vboot2 structs
|
|
*/
|
|
|
|
#include "2sysincludes.h"
|
|
#include "2common.h"
|
|
#include "2rsa.h"
|
|
#include "vb2_convert_structs.h"
|
|
#include "vboot_struct.h" /* For old struct sizes */
|
|
|
|
#include "test_common.h"
|
|
|
|
struct vb2_packed_key2 *vb2_convert_packed_key2(
|
|
const struct vb2_packed_key *key,
|
|
const char *desc, uint32_t *out_size)
|
|
{
|
|
struct vb2_packed_key2 k2 = {
|
|
.c.magic = VB2_MAGIC_PACKED_KEY2,
|
|
.c.struct_version_major = VB2_PACKED_KEY2_VERSION_MAJOR,
|
|
.c.struct_version_minor = VB2_PACKED_KEY2_VERSION_MINOR,
|
|
};
|
|
uint8_t *kbuf;
|
|
|
|
/* Calculate sizes and offsets */
|
|
k2.c.fixed_size = sizeof(k2);
|
|
k2.c.desc_size = roundup32(strlen(desc) + 1);
|
|
k2.key_offset = k2.c.fixed_size + k2.c.desc_size;
|
|
k2.key_size = key->key_size;
|
|
k2.c.total_size = k2.key_offset + k2.key_size;
|
|
|
|
/* Copy/initialize fields */
|
|
k2.key_version = key->key_version;
|
|
k2.sig_alg = vb2_crypto_to_signature(key->algorithm);
|
|
k2.hash_alg = vb2_crypto_to_hash(key->algorithm);
|
|
/* TODO: fill in a non-zero GUID */
|
|
|
|
/* Allocate the new buffer */
|
|
*out_size = k2.c.total_size;
|
|
kbuf = malloc(*out_size);
|
|
memset(kbuf, 0, *out_size);
|
|
|
|
/* Copy data into the buffer */
|
|
memcpy(kbuf, &k2, sizeof(k2));
|
|
|
|
/* strcpy() is safe because we allocated above based on strlen() */
|
|
strcpy((char *)(kbuf + k2.c.fixed_size), desc);
|
|
kbuf[k2.c.fixed_size + k2.c.desc_size - 1] = 0;
|
|
|
|
memcpy(kbuf + k2.key_offset,
|
|
(const uint8_t *)key + key->key_offset,
|
|
key->key_size);
|
|
|
|
/* Return the newly allocated buffer */
|
|
return (struct vb2_packed_key2 *)kbuf;
|
|
}
|