Coder Social home page Coder Social logo

atropinetears / selenite Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 2.0 225 KB

An Experimental Rust Crate for Post-Quantum Code-Signing Certificates.

License: Apache License 2.0

Rust 100.00%
post-quantum-cryptography post-quantum crypto cryptography sphincs falcon pqcrypto rust rust-lang crate

selenite's Introduction

Selenite

Crates.io Build Status Crates.io

An experimental rust crate for Post-Quantum Code-Signing Certificates.

All Digital Signatures are Round Three NIST Post-Quantum Candidates which are listed here.

Please read the documentation for usage.

Overview

Digital Signatures:

  • SPHINCS+
  • FALCON512 and FALCON1024
  • ED25519*
  • BLS*

*: Not Post-Quantum Cryptography

Example Usage

SPHINCS+ (SHAKE256)

Read SPHINCS+

SPHINCS+ is a Stateless Hash-Based Signature Scheme taking its cryptographic assumptions against Quantum Computers from cryptographic hash functions.

This Digital Signature implementation reaches a Security Level of 5, which is the most secure a signature can be, by using the hash function SHAKE256 and setting other security parameters. However, SPHINCS+ has slow verification time compared to other choices.

  • SPHINCS+ Version: sphincsshake256256srobust

  • Public Key Size: 64 bytes

  • Private Key Size: 128 bytes

  • Signature Size: 29,792 bytes

use selenite::crypto::*;

fn main() {
    // Generates The Respected Keypair
    let keypair = SphincsKeypair::new();

    // Signs The Message as a UTF-8 Encoded String
    let mut signature = keypair.sign("message_to_sign");

    // Returns a boolean representing whether the signature is valid or not
    let is_verified = signature.verify();
}

FALCON512/FALCON1024

Read FALCON

FALCON is a lattice-based signature scheme whos underlying problem is based upon the short integer solution problem (SIS) over NTRU lattices, for which no efficient solving algorithm is currently known in the general case, even with the help of quantum computers. Falcon512 is similar in classical security assumptions to the security of RSA2048.

  • Public Key Size: 897 bytes | 1793 bytes

  • Private Key Size: 1281 bytes | 2305 bytes

  • Signature Size: 660 bytes | 1280 bytes

use selenite::crypto::*;

fn main(){
    // Generates FALCON512 Keypair
    let keypair = Falcon512Keypair::new();
    
    // Generates FALCON1024 Keypair
    let keypair2 = Falcon1024Keypair::new();
    
    // Signs The Message as a UTF-8 Encoded String using the first keypair (FALCON512)
    let signature = keypair.sign("Message1");
    
    // Returns a boolean representing whether the signature is valid or not
    let is_verified = signature.verify();
}

ED25519

ED25519 is an elliptic-curve based digital signature by DJB that has small public keys, private keys, and signatures.

It is not post-quantum secure but has been included in this library.

  • Public Key Size: 32 bytes

  • Private Key Size: 32 bytes

  • Signature Size: 64 bytes

use selenite::crypto::*;

fn main(){
    // Generates ED25519 Keypair
    let keypair = ED25519::new();
    
  	// Signs Message
    let signature = keypair.sign("Message1");
    
    // Returns a boolean representing whether the signature is valid or not
    let is_verified = signature.verify();
}

BLS Signature

BLS is a pairing friendly elliptic curve that allows aggregation of signatures. Aggregation of signatures allow you to combine multiple signatures into a single one. Selenite supports aggregation (although it is still in the works).

use selenite::crypto::*;

fn main() {
    let keypair = BLSKeypair::new();
    
    let keypair2 = BLSKeypair::new();
    
    let signature = keypair.sign("This message is being signed by BLS");
    
    let signature2 = keypair2.sign("This message is also being signed by BLS");
    
    let is_verified = signature.verify();
       
}

Serialization

You can Serialize keypairs to YAML using serde-yaml.

fn serialize(){
    // Generates Keypair
    let keypair = SphincsKeypair::new();
    
    // Serializes Keypair To YAML
    let yaml = keypair.serialize();
    
    // Deserializes Keypair To Respected Struct
    let keypair_from_yaml = SphincsKeypair::deserialize(&yaml);
}
fn serialize_signature(){
    // Generates Keypair
    let keypair = SphincsKeypair::new();

    // Generates Signature
    let signature = keypair.sign("Hello World!");

    // [BINCODE] Serialize To Bincode
    let bincode: Vec<u8> = signature.serialize_to_bincode();

    // [YAML] Serialize To YAML
    let yaml = signature.serialize();
}

Randomness From CSPRNG

Selenite allows you to easily get secure randomness from your operating system.

use selenite::random::OsRandom;

fn main() {
    let randomness_32 = OsRandom::rand_32.expect("Failed To Get Randomness");

    let randomness_64 = OsRandom::rand_64.expect("Failed To Get Randomness");

    let randomness_128 = OsRandom::rand_128.expect("Failed To Get Randomness");
}

Create SPHINCS+ Certificate

use selenite::crypto::SphincsKeypair;
use selenite::certificate::*;

fn main(){
    let (cert,keypair) = SeleniteCertificate::new(
        String::from("Subject Name"),
        CertificateType::INDIVIDUAL,
        Some(String::from("[Optional] Username")),
        vec![KeyUsage::CODE_SIGNING,KeyUsage::DOCUMENT_SIGNING,KeyUsage::REVOCATION],
        Some(String::from("[Optional] Email Address")),
        Some(String::from("[Optional] Phone Number")),
        Some(String::from("[Optional] Address")),
        Some(String::from("[Optional] Backup Email")),
        Some(String::from("[Optional] Backup Phone Number")),
        Some(String::from("[Optional] Description")),
        Some(String::from("[Optional] Website")),
        Some(String::from("[Optional] @Github")),
        Some(String::from("[Optional] @Reddit")),
        Some(String::from("[Optional] @Twitter")),
        Some(String::from("[Optional] @Keybase")),
        Some(String::from("[Optional] Bitcoin Address (BTC)")),
        Some(String::from("[Optional] Ethereum Address (ETH)")),
        Some(String::from("[Optional] Monero Address (XMR)")),
        Some(String::from("[Optional] Zcash Address (ZEC)")),
        Some(String::from("[Optional] PGP Key")),
        Some(String::from("[Optional] Onion Website")),
        Some(String::from("[Optional] Backup PGP Key")),
        Some(0usize), // (Optional) | Last_Bitcoin_Block_Height,
        Some(String::from("[Optional] Last Bitcoin Block Hash")),
        );
}

To-Do

  • Add Dilithium, another round three candidate

  • Add better Serialization

  • Add Tests

  • Refactor Code

Resources

License

Licensed under either of

  • Apache License, Version 2.0

  • MIT license

at your option.

Contribution

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

selenite's People

Contributors

atropinetears avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

selenite's Issues

add Kyber

Kyber has been the selected KEM by NIST.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.