|
cryptnox-sdk-cpp 1.0.0
Platform-independent C++ core SDK for Cryptnox Hardware Wallet
|
Implementation of the Cryptnox secure channel protocol. More...
Go to the source code of this file.
Functions | |
| static bool | derReadLength (const uint8_t *buf, uint16_t bufLen, uint16_t &pos, uint16_t &fieldLen) |
| static bool | derSkipField (const uint8_t *buf, uint16_t bufLen, uint16_t &pos) |
| static bool | derWalkMfCert (const uint8_t *buf, uint16_t bufLen, uint16_t &tbsMsgStart, uint16_t &tbsMsgLen, const uint8_t *&pubKey65Ptr, const uint8_t *&sigPtr, uint8_t &sigLen) |
Variables | |
| static uint8_t | s_apduBuf [SEND_APDU_MAX_LEN] |
| static uint8_t | s_macBuf [MAX_MAC_DATA_LEN] |
| static uint8_t | s_dataBuf [ENC_BUF_MAX_LEN] |
| static uint8_t | s_mfCertBuf [CW_MANUF_CERT_MAX_BYTES] |
Implementation of the Cryptnox secure channel protocol.
Implements the methods declared in CW_SecureChannel.h: APDU framing, certificate chain verification against the trusted CA keys (CW_TrustedKeys.h), ECDH session key derivation, AES-CBC encrypted messaging with rolling IV, and MAC verification on every response.
Module-level static scratch buffers are reused across calls to keep the stack footprint small; secret material is wiped after use.
Definition in file CW_SecureChannel.cpp.
| #define AES_BLOCK_SIZE 16U |
Definition at line 45 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcDecrypt(), CW_SecureChannel::aesCbcEncrypt(), and CW_SecureChannel::mutuallyAuthenticate().
| #define APDU_HEADER_LEN (4U) |
Definition at line 46 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::mutuallyAuthenticate().
| #define APDU_LC_LEN (1U) |
Definition at line 47 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcEncrypt(), and CW_SecureChannel::mutuallyAuthenticate().
| #define CARDEPHEMERALPUBKEY_SIZE 64U |
Definition at line 44 of file CW_SecureChannel.cpp.
| #define CLIENT_PRIVATE_KEY_SIZE 32U |
Definition at line 42 of file CW_SecureChannel.cpp.
| #define CLIENT_PUBLIC_KEY_SIZE 64U |
Definition at line 43 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::openSecureChannel().
| #define COMMON_PAIRING_DATA CW_PAIRING_DATA |
Definition at line 41 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::mutuallyAuthenticate().
| #define DER_BIT_UNUSED_ZERO (0x00U) /* BIT STRING unused-bits field must be 0 */ |
Definition at line 80 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define DER_EC_POINT_BYTES (65U) /* 0x04 || X[32] || Y[32] */ |
Definition at line 79 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define DER_EC_UNCOMPRESSED (0x04U) /* uncompressed point prefix */ |
Definition at line 78 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define DER_LEN_LONG_1 (0x81U) /* long form, 1 following byte */ |
Definition at line 74 of file CW_SecureChannel.cpp.
Referenced by derReadLength().
| #define DER_LEN_LONG_2 (0x82U) /* long form, 2 following bytes */ |
Definition at line 75 of file CW_SecureChannel.cpp.
Referenced by derReadLength().
| #define DER_LEN_LONG_FLAG (0x80U) /* set = long-form length */ |
Definition at line 73 of file CW_SecureChannel.cpp.
Referenced by derReadLength().
| #define DER_TAG_BIT_STRING (0x03U) /* BIT STRING */ |
Definition at line 69 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define DER_TAG_CTX0 (0xA0U) /* [0] EXPLICIT — version in v3 TBSCertificate */ |
Definition at line 70 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define DER_TAG_SEQUENCE (0x30U) /* SEQUENCE (universal, constructed) */ |
Definition at line 68 of file CW_SecureChannel.cpp.
Referenced by derWalkMfCert().
| #define ENC_BUF_MAX_LEN (INPUT_BUFFER_LIMIT + AES_BLOCK_SIZE) |
Definition at line 50 of file CW_SecureChannel.cpp.
| #define GETCARDCERTIFICATE_IN_BYTES (RESPONSE_GETCARDCERTIFICATE_IN_BYTES - RESPONSE_STATUS_WORDS_IN_BYTES) |
Definition at line 38 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::getCardCertificate().
| #define INPUT_BUFFER_LIMIT (CW_USER_DATA_PAGE_SIZE) |
Definition at line 49 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcEncrypt().
| #define MAC_APDU_LEN (12U) |
Definition at line 48 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcEncrypt().
| #define MAX_MAC_DATA_LEN (APDU_HEADER_LEN + MAC_APDU_LEN + ENC_BUF_MAX_LEN) |
Definition at line 51 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcEncrypt().
| #define OPENSECURECHANNEL_SALT_IN_BYTES (RESPONSE_OPENSECURECHANNEL_IN_BYTES - RESPONSE_STATUS_WORDS_IN_BYTES) |
Definition at line 37 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::openSecureChannel().
| #define RANDOM_BYTES 8U |
Definition at line 40 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::getCardCertificate().
| #define REQUEST_MUTUALLYAUTHENTICATE_IN_BYTES 69U |
Definition at line 33 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::mutuallyAuthenticate().
| #define RESPONSE_GETCARDCERTIFICATE_IN_BYTES 148U |
Definition at line 27 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::getCardCertificate().
| #define RESPONSE_GETMANUFACTURERCERT_PAGE_IN_BYTES 420U |
Definition at line 31 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::getManufacturerCertificate().
| #define RESPONSE_MUTUALLYAUTHENTICATE_IN_BYTES 66U |
Definition at line 34 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::mutuallyAuthenticate().
| #define RESPONSE_OPENSECURECHANNEL_IN_BYTES 34U |
Definition at line 32 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::openSecureChannel().
| #define RESPONSE_SELECT_IN_BYTES 40U |
Definition at line 29 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::selectApdu().
| #define RESPONSE_STATUS_WORDS_IN_BYTES 2U |
Definition at line 35 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::getCardCertificate(), and CW_SecureChannel::getManufacturerCertificate().
| #define SEND_APDU_MAX_LEN (APDU_HEADER_LEN + APDU_LC_LEN + AES_BLOCK_SIZE + ENC_BUF_MAX_LEN) |
Definition at line 52 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcEncrypt().
|
static |
Definition at line 732 of file CW_SecureChannel.cpp.
References DER_LEN_LONG_1, DER_LEN_LONG_2, and DER_LEN_LONG_FLAG.
Referenced by derSkipField(), and derWalkMfCert().
|
static |
Definition at line 767 of file CW_SecureChannel.cpp.
References derReadLength().
Referenced by derWalkMfCert().
|
static |
Definition at line 791 of file CW_SecureChannel.cpp.
References DER_BIT_UNUSED_ZERO, DER_EC_POINT_BYTES, DER_EC_UNCOMPRESSED, DER_TAG_BIT_STRING, DER_TAG_CTX0, DER_TAG_SEQUENCE, derReadLength(), and derSkipField().
Referenced by CW_SecureChannel::verifyCertificateChain().
|
static |
Definition at line 60 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcDecrypt(), and CW_SecureChannel::aesCbcEncrypt().
|
static |
Definition at line 62 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcDecrypt(), and CW_SecureChannel::aesCbcEncrypt().
|
static |
Definition at line 61 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::aesCbcDecrypt(), and CW_SecureChannel::aesCbcEncrypt().
|
static |
Definition at line 65 of file CW_SecureChannel.cpp.
Referenced by CW_SecureChannel::preFetchManufacturerCert(), and CW_SecureChannel::verifyCertificateChain().