libsignal_service/groups_v2/
utils.rs

1use libsignal_protocol::error::SignalProtocolError;
2use zkgroup::groups::GroupMasterKey;
3use zkgroup::GROUP_MASTER_KEY_LEN;
4
5/// Given a 16-byte GroupV1 ID, derive the migration key.
6///
7/// Panics if the group_id is not 16 bytes long.
8pub fn derive_v2_migration_master_key(
9    group_id: &[u8],
10) -> Result<GroupMasterKey, SignalProtocolError> {
11    assert_eq!(group_id.len(), 16, "Group ID must be exactly 16 bytes");
12
13    let mut bytes = [0; GROUP_MASTER_KEY_LEN];
14    hkdf::Hkdf::<sha2::Sha256>::new(None, group_id)
15        .expand(b"GV2 Migration", &mut bytes)
16        .expect("valid output length");
17    Ok(GroupMasterKey::new(bytes))
18}