资源简介
C++ SHA256加密计算
代码片段和文件信息
/*********************************************************************
* Filename: sha256.c
* Original Author: Brad Conte (brad AT bradconte.com)
* Labeled and modified by: AnSheng(https://github.com/monkeyDemon)
* Copyright:
* Disclaimer: This code is presented “as is“ without any guarantees.
* Details: Performs known-answer tests on the corresponding SHA1
implementation. These tests do not encompass the full
range of available test vectors however if the tests
pass it is very very likely that the code is correct
and was compiled properly. This code also serves as
example usage of the functions.
*********************************************************************/
/*************************** HEADER FILES ***************************/
#include
#include
#include “sha256.h“
/****************************** MACROS ******************************/
#define ROTLEFT(ab) (((a) << (b)) | ((a) >> (32-(b))))
#define ROTRIGHT(ab) (((a) >> (b)) | ((a) << (32-(b))))
#define CH(xyz) (((x) & (y)) ^ (~(x) & (z)))
#define MAJ(xyz) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define EP0(x) (ROTRIGHT(x2) ^ ROTRIGHT(x13) ^ ROTRIGHT(x22))
#define EP1(x) (ROTRIGHT(x6) ^ ROTRIGHT(x11) ^ ROTRIGHT(x25))
#define SIG0(x) (ROTRIGHT(x7) ^ ROTRIGHT(x18) ^ ((x) >> 3))
#define SIG1(x) (ROTRIGHT(x17) ^ ROTRIGHT(x19) ^ ((x) >> 10))
/**************************** VARIABLES *****************************/
static const WORD k[64] = {
0x428a2f980x713744910xb5c0fbcf0xe9b5dba50x3956c25b0x59f111f10x923f82a40xab1c5ed5
0xd807aa980x12835b010x243185be0x550c7dc30x72be5d740x80deb1fe0x9bdc06a70xc19bf174
0xe49b69c10xefbe47860x0fc19dc60x240ca1cc0x2de92c6f0x4a7484aa0x5cb0a9dc0x76f988da
0x983e51520xa831c66d0xb00327c80xbf597fc70xc6e00bf30xd5a791470x06ca63510x14292967
0x27b70a850x2e1b21380x4d2c6dfc0x53380d130x650a73540x766a0abb0x81c2c92e0x92722c85
0xa2bfe8a10xa81a664b0xc24b8b700xc76c51a30xd192e8190xd69906240xf40e35850x106aa070
0x19a4c1160x1e376c080x2748774c0x34b0bcb50x391c0cb30x4ed8aa4a0x5b9cca4f0x682e6ff3
0x748f82ee0x78a5636f0x84c878140x8cc702080x90befffa0xa4506ceb0xbef9a3f70xc67178f2
};
/*********************** FUNCTION DEFINITIONS ***********************/
void sha256_transform(SHA256_CTX* ctx const BYTE data[])
{
WORD a b c d e f g h i j t1 t2 m[64];
// initialization
for (i = 0 j = 0; i < 16; ++i j += 4)
m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]);
for (; i < 64; ++i)
m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16];
a = ctx->state[0];
b = ctx->state[1];
c = ctx->state[2];
d = ctx->state[3];
e = ctx->state[4];
f = ctx->state[5];
g = ctx->state[6];
h = ctx->state[7];
for (i = 0; i < 64; ++i)
{
t1 = h + EP1(e) + CH(e f g) + k[i] + m[i];
t2 = EP0(a) + MAJ(a b c);
h = g;
g = f;
f = e;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5477 2019-11-04 00:16 sha256.c
文件 1059 2019-11-04 00:16 sha256.h
相关资源
- Windows_API_函数大全 C/C++
- 思维导图(C++ Primer Plus(第六版).
- 信息学奥赛c++第一阶课件.pptx
- c++ 注入exe
- 大话设计模式C++
- c++数组快排算法
- 吕鑫vc6c++数据结构视频源码
- 智商超高的中国象棋游戏源码(C++版
- c++爱心表白(心.cpp)
- CC++词典手册.chm
- 家谱管理系统(C++)源码以及文档
- 派克变换VC++源码(附文档)
- 《一个月挑战C++》.chm
- c++ 文件操作(读取、写入)
- Effective Modern C++ 中文
- c++ 刷屏软件代码
- Beginning C++17 5th Edition.pdf56911
- c++2020年标准
- 04737C++ 程序设计精华.docx
- QR二维码C++源码 算法实现
- C++_Primer_4th_习题答案
- C++ Primer by Stanley B. Lippman Josée La
- C++程序设计精讲
- Effective C++(中文版).azw3
- 期货交易的C++简易demo
- c++知识点总结.doc
- visual c++高级编程及其项目应用开发源
-
c++ 用户登录(基于xm
l) - C++餐饮管理系统源码(控制台)
- C++通讯录管理系统源码(控制台)
评论
共有 条评论