mozilla/rust — pull request #8501 by DaGenix (2013-08-14 00:58:57+00:00)
Title: Crypto: Improve checked add functions & add tests

Improve the functions that keep track of the size of the data on which a Digest is being computed and add some tests. The tests are a little redundant for the success cases - if they didn't work, the Digests that use them would fail. The failure tests are a bit more useful since its very difficult to test them through the Digests - processing 2^64+1 bits of data would take a long time!

The performance stays basically the same. Some numbers improve, but, that may be just noise:

before:
```
test sha1::bench::sha1_10 ... bench: 74 ns/iter (+/- 0) = 135 MB/s
test sha1::bench::sha1_1k ... bench: 6154 ns/iter (+/- 57) = 166 MB/s
test sha1::bench::sha1_64k ... bench: 392056 ns/iter (+/- 2536) = 167 MB/s
test sha2::bench::sha256_10 ... bench: 82 ns/iter (+/- 3) = 121 MB/s
test sha2::bench::sha256_1k ... bench: 6789 ns/iter (+/- 79) = 150 MB/s
test sha2::bench::sha256_64k ... bench: 431722 ns/iter (+/- 6228) = 151 MB/s
test sha2::bench::sha512_10 ... bench: 56 ns/iter (+/- 1) = 178 MB/s
test sha2::bench::sha512_1k ... bench: 4414 ns/iter (+/- 33) = 231 MB/s
test sha2::bench::sha512_64k ... bench: 280875 ns/iter (+/- 3053) = 233 MB/s
```
after:
```
test sha1::bench::sha1_10 ... bench: 72 ns/iter (+/- 1) = 138 MB/s
test sha1::bench::sha1_1k ... bench: 6126 ns/iter (+/- 62) = 167 MB/s
test sha1::bench::sha1_64k ... bench: 391137 ns/iter (+/- 4729) = 167 MB/s
test sha2::bench::sha256_10 ... bench: 79 ns/iter (+/- 1) = 126 MB/s
test sha2::bench::sha256_1k ... bench: 6737 ns/iter (+/- 96) = 151 MB/s
test sha2::bench::sha256_64k ... bench: 432411 ns/iter (+/- 3791) = 151 MB/s
test sha2::bench::sha512_10 ... bench: 56 ns/iter (+/- 0) = 178 MB/s
test sha2::bench::sha512_1k ... bench: 4337 ns/iter (+/- 26) = 236 MB/s
test sha2::bench::sha512_64k ... bench: 272142 ns/iter (+/- 1499) = 240 MB/s
```