⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tiger.c

📁 该压缩包中包括 tom的加密函数库及pdf说明 ,以及Rinick s ECC:椭圆曲线非对称加密密钥生成器
💻 C
📖 第 1 页 / 共 4 页
字号:
#elsestatic int  tiger_compress(hash_state *md, unsigned char *buf)#endif{    ulong64 a, b, c, x[8];    unsigned long i;    /* load words */    for (i = 0; i < 8; i++) {        LOAD64L(x[i],&buf[8*i]);    }    a = md->tiger.state[0];    b = md->tiger.state[1];    c = md->tiger.state[2];    pass(&a,&b,&c,x,5);    key_schedule(x);    pass(&c,&a,&b,x,7);    key_schedule(x);    pass(&b,&c,&a,x,9);    /* store state */    md->tiger.state[0] = a ^ md->tiger.state[0];    md->tiger.state[1] = b - md->tiger.state[1];    md->tiger.state[2] = c + md->tiger.state[2];    return CRYPT_OK;}#ifdef LTC_CLEAN_STACKstatic int tiger_compress(hash_state *md, unsigned char *buf){   int err;   err = _tiger_compress(md, buf);   burn_stack(sizeof(ulong64) * 11 + sizeof(unsigned long));   return err;}#endif/**   Initialize the hash state   @param md   The hash state you wish to initialize   @return CRYPT_OK if successful*/int tiger_init(hash_state *md){    LTC_ARGCHK(md != NULL);    md->tiger.state[0] = CONST64(0x0123456789ABCDEF);    md->tiger.state[1] = CONST64(0xFEDCBA9876543210);    md->tiger.state[2] = CONST64(0xF096A5B4C3B2E187);    md->tiger.curlen = 0;    md->tiger.length = 0;    return CRYPT_OK;}/**   Process a block of memory though the hash   @param md     The hash state   @param in     The data to hash   @param inlen  The length of the data (octets)   @return CRYPT_OK if successful*/HASH_PROCESS(tiger_process, tiger_compress, tiger, 64)/**   Terminate the hash to get the digest   @param md  The hash state   @param out [out] The destination of the hash (24 bytes)   @return CRYPT_OK if successful*/int tiger_done(hash_state * md, unsigned char *out){    LTC_ARGCHK(md  != NULL);    LTC_ARGCHK(out != NULL);    if (md->tiger.curlen >= sizeof(md->tiger.buf)) {       return CRYPT_INVALID_ARG;    }    /* increase the length of the message */    md->tiger.length += md->tiger.curlen * 8;    /* append the '1' bit */    md->tiger.buf[md->tiger.curlen++] = (unsigned char)0x01;    /* if the length is currently above 56 bytes we append zeros     * then compress.  Then we can fall back to padding zeros and length     * encoding like normal. */    if (md->tiger.curlen > 56) {        while (md->tiger.curlen < 64) {            md->tiger.buf[md->tiger.curlen++] = (unsigned char)0;        }        tiger_compress(md, md->tiger.buf);        md->tiger.curlen = 0;    }    /* pad upto 56 bytes of zeroes */    while (md->tiger.curlen < 56) {        md->tiger.buf[md->tiger.curlen++] = (unsigned char)0;     }    /* store length */    STORE64L(md->tiger.length, md->tiger.buf+56);    tiger_compress(md, md->tiger.buf);    /* copy output */    STORE64L(md->tiger.state[0], &out[0]);    STORE64L(md->tiger.state[1], &out[8]);    STORE64L(md->tiger.state[2], &out[16]);#ifdef LTC_CLEAN_STACK    zeromem(md, sizeof(hash_state));#endif    return CRYPT_OK;}/**  Self-test the hash  @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled*/  int  tiger_test(void){ #ifndef LTC_TEST    return CRYPT_NOP; #else      static const struct {      char *msg;      unsigned char hash[24];  } tests[] = {    { "",     { 0x32, 0x93, 0xac, 0x63, 0x0c, 0x13, 0xf0, 0x24,       0x5f, 0x92, 0xbb, 0xb1, 0x76, 0x6e, 0x16, 0x16,       0x7a, 0x4e, 0x58, 0x49, 0x2d, 0xde, 0x73, 0xf3 }    },    { "abc",     { 0x2a, 0xab, 0x14, 0x84, 0xe8, 0xc1, 0x58, 0xf2,       0xbf, 0xb8, 0xc5, 0xff, 0x41, 0xb5, 0x7a, 0x52,       0x51, 0x29, 0x13, 0x1c, 0x95, 0x7b, 0x5f, 0x93 }    },    { "Tiger",     { 0xdd, 0x00, 0x23, 0x07, 0x99, 0xf5, 0x00, 0x9f,       0xec, 0x6d, 0xeb, 0xc8, 0x38, 0xbb, 0x6a, 0x27,       0xdf, 0x2b, 0x9d, 0x6f, 0x11, 0x0c, 0x79, 0x37 }    },    { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",     { 0xf7, 0x1c, 0x85, 0x83, 0x90, 0x2a, 0xfb, 0x87,       0x9e, 0xdf, 0xe6, 0x10, 0xf8, 0x2c, 0x0d, 0x47,       0x86, 0xa3, 0xa5, 0x34, 0x50, 0x44, 0x86, 0xb5 }    },    { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-",     { 0xc5, 0x40, 0x34, 0xe5, 0xb4, 0x3e, 0xb8, 0x00,       0x58, 0x48, 0xa7, 0xe0, 0xae, 0x6a, 0xac, 0x76,       0xe4, 0xff, 0x59, 0x0a, 0xe7, 0x15, 0xfd, 0x25 }    },  };  int i;  unsigned char tmp[24];  hash_state md;  for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {      tiger_init(&md);      tiger_process(&md, (unsigned char *)tests[i].msg, (unsigned long)strlen(tests[i].msg));      tiger_done(&md, tmp);      if (memcmp(tmp, tests[i].hash, 24) != 0) {          return CRYPT_FAIL_TESTVECTOR;      }  }  return CRYPT_OK;  #endif}#endif/*Hash of "":        24F0130C63AC9332 16166E76B1BB925F F373DE2D49584E7AHash of "abc":        F258C1E88414AB2A 527AB541FFC5B8BF 935F7B951C132951Hash of "Tiger":        9F00F599072300DD 276ABB38C8EB6DEC 37790C116F9D2BDFHash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-":        87FB2A9083851CF7 470D2CF810E6DF9E B586445034A5A386Hash of "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz+0123456789":        467DB80863EBCE48 8DF1CD1261655DE9 57896565975F9197Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham":        0C410A042968868A 1671DA5A3FD29A72 5EC1E457D3CDB303Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge.":        EBF591D5AFA655CE 7F22894FF87F54AC 89C811B6B0DA3193Hash of "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham, proceedings of Fast Software Encryption 3, Cambridge, 1996.":        3D9AEB03D1BD1A63 57B2774DFD6D5B24 DD68151D503974FCHash of "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-":        00B83EB4E53440C5 76AC6AAEE0A74858 25FD15E70A59FFE4*//* $Source: /cvs/libtom/libtomcrypt/src/hashes/tiger.c,v $ *//* $Revision: 1.5 $ *//* $Date: 2005/05/23 02:42:07 $ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -