资源简介
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注入
相关资源
- CCS FFT c语言算法
- 小波变换算法 c语言版
- 3des加密算法C语言实现
- DES加密算法C语言实现
- 线性回归算法c语言实现
- 基于C语言的模拟退火算法
- C语言实现的DES对称加密算法
- 用VC6.0实现多边形扫描线填充算法
- c语言编写的货郎担算法
- Em算法(使用C++编写)
- STM32烧写算法flash包
- 永磁同步电机的FOC控制算法
- Proteus仿真:PID算法输出.rar
- 一个模糊PID温度控制算法源代码
- 经典滤波算法
- KMP算法C语言程序
- SVM算法实现(源码+文档)
- 算法A律U律实现
- 人工蜂群算法.docx
- C++ SHA256加密计算
- BlowFish加密算法
- C语言常用算法源代码
- c++数组快排算法
- 算法表达式求值.cpp
- PID算法.c
- QR二维码C++源码 算法实现
- 基于opencv漫水填充算法综合
- 信息学奥赛一本通——算法部分
- 银行家算法分配资源的模拟实现(m
- C语言程序设计50例.docx
评论
共有 条评论