Skip to content

Commit c2281f8

Browse files
authored
Fix compress function (#6)
* fix: removed message argument from assert * fix: correct Montgomery form handling in compress
1 parent f1eda8f commit c2281f8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

build.zig.zon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@
1515
"VERSION",
1616
},
1717
}
18-

src/poseidon2/poseidon2.zig

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,24 @@ pub fn Poseidon2(
3030
pub const State = [width]F.MontFieldElem;
3131

3232
pub fn compress(comptime output_len: comptime_int, input: [width]F.FieldElem) [output_len]F.FieldElem {
33-
assert(output_len <= width, "output_len must be <= width");
33+
assert(output_len <= width);
3434

3535
var state: State = undefined;
3636
inline for (0..width) |i| {
3737
F.toMontgomery(&state[i], input[i]);
3838
}
3939
permutation(&state);
4040
inline for (0..width) |i| {
41-
F.add(&state[i], state[i], input[i]);
42-
F.fromMontgomery(&state[i], state[i]);
41+
var input_mont: F.MontFieldElem = undefined;
42+
F.toMontgomery(&input_mont, input[i]);
43+
F.add(&state[i], state[i], input_mont);
4344
}
44-
return state[0..output_len];
45+
46+
var result: [output_len]F.FieldElem = undefined;
47+
inline for (0..output_len) |i| {
48+
result[i] = F.toNormal(state[i]);
49+
}
50+
return result;
4551
}
4652

4753
pub fn permutation(state: *State) void {

0 commit comments

Comments
 (0)