- FEA32Lib.h
- /*
- BytesEncrypt字节流加密函数
- buffer输入为明文,输出为密文。明文密文共用。
- len为明文长度。
- mainkey为系统主密钥或用户自定义主密钥。
- bits为主密钥位数32-2048位。
- subkey为32位子密钥输入。
- 函数返回32位子密钥,级联时需要。
- */
- unsigned int BytesEncrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned int subkey);
- /*
- BytesDecrypt字节流解密函数
- buffer输入为密文,输出为明文。明文密文共用。
- len为密文长度。
- mainkey为系统主密钥或用户自定义主密钥。
- bits为主密钥位数32-2048位。
- subkey为32位子密钥输入。
- 函数返回32位子密钥,级联时需要。
- */
- unsigned int BytesDecrypt(unsigned char* buffer, int len, unsigned char* mainkey, int bits, unsigned int subkey);
- main.c
- //#include "STM32F10x.h" // Device header
- #include <stdio.h>
- #include <stdint.h>
- #include "FEA32Lib.h"
- /*-----------------------------------------------------------------------------------------------
- HotFEA加解密程序_FEA32 HotPower[url=home.php?mod=space&uid=516618]@163.com[/url] 2023-10-12 22:11:54于北京
- ----------------------------------------------------------------------------------------------*/
- const unsigned char FEAMainKeyArray[16] = {//系统默认FEA32的32位主密钥,自定义128位主密钥(可以自定义32-2048位主密钥)
- 0x7D, 0x35, 0x82, 0x36, 0xA6, 0x05, 0x0F, 0xB8, 0x2B, 0x52, 0x50, 0x5D, 0x5B, 0x63, 0x3F, 0x8D
- };
- unsigned int FEASubKeyEncrypt = 0xB7073293;//系统默认FEA的32位加密子密钥,可以自定义32位加密子密钥
- unsigned int FEASubKeyDecrypt = 0xB7073293;//系统默认FEA的32位解密子密钥,可以自定义32位解密子密钥
- unsigned char FEATextBuffers[1024] = {//明文数组1024个字节 ,外部存储器
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39
- };
- int main (void) {
- int i;
- BytesEncrypt(FEATextBuffers, 1024, (unsigned char*)FEAMainKeyArray, 128, FEASubKeyEncrypt);//自定义128位主密钥,不级联
- BytesDecrypt(FEATextBuffers, 1024, (unsigned char*)FEAMainKeyArray, 128, FEASubKeyDecrypt);//自定义128位主密钥,不级联
- //加解密函数速率50KB/S
- for(i = 0;i < 25;i++){
- FEASubKeyEncrypt = BytesEncrypt(FEATextBuffers, 1024, (unsigned char*)FEAMainKeyArray, 128, FEASubKeyEncrypt);//自定义128位主密钥,级联
- FEASubKeyDecrypt = BytesDecrypt(FEATextBuffers, 1024, (unsigned char*)FEAMainKeyArray, 128, FEASubKeyDecrypt);//自定义128位主密钥,级联
- }
- for(i = 0;i < 16;i++){
- if(i == 0) printf ("%02X", FEATextBuffers[i]);
- else printf (", %02X", FEATextBuffers[i]);
- }
- printf ("\n");
- while (1) {
- printf ("End\n"); /* Print "Hello World" */
- }
- }