-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ed25519 digital signature scheme (#179)
* init: eddsa * fix lint&spell * improve code comment and add doc * fix readme dsa, downgrade anim quality * fix latex, add bench * improve keygen algo * improve doc * fix doc * fix doc tex, add sha512 * update spell dict * mv imgs/gifs to assets, cleanup * add mdbook and deploy on gh-pages * fix fmt * use write_all instead of write * update readme,book.toml,add desc to create_mdbook * finalize * update book.toml * add sk,pk to struct, generic sha * remove unused feature
- Loading branch information
Showing
35 changed files
with
2,335 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ ronkathon | |
crate | ||
nd | ||
te | ||
SHS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
name: Deploy mdBook site to Pages | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
|
||
jobs: | ||
# Build job | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
MDBOOK_VERSION: 0.4.43 | ||
MDBOOK_KATEX_VERSION: 0.9.2 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install mdBook | ||
run: | | ||
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh | ||
rustup update | ||
cargo install --version ${MDBOOK_VERSION} mdbook | ||
cargo install --version ${MDBOOK_KATEX_VERSION} mdbook-katex | ||
- name: Setup Pages | ||
id: pages | ||
uses: actions/configure-pages@v5 | ||
- name: Build with mdBook | ||
run: | | ||
cargo run --bin create_mdbook | ||
cp -r assets book/ | ||
mdbook build | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: ./docs | ||
|
||
# Deployment job | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
needs: build | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,9 @@ dump | |
|
||
# coverage files | ||
lcov.info | ||
|
||
# mdbook | ||
create_mdbook | ||
book | ||
mdbook | ||
docs |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
- [Introduction](README.md) | ||
- [Algebra](src/algebra/README.md) | ||
- [Field](src/algebra/field/README.md) | ||
- [Binary Towers](src/algebra/field/binary_towers/README.md) | ||
- [Group](src/algebra/group/README.md) | ||
- [Codes](src/codes/README.md) | ||
- [Compiler](src/compiler/README.md) | ||
- [Curve](src/curve/README.md) | ||
- [Digital Signature Algorithms](src/dsa/README.md) | ||
- [Encryption]() | ||
- [Asymmetric]() | ||
- [RSA](src/encryption/asymmetric/rsa/README.md) | ||
- [Symmetric Encryption](src/encryption/symmetric/README.md) | ||
- [AES](src/encryption/symmetric/aes/README.md) | ||
- [ChaCha](src/encryption/symmetric/chacha/README.md) | ||
- [DES](src/encryption/symmetric/des/README.md) | ||
- [Modes](src/encryption/symmetric/modes/README.md) | ||
- [Hashes](src/hashes/README.md) | ||
- [Poseidon](src/hashes/poseidon/README.md) | ||
- [HMAC](src/hmac/README.md) | ||
- [KZG](src/kzg/README.md) | ||
- [Merkle Trees](src/tree/README.md) |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[book] | ||
authors = ["Contributors to Ronkathon"] | ||
language = "en" | ||
multilingual = false | ||
src = "book" | ||
title = "Ronkathon: Cryptography Educational Foundations" | ||
description = "Cryptography Educational Foundations" | ||
|
||
[build] | ||
build-dir = "docs" | ||
use-default-preprocessors = true | ||
create-missing = true | ||
|
||
[preprocessor.katex] | ||
after = ["links"] | ||
|
||
[output.html] | ||
default-theme = "dark" | ||
preferred-dark-theme = "coal" | ||
git-repository-url = "https://github.com/pluto/ronkathon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/// Example of Ed25519 digital signature algorithm. | ||
use ronkathon::dsa::eddsa::Ed25519; | ||
|
||
fn main() { | ||
let ed25519 = Ed25519::new(None); | ||
let msg = b"Hello World"; | ||
|
||
let signature = ed25519.sign(msg); | ||
assert!(ed25519.verify(msg, signature)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/// Read SUMMARY.md and copy `README.md` files given in it to `book` directory. | ||
/// Additionally, change the links to other `README.md` files to `index.md`, so that link | ||
/// points to correct file in the mdbook. | ||
use std::{ | ||
fs::{self, File}, | ||
io::{self, BufRead, BufReader, Write}, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use regex::Regex; | ||
|
||
const DEST: &str = "book"; | ||
|
||
fn main() -> io::Result<()> { | ||
let dest_path = Path::new(DEST); | ||
if !dest_path.exists() { | ||
fs::create_dir(dest_path)?; | ||
} | ||
|
||
let mut readmes = Vec::<PathBuf>::new(); | ||
let f = File::open("SUMMARY.md")?; | ||
let reader = BufReader::new(f); | ||
|
||
let re = Regex::new(r"\[.*\]\((.*)\)").unwrap(); | ||
|
||
for line in reader.lines() { | ||
for (_, [link]) in re.captures_iter(&line?).map(|c| c.extract()) { | ||
if !link.is_empty() { | ||
readmes.push(PathBuf::from(link)); | ||
} | ||
} | ||
} | ||
|
||
let readme_re = Regex::new(r"README.md").unwrap(); | ||
|
||
for src in &readmes { | ||
println!("Working on: {}", src.display()); | ||
|
||
let dest = Path::new(DEST).join(src); | ||
let dest_folder = dest.parent().unwrap(); | ||
if !dest_folder.exists() { | ||
fs::create_dir_all(dest_folder)?; | ||
} | ||
let src_file = File::open(src)?; | ||
let reader = BufReader::new(src_file); | ||
|
||
let mut dest_file = File::create(&dest)?; | ||
|
||
for line in reader.lines() { | ||
let before = line.unwrap(); | ||
let after = readme_re.replace_all(&before, "index.md"); | ||
dest_file.write_all(after.as_bytes())?; | ||
dest_file.write_all(b"\n")?; | ||
} | ||
} | ||
|
||
println!("Copying SUMMARY.md to {DEST}/SUMMARY.md"); | ||
fs::copy("SUMMARY.md", "book/SUMMARY.md")?; | ||
|
||
println!("Done!"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Digital Signature Algorithms (DSA) | ||
|
||
### What are digital signatures? | ||
|
||
Like its name, **Digital Signatures** are digital analogs of physical signatures. For example, when you want to write a cheque you have to "sign" it for authentication purposes. But think about how you would do the same over the internet. | ||
Here is where **Digital Signatures** come into the picture. | ||
|
||
**Digital Signatures** have the following properties: | ||
1. **Authenticity**: Just like physical signatures, digital signatures provide a way to verify the identity of a signer. | ||
2. **Integrity**: Digital signatures provide a mechanism to detect unauthorized modification to a message. | ||
3. **Non-repudiation**: Digital signatures have a nice property that once a signer signs a message, they cannot deny having done so. | ||
|
||
### How does a digital signature scheme look like? | ||
|
||
Digital signature schemes consists of three algorithms $\text{Gen, Sign, Verify}$, such that: | ||
|
||
1. The key generation algorithm, $\text{Gen}$ which takes in the security parameter $n$ and outputs public key, $\text{pk}$ and private key, $\text{sk}$. | ||
2. The signing algorithm $\text{Sign}$ takes as input the keys and a message and outputs a signature. | ||
3. The verification algorithm $\text{Verify}$, takes as input the public key, a message, and a signature. | ||
It outputs bit 1 if the signature is valid for the given message and public key, otherwise 0. | ||
|
||
### How is a digital signature scheme used? | ||
|
||
To explain how digital signature schemes are used, let's take the example of two people, Bobby and Alex. | ||
Bobby is the one whose signature is required, so Bobby will run the $\text{Gen(n)}$ algorithm to obtain, $\text{pk, sk}$. | ||
Then, the public key, $\text{pk}$, is publicized as belonging to Bobby. This not only provides authentication but also ensures non-repudiation. This one of the critical parts of a secure digital signature scheme. | ||
You can read more on this here: [Public key infrastructure](https://en.wikipedia.org/wiki/Public_key_infrastructure) | ||
|
||
![](../../assets/keygen.gif) | ||
|
||
Now when Alex sends a message(document, contract, etc.), $m$, for Bobby to sign, they compute the signature, $s$ as, $s\leftarrow\text{Sign(sk,m)}$ and sents $s$ to Alex or any other party who wants to take a look. | ||
Now, any party who wants to see if Bobby signed the document or not, applies the verification algorithm using the public key as $\text{Verify(pk,m,s)}$. Thus Alex or any other party can be sure of the authenicity of | ||
the signature as well as the integrity of the message. | ||
|
||
![](../../assets/sign_and_verify.gif) | ||
|
||
### When is a signature scheme said to be secure? | ||
|
||
A digital signature scheme is said to be secure if an adversary is unable to generate a forgery, that is, a message (not previously signed) and a valid signature for a fixed public key, in any case. | ||
|
||
### Examples of digital signature scheme | ||
|
||
1. Elliptic Curve Digital Signature Scheme(ECDSA) | ||
2. Edwards-Curve Digital Signature Scheme(EdDSA) | ||
|
||
## References | ||
|
||
1. "Introduction to Modern Cryptography" by Jonathan Katz and Yehuda Lindell | ||
2. [Digital Signatures](https://asecuritysite.com/signatures) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.