diff --git a/README.md b/README.md index d297141..acca648 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ Why use `hashit`? - You can get multiple hashes "for free" on any CPU with multiple cores - Works very well across multiple platforms without slowdown (Windows, Linux, macOS) - Builds on illumos and Solaris, without the `sqlite` format, auditing SQLite databases or `--progress`, as the libraries they use do not support those platforms - - Supports many hashes `hashit --hashes` CRC32, xxHash64, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, Blake2b-256, Blake2b-512, Blake3, SHA3-224, SHA3-256, SHA3-384, SHA3-512, ed2k. Select them with `--hash` using the lowercase names shown in brackets by `hashit --hashes`, such as `sha3256` or `blake2b256`, or `--hash all`. The `ed2k` hash of a file which is an exact multiple of 9,728,000 bytes uses the variant without an extra empty chunk, so differs from tools such as `rhash` for those sizes + - Supports many hashes `hashit --hashes` CRC32, xxHash64, MD4, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, Blake2b-256, Blake2b-512, Blake3, SHA3-224, SHA3-256, SHA3-384, SHA3-512, ed2k, Tiger, Whirlpool. Select them with `--hash` using the lowercase names shown in brackets by `hashit --hashes`, such as `sha3256` or `blake2b256`, or `--hash all`. Whirlpool is about ten times slower than SHA512, so `--hash all` takes much longer on large files than it did without it. The `ed2k` hash of a file which is an exact multiple of 9,728,000 bytes uses the variant without an extra empty chunk, so differs from tools such as `rhash` for those sizes - Output is compatible with `hashdeep`, and audits can be verified by either tool (see [Absolute Paths](#absolute-paths)) ### Usage @@ -162,6 +162,8 @@ Blake2b-512 ad692390b5e680f24490d5f4676f279f84e802c79b98ef36369404b88d8ced237dbd SHA3-384 8301eb66f20215a14a77aa6e977a9d08524caf31fa09a9fd97e7b3c4c3e9266159d9c35c661960024654ff36f5131302 SHA3-512 1024928532bccfe9feb0b3f9fe54eda6fb05685fb3236eb09cb3765f0d1face3ea5f5dc681aaeec44134cd89691348a03cc6a2abfe1eae55d8eb274a51f97e3d ed2k a4961e3d704e28a40debbf1f1e4a62cd + Tiger 8461dc5bd991619db31c3fb2b6a1dd451cf64086ad12ce68 + Whirlpool 3166f9a5ecf7ff1992e792c39cd7ad52a1b5079447a96e96d506a964bb4be956ee78d98d85948296967de031913399ad2d7e821f3a9fd478bf7ee659918949f2 $ mkdir -p example/sub && echo hello > example/a.txt && echo world > example/sub/b.txt $ hashit --hash md5 example @@ -189,7 +191,7 @@ Files are processed in parallel, so the order of the output may vary between run `--format` (`-f`) selects the output format. Results are written to standard output, or to a file with `--output` (`-o`). The output file is written to a temporary file next to it first, so the directory must be writable, being the directory of the file a symbolic link points to when `--output` is one, and an existing file is only replaced with `--overwrite`, is never replaced when it is a directory or other special file, and is kept rather than replaced when any error occurred. A new output file is still written when errors occurred, so it may not contain every file. A replaced file keeps its permission bits, but not its owner, special bits such as setuid, or extended attributes. When `--output` is a symbolic link the file it points to is replaced, and a symbolic link which cannot be followed, such as a loop or a link to a file which does not exist, is refused. The replacement is a new file, so other hard links to the old file keep the old content. If `hashit` is interrupted by `SIGINT`, `SIGTERM`, `SIGHUP`, `SIGQUIT` or `SIGPIPE` the temporary file is removed and it exits with 128 plus the signal number, such as `130` for `SIGINT`. A signal which was ignored when `hashit` started, such as `SIGHUP` under `nohup`, stays ignored. Other signals such as `SIGUSR1` are ignored, and `SIGKILL` cannot be caught, so leaves the temporary file behind. The message `results written to` is printed to standard output. The output file, the audit file, and paths reaching them through a symbolic link, either a link to the file or a symbolically linked directory, are never included in the results. Another hard link to the output file is ordinary data and is included. Supplying one of them explicitly, such as with a wildcard like `hashit -a sums.md5 *`, skips it with a `WARN`. When the only files supplied were the output or audit file an existing output file is kept rather than replaced with empty results, so `hashit -o doc.txt --overwrite doc.txt` is an error. Without `--overwrite` a file created at the output path while `hashit` was running, such as by another run writing the same output, is not replaced, and the new results are discarded with an error. - `text`, the default, shown above. `--mtime` adds an `MTime` line in local time. -- `json`, an array of objects such as `[{"File":"example/a.txt","MD5":"b1946ac92492d2347c6235b4d2611184","Bytes":6}]`. The keys are `File`, `CRC32`, `XxHash64`, `MD4`, `MD5`, `SHA1`, `SHA224`, `SHA256`, `SHA384`, `SHA512`, `Blake2b256`, `Blake2b512`, `Blake3`, `Sha3224`, `Sha3256`, `Sha3384`, `Sha3512`, `ed2k` and `Bytes`. Hashes which were not calculated are omitted. `--mtime` adds `MTime` in RFC 3339 format with nanoseconds and the local time zone. +- `json`, an array of objects such as `[{"File":"example/a.txt","MD5":"b1946ac92492d2347c6235b4d2611184","Bytes":6}]`. The keys are `File`, `CRC32`, `XxHash64`, `MD4`, `MD5`, `SHA1`, `SHA224`, `SHA256`, `SHA384`, `SHA512`, `Blake2b256`, `Blake2b512`, `Blake3`, `Sha3224`, `Sha3256`, `Sha3384`, `Sha3512`, `ed2k`, `Tiger`, `Whirlpool` and `Bytes`. Hashes which were not calculated are omitted. `--mtime` adds `MTime` in RFC 3339 format with nanoseconds and the local time zone. - `sum`, the same as `md5sum` and similar tools, with one line per hash per file when several hashes are selected. `--mtime` adds a `# mtime` comment line, see [Auditing with sum Files](#auditing-with-sum-files). - `hashdeep`, see [Auditing](#auditing). `--mtime` adds a `## mtime` comment line, see [Modification Times](#modification-times). - `hashonly`, one hash per line. With several hashes or files there is nothing to say which hash belongs to which file, so it is best used with a single hash and file. `--mtime` adds the time on its own line. @@ -253,7 +255,7 @@ In this case, `hashit` would process `main.go` (and the `.hashignore` file itsel `hashit` provides a powerful auditing feature that is compatible with `hashdeep`. This allows you to verify the integrity of a set of files by comparing their current state against a previously generated list of known hashes. -You can use `hashit` to generate an audit file and have `hashdeep` verify it, or use `hashdeep` to generate the audit file and have `hashit` verify it. +You can use `hashit` to generate an audit file and have `hashdeep` verify it, or use `hashdeep` to generate the audit file and have `hashit` verify it. `hashit` can audit a `hashdeep` file made with any of the hashes `hashdeep` writes: MD5, SHA1, SHA256, Tiger and Whirlpool. `hashdeep` before 4.2 (2012) calculated Tiger wrongly for large files, so a file it wrote with a Tiger column may report those files as modified, by `hashit` and by current versions of `hashdeep` alike, and needs writing again. #### Generating an Audit File @@ -265,6 +267,8 @@ $ hashit --format hashdeep processor > audit.txt This will create a file named `audit.txt` containing the hashes of the files in the `processor` directory. +Like `hashdeep`, it holds MD5 and SHA256 unless `-c` chooses others. It can hold any of the hashes `hashdeep` writes, MD5, SHA1, SHA256, Tiger and Whirlpool, in that order, so `hashit --format hashdeep -c sha256,tiger processor` writes SHA256 and Tiger. Other hashes are left out with a warning, and if none of the chosen hashes can be held, MD5 and SHA256 are written. + #### Verifying with `hashdeep` You can then use `hashdeep` to audit a directory against the file generated by `hashit`. @@ -305,6 +309,69 @@ Known files expecting: 14 Files missing: 0 ``` +#### Tiger and Whirlpool + +`hashdeep` calculates five hashes: MD5, SHA1, SHA256, Tiger and Whirlpool. It also ships as `tigerdeep` and `whirlpooldeep`, which write only one of them. Collections catalogued with those tools, such as forensic case files and archives, may hold only Tiger or Whirlpool, chosen as both come from outside the MD5 and SHA family. Tiger is a fast 192 bit hash, and Whirlpool is a 512 bit hash standardised in ISO/IEC 10118-3. `hashit` calculates both, so it can audit any file those tools write, and write files they can audit, without converting them or calculating the hashes again. + +Whirlpool is about ten times slower than SHA512, so only choose it when another tool or an existing catalogue needs it. + +To audit a `hashdeep` file holding Tiger and Whirlpool with `hashit`: + +```shell +$ hashdeep -c tiger,whirlpool -r -l photos > photos.hd +$ head -2 photos.hd +%%%% HASHDEEP-1.0 +%%%% size,tiger,whirlpool,filename + +$ hashit -a photos.hd photos +hashit: Audit passed + Files examined: 2 +Known files expecting: 2 + Files matched: 2 + Files modified: 0 + Files moved: 0 + New files found: 0 + Files missing: 0 +``` + +To write a `hashdeep` file with Tiger for `hashdeep` to audit, or every `hashdeep` hash with `-c all`: + +```shell +$ hashit -f hashdeep -c sha256,tiger photos > photos.hd +$ head -2 photos.hd +%%%% HASHDEEP-1.0 +%%%% size,sha256,tiger,filename + +$ hashdeep -r -l -a -k photos.hd photos +hashdeep: Audit passed + +$ hashit -f hashdeep -c all photos | head -2 | tail -1 +%%%% size,md5,sha1,sha256,tiger,whirlpool,filename +``` + +`tigerdeep` output can be audited as it is, as a hash of 48 characters can only be Tiger. A Whirlpool hash is 128 characters, as long as a SHA512 hash, so give `whirlpooldeep` output a `.whirlpool` extension: + +```shell +$ tigerdeep -r -l photos > photos.tiger +$ hashit -a photos.tiger photos +hashit: Audit passed + +$ whirlpooldeep -r -l photos > photos.whirlpool +$ hashit -a photos.whirlpool photos +hashit: Audit passed +``` + +Both match the hashes `hashdeep` and `rhash` calculate: + +```shell +$ hashit -c tiger,whirlpool photos/a.txt +photos/a.txt (6 bytes) + Tiger b529747e5337b97818c401dd266799a693165013ce146cac + Whirlpool 63f8341c1720d76087bb66a8f3fc9ea21a279edeae866a3611ba425cbd9ac9a4e39b97066b492fed6037988a72a045344c8675107e6bb569276c2f597ea9cbb7 +``` + +Here `photos/a.txt` holds `hello` and a newline. + #### Understanding Audit Results `hashit`'s audit output is designed to be similar to `hashdeep`'s verbose output, providing a clear summary of what has changed. @@ -409,7 +476,7 @@ $ hashit -a checksums.md5 . Note that `md5sum *` does not include files in subdirectories, while `hashit` audits the whole directory, so for a directory with subdirectories generate the file with something like `find -L . -type f -exec md5sum {} +`, where `-L` follows symbolic links as `hashit` does. -The hash is determined by the file extension where it is one of `.md4`, `.md5`, `.sha1`, `.sha224`, `.sha256`, `.sha384`, `.sha512`, `.sha3-224`, `.sha3-256`, `.sha3-384`, `.sha3-512`, `.b2` or `.blake2b` (Blake2b-512 or Blake2b-256), `.b3` or `.blake3`, `.ed2k`, or `.crc32`, and otherwise by the length of the hash. A hash of 8 characters is assumed to be `crc32` and one of 16 `xxhash64`. Where lengths are shared the more common hash is assumed, being `md5` over `md4` and `ed2k`, `sha224` over `sha3-224`, `sha256` over `sha3-256`, `blake3` and `b2sum -l 256`, `sha384` over `sha3-384`, and `sha512` over `sha3-512` and `b2sum`. A wrong guess reports every file as modified, so name `b2sum` files `.b2` or use `--tag` output for the others. Relative paths are resolved against both the current directory and the directory containing the sum file, so run the audit from the directory the sum file was created in, or keep the sum file at the root of the files it lists. +The hash is determined by the file extension where it is one of `.md4`, `.md5`, `.sha1`, `.sha224`, `.sha256`, `.sha384`, `.sha512`, `.sha3-224`, `.sha3-256`, `.sha3-384`, `.sha3-512`, `.b2` or `.blake2b` (Blake2b-512 or Blake2b-256), `.b3` or `.blake3`, `.ed2k`, `.tiger`, `.whirlpool`, or `.crc32`, and otherwise by the length of the hash. A hash of 8 characters is assumed to be `crc32`, one of 16 `xxhash64` and one of 48 `tiger`. Where lengths are shared the more common hash is assumed, being `md5` over `md4` and `ed2k`, `sha224` over `sha3-224`, `sha256` over `sha3-256`, `blake3` and `b2sum -l 256`, `sha384` over `sha3-384`, and `sha512` over `sha3-512`, `whirlpool` and `b2sum`. A wrong guess reports every file as modified, with a warning naming the other hashes of that length and their extensions, so name `b2sum` files `.b2` and Whirlpool files `.whirlpool`, or use `--tag` output for the others. A line whose hash is not the length of any hash its extension names, such as `b2sum -l 192` output in a `.b2` file, is not recognised rather than guessed. Relative paths are resolved against both the current directory and the directory containing the sum file, so run the audit from the directory the sum file was created in, or keep the sum file at the root of the files it lists. Likewise the output of `hashit --format sum` can be verified by `md5sum -c` and friends, so long as only a single hash is selected: @@ -437,7 +504,9 @@ This method is recommended for any large-scale or repeated auditing tasks. #### Generating a SQLite Audit Database -To generate a SQLite database of hashes, use the `--format sqlite` flag combined with `--output`. Without `--output` the database is written to `hashit.db`. It is recommended to use `--hash all` to store all possible hashes, which enables the most robust "paranoid" audit checks when the audit is also run with `--hash all`. +To generate a SQLite database of hashes, use the `--format sqlite` flag combined with `--output`. Without `--output` the database is written to `hashit.db`. It is recommended to use `--hash all` to store all possible hashes, which enables the most robust "paranoid" audit checks when the audit is also run with `--hash all`. That includes Whirlpool, which is much slower than the others, so for large collections `--hash sha512,blake3` or similar may be a better trade off. + +Databases written by `hashit` 1.5.0, before Tiger and Whirlpool were added, cannot be audited by later versions, which say so, and need to be created again. ```shell # Generate a database with all hashes for the current directory diff --git a/assets/db/migrations.sql b/assets/db/migrations.sql index 4e4da08..6f93431 100644 --- a/assets/db/migrations.sql +++ b/assets/db/migrations.sql @@ -19,6 +19,8 @@ create table if not exists file_hashes ( sha3_384 text, sha3_512 text, ed2k text, + tiger text, + whirlpool text, size integer not null, mtime text null ); diff --git a/assets/db/queries.sql b/assets/db/queries.sql index f092e7f..bb73a10 100644 --- a/assets/db/queries.sql +++ b/assets/db/queries.sql @@ -3,9 +3,9 @@ -- name: FileHashInsertReplace :one insert or replace into file_hashes ( filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, - blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, + blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime -) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) returning *; -- name: FileHashByFilePath :one diff --git a/go.mod b/go.mod index 8782e9a..b52ae93 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 github.com/djherbis/times v1.6.0 github.com/gosuri/uiprogress v0.0.1 + github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004 github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 github.com/spf13/cobra v1.10.2 github.com/zeebo/blake3 v0.2.4 diff --git a/go.sum b/go.sum index 3c46d13..f74b7e1 100644 --- a/go.sum +++ b/go.sum @@ -21,6 +21,8 @@ github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004 h1:G+9t9cEtnC9jFiTxyptEKuNIAbiN5ZCQzX2a74lj3xg= +github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004/go.mod h1:KmHnJWQrgEvbuy0vcvj00gtMqbvNn1L+3YUZLK/B92c= github.com/klauspost/cpuid/v2 v2.4.1 h1:I9KxadAkvo+QjtcEE2f2tyfEvmIla/T0m+14PrZNl0U= github.com/klauspost/cpuid/v2 v2.4.1/go.mod h1:19jmZ9mjzoF//ddRSUsv0zfBTJWh3QJh9FNxZTMrGxU= github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= diff --git a/processor/audit.go b/processor/audit.go index 7737316..f9ff26b 100644 --- a/processor/audit.go +++ b/processor/audit.go @@ -108,6 +108,8 @@ func fileHashToRecord(f database.FileHash) *AuditRecord { add(HashNames.Sha3384, f.Sha3384) add(HashNames.Sha3512, f.Sha3512) add(HashNames.Ed2k, f.Ed2k) + add(HashNames.Tiger, f.Tiger) + add(HashNames.Whirlpool, f.Whirlpool) return r } @@ -213,6 +215,14 @@ func sqliteAuditHashes(pathName string) ([]string, error) { if keyed != 1 || shadowed != 0 || withoutRowid != 0 || text != 1 || hasCollateClause(tableSQL.String) || nullPath != 0 || !strings.EqualFold(collation.String, "binary") { return nil, errors.New("audit database was not created by hashit, its file_hashes table must have a text filepath on every row as its primary key, compared exactly, and a rowid") } + // databases written before tiger and whirlpool were added, such as by 1.5.0, lack their columns + var current int + if err := db.QueryRow("select count(*) from pragma_table_info('file_hashes') where name in ('tiger', 'whirlpool')").Scan(¤t); err != nil { + return nil, err + } + if current != 2 { + return nil, errors.New("audit database was written by an older version of hashit, which this version cannot read, so create it again with this version") + } // a database of an empty directory has no records, and passes when audited against one // databases record which hashes they hold, but those from earlier development builds do not, @@ -542,7 +552,7 @@ func markSqliteDuplicates(ctx context.Context, tx *sql.Tx, base string) (int, er path := `replace(filepath, '\', '/')` values := []string{"substr(" + path + ", length(rtrim(" + path + ", replace(" + path + ", '/', ''))) + 1)"} for _, column := range []string{"crc32", "xxhash64", "md4", "md5", "sha1", "sha224", "sha256", "sha384", "sha512", - "blake2b_256", "blake2b_512", "blake3", "sha3_224", "sha3_256", "sha3_384", "sha3_512", "ed2k"} { + "blake2b_256", "blake2b_512", "blake3", "sha3_224", "sha3_256", "sha3_384", "sha3_512", "ed2k", "tiger", "whirlpool"} { values = append(values, "lower(ifnull("+column+", ''))") } key := "size || '|' || " + strings.Join(values, " || '|' || ") @@ -851,7 +861,7 @@ func judgeSqliteAudit(ctx context.Context, db *sql.DB, tx *sql.Tx, stmts *sqlite // stream every record in path order joined against what we saw, reporting as we go rows, err := db.QueryContext(ctx, `select f.filepath, f.crc32, f.xxhash64, f.md4, f.md5, f.sha1, f.sha224, f.sha256, f.sha384, f.sha512, - f.blake2b_256, f.blake2b_512, f.blake3, f.sha3_224, f.sha3_256, f.sha3_384, f.sha3_512, f.ed2k, f.size, f.mtime, + f.blake2b_256, f.blake2b_512, f.blake3, f.sha3_224, f.sha3_256, f.sha3_384, f.sha3_512, f.ed2k, f.tiger, f.whirlpool, f.size, f.mtime, s.status, s.disk_file from file_hashes f left join temp.seen s on s.filepath = f.filepath where f.rowid not in (select rid from temp.duplicates) @@ -871,7 +881,7 @@ order by f.filepath`) var status sql.NullInt64 var diskFile sql.NullString err := rows.Scan(&f.Filepath, &f.Crc32, &f.Xxhash64, &f.Md4, &f.Md5, &f.Sha1, &f.Sha224, &f.Sha256, &f.Sha384, &f.Sha512, - &f.Blake2b256, &f.Blake2b512, &f.Blake3, &f.Sha3224, &f.Sha3256, &f.Sha3384, &f.Sha3512, &f.Ed2k, + &f.Blake2b256, &f.Blake2b512, &f.Blake3, &f.Sha3224, &f.Sha3256, &f.Sha3384, &f.Sha3512, &f.Ed2k, &f.Tiger, &f.Whirlpool, &f.Size, &f.Mtime, &status, &diskFile) if err != nil { printError(fmt.Sprintf("failed to read audit database: %s", err.Error())) diff --git a/processor/audit_parser.go b/processor/audit_parser.go index 366c5f7..284ff96 100644 --- a/processor/audit_parser.go +++ b/processor/audit_parser.go @@ -53,6 +53,7 @@ type Auditor struct { source string // the audit file's contents, see reparse sourceName string // the audit file's path, see reparse excluded []string // paths passed to Exclude, see reparse + guessed []string // sum file hashes named only by their length, see GuessedHashHint } type FileStatus int @@ -65,12 +66,14 @@ const ( FileMissing ) -// hashdeepColumns maps hashdeep column names to hashit hash names. Hashdeep also supports -// tiger and whirlpool which we cannot calculate, so those columns are ignored +// hashdeepColumns maps hashdeep column names to hashit hash names, which covers every hash +// hashdeep can write var hashdeepColumns = map[string]string{ - "md5": HashNames.MD5, - "sha1": HashNames.SHA1, - "sha256": HashNames.SHA256, + "md5": HashNames.MD5, + "sha1": HashNames.SHA1, + "sha256": HashNames.SHA256, + "tiger": HashNames.Tiger, + "whirlpool": HashNames.Whirlpool, } // bsdTagNames maps the algorithm names used by the BSD style output of md5sum --tag @@ -94,29 +97,33 @@ var bsdTagNames = map[string]string{ "SHA3-256": HashNames.Sha3256, "SHA3-384": HashNames.Sha3384, "SHA3-512": HashNames.Sha3512, + "TIGER": HashNames.Tiger, + "WHIRLPOOL": HashNames.Whirlpool, } // sumExtensions maps checksum file extensions to the hashes they usually contain, which lets us // tell apart hashes of the same length such as md4 and md5. Where tools can write more than one // length, such as b2sum -l 256, the hash matching the length of the value is used var sumExtensions = map[string][]string{ - ".crc32": {HashNames.CRC32}, - ".md4": {HashNames.MD4}, - ".md5": {HashNames.MD5}, - ".sha1": {HashNames.SHA1}, - ".sha224": {HashNames.SHA224}, - ".sha256": {HashNames.SHA256}, - ".sha384": {HashNames.SHA384}, - ".sha512": {HashNames.SHA512}, - ".blake2b": {HashNames.Blake2b512, HashNames.Blake2b256}, - ".b2": {HashNames.Blake2b512, HashNames.Blake2b256}, - ".blake3": {HashNames.Blake3}, - ".sha3-224": {HashNames.Sha3224}, - ".sha3-256": {HashNames.Sha3256}, - ".sha3-384": {HashNames.Sha3384}, - ".sha3-512": {HashNames.Sha3512}, - ".b3": {HashNames.Blake3}, - ".ed2k": {HashNames.Ed2k}, + ".crc32": {HashNames.CRC32}, + ".md4": {HashNames.MD4}, + ".md5": {HashNames.MD5}, + ".sha1": {HashNames.SHA1}, + ".sha224": {HashNames.SHA224}, + ".sha256": {HashNames.SHA256}, + ".sha384": {HashNames.SHA384}, + ".sha512": {HashNames.SHA512}, + ".blake2b": {HashNames.Blake2b512, HashNames.Blake2b256}, + ".b2": {HashNames.Blake2b512, HashNames.Blake2b256}, + ".blake3": {HashNames.Blake3}, + ".sha3-224": {HashNames.Sha3224}, + ".sha3-256": {HashNames.Sha3256}, + ".sha3-384": {HashNames.Sha3384}, + ".sha3-512": {HashNames.Sha3512}, + ".b3": {HashNames.Blake3}, + ".ed2k": {HashNames.Ed2k}, + ".tiger": {HashNames.Tiger}, + ".whirlpool": {HashNames.Whirlpool}, } // sumLengths is the hash assumed for a given hex length when the file extension does not tell us @@ -125,6 +132,7 @@ var sumLengths = map[int]string{ 16: HashNames.XxHash64, 32: HashNames.MD5, 40: HashNames.SHA1, + 48: HashNames.Tiger, 56: HashNames.SHA224, 64: HashNames.SHA256, 96: HashNames.SHA384, @@ -150,16 +158,54 @@ var hashLengths = map[string]int{ HashNames.Sha3384: 96, HashNames.Sha3512: 128, HashNames.Ed2k: 32, + HashNames.Tiger: 48, + HashNames.Whirlpool: 128, } // hashPriority is the order hashes are compared and indexed in, strongest first var hashPriority = []string{ - HashNames.SHA512, HashNames.Sha3512, HashNames.Blake2b512, HashNames.SHA384, HashNames.Sha3384, - HashNames.SHA256, HashNames.Sha3256, HashNames.Blake2b256, HashNames.Blake3, - HashNames.SHA224, HashNames.Sha3224, HashNames.SHA1, HashNames.MD5, HashNames.MD4, HashNames.Ed2k, + HashNames.SHA512, HashNames.Sha3512, HashNames.Blake2b512, HashNames.Whirlpool, HashNames.SHA384, + HashNames.Sha3384, HashNames.SHA256, HashNames.Sha3256, HashNames.Blake2b256, HashNames.Blake3, + HashNames.SHA224, HashNames.Sha3224, HashNames.Tiger, HashNames.SHA1, HashNames.MD5, HashNames.MD4, HashNames.Ed2k, HashNames.XxHash64, HashNames.CRC32, } +// GuessedHashHint returns a warning for an audit where no file matched, when the sum file's hashes +// were taken from their length alone and other hashes are as long, such as whirlpool output read as +// sha512, or an empty string otherwise +func (hdl *Auditor) GuessedHashHint() string { + var hints []string + for _, name := range hdl.guessed { + var others []string + for _, other := range hashPriority { + if other == name || hashLengths[other] != hashLengths[name] { + continue + } + var exts []string + for ext, names := range sumExtensions { + if contains(names, other) { + exts = append(exts, ext) + } + } + sort.Strings(exts) + if len(exts) != 0 { + others = append(others, fmt.Sprintf("%s (%s)", other, strings.Join(exts, " or "))) + } + } + if len(others) != 0 { + list := strings.Join(others, ", ") + if len(others) > 1 { + list = strings.Join(others[:len(others)-1], ", ") + " or " + others[len(others)-1] + } + hints = append(hints, fmt.Sprintf("hashes %d long were read as %s, if they are %s, give the audit file that extension", hashLengths[name], name, list)) + } + } + if len(hints) == 0 { + return "" + } + return "no file matched the audit file; " + strings.Join(hints, "; ") +} + // NewAuditor parses the supplied audit file content. The filename is used to determine // where relative paths in a sum file are relative to and what hash a sum file contains func NewAuditor(input string, auditFilename string) (*Auditor, error) { @@ -1340,6 +1386,11 @@ func (hdl *Auditor) parseSumFile(input string, auditFilename string) error { continue } + // a GNU style line, which begins with its value, in a file whose extension does not name the hash + if len(extHashes) == 0 && strings.HasPrefix(strings.ToLower(strings.TrimPrefix(line, "\\")), value) && !contains(hdl.guessed, name) { + hdl.guessed = append(hdl.guessed, name) + } + // hashit's sum format writes one line per hash, so merge them into a single record r, exists := byFile[filename] if !exists { @@ -1394,6 +1445,11 @@ func parseSumLine(line string, extHashes []string) (string, string, string, bool break } } + // a file whose extension names its hashes is not guessed at by length, as b2sum -l 192 output + // named .b2 would be taken as tiger, and every file reported modified + if name == "" && len(extHashes) != 0 { + return "", "", "", false + } if name == "" { n, ok := sumLengths[len(value)] if !ok { diff --git a/processor/audit_parser_test.go b/processor/audit_parser_test.go index e5e6873..63f635c 100644 --- a/processor/audit_parser_test.go +++ b/processor/audit_parser_test.go @@ -4,6 +4,7 @@ package processor import ( "path/filepath" + "strings" "testing" ) @@ -95,13 +96,13 @@ func TestNewAuditorHashdeepMultipleHeaders(t *testing.T) { if r == nil || r.Hashes["sha1"] != testSHA1 || r.Hashes["sha256"] != testSHA256 { t.Errorf("expected sha1 and sha256 for b.txt got %v", r) } - if _, ok := r.Hashes["tiger"]; ok { - t.Error("tiger is not supported and should be ignored") + if r.Hashes["tiger"] != "deadbeef" { + t.Errorf("expected tiger for b.txt got %v", r.Hashes) } } func TestNewAuditorHashdeepUnsupported(t *testing.T) { - input := "%%%% HASHDEEP-1.0\n%%%% size,tiger,filename\n2,deadbeef,a.txt\n" + input := "%%%% HASHDEEP-1.0\n%%%% size,unknownhash,filename\n2,deadbeef,a.txt\n" if _, err := NewAuditor(input, "hashes.txt"); err == nil { t.Error("expected error when no supported hash is present") } @@ -246,3 +247,91 @@ func TestNewAuditorSumExtensionLengths(t *testing.T) { } } } + +func TestNewAuditorTigerWhirlpool(t *testing.T) { + // of "hi\n", as hashdeep and rhash write them + tigerHash := "d332cad51f518b1898a5c1bcf68ccca3c6d29b5de317a105" + whirlpoolHash := "917d29663e30e6c211b171967c3103d2e087a59389cae751ff803f55e87f8c96608f0e3a88755d8c3133f8f320d2994630a24948ffb62fa2e577fc3c70772328" + res := Result{File: "a.txt", Tiger: tigerHash, Whirlpool: whirlpoolHash, Bytes: 3} + cases := []struct { + name, input, filename string + hashes []string + }{ + {"hashdeep", "%%%% HASHDEEP-1.0\n%%%% size,tiger,whirlpool,filename\n3," + tigerHash + "," + whirlpoolHash + ",a.txt\n", "m.hd", []string{"tiger", "whirlpool"}}, + {"bsd tags", "TIGER (a.txt) = " + tigerHash + "\nWHIRLPOOL (a.txt) = " + whirlpoolHash + "\n", "m.sum", []string{"tiger", "whirlpool"}}, + // only tiger is 48 long, while 128 is sha512 unless the extension says otherwise + {"tiger by length", tigerHash + " a.txt\n", "m.txt", []string{"tiger"}}, + {"whirlpool by extension", whirlpoolHash + " a.txt\n", "m.whirlpool", []string{"whirlpool"}}, + } + for _, c := range cases { + hdl, err := NewAuditor(c.input, c.filename) + if err != nil { + t.Fatalf("%s: %v", c.name, err) + } + if got := hdl.HashNames(); len(got) != len(c.hashes) || !contains(got, c.hashes[0]) || !contains(got, c.hashes[len(c.hashes)-1]) { + t.Errorf("%s: expected hashes %v got %v", c.name, c.hashes, got) + } + if _, status := hdl.Find(res); status != FileMatched { + t.Errorf("%s: expected match got %v", c.name, status) + } + // a fresh auditor, as a record which matched a file is not matched again + hdl, err = NewAuditor(c.input, c.filename) + if err != nil { + t.Fatalf("%s: %v", c.name, err) + } + changed := res + changed.Tiger = "00" + tigerHash[2:] + changed.Whirlpool = "00" + whirlpoolHash[2:] + if _, status := hdl.Find(changed); status != FileModified { + t.Errorf("%s: expected modified got %v", c.name, status) + } + } +} + +func TestNewAuditorExtensionLengthMismatch(t *testing.T) { + // b2sum -l 192 and -l 160 output is 48 and 40 long, which blake2b files never are, so it is not + // taken as tiger or sha1 by length + for _, value := range []string{strings.Repeat("a", 48), strings.Repeat("a", 40)} { + for _, filename := range []string{"m.b2", "m.blake2b", "m.sha256"} { + if _, err := NewAuditor(value+" a.txt\n", filename); err == nil { + t.Errorf("%s of length %d: expected the file to be refused", filename, len(value)) + } + } + // without an extension naming the hash, the length is used + if _, err := NewAuditor(value+" a.txt\n", "m.txt"); err != nil { + t.Errorf("m.txt of length %d: %v", len(value), err) + } + } +} + +func TestGuessedHashHint(t *testing.T) { + sha512Like := strings.Repeat("a", 128) + " a.txt\n" + cases := []struct { + input, filename string + want []string + }{ + {sha512Like, "m.txt", []string{"read as sha512", "whirlpool (.whirlpool)", "sha3512 (.sha3-512)"}}, + // the extension names the hash, so nothing was guessed + {sha512Like, "m.whirlpool", nil}, + // a bsd tag names the hash + {"SHA512 (a.txt) = " + strings.Repeat("a", 128) + "\n", "m.txt", nil}, + // only tiger is 48 long, so there is nothing else it could be + {strings.Repeat("a", 48) + " a.txt\n", "m.txt", nil}, + {"%%%% HASHDEEP-1.0\n%%%% size,md5,filename\n1," + strings.Repeat("a", 32) + ",a.txt\n", "m.txt", nil}, + } + for _, c := range cases { + hdl, err := NewAuditor(c.input, c.filename) + if err != nil { + t.Fatalf("%s: %v", c.filename, err) + } + hint := hdl.GuessedHashHint() + if c.want == nil && hint != "" { + t.Errorf("%q in %s: expected no hint got %q", c.input, c.filename, hint) + } + for _, w := range c.want { + if !strings.Contains(hint, w) { + t.Errorf("%q in %s: expected hint containing %q got %q", c.input, c.filename, w, hint) + } + } + } +} diff --git a/processor/database/models.go b/processor/database/models.go index 34f07ab..0c26f8c 100644 --- a/processor/database/models.go +++ b/processor/database/models.go @@ -27,6 +27,8 @@ type FileHash struct { Sha3384 sql.NullString Sha3512 sql.NullString Ed2k sql.NullString + Tiger sql.NullString + Whirlpool sql.NullString Size int64 Mtime interface{} } diff --git a/processor/database/queries.sql.go b/processor/database/queries.sql.go index 3ebdd01..ef89a02 100644 --- a/processor/database/queries.sql.go +++ b/processor/database/queries.sql.go @@ -11,7 +11,7 @@ import ( ) const fileHashByFilePath = `-- name: FileHashByFilePath :one -select filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes where filepath = ? +select filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes where filepath = ? ` func (q *Queries) FileHashByFilePath(ctx context.Context, filepath string) (FileHash, error) { @@ -36,6 +36,8 @@ func (q *Queries) FileHashByFilePath(ctx context.Context, filepath string) (File &i.Sha3384, &i.Sha3512, &i.Ed2k, + &i.Tiger, + &i.Whirlpool, &i.Size, &i.Mtime, ) @@ -54,7 +56,7 @@ func (q *Queries) FileHashCount(ctx context.Context) (int64, error) { } const fileHashFirst = `-- name: FileHashFirst :one -select filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes limit 1 +select filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes limit 1 ` func (q *Queries) FileHashFirst(ctx context.Context) (FileHash, error) { @@ -79,6 +81,8 @@ func (q *Queries) FileHashFirst(ctx context.Context) (FileHash, error) { &i.Sha3384, &i.Sha3512, &i.Ed2k, + &i.Tiger, + &i.Whirlpool, &i.Size, &i.Mtime, ) @@ -89,10 +93,10 @@ const fileHashInsertReplace = `-- name: FileHashInsertReplace :one insert or replace into file_hashes ( filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, - blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, + blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime -) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) -returning filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime +) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) +returning filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime ` type FileHashInsertReplaceParams struct { @@ -114,6 +118,8 @@ type FileHashInsertReplaceParams struct { Sha3384 sql.NullString Sha3512 sql.NullString Ed2k sql.NullString + Tiger sql.NullString + Whirlpool sql.NullString Size int64 Mtime interface{} } @@ -139,6 +145,8 @@ func (q *Queries) FileHashInsertReplace(ctx context.Context, arg FileHashInsertR arg.Sha3384, arg.Sha3512, arg.Ed2k, + arg.Tiger, + arg.Whirlpool, arg.Size, arg.Mtime, ) @@ -162,6 +170,8 @@ func (q *Queries) FileHashInsertReplace(ctx context.Context, arg FileHashInsertR &i.Sha3384, &i.Sha3512, &i.Ed2k, + &i.Tiger, + &i.Whirlpool, &i.Size, &i.Mtime, ) diff --git a/processor/formatters.go b/processor/formatters.go index 82084c2..52c6f50 100644 --- a/processor/formatters.go +++ b/processor/formatters.go @@ -530,6 +530,12 @@ func judgeAudit(founds []auditFound, newFileCandidates []Result, examinedCount i if auditFailed(filesModified, moved, len(newFiles), filesMissing) { status = Failed } + // a single modified file is more likely changed than read as the wrong hash + if matched == 0 && filesModified > 1 { + if hint := auditor.GuessedHashHint(); hint != "" { + printWarn(hint) + } + } // the below is output based on what we get from hashdeep // verbose (not very verbose) @@ -599,6 +605,12 @@ func toSum(input chan Result) string { if hasHash(HashNames.Ed2k) { str.WriteString(sumLine(res.Ed2k, res.File)) } + if hasHash(HashNames.Tiger) { + str.WriteString(sumLine(res.Tiger, res.File)) + } + if hasHash(HashNames.Whirlpool) { + str.WriteString(sumLine(res.Whirlpool, res.File)) + } // written as a comment so md5sum -c and similar tools ignore it rather than warn if MTime && res.MTime != nil { @@ -680,6 +692,12 @@ func toHashOnly(input chan Result) (string, bool) { if hasHash(HashNames.Ed2k) { str.WriteString(res.Ed2k + "\n") } + if hasHash(HashNames.Tiger) { + str.WriteString(res.Tiger + "\n") + } + if hasHash(HashNames.Whirlpool) { + str.WriteString(res.Whirlpool + "\n") + } if MTime && res.MTime != nil { str.WriteString(fmt.Sprintf("%s\n", res.MTime.Format("2006-01-02 15:04:05"))) @@ -758,6 +776,12 @@ func toText(input chan Result) (string, bool) { if hasHash(HashNames.Ed2k) { str.WriteString(" ed2k " + res.Ed2k + "\n") } + if hasHash(HashNames.Tiger) { + str.WriteString(" Tiger " + res.Tiger + "\n") + } + if hasHash(HashNames.Whirlpool) { + str.WriteString(" Whirlpool " + res.Whirlpool + "\n") + } if MTime && res.MTime != nil { str.WriteString(fmt.Sprintf(" MTime %s\n", res.MTime.Format("2006-01-02 15:04:05"))) @@ -782,6 +806,9 @@ func toJSON(input chan Result) string { return string(jsonString) + "\n" } +// hashdeepFormatHashes are the hashes hashdeep calculates, in the order it writes them +var hashdeepFormatHashes = []string{HashNames.MD5, HashNames.SHA1, HashNames.SHA256, HashNames.Tiger, HashNames.Whirlpool} + func toHashDeep(input chan Result) string { var str strings.Builder @@ -792,15 +819,16 @@ func toHashDeep(input chan Result) string { } str.WriteString("%%%% HASHDEEP-1.0\n") - if !contains(Hash, "sha256") && !contains(Hash, "all") { - str.WriteString("%%%% size,md5,filename") - } else if contains(Hash, "sha256") && !contains(Hash, "all") && !contains(Hash, "md5") { - str.WriteString("%%%% size,sha256,filename") - } else { - str.WriteString("%%%% size,md5,sha256,filename") + var columns []string + for _, h := range hashdeepFormatHashes { + if hasHash(h) { + columns = append(columns, h) + } } - - str.WriteString("\n") + if len(columns) == 0 { + columns = []string{HashNames.MD5, HashNames.SHA256} + } + str.WriteString("%%%% size," + strings.Join(columns, ",") + ",filename\n") str.WriteString(fmt.Sprintf("## Invoked from: %s\n", pwd)) str.WriteString(fmt.Sprintf("## $ %s\n", strings.Join(os.Args, " "))) @@ -810,13 +838,9 @@ func toHashDeep(input chan Result) string { // Bytes first, always the same. str.WriteString(fmt.Sprintf("%d,", res.Bytes)) - // Follows the same logic as the headers. - if !contains(Hash, "sha256") && !contains(Hash, "all") { - str.WriteString(fmt.Sprintf("%s,", res.MD5)) - } else if contains(Hash, "sha256") && !contains(Hash, "all") && !contains(Hash, "md5") { - str.WriteString(fmt.Sprintf("%s,", res.SHA256)) - } else { - str.WriteString(fmt.Sprintf("%s,%s,", res.MD5, res.SHA256)) + for _, h := range columns { + str.WriteString(res.hashValue(h)) + str.WriteString(",") } // Finish with filename and newline. @@ -929,6 +953,8 @@ func toSqlite(input chan Result) (string, bool) { Sha3384: toSqlNull(res.Sha3384), Sha3512: toSqlNull(res.Sha3512), Ed2k: toSqlNull(res.Ed2k), + Tiger: toSqlNull(res.Tiger), + Whirlpool: toSqlNull(res.Whirlpool), Size: res.Bytes, Mtime: toSqlNull(mtime), }) @@ -1003,6 +1029,8 @@ func printHashes() { fmt.Fprintf(stdout, " SHA3-384 (%s)\n", HashNames.Sha3384) fmt.Fprintf(stdout, " SHA3-512 (%s)\n", HashNames.Sha3512) fmt.Fprintf(stdout, " ed2k (%s)\n", HashNames.Ed2k) + fmt.Fprintf(stdout, " Tiger (%s)\n", HashNames.Tiger) + fmt.Fprintf(stdout, " Whirlpool (%s)\n", HashNames.Whirlpool) } func contains(list []string, v string) bool { diff --git a/processor/processor.go b/processor/processor.go index 49b91b4..8d8bc46 100644 --- a/processor/processor.go +++ b/processor/processor.go @@ -228,6 +228,8 @@ var HashNames = Result{ Sha3384: "sha3384", Sha3512: "sha3512", Ed2k: "ed2k", + Tiger: "tiger", + Whirlpool: "whirlpool", } // Process is the main entry point of the command line it sets everything up and starts running @@ -380,10 +382,29 @@ func Process() { // If format is set to hashdeep // an audit uses the hashes chosen for it above and ignores --format if strings.ToLower(Format) == "hashdeep" && AuditFile == "" { - // if hashdeep, we need to ensure md5 is set or sha256, or both, and if neither are set both - if !hasHash("md5") && !hasHash("sha256") { - printWarn("hashdeep format without supported hash - setting md5 and sha256") - Hash = []string{"md5", "sha256"} + // hashdeep files hold only the hashes hashdeep calculates, and without -c it writes md5 and sha256 + var kept, dropped []string + for _, h := range hashdeepFormatHashes { + if hasHash(h) { + kept = append(kept, h) + } + } + for _, h := range Hash { + if h != "all" && !contains(hashdeepFormatHashes, h) { + dropped = append(dropped, h) + } + } + switch { + case !HashSupplied: + Hash = []string{HashNames.MD5, HashNames.SHA256} + case len(kept) == 0: + printWarn("hashdeep format holds only md5, sha1, sha256, tiger and whirlpool - setting md5 and sha256") + Hash = []string{HashNames.MD5, HashNames.SHA256} + default: + if len(dropped) != 0 { + printWarn(fmt.Sprintf("hashdeep format holds only md5, sha1, sha256, tiger and whirlpool - leaving out %s", strings.Join(dropped, ", "))) + } + Hash = kept } } diff --git a/processor/structs.go b/processor/structs.go index 0ca37de..902be04 100644 --- a/processor/structs.go +++ b/processor/structs.go @@ -24,6 +24,8 @@ type Result struct { Sha3384 string `json:",omitempty"` Sha3512 string `json:",omitempty"` Ed2k string `json:"ed2k,omitempty"` + Tiger string `json:",omitempty"` + Whirlpool string `json:",omitempty"` Bytes int64 MTime *time.Time `json:",omitzero"` } @@ -65,6 +67,10 @@ func (r Result) hashValue(name string) string { return r.Sha3512 case HashNames.Ed2k: return r.Ed2k + case HashNames.Tiger: + return r.Tiger + case HashNames.Whirlpool: + return r.Whirlpool } return "" } diff --git a/processor/tiger/LICENSE b/processor/tiger/LICENSE new file mode 100644 index 0000000..c811438 --- /dev/null +++ b/processor/tiger/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2013 Xiuming Chen + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/processor/tiger/compress.go b/processor/tiger/compress.go new file mode 100644 index 0000000..736fddc --- /dev/null +++ b/processor/tiger/compress.go @@ -0,0 +1,73 @@ +package tiger + +import "encoding/binary" + +func pass(a, b, c uint64, x []uint64, mul uint64) (uint64, uint64, uint64) { + a, b, c = round(a, b, c, x[0], mul) + b, c, a = round(b, c, a, x[1], mul) + c, a, b = round(c, a, b, x[2], mul) + a, b, c = round(a, b, c, x[3], mul) + b, c, a = round(b, c, a, x[4], mul) + c, a, b = round(c, a, b, x[5], mul) + a, b, c = round(a, b, c, x[6], mul) + b, c, a = round(b, c, a, x[7], mul) + return a, b, c +} + +func round(a, b, c, x, mul uint64) (uint64, uint64, uint64) { + c ^= x + a -= t1[c&0xff] ^ t2[(c>>16)&0xff] ^ t3[(c>>32)&0xff] ^ t4[(c>>48)&0xff] + b += t4[(c>>8)&0xff] ^ t3[(c>>24)&0xff] ^ t2[(c>>40)&0xff] ^ t1[(c>>56)&0xff] + b *= mul + return a, b, c +} + +func keySchedule(x []uint64) { + x[0] -= x[7] ^ 0xa5a5a5a5a5a5a5a5 + x[1] ^= x[0] + x[2] += x[1] + x[3] -= x[2] ^ ((^x[1]) << 19) + x[4] ^= x[3] + x[5] += x[4] + x[6] -= x[5] ^ ((^x[4]) >> 23) + x[7] ^= x[6] + x[0] += x[7] + x[1] -= x[0] ^ ((^x[7]) << 19) + x[2] ^= x[1] + x[3] += x[2] + x[4] -= x[3] ^ ((^x[2]) >> 23) + x[5] ^= x[4] + x[6] += x[5] + x[7] -= x[6] ^ 0x0123456789abcdef +} + +func (d *digest) compress(data []byte) { + // save_abc + a := d.a + b := d.b + c := d.c + + // Tiger reads its input as little-endian words whatever the byte order of the machine. The + // original read them in the machine's own order, so gave other hashes on big-endian machines + x := []uint64{ + binary.LittleEndian.Uint64(data[0:8]), + binary.LittleEndian.Uint64(data[8:16]), + binary.LittleEndian.Uint64(data[16:24]), + binary.LittleEndian.Uint64(data[24:32]), + binary.LittleEndian.Uint64(data[32:40]), + binary.LittleEndian.Uint64(data[40:48]), + binary.LittleEndian.Uint64(data[48:56]), + binary.LittleEndian.Uint64(data[56:64]), + } + + d.a, d.b, d.c = pass(d.a, d.b, d.c, x, 5) + keySchedule(x) + d.c, d.a, d.b = pass(d.c, d.a, d.b, x, 7) + keySchedule(x) + d.b, d.c, d.a = pass(d.b, d.c, d.a, x, 9) + + // feedforward + d.a ^= a + d.b -= b + d.c += c +} diff --git a/processor/tiger/sboxes.go b/processor/tiger/sboxes.go new file mode 100644 index 0000000..cd05dff --- /dev/null +++ b/processor/tiger/sboxes.go @@ -0,0 +1,269 @@ +package tiger + +var t1 = [...]uint64{ + 0x02aab17cf7e90c5e, 0xac424b03e243a8ec, 0x72cd5be30dd5fcd3, 0x6d019b93f6f97f3a, + 0xcd9978ffd21f9193, 0x7573a1c9708029e2, 0xb164326b922a83c3, 0x46883eee04915870, + 0xeaace3057103ece6, 0xc54169b808a3535c, 0x4ce754918ddec47c, 0x0aa2f4dfdc0df40c, + 0x10b76f18a74dbefa, 0xc6ccb6235ad1ab6a, 0x13726121572fe2ff, 0x1a488c6f199d921e, + 0x4bc9f9f4da0007ca, 0x26f5e6f6e85241c7, 0x859079dbea5947b6, 0x4f1885c5c99e8c92, + 0xd78e761ea96f864b, 0x8e36428c52b5c17d, 0x69cf6827373063c1, 0xb607c93d9bb4c56e, + 0x7d820e760e76b5ea, 0x645c9cc6f07fdc42, 0xbf38a078243342e0, 0x5f6b343c9d2e7d04, + 0xf2c28aeb600b0ec6, 0x6c0ed85f7254bcac, 0x71592281a4db4fe5, 0x1967fa69ce0fed9f, + 0xfd5293f8b96545db, 0xc879e9d7f2a7600b, 0x860248920193194e, 0xa4f9533b2d9cc0b3, + 0x9053836c15957613, 0xdb6dcf8afc357bf1, 0x18beea7a7a370f57, 0x037117ca50b99066, + 0x6ab30a9774424a35, 0xf4e92f02e325249b, 0x7739db07061ccae1, 0xd8f3b49ceca42a05, + 0xbd56be3f51382f73, 0x45faed5843b0bb28, 0x1c813d5c11bf1f83, 0x8af0e4b6d75fa169, + 0x33ee18a487ad9999, 0x3c26e8eab1c94410, 0xb510102bc0a822f9, 0x141eef310ce6123b, + 0xfc65b90059ddb154, 0xe0158640c5e0e607, 0x884e079826c3a3cf, 0x930d0d9523c535fd, + 0x35638d754e9a2b00, 0x4085fccf40469dd5, 0xc4b17ad28be23a4c, 0xcab2f0fc6a3e6a2e, + 0x2860971a6b943fcd, 0x3dde6ee212e30446, 0x6222f32ae01765ae, 0x5d550bb5478308fe, + 0xa9efa98da0eda22a, 0xc351a71686c40da7, 0x1105586d9c867c84, 0xdcffee85fda22853, + 0xccfbd0262c5eef76, 0xbaf294cb8990d201, 0xe69464f52afad975, 0x94b013afdf133e14, + 0x06a7d1a32823c958, 0x6f95fe5130f61119, 0xd92ab34e462c06c0, 0xed7bde33887c71d2, + 0x79746d6e6518393e, 0x5ba419385d713329, 0x7c1ba6b948a97564, 0x31987c197bfdac67, + 0xde6c23c44b053d02, 0x581c49fed002d64d, 0xdd474d6338261571, 0xaa4546c3e473d062, + 0x928fce349455f860, 0x48161bbacaab94d9, 0x63912430770e6f68, 0x6ec8a5e602c6641c, + 0x87282515337ddd2b, 0x2cda6b42034b701b, 0xb03d37c181cb096d, 0xe108438266c71c6f, + 0x2b3180c7eb51b255, 0xdf92b82f96c08bbc, 0x5c68c8c0a632f3ba, 0x5504cc861c3d0556, + 0xabbfa4e55fb26b8f, 0x41848b0ab3baceb4, 0xb334a273aa445d32, 0xbca696f0a85ad881, + 0x24f6ec65b528d56c, 0x0ce1512e90f4524a, 0x4e9dd79d5506d35a, 0x258905fac6ce9779, + 0x2019295b3e109b33, 0xf8a9478b73a054cc, 0x2924f2f934417eb0, 0x3993357d536d1bc4, + 0x38a81ac21db6ff8b, 0x47c4fbf17d6016bf, 0x1e0faadd7667e3f5, 0x7abcff62938beb96, + 0xa78dad948fc179c9, 0x8f1f98b72911e50d, 0x61e48eae27121a91, 0x4d62f7ad31859808, + 0xeceba345ef5ceaeb, 0xf5ceb25ebc9684ce, 0xf633e20cb7f76221, 0xa32cdf06ab8293e4, + 0x985a202ca5ee2ca4, 0xcf0b8447cc8a8fb1, 0x9f765244979859a3, 0xa8d516b1a1240017, + 0x0bd7ba3ebb5dc726, 0xe54bca55b86adb39, 0x1d7a3afd6c478063, 0x519ec608e7669edd, + 0x0e5715a2d149aa23, 0x177d4571848ff194, 0xeeb55f3241014c22, 0x0f5e5ca13a6e2ec2, + 0x8029927b75f5c361, 0xad139fabc3d6e436, 0x0d5df1a94ccf402f, 0x3e8bd948bea5dfc8, + 0xa5a0d357bd3ff77e, 0xa2d12e251f74f645, 0x66fd9e525e81a082, 0x2e0c90ce7f687a49, + 0xc2e8bcbeba973bc5, 0x000001bce509745f, 0x423777bbe6dab3d6, 0xd1661c7eaef06eb5, + 0xa1781f354daacfd8, 0x2d11284a2b16affc, 0xf1fc4f67fa891d1f, 0x73ecc25dcb920ada, + 0xae610c22c2a12651, 0x96e0a810d356b78a, 0x5a9a381f2fe7870f, 0xd5ad62ede94e5530, + 0xd225e5e8368d1427, 0x65977b70c7af4631, 0x99f889b2de39d74f, 0x233f30bf54e1d143, + 0x9a9675d3d9a63c97, 0x5470554ff334f9a8, 0x166acb744a4f5688, 0x70c74caab2e4aead, + 0xf0d091646f294d12, 0x57b82a89684031d1, 0xefd95a5a61be0b6b, 0x2fbd12e969f2f29a, + 0x9bd37013feff9fe8, 0x3f9b0404d6085a06, 0x4940c1f3166cfe15, 0x09542c4dcdf3defb, + 0xb4c5218385cd5ce3, 0xc935b7dc4462a641, 0x3417f8a68ed3b63f, 0xb80959295b215b40, + 0xf99cdaef3b8c8572, 0x018c0614f8fcb95d, 0x1b14accd1a3acdf3, 0x84d471f200bb732d, + 0xc1a3110e95e8da16, 0x430a7220bf1a82b8, 0xb77e090d39df210e, 0x5ef4bd9f3cd05e9d, + 0x9d4ff6da7e57a444, 0xda1d60e183d4a5f8, 0xb287c38417998e47, 0xfe3edc121bb31886, + 0xc7fe3ccc980ccbef, 0xe46fb590189bfd03, 0x3732fd469a4c57dc, 0x7ef700a07cf1ad65, + 0x59c64468a31d8859, 0x762fb0b4d45b61f6, 0x155baed099047718, 0x68755e4c3d50baa6, + 0xe9214e7f22d8b4df, 0x2addbf532eac95f4, 0x32ae3909b4bd0109, 0x834df537b08e3450, + 0xfa209da84220728d, 0x9e691d9b9efe23f7, 0x0446d288c4ae8d7f, 0x7b4cc524e169785b, + 0x21d87f0135ca1385, 0xcebb400f137b8aa5, 0x272e2b66580796be, 0x3612264125c2b0de, + 0x057702bdad1efbb2, 0xd4babb8eacf84be9, 0x91583139641bc67b, 0x8bdc2de08036e024, + 0x603c8156f49f68ed, 0xf7d236f7dbef5111, 0x9727c4598ad21e80, 0xa08a0896670a5fd7, + 0xcb4a8f4309eba9cb, 0x81af564b0f7036a1, 0xc0b99aa778199abd, 0x959f1ec83fc8e952, + 0x8c505077794a81b9, 0x3acaaf8f056338f0, 0x07b43f50627a6778, 0x4a44ab49f5eccc77, + 0x3bc3d6e4b679ee98, 0x9cc0d4d1cf14108c, 0x4406c00b206bc8a0, 0x82a18854c8d72d89, + 0x67e366b35c3c432c, 0xb923dd61102b37f2, 0x56ab2779d884271d, 0xbe83e1b0ff1525af, + 0xfb7c65d4217e49a9, 0x6bdbe0e76d48e7d4, 0x08df828745d9179e, 0x22ea6a9add53bd34, + 0xe36e141c5622200a, 0x7f805d1b8cb750ee, 0xafe5c7a59f58e837, 0xe27f996a4fb1c23c, + 0xd3867dfb0775f0d0, 0xd0e673de6e88891a, 0x123aeb9eafb86c25, 0x30f1d5d5c145b895, + 0xbb434a2dee7269e7, 0x78cb67ecf931fa38, 0xf33b0372323bbf9c, 0x52d66336fb279c74, + 0x505f33ac0afb4eaa, 0xe8a5cd99a2cce187, 0x534974801e2d30bb, 0x8d2d5711d5876d90, + 0x1f1a412891bc038e, 0xd6e2e71d82e56648, 0x74036c3a497732b7, 0x89b67ed96361f5ab, + 0xffed95d8f1ea02a2, 0xe72b3bd61464d43d, 0xa6300f170bdc4820, 0xebc18760ed78a77a, +} + +var t2 = [...]uint64{ + 0xe6a6be5a05a12138, 0xb5a122a5b4f87c98, 0x563c6089140b6990, 0x4c46cb2e391f5dd5, + 0xd932addbc9b79434, 0x08ea70e42015aff5, 0xd765a6673e478cf1, 0xc4fb757eab278d99, + 0xdf11c6862d6e0692, 0xddeb84f10d7f3b16, 0x6f2ef604a665ea04, 0x4a8e0f0ff0e0dfb3, + 0xa5edeef83dbcba51, 0xfc4f0a2a0ea4371e, 0xe83e1da85cb38429, 0xdc8ff882ba1b1ce2, + 0xcd45505e8353e80d, 0x18d19a00d4db0717, 0x34a0cfeda5f38101, 0x0be77e518887caf2, + 0x1e341438b3c45136, 0xe05797f49089ccf9, 0xffd23f9df2591d14, 0x543dda228595c5cd, + 0x661f81fd99052a33, 0x8736e641db0f7b76, 0x15227725418e5307, 0xe25f7f46162eb2fa, + 0x48a8b2126c13d9fe, 0xafdc541792e76eea, 0x03d912bfc6d1898f, 0x31b1aafa1b83f51b, + 0xf1ac2796e42ab7d9, 0x40a3a7d7fcd2ebac, 0x1056136d0afbbcc5, 0x7889e1dd9a6d0c85, + 0xd33525782a7974aa, 0xa7e25d09078ac09b, 0xbd4138b3eac6edd0, 0x920abfbe71eb9e70, + 0xa2a5d0f54fc2625c, 0xc054e36b0b1290a3, 0xf6dd59ff62fe932b, 0x3537354511a8ac7d, + 0xca845e9172fadcd4, 0x84f82b60329d20dc, 0x79c62ce1cd672f18, 0x8b09a2add124642c, + 0xd0c1e96a19d9e726, 0x5a786a9b4ba9500c, 0x0e020336634c43f3, 0xc17b474aeb66d822, + 0x6a731ae3ec9baac2, 0x8226667ae0840258, 0x67d4567691caeca5, 0x1d94155c4875adb5, + 0x6d00fd985b813fdf, 0x51286efcb774cd06, 0x5e8834471fa744af, 0xf72ca0aee761ae2e, + 0xbe40e4cdaee8e09a, 0xe9970bbb5118f665, 0x726e4beb33df1964, 0x703b000729199762, + 0x4631d816f5ef30a7, 0xb880b5b51504a6be, 0x641793c37ed84b6c, 0x7b21ed77f6e97d96, + 0x776306312ef96b73, 0xae528948e86ff3f4, 0x53dbd7f286a3f8f8, 0x16cadce74cfc1063, + 0x005c19bdfa52c6dd, 0x68868f5d64d46ad3, 0x3a9d512ccf1e186a, 0x367e62c2385660ae, + 0xe359e7ea77dcb1d7, 0x526c0773749abe6e, 0x735ae5f9d09f734b, 0x493fc7cc8a558ba8, + 0xb0b9c1533041ab45, 0x321958ba470a59bd, 0x852db00b5f46c393, 0x91209b2bd336b0e5, + 0x6e604f7d659ef19f, 0xb99a8ae2782ccb24, 0xccf52ab6c814c4c7, 0x4727d9afbe11727b, + 0x7e950d0c0121b34d, 0x756f435670ad471f, 0xf5add442615a6849, 0x4e87e09980b9957a, + 0x2acfa1df50aee355, 0xd898263afd2fd556, 0xc8f4924dd80c8fd6, 0xcf99ca3d754a173a, + 0xfe477bacaf91bf3c, 0xed5371f6d690c12d, 0x831a5c285e687094, 0xc5d3c90a3708a0a4, + 0x0f7f903717d06580, 0x19f9bb13b8fdf27f, 0xb1bd6f1b4d502843, 0x1c761ba38fff4012, + 0x0d1530c4e2e21f3b, 0x8943ce69a7372c8a, 0xe5184e11feb5ce66, 0x618bdb80bd736621, + 0x7d29bad68b574d0b, 0x81bb613e25e6fe5b, 0x071c9c10bc07913f, 0xc7beeb7909ac2d97, + 0xc3e58d353bc5d757, 0xeb017892f38f61e8, 0xd4effb9c9b1cc21a, 0x99727d26f494f7ab, + 0xa3e063a2956b3e03, 0x9d4a8b9a4aa09c30, 0x3f6ab7d500090fb4, 0x9cc0f2a057268ac0, + 0x3dee9d2dedbf42d1, 0x330f49c87960a972, 0xc6b2720287421b41, 0x0ac59ec07c00369c, + 0xef4eac49cb353425, 0xf450244eef0129d8, 0x8acc46e5caf4deb6, 0x2ffeab63989263f7, + 0x8f7cb9fe5d7a4578, 0x5bd8f7644e634635, 0x427a7315bf2dc900, 0x17d0c4aa2125261c, + 0x3992486c93518e50, 0xb4cbfee0a2d7d4c3, 0x7c75d6202c5ddd8d, 0xdbc295d8e35b6c61, + 0x60b369d302032b19, 0xce42685fdce44132, 0x06f3ddb9ddf65610, 0x8ea4d21db5e148f0, + 0x20b0fce62fcd496f, 0x2c1b912358b0ee31, 0xb28317b818f5a308, 0xa89c1e189ca6d2cf, + 0x0c6b18576aaadbc8, 0xb65deaa91299fae3, 0xfb2b794b7f1027e7, 0x04e4317f443b5beb, + 0x4b852d325939d0a6, 0xd5ae6beefb207ffc, 0x309682b281c7d374, 0xbae309a194c3b475, + 0x8cc3f97b13b49f05, 0x98a9422ff8293967, 0x244b16b01076ff7c, 0xf8bf571c663d67ee, + 0x1f0d6758eee30da1, 0xc9b611d97adeb9b7, 0xb7afd5887b6c57a2, 0x6290ae846b984fe1, + 0x94df4cdeacc1a5fd, 0x058a5bd1c5483aff, 0x63166cc142ba3c37, 0x8db8526eb2f76f40, + 0xe10880036f0d6d4e, 0x9e0523c9971d311d, 0x45ec2824cc7cd691, 0x575b8359e62382c9, + 0xfa9e400dc4889995, 0xd1823ecb45721568, 0xdafd983b8206082f, 0xaa7d29082386a8cb, + 0x269fcd4403b87588, 0x1b91f5f728bdd1e0, 0xe4669f39040201f6, 0x7a1d7c218cf04ade, + 0x65623c29d79ce5ce, 0x2368449096c00bb1, 0xab9bf1879da503ba, 0xbc23ecb1a458058e, + 0x9a58df01bb401ecc, 0xa070e868a85f143d, 0x4ff188307df2239e, 0x14d565b41a641183, + 0xee13337452701602, 0x950e3dcf3f285e09, 0x59930254b9c80953, 0x3bf299408930da6d, + 0xa955943f53691387, 0xa15edecaa9cb8784, 0x29142127352be9a0, 0x76f0371fff4e7afb, + 0x0239f450274f2228, 0xbb073af01d5e868b, 0xbfc80571c10e96c1, 0xd267088568222e23, + 0x9671a3d48e80b5b0, 0x55b5d38ae193bb81, 0x693ae2d0a18b04b8, 0x5c48b4ecadd5335f, + 0xfd743b194916a1ca, 0x2577018134be98c4, 0xe77987e83c54a4ad, 0x28e11014da33e1b9, + 0x270cc59e226aa213, 0x71495f756d1a5f60, 0x9be853fb60afef77, 0xadc786a7f7443dbf, + 0x0904456173b29a82, 0x58bc7a66c232bd5e, 0xf306558c673ac8b2, 0x41f639c6b6c9772a, + 0x216defe99fda35da, 0x11640cc71c7be615, 0x93c43694565c5527, 0xea038e6246777839, + 0xf9abf3ce5a3e2469, 0x741e768d0fd312d2, 0x0144b883ced652c6, 0xc20b5a5ba33f8552, + 0x1ae69633c3435a9d, 0x97a28ca4088cfdec, 0x8824a43c1e96f420, 0x37612fa66eeea746, + 0x6b4cb165f9cf0e5a, 0x43aa1c06a0abfb4a, 0x7f4dc26ff162796b, 0x6cbacc8e54ed9b0f, + 0xa6b7ffefd2bb253e, 0x2e25bc95b0a29d4f, 0x86d6a58bdef1388c, 0xded74ac576b6f054, + 0x8030bdbc2b45805d, 0x3c81af70e94d9289, 0x3eff6dda9e3100db, 0xb38dc39fdfcc8847, + 0x123885528d17b87e, 0xf2da0ed240b1b642, 0x44cefadcd54bf9a9, 0x1312200e433c7ee6, + 0x9ffcc84f3a78c748, 0xf0cd1f72248576bb, 0xec6974053638cfe4, 0x2ba7b67c0cec4e4c, + 0xac2f4df3e5ce32ed, 0xcb33d14326ea4c11, 0xa4e9044cc77e58bc, 0x5f513293d934fcef, + 0x5dc9645506e55444, 0x50de418f317de40a, 0x388cb31a69dde259, 0x2db4a83455820a86, + 0x9010a91e84711ae9, 0x4df7f0b7b1498371, 0xd62a2eabc0977179, 0x22fac097aa8d5c0e, +} + +var t3 = [...]uint64{ + 0xf49fcc2ff1daf39b, 0x487fd5c66ff29281, 0xe8a30667fcdca83f, 0x2c9b4be3d2fcce63, + 0xda3ff74b93fbbbc2, 0x2fa165d2fe70ba66, 0xa103e279970e93d4, 0xbecdec77b0e45e71, + 0xcfb41e723985e497, 0xb70aaa025ef75017, 0xd42309f03840b8e0, 0x8efc1ad035898579, + 0x96c6920be2b2abc5, 0x66af4163375a9172, 0x2174abdcca7127fb, 0xb33ccea64a72ff41, + 0xf04a4933083066a5, 0x8d970acdd7289af5, 0x8f96e8e031c8c25e, 0xf3fec02276875d47, + 0xec7bf310056190dd, 0xf5adb0aebb0f1491, 0x9b50f8850fd58892, 0x4975488358b74de8, + 0xa3354ff691531c61, 0x0702bbe481d2c6ee, 0x89fb24057deded98, 0xac3075138596e902, + 0x1d2d3580172772ed, 0xeb738fc28e6bc30d, 0x5854ef8f63044326, 0x9e5c52325add3bbe, + 0x90aa53cf325c4623, 0xc1d24d51349dd067, 0x2051cfeea69ea624, 0x13220f0a862e7e4f, + 0xce39399404e04864, 0xd9c42ca47086fcb7, 0x685ad2238a03e7cc, 0x066484b2ab2ff1db, + 0xfe9d5d70efbf79ec, 0x5b13b9dd9c481854, 0x15f0d475ed1509ad, 0x0bebcd060ec79851, + 0xd58c6791183ab7f8, 0xd1187c5052f3eee4, 0xc95d1192e54e82ff, 0x86eea14cb9ac6ca2, + 0x3485beb153677d5d, 0xdd191d781f8c492a, 0xf60866baa784ebf9, 0x518f643ba2d08c74, + 0x8852e956e1087c22, 0xa768cb8dc410ae8d, 0x38047726bfec8e1a, 0xa67738b4cd3b45aa, + 0xad16691cec0dde19, 0xc6d4319380462e07, 0xc5a5876d0ba61938, 0x16b9fa1fa58fd840, + 0x188ab1173ca74f18, 0xabda2f98c99c021f, 0x3e0580ab134ae816, 0x5f3b05b773645abb, + 0x2501a2be5575f2f6, 0x1b2f74004e7e8ba9, 0x1cd7580371e8d953, 0x7f6ed89562764e30, + 0xb15926ff596f003d, 0x9f65293da8c5d6b9, 0x6ecef04dd690f84c, 0x4782275fff33af88, + 0xe41433083f820801, 0xfd0dfe409a1af9b5, 0x4325a3342cdb396b, 0x8ae77e62b301b252, + 0xc36f9e9f6655615a, 0x85455a2d92d32c09, 0xf2c7dea949477485, 0x63cfb4c133a39eba, + 0x83b040cc6ebc5462, 0x3b9454c8fdb326b0, 0x56f56a9e87ffd78c, 0x2dc2940d99f42bc6, + 0x98f7df096b096e2d, 0x19a6e01e3ad852bf, 0x42a99ccbdbd4b40b, 0xa59998af45e9c559, + 0x366295e807d93186, 0x6b48181bfaa1f773, 0x1fec57e2157a0a1d, 0x4667446af6201ad5, + 0xe615ebcacfb0f075, 0xb8f31f4f68290778, 0x22713ed6ce22d11e, 0x3057c1a72ec3c93b, + 0xcb46acc37c3f1f2f, 0xdbb893fd02aaf50e, 0x331fd92e600b9fcf, 0xa498f96148ea3ad6, + 0xa8d8426e8b6a83ea, 0xa089b274b7735cdc, 0x87f6b3731e524a11, 0x118808e5cbc96749, + 0x9906e4c7b19bd394, 0xafed7f7e9b24a20c, 0x6509eadeeb3644a7, 0x6c1ef1d3e8ef0ede, + 0xb9c97d43e9798fb4, 0xa2f2d784740c28a3, 0x7b8496476197566f, 0x7a5be3e6b65f069d, + 0xf96330ed78be6f10, 0xeee60de77a076a15, 0x2b4bee4aa08b9bd0, 0x6a56a63ec7b8894e, + 0x02121359ba34fef4, 0x4cbf99f8283703fc, 0x398071350caf30c8, 0xd0a77a89f017687a, + 0xf1c1a9eb9e423569, 0x8c7976282dee8199, 0x5d1737a5dd1f7abd, 0x4f53433c09a9fa80, + 0xfa8b0c53df7ca1d9, 0x3fd9dcbc886ccb77, 0xc040917ca91b4720, 0x7dd00142f9d1dcdf, + 0x8476fc1d4f387b58, 0x23f8e7c5f3316503, 0x032a2244e7e37339, 0x5c87a5d750f5a74b, + 0x082b4cc43698992e, 0xdf917becb858f63c, 0x3270b8fc5bf86dda, 0x10ae72bb29b5dd76, + 0x576ac94e7700362b, 0x1ad112dac61efb8f, 0x691bc30ec5faa427, 0xff246311cc327143, + 0x3142368e30e53206, 0x71380e31e02ca396, 0x958d5c960aad76f1, 0xf8d6f430c16da536, + 0xc8ffd13f1be7e1d2, 0x7578ae66004ddbe1, 0x05833f01067be646, 0xbb34b5ad3bfe586d, + 0x095f34c9a12b97f0, 0x247ab64525d60ca8, 0xdcdbc6f3017477d1, 0x4a2e14d4decad24d, + 0xbdb5e6d9be0a1eeb, 0x2a7e70f7794301ab, 0xdef42d8a270540fd, 0x01078ec0a34c22c1, + 0xe5de511af4c16387, 0x7ebb3a52bd9a330a, 0x77697857aa7d6435, 0x004e831603ae4c32, + 0xe7a21020ad78e312, 0x9d41a70c6ab420f2, 0x28e06c18ea1141e6, 0xd2b28cbd984f6b28, + 0x26b75f6c446e9d83, 0xba47568c4d418d7f, 0xd80badbfe6183d8e, 0x0e206d7f5f166044, + 0xe258a43911cbca3e, 0x723a1746b21dc0bc, 0xc7caa854f5d7cdd3, 0x7cac32883d261d9c, + 0x7690c26423ba942c, 0x17e55524478042b8, 0xe0be477656a2389f, 0x4d289b5e67ab2da0, + 0x44862b9c8fbbfd31, 0xb47cc8049d141365, 0x822c1b362b91c793, 0x4eb14655fb13dfd8, + 0x1ecbba0714e2a97b, 0x6143459d5cde5f14, 0x53a8fbf1d5f0ac89, 0x97ea04d81c5e5b00, + 0x622181a8d4fdb3f3, 0xe9bcd341572a1208, 0x1411258643cce58a, 0x9144c5fea4c6e0a4, + 0x0d33d06565cf620f, 0x54a48d489f219ca1, 0xc43e5eac6d63c821, 0xa9728b3a72770daf, + 0xd7934e7b20df87ef, 0xe35503b61a3e86e5, 0xcae321fbc819d504, 0x129a50b3ac60bfa6, + 0xcd5e68ea7e9fb6c3, 0xb01c90199483b1c7, 0x3de93cd5c295376c, 0xaed52edf2ab9ad13, + 0x2e60f512c0a07884, 0xbc3d86a3e36210c9, 0x35269d9b163951ce, 0x0c7d6e2ad0cdb5fa, + 0x59e86297d87f5733, 0x298ef221898db0e7, 0x55000029d1a5aa7e, 0x8bc08ae1b5061b45, + 0xc2c31c2b6c92703a, 0x94cc596baf25ef42, 0x0a1d73db22540456, 0x04b6a0f9d9c4179a, + 0xeffdafa2ae3d3c60, 0xf7c8075bb49496c4, 0x9cc5c7141d1cd4e3, 0x78bd1638218e5534, + 0xb2f11568f850246a, 0xedfabcfa9502bc29, 0x796ce5f2da23051b, 0xaae128b0dc93537c, + 0x3a493da0ee4b29ae, 0xb5df6b2c416895d7, 0xfcabbd25122d7f37, 0x70810b58105dc4b1, + 0xe10fdd37f7882a90, 0x524dcab5518a3f5c, 0x3c9e85878451255b, 0x4029828119bd34e2, + 0x74a05b6f5d3ceccb, 0xb610021542e13eca, 0x0ff979d12f59e2ac, 0x6037da27e4f9cc50, + 0x5e92975a0df1847d, 0xd66de190d3e623fe, 0x5032d6b87b568048, 0x9a36b7ce8235216e, + 0x80272a7a24f64b4a, 0x93efed8b8c6916f7, 0x37ddbff44cce1555, 0x4b95db5d4b99bd25, + 0x92d3fda169812fc0, 0xfb1a4a9a90660bb6, 0x730c196946a4b9b2, 0x81e289aa7f49da68, + 0x64669a0f83b1a05f, 0x27b3ff7d9644f48b, 0xcc6b615c8db675b3, 0x674f20b9bcebbe95, + 0x6f31238275655982, 0x5ae488713e45cf05, 0xbf619f9954c21157, 0xeabac46040a8eae9, + 0x454c6fe9f2c0c1cd, 0x419cf6496412691c, 0xd3dc3bef265b0f70, 0x6d0e60f5c3578a9e, +} + +var t4 = [...]uint64{ + 0x5b0e608526323c55, 0x1a46c1a9fa1b59f5, 0xa9e245a17c4c8ffa, 0x65ca5159db2955d7, + 0x05db0a76ce35afc2, 0x81eac77ea9113d45, 0x528ef88ab6ac0a0d, 0xa09ea253597be3ff, + 0x430ddfb3ac48cd56, 0xc4b3a67af45ce46f, 0x4ececfd8fbe2d05e, 0x3ef56f10b39935f0, + 0x0b22d6829cd619c6, 0x17fd460a74df2069, 0x6cf8cc8e8510ed40, 0xd6c824bf3a6ecaa7, + 0x61243d581a817049, 0x048bacb6bbc163a2, 0xd9a38ac27d44cc32, 0x7fddff5baaf410ab, + 0xad6d495aa804824b, 0xe1a6a74f2d8c9f94, 0xd4f7851235dee8e3, 0xfd4b7f886540d893, + 0x247c20042aa4bfda, 0x096ea1c517d1327c, 0xd56966b4361a6685, 0x277da5c31221057d, + 0x94d59893a43acff7, 0x64f0c51ccdc02281, 0x3d33bcc4ff6189db, 0xe005cb184ce66af1, + 0xff5ccd1d1db99bea, 0xb0b854a7fe42980f, 0x7bd46a6a718d4b9f, 0xd10fa8cc22a5fd8c, + 0xd31484952be4bd31, 0xc7fa975fcb243847, 0x4886ed1e5846c407, 0x28cddb791eb70b04, + 0xc2b00be2f573417f, 0x5c9590452180f877, 0x7a6bddfff370eb00, 0xce509e38d6d9d6a4, + 0xebeb0f00647fa702, 0x1dcc06cf76606f06, 0xe4d9f28ba286ff0a, 0xd85a305dc918c262, + 0x475b1d8732225f54, 0x2d4fb51668ccb5fe, 0xa679b9d9d72bba20, 0x53841c0d912d43a5, + 0x3b7eaa48bf12a4e8, 0x781e0e47f22f1ddf, 0xeff20ce60ab50973, 0x20d261d19dffb742, + 0x16a12b03062a2e39, 0x1960eb2239650495, 0x251c16fed50eb8b8, 0x9ac0c330f826016e, + 0xed152665953e7671, 0x02d63194a6369570, 0x5074f08394b1c987, 0x70ba598c90b25ce1, + 0x794a15810b9742f6, 0x0d5925e9fcaf8c6c, 0x3067716cd868744e, 0x910ab077e8d7731b, + 0x6a61bbdb5ac42f61, 0x93513efbf0851567, 0xf494724b9e83e9d5, 0xe887e1985c09648d, + 0x34b1d3c675370cfd, 0xdc35e433bc0d255d, 0xd0aab84234131be0, 0x08042a50b48b7eaf, + 0x9997c4ee44a3ab35, 0x829a7b49201799d0, 0x263b8307b7c54441, 0x752f95f4fd6a6ca6, + 0x927217402c08c6e5, 0x2a8ab754a795d9ee, 0xa442f7552f72943d, 0x2c31334e19781208, + 0x4fa98d7ceaee6291, 0x55c3862f665db309, 0xbd0610175d53b1f3, 0x46fe6cb840413f27, + 0x3fe03792df0cfa59, 0xcfe700372eb85e8f, 0xa7be29e7adbce118, 0xe544ee5cde8431dd, + 0x8a781b1b41f1873e, 0xa5c94c78a0d2f0e7, 0x39412e2877b60728, 0xa1265ef3afc9a62c, + 0xbcc2770c6a2506c5, 0x3ab66dd5dce1ce12, 0xe65499d04a675b37, 0x7d8f523481bfd216, + 0x0f6f64fcec15f389, 0x74efbe618b5b13c8, 0xacdc82b714273e1d, 0xdd40bfe003199d17, + 0x37e99257e7e061f8, 0xfa52626904775aaa, 0x8bbbf63a463d56f9, 0xf0013f1543a26e64, + 0xa8307e9f879ec898, 0xcc4c27a4150177cc, 0x1b432f2cca1d3348, 0xde1d1f8f9f6fa013, + 0x606602a047a7ddd6, 0xd237ab64cc1cb2c7, 0x9b938e7225fcd1d3, 0xec4e03708e0ff476, + 0xfeb2fbda3d03c12d, 0xae0bced2ee43889a, 0x22cb8923ebfb4f43, 0x69360d013cf7396d, + 0x855e3602d2d4e022, 0x073805bad01f784c, 0x33e17a133852f546, 0xdf4874058ac7b638, + 0xba92b29c678aa14a, 0x0ce89fc76cfaadcd, 0x5f9d4e0908339e34, 0xf1afe9291f5923b9, + 0x6e3480f60f4a265f, 0xeebf3a2ab29b841c, 0xe21938a88f91b4ad, 0x57dfeff845c6d3c3, + 0x2f006b0bf62caaf2, 0x62f479ef6f75ee78, 0x11a55ad41c8916a9, 0xf229d29084fed453, + 0x42f1c27b16b000e6, 0x2b1f76749823c074, 0x4b76eca3c2745360, 0x8c98f463b91691bd, + 0x14bcc93cf1ade66a, 0x8885213e6d458397, 0x8e177df0274d4711, 0xb49b73b5503f2951, + 0x10168168c3f96b6b, 0x0e3d963b63cab0ae, 0x8dfc4b5655a1db14, 0xf789f1356e14de5c, + 0x683e68af4e51dac1, 0xc9a84f9d8d4b0fd9, 0x3691e03f52a0f9d1, 0x5ed86e46e1878e80, + 0x3c711a0e99d07150, 0x5a0865b20c4e9310, 0x56fbfc1fe4f0682e, 0xea8d5de3105edf9b, + 0x71abfdb12379187a, 0x2eb99de1bee77b9c, 0x21ecc0ea33cf4523, 0x59a4d7521805c7a1, + 0x3896f5eb56ae7c72, 0xaa638f3db18f75dc, 0x9f39358dabe9808e, 0xb7defa91c00b72ac, + 0x6b5541fd62492d92, 0x6dc6dee8f92e4d5b, 0x353f57abc4beea7e, 0x735769d6da5690ce, + 0x0a234aa642391484, 0xf6f9508028f80d9d, 0xb8e319a27ab3f215, 0x31ad9c1151341a4d, + 0x773c22a57bef5805, 0x45c7561a07968633, 0xf913da9e249dbe36, 0xda652d9b78a64c68, + 0x4c27a97f3bc334ef, 0x76621220e66b17f4, 0x967743899acd7d0b, 0xf3ee5bcae0ed6782, + 0x409f753600c879fc, 0x06d09a39b5926db6, 0x6f83aeb0317ac588, 0x01e6ca4a86381f21, + 0x66ff3462d19f3025, 0x72207c24ddfd3bfb, 0x4af6b6d3e2ece2eb, 0x9c994dbec7ea08de, + 0x49ace597b09a8bc4, 0xb38c4766cf0797ba, 0x131b9373c57c2a75, 0xb1822cce61931e58, + 0x9d7555b909ba1c0c, 0x127fafdd937d11d2, 0x29da3badc66d92e4, 0xa2c1d57154c2ecbc, + 0x58c5134d82f6fe24, 0x1c3ae3515b62274f, 0xe907c82e01cb8126, 0xf8ed091913e37fcb, + 0x3249d8f9c80046c9, 0x80cf9bede388fb63, 0x1881539a116cf19e, 0x5103f3f76bd52457, + 0x15b7e6f5ae47f7a8, 0xdbd7c6ded47e9ccf, 0x44e55c410228bb1a, 0xb647d4255edb4e99, + 0x5d11882bb8aafc30, 0xf5098bbb29d3212a, 0x8fb5ea14e90296b3, 0x677b942157dd025a, + 0xfb58e7c0a390acb5, 0x89d3674c83bd4a01, 0x9e2da4df4bf3b93b, 0xfcc41e328cab4829, + 0x03f38c96ba582c52, 0xcad1bdbd7fd85db2, 0xbbb442c16082ae83, 0xb95fe86ba5da9ab0, + 0xb22e04673771a93f, 0x845358c9493152d8, 0xbe2a488697b4541e, 0x95a2dc2dd38e6966, + 0xc02c11ac923c852b, 0x2388b1990df2a87b, 0x7c8008fa1b4f37be, 0x1f70d0c84d54e503, + 0x5490adec7ece57d4, 0x002b3c27d9063a3a, 0x7eaea3848030a2bf, 0xc602326ded2003c0, + 0x83a7287d69a94086, 0xc57a5fcb30f57a8a, 0xb56844e479ebe779, 0xa373b40f05dcbce9, + 0xd71a786e88570ee2, 0x879cbacdbde8f6a0, 0x976ad1bcc164a32f, 0xab21e25e9666d78b, + 0x901063aae5e5c33c, 0x9818b34448698d90, 0xe36487ae3e1e8abb, 0xafbdf931893bdcb4, + 0x6345a0dc5fbbd519, 0x8628fe269b9465ca, 0x1e5d01603f9c51ec, 0x4de44006a15049b7, + 0xbf6c70e5f776cbb1, 0x411218f2ef552bed, 0xcb0c0708705a36a3, 0xe74d14754f986044, + 0xcd56d9430ea8280e, 0xc12591d7535f5065, 0xc83223f1720aef96, 0xc3a0396f7363a51f, +} diff --git a/processor/tiger/tiger.go b/processor/tiger/tiger.go new file mode 100644 index 0000000..e123976 --- /dev/null +++ b/processor/tiger/tiger.go @@ -0,0 +1,118 @@ +// Package tiger implements the Tiger hash algorithm. It is a copy of https://github.com/cxmcc/tiger +// at bde35e2713d7, under the MIT license in LICENSE, changed to read input as little-endian on +// every machine, as Tiger is defined, rather than in the machine's byte order +package tiger + +import "hash" + +// The size of a Tiger hash value in bytes +const Size = 24 + +// The blocksize of Tiger hash function in bytes +const BlockSize = 64 + +const ( + chunk = 64 + initA = 0x0123456789abcdef + initB = 0xfedcba9876543210 + initC = 0xf096a5b4c3b2e187 +) + +type digest struct { + a uint64 + b uint64 + c uint64 + x [chunk]byte + nx int + length uint64 + ver int +} + +func (d *digest) Reset() { + d.a = initA + d.b = initB + d.c = initC + d.nx = 0 + d.length = 0 +} + +// New returns a new hash.Hash computing the Tiger hash value +func New() hash.Hash { + d := new(digest) + d.Reset() + d.ver = 1 + return d +} + +// New returns a new hash.Hash computing the Tiger2 hash value +func New2() hash.Hash { + d := new(digest) + d.Reset() + d.ver = 2 + return d +} + +func (d *digest) BlockSize() int { + return BlockSize +} + +func (d *digest) Size() int { + return Size +} + +func (d *digest) Write(p []byte) (length int, err error) { + length = len(p) + d.length += uint64(length) + if d.nx > 0 { + n := len(p) + if n > chunk-d.nx { + n = chunk - d.nx + } + copy(d.x[d.nx:d.nx+n], p[:n]) + d.nx += n + if d.nx == chunk { + d.compress(d.x[:chunk]) + d.nx = 0 + } + p = p[n:] + } + for len(p) >= chunk { + d.compress(p[:chunk]) + p = p[chunk:] + } + if len(p) > 0 { + d.nx = copy(d.x[:], p) + } + return +} + +func (d digest) Sum(in []byte) []byte { + length := d.length + var tmp [64]byte + if d.ver == 1 { + tmp[0] = 0x01 + } else { + tmp[0] = 0x80 + } + + size := length & 0x3f + if size < 56 { + d.Write(tmp[:56-size]) + } else { + d.Write(tmp[:64+56-size]) + } + + length <<= 3 + for i := uint(0); i < 8; i++ { + tmp[i] = byte(length >> (8 * i)) + } + d.Write(tmp[:8]) + + for i := uint(0); i < 8; i++ { + tmp[i] = byte(d.a >> (8 * i)) + tmp[i+8] = byte(d.b >> (8 * i)) + tmp[i+16] = byte(d.c >> (8 * i)) + } + + return append(in, tmp[:24]...) +} diff --git a/processor/tiger/tiger_test.go b/processor/tiger/tiger_test.go new file mode 100644 index 0000000..bfab2de --- /dev/null +++ b/processor/tiger/tiger_test.go @@ -0,0 +1,58 @@ +package tiger + +import ( + "encoding/hex" + "strings" + "testing" +) + +// test vectors from the Tiger reference, which hashdeep and rhash agree with +func TestTiger(t *testing.T) { + cases := map[string]string{ + "": "3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3", + "abc": "2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93", + "Tiger": "dd00230799f5009fec6debc838bb6a27df2b9d6f110c7937", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-": "f71c8583902afb879edfe610f82c0d4786a3a534504486b5", + strings.Repeat("a", 1000000): "6db0e2729cbead93d715c6a7d36302e9b3cee0d2bc314b41", + } + for input, want := range cases { + d := New() + // written in pieces, so input split across blocks is hashed the same + for i := 0; i < len(input); i += 37 { + _, _ = d.Write([]byte(input[i:min(i+37, len(input))])) + } + if got := hex.EncodeToString(d.Sum(nil)); got != want { + t.Errorf("tiger of %.20q: expected %s got %s", input, want, got) + } + } +} + +// as upstream checks, Sum part way through leaves the state alone, and Reset starts again +func TestTigerSumAndReset(t *testing.T) { + d := New() + _, _ = d.Write([]byte("Ti")) + if got := hex.EncodeToString(d.Sum(nil)); got == "dd00230799f5009fec6debc838bb6a27df2b9d6f110c7937" { + t.Fatal("expected the hash of a partial write to differ") + } + _, _ = d.Write([]byte("ger")) + want := "dd00230799f5009fec6debc838bb6a27df2b9d6f110c7937" + if got := hex.EncodeToString(d.Sum(nil)); got != want { + t.Errorf("after Sum part way through: expected %s got %s", want, got) + } + if got := hex.EncodeToString(d.Sum(nil)); got != want { + t.Errorf("Sum called twice: expected %s got %s", want, got) + } + prefix := []byte("prefix") + if got := d.Sum(prefix); string(got[:len(prefix)]) != "prefix" || hex.EncodeToString(got[len(prefix):]) != want { + t.Errorf("Sum should append to its argument, got %x", got) + } + + d.Reset() + _, _ = d.Write([]byte("abc")) + if got := hex.EncodeToString(d.Sum(nil)); got != "2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93" { + t.Errorf("after Reset: expected the hash of abc got %s", got) + } + if d.Size() != 24 || d.BlockSize() != 64 { + t.Errorf("expected size 24 and block size 64, got %d and %d", d.Size(), d.BlockSize()) + } +} diff --git a/processor/workers.go b/processor/workers.go index 69b7ff4..428e28c 100644 --- a/processor/workers.go +++ b/processor/workers.go @@ -23,8 +23,10 @@ import ( "syscall" "time" + "github.com/boyter/hashit/processor/tiger" "github.com/cespare/xxhash/v2" "github.com/djherbis/times" + "github.com/jzelinskie/whirlpool" "github.com/minio/blake2b-simd" "github.com/zeebo/blake3" "go.felesatra.moe/hash/ed2k" @@ -251,6 +253,8 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) sha3_384_d := sha3.New384() sha3_512_d := sha3.New512() ed2k_d := ed2k.New() + tiger_d := tiger.New() + whirlpool_d := whirlpool.New() chanSize := 50 // 50 in tests has less backpressure than 10 but isn't so large as to cause issues @@ -271,6 +275,8 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) sha3_384_c := make(chan []byte, chanSize) sha3_512_c := make(chan []byte, chanSize) ed2k_c := make(chan []byte, chanSize) + tiger_c := make(chan []byte, chanSize) + whirlpool_c := make(chan []byte, chanSize) var wg sync.WaitGroup @@ -440,6 +446,46 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) wg.Done() }() } + if hasHash(HashNames.Tiger) { + wg.Add(1) + go func() { + for b := range tiger_c { + _, _ = tiger_d.Write(b) + } + wg.Done() + }() + } + if hasHash(HashNames.Whirlpool) { + wg.Add(1) + go func() { + for b := range whirlpool_c { + _, _ = whirlpool_d.Write(b) + } + wg.Done() + }() + } + + closeAll := func() { + close(crc32c) + close(xxhash64c) + close(md4c) + close(md5c) + close(sha1c) + close(sha224c) + close(sha256c) + close(sha384c) + close(sha512c) + close(blake2b_256_c) + close(blake2b_512_c) + close(blake3c) + close(sha3_224_c) + close(sha3_256_c) + close(sha3_384_c) + close(sha3_512_c) + close(ed2k_c) + close(tiger_c) + close(whirlpool_c) + } sum := 0 data := make([]byte, 4_194_304) @@ -447,6 +493,9 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) n, err := file.Read(data) if err != nil && err != io.EOF { fileFailed(filename, fmt.Sprintf("reading file %s: %s", filename, err.Error())) + // the hashing goroutines would otherwise wait on their channels forever + closeAll() + wg.Wait() return Result{}, err } @@ -519,30 +568,19 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) if hasHash(HashNames.Ed2k) { ed2k_c <- tmp[:n] } + if hasHash(HashNames.Tiger) { + tiger_c <- tmp[:n] + } + if hasHash(HashNames.Whirlpool) { + whirlpool_c <- tmp[:n] + } if err == io.EOF { break } } - close(crc32c) - close(xxhash64c) - close(md4c) - close(md5c) - close(sha1c) - close(sha224c) - close(sha256c) - close(sha384c) - close(sha512c) - close(blake2b_256_c) - close(blake2b_512_c) - close(blake3c) - close(sha3_224_c) - close(sha3_256_c) - close(sha3_384_c) - close(sha3_512_c) - close(ed2k_c) - + closeAll() wg.Wait() return Result{ @@ -565,6 +603,8 @@ func processScanner(filename string, fsize int, bar progressBar) (Result, error) Sha3384: encodeIfHashEnabled(sha3_384_d, HashNames.Sha3384), Sha3512: encodeIfHashEnabled(sha3_512_d, HashNames.Sha3512), Ed2k: encodeIfHashEnabled(ed2k_d, HashNames.Ed2k), + Tiger: encodeIfHashEnabled(tiger_d, HashNames.Tiger), + Whirlpool: encodeIfHashEnabled(whirlpool_d, HashNames.Whirlpool), }, nil } @@ -590,6 +630,8 @@ func processStandardInput(output chan Result) { sha3_384_d := sha3.New384() sha3_512_d := sha3.New512() ed2k_d := ed2k.New() + tiger_d := tiger.New() + whirlpool_d := whirlpool.New() crc32c := make(chan []byte, 10) xxhash64c := make(chan []byte, 10) @@ -608,6 +650,8 @@ func processStandardInput(output chan Result) { sha3_384_c := make(chan []byte, 10) sha3_512_c := make(chan []byte, 10) ed2k_c := make(chan []byte, 10) + tiger_c := make(chan []byte, 10) + whirlpool_c := make(chan []byte, 10) var wg sync.WaitGroup @@ -776,6 +820,24 @@ func processStandardInput(output chan Result) { wg.Done() }() } + if hasHash(HashNames.Tiger) { + wg.Add(1) + go func() { + for b := range tiger_c { + _, _ = tiger_d.Write(b) + } + wg.Done() + }() + } + if hasHash(HashNames.Whirlpool) { + wg.Add(1) + go func() { + for b := range whirlpool_c { + _, _ = whirlpool_d.Write(b) + } + wg.Done() + }() + } for { n, err := r.Read(buf[:cap(buf)]) @@ -853,6 +915,12 @@ func processStandardInput(output chan Result) { if hasHash(HashNames.Ed2k) { ed2k_c <- chunk } + if hasHash(HashNames.Tiger) { + tiger_c <- chunk + } + if hasHash(HashNames.Whirlpool) { + whirlpool_c <- chunk + } if err != nil && err != io.EOF { printError(fmt.Sprintf("reading standard input: %s", err.Error())) @@ -877,6 +945,8 @@ func processStandardInput(output chan Result) { close(sha3_384_c) close(sha3_512_c) close(ed2k_c) + close(tiger_c) + close(whirlpool_c) wg.Wait() @@ -900,6 +970,8 @@ func processStandardInput(output chan Result) { Sha3384: encodeIfHashEnabled(sha3_384_d, HashNames.Sha3384), Sha3512: encodeIfHashEnabled(sha3_512_d, HashNames.Sha3512), Ed2k: encodeIfHashEnabled(ed2k_d, HashNames.Ed2k), + Tiger: encodeIfHashEnabled(tiger_d, HashNames.Tiger), + Whirlpool: encodeIfHashEnabled(whirlpool_d, HashNames.Whirlpool), } close(output) @@ -1168,6 +1240,36 @@ func processReadFileParallel(filename string, content *[]byte) (Result, error) { }() } + if hasHash(HashNames.Tiger) { + wg.Add(1) + go func() { + startTime := makeTimestampNano() + d := tiger.New() + _, _ = d.Write(*content) + result.Tiger = hex.EncodeToString(d.Sum(nil)) + + if Trace { + printTrace(fmt.Sprintf("nanoseconds processing tiger: %s: %d", filename, makeTimestampNano()-startTime)) + } + wg.Done() + }() + } + + if hasHash(HashNames.Whirlpool) { + wg.Add(1) + go func() { + startTime := makeTimestampNano() + d := whirlpool.New() + _, _ = d.Write(*content) + result.Whirlpool = hex.EncodeToString(d.Sum(nil)) + + if Trace { + printTrace(fmt.Sprintf("nanoseconds processing whirlpool: %s: %d", filename, makeTimestampNano()-startTime)) + } + wg.Done() + }() + } + wg.Wait() return result, nil } @@ -1363,6 +1465,28 @@ func processReadFile(filename string, content *[]byte) (Result, error) { } } + if hasHash(HashNames.Tiger) { + startTime := makeTimestampNano() + d := tiger.New() + _, _ = d.Write(*content) + result.Tiger = hex.EncodeToString(d.Sum(nil)) + + if Trace { + printTrace(fmt.Sprintf("nanoseconds processing tiger: %s: %d", filename, makeTimestampNano()-startTime)) + } + } + + if hasHash(HashNames.Whirlpool) { + startTime := makeTimestampNano() + d := whirlpool.New() + _, _ = d.Write(*content) + result.Whirlpool = hex.EncodeToString(d.Sum(nil)) + + if Trace { + printTrace(fmt.Sprintf("nanoseconds processing whirlpool: %s: %d", filename, makeTimestampNano()-startTime)) + } + } + return result, nil } diff --git a/processor/workers_test.go b/processor/workers_test.go index dbbcea5..9c93314 100644 --- a/processor/workers_test.go +++ b/processor/workers_test.go @@ -7,7 +7,9 @@ import ( "crypto/sha256" "os" "path/filepath" + "runtime" "testing" + "time" ) func TestProcessReadFile(t *testing.T) { @@ -220,3 +222,35 @@ func TestAllHashPathsAgree(t *testing.T) { } } } + +func TestProcessScannerReadErrorStopsGoroutines(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("reading a directory is how the read error is caused") + } + saved := Hash + defer func() { Hash = saved }() + Hash = []string{"all"} + + // a directory opens but fails to read, which used to leave every hashing goroutine waiting + dir := t.TempDir() + defer func() { + failedFiles.Delete(dir) + fileErrors.Store(false) + }() + before := runtime.NumGoroutine() + for range 5 { + if _, err := processScanner(dir, 10, nil); err == nil { + t.Fatal("expected a read error") + } + } + // goroutines of other tests may still be ending, so allow a moment and a few, as a leak leaves + // one per hash for every read + after := runtime.NumGoroutine() + for i := 0; i < 100 && after > before; i++ { + time.Sleep(10 * time.Millisecond) + after = runtime.NumGoroutine() + } + if after-before >= len(hashPriority) { + t.Errorf("expected no goroutines left running, %d before and %d after", before, after) + } +} diff --git a/test-all.sh b/test-all.sh index 10b3add..aeb24be 100755 --- a/test-all.sh +++ b/test-all.sh @@ -52,14 +52,14 @@ fail_check() { echo -e "$3" fi echo -e "=======================================================" - exit + exit 1 } if ./hashit --not-a-real-option > /dev/null ; then echo -e "${RED}=================================================" echo -e "FAILED Invalid option should produce error code " echo -e "=======================================================" - exit + exit 1 else echo -e "${GREEN}PASSED invalid option test" fi @@ -70,7 +70,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should run correctly with no directory specified" echo -e "=======================================================" - exit + exit 1 fi if ./hashit * > /dev/null ; then @@ -79,7 +79,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should run correctly with all files specified" echo -e "=======================================================" - exit + exit 1 fi if ./hashit "*.go" | grep -q -i 'main.go'; then @@ -88,7 +88,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Globbing test for *.go" echo -e "=======================================================" - exit + exit 1 fi if ./hashit --debug --trace --verbose -f text --hash md5 --no-stream --stream-size 10 -r main.go > /dev/null ; then @@ -97,7 +97,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should run correctly with multiple options" echo -e "=======================================================" - exit + exit 1 fi if ./hashit processor > /dev/null ; then @@ -106,7 +106,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should run correctly with directory specified" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go -c md5 | grep -q -i 'md5'; then @@ -115,7 +115,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with short hash" echo -e "=======================================================" - exit + exit 1 fi for i in 'crc32' 'xxHash64' 'md4' 'md5' 'sha1' 'sha256' 'sha512' @@ -126,7 +126,7 @@ do echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash $i" echo -e "=======================================================" - exit + exit 1 fi done @@ -136,7 +136,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash blake2b256" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hash blake2b512 | grep -q -i 'blake2b-512'; then @@ -145,7 +145,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash blake2b512" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hash sha3224 | grep -q -i 'sha3-224'; then @@ -154,7 +154,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash sha3224" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hash sha3256 | grep -q -i 'sha3-256'; then @@ -163,7 +163,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash sha3256" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hash sha3384 | grep -q -i 'sha3-384'; then @@ -172,7 +172,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash sha3384" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hash sha3512 | grep -q -i 'sha3-512'; then @@ -181,7 +181,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to work with hash sha3512" echo -e "=======================================================" - exit + exit 1 fi if ./hashit main.go --hashes | grep -q -i 'md5'; then @@ -190,7 +190,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to display hashes" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --hash xxhash64 | grep -q -i 'e4c191d091bd8853'; then @@ -199,7 +199,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to process xxhash64 stdin" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --hash md5 | grep -q -i 'b1946ac92492d2347c6235b4d2611184'; then @@ -208,7 +208,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to process md5 stdin" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --hash sha1 | grep -q -i 'f572d396fae9206628714fb2ce00f72e94f2258f'; then @@ -217,7 +217,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to process sha1 stdin" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --hash sha256 | grep -q -i '5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03'; then @@ -226,7 +226,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to process sha256 stdin" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --hash ed2k | grep -q -i '63481c78ae04c201fa01ea9d2b1db56d'; then @@ -235,7 +235,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to process ed2k stdin" echo -e "=======================================================" - exit + exit 1 fi if ./hashit --mtime ./hashit | grep -q -i 'Mtime'; then @@ -244,7 +244,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to deal with mtime default" echo -e "=======================================================" - exit + exit 1 fi if echo "hello" | ./hashit --mtime 2>&1 | grep -q -i 'WARN'; then @@ -253,7 +253,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to deal with mtime stdin" echo -e "=======================================================" - exit + exit 1 fi a=$(./hashit --no-stream * | sort | md5sum) @@ -264,7 +264,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED stream output test" echo -e "=================================================" - exit + exit 1 fi a=$(./hashit --format sum --hash md5 main.go) @@ -275,7 +275,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sum md5 format test" echo -e "=================================================" - exit + exit 1 fi a=$(./hashit --format sum --hash sha1 main.go) @@ -286,7 +286,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sum sha1 format test" echo -e "=================================================" - exit + exit 1 fi a=$(./hashit --format sum --hash sha256 main.go) @@ -297,7 +297,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sum sha256 format test" echo -e "=================================================" - exit + exit 1 fi a=$(./hashit --format sum --hash sha512 main.go) @@ -308,7 +308,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sum sha512 format test" echo -e "=================================================" - exit + exit 1 fi for i in '' '--stream-size 0' @@ -319,7 +319,7 @@ do echo -e "${RED}=======================================================" echo -e "FAILED $i test" echo -e "=======================================================" - exit + exit 1 fi done @@ -331,7 +331,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED small scanner test" echo -e "=================================================" - exit + exit 1 fi echo "" @@ -341,7 +341,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to create relative hashdeep audit" echo -e "=======================================================" - exit + exit 1 fi if ./hashit --format hashdeep vendor > audit.txt && hashdeep -l -r -a -k audit.txt vendor | grep -q -i 'Audit passed'; then @@ -350,7 +350,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to create large relative hashdeep audit" echo -e "=======================================================" - exit + exit 1 fi mkdir -p /tmp/hashit/ @@ -361,7 +361,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to create full hashdeep audit" echo -e "=======================================================" - exit + exit 1 fi echo "Running SQLite audit tests..." @@ -382,7 +382,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi # Test 2: Modified file @@ -397,7 +397,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi # Test 3: New file @@ -413,7 +413,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi mkdir -p /tmp/hashit/ @@ -424,7 +424,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED Should be able to create full hashdeep audit reverse" echo -e "=======================================================" - exit + exit 1 fi # Test 4: Missing file @@ -445,7 +445,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi echo "" @@ -469,7 +469,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi # Test 6: Audit passes with a common hash subset @@ -484,7 +484,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi # Test 7: Audit fails with a common hash subset after modification @@ -499,7 +499,7 @@ else echo -e "Output was:" echo -e "$AUDIT_OUTPUT" echo -e "=======================================================" - exit + exit 1 fi # Audit edge cases, see https://github.com/boyter/hashit/issues/12 @@ -562,7 +562,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED refuses to overwrite existing output file test" echo -e "=======================================================" - exit + exit 1 fi if "$HASHIT" --overwrite -o "$AUDITDIR/existing.txt" "$AUDITDIR/media" > /dev/null && ! grep -q "keep me" "$AUDITDIR/existing.txt"; then @@ -571,7 +571,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED overwrite replaces existing output file test" echo -e "=======================================================" - exit + exit 1 fi echo changed >> "$AUDITDIR/media/a.txt" @@ -581,7 +581,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED audit detects modified file test" echo -e "=======================================================" - exit + exit 1 fi audit_test "sqlite audit file inside audited directory test" \ "cd '$AUDITDIR/media' && '$HASHIT' -f sqlite -o audit.db . > /dev/null && '$HASHIT' -a audit.db ." @@ -591,7 +591,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sqlite refuses to overwrite existing database test" echo -e "=======================================================" - exit + exit 1 fi echo "not a database" > "$AUDITDIR/notadb.txt" @@ -601,7 +601,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sqlite overwrite refuses to replace non database test" echo -e "=======================================================" - exit + exit 1 fi audit_test "sqlite overwrite replaces existing database test" \ @@ -616,7 +616,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sqlite audit leaves no files behind test" echo -e "=======================================================" - exit + exit 1 fi mv "$AUDITDIR/media/sub/ünïcode.txt" "$AUDITDIR/media/moved.txt" @@ -626,7 +626,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED sqlite audit detects moved file test" echo -e "=======================================================" - exit + exit 1 fi if (cd "$AUDITDIR/media" && ! "$HASHIT" -a ../sums.md5 -o ../failed-audit.txt . > /dev/null) && grep -q 'Audit failed' "$AUDITDIR/failed-audit.txt"; then echo -e "${GREEN}PASSED failed audit to output file exits non zero test" @@ -634,7 +634,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED failed audit to output file exits non zero test" echo -e "=======================================================" - exit + exit 1 fi # https://github.com/boyter/hashit/issues/19 audit_test "hashdeep can audit hashit --absolute output test" \ @@ -653,7 +653,7 @@ for AUDITFILE in moved.txt moved.db; do echo -e "${RED}=======================================================" echo -e "FAILED allow moved $AUDITFILE test" echo -e "=======================================================" - exit + exit 1 fi done echo 3 > "$AUDITDIR/moved/new" @@ -664,7 +664,7 @@ for AUDITFILE in moved.txt moved.db; do echo -e "${RED}=======================================================" echo -e "FAILED allow moved still fails new file $AUDITFILE test" echo -e "=======================================================" - exit + exit 1 fi done @@ -835,6 +835,37 @@ if command -v rhash > /dev/null; then check "rhash bsd ed2k file test" "cd '$AUDITDIR/unread' && rhash --ed2k --bsd a > ../ed2k.txt && '$HASHIT' -a ../ed2k.txt a | grep -q 'Audit passed'" fi +# tiger and whirlpool, the hashes hashdeep can write besides md5, sha1 and sha256 +mkdir -p "$AUDITDIR/tw/t/sub" +printf '' > "$AUDITDIR/tw/t/empty" +echo hi > "$AUDITDIR/tw/t/hi" +head -c 3000000 /dev/urandom > "$AUDITDIR/tw/t/sub/big" +head -c 64 /dev/urandom > "$AUDITDIR/tw/t/sub/b64" +check "tiger and whirlpool match hashdeep test" \ + "cd '$AUDITDIR/tw' && [ \"\$('$HASHIT' -c tiger,whirlpool -f sum t/hi t/empty t/sub/big t/sub/b64 | sort)\" == \"\$(hashdeep -l -c tiger,whirlpool t/hi t/empty t/sub/big t/sub/b64 | grep -v '^[%#]' | awk -F, '{print \$2 \" \" \$4; print \$3 \" \" \$4}' | sort)\" ]" +check "hashdeep tiger and whirlpool file audit test" "cd '$AUDITDIR/tw' && hashdeep -c tiger,whirlpool -r -l t > tw.hd && '$HASHIT' -a tw.hd t | grep -q 'Audit passed'" +check "hashdeep file with every hash it writes audit test" "cd '$AUDITDIR/tw' && hashdeep -c md5,sha1,sha256,tiger,whirlpool -r -l t > all.hd && '$HASHIT' -a all.hd t | grep -q 'Audit passed'" +check "sum files of tiger and whirlpool audit test" \ + "cd '$AUDITDIR/tw' && '$HASHIT' -c tiger -f sum t > s.txt && '$HASHIT' -a s.txt t | grep -q 'Audit passed' && '$HASHIT' -c whirlpool -f sum t > s.whirlpool && '$HASHIT' -a s.whirlpool t | grep -q 'Audit passed'" +check "sqlite tiger and whirlpool audit test" "cd '$AUDITDIR/tw' && '$HASHIT' -c tiger,whirlpool -f sqlite -o tw.db t > /dev/null && '$HASHIT' -c tiger,whirlpool -a tw.db t | grep -q 'Audit passed'" +# a database written before tiger and whirlpool were added, such as by 1.5.0, has no columns for them and is refused, +# made here by copying a current one into the 1.5.0 table +check "sqlite database without tiger and whirlpool columns is refused test" \ + "cd '$AUDITDIR/tw' && '$HASHIT' -f sqlite -o old.db t > /dev/null && sqlite3 old.db 'create table old (filepath text primary key, crc32 text, xxhash64 text, md4 text, md5 text, sha1 text, sha224 text, sha256 text, sha384 text, sha512 text, blake2b_256 text, blake2b_512 text, blake3 text, sha3_224 text, sha3_256 text, sha3_384 text, sha3_512 text, ed2k text, size integer not null, mtime text null); insert into old select filepath, crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes; drop table file_hashes; alter table old rename to file_hashes' && ! '$HASHIT' -a old.db t > old.out 2>&1 && grep -q 'older version of hashit' old.out" +# the hashdeep format holds every hashdeep hash requested, in hashdeep's order, and md5 and sha256 by default +check "hashdeep format writes requested hashdeep hashes test" \ + "cd '$AUDITDIR/tw' && '$HASHIT' -f hashdeep -c whirlpool,tiger,sha1 t > req.hd && grep -q '^%%%% size,sha1,tiger,whirlpool,filename\$' req.hd && hashdeep -r -l -a -k req.hd t | grep -q 'Audit passed' && '$HASHIT' -a req.hd t | grep -q 'Audit passed'" +check "hashdeep format writes md5 and sha256 by default test" \ + "cd '$AUDITDIR/tw' && '$HASHIT' -f hashdeep t | grep -q '^%%%% size,md5,sha256,filename\$'" +check "hashdeep format leaves out hashes hashdeep lacks with a warning test" \ + "cd '$AUDITDIR/tw' && '$HASHIT' -f hashdeep -c md5,blake3 t 2> req.err | grep -q '^%%%% size,md5,filename\$' && grep -q 'leaving out blake3' req.err" +echo changed >> "$AUDITDIR/tw/t/hi" +check "modified file fails tiger and whirlpool audits test" \ + "cd '$AUDITDIR/tw' && ! '$HASHIT' -a tw.hd t > /dev/null && ! '$HASHIT' -a all.hd t > /dev/null && ! '$HASHIT' -a s.txt t > /dev/null && ! '$HASHIT' -a s.whirlpool t > /dev/null && ! '$HASHIT' -a req.hd t > /dev/null && ! hashdeep -r -l -a -k req.hd t > /dev/null && ! '$HASHIT' -c tiger,whirlpool -a tw.db t > /dev/null && ! hashdeep -r -l -a -k tw.hd t > /dev/null" +if command -v rhash > /dev/null; then + check "rhash bsd tiger and whirlpool file test" "cd '$AUDITDIR/unread' && rhash --tiger --whirlpool --bsd a > ../tw.sum && '$HASHIT' -a ../tw.sum a | grep -q 'Audit passed'" +fi + # explicitly supplied special files and broken links are errors, found while walking they are skipped mkdir -p "$AUDITDIR/explicit" echo 1 > "$AUDITDIR/explicit/a" @@ -1091,7 +1122,7 @@ check "conflicting sum lines audited from outside its directory are not a move t mkdir -p "$AUDITDIR/r12/u" echo u > "$AUDITDIR/r12/u/u" (cd "$AUDITDIR/r12/u" && "$HASHIT" -f sqlite -o ../u.db . > /dev/null) -sqlite3 "$AUDITDIR/r12/u.db" "insert into file_hashes select 'x/../u', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes" +sqlite3 "$AUDITDIR/r12/u.db" "insert into file_hashes select 'x/../u', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes" mkdir -p "$AUDITDIR/r12/u/x" chmod 000 "$AUDITDIR/r12/u/u" # the second row lists the same values for the same file, so is a duplicate as in a hashdeep file @@ -1139,7 +1170,7 @@ check "sum line naming a directory is not a file test" "cd '$AUDITDIR/r13/s3' && mkdir -p "$AUDITDIR/r13/uv/A" "$AUDITDIR/r13/uv/C" echo f > "$AUDITDIR/r13/uv/A/f" && echo g > "$AUDITDIR/r13/uv/A/g" && echo cf > "$AUDITDIR/r13/uv/C/f" (cd "$AUDITDIR/r13/uv/A" && "$HASHIT" -f sqlite -o ../m.db . > /dev/null) -sqlite3 "$AUDITDIR/r13/uv/m.db" "insert into file_hashes select '$AUDITDIR/r13/uv/C/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes where filepath = './f'" +sqlite3 "$AUDITDIR/r13/uv/m.db" "insert into file_hashes select '$AUDITDIR/r13/uv/C/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes where filepath = './f'" rm "$AUDITDIR/r13/uv/A/f" && chmod 000 "$AUDITDIR/r13/uv/C/f" check "missing record sharing a path with an unreadable file is not unreadable test" \ "cd '$AUDITDIR/r13/uv/C' && '$HASHIT' -v -a ../m.db . 2>/dev/null | grep -q '^./f: File expected but not found'" @@ -1180,7 +1211,7 @@ check "symlink and .. leading to the symlinked working directory test" "cd '$AUD mkdir -p "$AUDITDIR/r14/ud/A" "$AUDITDIR/r14/ud/O" echo one > "$AUDITDIR/r14/ud/A/f" && echo two > "$AUDITDIR/r14/ud/A/g" (cd "$AUDITDIR/r14/ud/A" && "$HASHIT" -f sqlite -o ../O/m.db . > /dev/null) -sqlite3 "$AUDITDIR/r14/ud/O/m.db" "insert into file_hashes select './/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes where filepath = './f'" +sqlite3 "$AUDITDIR/r14/ud/O/m.db" "insert into file_hashes select './/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes where filepath = './f'" mv "$AUDITDIR/r14/ud/A" "$AUDITDIR/r14/ud/B" && mv "$AUDITDIR/r14/ud/O/m.db" "$AUDITDIR/r14/ud/B/" chmod 000 "$AUDITDIR/r14/ud/B/f" check "every spelling of an unreadable file in a moved sqlite tree is reported test" \ @@ -1200,7 +1231,7 @@ check "sum lines naming the same file with different correct hashes pass test" " mkdir -p "$AUDITDIR/r15/uo/A" echo one > "$AUDITDIR/r15/uo/A/f" && echo two > "$AUDITDIR/r15/uo/A/g" (cd "$AUDITDIR/r15/uo/A" && "$HASHIT" -f sqlite -o ../m.db . > /dev/null) -sqlite3 "$AUDITDIR/r15/uo/m.db" "insert into file_hashes select './/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, size, mtime from file_hashes where filepath = './f'" +sqlite3 "$AUDITDIR/r15/uo/m.db" "insert into file_hashes select './/f', crc32, xxhash64, md4, md5, sha1, sha224, sha256, sha384, sha512, blake2b_256, blake2b_512, blake3, sha3_224, sha3_256, sha3_384, sha3_512, ed2k, tiger, whirlpool, size, mtime from file_hashes where filepath = './f'" mv "$AUDITDIR/r15/uo/A" "$AUDITDIR/r15/uo/B" && chmod 000 "$AUDITDIR/r15/uo/B/f" check "every spelling of an unreadable file in a moved tree with the sqlite file outside it test" \ "cd '$AUDITDIR/r15/uo/B' && '$HASHIT' -v -a ../m.db . 2>/dev/null > ../uo.out; [ \"\$(grep -c 'File could not be read' ../uo.out)\" == 1 ] && ! grep -q 'not found' ../uo.out" @@ -1442,7 +1473,7 @@ for HASHNAME in $("$HASHIT" --hashes | sed -n 's/.*(\(.*\))/\1/p'); do echo -e "${RED}=======================================================" echo -e "FAILED $HASHNAME parallel and stream agree test" echo -e "=======================================================" - exit + exit 1 fi done @@ -1463,7 +1494,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED large stdin hash test" echo -e "=======================================================" - exit + exit 1 fi echo "$AUDITDIR/media/a.txt" > "$AUDITDIR/input-list.txt" @@ -1473,7 +1504,7 @@ else echo -e "${RED}=======================================================" echo -e "FAILED input file used when stdin is a pipe test" echo -e "=======================================================" - exit + exit 1 fi rm -rf "$AUDITDIR" diff --git a/vendor/github.com/jzelinskie/whirlpool/.travis.yml b/vendor/github.com/jzelinskie/whirlpool/.travis.yml new file mode 100644 index 0000000..d7001e8 --- /dev/null +++ b/vendor/github.com/jzelinskie/whirlpool/.travis.yml @@ -0,0 +1,4 @@ +arch: + - ppc64le + - amd64 +language: go diff --git a/vendor/github.com/jzelinskie/whirlpool/LICENSE b/vendor/github.com/jzelinskie/whirlpool/LICENSE new file mode 100644 index 0000000..b9329c2 --- /dev/null +++ b/vendor/github.com/jzelinskie/whirlpool/LICENSE @@ -0,0 +1,24 @@ +Copyright (c) 2012, Jimmy Zelinskie +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/jzelinskie/whirlpool/README.md b/vendor/github.com/jzelinskie/whirlpool/README.md new file mode 100644 index 0000000..3445070 --- /dev/null +++ b/vendor/github.com/jzelinskie/whirlpool/README.md @@ -0,0 +1,43 @@ +# whirlpool.go +A [whirlpool hashing](https://en.wikipedia.org/wiki/Whirlpool_(cryptography)) library for go + +## Build status + +[![Build Status](https://secure.travis-ci.org/jzelinskie/whirlpool.png)](http://travis-ci.org/jzelinskie/whirlpool) + +## Setup + +```bash +$ go get github.com/jzelinskie/whirlpool +``` + +## Example + +```Go +package main + +import ( + "fmt" + "github.com/jzelinskie/whirlpool" +) + +func main() { + w := whirlpool.New() + text := []byte("This is an example.") + w.Write(text) + fmt.Println(w.Sum(nil)) +} +``` + +## Docs + +Check out the [gopkgdoc page](http://go.pkgdoc.org/github.com/jzelinskie/whirlpool), but there isn't much -- it works just like the other hashes in the standard library + +## Branches + +* master - stable, works like the hash libs in the corelib +* trace - same code as master, but prints midstate values to stdout + +## license + +Modified BSD License diff --git a/vendor/github.com/jzelinskie/whirlpool/const.go b/vendor/github.com/jzelinskie/whirlpool/const.go new file mode 100644 index 0000000..4a6f110 --- /dev/null +++ b/vendor/github.com/jzelinskie/whirlpool/const.go @@ -0,0 +1,565 @@ +// Copyright 2012 Jimmy Zelinskie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package whirlpool + +const ( + rounds = 10 + lengthBytes = 32 + lengthBits = 8 * lengthBytes + digestBytes = 64 + digestBits = 8 * digestBytes + wblockBytes = 64 + wblockBits = 8 * wblockBytes +) + +var _C0 = [256]uint64{ + 0x18186018c07830d8, 0x23238c2305af4626, 0xc6c63fc67ef991b8, 0xe8e887e8136fcdfb, + 0x878726874ca113cb, 0xb8b8dab8a9626d11, 0x0101040108050209, 0x4f4f214f426e9e0d, + 0x3636d836adee6c9b, 0xa6a6a2a6590451ff, 0xd2d26fd2debdb90c, 0xf5f5f3f5fb06f70e, + 0x7979f979ef80f296, 0x6f6fa16f5fcede30, 0x91917e91fcef3f6d, 0x52525552aa07a4f8, + 0x60609d6027fdc047, 0xbcbccabc89766535, 0x9b9b569baccd2b37, 0x8e8e028e048c018a, + 0xa3a3b6a371155bd2, 0x0c0c300c603c186c, 0x7b7bf17bff8af684, 0x3535d435b5e16a80, + 0x1d1d741de8693af5, 0xe0e0a7e05347ddb3, 0xd7d77bd7f6acb321, 0xc2c22fc25eed999c, + 0x2e2eb82e6d965c43, 0x4b4b314b627a9629, 0xfefedffea321e15d, 0x575741578216aed5, + 0x15155415a8412abd, 0x7777c1779fb6eee8, 0x3737dc37a5eb6e92, 0xe5e5b3e57b56d79e, + 0x9f9f469f8cd92313, 0xf0f0e7f0d317fd23, 0x4a4a354a6a7f9420, 0xdada4fda9e95a944, + 0x58587d58fa25b0a2, 0xc9c903c906ca8fcf, 0x2929a429558d527c, 0x0a0a280a5022145a, + 0xb1b1feb1e14f7f50, 0xa0a0baa0691a5dc9, 0x6b6bb16b7fdad614, 0x85852e855cab17d9, + 0xbdbdcebd8173673c, 0x5d5d695dd234ba8f, 0x1010401080502090, 0xf4f4f7f4f303f507, + 0xcbcb0bcb16c08bdd, 0x3e3ef83eedc67cd3, 0x0505140528110a2d, 0x676781671fe6ce78, + 0xe4e4b7e47353d597, 0x27279c2725bb4e02, 0x4141194132588273, 0x8b8b168b2c9d0ba7, + 0xa7a7a6a7510153f6, 0x7d7de97dcf94fab2, 0x95956e95dcfb3749, 0xd8d847d88e9fad56, + 0xfbfbcbfb8b30eb70, 0xeeee9fee2371c1cd, 0x7c7ced7cc791f8bb, 0x6666856617e3cc71, + 0xdddd53dda68ea77b, 0x17175c17b84b2eaf, 0x4747014702468e45, 0x9e9e429e84dc211a, + 0xcaca0fca1ec589d4, 0x2d2db42d75995a58, 0xbfbfc6bf9179632e, 0x07071c07381b0e3f, + 0xadad8ead012347ac, 0x5a5a755aea2fb4b0, 0x838336836cb51bef, 0x3333cc3385ff66b6, + 0x636391633ff2c65c, 0x02020802100a0412, 0xaaaa92aa39384993, 0x7171d971afa8e2de, + 0xc8c807c80ecf8dc6, 0x19196419c87d32d1, 0x494939497270923b, 0xd9d943d9869aaf5f, + 0xf2f2eff2c31df931, 0xe3e3abe34b48dba8, 0x5b5b715be22ab6b9, 0x88881a8834920dbc, + 0x9a9a529aa4c8293e, 0x262698262dbe4c0b, 0x3232c8328dfa64bf, 0xb0b0fab0e94a7d59, + 0xe9e983e91b6acff2, 0x0f0f3c0f78331e77, 0xd5d573d5e6a6b733, 0x80803a8074ba1df4, + 0xbebec2be997c6127, 0xcdcd13cd26de87eb, 0x3434d034bde46889, 0x48483d487a759032, + 0xffffdbffab24e354, 0x7a7af57af78ff48d, 0x90907a90f4ea3d64, 0x5f5f615fc23ebe9d, + 0x202080201da0403d, 0x6868bd6867d5d00f, 0x1a1a681ad07234ca, 0xaeae82ae192c41b7, + 0xb4b4eab4c95e757d, 0x54544d549a19a8ce, 0x93937693ece53b7f, 0x222288220daa442f, + 0x64648d6407e9c863, 0xf1f1e3f1db12ff2a, 0x7373d173bfa2e6cc, 0x12124812905a2482, + 0x40401d403a5d807a, 0x0808200840281048, 0xc3c32bc356e89b95, 0xecec97ec337bc5df, + 0xdbdb4bdb9690ab4d, 0xa1a1bea1611f5fc0, 0x8d8d0e8d1c830791, 0x3d3df43df5c97ac8, + 0x97976697ccf1335b, 0x0000000000000000, 0xcfcf1bcf36d483f9, 0x2b2bac2b4587566e, + 0x7676c57697b3ece1, 0x8282328264b019e6, 0xd6d67fd6fea9b128, 0x1b1b6c1bd87736c3, + 0xb5b5eeb5c15b7774, 0xafaf86af112943be, 0x6a6ab56a77dfd41d, 0x50505d50ba0da0ea, + 0x45450945124c8a57, 0xf3f3ebf3cb18fb38, 0x3030c0309df060ad, 0xefef9bef2b74c3c4, + 0x3f3ffc3fe5c37eda, 0x55554955921caac7, 0xa2a2b2a2791059db, 0xeaea8fea0365c9e9, + 0x656589650fecca6a, 0xbabad2bab9686903, 0x2f2fbc2f65935e4a, 0xc0c027c04ee79d8e, + 0xdede5fdebe81a160, 0x1c1c701ce06c38fc, 0xfdfdd3fdbb2ee746, 0x4d4d294d52649a1f, + 0x92927292e4e03976, 0x7575c9758fbceafa, 0x06061806301e0c36, 0x8a8a128a249809ae, + 0xb2b2f2b2f940794b, 0xe6e6bfe66359d185, 0x0e0e380e70361c7e, 0x1f1f7c1ff8633ee7, + 0x6262956237f7c455, 0xd4d477d4eea3b53a, 0xa8a89aa829324d81, 0x96966296c4f43152, + 0xf9f9c3f99b3aef62, 0xc5c533c566f697a3, 0x2525942535b14a10, 0x59597959f220b2ab, + 0x84842a8454ae15d0, 0x7272d572b7a7e4c5, 0x3939e439d5dd72ec, 0x4c4c2d4c5a619816, + 0x5e5e655eca3bbc94, 0x7878fd78e785f09f, 0x3838e038ddd870e5, 0x8c8c0a8c14860598, + 0xd1d163d1c6b2bf17, 0xa5a5aea5410b57e4, 0xe2e2afe2434dd9a1, 0x616199612ff8c24e, + 0xb3b3f6b3f1457b42, 0x2121842115a54234, 0x9c9c4a9c94d62508, 0x1e1e781ef0663cee, + 0x4343114322528661, 0xc7c73bc776fc93b1, 0xfcfcd7fcb32be54f, 0x0404100420140824, + 0x51515951b208a2e3, 0x99995e99bcc72f25, 0x6d6da96d4fc4da22, 0x0d0d340d68391a65, + 0xfafacffa8335e979, 0xdfdf5bdfb684a369, 0x7e7ee57ed79bfca9, 0x242490243db44819, + 0x3b3bec3bc5d776fe, 0xabab96ab313d4b9a, 0xcece1fce3ed181f0, 0x1111441188552299, + 0x8f8f068f0c890383, 0x4e4e254e4a6b9c04, 0xb7b7e6b7d1517366, 0xebeb8beb0b60cbe0, + 0x3c3cf03cfdcc78c1, 0x81813e817cbf1ffd, 0x94946a94d4fe3540, 0xf7f7fbf7eb0cf31c, + 0xb9b9deb9a1676f18, 0x13134c13985f268b, 0x2c2cb02c7d9c5851, 0xd3d36bd3d6b8bb05, + 0xe7e7bbe76b5cd38c, 0x6e6ea56e57cbdc39, 0xc4c437c46ef395aa, 0x03030c03180f061b, + 0x565645568a13acdc, 0x44440d441a49885e, 0x7f7fe17fdf9efea0, 0xa9a99ea921374f88, + 0x2a2aa82a4d825467, 0xbbbbd6bbb16d6b0a, 0xc1c123c146e29f87, 0x53535153a202a6f1, + 0xdcdc57dcae8ba572, 0x0b0b2c0b58271653, 0x9d9d4e9d9cd32701, 0x6c6cad6c47c1d82b, + 0x3131c43195f562a4, 0x7474cd7487b9e8f3, 0xf6f6fff6e309f115, 0x464605460a438c4c, + 0xacac8aac092645a5, 0x89891e893c970fb5, 0x14145014a04428b4, 0xe1e1a3e15b42dfba, + 0x16165816b04e2ca6, 0x3a3ae83acdd274f7, 0x6969b9696fd0d206, 0x09092409482d1241, + 0x7070dd70a7ade0d7, 0xb6b6e2b6d954716f, 0xd0d067d0ceb7bd1e, 0xeded93ed3b7ec7d6, + 0xcccc17cc2edb85e2, 0x424215422a578468, 0x98985a98b4c22d2c, 0xa4a4aaa4490e55ed, + 0x2828a0285d885075, 0x5c5c6d5cda31b886, 0xf8f8c7f8933fed6b, 0x8686228644a411c2, +} + +var _C1 = [256]uint64{ + 0xd818186018c07830, 0x2623238c2305af46, 0xb8c6c63fc67ef991, 0xfbe8e887e8136fcd, + 0xcb878726874ca113, 0x11b8b8dab8a9626d, 0x0901010401080502, 0x0d4f4f214f426e9e, + 0x9b3636d836adee6c, 0xffa6a6a2a6590451, 0x0cd2d26fd2debdb9, 0x0ef5f5f3f5fb06f7, + 0x967979f979ef80f2, 0x306f6fa16f5fcede, 0x6d91917e91fcef3f, 0xf852525552aa07a4, + 0x4760609d6027fdc0, 0x35bcbccabc897665, 0x379b9b569baccd2b, 0x8a8e8e028e048c01, + 0xd2a3a3b6a371155b, 0x6c0c0c300c603c18, 0x847b7bf17bff8af6, 0x803535d435b5e16a, + 0xf51d1d741de8693a, 0xb3e0e0a7e05347dd, 0x21d7d77bd7f6acb3, 0x9cc2c22fc25eed99, + 0x432e2eb82e6d965c, 0x294b4b314b627a96, 0x5dfefedffea321e1, 0xd5575741578216ae, + 0xbd15155415a8412a, 0xe87777c1779fb6ee, 0x923737dc37a5eb6e, 0x9ee5e5b3e57b56d7, + 0x139f9f469f8cd923, 0x23f0f0e7f0d317fd, 0x204a4a354a6a7f94, 0x44dada4fda9e95a9, + 0xa258587d58fa25b0, 0xcfc9c903c906ca8f, 0x7c2929a429558d52, 0x5a0a0a280a502214, + 0x50b1b1feb1e14f7f, 0xc9a0a0baa0691a5d, 0x146b6bb16b7fdad6, 0xd985852e855cab17, + 0x3cbdbdcebd817367, 0x8f5d5d695dd234ba, 0x9010104010805020, 0x07f4f4f7f4f303f5, + 0xddcbcb0bcb16c08b, 0xd33e3ef83eedc67c, 0x2d0505140528110a, 0x78676781671fe6ce, + 0x97e4e4b7e47353d5, 0x0227279c2725bb4e, 0x7341411941325882, 0xa78b8b168b2c9d0b, + 0xf6a7a7a6a7510153, 0xb27d7de97dcf94fa, 0x4995956e95dcfb37, 0x56d8d847d88e9fad, + 0x70fbfbcbfb8b30eb, 0xcdeeee9fee2371c1, 0xbb7c7ced7cc791f8, 0x716666856617e3cc, + 0x7bdddd53dda68ea7, 0xaf17175c17b84b2e, 0x454747014702468e, 0x1a9e9e429e84dc21, + 0xd4caca0fca1ec589, 0x582d2db42d75995a, 0x2ebfbfc6bf917963, 0x3f07071c07381b0e, + 0xacadad8ead012347, 0xb05a5a755aea2fb4, 0xef838336836cb51b, 0xb63333cc3385ff66, + 0x5c636391633ff2c6, 0x1202020802100a04, 0x93aaaa92aa393849, 0xde7171d971afa8e2, + 0xc6c8c807c80ecf8d, 0xd119196419c87d32, 0x3b49493949727092, 0x5fd9d943d9869aaf, + 0x31f2f2eff2c31df9, 0xa8e3e3abe34b48db, 0xb95b5b715be22ab6, 0xbc88881a8834920d, + 0x3e9a9a529aa4c829, 0x0b262698262dbe4c, 0xbf3232c8328dfa64, 0x59b0b0fab0e94a7d, + 0xf2e9e983e91b6acf, 0x770f0f3c0f78331e, 0x33d5d573d5e6a6b7, 0xf480803a8074ba1d, + 0x27bebec2be997c61, 0xebcdcd13cd26de87, 0x893434d034bde468, 0x3248483d487a7590, + 0x54ffffdbffab24e3, 0x8d7a7af57af78ff4, 0x6490907a90f4ea3d, 0x9d5f5f615fc23ebe, + 0x3d202080201da040, 0x0f6868bd6867d5d0, 0xca1a1a681ad07234, 0xb7aeae82ae192c41, + 0x7db4b4eab4c95e75, 0xce54544d549a19a8, 0x7f93937693ece53b, 0x2f222288220daa44, + 0x6364648d6407e9c8, 0x2af1f1e3f1db12ff, 0xcc7373d173bfa2e6, 0x8212124812905a24, + 0x7a40401d403a5d80, 0x4808082008402810, 0x95c3c32bc356e89b, 0xdfecec97ec337bc5, + 0x4ddbdb4bdb9690ab, 0xc0a1a1bea1611f5f, 0x918d8d0e8d1c8307, 0xc83d3df43df5c97a, + 0x5b97976697ccf133, 0x0000000000000000, 0xf9cfcf1bcf36d483, 0x6e2b2bac2b458756, + 0xe17676c57697b3ec, 0xe68282328264b019, 0x28d6d67fd6fea9b1, 0xc31b1b6c1bd87736, + 0x74b5b5eeb5c15b77, 0xbeafaf86af112943, 0x1d6a6ab56a77dfd4, 0xea50505d50ba0da0, + 0x5745450945124c8a, 0x38f3f3ebf3cb18fb, 0xad3030c0309df060, 0xc4efef9bef2b74c3, + 0xda3f3ffc3fe5c37e, 0xc755554955921caa, 0xdba2a2b2a2791059, 0xe9eaea8fea0365c9, + 0x6a656589650fecca, 0x03babad2bab96869, 0x4a2f2fbc2f65935e, 0x8ec0c027c04ee79d, + 0x60dede5fdebe81a1, 0xfc1c1c701ce06c38, 0x46fdfdd3fdbb2ee7, 0x1f4d4d294d52649a, + 0x7692927292e4e039, 0xfa7575c9758fbcea, 0x3606061806301e0c, 0xae8a8a128a249809, + 0x4bb2b2f2b2f94079, 0x85e6e6bfe66359d1, 0x7e0e0e380e70361c, 0xe71f1f7c1ff8633e, + 0x556262956237f7c4, 0x3ad4d477d4eea3b5, 0x81a8a89aa829324d, 0x5296966296c4f431, + 0x62f9f9c3f99b3aef, 0xa3c5c533c566f697, 0x102525942535b14a, 0xab59597959f220b2, + 0xd084842a8454ae15, 0xc57272d572b7a7e4, 0xec3939e439d5dd72, 0x164c4c2d4c5a6198, + 0x945e5e655eca3bbc, 0x9f7878fd78e785f0, 0xe53838e038ddd870, 0x988c8c0a8c148605, + 0x17d1d163d1c6b2bf, 0xe4a5a5aea5410b57, 0xa1e2e2afe2434dd9, 0x4e616199612ff8c2, + 0x42b3b3f6b3f1457b, 0x342121842115a542, 0x089c9c4a9c94d625, 0xee1e1e781ef0663c, + 0x6143431143225286, 0xb1c7c73bc776fc93, 0x4ffcfcd7fcb32be5, 0x2404041004201408, + 0xe351515951b208a2, 0x2599995e99bcc72f, 0x226d6da96d4fc4da, 0x650d0d340d68391a, + 0x79fafacffa8335e9, 0x69dfdf5bdfb684a3, 0xa97e7ee57ed79bfc, 0x19242490243db448, + 0xfe3b3bec3bc5d776, 0x9aabab96ab313d4b, 0xf0cece1fce3ed181, 0x9911114411885522, + 0x838f8f068f0c8903, 0x044e4e254e4a6b9c, 0x66b7b7e6b7d15173, 0xe0ebeb8beb0b60cb, + 0xc13c3cf03cfdcc78, 0xfd81813e817cbf1f, 0x4094946a94d4fe35, 0x1cf7f7fbf7eb0cf3, + 0x18b9b9deb9a1676f, 0x8b13134c13985f26, 0x512c2cb02c7d9c58, 0x05d3d36bd3d6b8bb, + 0x8ce7e7bbe76b5cd3, 0x396e6ea56e57cbdc, 0xaac4c437c46ef395, 0x1b03030c03180f06, + 0xdc565645568a13ac, 0x5e44440d441a4988, 0xa07f7fe17fdf9efe, 0x88a9a99ea921374f, + 0x672a2aa82a4d8254, 0x0abbbbd6bbb16d6b, 0x87c1c123c146e29f, 0xf153535153a202a6, + 0x72dcdc57dcae8ba5, 0x530b0b2c0b582716, 0x019d9d4e9d9cd327, 0x2b6c6cad6c47c1d8, + 0xa43131c43195f562, 0xf37474cd7487b9e8, 0x15f6f6fff6e309f1, 0x4c464605460a438c, + 0xa5acac8aac092645, 0xb589891e893c970f, 0xb414145014a04428, 0xbae1e1a3e15b42df, + 0xa616165816b04e2c, 0xf73a3ae83acdd274, 0x066969b9696fd0d2, 0x4109092409482d12, + 0xd77070dd70a7ade0, 0x6fb6b6e2b6d95471, 0x1ed0d067d0ceb7bd, 0xd6eded93ed3b7ec7, + 0xe2cccc17cc2edb85, 0x68424215422a5784, 0x2c98985a98b4c22d, 0xeda4a4aaa4490e55, + 0x752828a0285d8850, 0x865c5c6d5cda31b8, 0x6bf8f8c7f8933fed, 0xc28686228644a411, +} + +var _C2 = [256]uint64{ + 0x30d818186018c078, 0x462623238c2305af, 0x91b8c6c63fc67ef9, 0xcdfbe8e887e8136f, + 0x13cb878726874ca1, 0x6d11b8b8dab8a962, 0x0209010104010805, 0x9e0d4f4f214f426e, + 0x6c9b3636d836adee, 0x51ffa6a6a2a65904, 0xb90cd2d26fd2debd, 0xf70ef5f5f3f5fb06, + 0xf2967979f979ef80, 0xde306f6fa16f5fce, 0x3f6d91917e91fcef, 0xa4f852525552aa07, + 0xc04760609d6027fd, 0x6535bcbccabc8976, 0x2b379b9b569baccd, 0x018a8e8e028e048c, + 0x5bd2a3a3b6a37115, 0x186c0c0c300c603c, 0xf6847b7bf17bff8a, 0x6a803535d435b5e1, + 0x3af51d1d741de869, 0xddb3e0e0a7e05347, 0xb321d7d77bd7f6ac, 0x999cc2c22fc25eed, + 0x5c432e2eb82e6d96, 0x96294b4b314b627a, 0xe15dfefedffea321, 0xaed5575741578216, + 0x2abd15155415a841, 0xeee87777c1779fb6, 0x6e923737dc37a5eb, 0xd79ee5e5b3e57b56, + 0x23139f9f469f8cd9, 0xfd23f0f0e7f0d317, 0x94204a4a354a6a7f, 0xa944dada4fda9e95, + 0xb0a258587d58fa25, 0x8fcfc9c903c906ca, 0x527c2929a429558d, 0x145a0a0a280a5022, + 0x7f50b1b1feb1e14f, 0x5dc9a0a0baa0691a, 0xd6146b6bb16b7fda, 0x17d985852e855cab, + 0x673cbdbdcebd8173, 0xba8f5d5d695dd234, 0x2090101040108050, 0xf507f4f4f7f4f303, + 0x8bddcbcb0bcb16c0, 0x7cd33e3ef83eedc6, 0x0a2d050514052811, 0xce78676781671fe6, + 0xd597e4e4b7e47353, 0x4e0227279c2725bb, 0x8273414119413258, 0x0ba78b8b168b2c9d, + 0x53f6a7a7a6a75101, 0xfab27d7de97dcf94, 0x374995956e95dcfb, 0xad56d8d847d88e9f, + 0xeb70fbfbcbfb8b30, 0xc1cdeeee9fee2371, 0xf8bb7c7ced7cc791, 0xcc716666856617e3, + 0xa77bdddd53dda68e, 0x2eaf17175c17b84b, 0x8e45474701470246, 0x211a9e9e429e84dc, + 0x89d4caca0fca1ec5, 0x5a582d2db42d7599, 0x632ebfbfc6bf9179, 0x0e3f07071c07381b, + 0x47acadad8ead0123, 0xb4b05a5a755aea2f, 0x1bef838336836cb5, 0x66b63333cc3385ff, + 0xc65c636391633ff2, 0x041202020802100a, 0x4993aaaa92aa3938, 0xe2de7171d971afa8, + 0x8dc6c8c807c80ecf, 0x32d119196419c87d, 0x923b494939497270, 0xaf5fd9d943d9869a, + 0xf931f2f2eff2c31d, 0xdba8e3e3abe34b48, 0xb6b95b5b715be22a, 0x0dbc88881a883492, + 0x293e9a9a529aa4c8, 0x4c0b262698262dbe, 0x64bf3232c8328dfa, 0x7d59b0b0fab0e94a, + 0xcff2e9e983e91b6a, 0x1e770f0f3c0f7833, 0xb733d5d573d5e6a6, 0x1df480803a8074ba, + 0x6127bebec2be997c, 0x87ebcdcd13cd26de, 0x68893434d034bde4, 0x903248483d487a75, + 0xe354ffffdbffab24, 0xf48d7a7af57af78f, 0x3d6490907a90f4ea, 0xbe9d5f5f615fc23e, + 0x403d202080201da0, 0xd00f6868bd6867d5, 0x34ca1a1a681ad072, 0x41b7aeae82ae192c, + 0x757db4b4eab4c95e, 0xa8ce54544d549a19, 0x3b7f93937693ece5, 0x442f222288220daa, + 0xc86364648d6407e9, 0xff2af1f1e3f1db12, 0xe6cc7373d173bfa2, 0x248212124812905a, + 0x807a40401d403a5d, 0x1048080820084028, 0x9b95c3c32bc356e8, 0xc5dfecec97ec337b, + 0xab4ddbdb4bdb9690, 0x5fc0a1a1bea1611f, 0x07918d8d0e8d1c83, 0x7ac83d3df43df5c9, + 0x335b97976697ccf1, 0x0000000000000000, 0x83f9cfcf1bcf36d4, 0x566e2b2bac2b4587, + 0xece17676c57697b3, 0x19e68282328264b0, 0xb128d6d67fd6fea9, 0x36c31b1b6c1bd877, + 0x7774b5b5eeb5c15b, 0x43beafaf86af1129, 0xd41d6a6ab56a77df, 0xa0ea50505d50ba0d, + 0x8a5745450945124c, 0xfb38f3f3ebf3cb18, 0x60ad3030c0309df0, 0xc3c4efef9bef2b74, + 0x7eda3f3ffc3fe5c3, 0xaac755554955921c, 0x59dba2a2b2a27910, 0xc9e9eaea8fea0365, + 0xca6a656589650fec, 0x6903babad2bab968, 0x5e4a2f2fbc2f6593, 0x9d8ec0c027c04ee7, + 0xa160dede5fdebe81, 0x38fc1c1c701ce06c, 0xe746fdfdd3fdbb2e, 0x9a1f4d4d294d5264, + 0x397692927292e4e0, 0xeafa7575c9758fbc, 0x0c3606061806301e, 0x09ae8a8a128a2498, + 0x794bb2b2f2b2f940, 0xd185e6e6bfe66359, 0x1c7e0e0e380e7036, 0x3ee71f1f7c1ff863, + 0xc4556262956237f7, 0xb53ad4d477d4eea3, 0x4d81a8a89aa82932, 0x315296966296c4f4, + 0xef62f9f9c3f99b3a, 0x97a3c5c533c566f6, 0x4a102525942535b1, 0xb2ab59597959f220, + 0x15d084842a8454ae, 0xe4c57272d572b7a7, 0x72ec3939e439d5dd, 0x98164c4c2d4c5a61, + 0xbc945e5e655eca3b, 0xf09f7878fd78e785, 0x70e53838e038ddd8, 0x05988c8c0a8c1486, + 0xbf17d1d163d1c6b2, 0x57e4a5a5aea5410b, 0xd9a1e2e2afe2434d, 0xc24e616199612ff8, + 0x7b42b3b3f6b3f145, 0x42342121842115a5, 0x25089c9c4a9c94d6, 0x3cee1e1e781ef066, + 0x8661434311432252, 0x93b1c7c73bc776fc, 0xe54ffcfcd7fcb32b, 0x0824040410042014, + 0xa2e351515951b208, 0x2f2599995e99bcc7, 0xda226d6da96d4fc4, 0x1a650d0d340d6839, + 0xe979fafacffa8335, 0xa369dfdf5bdfb684, 0xfca97e7ee57ed79b, 0x4819242490243db4, + 0x76fe3b3bec3bc5d7, 0x4b9aabab96ab313d, 0x81f0cece1fce3ed1, 0x2299111144118855, + 0x03838f8f068f0c89, 0x9c044e4e254e4a6b, 0x7366b7b7e6b7d151, 0xcbe0ebeb8beb0b60, + 0x78c13c3cf03cfdcc, 0x1ffd81813e817cbf, 0x354094946a94d4fe, 0xf31cf7f7fbf7eb0c, + 0x6f18b9b9deb9a167, 0x268b13134c13985f, 0x58512c2cb02c7d9c, 0xbb05d3d36bd3d6b8, + 0xd38ce7e7bbe76b5c, 0xdc396e6ea56e57cb, 0x95aac4c437c46ef3, 0x061b03030c03180f, + 0xacdc565645568a13, 0x885e44440d441a49, 0xfea07f7fe17fdf9e, 0x4f88a9a99ea92137, + 0x54672a2aa82a4d82, 0x6b0abbbbd6bbb16d, 0x9f87c1c123c146e2, 0xa6f153535153a202, + 0xa572dcdc57dcae8b, 0x16530b0b2c0b5827, 0x27019d9d4e9d9cd3, 0xd82b6c6cad6c47c1, + 0x62a43131c43195f5, 0xe8f37474cd7487b9, 0xf115f6f6fff6e309, 0x8c4c464605460a43, + 0x45a5acac8aac0926, 0x0fb589891e893c97, 0x28b414145014a044, 0xdfbae1e1a3e15b42, + 0x2ca616165816b04e, 0x74f73a3ae83acdd2, 0xd2066969b9696fd0, 0x124109092409482d, + 0xe0d77070dd70a7ad, 0x716fb6b6e2b6d954, 0xbd1ed0d067d0ceb7, 0xc7d6eded93ed3b7e, + 0x85e2cccc17cc2edb, 0x8468424215422a57, 0x2d2c98985a98b4c2, 0x55eda4a4aaa4490e, + 0x50752828a0285d88, 0xb8865c5c6d5cda31, 0xed6bf8f8c7f8933f, 0x11c28686228644a4, +} + +var _C3 = [256]uint64{ + 0x7830d818186018c0, 0xaf462623238c2305, 0xf991b8c6c63fc67e, 0x6fcdfbe8e887e813, + 0xa113cb878726874c, 0x626d11b8b8dab8a9, 0x0502090101040108, 0x6e9e0d4f4f214f42, + 0xee6c9b3636d836ad, 0x0451ffa6a6a2a659, 0xbdb90cd2d26fd2de, 0x06f70ef5f5f3f5fb, + 0x80f2967979f979ef, 0xcede306f6fa16f5f, 0xef3f6d91917e91fc, 0x07a4f852525552aa, + 0xfdc04760609d6027, 0x766535bcbccabc89, 0xcd2b379b9b569bac, 0x8c018a8e8e028e04, + 0x155bd2a3a3b6a371, 0x3c186c0c0c300c60, 0x8af6847b7bf17bff, 0xe16a803535d435b5, + 0x693af51d1d741de8, 0x47ddb3e0e0a7e053, 0xacb321d7d77bd7f6, 0xed999cc2c22fc25e, + 0x965c432e2eb82e6d, 0x7a96294b4b314b62, 0x21e15dfefedffea3, 0x16aed55757415782, + 0x412abd15155415a8, 0xb6eee87777c1779f, 0xeb6e923737dc37a5, 0x56d79ee5e5b3e57b, + 0xd923139f9f469f8c, 0x17fd23f0f0e7f0d3, 0x7f94204a4a354a6a, 0x95a944dada4fda9e, + 0x25b0a258587d58fa, 0xca8fcfc9c903c906, 0x8d527c2929a42955, 0x22145a0a0a280a50, + 0x4f7f50b1b1feb1e1, 0x1a5dc9a0a0baa069, 0xdad6146b6bb16b7f, 0xab17d985852e855c, + 0x73673cbdbdcebd81, 0x34ba8f5d5d695dd2, 0x5020901010401080, 0x03f507f4f4f7f4f3, + 0xc08bddcbcb0bcb16, 0xc67cd33e3ef83eed, 0x110a2d0505140528, 0xe6ce78676781671f, + 0x53d597e4e4b7e473, 0xbb4e0227279c2725, 0x5882734141194132, 0x9d0ba78b8b168b2c, + 0x0153f6a7a7a6a751, 0x94fab27d7de97dcf, 0xfb374995956e95dc, 0x9fad56d8d847d88e, + 0x30eb70fbfbcbfb8b, 0x71c1cdeeee9fee23, 0x91f8bb7c7ced7cc7, 0xe3cc716666856617, + 0x8ea77bdddd53dda6, 0x4b2eaf17175c17b8, 0x468e454747014702, 0xdc211a9e9e429e84, + 0xc589d4caca0fca1e, 0x995a582d2db42d75, 0x79632ebfbfc6bf91, 0x1b0e3f07071c0738, + 0x2347acadad8ead01, 0x2fb4b05a5a755aea, 0xb51bef838336836c, 0xff66b63333cc3385, + 0xf2c65c636391633f, 0x0a04120202080210, 0x384993aaaa92aa39, 0xa8e2de7171d971af, + 0xcf8dc6c8c807c80e, 0x7d32d119196419c8, 0x70923b4949394972, 0x9aaf5fd9d943d986, + 0x1df931f2f2eff2c3, 0x48dba8e3e3abe34b, 0x2ab6b95b5b715be2, 0x920dbc88881a8834, + 0xc8293e9a9a529aa4, 0xbe4c0b262698262d, 0xfa64bf3232c8328d, 0x4a7d59b0b0fab0e9, + 0x6acff2e9e983e91b, 0x331e770f0f3c0f78, 0xa6b733d5d573d5e6, 0xba1df480803a8074, + 0x7c6127bebec2be99, 0xde87ebcdcd13cd26, 0xe468893434d034bd, 0x75903248483d487a, + 0x24e354ffffdbffab, 0x8ff48d7a7af57af7, 0xea3d6490907a90f4, 0x3ebe9d5f5f615fc2, + 0xa0403d202080201d, 0xd5d00f6868bd6867, 0x7234ca1a1a681ad0, 0x2c41b7aeae82ae19, + 0x5e757db4b4eab4c9, 0x19a8ce54544d549a, 0xe53b7f93937693ec, 0xaa442f222288220d, + 0xe9c86364648d6407, 0x12ff2af1f1e3f1db, 0xa2e6cc7373d173bf, 0x5a24821212481290, + 0x5d807a40401d403a, 0x2810480808200840, 0xe89b95c3c32bc356, 0x7bc5dfecec97ec33, + 0x90ab4ddbdb4bdb96, 0x1f5fc0a1a1bea161, 0x8307918d8d0e8d1c, 0xc97ac83d3df43df5, + 0xf1335b97976697cc, 0x0000000000000000, 0xd483f9cfcf1bcf36, 0x87566e2b2bac2b45, + 0xb3ece17676c57697, 0xb019e68282328264, 0xa9b128d6d67fd6fe, 0x7736c31b1b6c1bd8, + 0x5b7774b5b5eeb5c1, 0x2943beafaf86af11, 0xdfd41d6a6ab56a77, 0x0da0ea50505d50ba, + 0x4c8a574545094512, 0x18fb38f3f3ebf3cb, 0xf060ad3030c0309d, 0x74c3c4efef9bef2b, + 0xc37eda3f3ffc3fe5, 0x1caac75555495592, 0x1059dba2a2b2a279, 0x65c9e9eaea8fea03, + 0xecca6a656589650f, 0x686903babad2bab9, 0x935e4a2f2fbc2f65, 0xe79d8ec0c027c04e, + 0x81a160dede5fdebe, 0x6c38fc1c1c701ce0, 0x2ee746fdfdd3fdbb, 0x649a1f4d4d294d52, + 0xe0397692927292e4, 0xbceafa7575c9758f, 0x1e0c360606180630, 0x9809ae8a8a128a24, + 0x40794bb2b2f2b2f9, 0x59d185e6e6bfe663, 0x361c7e0e0e380e70, 0x633ee71f1f7c1ff8, + 0xf7c4556262956237, 0xa3b53ad4d477d4ee, 0x324d81a8a89aa829, 0xf4315296966296c4, + 0x3aef62f9f9c3f99b, 0xf697a3c5c533c566, 0xb14a102525942535, 0x20b2ab59597959f2, + 0xae15d084842a8454, 0xa7e4c57272d572b7, 0xdd72ec3939e439d5, 0x6198164c4c2d4c5a, + 0x3bbc945e5e655eca, 0x85f09f7878fd78e7, 0xd870e53838e038dd, 0x8605988c8c0a8c14, + 0xb2bf17d1d163d1c6, 0x0b57e4a5a5aea541, 0x4dd9a1e2e2afe243, 0xf8c24e616199612f, + 0x457b42b3b3f6b3f1, 0xa542342121842115, 0xd625089c9c4a9c94, 0x663cee1e1e781ef0, + 0x5286614343114322, 0xfc93b1c7c73bc776, 0x2be54ffcfcd7fcb3, 0x1408240404100420, + 0x08a2e351515951b2, 0xc72f2599995e99bc, 0xc4da226d6da96d4f, 0x391a650d0d340d68, + 0x35e979fafacffa83, 0x84a369dfdf5bdfb6, 0x9bfca97e7ee57ed7, 0xb44819242490243d, + 0xd776fe3b3bec3bc5, 0x3d4b9aabab96ab31, 0xd181f0cece1fce3e, 0x5522991111441188, + 0x8903838f8f068f0c, 0x6b9c044e4e254e4a, 0x517366b7b7e6b7d1, 0x60cbe0ebeb8beb0b, + 0xcc78c13c3cf03cfd, 0xbf1ffd81813e817c, 0xfe354094946a94d4, 0x0cf31cf7f7fbf7eb, + 0x676f18b9b9deb9a1, 0x5f268b13134c1398, 0x9c58512c2cb02c7d, 0xb8bb05d3d36bd3d6, + 0x5cd38ce7e7bbe76b, 0xcbdc396e6ea56e57, 0xf395aac4c437c46e, 0x0f061b03030c0318, + 0x13acdc565645568a, 0x49885e44440d441a, 0x9efea07f7fe17fdf, 0x374f88a9a99ea921, + 0x8254672a2aa82a4d, 0x6d6b0abbbbd6bbb1, 0xe29f87c1c123c146, 0x02a6f153535153a2, + 0x8ba572dcdc57dcae, 0x2716530b0b2c0b58, 0xd327019d9d4e9d9c, 0xc1d82b6c6cad6c47, + 0xf562a43131c43195, 0xb9e8f37474cd7487, 0x09f115f6f6fff6e3, 0x438c4c464605460a, + 0x2645a5acac8aac09, 0x970fb589891e893c, 0x4428b414145014a0, 0x42dfbae1e1a3e15b, + 0x4e2ca616165816b0, 0xd274f73a3ae83acd, 0xd0d2066969b9696f, 0x2d12410909240948, + 0xade0d77070dd70a7, 0x54716fb6b6e2b6d9, 0xb7bd1ed0d067d0ce, 0x7ec7d6eded93ed3b, + 0xdb85e2cccc17cc2e, 0x578468424215422a, 0xc22d2c98985a98b4, 0x0e55eda4a4aaa449, + 0x8850752828a0285d, 0x31b8865c5c6d5cda, 0x3fed6bf8f8c7f893, 0xa411c28686228644, +} + +var _C4 = [256]uint64{ + 0xc07830d818186018, 0x05af462623238c23, 0x7ef991b8c6c63fc6, 0x136fcdfbe8e887e8, + 0x4ca113cb87872687, 0xa9626d11b8b8dab8, 0x0805020901010401, 0x426e9e0d4f4f214f, + 0xadee6c9b3636d836, 0x590451ffa6a6a2a6, 0xdebdb90cd2d26fd2, 0xfb06f70ef5f5f3f5, + 0xef80f2967979f979, 0x5fcede306f6fa16f, 0xfcef3f6d91917e91, 0xaa07a4f852525552, + 0x27fdc04760609d60, 0x89766535bcbccabc, 0xaccd2b379b9b569b, 0x048c018a8e8e028e, + 0x71155bd2a3a3b6a3, 0x603c186c0c0c300c, 0xff8af6847b7bf17b, 0xb5e16a803535d435, + 0xe8693af51d1d741d, 0x5347ddb3e0e0a7e0, 0xf6acb321d7d77bd7, 0x5eed999cc2c22fc2, + 0x6d965c432e2eb82e, 0x627a96294b4b314b, 0xa321e15dfefedffe, 0x8216aed557574157, + 0xa8412abd15155415, 0x9fb6eee87777c177, 0xa5eb6e923737dc37, 0x7b56d79ee5e5b3e5, + 0x8cd923139f9f469f, 0xd317fd23f0f0e7f0, 0x6a7f94204a4a354a, 0x9e95a944dada4fda, + 0xfa25b0a258587d58, 0x06ca8fcfc9c903c9, 0x558d527c2929a429, 0x5022145a0a0a280a, + 0xe14f7f50b1b1feb1, 0x691a5dc9a0a0baa0, 0x7fdad6146b6bb16b, 0x5cab17d985852e85, + 0x8173673cbdbdcebd, 0xd234ba8f5d5d695d, 0x8050209010104010, 0xf303f507f4f4f7f4, + 0x16c08bddcbcb0bcb, 0xedc67cd33e3ef83e, 0x28110a2d05051405, 0x1fe6ce7867678167, + 0x7353d597e4e4b7e4, 0x25bb4e0227279c27, 0x3258827341411941, 0x2c9d0ba78b8b168b, + 0x510153f6a7a7a6a7, 0xcf94fab27d7de97d, 0xdcfb374995956e95, 0x8e9fad56d8d847d8, + 0x8b30eb70fbfbcbfb, 0x2371c1cdeeee9fee, 0xc791f8bb7c7ced7c, 0x17e3cc7166668566, + 0xa68ea77bdddd53dd, 0xb84b2eaf17175c17, 0x02468e4547470147, 0x84dc211a9e9e429e, + 0x1ec589d4caca0fca, 0x75995a582d2db42d, 0x9179632ebfbfc6bf, 0x381b0e3f07071c07, + 0x012347acadad8ead, 0xea2fb4b05a5a755a, 0x6cb51bef83833683, 0x85ff66b63333cc33, + 0x3ff2c65c63639163, 0x100a041202020802, 0x39384993aaaa92aa, 0xafa8e2de7171d971, + 0x0ecf8dc6c8c807c8, 0xc87d32d119196419, 0x7270923b49493949, 0x869aaf5fd9d943d9, + 0xc31df931f2f2eff2, 0x4b48dba8e3e3abe3, 0xe22ab6b95b5b715b, 0x34920dbc88881a88, + 0xa4c8293e9a9a529a, 0x2dbe4c0b26269826, 0x8dfa64bf3232c832, 0xe94a7d59b0b0fab0, + 0x1b6acff2e9e983e9, 0x78331e770f0f3c0f, 0xe6a6b733d5d573d5, 0x74ba1df480803a80, + 0x997c6127bebec2be, 0x26de87ebcdcd13cd, 0xbde468893434d034, 0x7a75903248483d48, + 0xab24e354ffffdbff, 0xf78ff48d7a7af57a, 0xf4ea3d6490907a90, 0xc23ebe9d5f5f615f, + 0x1da0403d20208020, 0x67d5d00f6868bd68, 0xd07234ca1a1a681a, 0x192c41b7aeae82ae, + 0xc95e757db4b4eab4, 0x9a19a8ce54544d54, 0xece53b7f93937693, 0x0daa442f22228822, + 0x07e9c86364648d64, 0xdb12ff2af1f1e3f1, 0xbfa2e6cc7373d173, 0x905a248212124812, + 0x3a5d807a40401d40, 0x4028104808082008, 0x56e89b95c3c32bc3, 0x337bc5dfecec97ec, + 0x9690ab4ddbdb4bdb, 0x611f5fc0a1a1bea1, 0x1c8307918d8d0e8d, 0xf5c97ac83d3df43d, + 0xccf1335b97976697, 0x0000000000000000, 0x36d483f9cfcf1bcf, 0x4587566e2b2bac2b, + 0x97b3ece17676c576, 0x64b019e682823282, 0xfea9b128d6d67fd6, 0xd87736c31b1b6c1b, + 0xc15b7774b5b5eeb5, 0x112943beafaf86af, 0x77dfd41d6a6ab56a, 0xba0da0ea50505d50, + 0x124c8a5745450945, 0xcb18fb38f3f3ebf3, 0x9df060ad3030c030, 0x2b74c3c4efef9bef, + 0xe5c37eda3f3ffc3f, 0x921caac755554955, 0x791059dba2a2b2a2, 0x0365c9e9eaea8fea, + 0x0fecca6a65658965, 0xb9686903babad2ba, 0x65935e4a2f2fbc2f, 0x4ee79d8ec0c027c0, + 0xbe81a160dede5fde, 0xe06c38fc1c1c701c, 0xbb2ee746fdfdd3fd, 0x52649a1f4d4d294d, + 0xe4e0397692927292, 0x8fbceafa7575c975, 0x301e0c3606061806, 0x249809ae8a8a128a, + 0xf940794bb2b2f2b2, 0x6359d185e6e6bfe6, 0x70361c7e0e0e380e, 0xf8633ee71f1f7c1f, + 0x37f7c45562629562, 0xeea3b53ad4d477d4, 0x29324d81a8a89aa8, 0xc4f4315296966296, + 0x9b3aef62f9f9c3f9, 0x66f697a3c5c533c5, 0x35b14a1025259425, 0xf220b2ab59597959, + 0x54ae15d084842a84, 0xb7a7e4c57272d572, 0xd5dd72ec3939e439, 0x5a6198164c4c2d4c, + 0xca3bbc945e5e655e, 0xe785f09f7878fd78, 0xddd870e53838e038, 0x148605988c8c0a8c, + 0xc6b2bf17d1d163d1, 0x410b57e4a5a5aea5, 0x434dd9a1e2e2afe2, 0x2ff8c24e61619961, + 0xf1457b42b3b3f6b3, 0x15a5423421218421, 0x94d625089c9c4a9c, 0xf0663cee1e1e781e, + 0x2252866143431143, 0x76fc93b1c7c73bc7, 0xb32be54ffcfcd7fc, 0x2014082404041004, + 0xb208a2e351515951, 0xbcc72f2599995e99, 0x4fc4da226d6da96d, 0x68391a650d0d340d, + 0x8335e979fafacffa, 0xb684a369dfdf5bdf, 0xd79bfca97e7ee57e, 0x3db4481924249024, + 0xc5d776fe3b3bec3b, 0x313d4b9aabab96ab, 0x3ed181f0cece1fce, 0x8855229911114411, + 0x0c8903838f8f068f, 0x4a6b9c044e4e254e, 0xd1517366b7b7e6b7, 0x0b60cbe0ebeb8beb, + 0xfdcc78c13c3cf03c, 0x7cbf1ffd81813e81, 0xd4fe354094946a94, 0xeb0cf31cf7f7fbf7, + 0xa1676f18b9b9deb9, 0x985f268b13134c13, 0x7d9c58512c2cb02c, 0xd6b8bb05d3d36bd3, + 0x6b5cd38ce7e7bbe7, 0x57cbdc396e6ea56e, 0x6ef395aac4c437c4, 0x180f061b03030c03, + 0x8a13acdc56564556, 0x1a49885e44440d44, 0xdf9efea07f7fe17f, 0x21374f88a9a99ea9, + 0x4d8254672a2aa82a, 0xb16d6b0abbbbd6bb, 0x46e29f87c1c123c1, 0xa202a6f153535153, + 0xae8ba572dcdc57dc, 0x582716530b0b2c0b, 0x9cd327019d9d4e9d, 0x47c1d82b6c6cad6c, + 0x95f562a43131c431, 0x87b9e8f37474cd74, 0xe309f115f6f6fff6, 0x0a438c4c46460546, + 0x092645a5acac8aac, 0x3c970fb589891e89, 0xa04428b414145014, 0x5b42dfbae1e1a3e1, + 0xb04e2ca616165816, 0xcdd274f73a3ae83a, 0x6fd0d2066969b969, 0x482d124109092409, + 0xa7ade0d77070dd70, 0xd954716fb6b6e2b6, 0xceb7bd1ed0d067d0, 0x3b7ec7d6eded93ed, + 0x2edb85e2cccc17cc, 0x2a57846842421542, 0xb4c22d2c98985a98, 0x490e55eda4a4aaa4, + 0x5d8850752828a028, 0xda31b8865c5c6d5c, 0x933fed6bf8f8c7f8, 0x44a411c286862286, +} + +var _C5 = [256]uint64{ + 0x18c07830d8181860, 0x2305af462623238c, 0xc67ef991b8c6c63f, 0xe8136fcdfbe8e887, + 0x874ca113cb878726, 0xb8a9626d11b8b8da, 0x0108050209010104, 0x4f426e9e0d4f4f21, + 0x36adee6c9b3636d8, 0xa6590451ffa6a6a2, 0xd2debdb90cd2d26f, 0xf5fb06f70ef5f5f3, + 0x79ef80f2967979f9, 0x6f5fcede306f6fa1, 0x91fcef3f6d91917e, 0x52aa07a4f8525255, + 0x6027fdc04760609d, 0xbc89766535bcbcca, 0x9baccd2b379b9b56, 0x8e048c018a8e8e02, + 0xa371155bd2a3a3b6, 0x0c603c186c0c0c30, 0x7bff8af6847b7bf1, 0x35b5e16a803535d4, + 0x1de8693af51d1d74, 0xe05347ddb3e0e0a7, 0xd7f6acb321d7d77b, 0xc25eed999cc2c22f, + 0x2e6d965c432e2eb8, 0x4b627a96294b4b31, 0xfea321e15dfefedf, 0x578216aed5575741, + 0x15a8412abd151554, 0x779fb6eee87777c1, 0x37a5eb6e923737dc, 0xe57b56d79ee5e5b3, + 0x9f8cd923139f9f46, 0xf0d317fd23f0f0e7, 0x4a6a7f94204a4a35, 0xda9e95a944dada4f, + 0x58fa25b0a258587d, 0xc906ca8fcfc9c903, 0x29558d527c2929a4, 0x0a5022145a0a0a28, + 0xb1e14f7f50b1b1fe, 0xa0691a5dc9a0a0ba, 0x6b7fdad6146b6bb1, 0x855cab17d985852e, + 0xbd8173673cbdbdce, 0x5dd234ba8f5d5d69, 0x1080502090101040, 0xf4f303f507f4f4f7, + 0xcb16c08bddcbcb0b, 0x3eedc67cd33e3ef8, 0x0528110a2d050514, 0x671fe6ce78676781, + 0xe47353d597e4e4b7, 0x2725bb4e0227279c, 0x4132588273414119, 0x8b2c9d0ba78b8b16, + 0xa7510153f6a7a7a6, 0x7dcf94fab27d7de9, 0x95dcfb374995956e, 0xd88e9fad56d8d847, + 0xfb8b30eb70fbfbcb, 0xee2371c1cdeeee9f, 0x7cc791f8bb7c7ced, 0x6617e3cc71666685, + 0xdda68ea77bdddd53, 0x17b84b2eaf17175c, 0x4702468e45474701, 0x9e84dc211a9e9e42, + 0xca1ec589d4caca0f, 0x2d75995a582d2db4, 0xbf9179632ebfbfc6, 0x07381b0e3f07071c, + 0xad012347acadad8e, 0x5aea2fb4b05a5a75, 0x836cb51bef838336, 0x3385ff66b63333cc, + 0x633ff2c65c636391, 0x02100a0412020208, 0xaa39384993aaaa92, 0x71afa8e2de7171d9, + 0xc80ecf8dc6c8c807, 0x19c87d32d1191964, 0x497270923b494939, 0xd9869aaf5fd9d943, + 0xf2c31df931f2f2ef, 0xe34b48dba8e3e3ab, 0x5be22ab6b95b5b71, 0x8834920dbc88881a, + 0x9aa4c8293e9a9a52, 0x262dbe4c0b262698, 0x328dfa64bf3232c8, 0xb0e94a7d59b0b0fa, + 0xe91b6acff2e9e983, 0x0f78331e770f0f3c, 0xd5e6a6b733d5d573, 0x8074ba1df480803a, + 0xbe997c6127bebec2, 0xcd26de87ebcdcd13, 0x34bde468893434d0, 0x487a75903248483d, + 0xffab24e354ffffdb, 0x7af78ff48d7a7af5, 0x90f4ea3d6490907a, 0x5fc23ebe9d5f5f61, + 0x201da0403d202080, 0x6867d5d00f6868bd, 0x1ad07234ca1a1a68, 0xae192c41b7aeae82, + 0xb4c95e757db4b4ea, 0x549a19a8ce54544d, 0x93ece53b7f939376, 0x220daa442f222288, + 0x6407e9c86364648d, 0xf1db12ff2af1f1e3, 0x73bfa2e6cc7373d1, 0x12905a2482121248, + 0x403a5d807a40401d, 0x0840281048080820, 0xc356e89b95c3c32b, 0xec337bc5dfecec97, + 0xdb9690ab4ddbdb4b, 0xa1611f5fc0a1a1be, 0x8d1c8307918d8d0e, 0x3df5c97ac83d3df4, + 0x97ccf1335b979766, 0x0000000000000000, 0xcf36d483f9cfcf1b, 0x2b4587566e2b2bac, + 0x7697b3ece17676c5, 0x8264b019e6828232, 0xd6fea9b128d6d67f, 0x1bd87736c31b1b6c, + 0xb5c15b7774b5b5ee, 0xaf112943beafaf86, 0x6a77dfd41d6a6ab5, 0x50ba0da0ea50505d, + 0x45124c8a57454509, 0xf3cb18fb38f3f3eb, 0x309df060ad3030c0, 0xef2b74c3c4efef9b, + 0x3fe5c37eda3f3ffc, 0x55921caac7555549, 0xa2791059dba2a2b2, 0xea0365c9e9eaea8f, + 0x650fecca6a656589, 0xbab9686903babad2, 0x2f65935e4a2f2fbc, 0xc04ee79d8ec0c027, + 0xdebe81a160dede5f, 0x1ce06c38fc1c1c70, 0xfdbb2ee746fdfdd3, 0x4d52649a1f4d4d29, + 0x92e4e03976929272, 0x758fbceafa7575c9, 0x06301e0c36060618, 0x8a249809ae8a8a12, + 0xb2f940794bb2b2f2, 0xe66359d185e6e6bf, 0x0e70361c7e0e0e38, 0x1ff8633ee71f1f7c, + 0x6237f7c455626295, 0xd4eea3b53ad4d477, 0xa829324d81a8a89a, 0x96c4f43152969662, + 0xf99b3aef62f9f9c3, 0xc566f697a3c5c533, 0x2535b14a10252594, 0x59f220b2ab595979, + 0x8454ae15d084842a, 0x72b7a7e4c57272d5, 0x39d5dd72ec3939e4, 0x4c5a6198164c4c2d, + 0x5eca3bbc945e5e65, 0x78e785f09f7878fd, 0x38ddd870e53838e0, 0x8c148605988c8c0a, + 0xd1c6b2bf17d1d163, 0xa5410b57e4a5a5ae, 0xe2434dd9a1e2e2af, 0x612ff8c24e616199, + 0xb3f1457b42b3b3f6, 0x2115a54234212184, 0x9c94d625089c9c4a, 0x1ef0663cee1e1e78, + 0x4322528661434311, 0xc776fc93b1c7c73b, 0xfcb32be54ffcfcd7, 0x0420140824040410, + 0x51b208a2e3515159, 0x99bcc72f2599995e, 0x6d4fc4da226d6da9, 0x0d68391a650d0d34, + 0xfa8335e979fafacf, 0xdfb684a369dfdf5b, 0x7ed79bfca97e7ee5, 0x243db44819242490, + 0x3bc5d776fe3b3bec, 0xab313d4b9aabab96, 0xce3ed181f0cece1f, 0x1188552299111144, + 0x8f0c8903838f8f06, 0x4e4a6b9c044e4e25, 0xb7d1517366b7b7e6, 0xeb0b60cbe0ebeb8b, + 0x3cfdcc78c13c3cf0, 0x817cbf1ffd81813e, 0x94d4fe354094946a, 0xf7eb0cf31cf7f7fb, + 0xb9a1676f18b9b9de, 0x13985f268b13134c, 0x2c7d9c58512c2cb0, 0xd3d6b8bb05d3d36b, + 0xe76b5cd38ce7e7bb, 0x6e57cbdc396e6ea5, 0xc46ef395aac4c437, 0x03180f061b03030c, + 0x568a13acdc565645, 0x441a49885e44440d, 0x7fdf9efea07f7fe1, 0xa921374f88a9a99e, + 0x2a4d8254672a2aa8, 0xbbb16d6b0abbbbd6, 0xc146e29f87c1c123, 0x53a202a6f1535351, + 0xdcae8ba572dcdc57, 0x0b582716530b0b2c, 0x9d9cd327019d9d4e, 0x6c47c1d82b6c6cad, + 0x3195f562a43131c4, 0x7487b9e8f37474cd, 0xf6e309f115f6f6ff, 0x460a438c4c464605, + 0xac092645a5acac8a, 0x893c970fb589891e, 0x14a04428b4141450, 0xe15b42dfbae1e1a3, + 0x16b04e2ca6161658, 0x3acdd274f73a3ae8, 0x696fd0d2066969b9, 0x09482d1241090924, + 0x70a7ade0d77070dd, 0xb6d954716fb6b6e2, 0xd0ceb7bd1ed0d067, 0xed3b7ec7d6eded93, + 0xcc2edb85e2cccc17, 0x422a578468424215, 0x98b4c22d2c98985a, 0xa4490e55eda4a4aa, + 0x285d8850752828a0, 0x5cda31b8865c5c6d, 0xf8933fed6bf8f8c7, 0x8644a411c2868622, +} + +var _C6 = [256]uint64{ + 0x6018c07830d81818, 0x8c2305af46262323, 0x3fc67ef991b8c6c6, 0x87e8136fcdfbe8e8, + 0x26874ca113cb8787, 0xdab8a9626d11b8b8, 0x0401080502090101, 0x214f426e9e0d4f4f, + 0xd836adee6c9b3636, 0xa2a6590451ffa6a6, 0x6fd2debdb90cd2d2, 0xf3f5fb06f70ef5f5, + 0xf979ef80f2967979, 0xa16f5fcede306f6f, 0x7e91fcef3f6d9191, 0x5552aa07a4f85252, + 0x9d6027fdc0476060, 0xcabc89766535bcbc, 0x569baccd2b379b9b, 0x028e048c018a8e8e, + 0xb6a371155bd2a3a3, 0x300c603c186c0c0c, 0xf17bff8af6847b7b, 0xd435b5e16a803535, + 0x741de8693af51d1d, 0xa7e05347ddb3e0e0, 0x7bd7f6acb321d7d7, 0x2fc25eed999cc2c2, + 0xb82e6d965c432e2e, 0x314b627a96294b4b, 0xdffea321e15dfefe, 0x41578216aed55757, + 0x5415a8412abd1515, 0xc1779fb6eee87777, 0xdc37a5eb6e923737, 0xb3e57b56d79ee5e5, + 0x469f8cd923139f9f, 0xe7f0d317fd23f0f0, 0x354a6a7f94204a4a, 0x4fda9e95a944dada, + 0x7d58fa25b0a25858, 0x03c906ca8fcfc9c9, 0xa429558d527c2929, 0x280a5022145a0a0a, + 0xfeb1e14f7f50b1b1, 0xbaa0691a5dc9a0a0, 0xb16b7fdad6146b6b, 0x2e855cab17d98585, + 0xcebd8173673cbdbd, 0x695dd234ba8f5d5d, 0x4010805020901010, 0xf7f4f303f507f4f4, + 0x0bcb16c08bddcbcb, 0xf83eedc67cd33e3e, 0x140528110a2d0505, 0x81671fe6ce786767, + 0xb7e47353d597e4e4, 0x9c2725bb4e022727, 0x1941325882734141, 0x168b2c9d0ba78b8b, + 0xa6a7510153f6a7a7, 0xe97dcf94fab27d7d, 0x6e95dcfb37499595, 0x47d88e9fad56d8d8, + 0xcbfb8b30eb70fbfb, 0x9fee2371c1cdeeee, 0xed7cc791f8bb7c7c, 0x856617e3cc716666, + 0x53dda68ea77bdddd, 0x5c17b84b2eaf1717, 0x014702468e454747, 0x429e84dc211a9e9e, + 0x0fca1ec589d4caca, 0xb42d75995a582d2d, 0xc6bf9179632ebfbf, 0x1c07381b0e3f0707, + 0x8ead012347acadad, 0x755aea2fb4b05a5a, 0x36836cb51bef8383, 0xcc3385ff66b63333, + 0x91633ff2c65c6363, 0x0802100a04120202, 0x92aa39384993aaaa, 0xd971afa8e2de7171, + 0x07c80ecf8dc6c8c8, 0x6419c87d32d11919, 0x39497270923b4949, 0x43d9869aaf5fd9d9, + 0xeff2c31df931f2f2, 0xabe34b48dba8e3e3, 0x715be22ab6b95b5b, 0x1a8834920dbc8888, + 0x529aa4c8293e9a9a, 0x98262dbe4c0b2626, 0xc8328dfa64bf3232, 0xfab0e94a7d59b0b0, + 0x83e91b6acff2e9e9, 0x3c0f78331e770f0f, 0x73d5e6a6b733d5d5, 0x3a8074ba1df48080, + 0xc2be997c6127bebe, 0x13cd26de87ebcdcd, 0xd034bde468893434, 0x3d487a7590324848, + 0xdbffab24e354ffff, 0xf57af78ff48d7a7a, 0x7a90f4ea3d649090, 0x615fc23ebe9d5f5f, + 0x80201da0403d2020, 0xbd6867d5d00f6868, 0x681ad07234ca1a1a, 0x82ae192c41b7aeae, + 0xeab4c95e757db4b4, 0x4d549a19a8ce5454, 0x7693ece53b7f9393, 0x88220daa442f2222, + 0x8d6407e9c8636464, 0xe3f1db12ff2af1f1, 0xd173bfa2e6cc7373, 0x4812905a24821212, + 0x1d403a5d807a4040, 0x2008402810480808, 0x2bc356e89b95c3c3, 0x97ec337bc5dfecec, + 0x4bdb9690ab4ddbdb, 0xbea1611f5fc0a1a1, 0x0e8d1c8307918d8d, 0xf43df5c97ac83d3d, + 0x6697ccf1335b9797, 0x0000000000000000, 0x1bcf36d483f9cfcf, 0xac2b4587566e2b2b, + 0xc57697b3ece17676, 0x328264b019e68282, 0x7fd6fea9b128d6d6, 0x6c1bd87736c31b1b, + 0xeeb5c15b7774b5b5, 0x86af112943beafaf, 0xb56a77dfd41d6a6a, 0x5d50ba0da0ea5050, + 0x0945124c8a574545, 0xebf3cb18fb38f3f3, 0xc0309df060ad3030, 0x9bef2b74c3c4efef, + 0xfc3fe5c37eda3f3f, 0x4955921caac75555, 0xb2a2791059dba2a2, 0x8fea0365c9e9eaea, + 0x89650fecca6a6565, 0xd2bab9686903baba, 0xbc2f65935e4a2f2f, 0x27c04ee79d8ec0c0, + 0x5fdebe81a160dede, 0x701ce06c38fc1c1c, 0xd3fdbb2ee746fdfd, 0x294d52649a1f4d4d, + 0x7292e4e039769292, 0xc9758fbceafa7575, 0x1806301e0c360606, 0x128a249809ae8a8a, + 0xf2b2f940794bb2b2, 0xbfe66359d185e6e6, 0x380e70361c7e0e0e, 0x7c1ff8633ee71f1f, + 0x956237f7c4556262, 0x77d4eea3b53ad4d4, 0x9aa829324d81a8a8, 0x6296c4f431529696, + 0xc3f99b3aef62f9f9, 0x33c566f697a3c5c5, 0x942535b14a102525, 0x7959f220b2ab5959, + 0x2a8454ae15d08484, 0xd572b7a7e4c57272, 0xe439d5dd72ec3939, 0x2d4c5a6198164c4c, + 0x655eca3bbc945e5e, 0xfd78e785f09f7878, 0xe038ddd870e53838, 0x0a8c148605988c8c, + 0x63d1c6b2bf17d1d1, 0xaea5410b57e4a5a5, 0xafe2434dd9a1e2e2, 0x99612ff8c24e6161, + 0xf6b3f1457b42b3b3, 0x842115a542342121, 0x4a9c94d625089c9c, 0x781ef0663cee1e1e, + 0x1143225286614343, 0x3bc776fc93b1c7c7, 0xd7fcb32be54ffcfc, 0x1004201408240404, + 0x5951b208a2e35151, 0x5e99bcc72f259999, 0xa96d4fc4da226d6d, 0x340d68391a650d0d, + 0xcffa8335e979fafa, 0x5bdfb684a369dfdf, 0xe57ed79bfca97e7e, 0x90243db448192424, + 0xec3bc5d776fe3b3b, 0x96ab313d4b9aabab, 0x1fce3ed181f0cece, 0x4411885522991111, + 0x068f0c8903838f8f, 0x254e4a6b9c044e4e, 0xe6b7d1517366b7b7, 0x8beb0b60cbe0ebeb, + 0xf03cfdcc78c13c3c, 0x3e817cbf1ffd8181, 0x6a94d4fe35409494, 0xfbf7eb0cf31cf7f7, + 0xdeb9a1676f18b9b9, 0x4c13985f268b1313, 0xb02c7d9c58512c2c, 0x6bd3d6b8bb05d3d3, + 0xbbe76b5cd38ce7e7, 0xa56e57cbdc396e6e, 0x37c46ef395aac4c4, 0x0c03180f061b0303, + 0x45568a13acdc5656, 0x0d441a49885e4444, 0xe17fdf9efea07f7f, 0x9ea921374f88a9a9, + 0xa82a4d8254672a2a, 0xd6bbb16d6b0abbbb, 0x23c146e29f87c1c1, 0x5153a202a6f15353, + 0x57dcae8ba572dcdc, 0x2c0b582716530b0b, 0x4e9d9cd327019d9d, 0xad6c47c1d82b6c6c, + 0xc43195f562a43131, 0xcd7487b9e8f37474, 0xfff6e309f115f6f6, 0x05460a438c4c4646, + 0x8aac092645a5acac, 0x1e893c970fb58989, 0x5014a04428b41414, 0xa3e15b42dfbae1e1, + 0x5816b04e2ca61616, 0xe83acdd274f73a3a, 0xb9696fd0d2066969, 0x2409482d12410909, + 0xdd70a7ade0d77070, 0xe2b6d954716fb6b6, 0x67d0ceb7bd1ed0d0, 0x93ed3b7ec7d6eded, + 0x17cc2edb85e2cccc, 0x15422a5784684242, 0x5a98b4c22d2c9898, 0xaaa4490e55eda4a4, + 0xa0285d8850752828, 0x6d5cda31b8865c5c, 0xc7f8933fed6bf8f8, 0x228644a411c28686, +} + +var _C7 = [256]uint64{ + 0x186018c07830d818, 0x238c2305af462623, 0xc63fc67ef991b8c6, 0xe887e8136fcdfbe8, + 0x8726874ca113cb87, 0xb8dab8a9626d11b8, 0x0104010805020901, 0x4f214f426e9e0d4f, + 0x36d836adee6c9b36, 0xa6a2a6590451ffa6, 0xd26fd2debdb90cd2, 0xf5f3f5fb06f70ef5, + 0x79f979ef80f29679, 0x6fa16f5fcede306f, 0x917e91fcef3f6d91, 0x525552aa07a4f852, + 0x609d6027fdc04760, 0xbccabc89766535bc, 0x9b569baccd2b379b, 0x8e028e048c018a8e, + 0xa3b6a371155bd2a3, 0x0c300c603c186c0c, 0x7bf17bff8af6847b, 0x35d435b5e16a8035, + 0x1d741de8693af51d, 0xe0a7e05347ddb3e0, 0xd77bd7f6acb321d7, 0xc22fc25eed999cc2, + 0x2eb82e6d965c432e, 0x4b314b627a96294b, 0xfedffea321e15dfe, 0x5741578216aed557, + 0x155415a8412abd15, 0x77c1779fb6eee877, 0x37dc37a5eb6e9237, 0xe5b3e57b56d79ee5, + 0x9f469f8cd923139f, 0xf0e7f0d317fd23f0, 0x4a354a6a7f94204a, 0xda4fda9e95a944da, + 0x587d58fa25b0a258, 0xc903c906ca8fcfc9, 0x29a429558d527c29, 0x0a280a5022145a0a, + 0xb1feb1e14f7f50b1, 0xa0baa0691a5dc9a0, 0x6bb16b7fdad6146b, 0x852e855cab17d985, + 0xbdcebd8173673cbd, 0x5d695dd234ba8f5d, 0x1040108050209010, 0xf4f7f4f303f507f4, + 0xcb0bcb16c08bddcb, 0x3ef83eedc67cd33e, 0x05140528110a2d05, 0x6781671fe6ce7867, + 0xe4b7e47353d597e4, 0x279c2725bb4e0227, 0x4119413258827341, 0x8b168b2c9d0ba78b, + 0xa7a6a7510153f6a7, 0x7de97dcf94fab27d, 0x956e95dcfb374995, 0xd847d88e9fad56d8, + 0xfbcbfb8b30eb70fb, 0xee9fee2371c1cdee, 0x7ced7cc791f8bb7c, 0x66856617e3cc7166, + 0xdd53dda68ea77bdd, 0x175c17b84b2eaf17, 0x47014702468e4547, 0x9e429e84dc211a9e, + 0xca0fca1ec589d4ca, 0x2db42d75995a582d, 0xbfc6bf9179632ebf, 0x071c07381b0e3f07, + 0xad8ead012347acad, 0x5a755aea2fb4b05a, 0x8336836cb51bef83, 0x33cc3385ff66b633, + 0x6391633ff2c65c63, 0x020802100a041202, 0xaa92aa39384993aa, 0x71d971afa8e2de71, + 0xc807c80ecf8dc6c8, 0x196419c87d32d119, 0x4939497270923b49, 0xd943d9869aaf5fd9, + 0xf2eff2c31df931f2, 0xe3abe34b48dba8e3, 0x5b715be22ab6b95b, 0x881a8834920dbc88, + 0x9a529aa4c8293e9a, 0x2698262dbe4c0b26, 0x32c8328dfa64bf32, 0xb0fab0e94a7d59b0, + 0xe983e91b6acff2e9, 0x0f3c0f78331e770f, 0xd573d5e6a6b733d5, 0x803a8074ba1df480, + 0xbec2be997c6127be, 0xcd13cd26de87ebcd, 0x34d034bde4688934, 0x483d487a75903248, + 0xffdbffab24e354ff, 0x7af57af78ff48d7a, 0x907a90f4ea3d6490, 0x5f615fc23ebe9d5f, + 0x2080201da0403d20, 0x68bd6867d5d00f68, 0x1a681ad07234ca1a, 0xae82ae192c41b7ae, + 0xb4eab4c95e757db4, 0x544d549a19a8ce54, 0x937693ece53b7f93, 0x2288220daa442f22, + 0x648d6407e9c86364, 0xf1e3f1db12ff2af1, 0x73d173bfa2e6cc73, 0x124812905a248212, + 0x401d403a5d807a40, 0x0820084028104808, 0xc32bc356e89b95c3, 0xec97ec337bc5dfec, + 0xdb4bdb9690ab4ddb, 0xa1bea1611f5fc0a1, 0x8d0e8d1c8307918d, 0x3df43df5c97ac83d, + 0x976697ccf1335b97, 0x0000000000000000, 0xcf1bcf36d483f9cf, 0x2bac2b4587566e2b, + 0x76c57697b3ece176, 0x82328264b019e682, 0xd67fd6fea9b128d6, 0x1b6c1bd87736c31b, + 0xb5eeb5c15b7774b5, 0xaf86af112943beaf, 0x6ab56a77dfd41d6a, 0x505d50ba0da0ea50, + 0x450945124c8a5745, 0xf3ebf3cb18fb38f3, 0x30c0309df060ad30, 0xef9bef2b74c3c4ef, + 0x3ffc3fe5c37eda3f, 0x554955921caac755, 0xa2b2a2791059dba2, 0xea8fea0365c9e9ea, + 0x6589650fecca6a65, 0xbad2bab9686903ba, 0x2fbc2f65935e4a2f, 0xc027c04ee79d8ec0, + 0xde5fdebe81a160de, 0x1c701ce06c38fc1c, 0xfdd3fdbb2ee746fd, 0x4d294d52649a1f4d, + 0x927292e4e0397692, 0x75c9758fbceafa75, 0x061806301e0c3606, 0x8a128a249809ae8a, + 0xb2f2b2f940794bb2, 0xe6bfe66359d185e6, 0x0e380e70361c7e0e, 0x1f7c1ff8633ee71f, + 0x62956237f7c45562, 0xd477d4eea3b53ad4, 0xa89aa829324d81a8, 0x966296c4f4315296, + 0xf9c3f99b3aef62f9, 0xc533c566f697a3c5, 0x25942535b14a1025, 0x597959f220b2ab59, + 0x842a8454ae15d084, 0x72d572b7a7e4c572, 0x39e439d5dd72ec39, 0x4c2d4c5a6198164c, + 0x5e655eca3bbc945e, 0x78fd78e785f09f78, 0x38e038ddd870e538, 0x8c0a8c148605988c, + 0xd163d1c6b2bf17d1, 0xa5aea5410b57e4a5, 0xe2afe2434dd9a1e2, 0x6199612ff8c24e61, + 0xb3f6b3f1457b42b3, 0x21842115a5423421, 0x9c4a9c94d625089c, 0x1e781ef0663cee1e, + 0x4311432252866143, 0xc73bc776fc93b1c7, 0xfcd7fcb32be54ffc, 0x0410042014082404, + 0x515951b208a2e351, 0x995e99bcc72f2599, 0x6da96d4fc4da226d, 0x0d340d68391a650d, + 0xfacffa8335e979fa, 0xdf5bdfb684a369df, 0x7ee57ed79bfca97e, 0x2490243db4481924, + 0x3bec3bc5d776fe3b, 0xab96ab313d4b9aab, 0xce1fce3ed181f0ce, 0x1144118855229911, + 0x8f068f0c8903838f, 0x4e254e4a6b9c044e, 0xb7e6b7d1517366b7, 0xeb8beb0b60cbe0eb, + 0x3cf03cfdcc78c13c, 0x813e817cbf1ffd81, 0x946a94d4fe354094, 0xf7fbf7eb0cf31cf7, + 0xb9deb9a1676f18b9, 0x134c13985f268b13, 0x2cb02c7d9c58512c, 0xd36bd3d6b8bb05d3, + 0xe7bbe76b5cd38ce7, 0x6ea56e57cbdc396e, 0xc437c46ef395aac4, 0x030c03180f061b03, + 0x5645568a13acdc56, 0x440d441a49885e44, 0x7fe17fdf9efea07f, 0xa99ea921374f88a9, + 0x2aa82a4d8254672a, 0xbbd6bbb16d6b0abb, 0xc123c146e29f87c1, 0x535153a202a6f153, + 0xdc57dcae8ba572dc, 0x0b2c0b582716530b, 0x9d4e9d9cd327019d, 0x6cad6c47c1d82b6c, + 0x31c43195f562a431, 0x74cd7487b9e8f374, 0xf6fff6e309f115f6, 0x4605460a438c4c46, + 0xac8aac092645a5ac, 0x891e893c970fb589, 0x145014a04428b414, 0xe1a3e15b42dfbae1, + 0x165816b04e2ca616, 0x3ae83acdd274f73a, 0x69b9696fd0d20669, 0x092409482d124109, + 0x70dd70a7ade0d770, 0xb6e2b6d954716fb6, 0xd067d0ceb7bd1ed0, 0xed93ed3b7ec7d6ed, + 0xcc17cc2edb85e2cc, 0x4215422a57846842, 0x985a98b4c22d2c98, 0xa4aaa4490e55eda4, + 0x28a0285d88507528, 0x5c6d5cda31b8865c, 0xf8c7f8933fed6bf8, 0x86228644a411c286, +} + +var rc = [rounds + 1]uint64{ + 0x0000000000000000, + 0x1823c6e887b8014f, + 0x36a6d2f5796f9152, + 0x60bc9b8ea30c7b35, + 0x1de0d7c22e4bfe57, + 0x157737e59ff04ada, + 0x58c9290ab1a06b85, + 0xbd5d10f4cb3e0567, + 0xe427418ba77d95d8, + 0xfbee7c66dd17479e, + 0xca2dbf07ad5a8333, +} diff --git a/vendor/github.com/jzelinskie/whirlpool/whirlpool.go b/vendor/github.com/jzelinskie/whirlpool/whirlpool.go new file mode 100644 index 0000000..0c16bef --- /dev/null +++ b/vendor/github.com/jzelinskie/whirlpool/whirlpool.go @@ -0,0 +1,240 @@ +// Copyright 2012 Jimmy Zelinskie. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package whirlpool implements the ISO/IEC 10118-3:2004 whirlpool +// cryptographic hash. Whirlpool is defined in +// http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html +package whirlpool + +import ( + "encoding/binary" + "hash" +) + +// whirlpool represents the partial evaluation of a checksum. +type whirlpool struct { + bitLength [lengthBytes]byte // Number of hashed bits. + buffer [wblockBytes]byte // Buffer of data to be hashed. + bufferBits int // Current number of bits on the buffer. + bufferPos int // Current byte location on buffer. + hash [digestBytes / 8]uint64 // Hash state. +} + +// New returns a new hash.Hash computing the whirlpool checksum. +func New() hash.Hash { + return new(whirlpool) +} + +func (w *whirlpool) Reset() { + // Cleanup the buffer. + w.buffer = [wblockBytes]byte{} + w.bufferBits = 0 + w.bufferPos = 0 + + // Cleanup the digest. + w.hash = [digestBytes / 8]uint64{} + + // Clean up the number of hashed bits. + w.bitLength = [lengthBytes]byte{} +} + +func (w *whirlpool) Size() int { + return digestBytes +} + +func (w *whirlpool) BlockSize() int { + return wblockBytes +} + +func (w *whirlpool) transform() { + var ( + K [8]uint64 // Round key. + block [8]uint64 // μ(buffer). + state [8]uint64 // Cipher state. + L [8]uint64 + ) + + // Map the buffer to a block. + for i := 0; i < 8; i++ { + b := 8 * i + block[i] = binary.BigEndian.Uint64(w.buffer[b:]) + } + + // Compute & apply K^0 to the cipher state. + for i := 0; i < 8; i++ { + K[i] = w.hash[i] + state[i] = block[i] ^ K[i] + } + + // Iterate over all the rounds. + for r := 1; r <= rounds; r++ { + // Compute K^rounds from K^(rounds-1). + for i := 0; i < 8; i++ { + L[i] = _C0[byte(K[i%8]>>56)] ^ + _C1[byte(K[(i+7)%8]>>48)] ^ + _C2[byte(K[(i+6)%8]>>40)] ^ + _C3[byte(K[(i+5)%8]>>32)] ^ + _C4[byte(K[(i+4)%8]>>24)] ^ + _C5[byte(K[(i+3)%8]>>16)] ^ + _C6[byte(K[(i+2)%8]>>8)] ^ + _C7[byte(K[(i+1)%8])] + } + L[0] ^= rc[r] + + for i := 0; i < 8; i++ { + K[i] = L[i] + } + + // Apply r-th round transformation. + for i := 0; i < 8; i++ { + L[i] = _C0[byte(state[i%8]>>56)] ^ + _C1[byte(state[(i+7)%8]>>48)] ^ + _C2[byte(state[(i+6)%8]>>40)] ^ + _C3[byte(state[(i+5)%8]>>32)] ^ + _C4[byte(state[(i+4)%8]>>24)] ^ + _C5[byte(state[(i+3)%8]>>16)] ^ + _C6[byte(state[(i+2)%8]>>8)] ^ + _C7[byte(state[(i+1)%8])] ^ + K[i%8] + } + + for i := 0; i < 8; i++ { + state[i] = L[i] + } + } + + // Apply the Miyaguchi-Preneel compression function. + for i := 0; i < 8; i++ { + w.hash[i] ^= state[i] ^ block[i] + } +} + +func (w *whirlpool) Write(source []byte) (int, error) { + var ( + sourcePos int // Index of the leftmost source. + nn int = len(source) // Num of bytes to process. + sourceBits uint64 = uint64(nn * 8) // Num of bits to process. + sourceGap uint = uint((8 - (int(sourceBits & 7))) & 7) // Space on source[sourcePos]. + bufferRem uint = uint(w.bufferBits & 7) // Occupied bits on buffer[bufferPos]. + b uint32 // Current byte. + ) + + // Tally the length of the data added. + for i, carry, value := 31, uint32(0), uint64(sourceBits); i >= 0 && (carry != 0 || value != 0); i-- { + carry += uint32(w.bitLength[i]) + (uint32(value & 0xff)) + w.bitLength[i] = byte(carry) + carry >>= 8 + value >>= 8 + } + + // Process data in chunks of 8 bits. + for sourceBits > 8 { + // Take a byte form the source. + b = uint32(((source[sourcePos] << sourceGap) & 0xff) | + ((source[sourcePos+1] & 0xff) >> (8 - sourceGap))) + + // Process this byte. + w.buffer[w.bufferPos] |= uint8(b >> bufferRem) + w.bufferPos++ + w.bufferBits += int(8 - bufferRem) + + if w.bufferBits == digestBits { + // Process this block. + w.transform() + // Reset the buffer. + w.bufferBits = 0 + w.bufferPos = 0 + } + w.buffer[w.bufferPos] = byte(b << (8 - bufferRem)) + w.bufferBits += int(bufferRem) + + // Proceed to remaining data. + sourceBits -= 8 + sourcePos++ + } + + // 0 <= sourceBits <= 8; All data leftover is in source[sourcePos]. + if sourceBits > 0 { + b = uint32((source[sourcePos] << sourceGap) & 0xff) // The bits are left-justified. + + // Process the remaining bits. + w.buffer[w.bufferPos] |= byte(b) >> bufferRem + } else { + b = 0 + } + + if uint64(bufferRem)+sourceBits < 8 { + // The remaining data fits on the buffer[bufferPos]. + w.bufferBits += int(sourceBits) + } else { + // The buffer[bufferPos] is full. + w.bufferPos++ + w.bufferBits += 8 - int(bufferRem) // bufferBits = 8*bufferPos + sourceBits -= uint64(8 - bufferRem) + + // Now, 0 <= sourceBits <= 8; all data leftover is in source[sourcePos]. + if w.bufferBits == digestBits { + // Process this data block. + w.transform() + // Reset buffer. + w.bufferBits = 0 + w.bufferPos = 0 + } + w.buffer[w.bufferPos] = byte(b << (8 - bufferRem)) + w.bufferBits += int(sourceBits) + } + return nn, nil +} + +func (w *whirlpool) Sum(in []byte) []byte { + // Copy the whirlpool so that the caller can keep summing. + n := *w + + // Append a 1-bit. + n.buffer[n.bufferPos] |= 0x80 >> (uint(n.bufferBits) & 7) + n.bufferPos++ + + // The remaining bits should be 0. Pad with 0s to be complete. + if n.bufferPos > wblockBytes-lengthBytes { + if n.bufferPos < wblockBytes { + for i := 0; i < wblockBytes-n.bufferPos; i++ { + n.buffer[n.bufferPos+i] = 0 + } + } + // Process this data block. + n.transform() + // Reset the buffer. + n.bufferPos = 0 + } + + if n.bufferPos < wblockBytes-lengthBytes { + for i := 0; i < (wblockBytes-lengthBytes)-n.bufferPos; i++ { + n.buffer[n.bufferPos+i] = 0 + } + } + n.bufferPos = wblockBytes - lengthBytes + + // Append the bit length of the hashed data. + for i := 0; i < lengthBytes; i++ { + n.buffer[n.bufferPos+i] = n.bitLength[i] + } + + // Process this data block. + n.transform() + + // Return the final digest as []byte. + var digest [digestBytes]byte + for i := 0; i < digestBytes/8; i++ { + digest[i*8] = byte(n.hash[i] >> 56) + digest[i*8+1] = byte(n.hash[i] >> 48) + digest[i*8+2] = byte(n.hash[i] >> 40) + digest[i*8+3] = byte(n.hash[i] >> 32) + digest[i*8+4] = byte(n.hash[i] >> 24) + digest[i*8+5] = byte(n.hash[i] >> 16) + digest[i*8+6] = byte(n.hash[i] >> 8) + digest[i*8+7] = byte(n.hash[i]) + } + + return append(in, digest[:digestBytes]...) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 15d617d..ec811cd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -27,6 +27,9 @@ github.com/gosuri/uiprogress/util/strutil # github.com/inconshreveable/mousetrap v1.1.0 ## explicit; go 1.18 github.com/inconshreveable/mousetrap +# github.com/jzelinskie/whirlpool v0.0.0-20201016144138-0675e54bb004 +## explicit +github.com/jzelinskie/whirlpool # github.com/klauspost/cpuid/v2 v2.4.1 ## explicit; go 1.24.0 github.com/klauspost/cpuid/v2