You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
scauligi edited this page Mar 19, 2018
·
1 revision
All of the following snippets are constant-time C code, and use the macros found here.
// Assignment based on a secret conditionvoidselecting_things(uint32_tcond) {
intx=const_select(cond, 42, 137);
}
// Accessing a secret index in a buffervoiduse_secret_index(constuint8_t*buf, uint32_tbuf_len, uint32_tindex) {
for (inti=0; i<buf_len; i++) {
uint32_tmask=const_eq(i, index);
uint8_tb=const_select(mask, buf[i], 0);
}
}
// Ending computation "early"intcontains_17(constint*arr, uint32_tarr_len) {
uint32_tdone=0;
for (inti=0; i<arr_len; i++) {
uint32_tmask=const_eq(arr[i], 17);
// if mask is "true", then set done to "true"// otherwise leave done as-isdone=done | mask;
}
returnconst_select(done, 1, 0);
}