当前位置: 首页 > wzjs >正文

做网店去哪个网站货源好网络整合营销策划书

做网店去哪个网站货源好,网络整合营销策划书,网页制作教程 1 dreamweaver 北京希望电子出版社,js 网站客服代码一、简介: ATSHA204A是Microchip公司生产的一款高性能加密认证芯片,主要特性包括: 基于SHA-256哈希算法的安全认证 4.5KB EEPROM存储空间(可配置为密钥存储、OTP区域等) 唯一的72位序列号 支持I2C和单线接口 工作…

一、简介:

ATSHA204A是Microchip公司生产的一款高性能加密认证芯片,主要特性包括:

  • 基于SHA-256哈希算法的安全认证

  • 4.5KB EEPROM存储空间(可配置为密钥存储、OTP区域等)

  • 唯一的72位序列号

  • 支持I2C和单线接口

  • 工作电压:2.0V至5.5V

  • 低功耗设计

典型应用场景:

  • 设备认证

  • 安全启动验证

  • 固件保护

  • 防克隆保护

二、硬件接口:

TSHA204A          STM32L4XX
----------------------------
VCC        →       3.3V
GND        →       GND
SDA        →       PB7 (I2C1_SDA)
SCL        →       PB6 (I2C1_SCL)

注意:ATSHA204A的地址引脚决定了I2C地址,通常为0xC0(如果地址引脚全部接地)。

三、头文件:

#ifndef ATSHA204A_H
#define ATSHA204A_H

#include "stm32l4xx_hal.h"

#define ATSHA204A_I2C_ADDR         0xC0
#define ATSHA204A_CMD_WAKE         0x00
#define ATSHA204A_CMD_SLEEP        0x01
#define ATSHA204A_CMD_READ         0x02
#define ATSHA204A_CMD_WRITE        0x12
#define ATSHA204A_CMD_MAC          0x08
#define ATSHA204A_CMD_NONCE        0x16
#define ATSHA204A_CMD_RANDOM       0x1B

#define ATSHA204A_ZONE_CONFIG      0x00
#define ATSHA204A_ZONE_OTP         0x01
#define ATSHA204A_ZONE_DATA        0x02

#define ATSHA204A_STATUS_SUCCESS   0x00
#define ATSHA204A_STATUS_AFTER_WAKE 0x11

#define ATSHA204A_PACKET_SIZE      32
#define ATSHA204A_RESPONSE_TIMEOUT 1000

typedef struct {
    I2C_HandleTypeDef *hi2c;
    uint8_t i2c_addr;
} ATSHA204A_HandleTypeDef;

HAL_StatusTypeDef ATSHA204A_Init(ATSHA204A_HandleTypeDef *hatsha, I2C_HandleTypeDef *hi2c, uint8_t i2c_addr);
HAL_StatusTypeDef ATSHA204A_Wakeup(ATSHA204A_HandleTypeDef *hatsha);
HAL_StatusTypeDef ATSHA204A_Sleep(ATSHA204A_HandleTypeDef *hatsha);
HAL_StatusTypeDef ATSHA204A_Read(ATSHA204A_HandleTypeDef *hatsha, uint8_t zone, uint8_t block, uint8_t offset, uint8_t *data, uint8_t len);
HAL_StatusTypeDef ATSHA204A_Write(ATSHA204A_HandleTypeDef *hatsha, uint8_t zone, uint8_t block, uint8_t offset, const uint8_t *data, uint8_t len);
HAL_StatusTypeDef ATSHA204A_GetSerialNumber(ATSHA204A_HandleTypeDef *hatsha, uint8_t *serial);
HAL_StatusTypeDef ATSHA204A_GenerateRandom(ATSHA204A_HandleTypeDef *hatsha, uint8_t *random);
HAL_StatusTypeDef ATSHA204A_CalculateMAC(ATSHA204A_HandleTypeDef *hatsha, uint8_t *challenge, uint8_t *mac);

#endif /* ATSHA204A_H */

四、源文件:

#include "atsha204a.h"
#include <string.h>

static HAL_StatusTypeDef ATSHA204A_SendCommand(ATSHA204A_HandleTypeDef *hatsha, uint8_t *command, uint8_t cmd_len);
static HAL_StatusTypeDef ATSHA204A_ReceiveResponse(ATSHA204A_HandleTypeDef *hatsha, uint8_t *response, uint8_t resp_len);

HAL_StatusTypeDef ATSHA204A_Init(ATSHA204A_HandleTypeDef *hatsha, I2C_HandleTypeDef *hi2c, uint8_t i2c_addr) {
    hatsha->hi2c = hi2c;
    hatsha->i2c_addr = i2c_addr;
    return ATSHA204A_Wakeup(hatsha);
}

HAL_StatusTypeDef ATSHA204A_Wakeup(ATSHA204A_HandleTypeDef *hatsha) {
    // Wakeup is a special case - requires a low pulse on SDA
    // For I2C, we send a start condition with address 0x00
    uint8_t dummy = 0;
    HAL_StatusTypeDef status = HAL_I2C_Master_Transmit(hatsha->hi2c, 0x00, &dummy, 1, ATSHA204A_RESPONSE_TIMEOUT);
    
    // Wait for device to wake up
    HAL_Delay(2);
    
    return status;
}

HAL_StatusTypeDef ATSHA204A_Sleep(ATSHA204A_HandleTypeDef *hatsha) {
    uint8_t command[4] = {0};
    command[0] = 1; // Opcode count
    command[1] = ATSHA204A_CMD_SLEEP;
    
    return ATSHA204A_SendCommand(hatsha, command, 4);
}

HAL_StatusTypeDef ATSHA204A_Read(ATSHA204A_HandleTypeDef *hatsha, uint8_t zone, uint8_t block, uint8_t offset, uint8_t *data, uint8_t len) {
    uint8_t command[8] = {0};
    uint8_t response[ATSHA204A_PACKET_SIZE] = {0};
    
    command[0] = 7; // Opcode count
    command[1] = ATSHA204A_CMD_READ;
    command[2] = zone;
    command[3] = block;
    command[4] = offset;
    
    HAL_StatusTypeDef status = ATSHA204A_SendCommand(hatsha, command, 8);
    if (status != HAL_OK) return status;
    
    HAL_Delay(5); // Wait for command to complete
    
    status = ATSHA204A_ReceiveResponse(hatsha, response, ATSHA204A_PACKET_SIZE);
    if (status != HAL_OK) return status;
    
    if (response[0] != 0) return HAL_ERROR; // Check status byte
    
    memcpy(data, &response[1], len);
    return HAL_OK;
}

HAL_StatusTypeDef ATSHA204A_Write(ATSHA204A_HandleTypeDef *hatsha, uint8_t zone, uint8_t block, uint8_t offset, const uint8_t *data, uint8_t len) {
    uint8_t command[8 + 32] = {0}; // Max write size
    
    command[0] = 7 + len; // Opcode count
    command[1] = ATSHA204A_CMD_WRITE;
    command[2] = zone;
    command[3] = block;
    command[4] = offset;
    
    memcpy(&command[5], data, len);
    
    HAL_StatusTypeDef status = ATSHA204A_SendCommand(hatsha, command, 8 + len);
    if (status != HAL_OK) return status;
    
    HAL_Delay(20); // Write operations take longer
    
    return HAL_OK;
}

HAL_StatusTypeDef ATSHA204A_GetSerialNumber(ATSHA204A_HandleTypeDef *hatsha, uint8_t *serial) {
    return ATSHA204A_Read(hatsha, ATSHA204A_ZONE_CONFIG, 0, 0, serial, 9); // First 9 bytes of config zone contain serial
}

HAL_StatusTypeDef ATSHA204A_GenerateRandom(ATSHA204A_HandleTypeDef *hatsha, uint8_t *random) {
    uint8_t command[4] = {0};
    uint8_t response[35] = {0};
    
    command[0] = 1; // Opcode count
    command[1] = ATSHA204A_CMD_RANDOM;
    command[2] = 0x00; // Mode
    
    HAL_StatusTypeDef status = ATSHA204A_SendCommand(hatsha, command, 4);
    if (status != HAL_OK) return status;
    
    HAL_Delay(20); // Random number generation takes time
    
    status = ATSHA204A_ReceiveResponse(hatsha, response, 35);
    if (status != HAL_OK) return status;
    
    if (response[0] != 0) return HAL_ERROR; // Check status byte
    
    memcpy(random, &response[1], 32); // Copy 32-byte random number
    return HAL_OK;
}

HAL_StatusTypeDef ATSHA204A_CalculateMAC(ATSHA204A_HandleTypeDef *hatsha, uint8_t *challenge, uint8_t *mac) {
    uint8_t command[88] = {0}; // Max command size
    uint8_t response[35] = {0};
    
    command[0] = 83; // Opcode count
    command[1] = ATSHA204A_CMD_MAC;
    command[2] = 0x01; // Mode
    command[3] = 0x00; // Slot
    
    memcpy(&command[4], challenge, 32); // Copy challenge
    
    HAL_StatusTypeDef status = ATSHA204A_SendCommand(hatsha, command, 88);
    if (status != HAL_OK) return status;
    
    HAL_Delay(50); // MAC calculation takes time
    
    status = ATSHA204A_ReceiveResponse(hatsha, response, 35);
    if (status != HAL_OK) return status;
    
    if (response[0] != 0) return HAL_ERROR; // Check status byte
    
    memcpy(mac, &response[1], 32); // Copy 32-byte MAC
    return HAL_OK;
}

static HAL_StatusTypeDef ATSHA204A_SendCommand(ATSHA204A_HandleTypeDef *hatsha, uint8_t *command, uint8_t cmd_len) {
    // Calculate CRC
    // Note: Actual CRC implementation needed here
    command[cmd_len-2] = 0; // CRC placeholder
    command[cmd_len-1] = 0; // CRC placeholder
    
    return HAL_I2C_Master_Transmit(hatsha->hi2c, hatsha->i2c_addr, command, cmd_len, ATSHA204A_RESPONSE_TIMEOUT);
}

static HAL_StatusTypeDef ATSHA204A_ReceiveResponse(ATSHA204A_HandleTypeDef *hatsha, uint8_t *response, uint8_t resp_len) {
    return HAL_I2C_Master_Receive(hatsha->hi2c, hatsha->i2c_addr, response, resp_len, ATSHA204A_RESPONSE_TIMEOUT);
}

五、应用:

#include "atsha204a.h"
#include "stdio.h"

ATSHA204A_HandleTypeDef hatsha;

void ATSHA204A_Example(void) {
    uint8_t serial[9] = {0};
    uint8_t random[32] = {0};
    uint8_t mac[32] = {0};
    uint8_t challenge[32] = {0};
    
    // Initialize with I2C1 and default address
    if (ATSHA204A_Init(&hatsha, &hi2c1, ATSHA204A_I2C_ADDR) != HAL_OK) {
        printf("ATSHA204A initialization failed\r\n");
        return;
    }
    
    // Get serial number
    if (ATSHA204A_GetSerialNumber(&hatsha, serial) == HAL_OK) {
        printf("Serial Number: ");
        for (int i = 0; i < 9; i++) {
            printf("%02X", serial[i]);
        }
        printf("\r\n");
    }
    
    // Generate random number
    if (ATSHA204A_GenerateRandom(&hatsha, random) == HAL_OK) {
        printf("Random Number: ");
        for (int i = 0; i < 32; i++) {
            printf("%02X", random[i]);
        }
        printf("\r\n");
    }
    
    // Generate challenge (in real application, this would be from host)
    for (int i = 0; i < 32; i++) {
        challenge[i] = i;
    }
    
    // Calculate MAC
    if (ATSHA204A_CalculateMAC(&hatsha, challenge, mac) == HAL_OK) {
        printf("MAC: ");
        for (int i = 0; i < 32; i++) {
            printf("%02X", mac[i]);
        }
        printf("\r\n");
    }
    
    // Put device to sleep
    ATSHA204A_Sleep(&hatsha);
}

http://www.dtcms.com/wzjs/182078.html

相关文章:

  • 长沙网站设百度关键词搜索热度
  • 网购网站模板百度搜索资源平台官网
  • 聊城做wap网站找谁电商培训班一般多少钱一个月
  • 公司用员工信息做网站域名备案网络零售的优势有哪些
  • 网站建设合同 简单江西seo推广
  • 四川住房和城乡建设网站清远网站seo
  • 公司网站建设制作全如何做个网站推广自己产品
  • 运营型网站b2b平台排名
  • web网站开发分享网站亚洲长尾关键词挖掘
  • wordpress相关推荐代码seo推广教程视频
  • 怎么注册自己的微网站google推广 的效果
  • 网站效果展示seo服务公司上海
  • 东莞常平疫情最新通告宁波seo快速排名
  • 做北京塞车网站百度一下百度网页版主页
  • 一级域名网站里有二级域名推广网站排名优化seo教程
  • 长沙制作网站优化网站快速排名软件
  • 钓鱼转转网站在线生成软件怎么在百度发帖
  • 新手如何自己做网站seo百度百科
  • html5 企业国际网站 多国家 多语言 源代码 cookiesseo网站优化策划书
  • 织梦 网站无法显示该页面不错宁波seo公司
  • 宁远县建设局网站百度账号批发网
  • 网站如何做3d产品展示百度一下就知道官方网站
  • 免费博客网站有哪些如何做推广呢
  • 网站分析报告范文2000站长推广工具
  • 在后台怎么做网站内链百度荤seo公司
  • 做足球经理头像的网站seo网站优化师
  • angular 做的网站如何做公司网站推广
  • 有什么网站可以免费建站免费建网站百度应用app下载
  • 网站开发公司运营流程分享推广
  • 扬州建设工程信息网站站长工具查询seo