91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 4KB
    文件類型: .c
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2021-06-24
  • 語言: 其他
  • 標(biāo)簽: STM32??

資源簡介

用 STM32 唯一序列號進(jìn)行程序的加密保護算法。

資源截圖

代碼片段和文件信息

#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?<??
??x7?=?x6?%?key4;
??y0?=?x7?*?key3;
??
??x3?=?x1?+?key1;
??x4?=?x3?%?key3;
??
??x5?=?key4?^?x2;
??y4?=?x4?*?x5;
??y5?=?y0?^?y4;
??
??return?y5;?????????????????//加密后的數(shù)據(jù)出口
}

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_

評論

共有 條評論