Device interface library for multiple platforms including Mbed.

Dependents:   DeepCover Embedded Security in IoT MaximInterface MAXREFDES155#

Maxim Interface is a library framework focused on providing flexible and expressive hardware interfaces. Both communication interfaces such as I2C and 1-Wire and device interfaces such as DS18B20 are supported. Modern C++ concepts are used extensively while keeping compatibility with C++98/C++03 and requiring no external dependencies. The embedded-friendly design does not depend on exceptions or RTTI.

The full version of the project is hosted on GitLab: https://gitlab.com/iabenz/MaximInterface

Files at this revision

API Documentation at this revision

Comitter:
IanBenzMaxim
Date:
Fri May 29 16:19:22 2020 -0500
Parent:
11:3f3bf6bf5e6c
Commit message:
Updated to version 2.2.

Changed in this revision

MaximInterfaceDevices/DS28C16.cpp Show annotated file Show diff for this revision Revisions of this file
MaximInterfaceDevices/DS28C16.hpp Show annotated file Show diff for this revision Revisions of this file
MaximInterfaceDevices/DS28C40.cpp Show annotated file Show diff for this revision Revisions of this file
MaximInterfaceDevices/DS28C40.hpp Show annotated file Show diff for this revision Revisions of this file
MaximInterfaceDevices/DS28E83_DS28E84.cpp Show annotated file Show diff for this revision Revisions of this file
MaximInterfaceDevices/DS28E83_DS28E84.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28C16.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaximInterfaceDevices/DS28C16.cpp	Fri May 29 16:19:22 2020 -0500
@@ -0,0 +1,291 @@
+/*******************************************************************************
+* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************/
+
+#include <stddef.h>
+#include <algorithm>
+#include <MaximInterfaceCore/Error.hpp>
+#include "DS28C16.hpp"
+
+namespace MaximInterfaceDevices {
+
+using namespace Core;
+using std::copy;
+using std::fill;
+
+static const int readMemoryTimeMs = 5;
+static const int writeMemoryTimeMs = 60;
+static const int shortWriteMemoryTimeMs = 15;
+static const int computationTimeMs = 15;
+
+const int DS28C16::decrementCounterPage;
+const int DS28C16::masterSecretPage;
+const int DS28C16::memoryPages;
+
+Result<void> DS28C16::writeMemory(int pageNum, Page::const_span page) {
+  if (pageNum < 0 || pageNum >= memoryPages) {
+    return InvalidParameterError;
+  }
+
+  uint_least8_t request[2 + Page::size];
+  request[0] = 0x96;
+  request[1] = pageNum;
+  copy(page.begin(), page.end(), request + 2);
+  return runCommand(request, writeMemoryTimeMs);
+}
+
+Result<DS28C16::Page::array> DS28C16::readMemory(int pageNum) const {
+  if (pageNum < 0 || pageNum >= memoryPages) {
+    return InvalidParameterError;
+  }
+
+  uint_least8_t buffer[1 + Page::size * 2];
+  buffer[0] = 0x44;
+  buffer[1] = pageNum;
+  Result<span<uint_least8_t> > response =
+      runCommand(make_span(buffer, 2), readMemoryTimeMs, buffer);
+  if (!response) {
+    return response.error();
+  }
+  Page::array page;
+  response.value() = response.value().first(Page::size);
+  copy(response.value().begin(), response.value().end(), page.begin());
+  return page;
+}
+
+Result<DS28C16::Status> DS28C16::readStatus() const {
+  uint_least8_t buffer[1 + Status::PageProtectionList::size + RomId::size + 2];
+  buffer[0] = 0xAA;
+  const Result<span<uint_least8_t> > response =
+      runCommand(make_span(buffer, 1), readMemoryTimeMs, buffer);
+  if (!response) {
+    return response.error();
+  }
+  Status status;
+  span<uint_least8_t>::const_iterator responseIt = response.value().begin();
+  for (Status::PageProtectionList::array::iterator it =
+           status.pageProtection.begin();
+       it != status.pageProtection.end(); ++it) {
+    *it = *responseIt;
+    ++responseIt;
+  }
+  const span<uint_least8_t>::const_iterator responseItEnd =
+      responseIt + status.romId.size();
+  copy(responseIt, responseItEnd, status.romId.begin());
+  responseIt = responseItEnd;
+  status.manId = *responseIt;
+  ++responseIt;
+  status.deviceVersion = *responseIt;
+  return status;
+}
+
+Result<void> DS28C16::setPageProtection(int pageNum,
+                                        const PageProtection & protection) {
+  if (pageNum < 0 || pageNum >= memoryPages) {
+    return InvalidParameterError;
+  }
+
+  const uint_least8_t request[] = {
+      0xC3, static_cast<uint_least8_t>(pageNum),
+      static_cast<uint_least8_t>(protection.to_ulong())};
+  return runCommand(request, shortWriteMemoryTimeMs);
+}
+
+Result<DS28C16::DoublePage::array> DS28C16::computeAndReadPageAuthentication(
+    int pageNum, bool anonymous, DoublePage::const_span challenge) const {
+  if (pageNum < 0 || pageNum >= memoryPages) {
+    return InvalidParameterError;
+  }
+
+  const size_t requestSize = 3 + DoublePage::size;
+  const size_t responseSize = 1 + DoublePage::size;
+  uint_least8_t buffer[MaximInterfaceCore_MAX(requestSize, responseSize)];
+  buffer[0] = 0xA5;
+  buffer[1] = pageNum;
+  if (anonymous) {
+    buffer[1] |= 0xE0;
+  }
+  buffer[2] = 0x02;
+  copy(challenge.begin(), challenge.end(), buffer + 3);
+  const Result<span<uint_least8_t> > response =
+      runCommand(make_span(buffer, requestSize), computationTimeMs,
+                 make_span(buffer, responseSize));
+  if (!response) {
+    return response.error();
+  }
+  DoublePage::array hmac;
+  copy(response.value().begin(), response.value().end(), hmac.begin());
+  return hmac;
+}
+
+Result<void> DS28C16::computeSecret(int bindingDataPageNum,
+                                    bool constantBindingData, bool anonymous,
+                                    DoublePage::const_span partialSecret) {
+  if (bindingDataPageNum < 0 || bindingDataPageNum >= memoryPages) {
+    return InvalidParameterError;
+  }
+
+  uint_least8_t request[3 + DoublePage::size];
+  request[0] = 0x3C;
+  request[1] = bindingDataPageNum;
+  if (constantBindingData) {
+    request[1] |= 0x04;
+  }
+  if (anonymous) {
+    request[1] |= 0xE0;
+  }
+  request[2] = 0x08;
+  copy(partialSecret.begin(), partialSecret.end(), request + 3);
+  return runCommand(request, computationTimeMs);
+}
+
+Result<void> DS28C16::decrementCounter() {
+  const uint_least8_t request = 0xC9;
+  return runCommand(make_span(&request, 1), writeMemoryTimeMs);
+}
+
+Result<void> DS28C16::lockOutDisableDevice() {
+  const DisableDevicePassword::array password = {0};
+  return disableDevice(LockOutDisableDevice, password);
+}
+
+Result<void>
+DS28C16::setDisableDevicePassword(DisableDevicePassword::const_span password) {
+  return disableDevice(SetDisableDevicePassword, password);
+}
+
+Result<void>
+DS28C16::disableDevice(DisableDevicePassword::const_span password) {
+  return disableDevice(DisableDevice, password);
+}
+
+Result<void>
+DS28C16::disableDevice(DisableDeviceOperation operation,
+                       DisableDevicePassword::const_span password) {
+  const uint_least8_t request[] = {
+      0x33,        static_cast<uint_least8_t>(operation),
+      password[0], password[1],
+      0x71,        0x35,
+      0x0E,        0xAC,
+      0x95,        0xF8};
+  return runCommand(request, shortWriteMemoryTimeMs);
+}
+
+Result<span<uint_least8_t> >
+DS28C16::runCommand(span<const uint_least8_t> request, int delayTime,
+                    span<uint_least8_t> response) const {
+  const Result<span<uint_least8_t> > responseOutput =
+      doRunCommand(request, delayTime, response);
+  if (!responseOutput) {
+    return responseOutput;
+  }
+  if (responseOutput.value().empty()) {
+    return InvalidResponseError;
+  }
+  // Parse command result byte.
+  switch (responseOutput.value().front()) {
+  case 0xAA:
+    // Success response.
+    break;
+
+  case 0x00:
+    return AuthenticationError;
+
+  default:
+    return error_code(responseOutput.value().front(), errorCategory());
+  }
+  if (responseOutput.value().size() != response.size()) {
+    return InvalidResponseError;
+  }
+  return responseOutput.value().subspan(1);
+}
+
+Result<void> DS28C16::runCommand(span<const uint_least8_t> request,
+                                 int delayTime) {
+  uint_least8_t buffer;
+  MaximInterfaceCore_TRY(runCommand(request, delayTime, make_span(&buffer, 1)));
+  return none;
+}
+
+const error_category & DS28C16::errorCategory() {
+  static class : public error_category {
+  public:
+    virtual const char * name() const {
+      return "MaximInterfaceDevices.DS28C16";
+    }
+
+    virtual std::string message(int condition) const {
+      switch (condition) {
+      case InvalidOperationError:
+        return "Invalid Operation Error";
+
+      case InvalidParameterError:
+        return "Invalid Parameter Error";
+
+      case InvalidSequenceError:
+        return "Invalid Sequence Error";
+
+      case InternalError:
+        return "Internal Error";
+
+      case DeviceDisabledError:
+        return "Device Disabled Error";
+
+      case AuthenticationError:
+        return "Authentication Error";
+
+      case InvalidResponseError:
+        return "Invalid Response Error";
+      }
+      return defaultErrorMessage(condition);
+    }
+  } instance;
+  return instance;
+}
+
+DS28C16::PageAuthenticationData &
+DS28C16::PageAuthenticationData::setAnonymousRomId() {
+  fill(romId().begin(), romId().end(), 0xFF);
+  return *this;
+}
+
+DS28C16::ComputeSecretData &
+DS28C16::ComputeSecretData::setConstantBindingData(bool constantBindingData) {
+  if (constantBindingData) {
+    data.setPageNum(data.pageNum() | constantBindingDataMask);
+    fill(bindingData().begin(), bindingData().end(), 0);
+  } else {
+    data.setPageNum(data.pageNum() & ~constantBindingDataMask);
+  }
+  return *this;
+}
+
+} // namespace MaximInterfaceDevices
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28C16.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MaximInterfaceDevices/DS28C16.hpp	Fri May 29 16:19:22 2020 -0500
@@ -0,0 +1,460 @@
+/*******************************************************************************
+* Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************/
+
+#ifndef MaximInterfaceDevices_DS28C16_hpp
+#define MaximInterfaceDevices_DS28C16_hpp
+
+#include <stdint.h>
+#include <MaximInterfaceCore/Algorithm.hpp>
+#include <MaximInterfaceCore/array_span.hpp>
+#include <MaximInterfaceCore/FlagSet.hpp>
+#include <MaximInterfaceCore/RomId.hpp>
+#include <MaximInterfaceCore/RunCommand.hpp>
+#include <MaximInterfaceCore/system_error.hpp>
+#include "Config.hpp"
+
+namespace MaximInterfaceDevices {
+
+class DS28C16 {
+public:
+  /// Device command results.
+  enum ErrorValue {
+    InvalidOperationError = 0x55,
+    InvalidParameterError = 0x77,
+    InvalidSequenceError = 0x33,
+    InternalError = 0x22,
+    DeviceDisabledError = 0x88,
+    AuthenticationError = 0x100,
+    InvalidResponseError ///< Command response does not match expected format.
+  };
+
+  /// @name Device memory pages
+  /// @{
+
+  static const int decrementCounterPage = 2;
+  static const int masterSecretPage = 3;
+
+  /// @}
+
+  static const int memoryPages = 4;
+
+  /// Holds a device memory page.
+  typedef Core::array_span<uint_least8_t, 16> Page;
+
+  /// Holds a Challenge, Partial Secret, or HMAC.
+  typedef Core::array_span<uint_least8_t, 32> DoublePage;
+
+  /// Holds a password used to disable the device.
+  typedef Core::array_span<uint_least8_t, 2> DisableDevicePassword;
+
+  // Format page authentication input data.
+  class PageAuthenticationData;
+
+  // Format compute secret input data.
+  class ComputeSecretData;
+
+  /// Page protection types.
+  enum PageProtectionType {
+    RP = 0x01, ///< Read protection.
+    WP = 0x02, ///< Write protection.
+    DC = 0x08  ///< Decrement counter.
+  };
+  typedef Core::FlagSet<PageProtectionType, 4> PageProtection;
+
+  struct Status {
+    typedef Core::array_span<PageProtection, memoryPages> PageProtectionList;
+
+    PageProtectionList::array pageProtection;
+    Core::RomId::array romId;
+    uint_least8_t manId;
+    uint_least8_t deviceVersion;
+  };
+
+  explicit DS28C16(const Core::RunCommand & runCommand)
+      : doRunCommand(runCommand) {}
+
+  void setRunCommand(const Core::RunCommand & runCommand) {
+    doRunCommand = runCommand;
+  }
+
+  /// @brief Write memory with no protection.
+  /// @param pageNum Number of page to write.
+  /// @param page Data to write.
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  writeMemory(int pageNum, Page::const_span page);
+
+  /// @brief Read memory with no protection.
+  /// @param pageNum Number of page to read.
+  /// @returns Data that was read.
+  MaximInterfaceDevices_EXPORT Core::Result<Page::array>
+  readMemory(int pageNum) const;
+
+  /// @brief Reads the current status of the device.
+  /// @returns Status that was read.
+  MaximInterfaceDevices_EXPORT Core::Result<Status> readStatus() const;
+
+  /// @brief Set the protection settings of a page.
+  /// @param pageNum Number of page to write.
+  /// @param protection Protection to write.
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  setPageProtection(int pageNum, const PageProtection & protection);
+
+  /// @brief Compute and read page authentication with HMAC.
+  /// @param pageNum Number of page to authenticate.
+  /// @param anonymous True to disable use of ROM ID in computation.
+  /// @param challenge Random challenge used to prevent replay attacks.
+  /// @returns Computed page HMAC.
+  MaximInterfaceDevices_EXPORT Core::Result<DoublePage::array>
+  computeAndReadPageAuthentication(int pageNum, bool anonymous,
+                                   DoublePage::const_span challenge) const;
+
+  /// Decrement the decrement-only counter.
+  MaximInterfaceDevices_EXPORT Core::Result<void> decrementCounter();
+
+  /// Set password that will be subsequently used to disable the device.
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  setDisableDevicePassword(DisableDevicePassword::const_span password);
+
+  /// @brief Lock-out all disable functionality for the device.
+  /// @note Only allowed prior to setting password.
+  MaximInterfaceDevices_EXPORT Core::Result<void> lockOutDisableDevice();
+
+  /// Permanently disable the device.
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  disableDevice(DisableDevicePassword::const_span password);
+
+  /// @brief
+  /// Compute a derivative secret for authentication from the Master Secret.
+  /// @param bindingDataPageNum Page number for Binding Data.
+  /// @param constantBindingData
+  /// Use constant Binding Data instead of Binding Data from the selected page.
+  /// @param anonymous True to disable use of ROM ID in computation.
+  /// @param partialSecret Partial secret to use in computation.
+  /// @note
+  /// This command should be executed prior to the
+  /// Compute and Read Page Authentication command.
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  computeSecret(int bindingDataPageNum, bool constantBindingData,
+                bool anonymous, DoublePage::const_span partialSecret);
+
+  MaximInterfaceDevices_EXPORT static const Core::error_category &
+  errorCategory();
+
+protected:
+  MaximInterfaceDevices_EXPORT Core::Result<Core::span<uint_least8_t> >
+  runCommand(Core::span<const uint_least8_t> request, int delayTime,
+             Core::span<uint_least8_t> response) const;
+
+  MaximInterfaceDevices_EXPORT Core::Result<void>
+  runCommand(Core::span<const uint_least8_t> request, int delayTime);
+
+private:
+  enum DisableDeviceOperation {
+    SetDisableDevicePassword = 0x0F,
+    LockOutDisableDevice = 0x05,
+    DisableDevice = 0x00
+  };
+
+  Core::Result<void> disableDevice(DisableDeviceOperation operation,
+                                   DisableDevicePassword::const_span password);
+
+  Core::RunCommand doRunCommand;
+};
+
+} // namespace MaximInterfaceDevices
+namespace MaximInterfaceCore {
+
+template <>
+struct is_error_code_enum<MaximInterfaceDevices::DS28C16::ErrorValue>
+    : true_type {};
+
+} // namespace MaximInterfaceCore
+namespace MaximInterfaceDevices {
+
+inline Core::error_code make_error_code(DS28C16::ErrorValue e) {
+  return Core::error_code(e, DS28C16::errorCategory());
+}
+
+/// Format page authentication input data.
+class DS28C16::PageAuthenticationData {
+public:
+  typedef Core::array_span<uint_least8_t, Core::RomId::size + 2 * Page::size +
+                                              DoublePage::size + 3>
+      Result;
+
+  PageAuthenticationData() : result_() {}
+
+  /// Formatted data result.
+  Result::const_span result() const { return result_; }
+
+  /// @name ROM ID
+  /// @brief 1-Wire ROM ID of the device.
+  /// @{
+
+  /// Get mutable ROM ID.
+  Core::RomId::span romId() {
+    return make_span(result_).subspan<romIdIdx, Core::RomId::size>();
+  }
+
+  /// Get immutable ROM ID.
+  Core::RomId::const_span romId() const {
+    return const_cast<PageAuthenticationData &>(*this).romId();
+  }
+
+  /// Set ROM ID.
+  PageAuthenticationData & setRomId(Core::RomId::const_span romId) {
+    copy(romId, this->romId());
+    return *this;
+  }
+
+  /// Set ROM ID for use in anonymous mode.
+  MaximInterfaceDevices_EXPORT PageAuthenticationData & setAnonymousRomId();
+
+  /// @}
+
+  /// @name Page
+  /// @brief Data from a device memory page.
+  /// @{
+
+  /// Get mutable page.
+  Page::span page() {
+    return make_span(result_).subspan<pageIdx, Page::size>();
+  }
+
+  /// Get immutable page.
+  Page::const_span page() const {
+    return const_cast<PageAuthenticationData &>(*this).page();
+  }
+
+  /// Set page.
+  PageAuthenticationData & setPage(Page::const_span page) {
+    copy(page, this->page());
+    return *this;
+  }
+
+  /// @}
+
+  /// @name Challenge.
+  /// @brief Random challenge used to prevent replay attacks.
+  /// @{
+
+  /// Get mutable Challenge.
+  DoublePage::span challenge() {
+    return make_span(result_).subspan<challengeIdx, DoublePage::size>();
+  }
+
+  /// Get immutable Challenge.
+  DoublePage::const_span challenge() const {
+    return const_cast<PageAuthenticationData &>(*this).challenge();
+  }
+
+  /// Set Challenge.
+  PageAuthenticationData & setChallenge(DoublePage::const_span challenge) {
+    copy(challenge, this->challenge());
+    return *this;
+  }
+
+  /// @}
+
+  /// @name Page number
+  /// @brief Number of the page to use data from.
+  /// @{
+
+  /// Get page number.
+  int pageNum() const { return result_[pageNumIdx]; }
+
+  /// Set page number.
+  PageAuthenticationData & setPageNum(int pageNum) {
+    result_[pageNumIdx] = pageNum;
+    return *this;
+  }
+
+  /// @}
+
+  /// @name MAN ID
+  /// @brief Manufacturer ID of the device.
+  /// @{
+
+  /// Get mutable MAN ID.
+  uint_least8_t & manId() { return result_[manIdIdx]; }
+
+  /// Get immutable MAN ID.
+  uint_least8_t manId() const {
+    return const_cast<PageAuthenticationData &>(*this).manId();
+  }
+
+  /// Set MAN ID.
+  PageAuthenticationData & setManId(uint_least8_t manId) {
+    this->manId() = manId;
+    return *this;
+  }
+
+  /// @}
+
+private:
+  static const size_t romIdIdx = 0;
+  static const size_t pageIdx = romIdIdx + Core::RomId::size;
+  static const size_t challengeIdx = pageIdx + 2 * Page::size;
+  static const size_t pageNumIdx = challengeIdx + DoublePage::size;
+  static const size_t manIdIdx = pageNumIdx + 1;
+
+  Result::array result_;
+};
+
+/// Format compute secret input data.
+class DS28C16::ComputeSecretData {
+public:
+  typedef PageAuthenticationData::Result Result;
+
+  ComputeSecretData() : data() {
+    data.setPageNum(0x80 | constantBindingDataMask);
+  }
+
+  /// Formatted data result.
+  Result::const_span result() const { return data.result(); }
+
+  /// @name ROM ID
+  /// @brief 1-Wire ROM ID of the device.
+  /// @{
+
+  /// Get mutable ROM ID.
+  Core::RomId::span romId() { return data.romId(); }
+
+  /// Get immutable ROM ID.
+  Core::RomId::const_span romId() const { return data.romId(); }
+
+  /// Set ROM ID.
+  ComputeSecretData & setRomId(Core::RomId::const_span romId) {
+    data.setRomId(romId);
+    return *this;
+  }
+
+  /// @}
+
+  /// @name Binding Data
+  /// @brief Binding Data contained in the selected page.
+  /// @{
+
+  /// Get mutable Binding Data.
+  Page::span bindingData() { return data.page(); }
+
+  /// Get immutable Binding Data.
+  Page::const_span bindingData() const { return data.page(); }
+
+  /// Set Binding Data.
+  ComputeSecretData & setBindingData(Page::const_span bindingData) {
+    data.setPage(bindingData);
+    return *this;
+  }
+
+  /// @}
+
+  /// @name Constant Binding Data
+  /// @brief
+  /// Use constant Binding Data instead of Binding Data from the selected page.
+  /// @{
+
+  /// Get Constant Binding Data.
+  bool constantBindingData() const {
+    return (data.pageNum() & constantBindingDataMask) ==
+           constantBindingDataMask;
+  }
+
+  /// Set Constant Binding Data.
+  MaximInterfaceDevices_EXPORT ComputeSecretData &
+  setConstantBindingData(bool constantBindingData);
+
+  /// @}
+
+  /// @name Partial Secret
+  /// @brief Partial Secret used for customization.
+  /// @{
+
+  /// Get mutable Partial Secret.
+  DoublePage::span partialSecret() { return data.challenge(); }
+
+  /// Get immutable Partial Secret.
+  DoublePage::const_span partialSecret() const { return data.challenge(); }
+
+  /// Set Partial Secret.
+  ComputeSecretData & setPartialSecret(DoublePage::const_span partialSecret) {
+    data.setChallenge(partialSecret);
+    return *this;
+  }
+
+  /// @}
+
+  /// @name Binding Data page number
+  /// @{
+
+  /// Get Binding Data page number.
+  int bindingDataPageNum() const {
+    return data.pageNum() & bindingDataPageNumMask;
+  }
+
+  /// Set Binding Data page number.
+  ComputeSecretData & setBindingDataPageNum(int bindingDataPageNum) {
+    data.setPageNum((bindingDataPageNum & bindingDataPageNumMask) |
+                    (data.pageNum() & ~bindingDataPageNumMask));
+    return *this;
+  }
+
+  /// @}
+
+  /// @name MAN ID
+  /// @brief Manufacturer ID of the device.
+  /// @{
+
+  /// Get mutable MAN ID.
+  uint_least8_t & manId() { return data.manId(); }
+
+  /// Get immutable MAN ID.
+  uint_least8_t manId() const { return data.manId(); }
+
+  /// Set MAN ID.
+  ComputeSecretData & setManId(uint_least8_t manId) {
+    data.setManId(manId);
+    return *this;
+  }
+
+  /// @}
+
+private:
+  static const unsigned int bindingDataPageNumMask = 0x03;
+  static const unsigned int constantBindingDataMask = 0x04;
+
+  PageAuthenticationData data;
+};
+
+} // namespace MaximInterfaceDevices
+
+#endif
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28C40.cpp
--- a/MaximInterfaceDevices/DS28C40.cpp	Tue Dec 03 10:52:28 2019 -0600
+++ b/MaximInterfaceDevices/DS28C40.cpp	Fri May 29 16:19:22 2020 -0500
@@ -588,6 +588,9 @@
 
       case InvalidResponseError:
         return "Invalid Response Error";
+
+      case EntropyHealthTestError:
+        return "Entropy Health Test Error";
       }
       return defaultErrorMessage(condition);
     }
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28C40.hpp
--- a/MaximInterfaceDevices/DS28C40.hpp	Tue Dec 03 10:52:28 2019 -0600
+++ b/MaximInterfaceDevices/DS28C40.hpp	Fri May 29 16:19:22 2020 -0500
@@ -57,6 +57,7 @@
     InvalidOperationError = 0x55,
     InvalidParameterError = 0x77,
     DeviceDisabledError = 0x88,
+    EntropyHealthTestError = 0xDD,
     AuthenticationError = 0x100,
     InvalidResponseError ///< Command response does not match expected format.
   };
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28E83_DS28E84.cpp
--- a/MaximInterfaceDevices/DS28E83_DS28E84.cpp	Tue Dec 03 10:52:28 2019 -0600
+++ b/MaximInterfaceDevices/DS28E83_DS28E84.cpp	Fri May 29 16:19:22 2020 -0500
@@ -605,6 +605,9 @@
 
       case InvalidResponseError:
         return "Invalid Response Error";
+
+      case EntropyHealthTestError:
+        return "Entropy Health Test Error";
       }
       return defaultErrorMessage(condition);
     }
diff -r 3f3bf6bf5e6c -r 7eb41621ba22 MaximInterfaceDevices/DS28E83_DS28E84.hpp
--- a/MaximInterfaceDevices/DS28E83_DS28E84.hpp	Tue Dec 03 10:52:28 2019 -0600
+++ b/MaximInterfaceDevices/DS28E83_DS28E84.hpp	Fri May 29 16:19:22 2020 -0500
@@ -57,6 +57,7 @@
     InvalidOperationError = 0x55,
     InvalidParameterError = 0x77,
     DeviceDisabledError = 0x88,
+    EntropyHealthTestError = 0xDD,
     AuthenticationError = 0x100,
     InvalidResponseError ///< Command response does not match expected format.
   };