···77 ops,
88};
991010+/// Private integer representations for Role, to allow for better constant time compat.
1111+mod role {
1212+ pub const SENDER: u8 = 0;
1313+ pub const RECEIVER: u8 = 1;
1414+}
1515+1616+/// Public API for passing in Role
1017#[derive(Debug, Clone, Copy, PartialEq, Eq)]
1118#[repr(u8)]
1219pub enum Role {
1320 Sender,
1421 Receiver,
1515-}
1616-1717-impl CtEq for Role {
1818- fn ct_eq(&self, other: &Self) -> Choice {
1919- (*self as u8).ct_eq(&(*other as u8))
2020- }
2122}
22232324#[derive(Debug, Clone, Copy)]
···4041 /// Index into `state`
4142 start: usize,
4243 /// Represents whether we're a sender or a receiver
4343- role: Role,
4444+ role: u8,
4445 /// The last operation performed. This is to verify that the `more` flag is only used across
4546 /// identical operations.
4647 prev_flags: OpFlags,
···122123 rate,
123124 position: 0,
124125 start: 0,
125125- role,
126126+ role: role as u8,
126127 prev_flags: OpFlags::EMPTY,
127128 };
128129···264265 /// sending or receiving
265266 fn begin_op(&mut self, mut flags: OpFlags) {
266267 if flags.contains(OpFlags::TRANSPORT).to_bool() {
267267- let op_role = if flags.contains(OpFlags::INBOUND).to_bool() {
268268- Role::Receiver
269269- } else {
270270- Role::Sender
271271- };
268268+ let op_role = role::SENDER.ct_select(&role::RECEIVER, flags.contains(OpFlags::INBOUND));
272269273270 // So that the sender and receiver agree, toggle the I flag as necessary
274271 flags.set(OpFlags::INBOUND, self.role.ct_ne(&op_role));
···305302 // Flags that don't pass this assertion should normally call `absorb`, but `absorb` does not mutate,
306303 // so the implementor should have used operate_no_mutate instead
307304 // RATCHET is special-cased to never call operate directly
308308- debug_assert!(flags != ops::KEY && bool::from(flags.contains(OpFlags::CIPHER)));
305305+ debug_assert!(flags != ops::KEY && flags.contains(OpFlags::CIPHER).to_bool());
309306310307 const SPECIAL_CASES: [OpFlags; 3] = [ops::PRF, ops::SEND_MAC, ops::SEND_ENC];
311308 const OPS: [fn(&mut StrobeState, data: &mut [u8]); 4] = [
···343340344341 // Flags that trigger the assertion to fail are mutating operations.
345342 // RATCHET is special cased to never call operate/operate_no_mutate directly
346346- debug_assert!(flags == ops::KEY || !bool::from(flags.contains(OpFlags::CIPHER)));
343343+ debug_assert!(flags == ops::KEY || !flags.contains(OpFlags::CIPHER).to_bool());
347344348345 const OPS: [fn(&mut StrobeState, data: &[u8]); 2] =
349346 [StrobeState::absorb, StrobeState::overwrite];