|
1 | 1 | use crate::SIGNING_KEY; |
2 | | -use types::{PubKey, DhKey}; |
| 2 | +use types::{PubKey, DhKey, SymmetricKey}; |
3 | 3 | use std::collections::HashMap; |
4 | 4 | use std::{sync::SgxMutex as Mutex, sync::SgxMutexGuard as MutexGuard, vec::Vec}; |
5 | 5 | use serde::{Deserialize, Serialize}; |
6 | 6 | use secp256k1::{PublicKey, SecretKey, SharedSecret}; |
7 | 7 | use errors_t::{CryptoError, EnclaveError, ToolsError::MessagingError}; |
8 | 8 | use hash::{Keccak256, prepare_hash_multiple}; |
9 | 9 |
|
| 10 | +//use ring::aead::{self, Nonce, Aad}; |
| 11 | +//use std::{borrow::ToOwned}; |
| 12 | + |
10 | 13 |
|
11 | 14 | #[derive(Debug)] |
12 | 15 | pub struct KeyPair { |
@@ -50,11 +53,11 @@ impl KeyPair { |
50 | 53 | let pubkey = PublicKey::parse(&pubarr) |
51 | 54 | .map_err(|e| CryptoError::KeyError { key_type: "Private Key", err: Some(e) })?; |
52 | 55 |
|
53 | | - // let shared = SharedSecret::new(&pubkey, &self.privkey) |
54 | | - // .map_err(|_| CryptoError::DerivingKeyError { self_key: self.get_pubkey(), other_key: *_pubarr })?; |
| 56 | + let shared = SharedSecret::new(&pubkey, &self.privkey) |
| 57 | + .map_err(|_| CryptoError::DerivingKeyError { self_key: self.get_pubkey(), other_key: *_pubarr })?; |
55 | 58 |
|
56 | 59 | let mut result = [0u8; 32]; |
57 | | - //result.copy_from_slice(shared.as_ref()); |
| 60 | + result.copy_from_slice(shared.as_ref()); |
58 | 61 | Ok(result) |
59 | 62 | } |
60 | 63 |
|
@@ -161,6 +164,28 @@ impl UserMessage { |
161 | 164 | // } |
162 | 165 | } |
163 | 166 |
|
| 167 | + |
| 168 | +// const IV_SIZE: usize = 96/8; |
| 169 | +// static AES_MODE: &aead::Algorithm = &aead::AES_256_GCM; |
| 170 | +// type IV = [u8; IV_SIZE]; |
| 171 | + |
| 172 | +// pub fn decrypt(cipheriv: &[u8], key: &SymmetricKey) -> Result<Vec<u8>, CryptoError> { |
| 173 | +// if cipheriv.len() < IV_SIZE { |
| 174 | +// return Err(CryptoError::ImproperEncryption); |
| 175 | +// } |
| 176 | +// let aes_decrypt = aead::OpeningKey::new(&AES_MODE, key) |
| 177 | +// .map_err(|_| CryptoError::KeyError { key_type: "Decryption", err: None })?; |
| 178 | + |
| 179 | +// let (ciphertext, iv) = cipheriv.split_at(cipheriv.len()-12); |
| 180 | +// let nonce = aead::Nonce::try_assume_unique_for_key(&iv).unwrap(); // This Cannot fail because split_at promises that iv.len()==12 |
| 181 | +// let mut ciphertext = ciphertext.to_owned(); |
| 182 | +// let decrypted_data = aead::open_in_place(&aes_decrypt, nonce, Aad::empty(), 0, &mut ciphertext); |
| 183 | +// let decrypted_data = decrypted_data.map_err(|_| CryptoError::DecryptionError)?; |
| 184 | + |
| 185 | +// Ok(decrypted_data.to_vec()) |
| 186 | +// } |
| 187 | + |
| 188 | + |
164 | 189 | /// A trait that is basically a shortcut for `mutex.lock().expect(format!("{} mutex is posion", name))` |
165 | 190 | /// you instead call `mutex.lock_expect(name)` and it will act the same. |
166 | 191 | pub trait LockExpectMutex<T> { |
|
0 commit comments