feat: add enclave

This commit is contained in:
2020-11-05 23:31:14 +08:00
parent 691f77cf47
commit 47f94a6544
4 changed files with 321 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
mod sig;
fn main() {
println!("Hello, world!");
}

View File

@@ -0,0 +1,41 @@
use ring::{
signature::{ KeyPair, Ed25519KeyPair, UnparsedPublicKey, ED25519 },
hmac, rand, error::Unspecified,
digest,
};
pub struct SigningKeyPair {
key_pair: Vec<u8>,
}
impl SigningKeyPair {
fn new() -> Self {
let rng = rand::SystemRandom::new();
let pkcs8 = Ed25519KeyPair::generate_pkcs8(&rng).unwrap(); // TODO ...
SigningKeyPair{
key_pair: pkcs8.as_ref().to_vec(),
}
}
fn parse(&self) -> Ed25519KeyPair {
Ed25519KeyPair::from_pkcs8(&self.key_pair).unwrap() // TODO ...
}
}
pub struct SignedMessage {
msg: Vec<u8>,
sig: Vec<u8>,
desc: String,
}
impl SignedMessage {
pub fn sign(key_pair: &Ed25519KeyPair, msg: &[u8]) -> Vec<u8> {
let sig = key_pair.sign(msg);
sig.as_ref().to_vec()
}
pub fn verify(&self, public_key: &[u8]) -> bool {
let verify_result = UnparsedPublicKey::new(&ED25519, &public_key).verify(&self.msg, &self.sig);
verify_result.is_ok()
}
}