Skip to content

Commit

Permalink
Implement checksum verification (#4)
Browse files Browse the repository at this point in the history
This implements the -c / --check switch to verify checksums previously generated by ksum, similar in behaviour to other checksum programs such as sha256sum.

A test suite is also added to test the behaviour of ksum, including tests against various test vectors.

The --warn, --quiet, --strict switches are also implemented (only relevant when verifying checksums)
  • Loading branch information
damaki authored Aug 13, 2019
1 parent 3f16b0b commit ef3db9d
Show file tree
Hide file tree
Showing 60 changed files with 90,147 additions and 190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
obj
bin
__pycache__
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
language: c

dist: bionic

services:
- docker

Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ $ cat file1 | ksum --sha3-256 -
be5215abf72333a73b992dafdf4ab59884b948452e0015cfaddaa0b87a0e4515 -
```

### Checking checksums

The `-c` or `--check` switch can be used to read checksums from the `FILE`s
and check them.

For example, to generate a file called `checksums.txt` that contains the
checksums of `file1`, `file2`, and `file3`:

```
$ ksum --sha3-256 file1 file2 file3 > checksums.txt
```

Then, to verify the checksums use the `--check` switch (or its `-c` short
version):
```
$ ksum --sha3-256 --check checksums.txt
```

`ksum` exits with a status of 0 if all checksums are valid. Otherwise,
`ksum` prints diagnostic messages and exits with a non-zero status.
Here's an example error output:
```
$ ksum --sha3-256 --check checksums.txt
file2: FAILED
ksum: WARNING: checksums.txt: 1 computed checksum did NOT match
```

Note that `ksum` must be invoked with the same settings that was used to
generate the checksums. This is particularly important for algorithms
that are customizable, e.g. KMAC, ParallelHash, cSHAKE.

### Variable output length

Several of the algorithms supported by `ksum` can output a variable length
Expand Down Expand Up @@ -187,7 +218,6 @@ The table also includes the output of other checksum programs for reference
## TODO

Things not yet implemented:
* Check mode to verify files against pre-generated checksums.
* Testing against test vectors.
(although `libkeccak` itself is tested against test vectors)

Expand Down
7 changes: 7 additions & 0 deletions src/argument_parser.ads
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ is
type Argument_Handler is
access not null procedure (Short_Name, Long_Name, Arg : in String);

type Group_Type is
(Main_Switches,
Check_Switches,
Customization,
Algorithms);

type Switch_Descriptor is record
Short_Name : Unbounded_String;
Long_Name : Unbounded_String;
Description : Unbounded_String;
Group : Group_Type;
Has_Argument : Boolean;
Handler : Argument_Handler;
end record;
Expand Down
Loading

0 comments on commit ef3db9d

Please sign in to comment.