libsignal_protocol/ratchet/
params.rs

1//
2// Copyright 2020 Signal Messenger, LLC.
3// SPDX-License-Identifier: AGPL-3.0-only
4//
5
6use crate::{IdentityKey, IdentityKeyPair, KeyPair, PublicKey, kem};
7
8pub struct AliceSignalProtocolParameters {
9    our_identity_key_pair: IdentityKeyPair,
10    our_base_key_pair: KeyPair,
11
12    their_identity_key: IdentityKey,
13    their_signed_pre_key: PublicKey,
14    their_one_time_pre_key: Option<PublicKey>,
15    their_ratchet_key: PublicKey,
16    their_kyber_pre_key: kem::PublicKey,
17}
18
19impl AliceSignalProtocolParameters {
20    pub fn new(
21        our_identity_key_pair: IdentityKeyPair,
22        our_base_key_pair: KeyPair,
23        their_identity_key: IdentityKey,
24        their_signed_pre_key: PublicKey,
25        their_ratchet_key: PublicKey,
26        their_kyber_pre_key: kem::PublicKey,
27    ) -> Self {
28        Self {
29            our_identity_key_pair,
30            our_base_key_pair,
31            their_identity_key,
32            their_signed_pre_key,
33            their_one_time_pre_key: None,
34            their_ratchet_key,
35            their_kyber_pre_key,
36        }
37    }
38
39    pub fn set_their_one_time_pre_key(&mut self, ec_public: PublicKey) {
40        self.their_one_time_pre_key = Some(ec_public);
41    }
42
43    pub fn with_their_one_time_pre_key(mut self, ec_public: PublicKey) -> Self {
44        self.set_their_one_time_pre_key(ec_public);
45        self
46    }
47
48    #[inline]
49    pub fn our_identity_key_pair(&self) -> &IdentityKeyPair {
50        &self.our_identity_key_pair
51    }
52
53    #[inline]
54    pub fn our_base_key_pair(&self) -> &KeyPair {
55        &self.our_base_key_pair
56    }
57
58    #[inline]
59    pub fn their_identity_key(&self) -> &IdentityKey {
60        &self.their_identity_key
61    }
62
63    #[inline]
64    pub fn their_signed_pre_key(&self) -> &PublicKey {
65        &self.their_signed_pre_key
66    }
67
68    #[inline]
69    pub fn their_one_time_pre_key(&self) -> Option<&PublicKey> {
70        self.their_one_time_pre_key.as_ref()
71    }
72
73    #[inline]
74    pub fn their_kyber_pre_key(&self) -> &kem::PublicKey {
75        &self.their_kyber_pre_key
76    }
77
78    #[inline]
79    pub fn their_ratchet_key(&self) -> &PublicKey {
80        &self.their_ratchet_key
81    }
82}
83
84pub struct BobSignalProtocolParameters<'a> {
85    our_identity_key_pair: IdentityKeyPair,
86    our_signed_pre_key_pair: KeyPair,
87    our_one_time_pre_key_pair: Option<KeyPair>,
88    our_ratchet_key_pair: KeyPair,
89    our_kyber_pre_key_pair: kem::KeyPair,
90
91    their_identity_key: IdentityKey,
92    their_base_key: PublicKey,
93    their_kyber_ciphertext: &'a kem::SerializedCiphertext,
94}
95
96impl<'a> BobSignalProtocolParameters<'a> {
97    #[allow(clippy::too_many_arguments)]
98    pub fn new(
99        our_identity_key_pair: IdentityKeyPair,
100        our_signed_pre_key_pair: KeyPair,
101        our_one_time_pre_key_pair: Option<KeyPair>,
102        our_ratchet_key_pair: KeyPair,
103        our_kyber_pre_key_pair: kem::KeyPair,
104        their_identity_key: IdentityKey,
105        their_base_key: PublicKey,
106        their_kyber_ciphertext: &'a kem::SerializedCiphertext,
107    ) -> Self {
108        Self {
109            our_identity_key_pair,
110            our_signed_pre_key_pair,
111            our_one_time_pre_key_pair,
112            our_ratchet_key_pair,
113            our_kyber_pre_key_pair,
114            their_identity_key,
115            their_base_key,
116            their_kyber_ciphertext,
117        }
118    }
119
120    #[inline]
121    pub fn our_identity_key_pair(&self) -> &IdentityKeyPair {
122        &self.our_identity_key_pair
123    }
124
125    #[inline]
126    pub fn our_signed_pre_key_pair(&self) -> &KeyPair {
127        &self.our_signed_pre_key_pair
128    }
129
130    #[inline]
131    pub fn our_one_time_pre_key_pair(&self) -> Option<&KeyPair> {
132        self.our_one_time_pre_key_pair.as_ref()
133    }
134
135    #[inline]
136    pub fn our_ratchet_key_pair(&self) -> &KeyPair {
137        &self.our_ratchet_key_pair
138    }
139
140    #[inline]
141    pub fn our_kyber_pre_key_pair(&self) -> &kem::KeyPair {
142        &self.our_kyber_pre_key_pair
143    }
144
145    #[inline]
146    pub fn their_identity_key(&self) -> &IdentityKey {
147        &self.their_identity_key
148    }
149
150    #[inline]
151    pub fn their_base_key(&self) -> &PublicKey {
152        &self.their_base_key
153    }
154
155    #[inline]
156    pub fn their_kyber_ciphertext(&self) -> &kem::SerializedCiphertext {
157        self.their_kyber_ciphertext
158    }
159}