Fast elliptic curve cryptography in plain JavaScript for ECDSA, EdDSA, and ECDH operations
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Access to predefined elliptic curves and curve operations, supporting multiple curve types with optimized implementations for Short Weierstrass, Montgomery, Edwards, and Twisted Edwards curves.
Access to built-in elliptic curve configurations with optimized parameters.
const curves = require('elliptic').curves;
// NIST standard curves
curves.p192;
curves.p224;
curves.p256;
curves.p384;
curves.p521;
// Bitcoin curve with endomorphism optimization
curves.secp256k1;
// Curve25519 family
curves.curve25519; // Montgomery curve for ECDH
curves.ed25519; // Edwards curve for EdDSAUsage Examples:
const elliptic = require('elliptic');
const curves = elliptic.curves;
// Access curve configurations
console.log('secp256k1 prime:', curves.secp256k1.curve.p.toString(16));
console.log('P-256 generator:', curves.p256.g);
// Use with EC constructor
const EC = elliptic.ec;
const ec1 = new EC(curves.secp256k1);
const ec2 = new EC('secp256k1'); // EquivalentClass representing a configured elliptic curve with all necessary parameters.
/**
* Create curve instance with parameters
* @param options - Curve configuration options
* @returns PresetCurve instance
*/
function PresetCurve(options);Standard elliptic curves in the form: y² = x³ + ax + b
// Short Weierstrass curves
const shortCurves = {
p192: curves.p192, // NIST P-192 (secp192r1)
p224: curves.p224, // NIST P-224 (secp224r1)
p256: curves.p256, // NIST P-256 (secp256r1, prime256v1)
p384: curves.p384, // NIST P-384 (secp384r1)
p521: curves.p521, // NIST P-521 (secp521r1)
secp256k1: curves.secp256k1 // Bitcoin curve with endomorphism
};Characteristics:
Curves optimized for ECDH key exchange in the form: By² = x³ + Ax² + x
// Montgomery curves
const montgomeryCurves = {
curve25519: curves.curve25519 // Optimized for ECDH
};Characteristics:
Curves optimized for EdDSA in the form: x² + y² = 1 + dx²y²
// Edwards curves
const edwardsCurves = {
ed25519: curves.ed25519 // Optimized for EdDSA signatures
};Characteristics:
Each curve provides access to mathematical parameters and properties.
// Curve properties
curve.curve; // Underlying curve implementation
curve.g; // Generator point
curve.n; // Order of the generator point
curve.hash; // Associated hash functionUsage Examples:
const curves = require('elliptic').curves;
// Examine secp256k1 properties
const secp256k1 = curves.secp256k1;
console.log('Generator point:', secp256k1.g.toString());
console.log('Curve order:', secp256k1.n.toString(16));
console.log('Hash function:', secp256k1.hash);
// Check curve type
console.log('Curve type:', secp256k1.curve.type); // 'short'
// Access curve parameters
const curve = secp256k1.curve;
console.log('Prime field:', curve.p.toString(16));
console.log('Curve parameter a:', curve.a.toString(16));
console.log('Curve parameter b:', curve.b.toString(16));Security strength of supported curves in approximate bits:
const securityLevels = {
p192: 96, // ~96-bit security
secp256k1: 128, // ~128-bit security
p256: 128, // ~128-bit security
curve25519: 128, // ~128-bit security
ed25519: 128, // ~128-bit security
p384: 192, // ~192-bit security
p521: 256 // ~256-bit security
};// Modern applications
const ec = new (require('elliptic').ec)('p256');
// Bitcoin and cryptocurrency
const ec = new (require('elliptic').ec)('secp256k1');
// High security requirements
const ec = new (require('elliptic').ec)('p384');// Modern applications (recommended)
const eddsa = new (require('elliptic').eddsa)('ed25519');// Modern applications (recommended)
const ec = new (require('elliptic').ec)('curve25519');
// NIST compatibility
const ec = new (require('elliptic').ec)('p256');Relative performance of different curves:
Fastest to Slowest (typical):
Usage Examples:
const elliptic = require('elliptic');
// Performance-optimized choices
const fastECDH = new elliptic.ec('curve25519'); // Fastest ECDH
const fastEdDSA = new elliptic.eddsa('ed25519'); // Fastest signatures
const fastECDSA = new elliptic.ec('secp256k1'); // Fast ECDSA with endomorphism
// Standard/compatibility choices
const standardECDSA = new elliptic.ec('p256'); // NIST standard
const highSecECDSA = new elliptic.ec('p384'); // Higher securityAll predefined curves undergo validation during initialization:
// Automatic validation checks
// - Generator point is on the curve
// - Generator point has correct order
// - Curve parameters meet security requirements
// - Mathematical consistency of parametersWhile not commonly needed, curves can be defined with custom parameters:
/**
* Define custom curve (advanced usage)
* @param name - Curve identifier
* @param options - Curve parameters
*/
function defineCurve(name, options);Note: Use predefined curves unless you have specific requirements and deep cryptographic expertise.
All curves work consistently across:
Recommended Modern Curves:
Legacy/Specialized Curves:
Always use the predefined curve configurations rather than manual parameter specification to ensure: