亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? aes.c

?? 這個通用的Bootloader可以支持大部分具有自編程功能、帶有Boot區(qū)和UART串口的AVR單片機(主要是Mega系列)。如果是多串口的單片機
?? C
字號:
/*

                           e Y8b    Y8b YV4.08P888 88e
                          d8b Y8b    Y8b Y888P 888 888D
                         d888b Y8b    Y8b Y8P  888 88"
                        d888WuHan8b    Y8b Y   888 b,
                       d8888888b Y8b    Y8P    888 88b,
           8888 8888       ,e,                                  888
           8888 888820088e  " Y8b Y888P ,e e, 888,8, dP"Y ,"Y88b888
           8888 8888888 88b888 Y8b Y8P d88 88b888 " C88b "8" 888888
           8888 8888888 888888  Y8b "  888   ,888    Y88D,ee 888888
           'Y88 88P'888 888888   Y8P    "YeeP"888   d,dP "88 888888
   888 88b,                    d8  888                     888
   888 88P' e88 88e  e88 88e  d88  888 e88 88e  ,"Y88b e88 888 ,e e, 888,8,
   888 8K  d888 888bd888 8Shaoziyang88d888 888b"8" 888d888 888d88 88b888 "
   888 88b,Y888 888PY888 888P 888  888Y888 888P,ee 888Y888 888888   ,888
   888 88P' "88 88"  "88 88"  888  888 "88 88" "88 888 "88 888 "YeeP"888


  Project:       AVR 通用 BootLoader
  File:          aes.c
                 aes ( Rijndael ) 128/256 位密鑰加密算法
                 基于 AVR231 的 aes 子程序
                 針對 avr 8 位單片機和GCC編譯器進行了優(yōu)化
  Version:       1.0

  Compiler:      WinAVR 20071221 + AVR Studio 4.14.589

  Author:        Shaoziyang
                 Shaoziyang@gmail.com
                 http://avrubd.googlepages.com
                 http://groups.google.com/group/avrub?hl=en

  Date:          2008.6

  See readme.htm to get more information.

*/


//使用 OPT_MODE 進行代碼大小優(yōu)化或者運行速度優(yōu)化
//OPT_SPEED 可以提高解密速度 20% 以上
#define OPT_SIZE  1
#define OPT_SPEED 2

#define OPT_MODE  OPT_SIZE

#define BPOLY 0x1b          //!< Lower 8 bits of (x^8+x^4+x^3+x+1), ie. (x^4+x^3+x+1).
#define BLOCKSIZE 16        //!< 數(shù)據(jù)塊大小(字節(jié)).

#ifndef AES_128
#define AES_128   2
#endif

#ifndef AES_256
#define AES_256   3
#endif

#ifndef Algorithm
#define Algorithm AES_128
#endif

#if (Algorithm == AES_128)
  #define ROUNDS 10         //循環(huán)次數(shù)
  #define KEYLENGTH 16      //密鑰長度
#elif (Algorithm == AES_256)
  #define ROUNDS 14
  #define KEYLENGTH 32
#else
#error "Unknow encrypt algorithm!"
#endif


unsigned char block1[256];  //工作區(qū)1
unsigned char block2[256];  //工作區(qū)2
unsigned char tempbuf[256]; //臨時緩沖區(qū)
unsigned char chain[16];    //密鑰塊鏈

unsigned char *powTbl;      //!< Final location of exponentiation lookup table.
unsigned char *logTbl;      //!< Final location of logarithm lookup table.
unsigned char *sBox;        //!< Final location of s-box.
unsigned char *sBoxInv;     //!< Final location of inverse s-box.
unsigned char *expandedKey; //!< Final location of expanded key.


void CalcPowLog(unsigned char *powTbl, unsigned char *logTbl)
{
  unsigned char i = 0;
  unsigned char t = 1;

  do {
    // Use 0x03 as root for exponentiation and logarithms.
    powTbl[i] = t;
    logTbl[t] = i;
    i++;

    // Muliply t by 3 in GF(2^8).
    t ^= (t << 1) ^ (t & 0x80 ? BPOLY : 0);
  }while( t != 1 ); // Cyclic properties ensure that i < 255.

  powTbl[255] = powTbl[0]; // 255 = '-0', 254 = -1, etc.
}

void CalcSBox( unsigned char * sBox )
{
  unsigned char i, rot;
  unsigned char temp;
  unsigned char result;

  // Fill all entries of sBox[].
  i = 0;
  do {
    //Inverse in GF(2^8).
    if( i > 0 ) 
    {
      temp = powTbl[ 255 - logTbl[i] ];
    } 
    else 
    {
      temp = 0;
    }

    // Affine transformation in GF(2).
    result = temp ^ 0x63; // Start with adding a vector in GF(2).
    for( rot = 4; rot > 0; rot-- )
    {
      // Rotate left.
      temp = (temp<<1) | (temp>>7);

      // Add rotated byte in GF(2).
      result ^= temp;
    }

    // Put result in table.
    sBox[i] = result;
  } while( ++i != 0 );
}

void CalcSBoxInv( unsigned char * sBox, unsigned char * sBoxInv )
{
  unsigned char i = 0;
  unsigned char j = 0;

  // Iterate through all elements in sBoxInv using  i.
  do {
    // Search through sBox using j.
    do {
      // Check if current j is the inverse of current i.
      if( sBox[j] == i )
      {
        // If so, set sBoxInc and indicate search finished.
        sBoxInv[i] = j;
        j = 255;
      }
    } while( ++j != 0 );
  } while( ++i != 0 );
}

#if OPT_MODE == OPT_SIZE
void CalcCols(unsigned char *col)
{
  unsigned char i;

  for(i = 4; i > 0; i--)
  {
    *col = (*col << 1) ^ (*col & 0x80 ? BPOLY : 0);
    col++;
  }
}
#endif

void InvMixColumn( unsigned char * column )
{
  unsigned char r[4];

  r[0] = column[1] ^ column[2] ^ column[3];
  r[1] = column[0] ^ column[2] ^ column[3];
  r[2] = column[0] ^ column[1] ^ column[3];
  r[3] = column[0] ^ column[1] ^ column[2];

#if OPT_MODE == OPT_SIZE
  CalcCols(column);
#else
  column[0] = (column[0] << 1) ^ (column[0] & 0x80 ? BPOLY : 0);
  column[1] = (column[1] << 1) ^ (column[1] & 0x80 ? BPOLY : 0);
  column[2] = (column[2] << 1) ^ (column[2] & 0x80 ? BPOLY : 0);
  column[3] = (column[3] << 1) ^ (column[3] & 0x80 ? BPOLY : 0);
#endif

  r[0] ^= column[0] ^ column[1];
  r[1] ^= column[1] ^ column[2];
  r[2] ^= column[2] ^ column[3];
  r[3] ^= column[0] ^ column[3];

#if OPT_MODE == OPT_SIZE
  CalcCols(column);
#else
  column[0] = (column[0] << 1) ^ (column[0] & 0x80 ? BPOLY : 0);
  column[1] = (column[1] << 1) ^ (column[1] & 0x80 ? BPOLY : 0);
  column[2] = (column[2] << 1) ^ (column[2] & 0x80 ? BPOLY : 0);
  column[3] = (column[3] << 1) ^ (column[3] & 0x80 ? BPOLY : 0);
#endif

  r[0] ^= column[0] ^ column[2];
  r[1] ^= column[1] ^ column[3];
  r[2] ^= column[0] ^ column[2];
  r[3] ^= column[1] ^ column[3];

#if OPT_MODE == OPT_SIZE
  CalcCols(column);
#else
  column[0] = (column[0] << 1) ^ (column[0] & 0x80 ? BPOLY : 0);
  column[1] = (column[1] << 1) ^ (column[1] & 0x80 ? BPOLY : 0);
  column[2] = (column[2] << 1) ^ (column[2] & 0x80 ? BPOLY : 0);
  column[3] = (column[3] << 1) ^ (column[3] & 0x80 ? BPOLY : 0);
#endif

  column[0] ^= column[1] ^ column[2] ^ column[3];
  r[0] ^= column[0];
  r[1] ^= column[0];
  r[2] ^= column[0];
  r[3] ^= column[0];
  
  column[0] = r[0];
  column[1] = r[1];
  column[2] = r[2];
  column[3] = r[3];
}

void SubBytes( unsigned char * bytes, unsigned char count )
{
  do {
    *bytes = sBox[ *bytes ]; // Substitute every byte in state.
    bytes++;
  } while( --count );
}

void InvSubBytesAndXOR( unsigned char * bytes, unsigned char * key, unsigned char count )
{
  do {
    // *bytes = sBoxInv[ *bytes ] ^ *key; // Inverse substitute every byte in state and add key.
    *bytes = block2[ *bytes ] ^ *key; // Use block2 directly. Increases speed.
    bytes++;
    key++;
  } while( --count );
}

void InvShiftRows( unsigned char * state )
{
  unsigned char temp;          
  // Note: State is arranged column by column.

#if OPT_MODE == OPT_SIZE
  unsigned char i, j;

  for(i = 3; i > 0; i--)
  {
    for(j = i; j > 0; j--)
    {
      temp = state[i + 3 * 4];
      state[i + 3 * 4] = state[i + 2 * 4];
      state[i + 2 * 4] = state[i + 1 * 4];
      state[i + 1 * 4] = state[i + 0 * 4];
      state[i + 0 * 4] = temp;
    }
  }
#else
  // Cycle second row right one time.
  temp = state[ 1 + 3*4 ];
  state[ 1 + 3*4 ] = state[ 1 + 2*4 ];
  state[ 1 + 2*4 ] = state[ 1 + 1*4 ];
  state[ 1 + 1*4 ] = state[ 1 + 0*4 ];
  state[ 1 + 0*4 ] = temp;

  // Cycle third row right two times.
  temp = state[ 2 + 0*4 ];
  state[ 2 + 0*4 ] = state[ 2 + 2*4 ];
  state[ 2 + 2*4 ] = temp;
  temp = state[ 2 + 1*4 ];
  state[ 2 + 1*4 ] = state[ 2 + 3*4 ];
  state[ 2 + 3*4 ] = temp;

  // Cycle fourth row right three times, ie. left once.
  temp = state[ 3 + 0*4 ];
  state[ 3 + 0*4 ] = state[ 3 + 1*4 ];
  state[ 3 + 1*4 ] = state[ 3 + 2*4 ];
  state[ 3 + 2*4 ] = state[ 3 + 3*4 ];
  state[ 3 + 3*4 ] = temp;
#endif
}

void XORBytes( unsigned char * bytes1, unsigned char * bytes2, unsigned char count )
{
  do {
    *bytes1 ^= *bytes2; // Add in GF(2), ie. XOR.
    bytes1++;
    bytes2++;
  } while( --count );
}

void CopyBytes( unsigned char * to, unsigned char * from, unsigned char count )
{
  do {
    *to = *from;
    to++;
    from++;
  } while( --count );
}

void KeyExpansion( unsigned char * expandedKey )
{
  unsigned char temp[4], t;
  unsigned char i;
  unsigned char Rcon[4] = { 0x01, 0x00, 0x00, 0x00 }; // Round constant.

  const unsigned char * key = DecryptKey;

  // Copy key to start of expanded key.
  CopyBytes(expandedKey, (unsigned char *)key, KEYLENGTH);
  expandedKey += KEYLENGTH;

  // Prepare last 4 bytes of key in temp.
  CopyBytes(temp, (unsigned char *)key + KEYLENGTH - 4, 4);

  // Expand key.
  i = KEYLENGTH;
  while( i < BLOCKSIZE*(ROUNDS+1) ) 
  {
    // Are we at the start of a multiple of the key size?
    if( (i % KEYLENGTH) == 0 )
    {
      // Cycle left once.
      t = temp[0];
      temp[0] = temp[1];
      temp[1] = temp[2];
      temp[2] = temp[3];
      temp[3] = t;
      SubBytes( temp, 4 ); // Substitute each byte.
      XORBytes( temp, Rcon, 4 ); // Add constant in GF(2).
      *Rcon = (*Rcon << 1) ^ (*Rcon & 0x80 ? BPOLY : 0);
    }

    // Keysize larger than 24 bytes, ie. larger that 192 bits?
    #if KEYLENGTH > 24
    // Are we right past a block size?
    else if( (i % KEYLENGTH) == BLOCKSIZE ) {
      SubBytes( temp, 4 ); // Substitute each byte.
    }
    #endif

    // Add bytes in GF(2) one KEYLENGTH away.
    XORBytes( temp, expandedKey - KEYLENGTH, 4 );

    // Copy result to current 4 bytes.
    *(expandedKey++) = temp[0];
    *(expandedKey++) = temp[1];
    *(expandedKey++) = temp[2];
    *(expandedKey++) = temp[3];

    i += 4; // Next 4 bytes.
  }
}

void InvCipher( unsigned char * block, unsigned char * expandedKey )
{
  unsigned char i, j;
  unsigned char round = ROUNDS-1;
  expandedKey += BLOCKSIZE * ROUNDS;

  XORBytes( block, expandedKey, 16 );
  expandedKey -= BLOCKSIZE;

  do {
    InvShiftRows( block );
    InvSubBytesAndXOR( block, expandedKey, 16 );
    expandedKey -= BLOCKSIZE;
    for(i = 4, j = 0; i > 0; i--, j+=4)
      InvMixColumn( block + j );
  } while( --round );

  InvShiftRows( block );
  InvSubBytesAndXOR( block, expandedKey, 16 );
}

void aesDecInit(void)
{
  unsigned char i;
  
  for(i = 0; i < 16; i++)
    chain[i] = 0;
    
  powTbl = block1;
  logTbl = block2;
  CalcPowLog( powTbl, logTbl );

  sBox = tempbuf;
  CalcSBox( sBox );

  expandedKey = block1;
  KeyExpansion( expandedKey );

  sBoxInv = block2; // Must be block2.
  CalcSBoxInv( sBox, sBoxInv );
}

#define DecryptInit()     aesDecInit()

//解密數(shù)據(jù)塊
void DecryptBlock(unsigned char *buf, unsigned int nSize)
{
  unsigned int n;

  for(n = nSize; n > 0; n -= 16)
  {
    CopyBytes( tempbuf, buf, BLOCKSIZE );
    InvCipher( buf, expandedKey );
    XORBytes( buf, chain, BLOCKSIZE );
    CopyBytes( chain, tempbuf, BLOCKSIZE );
    buf += 16;
  }
}

//銷毀密鑰
void DestroyKey()
{
  unsigned char i;

#if (Algorithm == AES_128)
  for(i = 16; i > 0; i--)
#else
  for(i = 32; i > 0; i--)
#endif
  {
    DecryptKey[i - 1] = 0;
  }
}

//end of file

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩一区三区四区| www.av精品| 欧美日韩国产系列| 天堂成人免费av电影一区| 欧美久久免费观看| 视频一区二区三区在线| 日韩无一区二区| 国产伦精品一区二区三区免费 | 精品国产百合女同互慰| 精品亚洲成a人| 中文字幕巨乱亚洲| 在线视频国产一区| 奇米精品一区二区三区在线观看| 日韩免费观看2025年上映的电影 | 国产美女视频91| 中文字幕第一区二区| 91浏览器打开| 日韩高清不卡一区二区三区| 久久伊99综合婷婷久久伊| 成人在线视频首页| 五月综合激情日本mⅴ| 欧美成人vr18sexvr| 99久久99久久精品免费观看| 亚洲午夜精品在线| 欧美精品一区二区三区四区| 不卡一区二区在线| 日韩高清不卡一区| 中文字幕日韩精品一区| 欧美日韩视频第一区| 国产精品亚洲а∨天堂免在线| 亚洲男人天堂av| 欧美成人官网二区| 在线欧美小视频| 国产精品一区一区三区| 亚洲国产成人va在线观看天堂| 精品久久国产字幕高潮| 97精品国产露脸对白| 久久精品国产成人一区二区三区| 日韩毛片一二三区| 精品黑人一区二区三区久久| 一本久久a久久精品亚洲| 久久99国产精品免费网站| 亚洲视频一二三区| 国产丝袜欧美中文另类| 91精品欧美一区二区三区综合在| 91在线精品一区二区| 精品在线免费视频| 亚洲成人资源在线| 亚洲欧美欧美一区二区三区| 日韩欧美国产综合在线一区二区三区| www.亚洲色图| 国内精品久久久久影院一蜜桃| 亚洲123区在线观看| 《视频一区视频二区| 国产日产欧美一区二区视频| 91精品国产一区二区三区蜜臀| 99国产欧美久久久精品| 国产精品影视在线观看| 毛片av中文字幕一区二区| 亚洲va国产天堂va久久en| 自拍偷在线精品自拍偷无码专区 | 成人国产精品视频| 久久精品99国产国产精| 日韩不卡一区二区三区| 亚洲成av人片在www色猫咪| 亚洲同性同志一二三专区| 国产日韩欧美麻豆| 精品噜噜噜噜久久久久久久久试看 | 夜夜精品视频一区二区| 国产精品美女www爽爽爽| 精品福利视频一区二区三区| 日韩美女在线视频 | 极品瑜伽女神91| 日韩综合一区二区| 亚洲成人你懂的| 亚洲一区av在线| 亚洲成人免费电影| 午夜影院在线观看欧美| 婷婷综合另类小说色区| 亚洲成av人影院| 青娱乐精品视频| 另类综合日韩欧美亚洲| 精品一区二区三区影院在线午夜| 另类专区欧美蜜桃臀第一页| 久草在线在线精品观看| 久久99精品一区二区三区三区| 精品一区二区影视| 国产精品一区二区你懂的| 国产成人免费在线| 99久久精品久久久久久清纯| 色综合天天综合网天天狠天天| 日本道精品一区二区三区| 欧美日韩精品高清| 日韩天堂在线观看| 国产亚洲美州欧州综合国| 中文字幕的久久| 亚洲精品高清在线| 日本免费新一区视频| 视频在线观看91| 国产寡妇亲子伦一区二区| av成人免费在线观看| 在线观看网站黄不卡| 制服丝袜亚洲播放| 26uuu色噜噜精品一区| 国产精品三级视频| 一区二区三区在线视频观看58| 亚洲午夜一二三区视频| 日本不卡123| 成a人片亚洲日本久久| 欧美男女性生活在线直播观看| 精品少妇一区二区三区在线播放 | 午夜视频在线观看一区二区三区| 日韩1区2区日韩1区2区| 激情综合网av| 91小视频免费看| 欧美猛男超大videosgay| 26uuu久久天堂性欧美| 综合色天天鬼久久鬼色| 久久成人免费日本黄色| 91在线视频18| 欧美一级精品在线| 国产精品毛片大码女人| 五月天国产精品| 成人黄页毛片网站| 欧美一卡二卡在线观看| 国产精品欧美综合在线| 日韩精品成人一区二区三区| 成av人片一区二区| 欧美不卡一区二区三区四区| 亚洲精品写真福利| 国产在线精品一区二区三区不卡| www.欧美亚洲| 久久久欧美精品sm网站| 亚洲电影第三页| 成人国产在线观看| 精品国产伦一区二区三区观看方式| 亚洲乱码中文字幕综合| 国产精品小仙女| 欧美一区二区高清| 一区二区欧美在线观看| 北岛玲一区二区三区四区| 精品粉嫩aⅴ一区二区三区四区| 亚洲综合另类小说| www.亚洲国产| 国产日韩欧美制服另类| 久久不见久久见中文字幕免费| 欧美三级韩国三级日本三斤| 17c精品麻豆一区二区免费| 国产剧情一区二区三区| 日韩一级片在线播放| 午夜精品久久久久| 欧美做爰猛烈大尺度电影无法无天| 国产精品人妖ts系列视频| 国产乱码一区二区三区| 精品三级在线看| 青青草一区二区三区| 欧美日韩国产一级| 亚洲中国最大av网站| 一本大道久久精品懂色aⅴ| 国产精品久久夜| 国产91精品免费| 国产婷婷色一区二区三区四区| 精品一区二区三区的国产在线播放| 欧美精品一卡二卡| 丝袜美腿成人在线| 欧美伦理电影网| 偷偷要91色婷婷| 日韩免费一区二区| 精品一区二区在线免费观看| 欧美精品一区二区三区在线 | 精品视频123区在线观看| 亚洲一卡二卡三卡四卡| 欧美日韩一区二区三区四区 | 亚洲欧美日韩国产另类专区| 91在线国内视频| 亚洲一二三四区| 欧美久久久久久蜜桃| 日本麻豆一区二区三区视频| 欧美一二三区在线| 国产乱码精品一区二区三区五月婷| 久久色中文字幕| 成人美女视频在线看| 国产精品毛片久久久久久| 色综合久久天天| 天天av天天翘天天综合网色鬼国产| 欧美日韩国产电影| 精品一区二区免费视频| 国产欧美日韩在线| 一本一本大道香蕉久在线精品 | 丝袜a∨在线一区二区三区不卡| 欧美一级片免费看| 狠狠色综合日日| 国产精品久久久久久久久快鸭| 99在线视频精品| 午夜久久久久久电影| 欧美一级久久久| hitomi一区二区三区精品| 亚洲综合小说图片| 欧美精品一区二区三区视频| 99在线视频精品|