Skip to content

Commit dc4f0e8

Browse files
authored
Merge pull request #39008 from cuviper/beta-blake-endian
Backport #38960 to beta
2 parents a035041 + f3639ac commit dc4f0e8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/librustc_data_structures/blake2b.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,20 @@ fn blake2b_compress(ctx: &mut Blake2bCtx, last: bool) {
113113
}
114114

115115
{
116-
// Re-interpret the input buffer in the state as u64s
116+
// Re-interpret the input buffer in the state as an array
117+
// of little-endian u64s, converting them to machine
118+
// endianness. It's OK to modify the buffer in place
119+
// since this is the last time this data will be accessed
120+
// before it's overwritten.
121+
117122
let m: &mut [u64; 16] = unsafe {
118123
let b: &mut [u8; 128] = &mut ctx.b;
119124
::std::mem::transmute(b)
120125
};
121126

122-
// It's OK to modify the buffer in place since this is the last time
123-
// this data will be accessed before it's overwritten
124127
if cfg!(target_endian = "big") {
125128
for word in &mut m[..] {
126-
*word = word.to_be();
129+
*word = u64::from_le(*word);
127130
}
128131
}
129132

@@ -209,9 +212,10 @@ fn blake2b_final(ctx: &mut Blake2bCtx)
209212

210213
blake2b_compress(ctx, true);
211214

215+
// Modify our buffer to little-endian format as it will be read
216+
// as a byte array. It's OK to modify the buffer in place since
217+
// this is the last time this data will be accessed.
212218
if cfg!(target_endian = "big") {
213-
// Make sure that the data is in memory in little endian format, as is
214-
// demanded by BLAKE2
215219
for word in &mut ctx.h {
216220
*word = word.to_le();
217221
}

0 commit comments

Comments
 (0)