資源簡介
sha256加密簽名算法

代碼片段和文件信息
/*********************************************************************
*?Filename:???sha256.c
*?Author:?????Brad?Conte?(brad?AT?bradconte.com)
*?Copyright:
*?Disclaimer:?This?code?is?presented?“as?is“?without?any?guarantees.
*?Details:????Implementation?of?the?SHA-256?hashing?algorithm.
??????????????SHA-256?is?one?of?the?three?algorithms?in?the?SHA2
??????????????specification.?The?others?SHA-384?and?SHA-512?are?not
??????????????offered?in?this?implementation.
??????????????Algorithm?specification?can?be?found?here:
???????????????*?http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf
??????????????This?implementation?uses?little?endian?byte?order.
*********************************************************************/
/***************************?HEADER?FILES?***************************/
#include?
#include?
//#include?
#include?“sha256_2.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?***********************/
static?void?sha256_transform(SHA256_CTX?*ctx?const?BYTE?data[])
{
WORD?a?b?c?d?e?f?g?h?i?j?t1?t2?m[64];
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(efg)?+?k[i]?+?m[i];
t2?=?EP0
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5664??2017-07-28?16:50??sha256_2.c
?????文件???????1155??2017-07-28?16:55??sha256_2.h
-----------?---------??----------?-----??----
?????????????????6819????????????????????2
- 上一篇:CAD:excel 批量畫矩形
- 下一篇:基于小波變換模極大值的信號奇異性檢測
評論
共有 條評論