1d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * Use of this source code is governed by a BSD-style license that can be 3d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * found in the LICENSE file. 4d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * 5d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * Host-side functions for verified boot. 6d183644564ec27c106a3eb1931f565fae167a058Randall Spangler */ 7d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 8d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#ifndef VBOOT_REFERENCE_HOST_SIGNATURE_H_ 9d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#define VBOOT_REFERENCE_HOST_SIGNATURE_H_ 10d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 11d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#include "cryptolib.h" 12d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#include "host_key.h" 13d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#include "utility.h" 14d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#include "vboot_struct.h" 15d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 16d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 17d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Initialize a signature struct. */ 18d183644564ec27c106a3eb1931f565fae167a058Randall Spanglervoid SignatureInit(VbSignature* sig, uint8_t* sig_data, 19d183644564ec27c106a3eb1931f565fae167a058Randall Spangler uint64_t sig_size, uint64_t data_size); 20d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 21d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 22d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Allocate a new signature with space for a [sig_size] byte signature. */ 23d183644564ec27c106a3eb1931f565fae167a058Randall SpanglerVbSignature* SignatureAlloc(uint64_t sig_size, uint64_t data_size); 24d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 25d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 26d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Copy a signature key from [src] to [dest]. 27d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * 28d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * Returns 0 if success, non-zero if error. */ 29d183644564ec27c106a3eb1931f565fae167a058Randall Spanglerint SignatureCopy(VbSignature* dest, const VbSignature* src); 30d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 31d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 32d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Calculates a SHA-512 checksum. 33d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * Caller owns the returned pointer, and must free it with Free(). 34d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * 35068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * Returns NULL on error. */ 36d183644564ec27c106a3eb1931f565fae167a058Randall SpanglerVbSignature* CalculateChecksum(const uint8_t* data, uint64_t size); 37d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 38d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 392448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson/* Calculates a hash of the data using the algorithm from the specified key. 402448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson * Caller owns the returned pointer, and must free it with Free(). 412448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson * 422448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson * Returns NULL on error. */ 432448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill RichardsonVbSignature* CalculateHash(const uint8_t* data, uint64_t size, 442448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson const VbPrivateKey* key); 452448d3b3bc8e80232e7943c16b41eaab19faa1a2Bill Richardson 46d183644564ec27c106a3eb1931f565fae167a058Randall Spangler/* Calculates a signature for the data using the specified key. 47d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * Caller owns the returned pointer, and must free it with Free(). 48d183644564ec27c106a3eb1931f565fae167a058Randall Spangler * 49068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * Returns NULL on error. */ 50d183644564ec27c106a3eb1931f565fae167a058Randall SpanglerVbSignature* CalculateSignature(const uint8_t* data, uint64_t size, 51d183644564ec27c106a3eb1931f565fae167a058Randall Spangler const VbPrivateKey* key); 52d183644564ec27c106a3eb1931f565fae167a058Randall Spangler 53068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah/* Calculates a signature for the data using the specified key and 54068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * an external program. 55068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * Caller owns the returned pointer, and must free it with Free(). 56068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * 57068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah * Returns NULL on error. */ 58068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav ShahVbSignature* CalculateSignature_external(const uint8_t* data, uint64_t size, 59068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah const char* key_file, 60068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah uint64_t key_algorithm, 61068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah const char* external_signer); 62068fc6f251bc80190ad976d18ffe4726a3f33026Gaurav Shah 63d183644564ec27c106a3eb1931f565fae167a058Randall Spangler#endif /* VBOOT_REFERENCE_HOST_SIGNATURE_H_ */ 64