aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2024-05-07 08:52:55 -0400
committerTheCharlatan <seb.kung@gmail.com>2024-05-09 15:55:55 +0200
commit538fedde1d9c96a2bbe06cacc0cd6903135fbc83 (patch)
tree40cf1ef30b88ee9a093eabf81442042bad78fcaf /src
parent6f1d9064381d834b0f8daa9011f18ba40834d85a (diff)
common: Add ECC_Context RAII wrapper for ECC_Start/ECC_Stop
Diffstat (limited to 'src')
-rw-r--r--src/key.cpp10
-rw-r--r--src/key.h14
2 files changed, 24 insertions, 0 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 2bd6396298..8f31146311 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -457,3 +457,13 @@ void ECC_Stop() {
secp256k1_context_destroy(ctx);
}
}
+
+ECC_Context::ECC_Context()
+{
+ ECC_Start();
+}
+
+ECC_Context::~ECC_Context()
+{
+ ECC_Stop();
+}
diff --git a/src/key.h b/src/key.h
index 53acd179ba..5454c007d3 100644
--- a/src/key.h
+++ b/src/key.h
@@ -245,4 +245,18 @@ void ECC_Stop();
/** Check that required EC support is available at runtime. */
bool ECC_InitSanityCheck();
+/**
+ * RAII class initializing and deinitializing global state for elliptic curve support.
+ * Only one instance may be initialized at a time.
+ *
+ * In the future global ECC state could be removed, and this class could contain
+ * state and be passed as an argument to ECC key functions.
+ */
+class ECC_Context
+{
+public:
+ ECC_Context();
+ ~ECC_Context();
+};
+
#endif // BITCOIN_KEY_H