#include <string.h>#include <stdlib.h>#include "sha2.h"#include <sys/param.h>Go to the source code of this file.
Defines | |
| #define | SHA_2 |
| #define | SHA_256 |
| #define | SHA_384 |
| #define | SHA_512 |
| #define | SHA_LITTLE_ENDIAN 1234 |
| #define | SHA_BIG_ENDIAN 4321 |
| #define | rotr32(x, n) (((x) >> n) | ((x) << (32 - n))) |
| #define | bswap_32(x) (rotr32((x), 24) & 0x00ff00ff | rotr32((x), 8) & 0xff00ff00) |
| #define | SHA256_MASK (SHA256_BLOCK_SIZE - 1) |
| #define | bsw_32(p, n) |
| #define | ch(x, y, z) (((x) & (y)) ^ (~(x) & (z))) |
| #define | maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
| #define | s256_0(x) (rotr32((x), 2) ^ rotr32((x), 13) ^ rotr32((x), 22)) |
| #define | s256_1(x) (rotr32((x), 6) ^ rotr32((x), 11) ^ rotr32((x), 25)) |
| #define | g256_0(x) (rotr32((x), 7) ^ rotr32((x), 18) ^ ((x) >> 3)) |
| #define | g256_1(x) (rotr32((x), 17) ^ rotr32((x), 19) ^ ((x) >> 10)) |
| #define | h2(i) |
| #define | h2_cycle(i, j) |
| #define | SHA512_MASK (SHA512_BLOCK_SIZE - 1) |
| #define | rotr64(x, n) (((x) >> n) | ((x) << (64 - n))) |
| #define | bswap_64(x) (((sha2_64t)(bswap_32((sha2_32t)(x)))) << 32 | bswap_32((sha2_32t)((x) >> 32))) |
| #define | bsw_64(p, n) |
| #define | s512_0(x) (rotr64((x), 28) ^ rotr64((x), 34) ^ rotr64((x), 39)) |
| #define | s512_1(x) (rotr64((x), 14) ^ rotr64((x), 18) ^ rotr64((x), 41)) |
| #define | g512_0(x) (rotr64((x), 1) ^ rotr64((x), 8) ^ ((x) >> 7)) |
| #define | g512_1(x) (rotr64((x), 19) ^ rotr64((x), 61) ^ ((x) >> 6)) |
| #define | h5(i) |
| #define | h5_cycle(i, j) |
| #define | CTX_256(x) ((x)->uu->ctx256) |
| #define | CTX_384(x) ((x)->uu->ctx512) |
| #define | CTX_512(x) ((x)->uu->ctx512) |
Functions | |
| void | sha256_begin (sha256_ctx ctx[1]) |
| void | sha256_compile (sha256_ctx ctx[1]) |
| void | sha256_hash (const unsigned char data[], unsigned long len, sha256_ctx ctx[1]) |
| void | sha256_end (unsigned char hval[], sha256_ctx ctx[1]) |
| void | sha256 (unsigned char hval[], const unsigned char data[], unsigned long len) |
| void | sha512_compile (sha512_ctx ctx[1]) |
| void | sha512_hash (const unsigned char data[], unsigned long len, sha512_ctx ctx[1]) |
| static void | sha_end (unsigned char hval[], sha512_ctx ctx[1], const unsigned int hlen) |
| void | sha384_begin (sha384_ctx ctx[1]) |
| void | sha384_end (unsigned char hval[], sha384_ctx ctx[1]) |
| void | sha384 (unsigned char hval[], const unsigned char data[], unsigned long len) |
| void | sha512_begin (sha512_ctx ctx[1]) |
| void | sha512_end (unsigned char hval[], sha512_ctx ctx[1]) |
| void | sha512 (unsigned char hval[], const unsigned char data[], unsigned long len) |
| int | sha2_begin (unsigned long len, sha2_ctx ctx[1]) |
| void | sha2_hash (const unsigned char data[], unsigned long len, sha2_ctx ctx[1]) |
| void | sha2_end (unsigned char hval[], sha2_ctx ctx[1]) |
| int | sha2 (unsigned char hval[], unsigned long size, const unsigned char data[], unsigned long len) |
Variables | |
| const sha2_32t | k256 [64] |
| const sha2_32t | i256 [8] |
| static sha2_32t | m1 [4] |
| static sha2_32t | b1 [4] |
| const sha2_64t | k512 [80] |
| static sha2_64t | m2 [8] |
| static sha2_64t | b2 [8] |
| const sha2_64t | i384 [80] |
| const sha2_64t | i512 [80] |
| #define bsw_32 | ( | p, | |||
| n | ) |
| #define bsw_64 | ( | p, | |||
| n | ) |
| #define bswap_32 | ( | x | ) | (rotr32((x), 24) & 0x00ff00ff | rotr32((x), 8) & 0xff00ff00) |
| #define bswap_64 | ( | x | ) | (((sha2_64t)(bswap_32((sha2_32t)(x)))) << 32 | bswap_32((sha2_32t)((x) >> 32))) |
| #define CTX_256 | ( | x | ) | ((x)->uu->ctx256) |
| #define CTX_384 | ( | x | ) | ((x)->uu->ctx512) |
| #define CTX_512 | ( | x | ) | ((x)->uu->ctx512) |
| #define g256_0 | ( | x | ) | (rotr32((x), 7) ^ rotr32((x), 18) ^ ((x) >> 3)) |
| #define g256_1 | ( | x | ) | (rotr32((x), 17) ^ rotr32((x), 19) ^ ((x) >> 10)) |
| #define g512_0 | ( | x | ) | (rotr64((x), 1) ^ rotr64((x), 8) ^ ((x) >> 7)) |
| #define g512_1 | ( | x | ) | (rotr64((x), 19) ^ rotr64((x), 61) ^ ((x) >> 6)) |
| #define h2 | ( | i | ) |
Value:
ctx->wbuf[i & 15] += \
g256_1(ctx->wbuf[(i + 14) & 15]) + ctx->wbuf[(i + 9) & 15] + g256_0(ctx->wbuf[(i + 1) & 15])
Definition at line 123 of file sha2.cpp.
Referenced by libtorrent::dht::node_impl::verify_token().
| #define h2_cycle | ( | i, | |||
| j | ) |
Value:
v[(7 - i) & 7] += (j ? h2(i) : ctx->wbuf[i & 15]) + k256[i + j] \ + s256_1(v[(4 - i) & 7]) + ch(v[(4 - i) & 7], v[(5 - i) & 7], v[(6 - i) & 7]); \ v[(3 - i) & 7] += v[(7 - i) & 7]; \ v[(7 - i) & 7] += s256_0(v[(0 - i) & 7]) + maj(v[(0 - i) & 7], v[(1 - i) & 7], v[(2 - i) & 7])
Definition at line 126 of file sha2.cpp.
Referenced by sha256_compile().
| #define h5 | ( | i | ) |
| #define h5_cycle | ( | i, | |||
| j | ) |
Value:
v[(7 - i) & 7] += (j ? h5(i) : ctx->wbuf[i & 15]) + k512[i + j] \ + s512_1(v[(4 - i) & 7]) + ch(v[(4 - i) & 7], v[(5 - i) & 7], v[(6 - i) & 7]); \ v[(3 - i) & 7] += v[(7 - i) & 7]; \ v[(7 - i) & 7] += s512_0(v[(0 - i) & 7]) + maj(v[(0 - i) & 7], v[(1 - i) & 7], v[(2 - i) & 7])
Definition at line 284 of file sha2.cpp.
Referenced by sha512_compile().
| #define maj | ( | x, | |||
| y, | |||||
| z | ) | (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) |
| #define s256_0 | ( | x | ) | (rotr32((x), 2) ^ rotr32((x), 13) ^ rotr32((x), 22)) |
| #define s256_1 | ( | x | ) | (rotr32((x), 6) ^ rotr32((x), 11) ^ rotr32((x), 25)) |
| #define s512_0 | ( | x | ) | (rotr64((x), 28) ^ rotr64((x), 34) ^ rotr64((x), 39)) |
| #define s512_1 | ( | x | ) | (rotr64((x), 14) ^ rotr64((x), 18) ^ rotr64((x), 41)) |
| #define SHA256_MASK (SHA256_BLOCK_SIZE - 1) |
| #define SHA512_MASK (SHA512_BLOCK_SIZE - 1) |
| int sha2 | ( | unsigned char | hval[], | |
| unsigned long | size, | |||
| const unsigned char | data[], | |||
| unsigned long | len | |||
| ) |
Definition at line 536 of file sha2.cpp.
References SHA2_BAD, sha2_begin(), sha2_end(), SHA2_GOOD, and sha2_hash().
Referenced by vmsHash::Hash_SHA2().
| void sha256 | ( | unsigned char | hval[], | |
| const unsigned char | data[], | |||
| unsigned long | len | |||
| ) |
Definition at line 252 of file sha2.cpp.
References sha256_begin(), sha256_end(), and sha256_hash().
| void sha256_begin | ( | sha256_ctx | ctx[1] | ) |
Definition at line 157 of file sha2.cpp.
References sha256_ctx::count, sha256_ctx::hash, and i256.
Referenced by sha256().
| void sha256_compile | ( | sha256_ctx | ctx[1] | ) |
Definition at line 163 of file sha2.cpp.
References h2_cycle, and sha256_ctx::hash.
Referenced by sha256_end(), and sha256_hash().
| void sha256_end | ( | unsigned char | hval[], | |
| sha256_ctx | ctx[1] | |||
| ) |
Definition at line 209 of file sha2.cpp.
References b1, bsw_32, sha256_ctx::count, sha256_ctx::hash, m1, SHA256_BLOCK_SIZE, sha256_compile(), SHA256_DIGEST_SIZE, SHA256_MASK, and sha256_ctx::wbuf.
Referenced by sha256(), and sha2_end().
| void sha256_hash | ( | const unsigned char | data[], | |
| unsigned long | len, | |||
| sha256_ctx | ctx[1] | |||
| ) |
Definition at line 180 of file sha2.cpp.
References bsw_32, sha256_ctx::count, pos(), SHA256_BLOCK_SIZE, sha256_compile(), SHA256_MASK, and sha256_ctx::wbuf.
Referenced by sha256(), and sha2_hash().
| int sha2_begin | ( | unsigned long | len, | |
| sha2_ctx | ctx[1] | |||
| ) |
| void sha2_end | ( | unsigned char | hval[], | |
| sha2_ctx | ctx[1] | |||
| ) |
Definition at line 526 of file sha2.cpp.
References CTX_256, CTX_384, CTX_512, sha256_end(), sha2_ctx::sha2_len, SHA384_DIGEST_SIZE, SHA512_DIGEST_SIZE, and sha_end().
Referenced by vmsHash::Hash_SHA2(), and sha2().
| void sha2_hash | ( | const unsigned char | data[], | |
| unsigned long | len, | |||
| sha2_ctx | ctx[1] | |||
| ) |
Definition at line 516 of file sha2.cpp.
References CTX_256, CTX_384, CTX_512, sha256_hash(), sha2_ctx::sha2_len, sha384_hash, and sha512_hash().
Referenced by vmsHash::Hash_SHA2(), and sha2().
| void sha384 | ( | unsigned char | hval[], | |
| const unsigned char | data[], | |||
| unsigned long | len | |||
| ) |
| void sha384_begin | ( | sha384_ctx | ctx[1] | ) |
Definition at line 443 of file sha2.cpp.
References sha512_ctx::count, sha512_ctx::hash, and i384.
Referenced by sha384().
| void sha384_end | ( | unsigned char | hval[], | |
| sha384_ctx | ctx[1] | |||
| ) |
Definition at line 449 of file sha2.cpp.
References SHA384_DIGEST_SIZE, and sha_end().
Referenced by sha384().
| void sha512 | ( | unsigned char | hval[], | |
| const unsigned char | data[], | |||
| unsigned long | len | |||
| ) |
Definition at line 483 of file sha2.cpp.
References sha512_begin(), sha512_end(), and sha512_hash().
| void sha512_begin | ( | sha512_ctx | ctx[1] | ) |
Definition at line 472 of file sha2.cpp.
References sha512_ctx::count, sha512_ctx::hash, and i512.
Referenced by sha512().
| void sha512_compile | ( | sha512_ctx | ctx[1] | ) |
Definition at line 334 of file sha2.cpp.
References h5_cycle, and sha512_ctx::hash.
Referenced by sha512_hash(), and sha_end().
| void sha512_end | ( | unsigned char | hval[], | |
| sha512_ctx | ctx[1] | |||
| ) |
Definition at line 478 of file sha2.cpp.
References SHA512_DIGEST_SIZE, and sha_end().
Referenced by sha512().
| void sha512_hash | ( | const unsigned char | data[], | |
| unsigned long | len, | |||
| sha512_ctx | ctx[1] | |||
| ) |
Definition at line 352 of file sha2.cpp.
References bsw_64, sha512_ctx::count, pos(), SHA512_BLOCK_SIZE, sha512_compile(), SHA512_MASK, and sha512_ctx::wbuf.
Referenced by sha2_hash(), and sha512().
| static void sha_end | ( | unsigned char | hval[], | |
| sha512_ctx | ctx[1], | |||
| const unsigned int | hlen | |||
| ) | [static] |
Definition at line 387 of file sha2.cpp.
References b2, bsw_64, sha512_ctx::count, sha512_ctx::hash, m2, SHA512_BLOCK_SIZE, sha512_compile(), SHA512_MASK, and sha512_ctx::wbuf.
Referenced by sha2_end(), sha384_end(), and sha512_end().
sha2_32t b1[4] [static] |
Initial value:
Definition at line 204 of file sha2.cpp.
Referenced by sha256_end(), CPrg_GeneralPage_FWDlg::UpdateEnabled(), and CDownloaderProperties_NewDownloadPage::UpdateEnabled().
sha2_64t b2[8] [static] |
Initial value:
{
n_u64(8000000000000000), n_u64(0080000000000000),
n_u64(0000800000000000), n_u64(0000008000000000),
n_u64(0000000080000000), n_u64(0000000000800000),
n_u64(0000000000008000), n_u64(0000000000000080)
}
Definition at line 379 of file sha2.cpp.
Referenced by sha_end(), CPrg_HistoryPage::UpdateEnabled(), and CDownloaderProperties_NewDownloadPage::UpdateEnabled().
| const sha2_32t i256[8] |
| const sha2_64t i384[80] |
Initial value:
{
n_u64(cbbb9d5dc1059ed8), n_u64(629a292a367cd507),
n_u64(9159015a3070dd17), n_u64(152fecd8f70e5939),
n_u64(67332667ffc00b31), n_u64(8eb44a8768581511),
n_u64(db0c2e0d64f98fa7), n_u64(47b5481dbefa4fa4)
}
Definition at line 435 of file sha2.cpp.
Referenced by sha2_begin(), and sha384_begin().
| const sha2_64t i512[80] |
Initial value:
{
n_u64(6a09e667f3bcc908), n_u64(bb67ae8584caa73b),
n_u64(3c6ef372fe94f82b), n_u64(a54ff53a5f1d36f1),
n_u64(510e527fade682d1), n_u64(9b05688c2b3e6c1f),
n_u64(1f83d9abfb41bd6b), n_u64(5be0cd19137e2179)
}
Definition at line 464 of file sha2.cpp.
Referenced by sha2_begin(), and sha512_begin().
| const sha2_32t k256[64] |
Initial value:
{ n_u32(428a2f98), n_u32(71374491), n_u32(b5c0fbcf), n_u32(e9b5dba5),
n_u32(3956c25b), n_u32(59f111f1), n_u32(923f82a4), n_u32(ab1c5ed5),
n_u32(d807aa98), n_u32(12835b01), n_u32(243185be), n_u32(550c7dc3),
n_u32(72be5d74), n_u32(80deb1fe), n_u32(9bdc06a7), n_u32(c19bf174),
n_u32(e49b69c1), n_u32(efbe4786), n_u32(0fc19dc6), n_u32(240ca1cc),
n_u32(2de92c6f), n_u32(4a7484aa), n_u32(5cb0a9dc), n_u32(76f988da),
n_u32(983e5152), n_u32(a831c66d), n_u32(b00327c8), n_u32(bf597fc7),
n_u32(c6e00bf3), n_u32(d5a79147), n_u32(06ca6351), n_u32(14292967),
n_u32(27b70a85), n_u32(2e1b2138), n_u32(4d2c6dfc), n_u32(53380d13),
n_u32(650a7354), n_u32(766a0abb), n_u32(81c2c92e), n_u32(92722c85),
n_u32(a2bfe8a1), n_u32(a81a664b), n_u32(c24b8b70), n_u32(c76c51a3),
n_u32(d192e819), n_u32(d6990624), n_u32(f40e3585), n_u32(106aa070),
n_u32(19a4c116), n_u32(1e376c08), n_u32(2748774c), n_u32(34b0bcb5),
n_u32(391c0cb3), n_u32(4ed8aa4a), n_u32(5b9cca4f), n_u32(682e6ff3),
n_u32(748f82ee), n_u32(78a5636f), n_u32(84c87814), n_u32(8cc70208),
n_u32(90befffa), n_u32(a4506ceb), n_u32(bef9a3f7), n_u32(c67178f2),
}
sha2_32t m1[4] [static] |
Initial value:
Definition at line 199 of file sha2.cpp.
Referenced by AMovieSetupRegisterFilter(), and sha256_end().
sha2_64t m2[8] [static] |
Initial value:
{
n_u64(0000000000000000), n_u64(ff00000000000000),
n_u64(ffff000000000000), n_u64(ffffff0000000000),
n_u64(ffffffff00000000), n_u64(ffffffffff000000),
n_u64(ffffffffffff0000), n_u64(ffffffffffffff00)
}
Definition at line 371 of file sha2.cpp.
Referenced by AMovieSetupRegisterFilter(), and sha_end().
1.5.6