Skip to content

Commit

Permalink
key_manager: added encrypt_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad committed Dec 12, 2024
1 parent 5df5250 commit ab6c7bf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions cosmwasm/enclaves/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cosmwasm/enclaves/shared/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enclave-ffi-types = { path = "../../ffi-types" }
log = "0.4.17"
hex = "0.4.2"
lazy_static = "1.4"
sha2 = "0.10"
serde = { git = "https://github.com/mesalock-linux/serde-sgx", features = [
"derive"
] }
Expand Down
11 changes: 11 additions & 0 deletions cosmwasm/enclaves/shared/utils/src/key_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use enclave_ffi_types::EnclaveError;
use lazy_static::lazy_static;
use log::*;
use sgx_types::{sgx_key_128bit_t, sgx_measurement_t};
use sha2::{Digest, Sha256};
use std::io::{Read, Write};
use std::sgxfs::SgxFile;
// For phase 1 of the seed rotation, all consensus secrets come in two parts:
Expand Down Expand Up @@ -181,6 +182,16 @@ impl Keychain {
}
}

pub fn encrypt_hash(&self, hv: [u8; 32]) -> [u8; 32] {
let mut hasher = Sha256::new();
hasher.update(self.consensus_seed.unwrap().current.as_slice());
hasher.update(hv);

let mut ret: [u8; 32] = [0_u8; 32];
ret.copy_from_slice(&hasher.finalize());
ret
}

pub fn get_migration_keys() -> KeyPair {
let mut sk = Ed25519PrivateKey::default();
sk.get_mut()[..16].copy_from_slice(&get_key_from_seed("migrate.0.kdk".as_bytes()));
Expand Down

0 comments on commit ab6c7bf

Please sign in to comment.