~yujiri/libsufec

08fe4f2ded721efb0c25296354403eb5f3999e77 — Evin Yulo 2 years ago a533899
fix message decrypting
1 files changed, 10 insertions(+), 11 deletions(-)

M src/crypto.rs
M src/crypto.rs => src/crypto.rs +10 -11
@@ 30,19 30,18 @@ pub fn decrypt_message(
	new_eph: &SecretKey,
	old_eph: &SecretKey,
) -> Option<(SufecAddr, Message)> {
	let inner = sealedbox::open(outer, &account.addr.id, &account.seckey).ok()?;
	let mut offset = 0;
	let addr_len = u32::from_be_bytes(inner.get(..4)?.try_into().unwrap()) as usize;
	offset += 4;
	let their_addr = SufecAddr::from_bytes(inner.get(offset..offset+addr_len)?)?;
	offset += addr_len;
	let their_eph = inner.get(offset..offset+PUBLICKEYBYTES)?;
	let mut inner: &[u8] = &sealedbox::open(outer, &account.addr.id, &account.seckey).ok()?;
	let addr_len = *inner.get(0)? as usize;
	inner = &inner[1..];
	let their_addr = SufecAddr::from_bytes(inner.get(..addr_len)?)?;
	inner = &inner[addr_len..];
	let their_eph = inner.get(..PUBLICKEYBYTES)?;
	inner = &inner[PUBLICKEYBYTES..];
	let their_eph = PublicKey::from_slice(their_eph).unwrap();
	offset += PUBLICKEYBYTES;
	let nonce = inner.get(offset..offset+NONCEBYTES)?;
	let nonce = inner.get(..NONCEBYTES)?;
	inner = &inner[NONCEBYTES..];
	let nonce = Nonce::from_slice(nonce).unwrap();
	offset += NONCEBYTES;
	let ciphertext = &inner[offset..];
	let ciphertext = inner;
	// Try with the new key.
	let shared_key = tripledh(&account.seckey, new_eph, &their_addr.id, &their_eph);
	let decrypted = match open_precomputed(ciphertext, &nonce, &shared_key).ok() {