资源简介
用 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 SDIO FATFS
- 5 UARTRecIT.zip
- stm32控制esp8266访问web
- 超完整的STM32的STM32 SD卡 TATFS文件格式
- STM32F103 LORA配置
- STM32 PWM输出不同相位差和占空比
- STM32 同一定时器不同通道产生不同频
- 铭正同创液晶STM32 240128 源码
- STM32F4 串口DMA发送接收方式代码例程
- stm32 SDIO操作库
- STM32 FM25CL64B 铁电存储器
- STM32 库函数的485通讯测试程序
- ODrive-fw-v0.3.6_keil.zip
- STM32F103的PWM的扫频程序
- ADS1292驱动程序 STM32 2020省TI杯电赛资
- STM32F103读取MPU6050原始数据
- stm32+esp8266
- STM32F4驱动线阵CCD——TCD1304
- stm32 IO口方式驱动WS2813B
- STM32f103两线PT100例程.rar
- STM32LL库使用指南工程模板
- SWD模式下调试STM32程序的方法
- STM32 红外遥控
- GD5F4G.zip
- STM32连接阿里云入门手册.pdf
- 麦轮底盘实验_手动.zip
- 基于STM32的数码管显示模板
- 图片提取软件内有教程
- STM32模拟SPi.rar
- STM32F407 US100 USART串口超声波
评论
共有 条评论