Skip to content

Commit

Permalink
Fix stack array access in Keccak OR.
Browse files Browse the repository at this point in the history
  • Loading branch information
J08nY committed Feb 27, 2024
1 parent 21f73cd commit 4c5cdba
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/common/keccak/keccak1600/amd64/bmi1/keccakf1600.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline fn __theta_rol_bmi1(reg u64[5] c) -> reg u64[5]
t = d[x];
?{}, t = #SHL_64(t, 1);
?{}, d[x] = #SHR_64(d[x], 63);
?{}, d[x] = #OR(t, d[x]);
?{}, d[x] = #OR_64(t, d[x]);

// D[x] ^= C[x-1]
d[x] ^= c[(x - 1 + 5) % 5];
Expand Down Expand Up @@ -81,7 +81,7 @@ inline fn __rol_sum_bmi1(
t = b[x];
?{}, t = #SHL_64(t, r);
?{}, b[x] = #SHR_64(b[x], 64 - r);
?{}, b[x] = #OR(t, b[x]);
?{}, b[x] = #OR_64(t, b[x]);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/common/keccak/keccak1600/amd64/ref/keccakf1600.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inline fn __theta_rol_ref(reg u64[5] c) -> reg u64[5]
t = d[x];
?{}, t = #SHL_64(t, 1);
?{}, d[x] = #SHR_64(d[x], 63);
?{}, d[x] = #OR(t, d[x]);
?{}, d[x] = #OR_64(t, d[x]);

// D[x] ^= C[x-1]
d[x] ^= c[(x - 1 + 5) % 5];
Expand Down Expand Up @@ -81,7 +81,7 @@ inline fn __rol_sum_ref(
t = b[x];
?{}, t = #SHL_64(t, r);
?{}, b[x] = #SHR_64(b[x], 64 - r);
?{}, b[x] = #OR(t, b[x]);
?{}, b[x] = #OR_64(t, b[x]);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/common/keccak/keccak1600/amd64/ref/keccakf1600_v0.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ inline fn __ROL64(reg u64 x, inline int c) -> reg u64
// _, _, y = #ROL_64(x, c);
?{}, y = #SHL_64(x, c);
?{}, x = #SHR_64(x, 64 - c);
?{}, y = #OR(y, x);
?{}, y = #OR_64(y, x);
}
return y;
}
Expand Down
5 changes: 3 additions & 2 deletions src/common/keccak/keccak1600/amd64/spec/keccakf1600.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inline fn __theta_spec(stack u64[25] a) -> stack u64[25]
t = d[x];
?{}, t = #SHL_64(t, 1);
?{}, d[x] = #SHR_64(d[x], 63);
?{}, d[x] = #OR(t, d[x]);
?{}, d[x] = #OR_64(t, d[x]);

d[x] ^= c[(x + 4) % 5];
}
Expand Down Expand Up @@ -88,7 +88,8 @@ inline fn __rho_spec(stack u64[25] a) -> stack u64[25]
t = a[i];
?{}, t = #SHL_64(t, z);
?{}, a[i] = #SHR_64(a[i], 64 - z);
?{}, a[i] = #OR(t, a[i]);
?{}, t = #OR_64(t, a[i]);
a[i] = t;
}
}

Expand Down

0 comments on commit 4c5cdba

Please sign in to comment.