资源简介
用 STM32 唯一序列号进行程序的加密保护算法。
代码片段和文件信息
#include
#include
#include “hardware.h“
#include “usart.h“
#define STM32_CPUID ((uint32_t)0x1FFFF7E8)
#define FLASH_USER_START_ADDR ((uint32_t)0x0800F000)
#define FLASH_USER_CHECK_ADDR_UID ((uint32_t)0x0800F010)
#define FLASH_USER_CHECK_ADDR_CRC ((uint32_t)0x0800F04C)
#define cFlash_mark 0xAA5555AA
#define cFlash_default 0xFFFFFFFF
const unsigned char * CopyRight = “Copyright (C) 2013 WARD. All rights reserved. GF“;
s_parameter Para_RAM;
s_current current;
volatile unsigned int Para_changed;
unsigned long Encryption(unsigned long input_data unsigned long key1 unsigned long key2 unsigned long key3 unsigned long key4)
{
unsigned long x1 x2 x3 x4 x5 x6 x7;
unsigned long y0 y4 y5;
x1 = (input_data & 0x0000ffff);
x2 = (input_data & 0xffff0000) >> 16;
x3 = x1 ^ key2;
x4 = x2 ^ key1;
x5 = x4 + x3;
x6 = x5 << 4;
x7 = x6 % key4;
y0 = x7 * key3;
x3 = x1 + key1;
x4 = x3 % key3;
x5 = key4 ^ x2;
y4 = x4 * x5;
y5 = y0 ^ y4;
return y5; //加密后的数据出口
}
unsigned int Caculate_crc(unsigned int *pVal unsigned int len)
{
unsigned int lval_crc;
/* Compute the CRC of 96 bits uid */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC ENABLE);
CRC_ResetDR();
lval_crc = CRC_CalcBlockCRC(pVal len);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC DISABLE);
return lval_crc;
}
unsigned int Caculate_uid_crc(void)
{
unsigned int buff_temp[3];
buff_temp[0] = *((__IO uint32_t *)STM32_CPUID );
buff_temp[1] = *((__IO uint32_t *)STM32_CPUID + 1);
buff_temp[2] = *((__IO uint32_t *)STM32_CPUID + 2);
/* Compute the CRC of 96 bits uid */
return Caculate_crc(buff_temp 3);
}
void Parameter_Save(void)
{
unsigned int buff_temp[0x20];
unsigned char *pStr *pSrc;
unsigned int i;
Para_RAM.crc = Caculate_crc((uint32_t *)&Para_RAM 19);
/* Unlock the Flash to enable the flash control register access */
FLASH_Unlock();
if (FLASH_ErasePage(FLASH_USER_START_ADDR) == FLASH_COMPLETE);
{
pStr = (unsigned char *)&buff_
- 上一篇:基于ALPHA-BETA算法的五子棋程序
- 下一篇:esp32 qt 源码
相关资源
- 直流无刷电机方波驱动 stm32 例程代码
- STM32中文资料
- STM32蓝牙和串口程序
- STM32f103超声波模块例程
- stm32f103c8t6 4 oled.rar
- stm32f030 IAP Demo(原创)
- STM32基于rt_thread操作系统的SDHC卡文件
- NRF24L01实现51与STM32双向通讯
- STM32F103 串口程序(完整版)
- stm32 ds18b20 温度传感器 测试通过
- stm32官方例程
- STM32F103定时器中断程序
- [免费]基于stm32f103ze 的OLED驱动代码
- STM32F103RBT6驱动UC1698控制芯片的160160黑
- STM32F103 DS18B20 V3.5.0固件库驱动程序工
- STM32定时器使用入门。看了这个程序会
- SIM908 SDIO FSMC STM32 FIFO
- STM32F103 CC2500完整驱动(模拟SPI)
- AD7606采集程序
- stm32 用SPI 方式读写 SDHC
- stm32通过DMA方式采集ADC数据
- 意法半导体STM全系列微控制器STM32ST
- 基于STM32芯片的SX1278 驱动 LORA.rar
- STM32的PCB封装库,以及原理图库,48
- SX1280.rar
- STM32 DS3231驱动.zip
- STM32F103C8T6+NRF24l01无线通信
- 21天学会嵌入式开发STM32.zip
- STM32 电子密码锁设计,LCD12864显示
- STM32 LCD12864并口驱动实验
评论
共有 条评论