123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include "extAuth.h"
- #include <stdio.h>
- #ifdef I_AM_LTE
- #define RAND_STR_LEN 6
- const unsigned char srcAuth[16]={0x17,0x0d,0x55,0x9f,0xab,0xcc,0x1c,0x8f,0x30,0x0a,0x28,0xda,0x3c,0x91,0x11,0x6d};
- const unsigned char randStr[RAND_STR_LEN]={'s','z','5','0','2','8'};
- static unsigned char codeRandStr[RAND_STR_LEN];
- unsigned char * extGetCodeRandStr(int *outlen){
- *outlen=RAND_STR_LEN;
- return codeRandStr;
- }
- /*随机生成一个种子
- offset,偏移时间*/
- static unsigned char extRandSeed(unsigned int offset){
- unsigned char seed;
- srand(getBaseSeconds()+offset);
- seed=rand()/256;
- return seed;
- }
- /*使用seed1,seed2对长度为srclen的srcStr进行运算加密*/
- static void extCodeToRandStrTmp(unsigned char seed1,unsigned char seed2,unsigned char *srcStr, int srclen){
- unsigned int i,j;
- unsigned char newSeed=seed1|seed2|0xa7;
- for(i=0;i<srclen;i++) srcStr[i] ^= seed1;
- for(i=0;i<srclen;i++) if(i%2) srcStr[i] ^= seed2;
- for(i=0;i<srclen;i++) if(i%2==0) srcStr[i] ^= newSeed;
- }
- /*获取随机串,地址赋予outStr输出,同时输出串长度*/
- unsigned char *extGetRandStr(int *outlen){
- unsigned char seed1,seed2;
- unsigned char tmp[RAND_STR_LEN];
- static unsigned int step=0;
- if(outlen<RAND_STR_LEN) return -1;
- memcpy(tmp, randStr, RAND_STR_LEN);
- seed1=extRandSeed(step);
- seed2=extRandSeed(0x1468+step);
- extCodeToRandStrTmp(seed1, seed2,tmp,RAND_STR_LEN);
- memcpy(codeRandStr,tmp,RAND_STR_LEN);
- *outlen=RAND_STR_LEN;
- step += 77;
- return codeRandStr;
- }
- #endif
- /*对长度为targetlen的targetString进行加密,入参还有长度为randlen的随机串*/
- void extCodeBuffer(unsigned char *randString, int randlen, unsigned char *targetString, int targetlen){
- int i,j,k;
- unsigned char value;
- //先使用随机串依次对targetString异常运行
- j=0;
- for(i=0;i<targetlen;i++){
- targetString[i] ^= randString[j];
- if(++j>=randlen) j=0;
- }
- //再对targetString的奇数索引字节,与randString的高低4位指向的srcAuth索引字节异常
- j=0;
- for(i=0;i<targetlen;i++){
- if(j%2) k=randStr[j]&0x0F;
- else k=(randStr[j]>>4)&0x0F;
- value=srcAuth[k];
- if(++j>=randlen) j=0;
- if(i%2) targetString[i] ^= value;
- }
- }
|