⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sha512.h

📁 IBE是一种非对称密码技术
💻 H
字号:
/* Copyright 2005-2006, Voltage Security, all rights reserved.
 */

#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"

#ifndef _SHA_512_H
#define _SHA_512_H

#ifdef __cplusplus
extern "C" {
#endif

/* The bulk of SHA-512 is done by a Transform function. This may be a
 * separate function, some implementation may "inline" it.
 *
 * @param ctx The SHA512 context.
 * @param block The block of data to use in updating the state.
 * @return none
 */
typedef void VOLT_CALLING_CONV (*VSHA512Transform) VOLT_PROTO_LIST ((
   Pointer ctx,
   unsigned char *block
));

/* This is the standard SHA-512 context.
 */
typedef struct
{
  UInt64 initState[8];
  UInt64 state[8];
  UInt64 W[80];
  UInt64 K[80];
  UInt64 countLow;
  UInt64 countHigh;
  unsigned char currentBlock[128];
  unsigned int currentBlockLen;
  VSHA512Transform SHA512Transform;
} VoltSHA512Ctx;

/* Implements VDigestInit.
 */
int VOLT_CALLING_CONV SHA512Init VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj
));

/* Implements VDigestUpdate.
 */
int VOLT_CALLING_CONV SHA512Update VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   unsigned char *dataToDigest,
   unsigned int dataToDigestLen
));

/* Implements VDigestFinal.
 */
int VOLT_CALLING_CONV SHA512Final VOLT_PROTO_LIST ((
   VoltAlgorithmObject *obj,
   unsigned char *digest
));

/* Implements VSHA512Transform.
 */
void VOLT_CALLING_CONV SHA512Transform VOLT_PROTO_LIST ((
   Pointer ctx,
   unsigned char *block
));

/* Implements VCtxDestroy.
 */
void VOLT_CALLING_CONV SHA512ClassCtxDestroy VOLT_PROTO_LIST ((
   Pointer obj,
   Pointer ctx
));

#define SHA512_GET_UINT64 VOLT_GET_UINT64

/* Rotate a 64-bit value right by count.
 */
#define SHA512_ROTR(_value,_count) VOLT_UINT64_ROTR(_value,_count)
/* Shift a 64-bit value right by count.
 */
#define SHA512_SHIFTR(_value,_count) _value >> _count

#define SHA512_INIT_H0 0x6a09e667f3bcc908
#define SHA512_INIT_H1 0xbb67ae8584caa73b
#define SHA512_INIT_H2 0x3c6ef372fe94f82b
#define SHA512_INIT_H3 0xa54ff53a5f1d36f1
#define SHA512_INIT_H4 0x510e527fade682d1
#define SHA512_INIT_H5 0x9b05688c2b3e6c1f
#define SHA512_INIT_H6 0x1f83d9abfb41bd6b
#define SHA512_INIT_H7 0x5be0cd19137e2179

/* SHA-512 constants.
 */
#define SHA512_K0  0x428a2f98d728ae22
#define SHA512_K1  0x7137449123ef65cd
#define SHA512_K2  0xb5c0fbcfec4d3b2f
#define SHA512_K3  0xe9b5dba58189dbbc
#define SHA512_K4  0x3956c25bf348b538
#define SHA512_K5  0x59f111f1b605d019
#define SHA512_K6  0x923f82a4af194f9b
#define SHA512_K7  0xab1c5ed5da6d8118
#define SHA512_K8  0xd807aa98a3030242
#define SHA512_K9  0x12835b0145706fbe
#define SHA512_K10 0x243185be4ee4b28c
#define SHA512_K11 0x550c7dc3d5ffb4e2
#define SHA512_K12 0x72be5d74f27b896f
#define SHA512_K13 0x80deb1fe3b1696b1
#define SHA512_K14 0x9bdc06a725c71235
#define SHA512_K15 0xc19bf174cf692694
#define SHA512_K16 0xe49b69c19ef14ad2
#define SHA512_K17 0xefbe4786384f25e3
#define SHA512_K18 0x0fc19dc68b8cd5b5
#define SHA512_K19 0x240ca1cc77ac9c65
#define SHA512_K20 0x2de92c6f592b0275
#define SHA512_K21 0x4a7484aa6ea6e483
#define SHA512_K22 0x5cb0a9dcbd41fbd4
#define SHA512_K23 0x76f988da831153b5
#define SHA512_K24 0x983e5152ee66dfab
#define SHA512_K25 0xa831c66d2db43210
#define SHA512_K26 0xb00327c898fb213f
#define SHA512_K27 0xbf597fc7beef0ee4
#define SHA512_K28 0xc6e00bf33da88fc2
#define SHA512_K29 0xd5a79147930aa725
#define SHA512_K30 0x06ca6351e003826f
#define SHA512_K31 0x142929670a0e6e70
#define SHA512_K32 0x27b70a8546d22ffc
#define SHA512_K33 0x2e1b21385c26c926
#define SHA512_K34 0x4d2c6dfc5ac42aed
#define SHA512_K35 0x53380d139d95b3df
#define SHA512_K36 0x650a73548baf63de
#define SHA512_K37 0x766a0abb3c77b2a8
#define SHA512_K38 0x81c2c92e47edaee6
#define SHA512_K39 0x92722c851482353b
#define SHA512_K40 0xa2bfe8a14cf10364
#define SHA512_K41 0xa81a664bbc423001
#define SHA512_K42 0xc24b8b70d0f89791
#define SHA512_K43 0xc76c51a30654be30
#define SHA512_K44 0xd192e819d6ef5218
#define SHA512_K45 0xd69906245565a910
#define SHA512_K46 0xf40e35855771202a
#define SHA512_K47 0x106aa07032bbd1b8
#define SHA512_K48 0x19a4c116b8d2d0c8
#define SHA512_K49 0x1e376c085141ab53
#define SHA512_K50 0x2748774cdf8eeb99
#define SHA512_K51 0x34b0bcb5e19b48a8
#define SHA512_K52 0x391c0cb3c5c95a63
#define SHA512_K53 0x4ed8aa4ae3418acb
#define SHA512_K54 0x5b9cca4f7763e373
#define SHA512_K55 0x682e6ff3d6b2b8a3
#define SHA512_K56 0x748f82ee5defb2fc
#define SHA512_K57 0x78a5636f43172f60
#define SHA512_K58 0x84c87814a1f0ab72
#define SHA512_K59 0x8cc702081a6439ec
#define SHA512_K60 0x90befffa23631e28
#define SHA512_K61 0xa4506cebde82bde9
#define SHA512_K62 0xbef9a3f7b2c67915
#define SHA512_K63 0xc67178f2e372532b
#define SHA512_K64 0xca273eceea26619c
#define SHA512_K65 0xd186b8c721c0c207
#define SHA512_K66 0xeada7dd6cde0eb1e
#define SHA512_K67 0xf57d4f7fee6ed178
#define SHA512_K68 0x06f067aa72176fba
#define SHA512_K69 0x0a637dc5a2c898a6
#define SHA512_K70 0x113f9804bef90dae
#define SHA512_K71 0x1b710b35131c471b
#define SHA512_K72 0x28db77f523047d84
#define SHA512_K73 0x32caab7b40c72493
#define SHA512_K74 0x3c9ebe0a15c9bebc
#define SHA512_K75 0x431d67c49c100d4c
#define SHA512_K76 0x4cc5d4becb3e42b6
#define SHA512_K77 0x597f299cfc657e2a
#define SHA512_K78 0x5fcb6fab3ad6faec
#define SHA512_K79 0x6c44198c4a475817

#define SHA512_K_ARRAY_COUNT 80
#define SHA512_K_ARRAY                            \
{                                                 \
  SHA512_K0,  SHA512_K1,  SHA512_K2,  SHA512_K3,  \
  SHA512_K4,  SHA512_K5,  SHA512_K6,  SHA512_K7,  \
  SHA512_K8,  SHA512_K9,  SHA512_K10, SHA512_K11, \
  SHA512_K12, SHA512_K13, SHA512_K14, SHA512_K15, \
  SHA512_K16, SHA512_K17, SHA512_K18, SHA512_K19, \
  SHA512_K20, SHA512_K21, SHA512_K22, SHA512_K23, \
  SHA512_K24, SHA512_K25, SHA512_K26, SHA512_K27, \
  SHA512_K28, SHA512_K29, SHA512_K30, SHA512_K31, \
  SHA512_K32, SHA512_K33, SHA512_K34, SHA512_K35, \
  SHA512_K36, SHA512_K37, SHA512_K38, SHA512_K39, \
  SHA512_K40, SHA512_K41, SHA512_K42, SHA512_K43, \
  SHA512_K44, SHA512_K45, SHA512_K46, SHA512_K47, \
  SHA512_K48, SHA512_K49, SHA512_K50, SHA512_K51, \
  SHA512_K52, SHA512_K53, SHA512_K54, SHA512_K55, \
  SHA512_K56, SHA512_K57, SHA512_K58, SHA512_K59, \
  SHA512_K60, SHA512_K61, SHA512_K62, SHA512_K63, \
  SHA512_K64, SHA512_K65, SHA512_K66, SHA512_K67, \
  SHA512_K68, SHA512_K69, SHA512_K70, SHA512_K71, \
  SHA512_K72, SHA512_K73, SHA512_K74, SHA512_K75, \
  SHA512_K76, SHA512_K77, SHA512_K78, SHA512_K79  \
}

/* Internal SHA-512 functions.
 */
#define SHA512_CAP_SIGMA_0(_x) \
    ((SHA512_ROTR (_x, 28)) ^ (SHA512_ROTR (_x, 34)) ^ (SHA512_ROTR (_x, 39)))
#define SHA512_CAP_SIGMA_1(_x) \
    ((SHA512_ROTR (_x, 14)) ^ (SHA512_ROTR (_x, 18)) ^ (SHA512_ROTR (_x, 41)))
#define SHA512_SIGMA_0(_x) \
    ((SHA512_ROTR (_x, 1)) ^ (SHA512_ROTR (_x, 8)) ^ (SHA512_SHIFTR (_x, 7)))
#define SHA512_SIGMA_1(_x) \
    ((SHA512_ROTR (_x, 19)) ^ (SHA512_ROTR (_x, 61)) ^ (SHA512_SHIFTR (_x, 6)))

#define SHA512_CH(_x,_y,_z)  ((_x & _y) ^ (~_x & _z))
#define SHA512_MAJ(_x,_y,_z) ((_x & _y) ^ (_x & _z) ^ (_y & _z))

#ifdef __cplusplus
}
#endif

#endif /* _SHA_512_H */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -