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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cbcmac.nc

?? tinyos密鑰管理組件 用在tinyos仿真里的
?? NC
字號:

module CBCMAC {
  provides {
    interface MAC;}
  uses {
    interface BlockCipher;
    interface BlockCipherInfo;
  }
}
implementation
{
  enum {
    // we allocate some static buffeers on the stack; they have to be less
    // than this size
    CBCMAC_BLOCK_SIZE = 8
  };
  typedef struct CBCMACContext {
    // the result of our partial computation. we xor this with new data and
    // then encrypt it when full.
    uint8_t  partial[CBCMAC_BLOCK_SIZE];
    // the total number of bytes left for the MAC to process.
    uint16_t length;
    // the current offset into the partial array. 
    uint8_t  blockPos;
  } __attribute__ ((packed)) CBCMACContext;
  
  /**
   * Initializes the MAC layer and stores any local state into the context
   * variable. The context variable should be used for future invocations
   * which share this key. It uses the preferred block size of the underlying
   * BlockCipher
   *
   * @param context opaque data structure to hold the module specific state
   *        associated with this key.
   * @param keySize length of the key in bytes.
   * @param key pointer to a buffer containing keySize bytes of shared key data
   * @return Whether initialization was successful. The command may be
   *         unsuccessful if the key size or blockSize are not valid for the
   *         given cipher implementation. 
   */
  command result_t MAC.init (MACContext * context, uint8_t keySize,
                             uint8_t * key)
    {
      if ( call BlockCipherInfo.getPreferredBlockSize() != CBCMAC_BLOCK_SIZE) {
        // the block cipher exceeds our max size.
        return FAIL;
      }
      // just init the underlying block cipher
      return call BlockCipher.init (&context->cc, CBCMAC_BLOCK_SIZE,
                                    keySize, key);
    }
  
  /**
   * Initializes an invocation of an incremental MAC computation. This is
   * provided for asynchronous operation so that the MAC may be incrementally
   * computed. Partial state is stored in the context.
   *
   * @param context opaque data structure to hold the module specific state
   *        associated with this invocation of the incremental computation.
   * @param length the total length of data that is forthcoming
   * @return whether the incremental initialization was successful. This can
   *        fail if the underlying cipher operation fails.
   */
  command result_t MAC.initIncrementalMAC (MACContext * context,
                                           uint16_t length)
    {
      // temp. plain text. to make CBC-Mac secure for variable length messages
      // we need to modify the normal CBC procedure: namely, we initialze the
      // mac by encrypting the 0th block as the length (in blocks) of the
      // message. This results in a secure MAC.
      //
      // see Mihir Bellare, Joe Kilian, Phillip Rogaway
      // The Security of the Cipher Block Chaining Message Authentication Code
      // 1995, p12-13

      // temp buffer to hold length buffer which we'll encrypt to the
      // real "partial" stored in the context. 
      uint8_t partial[CBCMAC_BLOCK_SIZE];
      // length divided by 8 [ ie num blocks]
      uint8_t numBlocks = length >> 3;
      memset (partial, 0, 6);
      partial[6] = (numBlocks >> 8) & 0xff;
      partial[7] = (numBlocks & 0xff);

      ((CBCMACContext*) context->context)->length = length;
      ((CBCMACContext*) context->context)->blockPos = 0;
      return call BlockCipher.encrypt (&context->cc, partial,
                                       ((CBCMACContext*) context->context)->partial);
    }
  
  /**
   * Computes an incremental MAC on msgLen bytes of the msg. This call is
   * tied to the initIncrementalMAC call, which must be made first. This call
   * can fail if the msgLen provided exceeds the amount specified earlier or
   * if a block cipher operation fails.
   *
   * @param context opaque data structure to hold the module specific state
   *        associated with this invocation of the incremental computation.
   * @param msg the message data to add to the incremental computation.
   * @param msgLen number of bytes to add for the incremental computation.
   * @return whether the incremental mac computation succeeded or not. It can
   *        fail if more data is provided than the initial initialization
   *        indicated or if the underlying block cipher fails.
   */
  command result_t MAC.incrementalMAC (MACContext * context, uint8_t * msg, 
                                       uint16_t msgLen)
    {
      uint8_t i, pos = ((CBCMACContext*) context->context)->blockPos;
      uint8_t * partial = ((CBCMACContext*) context->context)->partial;

      // only proceed if the we're expecting less than msgLen of data. 
      if ( ((CBCMACContext*) context->context)->length < msgLen) {
        return FAIL;
      }
      // simple here: just xor the msg with the partial and when we fill up
      // the partial, encrypt it.
      for (i = 0; i < msgLen; i++) {
        // unroll
        partial[pos++] ^= msg[i];
        if (pos == 7) {
          if (!call BlockCipher.encrypt (&context->cc, partial, partial)) {
            return FAIL;
          }
          pos = 0;
        }
      }
      
      ((CBCMACContext*) context->context)->length -= msgLen;
      ((CBCMACContext*) context->context)->blockPos = pos;
      return SUCCESS;
    }
    
  /**
   * Returns the actual MAC code from an in-progress incremental MAC
   * computation. The initIncrementalMAC and length bytes of data must have
   * been computed using the provided context for this function to succeed.
   * This function may fail if the requested MAC size exceeds the underlying
   * cipher block size, or if the incremental MAC computation has not yet
   * finished.
   *
   * @param context opaque data structure to hold the module specific state
   *        associated with this invocation of the incremental computation.
   * @param MAC resulting buffer of at least macSize to hold the generated MAC
   * @param macSize the number of bytes of MAC to generate. This must be
   *        less than or equal to the underlying blockCipher block size.
   * @return whether the command succeeded or not. It can fail if the
   *        underlying block cipher fails or if not all expected data was
   *        received from the initialization function
   */
  command result_t MAC.getIncrementalMAC (MACContext * context, uint8_t * res,
                                          uint8_t macSize)
    {
      uint8_t blockPos = ((CBCMACContext*) context->context)->blockPos;
      uint8_t * partial = ((CBCMACContext*) context->context)->partial;
      // make sure they're asking for a valid mac size and that we've received
      // all the data that we're expecting.
      if (! macSize || macSize > 8 ||
          ((CBCMACContext*) context->context)->length) {
        return FAIL;
      }
      // the last block may be a partial block [ie, may have some data that
      // has been xored but not yet encrypted]. if so, encrypt it.
      if (blockPos) {
        // one last encr: xor with 10000 
        partial[++blockPos] ^= 1;
        if (! call BlockCipher.encrypt (&context->cc, partial, partial)) {
          return FAIL;
        }
        ((CBCMACContext*) context->context)->blockPos = 0;        
      }
      memcpy ( res, ((CBCMACContext*) context->context)->partial, macSize);
      return SUCCESS;
    }

  /**
   * Computes a non-incremental MAC calculation on the given message. The
   * key from the init() call will be used for the MAC calculation.
   *
   * @param context opaque data structure to hold the module specific state
   *        associated with this invocation of the incremental computation.
   * @param msg a buffer of length size on which the MAC will be calculated
   * @param length the total length of the msg
   * @param buffer of at least macSize where the resulting MAC calculation
   *        will be stored.
   * @param macSzie the number of bytes of MAC to generate. This must be
   *        less than or equal to the underlying blockCipher block size.
   * @return whether the command suceeds or not. It can fail if the underlying
   *        blockCipher fails. 
   */
  command result_t MAC.MAC (MACContext * context, uint8_t * msg,
                            uint16_t length,
                            uint8_t *res, uint8_t macSize)
    {
      // we'll just call the incremental primitives that we've built:
      if (call MAC.initIncrementalMAC (context, length) != SUCCESS)
        return FAIL;
      if (call MAC.incrementalMAC (context, msg, length) != SUCCESS)
        return FAIL;
      return call MAC.getIncrementalMAC (context, res, macSize);
    }
  
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品日韩一区二区三区 | 成人a免费在线看| 亚洲第一主播视频| 亚洲精品亚洲人成人网| 亚洲欧美综合在线精品| 国产精品亲子乱子伦xxxx裸| 国产人伦精品一区二区| 国产欧美日韩中文久久| 亚洲国产精品高清| 亚洲欧美怡红院| 亚洲精品国久久99热| 亚洲一区二区精品视频| 视频一区中文字幕国产| 免费成人美女在线观看.| 国产精品一区三区| 国产999精品久久久久久| 99这里只有久久精品视频| 91麻豆免费在线观看| 欧美日韩视频不卡| 日韩精品一区二区三区蜜臀| 久久精品欧美一区二区三区麻豆| 欧美激情在线一区二区三区| 亚洲激情六月丁香| 日本 国产 欧美色综合| 国产成人丝袜美腿| 日本道色综合久久| 日韩一区二区三区视频在线| 亚洲国产精品99久久久久久久久 | 99久久精品99国产精品| 欧美午夜在线一二页| 日韩一级大片在线| 欧美激情自拍偷拍| 天堂va蜜桃一区二区三区| 国产美女视频91| 一本久道中文字幕精品亚洲嫩| 欧美军同video69gay| 国产亚洲1区2区3区| 亚洲亚洲精品在线观看| 国产露脸91国语对白| 97精品国产露脸对白| 欧美一级日韩免费不卡| 国产精品天美传媒| 蜜臀久久99精品久久久久久9| 99久久精品免费精品国产| 欧美电影在线免费观看| 综合久久久久综合| 国产一区欧美一区| 欧美日韩电影一区| ㊣最新国产の精品bt伙计久久| 日韩精品欧美精品| 日本乱人伦aⅴ精品| 国产欧美日韩卡一| 久久国产尿小便嘘嘘尿| 精品视频免费看| 亚洲欧洲无码一区二区三区| 黄一区二区三区| 欧美一三区三区四区免费在线看| 中文字幕视频一区| 国产不卡一区视频| 精品国产成人系列| 久久精品99国产精品日本| 欧美午夜精品理论片a级按摩| 国产精品久久久久久久久动漫| 国产精一区二区三区| 欧美成人a在线| 天堂精品中文字幕在线| 欧美日韩国产大片| 亚洲超丰满肉感bbw| 色综合久久中文综合久久牛| 国产精品久久久久久久久果冻传媒| 国产一区二区伦理| 精品久久人人做人人爱| 蜜桃av一区二区在线观看| 欧美日韩精品一区二区天天拍小说 | 亚洲va天堂va国产va久| 99视频国产精品| 亚洲欧洲在线观看av| 99精品热视频| 亚洲一区国产视频| 色成年激情久久综合| 亚洲综合999| 欧美色视频在线观看| 五月天激情小说综合| 欧美日韩国产精选| 久久精品二区亚洲w码| 久久精品夜色噜噜亚洲a∨| 国产美女在线精品| 日韩美女视频一区二区| 欧美亚洲国产一区二区三区 | 亚洲精品一区二区在线观看| 狠狠网亚洲精品| 国产精品欧美精品| 欧美最猛性xxxxx直播| 亚洲.国产.中文慕字在线| 91精品综合久久久久久| 精品一区二区在线视频| 亚洲国产精品av| 欧美日韩视频专区在线播放| 麻豆精品在线播放| 国产精品视频免费| 欧美色国产精品| 韩国精品久久久| 亚洲视频一区在线| 5月丁香婷婷综合| 国产精品影视在线| 亚洲永久精品大片| 精品国产电影一区二区| 9l国产精品久久久久麻豆| 亚洲二区在线视频| 久久精品视频在线看| 在线免费精品视频| 国产美女在线精品| 亚洲午夜在线视频| 久久久亚洲高清| 在线观看日韩国产| 国产精品一卡二卡在线观看| 亚洲综合区在线| 久久久www免费人成精品| 欧美亚洲国产一区在线观看网站| 国产一区啦啦啦在线观看| 一区二区三区精密机械公司| 久久久亚洲综合| 777久久久精品| 一本色道久久综合狠狠躁的推荐| 男人操女人的视频在线观看欧美 | 色婷婷久久久久swag精品| 日本91福利区| 亚洲电影第三页| 日韩毛片视频在线看| 日韩免费福利电影在线观看| 欧美亚州韩日在线看免费版国语版| 国产麻豆视频一区二区| 国产成都精品91一区二区三| 午夜久久久久久| 亚洲人成亚洲人成在线观看图片 | 一区二区三区资源| 国产欧美精品一区二区三区四区| 91精品蜜臀在线一区尤物| 色婷婷亚洲一区二区三区| 丁香婷婷深情五月亚洲| 久久成人久久鬼色| 日韩va欧美va亚洲va久久| 亚洲夂夂婷婷色拍ww47 | 欧美精品第一页| 欧美亚洲国产bt| 在线欧美日韩精品| 在线一区二区观看| 一本一道综合狠狠老| 波多野结衣亚洲一区| 成人午夜免费电影| 风流少妇一区二区| 国产福利精品一区二区| 国内精品久久久久影院一蜜桃| 免费观看在线色综合| 日韩av在线免费观看不卡| 日韩专区一卡二卡| 全部av―极品视觉盛宴亚洲| 免费在线观看日韩欧美| 美女看a上一区| 国产久卡久卡久卡久卡视频精品| 国产精品香蕉一区二区三区| 国产在线不卡一区| 国产成a人无v码亚洲福利| gogo大胆日本视频一区| 91美女蜜桃在线| 9191国产精品| 精品欧美黑人一区二区三区| 久久九九久久九九| 亚洲人成人一区二区在线观看| 亚洲欧美日韩国产中文在线| 亚洲第一福利一区| 久久精品国产99| 国产69精品一区二区亚洲孕妇| 不卡av免费在线观看| 在线观看av一区| 精品久久久久久最新网址| 国产三级一区二区| 亚洲激情图片qvod| 美国十次综合导航| 成a人片国产精品| 欧美日韩三级一区二区| 精品三级在线看| 亚洲天堂福利av| 日本人妖一区二区| 粉嫩av一区二区三区粉嫩 | 日韩**一区毛片| 国产一区二区看久久| 在线观看精品一区| 精品久久久久一区二区国产| 国产精品久久久久久久久图文区 | 91亚洲精品乱码久久久久久蜜桃 | 日本aⅴ免费视频一区二区三区| 成人精品小蝌蚪| 欧美高清dvd| 国产精品情趣视频| 麻豆91小视频| 欧美伊人久久大香线蕉综合69 | 中文av一区特黄| 午夜a成v人精品| 99久久亚洲一区二区三区青草|