---
title: "Overview"
description: "What the package computes. Short Weierstrass curves over a prime you pick and secp256k1 and P-256 and P-384 and P-521 and three Brainpool curves and sr25519 and ed25519 and Ed448 on their own"
canonical_url: "https://curves.agntn.dev/math"
---
# Overview

> What the package computes. Short Weierstrass curves over a prime you pick and secp256k1 and P-256 and P-384 and P-521 and three Brainpool curves and sr25519 and ed25519 and Ed448 on their own

## Two kinds of Weierstrass curve

Most of the package works on the short Weierstrass form, y² = x³ + ax + b, over the integers mod a prime p. That covers the toy curves of a CTF and secp256k1 alike. The difference is in what you hand over.

<table>
<thead>
  <tr>
    <th>
      
    </th>
    
    <th>
      Curves you define
    </th>
    
    <th>
      secp256k1
    </th>
    
    <th>
      P-256, P-384, P-521, brainpoolP256r1, brainpoolP384r1 and brainpoolP512r1
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Import
    </td>
    
    <td>
      <code>
        @agntn/curves
      </code>
    </td>
    
    <td>
      <code>
        @agntn/curves/secp256k1
      </code>
    </td>
    
    <td>
      <code>
        @agntn/curves/p256
      </code>
      
      , <code>
        @agntn/curves/p384
      </code>
      
      , <code>
        @agntn/curves/p521
      </code>
      
      , <code>
        @agntn/curves/brainpoolp256r1
      </code>
      
      , <code>
        @agntn/curves/brainpoolp384r1
      </code>
      
      , <code>
        @agntn/curves/brainpoolp512r1
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      Curve
    </td>
    
    <td>
      <code>
        defineCurve({ a, b, p })
      </code>
    </td>
    
    <td>
      fixed, from SEC 2
    </td>
    
    <td>
      fixed, from SEC 2 and RFC 5639
    </td>
  </tr>
  
  <tr>
    <td>
      Points
    </td>
    
    <td>
      <code>
        { x, y }
      </code>
      
       as bigints, <code>
        null
      </code>
      
       for infinity
    </td>
    
    <td>
      SEC1 hex, infinity refused
    </td>
    
    <td>
      SEC1 hex, infinity refused
    </td>
  </tr>
  
  <tr>
    <td>
      Scalars
    </td>
    
    <td>
      any bigint
    </td>
    
    <td>
      1 to n - 1, hex or bigint
    </td>
    
    <td>
      1 to n - 1, hex or bigint
    </td>
  </tr>
  
  <tr>
    <td>
      Extra
    </td>
    
    <td>
      lifting x, counting, listing, orders, logs
    </td>
    
    <td>
      scalars mod n, lifting x
    </td>
    
    <td>
      lifting x, ECDSA signing and verification
    </td>
  </tr>
  
  <tr>
    <td>
      Agent tool
    </td>
    
    <td>
      <code>
        curves_compute
      </code>
    </td>
    
    <td>
      <code>
        curves_secp256k1_compute
      </code>
    </td>
    
    <td>
      <code>
        curves_p256_compute
      </code>
      
      , <code>
        curves_p384_compute
      </code>
      
      , <code>
        curves_p521_compute
      </code>
      
      , <code>
        curves_brainpoolp256r1_compute
      </code>
      
      , <code>
        curves_brainpoolp384r1_compute
      </code>
      
      , <code>
        curves_brainpoolp512r1_compute
      </code>
    </td>
  </tr>
</tbody>
</table>

Why two? A toy curve is about the group. Count the points, find an order, take a log. secp256k1 is about keys. Nobody counts its points, and a log on it is not happening.

P-256, or secp256r1, uses SEC1 points, lifts x and signs and verifies ECDSA. Its signatures use deterministic RFC 6979 nonces. One letter separates secp256k1 from secp256r1. Now both can sign.

P-384 gives each coordinate 48 bytes, so its points take up more room than P-256's. It uses the same SEC 1 code and the same a = -3 formulas as P-256. The math doesn't change, only the ruler does.

P-521 fits each coordinate into 66 bytes, with only one bit used in the top byte. And yes, it's 521, not 512. That's not a typo.

Brainpool skips shortcut primes. Its a is neither 0 nor -3, so it needs formulas for any a. Two of its curves look like P-256 and P-384 by point length. brainpoolP512r1's 64-byte coordinates match nothing else here.

## And three that aren't Weierstrass

Polkadot went another way. Its accounts sign with sr25519. That's Schnorr over ristretto255, a group that sits on edwards25519. Not a Weierstrass curve at all, so it gets entries of its own. `@agntn/curves/sr25519` has keys, signatures and HDKD. `@agntn/curves/ristretto255` has the points underneath. And the agent tool? `curves_sr25519_compute`.

Monero sits on the same curve and skips the ristretto layer. Its keys are plain ed25519 points, small order ones included, so `@agntn/curves/ed25519` keeps the cofactor in view. No agent tool for that one yet, just the library.

Ed448 is edwards448 with a cofactor of 4. `@agntn/curves/ed448` verifies RFC 8032 signatures, and `curves_ed448_compute` brings verification to agents. Context is part of the signature, even when it's empty. Ed448's bigger bytes don't come with signing here.

## Pages

- [Curves and points](https://curves.agntn.dev/math/curves): define a curve, add and multiply points, check one, lift an x.
- [Orders and logs](https://curves.agntn.dev/math/groups): count, list, orders, discrete logs, and how far each goes.
- [Modular arithmetic](https://curves.agntn.dev/math/field): mod, powers, inverses, square roots and congruences over BigInt, refused when the input can't work.
- [Linear algebra](https://curves.agntn.dev/math/matrices): rank, nullspaces and systems over a prime field, with a proof when nothing solves them.
- [secp256k1](https://curves.agntn.dev/math/secp256k1): SEC1 points, scalars mod n, lifting x, ECDSA and BIP340 signatures.
- [sr25519](https://curves.agntn.dev/math/sr25519): Polkadot keys, signatures, hard and soft derivation, ristretto255.
- [ed25519](https://curves.agntn.dev/math/ed25519): RFC 8032 points, scalars, Monero subgroup checks and Ed25519 signatures.
- [Ed448](https://curves.agntn.dev/math/ed448): RFC 8032 signatures on edwards448, checked under their context.
- [P-256](https://curves.agntn.dev/math/p256): SEC1 points, point math, lifting x, ECDSA signing, verification and recovery.
- [P-384](https://curves.agntn.dev/math/p384): the same at 48 bytes a coordinate, for ES384 and certificates.
- [P-521](https://curves.agntn.dev/math/p521): 66 bytes a coordinate and a single bit in the top one, for ES512 and OpenPGP keys.
- [brainpoolP256r1](https://curves.agntn.dev/math/brainpoolp256r1): P-256 sized points with different parameters and a tricky resemblance.
- [brainpoolP384r1](https://curves.agntn.dev/math/brainpoolp384r1): 48-byte coordinates, like P-384, but a different curve.
- [brainpoolP512r1](https://curves.agntn.dev/math/brainpoolp512r1): 64-byte coordinates stand alone here.


## Sitemap

See the full [sitemap](https://curves.agntn.dev/sitemap.md) for all pages.
