@@ -204,75 +204,81 @@ fn sha256_digest_block_u32(state: &mut [u32; 8], block: &[u32; 16]) {
204
204
/// digest calculation. The schedule-related instructions allow 4 rounds to be
205
205
/// calculated as:
206
206
///
207
- /// ```compile_fail
208
- /// use std::simd::u32x4;
209
- /// use self::crypto::sha2::{
210
- /// sha256msg1,
211
- /// sha256msg2,
212
- /// sha256load
213
- /// };
207
+ /// ```ignore
208
+ /// // Pseudocode showing how Intel SHA extensions would work with SIMD vectors
209
+ /// // (not actual sha2raw API - for illustration only)
214
210
///
215
- /// fn schedule4_data(work: &mut [ u32x4], w: & [u32]) {
211
+ /// type u32x4 = [u32; 4]; // Represents a SIMD vector
216
212
///
217
- /// // this is to illustrate the data order
218
- /// work[0] = u32x4(w[3], w[2], w[1], w[0]);
219
- /// work[1] = u32x4(w[7], w[6], w[5], w[4]);
220
- /// work[2] = u32x4(w[11], w[10], w[9], w[8]);
221
- /// work[3] = u32x4(w[15], w[14], w[13], w[12]);
213
+ /// fn schedule4_data(work: &mut [u32x4], w: &[u32]) {
214
+ /// // Intel SHA extensions operate on 4 words at a time
215
+ /// work[0] = [w[3], w[2], w[1], w[0]];
216
+ /// work[1] = [w[7], w[6], w[5], w[4]];
217
+ /// work[2] = [w[11], w[10], w[9], w[8]];
218
+ /// work[3] = [w[15], w[14], w[13], w[12]];
222
219
/// }
223
220
///
224
221
/// fn schedule4_work(work: &mut [u32x4], t: usize) {
225
- ///
226
- /// // this is the core expression
227
- /// work[t] = sha256msg2(sha256msg1(work[t - 4], work[t - 3]) +
228
- /// sha256load(work[t - 2], work[t - 1]),
229
- /// work[t - 1])
222
+ /// // The SHA256MSG1/2 instructions compute 4 message schedule words
223
+ /// // This is pseudocode for what the CPU instructions do internally
224
+ /// work[t] = sha256msg2(
225
+ /// sha256msg1(work[t - 4], work[t - 3]) + work[t - 2],
226
+ /// work[t - 1]
227
+ /// )
230
228
/// }
231
229
/// ```
232
230
///
233
231
/// instead of 4 rounds of:
234
232
///
235
- /// ```compile_fail
233
+ /// ```ignore
234
+ /// // Traditional SHA-256 message schedule (one word at a time)
236
235
/// fn schedule_work(w: &mut [u32], t: usize) {
237
- /// w[t] = sigma1!(w[t - 2]) + w[t - 7] + sigma0!(w[t - 15]) + w[t - 16];
236
+ /// // sigma0 and sigma1 are the message schedule functions
237
+ /// w[t] = sigma1(w[t - 2]) + w[t - 7] + sigma0(w[t - 15]) + w[t - 16];
238
238
/// }
239
239
/// ```
240
240
///
241
241
/// and the digest-related instructions allow 4 rounds to be calculated as:
242
242
///
243
- /// ```compile_fail
244
- /// use std::simd::u32x4;
245
- /// use self::crypto::sha2::{K32X4,
246
- /// sha256rnds2,
247
- /// sha256swap
248
- /// } ;
243
+ /// ```ignore
244
+ /// // Pseudocode showing how Intel SHA extensions process 4 rounds at once
245
+ /// // (not actual sha2raw API - for illustration only)
246
+ ///
247
+ /// type u32x4 = [u32; 4]; // Represents a SIMD vector
248
+ /// const K32X4: [[u32; 4]; 16] = /* round constants */ ;
249
249
///
250
250
/// fn rounds4(state: &mut [u32; 8], work: &mut [u32x4], t: usize) {
251
- /// let [a, b, c, d, e, f, g, h]: [u32; 8] = *state;
251
+ /// let [a, b, c, d, e, f, g, h] = *state;
252
252
///
253
- /// // this is to illustrate the data order
254
- /// let mut abef = u32x4( a, b, e, f) ;
255
- /// let mut cdgh = u32x4( c, d, g, h) ;
256
- /// let temp = K32X4[t] + work[t];
253
+ /// // Intel SHA extensions pack state into two vectors
254
+ /// let mut abef = [ a, b, e, f] ;
255
+ /// let mut cdgh = [ c, d, g, h] ;
256
+ /// let temp = add_vectors( K32X4[t], work[t]) ;
257
257
///
258
- /// // this is the core expression
258
+ /// // SHA256RNDS2 performs 2 rounds of SHA-256
259
259
/// cdgh = sha256rnds2(cdgh, abef, temp);
260
260
/// abef = sha256rnds2(abef, cdgh, sha256swap(temp));
261
261
///
262
- /// *state = [abef.0, abef.1, cdgh.0, cdgh.1,
263
- /// abef.2, abef.3, cdgh.2, cdgh.3];
262
+ /// // Unpack back to state array
263
+ /// *state = [abef[0], abef[1], cdgh[0], cdgh[1],
264
+ /// abef[2], abef[3], cdgh[2], cdgh[3]];
264
265
/// }
265
266
/// ```
266
267
///
267
268
/// instead of 4 rounds of:
268
269
///
269
- /// ```compile_fail
270
- /// fn round(state: &mut [u32; 8], w: &mut [u32], t: usize) {
271
- /// let [a, b, c, mut d, e, f, g, mut h]: [u32; 8] = *state;
270
+ /// ```ignore
271
+ /// // Traditional SHA-256 round function (one round at a time)
272
+ /// // This is closer to what sha2raw actually implements
273
+ /// fn round(state: &mut [u32; 8], w: &[u32], t: usize) {
274
+ /// let [a, b, c, mut d, e, f, g, mut h] = *state;
272
275
///
273
- /// h += big_sigma1!(e) + choose!(e, f, g) + K32[t] + w[t]; d += h;
274
- /// h += big_sigma0!(a) + majority!(a, b, c);
276
+ /// // SHA-256 round operations using the functions defined in this module
277
+ /// h += big_sigma1(e) + choose(e, f, g) + K32[t] + w[t];
278
+ /// d += h;
279
+ /// h += big_sigma0(a) + majority(a, b, c);
275
280
///
281
+ /// // Rotate the state
276
282
/// *state = [h, a, b, c, d, e, f, g];
277
283
/// }
278
284
/// ```
0 commit comments