Structure
P256K.Context
The secp256k1 context manages cryptographic state for ECDSA and Schnorr operations with automatic side-channel protection via base point blinding.
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
struct Context
Mentioned In
Overview
Context wraps the libsecp256k1 context object that all cryptographic operations in the P256K library require, including ECDSA signing, Schnorr signatures, public key generation, and ECDH key agreement. It handles context creation with SECP256K1_CONTEXT_NONE flags and immediately randomizes the internal state using cryptographically secure random bytes to protect against side-channel attacks during operations that involve secret scalar multiplication with the elliptic curve base point.
Usage
Most operations should use the shared rawRepresentation context, which is created and randomized once at process startup.
let ctx = P256K.Context.rawRepresentation
Call create() when you need a fresh, independently randomized context with isolated cryptographic state.
let ctx = P256K.Context.create()
secp256k1 Context Lifecycle
The secp256k1 library requires a context object to be passed to nearly every API function. Context creation allocates internal data structures, and randomization seeds an internal counter that blinds intermediate values during secret scalar multiplication with the elliptic curve base point. The rawRepresentation property provides a single shared context that is created and randomized once at process startup, avoiding repeated allocation overhead.
Side-Channel Protection Scope
Randomization protects operations that multiply a secret scalar with the elliptic curve base point, including ECDSA signing, Schnorr signing, and public key generation. The ECDH module uses a different kind of point multiplication and does not currently benefit from context randomization.
Topics
Shared Context
Construction