Skip to content

Commit 8c182ef

Browse files
committed
use split_at in SQIsign read
1 parent fe9407f commit 8c182ef

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/protocols/sqisign.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,11 @@ impl<Fq: FqTrait> Sqisign<Fq> {
139139
}
140140

141141
// Decode all but the last bytes for the Montgomery coefficient A
142-
let pk_curve_bytes = &buf[..Fq::ENCODED_LENGTH];
142+
let (pk_curve_bytes, buf) = buf.split_at(Fq::ENCODED_LENGTH);
143143
let curve = Self::decode_curve(pk_curve_bytes)?;
144144

145145
// The remaining byte is the hint for the torsion basis generation
146-
let hint = *buf.last().unwrap();
146+
let hint = buf[0];
147147

148148
Ok(SqisignPublicKey { curve, hint })
149149
}
@@ -165,37 +165,30 @@ impl<Fq: FqTrait> Sqisign<Fq> {
165165
});
166166
}
167167

168-
// Extract out all the buffer bytes into slices.
169-
let mut read = Fq::ENCODED_LENGTH;
170-
171168
// Extract the bytes for the auxiliary curve
172-
let aux_bytes = &buf[..read];
169+
let (aux_bytes, buf) = buf.split_at(Fq::ENCODED_LENGTH);
173170
let aux_curve = Self::decode_curve(aux_bytes)?;
174171

175172
// Extract the two u8 to track backtracking and r such that the
176173
// response length is 2^r.
177-
let backtracking = buf[read] as usize;
178-
read += 1;
179-
let two_resp_length = buf[Fq::ENCODED_LENGTH + 1] as usize;
180-
read += 1;
174+
let backtracking = buf[0] as usize;
175+
let two_resp_length = buf[1] as usize;
176+
let (_, buf) = buf.split_at(2);
181177

182178
// Extract out the four scalars used for the change of basis
183179
let mut aij: [&[u8]; 4] = Default::default();
180+
let (mut aij_buf, buf) = buf.split_at(4 * aij_n_bytes);
184181
for i in 0..4 {
185-
aij[i] = &buf[read..read + aij_n_bytes];
186-
read += aij_n_bytes;
182+
(aij[i], aij_buf) = aij_buf.split_at(aij_n_bytes);
187183
}
188184

189185
// Extract out the challenge bytes used to create the chl kernel
190-
let chl_scalar = &buf[read..read + chl_n_bytes];
191-
read += chl_n_bytes;
186+
let (chl_scalar, buf) = buf.split_at(chl_n_bytes);
192187

193188
// Extract out the final two bytes, used for torsion basis on E_aux
194189
// and E_chl
195-
let hint_aux = buf[read];
196-
read += 1;
197-
let hint_chl = buf[read];
198-
assert!(read + 1 == buf.len());
190+
let hint_aux = buf[0];
191+
let hint_chl = buf[1];
199192

200193
Ok(SqisignSignature {
201194
aux_curve,

0 commit comments

Comments
 (0)