Crates.io | sra-wasm |
lib.rs | sra-wasm |
version | 0.1.0 |
source | src |
created_at | 2023-11-04 01:23:04.548848 |
updated_at | 2023-11-04 20:16:19.53278 |
description | A wasm implementation of the SRA protocol |
homepage | |
repository | https://github.com/zkCohort/sra-wasm |
max_upload_size | |
id | 1024792 |
size | 62,845 |
This Rust library utilizes WebAssembly (WASM) to implement encryption and decryption methods based on the SRA algorithm. It provides functions for generating encryption keys, encrypting and decrypting messages, and supporting operations such as modular exponentiation and extended Euclidean algorithm. The library is intended to be used in a web application, and is designed to be compiled to WASM and used in a JavaScript application.
The SRA algorithm is a public-key cryptosystem that uses modular exponentiation and the extended Euclidean algorithm to encrypt and decrypt messages. The algorithm is based on the following steps:
SRA is commutative, meaning that the order of encryption and decryption does not matter. This is proven by the following:
(m^eA mod N)^eB mod N = (m^eB mod N)^eA mod N
SRA is an algorithm developed by the inventors of RSA, Shamir, Rivest and Adleman. It is similar to RSA, but uses a different method for generating the public and private keys. The SRA algorithm is described in more detail in the following paper: A. Shamir, R.L. Rivest, L.M. Adleman, Mental poker, in: The Mathematical Gardner, Springer, 1981: pp. 37–43.
Here is a brief description of the functions implemented in the library:
js_generate_phi_n
: Generates a shared phi and N while keeping p and q secret.
js_generate_key_pair
: Generates an SRA key pair.
js_encrypt
: Encrypts a message using SRA encryption.
js_decrypt
: Decrypts a cipher using SRA decryption.
exp_by_squaring
: Implements the exponentiation by squaring algorithm.
encrypt
: Encrypts a message using SRA encryption.
decrypt
: Decrypts a cipher using SRA decryption.
get_fixed_sized_prime
: Generates a fixed-size prime number.
generate_phi_n
: Generates a shared phi and N while keeping p and q secret.
extended_gcd
: Implements the extended Euclidean algorithm.
mod_inverse
: Calculates the modular inverse of a number.
generate_key_pair
: Generates an SRA key pair.
The library includes a suite of tests to ensure correctness of the implemented functions. These tests can be run using the command wasm-pack test --node
.
To use this library, you need to have Rust and wasm-bindgen installed. You can then include it in your project by adding the following to your Cargo.toml file:
[dependencies]
sra_wasm = "0.1.0"
Then, in your main.rs file, you can use the library functions as follows:
use sra_wasm::\*;
fn main() {
// Use the library functions here
}
Contributions to this project are welcome. If you find a bug or want to add a new feature, please open an issue or submit a pull request. If your code adds new functionality, please write tests to confirm the new features function as expected. Make sure to incorporate your changes into the CHANGELOG.md file as well.
This project is licensed under the GNU GPLv3 license. See the LICENSE file for details.