Skip to content

Commit

Permalink
cksum/crc32: add code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarzik committed Mar 8, 2024
1 parent 96a93ae commit 1b70eec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions xform/src/crc32.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//

// Data straight from POSIX documentation
const CRCTAB: [u32; 256] = [
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
Expand Down Expand Up @@ -33,6 +43,9 @@ const CRCTAB: [u32; 256] = [
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4,
];

// Almost directly as presented in POSIX documentation

// Update CRC with given data.
pub fn update(crc_in: u32, buf: &[u8]) -> u32 {
let mut s = crc_in;

Expand All @@ -44,6 +57,7 @@ pub fn update(crc_in: u32, buf: &[u8]) -> u32 {
s
}

// Finalize crc with data size.
pub fn finalize(crc_in: u32, n_in: usize) -> u32 {
let mut s = crc_in;
let mut n = n_in;
Expand Down

0 comments on commit 1b70eec

Please sign in to comment.