Bitcoin Core 31.99.0
P2P Digital Currency
selftest.h
Go to the documentation of this file.
1/***********************************************************************
2 * Copyright (c) 2020 Pieter Wuille *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or https://www.opensource.org/licenses/mit-license.php.*
5 ***********************************************************************/
6
7#ifndef SECP256K1_SELFTEST_H
8#define SECP256K1_SELFTEST_H
9
10#include "hash.h"
11
12#include <string.h>
13
15 secp256k1_hash_ctx hash_ctx;
16 static const char *input63 = "For this sample, this 63-byte string will be used as input data";
17 static const unsigned char output32[32] = {
18 0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e,
19 0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42,
20 };
21 unsigned char out[32];
22 secp256k1_sha256 hasher;
24 hash_ctx.fn_sha256_compression = fn_compression;
25 secp256k1_sha256_write(&hash_ctx, &hasher, (const unsigned char*)input63, 63);
26 secp256k1_sha256_finalize(&hash_ctx, &hasher, out);
27 if (secp256k1_memcmp_var(out, output32, 32) != 0) {
28 return 0;
29 }
30 if (fn_compression != secp256k1_sha256_transform && !secp256k1_sha256_smoke_test(fn_compression)) {
31 return 0;
32 }
33 return 1;
34}
35
36static int secp256k1_selftest_passes(void) {
37 /* Use default sha256 compression */
39}
40
41#endif /* SECP256K1_SELFTEST_H */
static int secp256k1_sha256_smoke_test(const secp256k1_sha256_compression_function fn_compression)
Definition: hash_impl.h:141
static void secp256k1_sha256_transform(uint32_t *state, const unsigned char *blocks64, size_t n_blocks)
Definition: hash_impl.h:133
static void secp256k1_sha256_finalize(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_write(const secp256k1_hash_ctx *hash_ctx, secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static SECP256K1_INLINE int secp256k1_memcmp_var(const void *s1, const void *s2, size_t n)
Semantics like memcmp.
Definition: util.h:281
void(* secp256k1_sha256_compression_function)(uint32_t *state, const unsigned char *blocks64, size_t n_blocks)
A pointer to a function implementing SHA256's internal compression function.
Definition: secp256k1.h:407
static int secp256k1_selftest_sha256(secp256k1_sha256_compression_function fn_compression)
Definition: selftest.h:14
static int secp256k1_selftest_passes(void)
Definition: selftest.h:36
secp256k1_sha256_compression_function fn_sha256_compression
Definition: hash.h:16