feat: add enclave
This commit is contained in:
5
__enclave/virt_enclave/src/main.rs
Normal file
5
__enclave/virt_enclave/src/main.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
mod sig;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
41
__enclave/virt_enclave/src/sig.rs
Normal file
41
__enclave/virt_enclave/src/sig.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user