资源简介
SHA常用算法实现(SHA-1, SHA256, SHA384, SHA512),使用C语言,包含4个相对独立的算法,并有demo调用示例。
代码片段和文件信息
/*-
* 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: sha.c 351 2003-02-23 23:24:40Z asaddi $
*/
#ifdef HAVE_CONFIG_H
#include
#endif /* HAVE_CONFIG_H */
#if HAVE_INTTYPES_H
# include
#else
# if HAVE_STDINT_H
# include
# endif
#endif
#include
#include
#include
#include
#if HAVE_UNISTD_H
#include
#endif /* HAVE_UNISTD_H */
#include “sha1.h“
#include “sha256.h“
#include “sha384.h“
#include “sha512.h“
#include “version.h“
#ifndef lint
static const char rcsid[] =
“$Id: sha.c 351 2003-02-23 23:24:40Z asaddi $“;
#endif /* !lint */
static char *prog;
#define SHA_BUFFER_SIZE 65536
static uint8_t *buffer;
static int
shaFile (char *name FILE *f int which)
{
union {
SHA1Context sha1;
SHA256Context sha256;
SHA384Context sha384;
SHA512Context sha512;
} s;
size_t len;
uint8_t hash[SHA512_HASH_SIZE];
int hashLen i;
int success = 1;
switch (which) {
case 1:
SHA1Init (&s.sha1);
break;
case 2:
SHA256Init (&s.sha256);
break;
case 3:
SHA384Init (&s.sha384);
break;
case 5:
SHA512Init (&s.sha512);
break;
default:
abort ();
}
while ((len = fread (buffer 1 SHA_BUFFER_SIZE f)) > 0) {
switch (which) {
case 1:
SHA1Update (&s.sha1 buffer len);
break;
case 2:
SHA256Update (&s.sha256 buffer len);
break;
case 3:
SHA384Update (&s.sha384 buffer len);
break;
case 5:
SHA512Update (&s.sha512 buffer len);
break;
default:
abort ();
}
}
if (ferror (f)) {
#if HAVE_STRERROR
fprintf (stderr “
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6283 2003-02-25 05:23 SHA\sha.c
文件 14989 2003-07-26 05:57 SHA\sha1.c
文件 2209 2003-02-24 06:30 SHA\sha1.h
文件 12585 2017-11-06 13:20 SHA\sha256.c
文件 2244 2003-02-24 06:30 SHA\sha256.h
文件 13015 2003-07-26 05:57 SHA\sha384.c
文件 2252 2003-02-24 06:30 SHA\sha384.h
文件 13066 2003-07-26 05:58 SHA\sha512.c
文件 2248 2003-02-24 06:30 SHA\sha512.h
文件 9824 2017-11-06 11:49 SHA\shatest.c
文件 143 2003-07-26 06:00 SHA\version.h
目录 0 2017-11-06 13:27 SHA
----------- --------- ---------- ----- ----
78858 12
- 上一篇:数字信号处理C语言算法实现
- 下一篇:以调试方式进行Dll注入
相关资源
- 数字信号处理C语言算法实现
- 张乃孝数据结构与算法全集
- C/C++常用算法手册带详细书签目录
- 粒子群算法c++代码.rar
- QT C++ 算法 广搜BFS 最小步数解二阶魔
- 数据结构与算法学习辅导及习题详解
- 蚁群算法C++ vs2013
- algorithms in C++
- ICP算法实现C++
- 用C语言实现的基于adaboost算法的人脸
- NSGA II代码实现集合包含、讲解及 网络
- 道格拉斯算法C++实现233745
- bm3d图像去噪算法C++代码
- 3D三角形网格模型补洞源代码
- 基于边缘梯度的模板匹配算法
- psins导航算法源码C语言、matlab
- OpenSSLx86 & x64开发库
- aes加密算法源码
- 地图投影算法
- 数据结构与算法分析(C++语言描述)
- 计算机图形学MFC-双缓冲二维图形几何
- 算法:C语言实现(第5部分)图算法
- 编译原理之算符优先算法-迭代法
- 算法精解 C语言描述 pdf
- 严蔚敏《数据结构(C语言版)超级全
- 算法实现题3-1独立任务调度问题答案
- 数据结构与算法分析:C语言描述_原书
- 数据结构与算法分析:C语言描述_原书
- 数据结构与算法分析C++描述Larrynyhof
- 遗传算法c++代码.rar
评论
共有 条评论