Skip to content

Commit 5eebcd0

Browse files
selftest: Split into .h and _impl.h
1 parent f2db0d0 commit 5eebcd0

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ noinst_HEADERS += src/int128_struct_impl.h
5858
noinst_HEADERS += src/scratch.h
5959
noinst_HEADERS += src/scratch_impl.h
6060
noinst_HEADERS += src/selftest.h
61+
noinst_HEADERS += src/selftest_impl.h
6162
noinst_HEADERS += src/testrand.h
6263
noinst_HEADERS += src/testrand_impl.h
6364
noinst_HEADERS += src/hash.h

src/secp256k1.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#endif
4444
#include "scalar_impl.h"
4545
#include "scratch_impl.h"
46-
#include "selftest.h"
46+
#include "selftest_impl.h"
4747

4848
#ifdef SECP256K1_NO_BUILD
4949
# error "secp256k1.h processed without SECP256K1_BUILD defined while building secp256k1.c"

src/selftest.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,7 @@
77
#ifndef SECP256K1_SELFTEST_H
88
#define SECP256K1_SELFTEST_H
99

10-
#include "hash.h"
11-
#include "util.h"
12-
13-
#include <string.h>
14-
15-
static int secp256k1_selftest_sha256(void) {
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;
23-
secp256k1_sha256_initialize(&hasher);
24-
secp256k1_sha256_write(&hasher, (const unsigned char*)input63, 63);
25-
secp256k1_sha256_finalize(&hasher, out);
26-
return secp256k1_memcmp_var(out, output32, 32) == 0;
27-
}
28-
29-
static int secp256k1_selftest_passes(void) {
30-
return secp256k1_selftest_sha256();
31-
}
10+
static int secp256k1_selftest_sha256(void);
11+
static int secp256k1_selftest_passes(void);
3212

3313
#endif /* SECP256K1_SELFTEST_H */

src/selftest_impl.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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_IMPL_H
8+
#define SECP256K1_SELFTEST_IMPL_H
9+
10+
#include "hash.h"
11+
#include "selftest.h"
12+
#include "util.h"
13+
14+
#include <string.h>
15+
16+
static int secp256k1_selftest_sha256(void) {
17+
static const char *input63 = "For this sample, this 63-byte string will be used as input data";
18+
static const unsigned char output32[32] = {
19+
0xf0, 0x8a, 0x78, 0xcb, 0xba, 0xee, 0x08, 0x2b, 0x05, 0x2a, 0xe0, 0x70, 0x8f, 0x32, 0xfa, 0x1e,
20+
0x50, 0xc5, 0xc4, 0x21, 0xaa, 0x77, 0x2b, 0xa5, 0xdb, 0xb4, 0x06, 0xa2, 0xea, 0x6b, 0xe3, 0x42,
21+
};
22+
unsigned char out[32];
23+
secp256k1_sha256 hasher;
24+
secp256k1_sha256_initialize(&hasher);
25+
secp256k1_sha256_write(&hasher, (const unsigned char*)input63, 63);
26+
secp256k1_sha256_finalize(&hasher, out);
27+
return secp256k1_memcmp_var(out, output32, 32) == 0;
28+
}
29+
30+
static int secp256k1_selftest_passes(void) {
31+
return secp256k1_selftest_sha256();
32+
}
33+
34+
#endif /* SECP256K1_SELFTEST_IMPL_H */

0 commit comments

Comments
 (0)