12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- /*===========================================================================
- Combined Charging System (CCS): SECC
- NidNmk.h
- initiated by Vern, Joseph
- (since 2019/07/19)
- =============================================================================*/
- #include <stdint.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #if FIRMWARE_VERSION_COMPILE_SETTING_RELEASE_MODE == ENABLE
- //Saving System Log
- #define SAVE_SYS_LOG_MSG_NIDNMK_SWITCH DISABLE //ENABLE, DISABLE
- //Configuration for Debug Print Messages
- #define DEBUG_PRINTF_NIDNMK_SHOW DISABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_BRIEF_SHOW DISABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_DETAIL_SHOW DISABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_SYSTEM_LOG_SHOW DISABLE //ENABLE, DISABLE
- #else //debug mode
- //Saving System Log
- #define SAVE_SYS_LOG_MSG_NIDNMK_SWITCH ENABLE //ENABLE, DISABLE
- //Configuration for Debug Print Messages
- #define DEBUG_PRINTF_NIDNMK_SHOW ENABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_BRIEF_SHOW ENABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_DETAIL_SHOW ENABLE //ENABLE, DISABLE
- #define DEBUG_PRINTF_NIDNMK_SYSTEM_LOG_SHOW ENABLE //ENABLE, DISABLE
- #endif
- typedef struct sha256
- {
- uint32_t count [2];
- uint32_t state [8];
- uint8_t block [64];
- uint8_t extra [64];
- } NidSHA256;
- #define SHA256_DIGEST_LENGTH 256 / 8
- #define HPAVKEY_NMK_LEN 16
- #define HPAVKEY_NID_LEN 7
- #define SHR(word, bits) ((word & 0xFFFFFFFF) >> bits)
- #define ROTR(word, bits) (SHR(word, bits) | (word << (32 - bits)))
- #define DEFAULT_LEVEL 0
- //--------------------------------------------------------------------------
- /* Functions -----------------------------------------------------------*/
- //--------------------------------------------------------------------------
- void HPAVKeyNMK(uint8_t NMK [], const char *string);
- void HPAVKeyNID(uint8_t NID [], const uint8_t NMK [], uint8_t level);
- void SHA256Reset(struct sha256 *sha256);
- void SHA256Block(struct sha256 *sha256, void const *memory);
- void SHA256Write(struct sha256 *sha256, void const *memory, uint16_t extent);
- void SHAEncode(uint8_t memory [], uint32_t number);
- void SHA256Fetch(struct sha256 *sha256, uint8_t digest []);
- //System Log
- #if SAVE_SYS_LOG_MSG_NIDNMK_SWITCH == ENABLE
- #define SAVE_SYS_LOG_MSG_NIDNMK StoreLogMsg
- #else
- #define SAVE_SYS_LOG_MSG_NIDNMK(...)
- #endif
- //Debug Message
- #if DEBUG_PRINTF_NIDNMK_SHOW == ENABLE
- //Brief Messages
- #if DEBUG_PRINTF_NIDNMK_BRIEF_SHOW == ENABLE
- #define DEBUG_PRINTF_NIDNMK_BRIEF printf
- #else
- #define DEBUG_PRINTF_NIDNMK_BRIEF(...)
- #endif
- //Detail Messages
- #if DEBUG_PRINTF_NIDNMK_DETAIL_SHOW == ENABLE
- #define DEBUG_PRINTF_NIDNMK_DETAIL printf
- #else
- #define DEBUG_PRINTF_NIDNMK_DETAIL(...)
- #endif
- //System Log Messages
- #if DEBUG_PRINTF_NIDNMK_SYSTEM_LOG_SHOW == ENABLE
- #define DEBUG_PRINTF_NIDNMK_SYSTEM_LOG printf
- #else
- #define DEBUG_PRINTF_NIDNMK_SYSTEM_LOG(...)
- #endif
- #else
- #define DEBUG_PRINTF_NIDNMK_BRIEF(...)
- #define DEBUG_PRINTF_NIDNMK_DETAIL(...)
- #define DEBUG_PRINTF_NIDNMK_SYSTEM_LOG(...)
- #endif
|