feat: aes_gcm_decrypt
This commit is contained in:
@@ -4,7 +4,6 @@ use std::io::{Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use aes_gcm_stream::Aes256GcmStreamDecryptor;
|
||||
use openpgp_card::crypto_data::Cryptogram;
|
||||
use openpgp_card::OpenPgp;
|
||||
use rust_util::{debugging, failure, opt_result, simple_error, success, util_term, XResult};
|
||||
@@ -15,6 +14,7 @@ use yubikey::YubiKey;
|
||||
|
||||
use crate::{file, util};
|
||||
use crate::card::get_card;
|
||||
use crate::crypto::aes_gcm_decrypt;
|
||||
use crate::spec::{TinyEncryptEnvelop, TinyEncryptEnvelopType, TinyEncryptMeta};
|
||||
use crate::util::{decode_base64, decode_base64_url_no_pad, ENC_AES256_GCM_P256, simple_kdf, TINY_ENC_FILE_EXT};
|
||||
use crate::wrap_key::WrapKey;
|
||||
@@ -104,13 +104,8 @@ fn try_decrypt_key_ecdh(envelop: &TinyEncryptEnvelop, pin: &Option<String>, slot
|
||||
slot_id,
|
||||
), "Decrypt piv failed: {}");
|
||||
let key = simple_kdf(decrypted_shared_secret.as_slice());
|
||||
let key: [u8; 32] = opt_result!(key.as_slice().try_into(), "Invalid envelop: {}");
|
||||
let mut aes256_gcm = Aes256GcmStreamDecryptor::new(key, &wrap_key.nonce);
|
||||
let mut b1 = aes256_gcm.update(&wrap_key.encrypted_data);
|
||||
let b2 = opt_result!(aes256_gcm.finalize(), "Invalid envelop: {}");
|
||||
b1.extend_from_slice(&b2);
|
||||
|
||||
Ok(b1)
|
||||
let decrypted_key = aes_gcm_decrypt(&key, &wrap_key.nonce, &wrap_key.encrypted_data)?;
|
||||
Ok(decrypted_key)
|
||||
}
|
||||
|
||||
fn try_decrypt_key_pgp(envelop: &TinyEncryptEnvelop, pin: &Option<String>) -> XResult<Vec<u8>> {
|
||||
|
||||
Reference in New Issue
Block a user