?? sha256.h
字號(hào):
/* Copyright 2005-2006, Voltage Security, all rights reserved.
*/
#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#ifndef _SHA_256_H
#define _SHA_256_H
#ifdef __cplusplus
extern "C" {
#endif
/* The bulk of SHA-256 is done by a Transform function. This may be a
* separate function, some implementation may "inline" it.
*
* @param ctx The SHA256 context.
* @param block The block of data to use in updating the state.
* @return none
*/
typedef void VOLT_CALLING_CONV (*VSHA256Transform) VOLT_PROTO_LIST ((
Pointer ctx,
unsigned char *block
));
/* This is the standard SHA-256 context.
*/
typedef struct
{
UInt32 initState[8];
UInt32 state[8];
UInt32 W[64];
UInt32 K[64];
UInt32 countLow;
UInt32 countHigh;
unsigned char currentBlock[64];
unsigned int currentBlockLen;
VSHA256Transform SHA256Transform;
} VoltSHA256Ctx;
/* Implements VDigestInit.
*/
int VOLT_CALLING_CONV SHA256Init VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj
));
/* Implements VDigestUpdate.
*/
int VOLT_CALLING_CONV SHA256Update VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
unsigned char *dataToDigest,
unsigned int dataToDigestLen
));
/* Implements VDigestFinal.
*/
int VOLT_CALLING_CONV SHA256Final VOLT_PROTO_LIST ((
VoltAlgorithmObject *obj,
unsigned char *digest
));
/* Implements VSHA256Transform.
*/
void VOLT_CALLING_CONV SHA256Transform VOLT_PROTO_LIST ((
Pointer ctx,
unsigned char *block
));
/* Implements VCtxDestroy.
*/
void VOLT_CALLING_CONV SHA256ClassCtxDestroy VOLT_PROTO_LIST ((
Pointer obj,
Pointer ctx
));
#if VOLT_ENDIAN == VOLT_BIG_ENDIAN
#define SHA256_GET_UINT32(_buf,_value)\
VOLT_GET_BIG_ENDIAN_UINT32(_buf,_value)
#else
#define SHA256_GET_UINT32(_buf,_value)\
VOLT_GET_LITTLE_ENDIAN_UINT32(_buf,_value)
#endif
/* Rotate a 32-bit value right by count.
*/
#define SHA256_ROTR(_value,_count) VOLT_UINT32_ROTR(_value,_count)
/* Shift a 32-bit value right by count.
*/
#define SHA256_SHIFTR(_value,_count) _value >> _count
#define SHA256_INIT_H0 0x6a09e667
#define SHA256_INIT_H1 0xbb67ae85
#define SHA256_INIT_H2 0x3c6ef372
#define SHA256_INIT_H3 0xa54ff53a
#define SHA256_INIT_H4 0x510e527f
#define SHA256_INIT_H5 0x9b05688c
#define SHA256_INIT_H6 0x1f83d9ab
#define SHA256_INIT_H7 0x5be0cd19
/* SHA-256 constants.
*/
#define SHA256_K0 0x428a2f98
#define SHA256_K1 0x71374491
#define SHA256_K2 0xb5c0fbcf
#define SHA256_K3 0xe9b5dba5
#define SHA256_K4 0x3956c25b
#define SHA256_K5 0x59f111f1
#define SHA256_K6 0x923f82a4
#define SHA256_K7 0xab1c5ed5
#define SHA256_K8 0xd807aa98
#define SHA256_K9 0x12835b01
#define SHA256_K10 0x243185be
#define SHA256_K11 0x550c7dc3
#define SHA256_K12 0x72be5d74
#define SHA256_K13 0x80deb1fe
#define SHA256_K14 0x9bdc06a7
#define SHA256_K15 0xc19bf174
#define SHA256_K16 0xe49b69c1
#define SHA256_K17 0xefbe4786
#define SHA256_K18 0x0fc19dc6
#define SHA256_K19 0x240ca1cc
#define SHA256_K20 0x2de92c6f
#define SHA256_K21 0x4a7484aa
#define SHA256_K22 0x5cb0a9dc
#define SHA256_K23 0x76f988da
#define SHA256_K24 0x983e5152
#define SHA256_K25 0xa831c66d
#define SHA256_K26 0xb00327c8
#define SHA256_K27 0xbf597fc7
#define SHA256_K28 0xc6e00bf3
#define SHA256_K29 0xd5a79147
#define SHA256_K30 0x06ca6351
#define SHA256_K31 0x14292967
#define SHA256_K32 0x27b70a85
#define SHA256_K33 0x2e1b2138
#define SHA256_K34 0x4d2c6dfc
#define SHA256_K35 0x53380d13
#define SHA256_K36 0x650a7354
#define SHA256_K37 0x766a0abb
#define SHA256_K38 0x81c2c92e
#define SHA256_K39 0x92722c85
#define SHA256_K40 0xa2bfe8a1
#define SHA256_K41 0xa81a664b
#define SHA256_K42 0xc24b8b70
#define SHA256_K43 0xc76c51a3
#define SHA256_K44 0xd192e819
#define SHA256_K45 0xd6990624
#define SHA256_K46 0xf40e3585
#define SHA256_K47 0x106aa070
#define SHA256_K48 0x19a4c116
#define SHA256_K49 0x1e376c08
#define SHA256_K50 0x2748774c
#define SHA256_K51 0x34b0bcb5
#define SHA256_K52 0x391c0cb3
#define SHA256_K53 0x4ed8aa4a
#define SHA256_K54 0x5b9cca4f
#define SHA256_K55 0x682e6ff3
#define SHA256_K56 0x748f82ee
#define SHA256_K57 0x78a5636f
#define SHA256_K58 0x84c87814
#define SHA256_K59 0x8cc70208
#define SHA256_K60 0x90befffa
#define SHA256_K61 0xa4506ceb
#define SHA256_K62 0xbef9a3f7
#define SHA256_K63 0xc67178f2
#define SHA256_K_ARRAY_COUNT 64
#define SHA256_K_ARRAY \
{ \
SHA256_K0, SHA256_K1, SHA256_K2, SHA256_K3, \
SHA256_K4, SHA256_K5, SHA256_K6, SHA256_K7, \
SHA256_K8, SHA256_K9, SHA256_K10, SHA256_K11, \
SHA256_K12, SHA256_K13, SHA256_K14, SHA256_K15, \
SHA256_K16, SHA256_K17, SHA256_K18, SHA256_K19, \
SHA256_K20, SHA256_K21, SHA256_K22, SHA256_K23, \
SHA256_K24, SHA256_K25, SHA256_K26, SHA256_K27, \
SHA256_K28, SHA256_K29, SHA256_K30, SHA256_K31, \
SHA256_K32, SHA256_K33, SHA256_K34, SHA256_K35, \
SHA256_K36, SHA256_K37, SHA256_K38, SHA256_K39, \
SHA256_K40, SHA256_K41, SHA256_K42, SHA256_K43, \
SHA256_K44, SHA256_K45, SHA256_K46, SHA256_K47, \
SHA256_K48, SHA256_K49, SHA256_K50, SHA256_K51, \
SHA256_K52, SHA256_K53, SHA256_K54, SHA256_K55, \
SHA256_K56, SHA256_K57, SHA256_K58, SHA256_K59, \
SHA256_K60, SHA256_K61, SHA256_K62, SHA256_K63 \
}
/* Internal SHA-256 functions.
*/
#define SHA256_CAP_SIGMA_0(_x) \
((SHA256_ROTR (_x, 2)) ^ (SHA256_ROTR (_x, 13)) ^ (SHA256_ROTR (_x, 22)))
#define SHA256_CAP_SIGMA_1(_x) \
((SHA256_ROTR (_x, 6)) ^ (SHA256_ROTR (_x, 11)) ^ (SHA256_ROTR (_x, 25)))
#define SHA256_SIGMA_0(_x) \
((SHA256_ROTR (_x, 7)) ^ (SHA256_ROTR (_x, 18)) ^ (SHA256_SHIFTR (_x, 3)))
#define SHA256_SIGMA_1(_x) \
((SHA256_ROTR (_x, 17)) ^ (SHA256_ROTR (_x, 19)) ^ (SHA256_SHIFTR (_x, 10)))
#define SHA256_CH(_x,_y,_z) ((_x & _y) ^ (~_x & _z))
#define SHA256_MAJ(_x,_y,_z) ((_x & _y) ^ (_x & _z) ^ (_y & _z))
#ifdef __cplusplus
}
#endif
#endif /* _SHA_256_H */
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -