mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
revise API on backups routine to use 0.10
This commit is contained in:
parent
f7bcbbf2d0
commit
cc2c11f84c
1 changed files with 10 additions and 6 deletions
|
|
@ -2,7 +2,7 @@ use core::mem::size_of;
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
use aes_gcm_siv::{
|
use aes_gcm_siv::{
|
||||||
aead::{Aead, KeyInit, Payload},
|
aead::{Aead, Payload},
|
||||||
Aes256GcmSiv, Nonce, Tag,
|
Aes256GcmSiv, Nonce, Tag,
|
||||||
};
|
};
|
||||||
use rand_core::RngCore;
|
use rand_core::RngCore;
|
||||||
|
|
@ -105,17 +105,17 @@ impl DerefMut for BackupDataCt {
|
||||||
/// and `nonce_com` which is the commitment nonce, set at 256 bits.
|
/// and `nonce_com` which is the commitment nonce, set at 256 bits.
|
||||||
/// The result is two tuples, (kenc, kcom).
|
/// The result is two tuples, (kenc, kcom).
|
||||||
fn kcom_func(key: &[u8; 32], nonce_com: &[u8; 32]) -> (BackupKey, BackupKey) {
|
fn kcom_func(key: &[u8; 32], nonce_com: &[u8; 32]) -> (BackupKey, BackupKey) {
|
||||||
use digest::Digest;
|
use sha2::{Digest, Sha512_256Sw};
|
||||||
use sha2::{FallbackStrategy, Sha512Trunc256};
|
// Note: for such a small hash, it would be faster to use a software-only strategy
|
||||||
|
let mut h_enc = Sha512_256Sw::new();
|
||||||
let mut h_enc = Sha512Trunc256::new_with_strategy(FallbackStrategy::SoftwareOnly);
|
|
||||||
h_enc.update(key);
|
h_enc.update(key);
|
||||||
// per https://eprint.iacr.org/2020/1456.pdf Table 4 on page 13 Type I Lenc
|
// per https://eprint.iacr.org/2020/1456.pdf Table 4 on page 13 Type I Lenc
|
||||||
h_enc.update([0x43, 0x6f, 0x6, 0xd6, 0xd, 0x69, 0x74, 0x01, 0x01]);
|
h_enc.update([0x43, 0x6f, 0x6, 0xd6, 0xd, 0x69, 0x74, 0x01, 0x01]);
|
||||||
h_enc.update(nonce_com);
|
h_enc.update(nonce_com);
|
||||||
let k_enc = h_enc.finalize();
|
let k_enc = h_enc.finalize();
|
||||||
|
|
||||||
let mut h_com = Sha512Trunc256::new_with_strategy(FallbackStrategy::SoftwareOnly);
|
// Note: for such a small hash, it would be faster to use a software-only strategy
|
||||||
|
let mut h_com = Sha512_256Sw::new();
|
||||||
h_com.update(key);
|
h_com.update(key);
|
||||||
// per https://eprint.iacr.org/2020/1456.pdf Table 4 on page 13 Type I Lcom. Note one-bit difference in last byte.
|
// per https://eprint.iacr.org/2020/1456.pdf Table 4 on page 13 Type I Lcom. Note one-bit difference in last byte.
|
||||||
h_com.update([0x43, 0x6f, 0x6, 0xd6, 0xd, 0x69, 0x74, 0x01, 0x02]);
|
h_com.update([0x43, 0x6f, 0x6, 0xd6, 0xd, 0x69, 0x74, 0x01, 0x02]);
|
||||||
|
|
@ -129,6 +129,8 @@ fn kcom_func(key: &[u8; 32], nonce_com: &[u8; 32]) -> (BackupKey, BackupKey) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn create_backup(key: BackupKey, header: BackupHeader, keyrom: KeyRomExport) -> BackupDataCt {
|
pub(crate) fn create_backup(key: BackupKey, header: BackupHeader, keyrom: KeyRomExport) -> BackupDataCt {
|
||||||
|
use aes_gcm_siv::KeyInit;
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
let mut trng = trng::Trng::new(&xns).unwrap();
|
let mut trng = trng::Trng::new(&xns).unwrap();
|
||||||
|
|
||||||
|
|
@ -180,6 +182,8 @@ pub(crate) fn create_backup(key: BackupKey, header: BackupHeader, keyrom: KeyRom
|
||||||
/// It is up to the caller to validate if the plaintext header matches the decrypted
|
/// It is up to the caller to validate if the plaintext header matches the decrypted
|
||||||
/// version embedded in the return data.
|
/// version embedded in the return data.
|
||||||
pub(crate) fn restore_backup(key: &BackupKey, backup: &BackupDataCt) -> Option<BackupDataPt> {
|
pub(crate) fn restore_backup(key: &BackupKey, backup: &BackupDataCt) -> Option<BackupDataPt> {
|
||||||
|
use aes_gcm_siv::KeyInit;
|
||||||
|
|
||||||
let (kenc, kcom) = kcom_func(&key.0, &backup.commit_nonce);
|
let (kenc, kcom) = kcom_func(&key.0, &backup.commit_nonce);
|
||||||
let cipher = Aes256GcmSiv::new(&kenc.0.into());
|
let cipher = Aes256GcmSiv::new(&kenc.0.into());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue