Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/hash_impl.h
/********************************************************************** | /********************************************************************** | ||||
* Copyright (c) 2014 Pieter Wuille * | * Copyright (c) 2014 Pieter Wuille * | ||||
* Distributed under the MIT software license, see the accompanying * | * Distributed under the MIT software license, see the accompanying * | ||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||||
**********************************************************************/ | **********************************************************************/ | ||||
#ifndef SECP256K1_HASH_IMPL_H | #ifndef SECP256K1_HASH_IMPL_H | ||||
#define SECP256K1_HASH_IMPL_H | #define SECP256K1_HASH_IMPL_H | ||||
#include "hash.h" | #include "hash.h" | ||||
#include "util.h" | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <string.h> | #include <string.h> | ||||
#define Ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) | #define Ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) | ||||
#define Maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) | #define Maj(x,y,z) (((x) & (y)) | ((z) & ((x) | (y)))) | ||||
#define Sigma0(x) (((x) >> 2 | (x) << 30) ^ ((x) >> 13 | (x) << 19) ^ ((x) >> 22 | (x) << 10)) | #define Sigma0(x) (((x) >> 2 | (x) << 30) ^ ((x) >> 13 | (x) << 19) ^ ((x) >> 22 | (x) << 10)) | ||||
#define Sigma1(x) (((x) >> 6 | (x) << 26) ^ ((x) >> 11 | (x) << 21) ^ ((x) >> 25 | (x) << 7)) | #define Sigma1(x) (((x) >> 6 | (x) << 26) ^ ((x) >> 11 | (x) << 21) ^ ((x) >> 25 | (x) << 7)) | ||||
#define sigma0(x) (((x) >> 7 | (x) << 25) ^ ((x) >> 18 | (x) << 14) ^ ((x) >> 3)) | #define sigma0(x) (((x) >> 7 | (x) << 25) ^ ((x) >> 18 | (x) << 14) ^ ((x) >> 3)) | ||||
#define sigma1(x) (((x) >> 17 | (x) << 15) ^ ((x) >> 19 | (x) << 13) ^ ((x) >> 10)) | #define sigma1(x) (((x) >> 17 | (x) << 15) ^ ((x) >> 19 | (x) << 13) ^ ((x) >> 10)) | ||||
#define Round(a,b,c,d,e,f,g,h,k,w) do { \ | #define Round(a,b,c,d,e,f,g,h,k,w) do { \ | ||||
uint32_t t1 = (h) + Sigma1(e) + Ch((e), (f), (g)) + (k) + (w); \ | uint32_t t1 = (h) + Sigma1(e) + Ch((e), (f), (g)) + (k) + (w); \ | ||||
uint32_t t2 = Sigma0(a) + Maj((a), (b), (c)); \ | uint32_t t2 = Sigma0(a) + Maj((a), (b), (c)); \ | ||||
(d) += t1; \ | (d) += t1; \ | ||||
(h) = t1 + t2; \ | (h) = t1 + t2; \ | ||||
} while(0) | } while(0) | ||||
#ifdef WORDS_BIGENDIAN | #if defined(SECP256K1_BIG_ENDIAN) | ||||
#define BE32(x) (x) | #define BE32(x) (x) | ||||
#else | #elif defined(SECP256K1_LITTLE_ENDIAN) | ||||
#define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24)) | #define BE32(p) ((((p) & 0xFF) << 24) | (((p) & 0xFF00) << 8) | (((p) & 0xFF0000) >> 8) | (((p) & 0xFF000000) >> 24)) | ||||
#endif | #endif | ||||
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) { | static void secp256k1_sha256_initialize(secp256k1_sha256 *hash) { | ||||
hash->s[0] = 0x6a09e667ul; | hash->s[0] = 0x6a09e667ul; | ||||
hash->s[1] = 0xbb67ae85ul; | hash->s[1] = 0xbb67ae85ul; | ||||
hash->s[2] = 0x3c6ef372ul; | hash->s[2] = 0x3c6ef372ul; | ||||
hash->s[3] = 0xa54ff53aul; | hash->s[3] = 0xa54ff53aul; | ||||
▲ Show 20 Lines • Show All 243 Lines • Show Last 20 Lines |