1 /* Copyright (c) 2014 The Chromium OS Authors. All rights reserved. 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 * 5 * Host-side functions for verified boot key structures 6 */ 7 8 #ifndef VBOOT_REFERENCE_HOST_SIGNATURE2_H_ 9 #define VBOOT_REFERENCE_HOST_SIGNATURE2_H_ 10 11 #include "2struct.h" 12 13 struct vb2_private_key; 14 15 /** 16 * Sign data buffer 17 * 18 * @param sig_ptr On success, points to a newly allocated signature. 19 * Caller is responsible for calling free() on this. 20 * @param data Pointer to data to sign 21 * @param size Size of data to sign in bytes 22 * @param key Private key to use to sign data 23 * @param desc Optional description for signature. If NULL, the 24 * key description will be used. 25 * @return VB2_SUCCESS, or non-zero error code on failure. 26 */ 27 int vb2_sign_data(struct vb2_signature **sig_ptr, 28 const uint8_t *data, 29 uint32_t size, 30 const struct vb2_private_key *key, 31 const char *desc); 32 33 /** 34 * Calculate the signature size for a private key. 35 * 36 * @param size_ptr On success, contains the signature size in bytes. 37 * @param key Key to calculate signature length from. 38 * @param desc Optional description for signature. If NULL, the 39 * key description will be used. 40 * @return VB2_SUCCESS, or non-zero error code on failure. 41 */ 42 int vb2_sig_size_for_key(uint32_t *size_ptr, 43 const struct vb2_private_key *key, 44 const char *desc); 45 46 /** 47 * Calculate the total signature size for a list of keys. 48 * 49 * @param size_ptr On success, contains the signature size in bytes. 50 * @param key_list List of keys to calculate signature length from. 51 * @param key_count Number of keys. 52 * @return VB2_SUCCESS, or non-zero error code on failure. 53 */ 54 int vb2_sig_size_for_keys(uint32_t *size_ptr, 55 const struct vb2_private_key **key_list, 56 uint32_t key_count); 57 58 /** 59 * Sign object with a key. 60 * 61 * @param buf Buffer containing object to sign, starting with 62 * common header 63 * @param sig_offset Offset in buffer at which to store signature. All 64 * data before this in the buffer will be signed. 65 * @param key Key to sign object with 66 * @param desc If non-null, description to use for signature 67 */ 68 int vb2_sign_object(uint8_t *buf, 69 uint32_t sig_offset, 70 const struct vb2_private_key *key, 71 const char *desc); 72 73 /** 74 * Sign object with list of keys. 75 * 76 * @param buf Buffer containing object to sign, starting with 77 * common header 78 * @param sig_offset Offset to start signatures. All data before this 79 * in the buffer will be signed. 80 * @param key_list List of keys to sign object with 81 * @param key_count Number of keys in list 82 */ 83 int vb2_sign_object_multiple(uint8_t *buf, 84 uint32_t sig_offset, 85 const struct vb2_private_key **key_list, 86 uint32_t key_count); 87 88 #endif /* VBOOT_REFERENCE_HOST_SIGNATURE2_H_ */ 89