EncoreBootImageReader.h
/*
* File: EncoreBootImageReader.h
*
* Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
* See included license file for license details.
*/
#if !defined(_EncoreBootImageReader_h_)
#define _EncoreBootImageReader_h_
#include "EncoreBootImage.h"
namespace elftosb
{
class EncoreBootImageReader
{
public:
class read_error : public std::runtime_error
{
public:
read_error(const std::string &msg)
: std::runtime_error(msg)
{
}
};
typedef std::vector<EncoreBootImage::section_header_t> section_array_t;
typedef std::vector<EncoreBootImage::boot_command_t> boot_tag_array_t;
public:
EncoreBootImageReader(std::istream &stream)
: m_stream(stream)
{
}
virtual ~EncoreBootImageReader() {}
inline void setKey(const AESKey<128> &key) { m_dek = key; }
inline const AESKey<128> &getKey() const { return m_dek; }
void readImageHeader();
void computeHeaderDigest(sha1_digest_t &digest);
void readImageDigest();
void computeImageDigest(sha1_digest_t &digest);
void readSectionTable();
bool readKeyDictionary(const AESKey<128> &kek);
void readBootTags();
EncoreBootImage::Section *readSection(unsigned index);
inline bool isEncrypted() const { return m_header.m_keyCount > 0; }
const EncoreBootImage::boot_image_header_t &getHeader() const { return m_header; }
const sha1_digest_t &getDigest() const { return m_digest; }
inline const section_array_t &getSections() const { return m_sections; }
inline const boot_tag_array_t &getBootTags() const { return m_bootTags; }
protected:
std::istream &m_stream;
AESKey<128> m_dek;
EncoreBootImage::boot_image_header_t m_header;
sha1_digest_t m_digest;
section_array_t m_sections;
boot_tag_array_t m_bootTags;
protected:
uint8_t calculateCommandChecksum(EncoreBootImage::boot_command_t &header);
};
}; // namespace elftosb
#endif // _EncoreBootImageReader_h_
elftosb::EncoreBootImageReader::readImageHeader
void readImageHeader()
Reads the header from the image.
Definition: EncoreBootImageReader.cpp:20
elftosb::EncoreBootImageReader::m_sections
section_array_t m_sections
The section table.
Definition: EncoreBootImageReader.h:107
elftosb::EncoreBootImage::Section
Base class for a section of an Encore boot image.
Definition: EncoreBootImage.h:989
elftosb::EncoreBootImageReader::computeImageDigest
void computeImageDigest(sha1_digest_t &digest)
Run a SHA-1 digest over the entire image.
Definition: EncoreBootImageReader.cpp:107
std
STL namespace.
elftosb::EncoreBootImageReader
Reads a Piano/Encore boot image from an input stream.
Definition: EncoreBootImageReader.h:17
elftosb::EncoreBootImageReader::section_array_t
std::vector< EncoreBootImage::section_header_t > section_array_t
An array of section headers.
Definition: EncoreBootImageReader.h:34
elftosb::EncoreBootImageReader::read_error
Exception class used for error found while reading a boot image.
Definition: EncoreBootImageReader.h:23
elftosb::EncoreBootImageReader::m_stream
std::istream & m_stream
The input stream to read the image from.
Definition: EncoreBootImageReader.h:103
elftosb::EncoreBootImageReader::~EncoreBootImageReader
virtual ~EncoreBootImageReader()
Destructor.
Definition: EncoreBootImageReader.h:47
elftosb::EncoreBootImageReader::getDigest
const sha1_digest_t & getDigest() const
Returns a reference to the SHA-1 digest read from the image.
Definition: EncoreBootImageReader.h:95
elftosb::EncoreBootImageReader::isEncrypted
bool isEncrypted() const
Returns whether the image is encrypted or not.
Definition: EncoreBootImageReader.h:91
elftosb::EncoreBootImageReader::readSection
EncoreBootImage::Section * readSection(unsigned index)
Definition: EncoreBootImageReader.cpp:312
elftosb::EncoreBootImageReader::m_header
EncoreBootImage::boot_image_header_t m_header
Header from the boot image.
Definition: EncoreBootImageReader.h:105
elftosb::EncoreBootImageReader::readKeyDictionary
bool readKeyDictionary(const AESKey< 128 > &kek)
Reads the key dictionary, if the image is encrypted.
Definition: EncoreBootImageReader.cpp:169
elftosb::EncoreBootImageReader::computeHeaderDigest
void computeHeaderDigest(sha1_digest_t &digest)
Computes the actual SHA-1 digest of the image header.
Definition: EncoreBootImageReader.cpp:67
elftosb::EncoreBootImageReader::readImageDigest
void readImageDigest()
Reads the digest at the end of the image.
Definition: EncoreBootImageReader.cpp:79
elftosb::EncoreBootImageReader::readBootTags
void readBootTags()
Definition: EncoreBootImageReader.cpp:237
elftosb
Definition: BootImage.h:13
elftosb::EncoreBootImageReader::m_bootTags
boot_tag_array_t m_bootTags
The array of boot tags read from the image.
Definition: EncoreBootImageReader.h:108
elftosb::EncoreBootImageReader::m_digest
sha1_digest_t m_digest
SHA-1 digest as read from the image.
Definition: EncoreBootImageReader.h:106
elftosb::EncoreBootImage::boot_command_t
Structure for a Piano bootloader command.
Definition: EncoreBootImage.h:249
elftosb::EncoreBootImageReader::getBootTags
const boot_tag_array_t & getBootTags() const
Returns a reference to the STL container holding the boot tags.
Definition: EncoreBootImageReader.h:99
AESKey< 128 >
elftosb::EncoreBootImageReader::getSections
const section_array_t & getSections() const
Returns a reference to the STL container holding the section headers.
Definition: EncoreBootImageReader.h:97
elftosb::EncoreBootImage::boot_image_header_t::m_keyCount
uint16_t m_keyCount
Number of entries in DEK dictionary.
Definition: EncoreBootImage.h:168
elftosb::EncoreBootImageReader::readSectionTable
void readSectionTable()
Read the plaintext section table entries.
Definition: EncoreBootImageReader.cpp:131
elftosb::EncoreBootImageReader::boot_tag_array_t
std::vector< EncoreBootImage::boot_command_t > boot_tag_array_t
An array of boot tags.
Definition: EncoreBootImageReader.h:37
elftosb::EncoreBootImageReader::calculateCommandChecksum
uint8_t calculateCommandChecksum(EncoreBootImage::boot_command_t &header)
Calculates the 8-bit checksum on a boot command header.
Definition: EncoreBootImageReader.cpp:291
elftosb::EncoreBootImageReader::getHeader
const EncoreBootImage::boot_image_header_t & getHeader() const
Returns a reference to the image&#39;s header.
Definition: EncoreBootImageReader.h:93
elftosb::EncoreBootImageReader::m_dek
AESKey< 128 > m_dek
DEK (data encryption key) read from the key dictionary.
Definition: EncoreBootImageReader.h:104
elftosb::EncoreBootImage::boot_image_header_t
Header for the entire boot image.
Definition: EncoreBootImage.h:150
elftosb::EncoreBootImageReader::EncoreBootImageReader
EncoreBootImageReader(std::istream &stream)
Default constructor.
Definition: EncoreBootImageReader.h:41
elftosb::EncoreBootImageReader::read_error::read_error
read_error(const std::string &msg)
Constructor.
Definition: EncoreBootImageReader.h:27