Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 132 additions & 0 deletions .github/workflows/ed448-goldilocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: ed448-goldilocks

on:
pull_request:
paths:
- ".github/workflows/ed448-goldilocks.yml"
- "ed448-goldilocks/**"
- "Cargo.*"
push:
branches: master

defaults:
run:
working-directory: ed448-goldilocks

env:
CARGO_INCREMENTAL: 0
RUSTFLAGS: "-Dwarnings"
RUSTDOCFLAGS: "-Dwarnings"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.85.0 # MSRV
- stable
target:
- thumbv7em-none-eabi
- wasm32-unknown-unknown
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: cargo build --target ${{ matrix.target }} --release --no-default-features
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features alloc
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features pkcs8
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features signing
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features serde
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features zeroize
- run: cargo build --target ${{ matrix.target }} --release --no-default-features --features alloc,pkcs8,signing,serde,zeroize

benches:
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- 1.85.0 # MSRV
- stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- run: cargo build --all-features --benches

test:
runs-on: ubuntu-latest
strategy:
matrix:
include:
# 32-bit Linux
- target: i686-unknown-linux-gnu
rust: 1.85.0 # MSRV
deps: sudo apt update && sudo apt install gcc-multilib
- target: i686-unknown-linux-gnu
rust: stable
deps: sudo apt update && sudo apt install gcc-multilib

# 64-bit Linux
- target: x86_64-unknown-linux-gnu
rust: 1.85.0 # MSRV
- target: x86_64-unknown-linux-gnu
rust: stable

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- run: ${{ matrix.deps }}
- run: cargo check --target ${{ matrix.target }} --all-features
- run: cargo test --release --target ${{ matrix.target }} --no-default-features
- run: cargo test --release --target ${{ matrix.target }}
- run: cargo test --release --target ${{ matrix.target }} --all-features

cross:
strategy:
matrix:
include:
# ARM32
- target: armv7-unknown-linux-gnueabihf
rust: 1.85.0 # MSRV (cross)
- target: armv7-unknown-linux-gnueabihf
rust: stable

# ARM64
- target: aarch64-unknown-linux-gnu
rust: 1.85.0 # MSRV (cross)
- target: aarch64-unknown-linux-gnu
rust: stable

# PPC32
- target: powerpc-unknown-linux-gnu
rust: 1.85.0 # MSRV (cross)
- target: powerpc-unknown-linux-gnu
rust: stable

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ${{ matrix.deps }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
targets: ${{ matrix.target }}
- uses: RustCrypto/actions/cross-install@master
- run: cross test --release --target ${{ matrix.target }} --all-features

doc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: RustCrypto/actions/cargo-cache@master
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- run: cargo doc --all-features
42 changes: 40 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"p256",
"p384",
"p521",
"ed448-goldilocks",
"primefield",
"primeorder",
"sm2"
Expand Down
43 changes: 43 additions & 0 deletions ed448-goldilocks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "ed448-goldilocks"
version = "0.17.0-pre.0"
authors = ["RustCrypto Developers"]
categories = ["cryptography"]
keywords = ["cryptography", "decaf", "ed448", "ed448-goldilocks"]
homepage = "https://docs.rs/ed448-goldilocks/"
repository = "https://github.com/RustCrypto/elliptic-curves/tree/master/ed448"
documentation = "https://docs.rs/ed448-goldilocks"
license = "BSD-3-Clause"
edition = "2024"
rust-version = "1.85"
readme = "README.md"
description = """A pure-Rust implementation of Ed448 and Curve448 and Decaf.
This crate also includes signing and verifying of Ed448 signatures.
"""

[dependencies]
crypto-bigint = { version = "=0.7.0-pre.4", features = ["hybrid-array"], default-features = false }
crypto_signature = { version = "3.0.0-rc.0", default-features = false, features = ["digest", "rand_core"], optional = true, package = "signature" }
elliptic-curve = { version = "0.14.0-rc.3", features = ["arithmetic", "bits", "hash2curve", "jwk", "pkcs8", "pem", "sec1"] }
rand_core = { version = "0.9", default-features = false }
serdect = { version = "0.3.0", optional = true }
sha3 = { version = "0.11.0-rc.0", default-features = false }
subtle = { version = "2.6", default-features = false }
zeroize = { version = "1.8", default-features = false, optional = true }

[features]
default = ["std", "signing", "pkcs8"]
alloc = ["serdect/alloc", "zeroize/alloc", "crypto_signature/alloc"]
pkcs8 = ["elliptic-curve/pkcs8"]
signing = ["dep:crypto_signature", "zeroize"]
serde = ["dep:serdect"]
std = ["serdect/default", "zeroize/default"]
zeroize = ["dep:zeroize"]

[dev-dependencies]
hex-literal = "1"
hex = "0.4"
rand_core = { version = "0.9", features = ["os_rng"] }
rand_chacha = "0.9"
serde_bare = "0.5"
serde_json = "1.0"
91 changes: 91 additions & 0 deletions ed448-goldilocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<p align="center">
<img src="resources/bear.png" width = "400">
</p>

ed448-goldilocks-plus

[![Crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![BSD-3 Licensed][license-image]

THIS CODE HAS NOT BEEN AUDITED OR REVIEWED. USE AT YOUR OWN RISK.

## Field Choice

The field size is a Solinas trinomial prime 2^448 - 2^224 -1. This prime is called the Goldilocks prime.

## Curves

This repository implements three curves explicitly and another curve implicitly.

The three explicitly implemented curves are:

- Ed448-Goldilocks

- Curve448

- Twisted-Goldilocks


## Ed448-Goldilocks Curve

- The goldilocks curve is an Edwards curve with affine equation x^2 + y^2 = 1 - 39081x^2y^2 .
- This curve was defined by Mike Hamburg in https://eprint.iacr.org/2015/625.pdf .
- The cofactor of this curve over the goldilocks prime is 4.

## Twisted-Goldilocks Curve

- The twisted goldilocks curve is a Twisted Edwards curve with affine equation y^2 - x^2 = 1 - 39082x^2y^2 .
- This curve is also defined in https://eprint.iacr.org/2015/625.pdf .
- The cofactor of this curve over the goldilocks prime is 4.

### Isogeny

- This curve is 2-isogenous to Ed448-Goldilocks. Details of the isogeny can be found here: https://www.shiftleft.org/papers/isogeny/isogeny.pdf

## Curve448

This curve is 2-isogenous to Ed448-Goldilocks. Details of Curve448 can be found here: https://tools.ietf.org/html/rfc7748

The main usage of this curve is for X448.

N.B. In that document there is an Edwards curve that is birationally equivalent to Curve448, with a large `d` value. This curve is not implemented and to my knowledge, has no utility.

## Strategy

The main strategy for group arithmetic on Ed448-Goldilocks is to perform the 2-isogeny to map the point to the Twisted-Goldilocks curve, then use the faster Twisted Edwards formulas to perform scalar multiplication. Computing the 2-isogeny then the dual isogeny will pick up a factor of 4 once we map the point back to the Ed448-Goldilocks curve, so the scalar must be adjusted by a factor of 4. Adjusting the scalar is dependent on the point and the scalar. More details can be found in the 2-isogenous paper.

# Decaf

The Decaf strategy [link paper] is used to build a group of prime order from the Twisted Goldilocks curve. The Twisted Goldilocks curve is used as it has faster formulas. We can also use Curve448 or Ed448-Goldilocks. Decaf takes advantage of an isogeny with a Jacobi Quartic curve which is not explicitly defined. Details of this can be found here: https://www.shiftleft.org/papers/decaf/decaf.pdf However, to my knowledge there is no documentation for the Decaf protocol implemented in this repository, which is a tweaked version of the original decaf protocol linked in the paper.

## Completed Point vs Extensible Point

Deviating from Curve25519-Dalek, this library will implement Extensible points instead of Completed Points. Due to the following observation:

- There is a cost of 3/4 Field multiplications to switch from the CompletedPoint. So if we were to perform repeated doubling, this would add an extra cost for each doubling in projective form. More details on the ExtensiblePoint can be found here [3.2]: https://www.shiftleft.org/papers/fff/fff.pdf

## Credits

The library design was taken from Dalek's design of Curve25519. The code for Montgomery curve arithmetic was also taken from Dalek's library.

The golang implementation of Ed448 and libdecaf were used as references.

Special thanks to Mike Hamburg for answering all the questions asked regarding Decaf and goldilocks.

This library adds [hash_to_curve](https://datatracker.ietf.org/doc/rfc9380/) and serialization of structs.

## Contribution

Unless you explicitly state otherwise, any contribution intentionally
submitted for inclusion in the work by you, as defined in the BSD-3-Clause
license, shall be dual licensed as above, without any additional terms or
conditions.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/ed448-goldilocks-plus.svg
[crate-link]: https://crates.io/crates/ed448-goldilocks-plus
[docs-image]: https://docs.rs/ed448-goldilocks-plus/badge.svg
[docs-link]: https://docs.rs/ed448-goldilocks-plus/
[license-image]: https://img.shields.io/badge/License-BSD%203--Clause-blue.svg
Binary file added ed448-goldilocks/resources/bear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions ed448-goldilocks/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::*;
use crate::{Scalar, decaf::DecafPoint};

pub const DECAF_BASEPOINT: DecafPoint = DecafPoint(curve::twedwards::extended::ExtendedPoint {
X: TWISTED_EDWARDS_BASE_POINT.X,
Y: TWISTED_EDWARDS_BASE_POINT.Y,
Z: TWISTED_EDWARDS_BASE_POINT.Z,
T: TWISTED_EDWARDS_BASE_POINT.T,
});

/// `BASEPOINT_ORDER` is the order of the Ed448 basepoint, i.e.,
/// $$
/// \ell = 2^\{446\} + 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d.
/// $$
pub const BASEPOINT_ORDER: Scalar = Scalar(ORDER);
7 changes: 7 additions & 0 deletions ed448-goldilocks/src/curve.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod edwards;
pub mod montgomery;
pub(crate) mod scalar_mul;
pub(crate) mod twedwards;

pub use edwards::{AffinePoint, CompressedEdwardsY, EdwardsPoint};
pub use montgomery::{MontgomeryPoint, ProjectiveMontgomeryPoint};
15 changes: 15 additions & 0 deletions ed448-goldilocks/src/curve/edwards.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// This module contains the code for the Goldilocks curve.
/// The goldilocks curve is the (untwisted) Edwards curve with affine equation x^2 + y^2 = 1 - 39081x^2y^2
/// Scalar Multiplication for this curve is pre-dominantly delegated to the Twisted Edwards variation using a (doubling) isogeny
/// Passing the point back to the Goldilocks curve using the dual-isogeny clears the cofactor.
/// The small remainder of the Scalar Multiplication is computed on the untwisted curve.
/// See <https://www.shiftleft.org/papers/isogeny/isogeny.pdf> for details
///
/// This isogeny strategy does not clear the cofactor on the Goldilocks curve unless the Scalar is a multiple of 4.
/// or the point is known to be in the q-torsion subgroup.
/// Hence, one will need to multiply by the cofactor to ensure it is cleared when using the Goldilocks curve.
/// If this is a problem, one can use a different isogeny strategy (Decaf/Ristretto)
pub(crate) mod affine;
pub(crate) mod extended;
pub use affine::AffinePoint;
pub use extended::{CompressedEdwardsY, EdwardsPoint};
Loading