Skip to content

Commit b7e3882

Browse files
committed
Add metadata to Cargo.toml
1 parent 64463e2 commit b7e3882

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
name = "ct"
33
version = "0.1.0"
44
authors = ["Łukasz Niemier <[email protected]>"]
5+
6+
description = "Constatn time numeric operations in Rust"
7+
license = "MIT"
8+
9+
repository = "https://github.com/hauleth/ct"

src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ use std::mem::size_of;
44
#[derive(Clone, Copy, Debug)]
55
pub struct Ct<T>(T);
66

7+
impl<T> Ct<T> where T: Neg<Output=T> + BitAnd<Output=T> + BitXor<Output=T> + Copy {
8+
pub fn select(self, a: T, b: T) -> Self {
9+
let mask = -self;
10+
let ret = mask & (a ^ b);
11+
ret ^ a
12+
}
13+
}
14+
715
macro_rules! implement {
816
(Eq for $($t:ty),*) => {
917
$(
@@ -32,6 +40,11 @@ macro_rules! implement {
3240

3341
fn $fun(self, other: Self) -> Self::Output { Ct($t::$fun(self.0, other.0)) }
3442
}
43+
impl<$t> $op<$t> for Ct<$t> where $t: $op {
44+
type Output = Ct<$t::Output>;
45+
46+
fn $fun(self, other: $t) -> Self::Output { Ct($t::$fun(self.0, other)) }
47+
}
3548
};
3649
(unary $op:ident for Ct<$t:ident> with $fun:ident) => {
3750
impl<$t> $op for Ct<$t> where $t: $op {

0 commit comments

Comments
 (0)