资源简介
SHA-256算法的C++实现及demo
代码片段和文件信息
#include “sha256.h“
/// same as reset()
SHA256::SHA256()
{
reset();
}
/// restart
void SHA256::reset()
{
m_numBytes = 0;
m_bufferSize = 0;
// according to RFC 1321
m_hash[0] = 0x6a09e667;
m_hash[1] = 0xbb67ae85;
m_hash[2] = 0x3c6ef372;
m_hash[3] = 0xa54ff53a;
m_hash[4] = 0x510e527f;
m_hash[5] = 0x9b05688c;
m_hash[6] = 0x1f83d9ab;
m_hash[7] = 0x5be0cd19;
}
namespace
{
inline uint32_t rotate(uint32_t a uint32_t c)
{
return (a >> c) | (a << (32 - c));
}
inline uint32_t swap(uint32_t x)
{
return _byteswap_ulong(x);
}
// mix functions for processBlock()
inline uint32_t f1(uint32_t e uint32_t f uint32_t g)
{
uint32_t term1 = rotate(e 6) ^ rotate(e 11) ^ rotate(e 25);
uint32_t term2 = (e & f) ^ (~e & g); //(g ^ (e & (f ^ g)))
return term1 + term2;
}
inline uint32_t f2(uint32_t a uint32_t b uint32_t c)
{
uint32_t term1 = rotate(a 2) ^ rotate(a 13) ^ rotate(a 22);
uint32_t term2 = ((a | b) & c) | (a & b); //(a & (b ^ c)) ^ (b & c);
return term1 + term2;
}
}
/// process 64 bytes
void SHA256::processBlock(const void* data)
{
// get last hash
uint32_t a = m_hash[0];
uint32_t b = m_hash[1];
uint32_t c = m_hash[2];
uint32_t d = m_hash[3];
uint32_t e = m_hash[4];
uint32_t f = m_hash[5];
uint32_t g = m_hash[6];
uint32_t h = m_hash[7];
// data represented as 16x 32-bit words
const uint32_t* input = (uint32_t*) data;
// convert to big endian
uint32_t words[64];
int i;
for (i = 0; i < 16; i++)
#if defined(__BYTE_ORDER) && (__BYTE_ORDER != 0) && (__BYTE_ORDER == __BIG_ENDIAN)
words[i] = input[i];
#else
words[i] = swap(input[i]);
#endif
uint32_t xy; // temporaries
// first round
x = h + f1(efg) + 0x428a2f98 + words[ 0]; y = f2(abc); d += x; h = x + y;
x = g + f1(def) + 0x71374491 + words[ 1]; y = f2(hab); c += x; g = x + y;
x = f + f1(cde) + 0xb5c0fbcf + words[ 2]; y = f2(gha); b += x; f = x + y;
x = e + f1(bcd) + 0xe9b5dba5 + words[ 3]; y = f2(fgh); a += x; e = x + y;
x = d + f1(abc) + 0x3956c25b + words[ 4]; y = f2(efg); h += x; d = x + y;
x = c + f1(hab) + 0x59f111f1 + words[ 5]; y = f2(def); g += x; c = x + y;
x = b + f1(gha) + 0x923f82a4 + words[ 6]; y = f2(cde); f += x; b = x + y;
x = a + f1(fgh) + 0xab1c5ed5 + words[ 7]; y = f2(bcd); e += x; a = x + y;
// secound round
x = h + f1(efg) + 0xd807aa98 + words[ 8]; y = f2(abc); d += x; h = x + y;
x = g + f1(def) + 0x12835b01 + words[ 9]; y = f2(hab); c += x; g = x + y;
x = f + f1(cde) + 0x243185be + words[10]; y = f2(gha); b += x; f = x + y;
x = e + f1(bcd) + 0x550c7dc3 + words[11]; y = f2(fgh); a += x; e = x + y;
x = d + f1(abc) + 0x72be5d74 + words[12]; y = f2(efg); h += x; d = x + y;
x = c + f1(hab) + 0x80deb1fe + words[13]; y = f2(def); g += x; c = x + y;
x = b + f1(gha) + 0x9bdc06a7 + words[14]; y = f2(cde); f += x; b = x + y;
x = a + f1(fgh) + 0xc19bf174 + words[15
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-05-31 14:54 testsha256\
目录 0 2016-05-31 14:35 testsha256\Debug\
文件 85504 2016-05-31 14:53 testsha256\Debug\testsha256.exe
文件 578048 2016-05-31 14:53 testsha256\Debug\testsha256.ilk
文件 1126400 2016-05-31 14:53 testsha256\Debug\testsha256.pdb
目录 0 2016-05-31 14:53 testsha256\testsha256\
目录 0 2016-05-31 14:53 testsha256\testsha256\Debug\
文件 174855 2016-05-31 14:52 testsha256\testsha256\Debug\sha256.obj
文件 11147 2016-05-31 14:35 testsha256\testsha256\Debug\stdafx.obj
文件 1445 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.log
文件 159772 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.obj
文件 2162688 2016-05-31 14:35 testsha256\testsha256\Debug\testsha256.pch
目录 0 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\
文件 27858 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\CL.read.1.tlog
文件 1980 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\CL.write.1.tlog
文件 1940 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\cl.command.1.tlog
文件 1442 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\li
文件 3044 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\li
文件 674 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\li
文件 163 2016-05-31 14:53 testsha256\testsha256\Debug\testsha256.tlog\testsha256.lastbuildstate
文件 371712 2016-05-31 14:53 testsha256\testsha256\Debug\vc120.idb
文件 430080 2016-05-31 14:53 testsha256\testsha256\Debug\vc120.pdb
文件 1531 2016-05-31 14:26 testsha256\testsha256\ReadMe.txt
文件 13115 2016-05-31 14:51 testsha256\testsha256\sha256.cpp
文件 1247 2016-05-31 14:50 testsha256\testsha256\sha256.h
文件 216 2016-05-31 14:26 testsha256\testsha256\stdafx.cpp
文件 234 2016-05-31 14:26 testsha256\testsha256\stdafx.h
文件 236 2016-05-31 14:26 testsha256\testsha256\targetver.h
文件 346 2016-05-31 14:53 testsha256\testsha256\testsha256.cpp
文件 4631 2016-05-31 14:35 testsha256\testsha256\testsha256.vcxproj
文件 1495 2016-05-31 14:34 testsha256\testsha256\testsha256.vcxproj.filters
............此处省略3个文件信息
相关资源
- ue4蓝图c++动态改变staticmeshactor材质动
- matlab2013a/b vs2013支持
- MATLAB数字图像处理:从仿真到C C++代码
- C++基础入门.md
- 猜动物游戏.zip
- 学生管理系统c++
- 基于C++的JPEG图片信息隐藏及提取
- C++继承,剪刀石头布
- 运输问题c语言代码
- 校园失物招领管理系统.rar
- 卡尔曼滤波算法航迹预测.rar
- C++Builder6.0破解版安装包
- 简单文本编辑器C++
- 图灵机用作转换器计算x的y次幂,含
- C++实现的高斯投影正算和反算
- C++用类读取和处理TXT文件数据
- C++实现7.4汉明码编码
- C++实现DNS劫持
- 页面置换算法OPT、FIFO、LRU实现--C++版
- 面向对象程序设计风格的五子棋程序
- C++期末复习 程序填空题 1
- c++ 计算器 能实现带括号的小数计算
- C++课程设计——停车场管理
- linux C与C++混合编程通用makefile
- C++教程完整
- matlab的smooth()函数c++实现
- C++入门经典(第9版) ([美]Walter Sa
- 扫雷小游戏,c++版本
- 利用指针数组冒泡法排序
- dijkstra算法C++实现
评论
共有 条评论