Home | History | Annotate | Download | only in include
      1 /* Copyright (c) 2010 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.
      6  */
      7 
      8 #ifndef VBOOT_REFERENCE_HOST_KEY_H_
      9 #define VBOOT_REFERENCE_HOST_KEY_H_
     10 
     11 #include "cryptolib.h"
     12 #include "vboot_struct.h"
     13 
     14 
     15 typedef struct rsa_st RSA;
     16 
     17 /* Private key data */
     18 typedef struct VbPrivateKey {
     19   RSA* rsa_private_key;  /* Private key data */
     20   uint64_t algorithm;    /* Algorithm to use when signing */
     21 } VbPrivateKey;
     22 
     23 
     24 /* Read a private key from a .pem file.  Caller owns the returned pointer,
     25  * and must free it with PrivateKeyFree(). */
     26 VbPrivateKey* PrivateKeyReadPem(const char* filename, uint64_t algorithm);
     27 
     28 
     29 /* Free a private key. */
     30 void PrivateKeyFree(VbPrivateKey* key);
     31 
     32 /* Write a private key to a file in .vbprivk format. */
     33 int PrivateKeyWrite(const char* filename, const VbPrivateKey* key);
     34 
     35 /* Read a privake key from a .vbprivk file.  Caller owns the returned
     36  * pointer, and must free it with PrivateKeyFree().
     37  *
     38  * Returns NULL if error. */
     39 VbPrivateKey* PrivateKeyRead(const char* filename);
     40 
     41 
     42 
     43 /* Allocate a new public key with space for a [key_size] byte key. */
     44 VbPublicKey* PublicKeyAlloc(uint64_t key_size, uint64_t algorithm,
     45                             uint64_t version);
     46 
     47 
     48 /* Read a public key from a .vbpubk file.  Caller owns the returned
     49  * pointer, and must free it with Free().
     50  *
     51  * Returns NULL if error. */
     52 VbPublicKey* PublicKeyRead(const char* filename);
     53 
     54 /* Return true if the public key struct appears correct. */
     55 int PublicKeyLooksOkay(VbPublicKey *key, uint64_t file_size);
     56 
     57 /* Read a public key from a .keyb file.  Caller owns the returned
     58  * pointer, and must free it with Free().
     59  *
     60  * Returns NULL if error. */
     61 VbPublicKey* PublicKeyReadKeyb(const char* filename, uint64_t algorithm,
     62                                uint64_t version);
     63 
     64 
     65 /* Write a public key to a file in .vbpubk format. */
     66 int PublicKeyWrite(const char* filename, const VbPublicKey* key);
     67 
     68 
     69 #endif  /* VBOOT_REFERENCE_HOST_KEY_H_ */
     70