Skip to content

Commit

Permalink
Revert "Tristan/war 306 optimal ate pairing (#20)"
Browse files Browse the repository at this point in the history
This reverts commit f1579d2.
  • Loading branch information
trbritt authored Aug 19, 2024
1 parent f1579d2 commit 8983554
Show file tree
Hide file tree
Showing 18 changed files with 588 additions and 1,600 deletions.
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
authors = ["Tristan Britt <[email protected]>", "0xAlcibiades <[email protected]>"]
categories = ["cryptography", "mathematics"]
description = "Implementation of the BLS signature scheme using the alt-bn128 curve."
homepage = "https://github.com/warlock-labs/sylow"
homepage = "https://github.com/warlock-labs/alt-bn128-bls"
keywords = ["alt-bn128", "bls", "cryptography", "elliptic-curve", "pairing"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/warlock-labs/sylow.git"
name = "sylow"
repository = "https://github.com/warlock-labs/alt-bn128-bls.git"
name = "alt-bn128-bls"
version = "0.0.1"
edition = "2021"

Expand All @@ -20,6 +20,8 @@ subtle = "2.6.1"
crypto-bigint = "0.6.0-rc.2"
sha3 = "0.11.0-pre.4"

[lib]
proc-macro = true

[dev-dependencies]
serde = { version = "1.0.204", features = ["derive"] }
Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# sylow
# alt-bn128-bls

[![License](https://img.shields.io/crates/l/sylow)](https://choosealicense.com/licenses/mit/)
[![Crates.io](https://img.shields.io/crates/v/sylow)](https://crates.io/crates/sylow)
[![Docs](https://img.shields.io/crates/v/sylow?color=blue&label=docs)](https://docs.rs/sylow/)
![CI](https://github.com/warlock-labs/sylow/actions/workflows/CI.yml/badge.svg)
[![License](https://img.shields.io/crates/l/alt-bn128-bls)](https://choosealicense.com/licenses/mit/)
[![Crates.io](https://img.shields.io/crates/v/alt-bn128-bls)](https://crates.io/crates/alt-bn128-bls)
[![Docs](https://img.shields.io/crates/v/alt-bn128-bls?color=blue&label=docs)](https://docs.rs/alt-bn128-bls/)
![CI](https://github.com/warlock-labs/alt-bn128-bls/actions/workflows/CI.yml/badge.svg)

sylow is a Rust library implementing the BLS (Boneh-Lynn-Shacham) signature scheme using the alt-bn128 (BN254) elliptic curve. It provides threshold signing capabilities and associated utilities, initially developed for use in the Warlock Chaos product.
alt-bn128-bls is a Rust library implementing the BLS (Boneh-Lynn-Shacham) signature scheme using the alt-bn128 (BN254) elliptic curve. It provides threshold signing capabilities and associated utilities, initially developed for use in the Warlock Chaos product.

## Features

Expand All @@ -21,27 +21,24 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
sylow = "0.0.1"
alt-bn128-bls = "0.0.1"
```

Here's a basic example of generating a key pair, signing a message, and verifying the signature:

```rust
use sylow::{KeyPair, sign, verify};
use alt_bn128_bls::{KeyPair, sign, verify};

fn main() {
let key_pair = KeyPair::generate();
let message = b"Hello, World!";

if let Ok(signature) = sign(&key_pair.secret_key, message){
if let Ok(verify) = verify(&key_pair.public_key, message, &signature){
assert!(verify, "Signature verification failed");
}
}
let signature = sign(&key_pair.secret_key, message);
assert!(verify(&key_pair.public_key, message, &signature));
}
```

For more examples and usage details, see the [API documentation](https://docs.rs/sylow).
For more examples and usage details, see the [API documentation](https://docs.rs/alt-bn128-bls).

## Core Concepts

Expand All @@ -67,7 +64,7 @@ The following features and improvements are planned for future releases:

## Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on the [GitHub repository](https://github.com/warlock-labs/sylow).
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests on the [GitHub repository](https://github.com/warlock-labs/alt-bn128-bls).

## License

Expand All @@ -77,4 +74,4 @@ This project is licensed under the [MIT License](https://choosealicense.com/lice

Warlock Labs - [https://github.com/warlock-labs](https://github.com/warlock-labs)

Project Link: [https://github.com/warlock-labs/sylow](https://github.com/warlock-labs/sylow)
Project Link: [https://github.com/warlock-labs/alt-bn128-bls](https://github.com/warlock-labs/alt-bn128-bls)
53 changes: 14 additions & 39 deletions src/fields/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ use std::ops::{Add, AddAssign, Neg, Sub, SubAssign};
// since the underlying Mul, Add, etc., are not, and const traits are in the works
// https://github.com/rust-lang/rust/issues/67792
#[derive(Copy, Clone, Debug)]
pub struct FieldExtension<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>>(pub [F; N]);
pub(crate) struct FieldExtension<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>>(
pub(crate) [F; N],
);

impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> From<u64>
for FieldExtension<D, N, F>
Expand All @@ -28,17 +30,12 @@ impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> From<u64>
Self::new(&retval)
}
}
#[allow(dead_code)]
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> FieldExtension<D, N, F> {
/// This is a const constructor that takes a slice of field elements and returns a field extension
/// The usage of the generics means that it is possible to instantiate any representation of
/// an extension need.
pub const fn new(c: &[F; N]) -> Self {
pub(crate) const fn new(c: &[F; N]) -> Self {
Self(*c)
}
/// There is eventually a need to be able to perform multiplication across different field
/// extensions, and more or less this corresponds to a basic scaling, see
/// <https://eprint.iacr.org/2010/354.pdf>
pub fn scale(&self, factor: F) -> Self {
pub(crate) fn scale(&self, factor: F) -> Self {
let mut i = 0;
let mut retval = [F::zero(); N];
while i < N {
Expand All @@ -62,27 +59,16 @@ impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> ConstantTimeE
retval
}
}
impl<'a, 'b, const D: usize, const N: usize, F: FieldExtensionTrait<D, N>>
Add<&'b FieldExtension<D, N, F>> for &'a FieldExtension<D, N, F>
{
type Output = FieldExtension<D, N, F>;

fn add(self, other: &'b FieldExtension<D, N, F>) -> Self::Output {
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> Add for FieldExtension<D, N, F> {
type Output = Self;
fn add(self, other: Self) -> Self {
let mut i = 0;
let mut retval = [F::zero(); N];
while i < N {
retval[i] = self.0[i] + other.0[i];
i += 1;
}
Self::Output::new(&retval)
}
}
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> Add<FieldExtension<D, N, F>>
for FieldExtension<D, N, F>
{
type Output = Self;
fn add(self, other: FieldExtension<D, N, F>) -> Self::Output {
&self + &other
Self::new(&retval)
}
}
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> AddAssign
Expand All @@ -92,27 +78,16 @@ impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> AddAssign
*self = *self + other;
}
}
impl<'a, 'b, const D: usize, const N: usize, F: FieldExtensionTrait<D, N>>
Sub<&'b FieldExtension<D, N, F>> for &'a FieldExtension<D, N, F>
{
type Output = FieldExtension<D, N, F>;

fn sub(self, other: &'b FieldExtension<D, N, F>) -> Self::Output {
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> Sub for FieldExtension<D, N, F> {
type Output = Self;
fn sub(self, other: Self) -> Self {
let mut i = 0;
let mut retval = [F::zero(); N];
while i < N {
retval[i] = self.0[i] - other.0[i];
i += 1;
}
Self::Output::new(&retval)
}
}
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> Sub<FieldExtension<D, N, F>>
for FieldExtension<D, N, F>
{
type Output = Self;
fn sub(self, other: FieldExtension<D, N, F>) -> Self::Output {
&self - &other
Self::new(&retval)
}
}
impl<const D: usize, const N: usize, F: FieldExtensionTrait<D, N>> SubAssign
Expand Down
Loading

0 comments on commit 8983554

Please sign in to comment.