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

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

?? cbcmac.nc

?? 無線傳感器密鑰管理算法
?? NC
字號:
/*									tab:4
 * "Copyright (c) 2000-2002 The Regents of the University  of California.  
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 *
 * Provides a CBC-MAC (cipher block chaining message authentication code) as
 * an incremental computation. This is used to ensure data (message) integrity
 * -- i.e. that it hasn't been tampered with en route. See Schneier 455-6. 
 *
 * This implementation is incrementatl: it accepts quantities as few as a
 * byte at a time and saves state in the context. The user receives the
 * MAC via getIncrementalMac() call.
 *
 * Authors: Naveen Sastry
 * Date:    
 */
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一区二区三区免费野_久草精品视频
中文字幕一区二区三区av| 日韩欧美一二区| 成人一区二区三区中文字幕| 国模冰冰炮一区二区| 国产伦精品一区二区三区免费迷| 日本午夜精品一区二区三区电影| 日韩电影一区二区三区| 精品一区精品二区高清| 国产真实乱对白精彩久久| 国产激情91久久精品导航 | 日本欧洲一区二区| 麻豆中文一区二区| 国产精品1区2区| 色综合色狠狠天天综合色| 一本久久综合亚洲鲁鲁五月天 | 欧美三级三级三级| 日韩视频一区二区在线观看| 欧美一级黄色片| 久久久精品综合| 亚洲人成电影网站色mp4| 亚洲h精品动漫在线观看| 九九久久精品视频 | 亚洲精品欧美专区| 日韩精品国产欧美| 成人av网站在线| 欧美老肥妇做.爰bbww| 久久先锋资源网| 亚洲欧美一区二区三区久本道91| 婷婷一区二区三区| 成人av免费在线播放| 6080国产精品一区二区| 久久精品日产第一区二区三区高清版 | 在线观看中文字幕不卡| 日韩美女在线视频| 一区二区三区四区视频精品免费| 日本不卡123| 99精品欧美一区二区蜜桃免费| 91麻豆精品国产91| 亚洲日本在线天堂| 国产精品一区二区不卡| 717成人午夜免费福利电影| 亚洲国产精华液网站w| 日韩影视精彩在线| 91色|porny| 国产日产亚洲精品系列| 五月婷婷另类国产| 色综合一个色综合| 国产精品日韩成人| 国产制服丝袜一区| 日韩一二三区视频| 亚洲成人久久影院| 在线视频你懂得一区二区三区| 久久久久久久电影| 精品一区二区三区在线观看 | 国产在线乱码一区二区三区| 欧美性极品少妇| 亚洲日本在线a| 成人免费黄色大片| 国产亚洲欧美激情| 韩国成人精品a∨在线观看| 日韩一区二区三区av| 亚洲国产精品久久人人爱| 色综合网站在线| 亚洲欧美日韩国产综合| 97精品视频在线观看自产线路二 | 波多野结衣中文字幕一区二区三区| 日韩午夜激情免费电影| 热久久国产精品| 欧美一区二区视频免费观看| 视频一区二区三区在线| 欧美日韩不卡视频| 日本欧美加勒比视频| 欧美精品日韩一区| 男人的天堂亚洲一区| 欧美一级淫片007| 美女在线一区二区| 精品国产免费视频| 国产东北露脸精品视频| 国产区在线观看成人精品| 国产经典欧美精品| 中文字幕人成不卡一区| 日本电影亚洲天堂一区| 亚洲自拍偷拍九九九| 欧美日韩亚洲国产综合| 日本美女视频一区二区| 日韩欧美国产精品| 成人一区二区三区视频| 亚洲精品v日韩精品| 欧美三级资源在线| 精品在线播放免费| 国产精品美日韩| 精品视频999| 久久不见久久见免费视频1| 久久久久免费观看| 色偷偷一区二区三区| 偷拍自拍另类欧美| 国产日韩欧美激情| 在线观看免费成人| 蜜臀久久99精品久久久画质超高清| 久久综合五月天婷婷伊人| 99国产一区二区三精品乱码| 亚洲福利电影网| 久久这里只有精品首页| 色香色香欲天天天影视综合网| 日韩成人一区二区三区在线观看| 日韩欧美电影在线| 91在线观看下载| 美国三级日本三级久久99| 中文字幕一区二区不卡| 日韩欧美国产精品一区| 91福利视频网站| 国产不卡免费视频| 丝袜美腿成人在线| 中文字幕字幕中文在线中不卡视频| 91麻豆精品国产91久久久资源速度| 国产宾馆实践打屁股91| 日韩中文欧美在线| 一区二区三区在线不卡| 国产欧美一区二区精品婷婷| 7777精品久久久大香线蕉| 色综合久久中文字幕| 国产精一品亚洲二区在线视频| 亚洲一区在线播放| 国产精品动漫网站| 久久综合久久99| 欧美一区二区三区免费观看视频| 成人av集中营| 国产成人免费视频网站| 另类成人小视频在线| 五月综合激情日本mⅴ| 亚洲精选视频在线| 中文字幕欧美国产| 久久网站热最新地址| 日韩欧美一级在线播放| 欧美麻豆精品久久久久久| 一本大道av一区二区在线播放| 国产精品一区二区视频| 蜜臀av一区二区| 日韩精品亚洲专区| 婷婷成人综合网| 亚洲午夜精品网| 一区二区三区中文字幕| 亚洲欧美一区二区不卡| 成人免费在线视频| 亚洲视频一区二区在线| 亚洲欧美日本在线| 亚洲视频一区二区免费在线观看| 中文字幕不卡在线播放| 国产欧美日韩综合精品一区二区| 久久这里只有精品视频网| 久久影院午夜论| 久久精品夜色噜噜亚洲a∨| 久久精品人人做人人综合| 国产农村妇女毛片精品久久麻豆| 久久亚洲综合色一区二区三区| 欧美精品一区视频| 久久一区二区三区四区| 久久久久久亚洲综合| 欧美—级在线免费片| 成人欧美一区二区三区1314 | 欧美xxxxx牲另类人与| 欧美xxxxx裸体时装秀| 久久伊人中文字幕| 国产精品久久毛片av大全日韩| 国产精品久久毛片a| 一区二区三区四区av| 人人精品人人爱| 国产伦精一区二区三区| 99视频一区二区三区| 欧美日韩美女一区二区| 日韩欧美国产不卡| 国产精品网曝门| 亚洲国产综合色| 国产乱码字幕精品高清av| 99精品久久只有精品| 欧美一区三区四区| 欧美国产综合一区二区| 亚洲成人在线观看视频| 国内外成人在线| 一本到不卡精品视频在线观看| 88在线观看91蜜桃国自产| 国产日韩欧美精品综合| 亚洲国产日韩a在线播放性色| 精品一区二区三区免费播放| 99久久国产综合精品色伊| 91精品欧美久久久久久动漫| 国产日韩视频一区二区三区| 一区二区三区不卡在线观看 | 国产精品系列在线| 午夜伊人狠狠久久| 国产成人av影院| 日韩视频永久免费| 亚洲精品成人悠悠色影视| 国产在线精品一区二区| 欧美色大人视频| 1000精品久久久久久久久| 久久99国产精品成人| 欧美精三区欧美精三区| 国产精品人人做人人爽人人添| 石原莉奈在线亚洲三区|