Commit c9b0da17 authored by Nils Goroll's avatar Nils Goroll

add ICRC32

parent 235534b9
Pipeline #409 skipped
......@@ -188,6 +188,8 @@ The ``hash`` enum in the following can have one of the following
values:
* ``CRC32`` (not for HMACs)
* ``ICRC32`` (not for HMACs): CRC32 variant with inverted initialization
and result
* ``MD5``
* ``RS`` (not for HMACs)
* ``SHA1``
......@@ -203,8 +205,8 @@ values:
CONTENTS
========
* digest(ENUM {CRC32,RS,MD5,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB, ENUM {TASK,TOP})
* BLOB hash(ENUM {CRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB)
* digest(ENUM {CRC32,ICRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB, ENUM {TASK,TOP})
* BLOB hash(ENUM {CRC32,ICRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB)
* hmac(ENUM {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB)
* BLOB hmacf(ENUM {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512}, BLOB, BLOB)
* STRING version()
......@@ -217,7 +219,7 @@ digest
::
new OBJ = digest(ENUM {CRC32,RS,MD5,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512} hash, BLOB init=0, ENUM {TASK,TOP} scope=TASK)
new OBJ = digest(ENUM {CRC32,ICRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512} hash, BLOB init=0, ENUM {TASK,TOP} scope=TASK)
Initialize a message digest context for the algorithm ``hash``, and
optionally update it with ``init``. If ``init`` is left out, then an
......@@ -404,7 +406,7 @@ hash
::
BLOB hash(ENUM {CRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512} hash, BLOB msg)
BLOB hash(ENUM {CRC32,ICRC32,MD5,RS,SHA1,SHA224,SHA256,SHA384,SHA512,SHA3_224,SHA3_256,SHA3_384,SHA3_512} hash, BLOB msg)
Returns the message digest for ``msg`` as specified by ``hash``.
......
VMODENUM(CRC32)
VMODENUM(ICRC32)
VMODENUM(MD5)
VMODENUM(RS)
VMODENUM(SHA1)
......
......@@ -191,31 +191,27 @@ client c1 {
rxresp
expect resp.status == 200
# from librhash
expect resp.http.empty == "00000000"
expect resp.http.emptyf == resp.http.empty
expect resp.http.a == "00000061"
expect resp.http.a == "3AB551CE"
expect resp.http.as == resp.http.a
expect resp.http.af == resp.http.a
expect resp.http.abc == "B1012AAC"
expect resp.http.abc == "CA6598D0"
expect resp.http.abcs == resp.http.abc
expect resp.http.abcf == resp.http.abc
expect resp.http.msgdigest == "B4ACD743"
expect resp.http.msgdigest == "F1AEE4B8"
expect resp.http.msgdigests == resp.http.msgdigest
expect resp.http.msgdigestf == resp.http.msgdigest
expect resp.http.alphalc == "C19D0661"
expect resp.http.alphalc == "E3CBEE8F"
expect resp.http.alphalcs == resp.http.alphalc
expect resp.http.alphalcf == resp.http.alphalc
expect resp.http.alphanum == "4389DF19"
expect resp.http.alphanum == "02A641B3"
expect resp.http.alphanums == resp.http.alphanum
expect resp.http.alphanumf == resp.http.alphanum
expect resp.http.digits == "9DA5ECA0"
expect resp.http.digits == "F28A5294"
expect resp.http.digitss == resp.http.digits
expect resp.http.digitsf == resp.http.digits
expect resp.http.pangram == "29A4500B"
expect resp.http.pangram == "B9C60808"
expect resp.http.pangrams == resp.http.pangram
expect resp.http.pangramf == resp.http.pangram
expect resp.http.allbytes == "D65ECA00"
expect resp.http.allbytesf == resp.http.allbytes
} -run
......@@ -119,6 +119,9 @@ static void
init(const enum algorithm hash, hash_ctx * const hctx)
{
switch(hash) {
case ICRC32:
hctx->uint32[0] = ~0U;
break;
case CRC32:
hctx->uint32[0] = 0;
break;
......@@ -166,6 +169,7 @@ update(const enum algorithm hash, hash_ctx *restrict const hctx,
const uint8_t *restrict const msg, const size_t len)
{
switch(hash) {
case ICRC32:
case CRC32:
hctx->uint32[0] = rhash_get_crc32(hctx->uint32[0], msg, len);
break;
......@@ -204,6 +208,9 @@ final(const enum algorithm hash, hash_ctx *restrict const hctx,
uint8_t *restrict result)
{
switch(hash) {
case ICRC32:
hctx->uint32[0] ^= ~0U;
/* FALLTHROUGH */
case CRC32:
case RS:
be32_copy(result, 0, &hctx->uint32[0], sizeof(uint32_t));
......
......@@ -69,6 +69,10 @@ static const struct hashspec {
sizeof(uint32_t),
sizeof(uint32_t),
},
[ICRC32] = {
sizeof(uint32_t),
sizeof(uint32_t),
},
[MD5] = {
md5_hash_size,
md5_block_size,
......
......@@ -173,6 +173,8 @@ The ``hash`` enum in the following can have one of the following
values:
* ``CRC32`` (not for HMACs)
* ``ICRC32`` (not for HMACs): CRC32 variant with inverted initialization
and result
* ``MD5``
* ``RS`` (not for HMACs)
* ``SHA1``
......@@ -185,8 +187,8 @@ values:
* ``SHA3_384``
* ``SHA3_512``
$Object digest(ENUM {CRC32, RS, MD5, SHA1, SHA224, SHA256, SHA384, SHA512,
SHA3_224, SHA3_256, SHA3_384, SHA3_512} hash,
$Object digest(ENUM {CRC32, ICRC32, MD5, RS, SHA1, SHA224, SHA256, SHA384,
SHA512, SHA3_224, SHA3_256, SHA3_384, SHA3_512} hash,
BLOB init=0, ENUM {TASK, TOP} scope=TASK)
Initialize a message digest context for the algorithm ``hash``, and
......@@ -353,8 +355,8 @@ Example::
# Baz-Hash-Base64: base64-encoded SHA3_256 hash of "baz"
# Baz-Hash-Hex: hex-encoded SHA3_256 hash of "bar"
$Function BLOB hash(ENUM {CRC32, MD5, RS, SHA1, SHA224, SHA256, SHA384, SHA512,
SHA3_224, SHA3_256, SHA3_384, SHA3_512} hash,
$Function BLOB hash(ENUM {CRC32, ICRC32, MD5, RS, SHA1, SHA224, SHA256, SHA384,
SHA512, SHA3_224, SHA3_256, SHA3_384, SHA3_512} hash,
BLOB msg)
Returns the message digest for ``msg`` as specified by ``hash``.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment