zhangbo 3 gadi atpakaļ
vecāks
revīzija
40caa343f1

+ 1 - 0
GD32F450_BMC_BaseCode.initramfs

@@ -161,6 +161,7 @@ file /usr/bin/i2c-scan ${INSTALL_ROOT}/projects/${SAMPLE}/app/i2c_scan/i2c-scan
 file /usr/bin/ncp81111_cfg ${INSTALL_ROOT}/projects/${SAMPLE}/app/NCP81111_Config/ncp81111_cfg 755 0 0
 file /usr/bin/damon.sh ${INSTALL_ROOT}/projects/${SAMPLE}/app/damon.sh 777 0 0
 file /usr/bin/ipmitool ${INSTALL_ROOT}/projects/${SAMPLE}/app/ipmitool-1.8.18/ipmitool 755 0 0
+file /usr/bin/authlicense ${INSTALL_ROOT}/projects/${SAMPLE}/app/AuthLicense/authlicense 755 0 0
 
 dir /etc/goahead 755 0 0 
 dir /var/www 755 0 0

+ 8 - 0
app/AuthLicense/AuthLicense..h

@@ -0,0 +1,8 @@
+#ifndef __AUTHLICENSE_H__
+#define __AUTHLICENSE_H__
+
+
+int CheckLicense(uint8_t *guid, uint8_t *license);
+
+
+#endif

+ 395 - 0
app/AuthLicense/AuthLicense.c

@@ -0,0 +1,395 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "md5.h"
+
+/*
+preHandleIndex:
+    0: |
+    1: &
+    2: ^
+    3: !^
+    4: +
+    5: -
+*/
+int8_t preHandle(uint32_t *preGUIDptr, uint32_t key, uint8_t preHandleIndex)
+{
+	uint8_t i;
+    switch(preHandleIndex)
+    {
+    case 0: // |
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] |= key;
+        }
+        break;
+    case 1: // &
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] &= key;
+        }
+        break;
+    case 2: // ^
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] ^= key;
+        }
+        break;
+    case 3: // !^
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] ^= key;
+            preGUIDptr[i] = ~preGUIDptr[i];
+        }
+        break;
+    case 4: // +
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] += key;
+        }
+        break;
+    case 5: // -
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] -= key;
+        }
+        break;
+    default:
+        printf("´íÎóµ±Ç°Ñ¡ÔñµÄÔËË㷽ʽ²»¿ÉÓÃ\r\n");
+        return -1;
+    }
+    return 1;
+}
+int8_t bitDiffuse(uint8_t decrypt[16], uint8_t License[256], uint8_t bitSelectIndex)
+{
+	uint8_t i, j;	
+    //À©É¢µ½128×Ö½Ú
+    switch (bitSelectIndex) {
+    case 0:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x01;
+                else
+                    License[i*8+j] &= ~0x01;
+            }
+        }
+        break;
+    case 1:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x02;
+                else
+                    License[i*8+j] &= ~0x02;
+            }
+        }
+        break;
+    case 2:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x04;
+                else
+                    License[i*8+j] &= ~0x04;
+            }
+        }
+        break;
+    case 3:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x08;
+                else
+                    License[i*8+j] &= ~0x08;
+            }
+        }
+        break;
+    case 4:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x10;
+                else
+                    License[i*8+j] &= ~0x10;
+            }
+        }
+        break;
+    case 5:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x20;
+                else
+                    License[i*8+j] &= ~0x20;
+            }
+        }
+        break;
+    case 6:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x40;
+                else
+                    License[i*8+j] &= ~0x40;
+            }
+        }
+        break;
+    case 7:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x80;
+                else
+                    License[i*8+j] &= ~0x80;
+            }
+        }
+        break;
+    default:
+        printf("´íÎóÎÞЧµÄÀ©É¢Î»Ñ¡Ôñ\r\n");
+        return -1;
+
+    }	
+    return 1;
+}
+
+int8_t Authorize(uint8_t decrypt[16], uint8_t License[128], uint8_t bitSelectIndex)
+{
+	uint8_t i, j;	
+    switch (bitSelectIndex) {
+    case 0:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {			
+							if ( ( License[i*8+j] & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 1:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                 
+							if ( ( (License[i*8+j] >> 1) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}                   
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 2:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 2) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n"); 
+        break;
+    case 3:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 3) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    case 4:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 4) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");       
+        break;
+    case 5:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 5) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 6:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 6) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    case 7:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 7) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    default:
+        //printf("´íÎóÎÞЧµÄÀ©É¢Î»Ñ¡Ôñ\r\n");
+        return -1;
+
+    }	
+    return 1;
+}
+
+int8_t ExchangeCharToByte(uint8_t *LicenseKeySrc256, uint8_t *LicenseKeyDst128)
+{
+	uint8_t i, index;
+	uint8_t tmp;
+	uint8_t tmp2;
+	for(i=0;i<128;i++)
+	{
+		index = i*2;
+		if(LicenseKeySrc256[index] >= '0' && LicenseKeySrc256[index] <= '9')
+		{
+			tmp = LicenseKeySrc256[index] - '0';	
+		}
+		else if(LicenseKeySrc256[index] >= 'A' && LicenseKeySrc256[index] <= 'F')
+		{
+			tmp = LicenseKeySrc256[index] - 'A'+10;
+		}
+		else if(LicenseKeySrc256[index] >= 'a' && LicenseKeySrc256[index] <= 'f')
+		{
+			tmp = LicenseKeySrc256[index] - 'a'+10;
+		}
+		else
+		{
+			return -1;
+			//printf("error\r\n");
+		}
+				
+		if(LicenseKeySrc256[index+1] >= '0' && LicenseKeySrc256[index+1] <= '9')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - '0';
+		}
+		else if(LicenseKeySrc256[index+1] >= 'A' && LicenseKeySrc256[index+1] <= 'F')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - 'A'+10;
+		}
+		else if(LicenseKeySrc256[index+1] >= 'a' && LicenseKeySrc256[index+1] <= 'f')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - 'a'+10;
+		}
+		else
+		{
+			return -1;
+			//printf("error\r\n");
+		}		
+
+		LicenseKeyDst128[i] = ((tmp&0x0f) << 4) | (tmp2&0x0f);
+	}
+	return 1;
+}
+
+
+int CheckLicense(uint8_t *guid, uint8_t *license)
+{
+    uint32_t tmp = 0;
+    uint8_t  CalLicense[16] = {0};  //计算得出的有效的16字节License
+    MD5_CTX md5;
+    int i;
+
+    //根据GUID计算License    
+    preHandle((uint32_t*)guid, 0x33445566, 2);    //预处理
+    MD5_Init(&md5);
+    MD5_Update(&md5,guid,12);
+    MD5_Final(CalLicense, &md5);
+
+    //比对License
+    if(Authorize(CalLicense, license, 0) == 1) //授权通过
+    {
+        printf("License check Success!\n");         
+        return 0;
+    }
+    else    //授权不通过
+    {
+        printf("License is invalid, Please re input! \n");
+        return -1;
+    }
+}

+ 158 - 0
app/AuthLicense/AuthLicense_main.c

@@ -0,0 +1,158 @@
+#include <stdio.h>
+#include <stdint.h>
+#include "driver.h"
+#include <string.h>
+#include "hal_interface_api.h"
+#include <fcntl.h>
+
+/*
+i2c-scan -b 0
+*/
+
+void help()
+{
+	printf("authlicense -w \n");
+	printf("    -Write new license to flash. Input [128 bytes license]\n");
+	printf("authlicense -r \n");
+	printf("    -Read license form flash\n");
+	printf("authlicense -guid \n");
+	printf("    -Read device GUID.\n");
+}
+int main(int argc, char* argv[])
+{
+	int i;
+	char chr;
+	uint8_t tmp;
+	uint32_t tmp1;
+	uint8_t  GUID[12] = {0};
+	uint32_t *pUID = (uint32_t*)0x1FFF7A10;
+	uint8_t  *pLicense = (uint8_t*)0x08060000; 
+    uint8_t  HexLicense[128] = {0};
+    uint8_t CharLicense[256+10] = {0};
+
+	if(argc != 2)
+	{
+		help();
+		return -1;
+	}
+	//读取License
+	if(strcmp(argv[1], "-r") == 0)
+	{			
+		printf("License: ");
+		for(i=0;i<128;i++)
+		{
+			if(i%32 == 0)
+				printf("\t\n");
+
+			printf("%02x", *pLicense);
+			pLicense++;
+		}
+		printf("\n");
+	}
+	//写入License
+	else if(strcmp(argv[1], "-w") == 0)
+	{
+		while(1)
+		{
+			memset(CharLicense, 0, sizeof(CharLicense));
+			printf("\nPlease input license(128 bytes): ");
+			scanf("%s", CharLicense);
+			
+			//检查License长度
+			if(strlen(CharLicense) != 256)
+			{
+				printf("License length is 128 bytes, but input is %d bytes! Please re input!\n", (strlen(CharLicense)+1)/2);
+				continue;
+			}
+
+			for(i=0;i<128;i++)
+			{
+				//获取高4位
+				chr = CharLicense[2*i+0];
+				if((chr >= '0') && (chr <= '9'))
+				{
+					tmp = chr - '0';
+				}
+				else if((chr >= 'a') && (chr <= 'f'))
+				{
+					tmp = chr - 'a' + 10;
+				}
+				else if((chr >= 'A') && (chr <= 'F'))
+				{
+					tmp = chr - 'A' + 10;
+				}
+				else
+				{
+					printf("Invalid char %s\n", chr);
+					return -1;
+				}
+				HexLicense[i] = tmp<<4;
+				//获取低4位
+				chr = CharLicense[2*i+1];
+				if((chr >= '0') && (chr <= '9'))
+				{
+					tmp = chr - '0';
+				}
+				else if((chr >= 'a') && (chr <= 'f'))
+				{
+					tmp = chr - 'a' + 10;
+				}
+				else if((chr >= 'A') && (chr <= 'F'))
+				{
+					tmp = chr - 'A' + 10;
+				}
+				else
+				{
+					printf("Invalid char %s\n", chr);
+					return -1;
+				}
+				HexLicense[i] |= tmp;				
+			}
+
+			//获取GUID
+			for(i=0;i<3;i++)
+		    {
+		        tmp1 = *pUID;
+		        GUID[4*i+0] = tmp1&0xff;
+		        GUID[4*i+1] = (tmp1>>8)&0xff;
+		        GUID[4*i+2] = (tmp1>>16)&0xff;
+		        GUID[4*i+3] = (tmp1>>24)&0xff;
+		        pUID++;	
+		    }
+		    //检查Licnese是否有效
+			if(CheckLicense(GUID, HexLicense) == 0)
+			{
+				//将license写入Flash
+				//TODO:
+				printf("Save license to falsh ok.\n");
+				return 0;
+			}
+			else
+				continue;
+		}
+	}
+	//读取GUID
+	else if(strcmp(argv[1], "-guid") == 0)
+	{		
+	    printf("GUID: ");
+	    for(i=0;i<3;i++)
+	    {
+	        tmp1 = *pUID;
+	        GUID[4*i+0] = tmp1&0xff;
+	        GUID[4*i+1] = (tmp1>>8)&0xff;
+	        GUID[4*i+2] = (tmp1>>16)&0xff;
+	        GUID[4*i+3] = (tmp1>>24)&0xff;
+	        pUID++;
+	        printf("%02x %02x %02x %02x ",  GUID[4*i+0],GUID[4*i+1],GUID[4*i+2],GUID[4*i+3]);
+	    }
+	    printf("\n");	
+	}
+	else
+	{
+		printf("Invalid param %s\n", argv[1]);
+		help();
+		return -1;
+	}
+
+	return 0;
+}

+ 68 - 0
app/AuthLicense/MD5.c

@@ -0,0 +1,68 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include "md5.h"
+
+#define MD_CTX MD5_CTX
+#define MDInit MD5_Init
+#define MDUpdate MD5_Update
+#define MDFinal MD5_Final
+
+/*
+    INPUT  : Test string , buffer of 16 bytes to
+                store the digest,length of the string
+    OUTPUT	: Encrypted message in the buffer.
+    RETURN	: NONE
+    PROCESS	:Digests a string and prints the result.
+ */
+extern void AuthCodeCalMD5(
+          uint8_t  *string, 	/*test string */
+          uint8_t  *MD5Result,  /*result of MD5 digest*/
+          uint16_t LengthOfstring /*Length of input string */
+          )
+{
+    MD_CTX context;
+    uint8_t  digest[16];
+    MDInit (&context);
+    MDUpdate (&context, string, LengthOfstring);
+    MDFinal (digest, &context);
+    memcpy(MD5Result,digest,16);
+
+}
+unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
+{
+    MD5_CTX c;
+    static unsigned char m[16];
+
+    if (md == NULL) md=m;
+    MD5_Init(&c);
+    MD5_Update(&c,(unsigned char *)d,n);
+    MD5_Final(md,&c);
+//    OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */
+    return(md);
+}

+ 52 - 0
app/AuthLicense/Makefile

@@ -0,0 +1,52 @@
+EXEC		= authlicense
+
+CFLAGS		:= -Os -mcpu=cortex-m3 -mthumb
+LDFLAGS		:= -mcpu=cortex-m3 -mthumb -L$(INSTALL_ROOT)/A2F/root/usr/lib
+#BUILD_TIME 	= $(shell date +"%Y-%m-%d %H:%M:%S")
+
+
+
+CC	= $(CROSS_COMPILE_APPS)gcc
+
+#source
+SRC	= AuthLicense_main.c
+SRC += AuthLicense.c
+SRC += MD5.c
+SRC += md5c.c
+
+# hal_api
+SRC += $(wildcard ../hal_api/*.c) 
+
+#incldue
+CFLAGS	+= -I$(INSTALL_ROOT)/A2F/root/usr/include
+CFLAGS	+= -I ./
+CFLAGS	+= -I ../common_include
+CFLAGS	+= -I ../driver
+CFLAGS	+= -I ../hal_api
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc
+CFLAGS	+= -I ../driver/STM32F4xx_HAL_Driver/Inc/Legacy
+
+
+#library
+
+#sub-directory
+#SUBDIR 	= ./sensor
+
+
+
+
+
+
+$(EXEC): $(SRC)
+	#echo $(BUILD_TIME)
+	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $^ $(LIBS) -lpthread
+
+
+#object
+OBJS	= $(SRC:%.c=%.o)
+
+clean:
+	rm -f $(EXEC) $(OBJS)
+	rm -f *.gdb 
+

BIN
app/AuthLicense/authlicense


+ 59 - 0
app/AuthLicense/md5.h

@@ -0,0 +1,59 @@
+/* MD5.H - header file for MD5C.C
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#ifndef _MD5_H_
+#define _MD5_H_ 1
+
+#include <stdint.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef UINT4
+#define UINT4 unsigned int
+#endif
+
+#ifndef POINTER
+#define POINTER unsigned char *
+#endif
+/* MD5 context. */
+typedef struct {
+  UINT4 state[4];                                   /* state (ABCD) */
+  UINT4 count[2];        /* number of bits, modulo 2^64 (lsb first) */
+  unsigned char buffer[64];                         /* input buffer */
+} MD5_CTX;
+
+void MD5_Init (MD5_CTX *context);
+void MD5_Update (MD5_CTX * context, unsigned char * input, unsigned int inputLen);
+void MD5_Final (unsigned char digest[16], MD5_CTX *context);
+unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* _MD5_H_ */

+ 311 - 0
app/AuthLicense/md5c.c

@@ -0,0 +1,311 @@
+/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
+ */
+
+/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
+   rights reserved.
+
+   License to copy and use this software is granted provided that it
+   is identified as the "RSA Data Security, Inc. MD5 Message-Digest
+   Algorithm" in all material mentioning or referencing this software
+   or this function.
+
+   License is also granted to make and use derivative works provided
+   that such works are identified as "derived from the RSA Data
+   Security, Inc. MD5 Message-Digest Algorithm" in all material
+   mentioning or referencing the derived work.  
+                                                                    
+   RSA Data Security, Inc. makes no representations concerning either
+   the merchantability of this software or the suitability of this
+   software for any particular purpose. It is provided "as is"
+   without express or implied warranty of any kind.  
+                                                                    
+   These notices must be retained in any copies of any part of this
+   documentation and/or software.  
+ */
+
+#include "md5.h"
+
+/* Constants for MD5Transform routine.
+ */
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static void MD5Transform (UINT4 state[4], unsigned char block[64]);
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len);
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len);
+static void MD5_memcpy (unsigned char *output, unsigned char *input, unsigned int len);
+static void MD5_memset (unsigned char *output, int value, unsigned int len);
+
+static unsigned char PADDING[64] = {
+  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/* F, G, H and I are basic MD5 functions.
+ */
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
+
+/* ROTATE_LEFT rotates x left n bits.
+ */
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+   Rotation is separate from addition to prevent recomputation.
+ */
+#define FF(a, b, c, d, x, s, ac) { \
+    (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define GG(a, b, c, d, x, s, ac) { \
+    (a) += G ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define HH(a, b, c, d, x, s, ac) { \
+    (a) += H ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+#define II(a, b, c, d, x, s, ac) { \
+    (a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
+    (a) = ROTATE_LEFT ((a), (s)); \
+    (a) += (b); \
+  }
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+ */
+void MD5_Init (MD5_CTX *context)
+{
+  context->count[0] = context->count[1] = 0;
+
+  /* Load magic initialization constants.
+   */
+  context->state[0] = 0x67452301;
+  context->state[1] = 0xefcdab89;
+  context->state[2] = 0x98badcfe;
+  context->state[3] = 0x10325476;
+}
+
+/* MD5 block update operation. Continues an MD5 message-digest
+     operation, processing another message block, and updating the
+     context.
+ */
+void MD5_Update (MD5_CTX * context, unsigned char * input, unsigned int inputLen)
+{
+  unsigned int i, index, partLen;
+
+  /* Compute number of bytes mod 64 */
+  index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+  /* Update number of bits */
+  if ((context->count[0] += ((UINT4)inputLen << 3))
+      < ((UINT4)inputLen << 3))
+    context->count[1]++;
+  context->count[1] += ((UINT4)inputLen >> 29);
+  
+  partLen = 64 - index;
+  
+  /* Transform as many times as possible.
+   */
+  if (inputLen >= partLen) {
+    MD5_memcpy
+      ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+    MD5Transform (context->state, context->buffer);
+  
+    for (i = partLen; i + 63 < inputLen; i += 64)
+      MD5Transform (context->state, &input[i]);
+    
+    index = 0;
+  }
+  else
+    i = 0;
+  
+  /* Buffer remaining input */
+  MD5_memcpy 
+    ((POINTER)&context->buffer[index], (POINTER)&input[i],
+     inputLen-i);
+}
+
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+     the message digest and zeroizing the context.
+ */
+void MD5_Final (unsigned char digest[16], MD5_CTX *context)
+{
+  unsigned char bits[8];
+  unsigned int index, padLen;
+
+  /* Save number of bits */
+  Encode (bits, context->count, 8);
+
+  /* Pad out to 56 mod 64.
+   */
+  index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+  padLen = (index < 56) ? (56 - index) : (120 - index);
+  MD5_Update (context, PADDING, padLen);
+  
+  /* Append length (before padding) */
+  MD5_Update (context, bits, 8);
+
+  /* Store state in digest */
+  Encode (digest, context->state, 16);
+  
+  /* Zeroize sensitive information.
+   */
+  MD5_memset ((POINTER)context, 0, sizeof (*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+ */
+static void MD5Transform (UINT4 state[4], unsigned char block[64])
+{
+  UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+  
+  Decode (x, block, 64);
+
+  /* Round 1 */
+  FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
+  FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
+  FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
+  FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
+  FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
+  FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
+  FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
+  FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
+  FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
+  FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
+  FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+  FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+  FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+  FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+  FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+  FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+  /* Round 2 */
+  GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
+  GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
+  GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+  GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
+  GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
+  GG (d, a, b, c, x[10], S22,  0x2441453); /* 22 */
+  GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+  GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
+  GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
+  GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+  GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
+  GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
+  GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+  GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
+  GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
+  GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+  /* Round 3 */
+  HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
+  HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
+  HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+  HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+  HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
+  HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
+  HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
+  HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+  HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+  HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
+  HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
+  HH (b, c, d, a, x[ 6], S34,  0x4881d05); /* 44 */
+  HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
+  HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+  HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+  HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
+
+  /* Round 4 */
+  II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
+  II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
+  II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+  II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
+  II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+  II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
+  II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+  II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
+  II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
+  II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+  II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
+  II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+  II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
+  II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+  II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
+  II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
+
+  state[0] += a;
+  state[1] += b;
+  state[2] += c;
+  state[3] += d;
+  
+  /* Zeroize sensitive information.
+   */
+  MD5_memset ((POINTER)x, 0, sizeof (x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+     a multiple of 4.
+ */
+static void Encode (unsigned char *output, UINT4 *input, unsigned int len)
+{
+  unsigned int i, j;
+
+  for (i = 0, j = 0; j < len; i++, j += 4) {
+    output[j] = (unsigned char)(input[i] & 0xff);
+    output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
+    output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
+    output[j+3] = (unsigned char)((input[i] >> 24) & 0xff);
+  }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+     a multiple of 4.
+ */
+static void Decode (UINT4 *output, unsigned char *input, unsigned int len)
+{
+  unsigned int i, j;
+
+  for (i = 0, j = 0; j < len; i++, j += 4)
+    output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
+      (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
+}
+
+/* Note: Replace "for loop" with standard memcpy if possible.
+ */
+static void MD5_memcpy (unsigned char *output, unsigned char *input, unsigned int len)
+{
+  unsigned int i;
+  
+  for (i = 0; i < len; i++)
+    output[i] = input[i];
+}
+
+/* Note: Replace "for loop" with standard memset if possible.
+ */
+static void MD5_memset (unsigned char *output, int value, unsigned int len)
+{
+  unsigned int i;
+  
+  for (i = 0; i < len; i++)
+    ((char *)output)[i] = (char)value;
+}

+ 1 - 0
app/Makefile

@@ -19,6 +19,7 @@ all	:
 	make -C ./i2c_scan
 	make -C ./NCP81111_Config
 	make -C ./ipmitool-1.8.18
+	make -C ./AuthLicense
 clean	: 
 	make -C ./goahead-3.6.5 clean
 	make -C ./bmc clean

+ 8 - 0
app/bmc/AuthLicense..h

@@ -0,0 +1,8 @@
+#ifndef __AUTHLICENSE_H__
+#define __AUTHLICENSE_H__
+
+
+int CheckLicense();
+
+
+#endif

+ 443 - 0
app/bmc/AuthLicense.c

@@ -0,0 +1,443 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdio.h>
+#include "md5.h"
+
+/*
+preHandleIndex:
+    0: |
+    1: &
+    2: ^
+    3: !^
+    4: +
+    5: -
+*/
+int8_t preHandle(uint32_t *preGUIDptr, uint32_t key, uint8_t preHandleIndex)
+{
+	uint8_t i;
+    switch(preHandleIndex)
+    {
+    case 0: // |
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] |= key;
+        }
+        break;
+    case 1: // &
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] &= key;
+        }
+        break;
+    case 2: // ^
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] ^= key;
+        }
+        break;
+    case 3: // !^
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] ^= key;
+            preGUIDptr[i] = ~preGUIDptr[i];
+        }
+        break;
+    case 4: // +
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] += key;
+        }
+        break;
+    case 5: // -
+        for(i=0;i<3;i++)
+        {
+            preGUIDptr[i] -= key;
+        }
+        break;
+    default:
+        printf("´íÎóµ±Ç°Ñ¡ÔñµÄÔËË㷽ʽ²»¿ÉÓÃ\r\n");
+        return -1;
+    }
+    return 1;
+}
+int8_t bitDiffuse(uint8_t decrypt[16], uint8_t License[256], uint8_t bitSelectIndex)
+{
+	uint8_t i, j;	
+    //À©É¢µ½128×Ö½Ú
+    switch (bitSelectIndex) {
+    case 0:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x01;
+                else
+                    License[i*8+j] &= ~0x01;
+            }
+        }
+        break;
+    case 1:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x02;
+                else
+                    License[i*8+j] &= ~0x02;
+            }
+        }
+        break;
+    case 2:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x04;
+                else
+                    License[i*8+j] &= ~0x04;
+            }
+        }
+        break;
+    case 3:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x08;
+                else
+                    License[i*8+j] &= ~0x08;
+            }
+        }
+        break;
+    case 4:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x10;
+                else
+                    License[i*8+j] &= ~0x10;
+            }
+        }
+        break;
+    case 5:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x20;
+                else
+                    License[i*8+j] &= ~0x20;
+            }
+        }
+        break;
+    case 6:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x40;
+                else
+                    License[i*8+j] &= ~0x40;
+            }
+        }
+        break;
+    case 7:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                if((decrypt[i]&(0x01<<j)))
+                    License[i*8+j] |= 0x80;
+                else
+                    License[i*8+j] &= ~0x80;
+            }
+        }
+        break;
+    default:
+        printf("´íÎóÎÞЧµÄÀ©É¢Î»Ñ¡Ôñ\r\n");
+        return -1;
+
+    }	
+    return 1;
+}
+
+int8_t Authorize(uint8_t decrypt[16], uint8_t License[128], uint8_t bitSelectIndex)
+{
+	uint8_t i, j;	
+    //À©É¢µ½128×Ö½Ú
+    switch (bitSelectIndex) {
+    case 0:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {			
+							if ( ( License[i*8+j] & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 1:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+                 
+							if ( ( (License[i*8+j] >> 1) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}                   
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 2:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 2) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n"); 
+        break;
+    case 3:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 3) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    case 4:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 4) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");       
+        break;
+    case 5:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 5) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");
+        break;
+    case 6:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 6) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    case 7:
+        for(i=0;i<16;i++)
+        {
+            for(j=0;j<8;j++)
+            {
+							if ( ( (License[i*8+j] >> 7) & 0x01 ) == ( (decrypt[i] >> j) & 0x01 ) )
+							{		
+								//printf("run\r\n");
+							}
+							else{
+								return -1;
+								//printf("bitDiffuse2 error\r\n");
+							}  
+            }
+        }
+        //printf("bitDiffuse2 ok\r\n");        
+        break;
+    default:
+        //printf("´íÎóÎÞЧµÄÀ©É¢Î»Ñ¡Ôñ\r\n");
+        return -1;
+
+    }	
+    return 1;
+}
+
+int8_t ExchangeCharToByte(uint8_t *LicenseKeySrc256, uint8_t *LicenseKeyDst128)
+{
+	uint8_t i, index;
+	uint8_t tmp;
+	uint8_t tmp2;
+	for(i=0;i<128;i++)
+	{
+		index = i*2;
+		if(LicenseKeySrc256[index] >= '0' && LicenseKeySrc256[index] <= '9')
+		{
+			tmp = LicenseKeySrc256[index] - '0';	
+		}
+		else if(LicenseKeySrc256[index] >= 'A' && LicenseKeySrc256[index] <= 'F')
+		{
+			tmp = LicenseKeySrc256[index] - 'A'+10;
+		}
+		else if(LicenseKeySrc256[index] >= 'a' && LicenseKeySrc256[index] <= 'f')
+		{
+			tmp = LicenseKeySrc256[index] - 'a'+10;
+		}
+		else
+		{
+			return -1;
+			//printf("error\r\n");
+		}
+				
+		if(LicenseKeySrc256[index+1] >= '0' && LicenseKeySrc256[index+1] <= '9')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - '0';
+		}
+		else if(LicenseKeySrc256[index+1] >= 'A' && LicenseKeySrc256[index+1] <= 'F')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - 'A'+10;
+		}
+		else if(LicenseKeySrc256[index+1] >= 'a' && LicenseKeySrc256[index+1] <= 'f')
+		{
+			tmp2 = LicenseKeySrc256[index+1] - 'a'+10;
+		}
+		else
+		{
+			return -1;
+			//printf("error\r\n");
+		}		
+
+		LicenseKeyDst128[i] = ((tmp&0x0f) << 4) | (tmp2&0x0f);
+	}
+	return 1;
+}
+
+
+int CheckLicense()
+{
+    uint32_t *pUID = (uint32_t*)0x1FFF7A10;
+    uint8_t  GUID[12] = {0};
+    uint32_t tmp = 0;
+    uint8_t  *pLicense = (uint8_t*)0x08060000; 
+    uint8_t  LICENSE[128] = {0xE9,0x5F,0x60,0x69,0x92,0x01,0xDD,0x0F,0x98,0x42,0x57,0x15,
+                             0x6B,0x64,0x69,0xBE,0x03,0x0A,0x6A,0x17,0x25,0x7C,0xDC,0xAC,
+                             0xDF,0x10,0x04,0xBB,0x5C,0xE9,0xDA,0x70,0xD7,0xD9,0x22,0x8C,
+                             0xE9,0xAA,0xD7,0x2F,0x09,0x86,0xCE,0xE2,0x52,0xAD,0x9B,0x08,
+                             0x86,0x65,0xAF,0x52,0x55,0x38,0xC2,0xA9,0xD6,0x60,0x7B,0x36,
+                             0x5F,0x7F,0x41,0xBD,0x73,0x8C,0x7B,0x2A,0x14,0x12,0xDA,0x72,
+                             0x49,0x9C,0x11,0x96,0xD1,0x6B,0xA9,0x01,0x3B,0x6B,0x2E,0x1D,
+                             0x1F,0x67,0x97,0x21,0xA0,0x77,0xDD,0x29,0x3D,0xC1,0xE7,0x8C,
+                             0xC2,0x5F,0xB2,0x6B,0xA1,0x9F,0xAE,0x84,0x5F,0x6C,0x64,0x52,
+                             0x71,0x0B,0x59,0x51,0x29,0x07,0x32,0x9B,0x0B,0x6D,0x1E,0xB9,
+                             0x47,0x3B,0x73,0xBA,0x7F,0x14,0x95,0x87};    //从Flash中读出的带随机数填充的128字节License
+    uint8_t  CalLicense[16] = {0};  //计算得出的有效的16字节License
+    MD5_CTX md5;
+    int i;
+
+    //获取GUID
+    printf("GUID: ");
+    for(i=0;i<3;i++)
+    {
+        tmp = *pUID;
+        GUID[4*i+0] = tmp&0xff;
+        GUID[4*i+1] = (tmp>>8)&0xff;
+        GUID[4*i+2] = (tmp>>16)&0xff;
+        GUID[4*i+3] = (tmp>>24)&0xff;
+        pUID++;
+        printf("%02x %02x %02x %02x ",  GUID[4*i+0],GUID[4*i+1],GUID[4*i+2],GUID[4*i+3]);
+    }
+    printf("\n");
+
+    // //获取License
+    // printf("License: ");
+    // for(i=0;i<128;i++)
+    // {
+    //     LICENSE[i] = *pLicense;
+    //     pLicense++;
+    //     printf("%02x ", LICENSE[i]);
+    // }
+    // printf("\n" );
+
+    //根据GUID计算License    
+    preHandle((uint32_t*)GUID, 0x33445566, 2);    //预处理
+    MD5_Init(&md5);
+    MD5_Update(&md5,GUID,12);
+    MD5_Final(CalLicense, &md5);
+
+    printf("CalLicense: ");
+    for(i=0;i<16;i++)
+    {
+        printf("%02x ", CalLicense[i]);
+    }
+    printf("\n");
+
+    //比对License
+    if(Authorize(CalLicense, LICENSE, 0) == 1) //授权通过
+    {
+        printf("\r\nAlready Auth Success\r\n");         
+        return 0;
+    }
+    else    //授权不通过
+    {
+        printf("\n\n====================================================\n");
+        printf("\n\tLicense is invalid, Please authorize! \n");
+        printf("\n====================================================\n\n");
+        return -1;
+    }
+}

+ 2 - 0
app/bmc/Makefile

@@ -94,6 +94,8 @@ SRC += ./AuthChip/CM_WRCKSUM.c
 SRC += ./AuthChip/CM_WRITE.c
 SRC += ./AuthChip/CM_WRUSER.c
 
+SRC += ./AuthLicense.c
+
 # SRC += ../driver/STM32F4xx_HAL_Driver/system_stm32f4xx.c
 # SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c
 # SRC += ../driver/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_fmc.c

+ 27 - 23
app/bmc/main.c

@@ -77,31 +77,35 @@ BladeStatus_T gBladeStatus[BLADE_NUMBERS] = {
 static int tmp_fd;
 void main(void)
 {
-	if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
-	{
-		printf("Initialize AT88SC0104C failed!\n");
-		sleep(1);
-		return;
-	}
-	printf("cm_Auth_Encrp_Init ok\n");
+// 	if(0 != cm_Auth_Encrp_Init(1, 1, TRUE))
+// 	{
+// 		printf("Initialize AT88SC0104C failed!\n");
+// 		sleep(1);
+// 		return;
+// 	}
+// 	printf("cm_Auth_Encrp_Init ok\n");
 
-#if 0
-	if(0 != cm_Auth_Encrp_Personal(1, 1))
-	{
-		printf("Personal AT88SC0104C failed!\n");
-		sleep(1);
-		return ;
-	}
-#endif
+// #if 0
+// 	if(0 != cm_Auth_Encrp_Personal(1, 1))
+// 	{
+// 		printf("Personal AT88SC0104C failed!\n");
+// 		sleep(1);
+// 		return ;
+// 	}
+// #endif
 
-	if(0 != test_cryptomem())
-	{
-		while(1)
-		{
-			printf("Illegal Board!\n");
-			sleep(3);
-		}
-	}
+// 	if(0 != test_cryptomem())
+// 	{
+// 		while(1)
+// 		{
+// 			printf("Illegal Board!\n");
+// 			sleep(3);
+// 		}
+// 	}
+
+	//检查软件授权
+	if(CheckLicense() != 0)
+		exit(0);
 
 	PlatformInit();
 	Init_IPMI_FRU_SDR_SEL();