资源简介
sha256实现
依次执行
SHA256Init、
SHA256Update
SHA256Final
三个函数即可得到sha256结果
代码片段和文件信息
/*-
* Copyright (c) 2001-2003 Allan Saddi
* All rights reserved.
*
* Redistribution and use in source and binary forms with or without
* modification are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY ALLAN SADDI AND HIS CONTRIBUTORS ‘‘AS IS‘‘
* AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL ALLAN SADDI OR HIS CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR
* CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE DATA OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN
* CONTRACT STRICT LIABILITY OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id: sha256.c 680 2003-07-25 21:57:49Z asaddi $
*/
/*
* Define WORDS_BIGENDIAN if compiling on a big-endian architecture.
*
* Define SHA256_TEST to test the implementation using the NIST‘s
* sample messages. The output should be:
*
* ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
* 248d6a61 d20638b8 e5c02693 0c3e6039 a33ce459 64ff2167 f6ecedd4 19db06c1
* cdc76e5c 9914fb92 81a1c7e2 84d73e67 f1809a48 a497200e 046d39cc c7112cd0
*/
#include
#include “newsha256.h“
#ifndef lint
static const char rcsid[] =
“$Id: sha256.c 680 2003-07-25 21:57:49Z asaddi $“;
#endif /* !lint */
#define ROTL(x n) (((x) << (n)) | ((x) >> (32 - (n))))
#define ROTR(x n) (((x) >> (n)) | ((x) << (32 - (n))))
#define Ch(x y z) ((z) ^ ((x) & ((y) ^ (z))))
#define Maj(x y z) (((x) & ((y) | (z))) | ((y) & (z)))
#define SIGMA0(x) (ROTR((x) 2) ^ ROTR((x) 13) ^ ROTR((x) 22))
#define SIGMA1(x) (ROTR((x) 6) ^ ROTR((x) 11) ^ ROTR((x) 25))
#define sigma0(x) (ROTR((x) 7) ^ ROTR((x) 18) ^ ((x) >> 3))
#define sigma1(x) (ROTR((x) 17) ^ ROTR((x) 19) ^ ((x) >> 10))
#define DO_ROUND() { \
t1 = h + SIGMA1(e) + Ch(e f g) + *(Kp++) + *(W++); \
t2 = SIGMA0(a) + Maj(a b c); \
h = g; \
g = f; \
f = e; \
e = d + t1; \
d = c; \
c = b; \
b = a; \
a = t1 + t2; \
}
static const uint32_t K[64] = {
0x428a2f98L 0x71374491L 0xb5c0fbcfL 0xe9b5dba5L
0x3956c25bL 0x59f111f1L 0x923f82a4L 0xab1c5ed5L
0xd807aa98L 0x12835b01L 0x243185beL 0x550c7dc3L
0x72be5d74L 0x80deb1feL 0x9bdc06a7L 0xc19bf174L
0xe49b69c1L 0xefbe4786L 0x0fc19dc6L
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 12353 2009-12-10 17:16 newsha256.c
文件 2342 2009-12-10 17:15 newsha256.h
----------- --------- ---------- ----- ----
14695 2
- 上一篇:数据结构二叉树实验报告源代码及运行文件
- 下一篇:自动模拟键盘对指定窗口按键
评论
共有 条评论