diff options
Diffstat (limited to '')
61 files changed, 1740 insertions, 195 deletions
@@ -151,6 +151,10 @@ run_tests(const char *name, enum libhashsum_algorithm algorithm, size_t hash_siz fprintf(stderr, "libhashsum_init_hasher returned NULL pointer in .finalise\n"); return 2; } + if (hasher.stretch) { + fprintf(stderr, "libhashsum_init_hasher returned non-NULL pointer in .stretch\n"); + return 2; + } input_string_len = strlen(testcases[i].input); bits = testcases[i].extra_bits; if (bits) { diff --git a/libhashsum.h b/libhashsum.h index b10f2f4..22f7488 100644 --- a/libhashsum.h +++ b/libhashsum.h @@ -375,7 +375,7 @@ struct libhashsum_hasher { size_t (*process)(struct libhashsum_hasher *this, const void *data, size_t bytes); /** - * Update the hash state given it's final + * Update the hash state given its final * input data * * Regardless of the algorithm's standard, the function @@ -385,6 +385,9 @@ struct libhashsum_hasher { * bit and the most significant bit will be used as the * last bit * + * `this->hash_output` will be set to point to a buffer + * in `this->state` containing the hash + * * @param this The object containing this function pointer * @param data The new input data * @param bytes The number of bytes available in `data` for reading @@ -410,6 +413,13 @@ struct libhashsum_hasher { * bit and the most significant bit will be used as the * last bit * + * `this->hash_output` will be set to point to a buffer + * in `this->state` containing the hash. However if + * `this->hash_output` is already non-`NULL`, the function + * _may_ choose to immediately output to the buffer that + * `this->hash_output` pointers to (the application must + * make sure it is sufficiently large). + * * @param this The object containing this function pointer * @param data The new input data, the function may rewrite its content * @param bytes The number of bytes available in `data` for reading @@ -427,6 +437,42 @@ struct libhashsum_hasher { int (*finalise)(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extra_bits, size_t size); /** + * Extend the hash with an additional `this->hash_size` bytes + * + * This pointer will be set to `NULL` when the object initialised, + * but once `*.finalise` or `*.finalise_const` is called, it + * will be set a point to a function _if_ the algorithm supports + * extending the hash indefinitely (if there is a limit, this + * pointer will be set to `NULL` once the limit has been reached) + * + * If the hash function supports generating hashes before the + * entire file has been processed, this pointer be non-`NULL` + * immediately when the object is initialised, however the + * hash function does not support extending the hash, calling + * this function, `*.finalise`, or `*.finalise_const` will + * reset this pointer to `NULL`. (No currently supported hash + * function supports this behaviour.) + * + * `this->hash_output` will be set to point to a buffer + * in `this->state` containing the hash extent. Note that + * this overrides any hash previously generated for `this`. + * + * @param this The object containing this function pointer + * @param skip Non-zero if the function need not set + * `this->hash_output` and output the hash extent + * (note that the function may ignore this argument) + * @param buffer If non-`NULL`, the function _may_ choose output the + * hash extent to the provided buffer (the application + * must ensure it is sufficently large). If the function + * does output to the provided buffer, it will reset + * `this->hash_output` to `NULL`. + * + * @since 1.0 + */ + LIBHASHSUM_1_NONNULL_ + void (*stretch)(struct libhashsum_hasher *this, int skip, void *buffer); + + /** * Unless this pointer its `NULL`, it points to * function that shall be once the object (`this`) * is not needed anymore diff --git a/libhashsum_init_blake224_hasher.3 b/libhashsum_init_blake224_hasher.3 index 1dd1655..e25f92b 100644 --- a/libhashsum_init_blake224_hasher.3 +++ b/libhashsum_init_blake224_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blake224_hasher - initialise state for BLAKE224 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -108,7 +109,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -134,8 +135,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -167,6 +176,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blake224_hasher.c b/libhashsum_init_blake224_hasher.c index 642af8d..f4b0726 100644 --- a/libhashsum_init_blake224_hasher.c +++ b/libhashsum_init_blake224_hasher.c @@ -27,13 +27,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + if (!this->hash_output) + this->hash_output = this->state.blake224.buf; + memcpy(this->state.blake224.buf, m, bytes + (size_t)(extra_bits > 0U)); if (extra_bits) this->state.blake224.buf[bytes] = libhashsum_reverse_byte__(this->state.blake224.buf[bytes]); libblake_blake224_digest(&this->state.blake224.s, this->state.blake224.buf, bytes, - extra_bits, NULL, this->state.blake224.buf); + extra_bits, NULL, this->hash_output); memset(&this->state.blake224.s, 0, sizeof(this->state.blake224.s)); - this->hash_output = this->state.blake224.buf; return 0; } @@ -55,15 +57,17 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr bytes -= r; size -= r; + if (!this->hash_output) + this->hash_output = this->state.blake224.buf; + if (size < libblake_blake224_digest_get_required_input_size(bytes, extra_bits, NULL)) { memcpy(this->state.blake224.buf, m, bytes + (size_t)(extra_bits > 0U)); m = this->state.blake224.buf; } if (extra_bits) m[bytes] = libhashsum_reverse_byte__(m[bytes]); - libblake_blake224_digest(&this->state.blake224.s, m, bytes, extra_bits, NULL, this->state.blake224.buf); + libblake_blake224_digest(&this->state.blake224.s, m, bytes, extra_bits, NULL, this->hash_output); memset(&this->state.blake224.s, 0, sizeof(this->state.blake224.s)); - this->hash_output = this->state.blake224.buf; return 0; } @@ -104,6 +108,7 @@ libhashsum_init_blake224_hasher(struct libhashsum_hasher *this, const void *salt this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libblake_blake224_init2(&this->state.blake224.s, salt); return 0; diff --git a/libhashsum_init_blake256_hasher.3 b/libhashsum_init_blake256_hasher.3 index c427f51..9baf5e3 100644 --- a/libhashsum_init_blake256_hasher.3 +++ b/libhashsum_init_blake256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blake256_hasher - initialise state for BLAKE256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -108,7 +109,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -134,8 +135,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -167,6 +176,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blake256_hasher.c b/libhashsum_init_blake256_hasher.c index 39a8eb9..3d00290 100644 --- a/libhashsum_init_blake256_hasher.c +++ b/libhashsum_init_blake256_hasher.c @@ -27,13 +27,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + if (!this->hash_output) + this->hash_output = this->state.blake256.buf; + memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U)); if (extra_bits) this->state.blake256.buf[bytes] = libhashsum_reverse_byte__(this->state.blake256.buf[bytes]); libblake_blake256_digest(&this->state.blake256.s, this->state.blake256.buf, bytes, - extra_bits, NULL, this->state.blake256.buf); + extra_bits, NULL, this->hash_output); memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s)); - this->hash_output = this->state.blake256.buf; return 0; } @@ -55,15 +57,17 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr bytes -= r; size -= r; + if (!this->hash_output) + this->hash_output = this->state.blake256.buf; + if (size < libblake_blake256_digest_get_required_input_size(bytes, extra_bits, NULL)) { memcpy(this->state.blake256.buf, m, bytes + (size_t)(extra_bits > 0U)); m = this->state.blake256.buf; } if (extra_bits) m[bytes] = libhashsum_reverse_byte__(m[bytes]); - libblake_blake256_digest(&this->state.blake256.s, m, bytes, extra_bits, NULL, this->state.blake256.buf); + libblake_blake256_digest(&this->state.blake256.s, m, bytes, extra_bits, NULL, this->hash_output); memset(&this->state.blake256.s, 0, sizeof(this->state.blake256.s)); - this->hash_output = this->state.blake256.buf; return 0; } @@ -104,6 +108,7 @@ libhashsum_init_blake256_hasher(struct libhashsum_hasher *this, const void *salt this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libblake_blake256_init2(&this->state.blake256.s, salt); return 0; diff --git a/libhashsum_init_blake384_hasher.3 b/libhashsum_init_blake384_hasher.3 index 29b31b5..6882cba 100644 --- a/libhashsum_init_blake384_hasher.3 +++ b/libhashsum_init_blake384_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blake384_hasher - initialise state for BLAKE384 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -108,7 +109,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -134,8 +135,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -167,6 +176,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blake384_hasher.c b/libhashsum_init_blake384_hasher.c index 5346689..a64d5ee 100644 --- a/libhashsum_init_blake384_hasher.c +++ b/libhashsum_init_blake384_hasher.c @@ -27,13 +27,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + if (!this->hash_output) + this->hash_output = this->state.blake384.buf; + memcpy(this->state.blake384.buf, m, bytes + (size_t)(extra_bits > 0U)); if (extra_bits) this->state.blake384.buf[bytes] = libhashsum_reverse_byte__(this->state.blake384.buf[bytes]); libblake_blake384_digest(&this->state.blake384.s, this->state.blake384.buf, bytes, - extra_bits, NULL, this->state.blake384.buf); + extra_bits, NULL, this->hash_output); memset(&this->state.blake384.s, 0, sizeof(this->state.blake384.s)); - this->hash_output = this->state.blake384.buf; return 0; } @@ -55,15 +57,17 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr bytes -= r; size -= r; + if (!this->hash_output) + this->hash_output = this->state.blake384.buf; + if (size < libblake_blake384_digest_get_required_input_size(bytes, extra_bits, NULL)) { memcpy(this->state.blake384.buf, m, bytes + (size_t)(extra_bits > 0U)); m = this->state.blake384.buf; } if (extra_bits) m[bytes] = libhashsum_reverse_byte__(m[bytes]); - libblake_blake384_digest(&this->state.blake384.s, m, bytes, extra_bits, NULL, this->state.blake384.buf); + libblake_blake384_digest(&this->state.blake384.s, m, bytes, extra_bits, NULL, this->hash_output); memset(&this->state.blake384.s, 0, sizeof(this->state.blake384.s)); - this->hash_output = this->state.blake384.buf; return 0; } @@ -104,6 +108,7 @@ libhashsum_init_blake384_hasher(struct libhashsum_hasher *this, const void *salt this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libblake_blake384_init2(&this->state.blake384.s, salt); return 0; diff --git a/libhashsum_init_blake512_hasher.3 b/libhashsum_init_blake512_hasher.3 index a2d690d..efbebe0 100644 --- a/libhashsum_init_blake512_hasher.3 +++ b/libhashsum_init_blake512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blake512_hasher - initialise state for BLAKE512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -108,7 +109,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -134,8 +135,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -167,6 +176,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blake512_hasher.c b/libhashsum_init_blake512_hasher.c index a42b429..6407a7b 100644 --- a/libhashsum_init_blake512_hasher.c +++ b/libhashsum_init_blake512_hasher.c @@ -27,13 +27,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; + if (!this->hash_output) + this->hash_output = this->state.blake512.buf; + memcpy(this->state.blake512.buf, m, bytes + (size_t)(extra_bits > 0U)); if (extra_bits) this->state.blake512.buf[bytes] = libhashsum_reverse_byte__(this->state.blake512.buf[bytes]); libblake_blake512_digest(&this->state.blake512.s, this->state.blake512.buf, bytes, - extra_bits, NULL, this->state.blake512.buf); + extra_bits, NULL, this->hash_output); memset(&this->state.blake512.s, 0, sizeof(this->state.blake512.s)); - this->hash_output = this->state.blake512.buf; return 0; } @@ -55,15 +57,17 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr bytes -= r; size -= r; + if (!this->hash_output) + this->hash_output = this->state.blake512.buf; + if (size < libblake_blake512_digest_get_required_input_size(bytes, extra_bits, NULL)) { memcpy(this->state.blake512.buf, m, bytes + (size_t)(extra_bits > 0U)); m = this->state.blake512.buf; } if (extra_bits) m[bytes] = libhashsum_reverse_byte__(m[bytes]); - libblake_blake512_digest(&this->state.blake512.s, m, bytes, extra_bits, NULL, this->state.blake512.buf); + libblake_blake512_digest(&this->state.blake512.s, m, bytes, extra_bits, NULL, this->hash_output); memset(&this->state.blake512.s, 0, sizeof(this->state.blake512.s)); - this->hash_output = this->state.blake512.buf; return 0; } @@ -104,6 +108,7 @@ libhashsum_init_blake512_hasher(struct libhashsum_hasher *this, const void *salt this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libblake_blake512_init2(&this->state.blake512.s, salt); return 0; diff --git a/libhashsum_init_blake_hasher.3 b/libhashsum_init_blake_hasher.3 index f6f77bb..1535428 100644 --- a/libhashsum_init_blake_hasher.3 +++ b/libhashsum_init_blake_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blake_hasher - initialise state for BLAKE hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -140,7 +141,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -166,8 +167,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -199,6 +208,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blakeb_hasher.3 b/libhashsum_init_blakeb_hasher.3 index 3d1230e..2650f02 100644 --- a/libhashsum_init_blakeb_hasher.3 +++ b/libhashsum_init_blakeb_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blakeb_hasher - initialise state for BLAKEb hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -117,7 +118,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -143,8 +144,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -176,6 +185,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_blakes_hasher.3 b/libhashsum_init_blakes_hasher.3 index 23ce54f..bf16b9b 100644 --- a/libhashsum_init_blakes_hasher.3 +++ b/libhashsum_init_blakes_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_blakes_hasher - initialise state for BLAKEs hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -117,7 +118,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -143,8 +144,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -176,6 +185,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_hasher.3 b/libhashsum_init_hasher.3 index df8c382..0f3f978 100644 --- a/libhashsum_init_hasher.3 +++ b/libhashsum_init_hasher.3 @@ -18,6 +18,7 @@ libhashsum_init_hasher - initialise state for hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -284,7 +285,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -310,8 +311,22 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large), provided that the library +supports this behaviour for the selected hash +function, otherwise it will behave as if +.I hasher->hash_output +was set to +.IR NULL . +The function will failure if: .RS .TP .B EINVAL @@ -350,6 +365,63 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated, provided that the +hash function supports extending the hash. If the +hash extention support is limited, +.I *hasher->stretch +will reset +.I hasher->stretch +to +.I NULL +once the limit has been reached. If the hash +function supports generating hashes at any time, +.I hasher->stretch +will be set to point to a function at immediately. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will either be set to .I NULL diff --git a/libhashsum_init_hasher_from_string.3 b/libhashsum_init_hasher_from_string.3 index 00f7723..db88547 100644 --- a/libhashsum_init_hasher_from_string.3 +++ b/libhashsum_init_hasher_from_string.3 @@ -16,6 +16,7 @@ libhashsum_init_hasher_from_string - initialise state for hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -113,7 +114,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -139,8 +140,22 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large), provided that the library +supports this behaviour for the selected hash +function, otherwise it will behave as if +.I hasher->hash_output +was set to +.IR NULL . +The function will failure if: .RS .TP .B EINVAL @@ -179,6 +194,63 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated, provided that the +hash function supports extending the hash. If the +hash extention support is limited, +.I *hasher->stretch +will reset +.I hasher->stretch +to +.I NULL +once the limit has been reached. If the hash +function supports generating hashes at any time, +.I hasher->stretch +will be set to point to a function at immediately. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will either be set to .I NULL diff --git a/libhashsum_init_keccak_224_hasher.3 b/libhashsum_init_keccak_224_hasher.3 index 9852f68..74c5db5 100644 --- a/libhashsum_init_keccak_224_hasher.3 +++ b/libhashsum_init_keccak_224_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_keccak_224_hasher - initialise state for Keccak-224 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -91,7 +92,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -117,8 +118,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -150,6 +159,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_keccak_256_hasher.3 b/libhashsum_init_keccak_256_hasher.3 index 6492401..f73ea91 100644 --- a/libhashsum_init_keccak_256_hasher.3 +++ b/libhashsum_init_keccak_256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_keccak_256_hasher - initialise state for Keccak-256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -91,7 +92,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -117,8 +118,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -150,6 +159,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_keccak_384_hasher.3 b/libhashsum_init_keccak_384_hasher.3 index 1527ad0..7528e4f 100644 --- a/libhashsum_init_keccak_384_hasher.3 +++ b/libhashsum_init_keccak_384_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_keccak_384_hasher - initialise state for Keccak-384 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -91,7 +92,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -117,8 +118,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -150,6 +159,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_keccak_512_hasher.3 b/libhashsum_init_keccak_512_hasher.3 index d59f0ba..06846ed 100644 --- a/libhashsum_init_keccak_512_hasher.3 +++ b/libhashsum_init_keccak_512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_keccak_512_hasher - initialise state for Keccak-512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -91,7 +92,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -117,8 +118,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -150,6 +159,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c index 03dd466..ee146bc 100644 --- a/libhashsum_init_keccak__.c +++ b/libhashsum_init_keccak__.c @@ -4,6 +4,26 @@ LIBHASHSUM_1_NONNULL_ +static void +stretch(struct libhashsum_hasher *this, int skip, void *buffer) +{ + if (skip) { + libkeccak_fast_squeeze(&this->state.keccak.s, 1); + return; + } + + if (buffer) + this->hash_output = NULL; + else if (this->hash_size > sizeof(this->state.keccak.sum.buf)) + this->hash_output = this->state.keccak.sum.dyn; + else + this->hash_output = this->state.keccak.sum.buf; + + libkeccak_squeeze(&this->state.keccak.s, buffer ? buffer : this->hash_output); +} + + +LIBHASHSUM_1_NONNULL_ static size_t process(struct libhashsum_hasher *this, const void *data, size_t bytes) { @@ -29,15 +49,15 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; - if (this->hash_size > sizeof(this->state.keccak.sum.buf)) - this->hash_output = this->state.keccak.sum.dyn; - else - this->hash_output = this->state.keccak.sum.buf; + if (!this->hash_output) { + if (this->hash_size > sizeof(this->state.keccak.sum.buf)) + this->hash_output = this->state.keccak.sum.dyn; + else + this->hash_output = this->state.keccak.sum.buf; + } libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits, this->state.keccak.suffix, this->hash_output); libkeccak_state_wipe_message(&this->state.keccak.s); - libkeccak_state_fast_destroy(&this->state.keccak.s); - memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s)); - this->state.keccak.s.M = NULL; + this->stretch = &stretch; return 0; } @@ -68,10 +88,12 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr need += this->input_block_size; } - if (this->hash_size > sizeof(this->state.keccak.sum.buf)) - this->hash_output = this->state.keccak.sum.dyn; - else - this->hash_output = this->state.keccak.sum.buf; + if (!this->hash_output) { + if (this->hash_size > sizeof(this->state.keccak.sum.buf)) + this->hash_output = this->state.keccak.sum.dyn; + else + this->hash_output = this->state.keccak.sum.buf; + } if (size < need) libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits, this->state.keccak.suffix, this->state.keccak.squeezes > 1U ? NULL : this->hash_output); @@ -90,9 +112,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr libkeccak_squeeze(&this->state.keccak.s, this->hash_output); libkeccak_state_wipe_message(&this->state.keccak.s); - libkeccak_state_fast_destroy(&this->state.keccak.s); - memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s)); - this->state.keccak.s.M = NULL; + this->stretch = &stretch; return 0; } @@ -142,6 +162,7 @@ libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void * this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = &destroy; return 0; } diff --git a/libhashsum_init_keccak_hasher.3 b/libhashsum_init_keccak_hasher.3 index 3b2def5..1712da7 100644 --- a/libhashsum_init_keccak_hasher.3 +++ b/libhashsum_init_keccak_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_keccak_hasher - initialise state for Keccak hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -171,7 +172,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -197,8 +198,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -230,6 +239,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_md2_hasher.3 b/libhashsum_init_md2_hasher.3 index 5ec44b4..5d99295 100644 --- a/libhashsum_init_md2_hasher.3 +++ b/libhashsum_init_md2_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_md2_hasher - initialise state for MD2 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -149,6 +150,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_md2_hasher.c b/libhashsum_init_md2_hasher.c index cf0a495..b28a6ae 100644 --- a/libhashsum_init_md2_hasher.c +++ b/libhashsum_init_md2_hasher.c @@ -142,6 +142,7 @@ libhashsum_init_md2_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.md2, 0, sizeof(this->state.md2)); return 0; diff --git a/libhashsum_init_md4_hasher.3 b/libhashsum_init_md4_hasher.3 index fba261d..adbb8a3 100644 --- a/libhashsum_init_md4_hasher.3 +++ b/libhashsum_init_md4_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_md4_hasher - initialise state for MD4 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_md4_hasher.c b/libhashsum_init_md4_hasher.c index bc361d8..abcc115 100644 --- a/libhashsum_init_md4_hasher.c +++ b/libhashsum_init_md4_hasher.c @@ -122,15 +122,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(&this->state.md4.m, 0, sizeof(this->state.md4.m)); this->state.md4.count = 0; + if (!this->hash_output) + this->hash_output = this->state.md4.h.sum; + for (i = 0; i < 4U; i++) { hi = this->state.md4.h.h32[i]; - this->state.md4.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.md4.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.md4.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.md4.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.md4.h.sum; return 0; } @@ -185,6 +187,7 @@ libhashsum_init_md4_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.md4, 0, sizeof(this->state.md4)); this->state.md4.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_md5_hasher.3 b/libhashsum_init_md5_hasher.3 index be887fc..95abd7b 100644 --- a/libhashsum_init_md5_hasher.3 +++ b/libhashsum_init_md5_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_md5_hasher - initialise state for MD5 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_md5_hasher.c b/libhashsum_init_md5_hasher.c index 8147204..7eec6ed 100644 --- a/libhashsum_init_md5_hasher.c +++ b/libhashsum_init_md5_hasher.c @@ -138,15 +138,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(this->state.md5.w, 0, sizeof(this->state.md5.w)); this->state.md5.count = 0; + if (!this->hash_output) + this->hash_output = this->state.md5.h.sum; + for (i = 0; i < 4U; i++) { hi = this->state.md5.h.h32[i]; - this->state.md5.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.md5.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.md5.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.md5.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.md5.h.sum; return 0; } @@ -200,6 +202,7 @@ libhashsum_init_md5_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.md5, 0, sizeof(this->state.md5)); this->state.md5.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_rawshake128_hasher.3 b/libhashsum_init_rawshake128_hasher.3 index fdc0f1d..178a03b 100644 --- a/libhashsum_init_rawshake128_hasher.3 +++ b/libhashsum_init_rawshake128_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_rawshake128_hasher - initialise state for RawSHAKE128 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_rawshake256_hasher.3 b/libhashsum_init_rawshake256_hasher.3 index e0b1e69..f24b6e1 100644 --- a/libhashsum_init_rawshake256_hasher.3 +++ b/libhashsum_init_rawshake256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_rawshake256_hasher - initialise state for RawSHAKE256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_rawshake512_hasher.3 b/libhashsum_init_rawshake512_hasher.3 index 3ee9aa6..04da5c4 100644 --- a/libhashsum_init_rawshake512_hasher.3 +++ b/libhashsum_init_rawshake512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_rawshake512_hasher - initialise state for RawSHAKE512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_rawshake_hasher.3 b/libhashsum_init_rawshake_hasher.3 index cd2b9a0..6fa7416 100644 --- a/libhashsum_init_rawshake_hasher.3 +++ b/libhashsum_init_rawshake_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_rawshake_hasher - initialise state for RawSHAKE hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -120,7 +121,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -146,8 +147,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -179,6 +188,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_ripemd_128_hasher.3 b/libhashsum_init_ripemd_128_hasher.3 index 856fedf..4093084 100644 --- a/libhashsum_init_ripemd_128_hasher.3 +++ b/libhashsum_init_ripemd_128_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_ripemd_128_hasher - initialise state for RIPEMD-128 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_ripemd_128_hasher.c b/libhashsum_init_ripemd_128_hasher.c index d958adb..02ac338 100644 --- a/libhashsum_init_ripemd_128_hasher.c +++ b/libhashsum_init_ripemd_128_hasher.c @@ -158,15 +158,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(&this->state.ripemd_128.m, 0, sizeof(this->state.ripemd_128.m)); this->state.ripemd_128.count = 0; + if (!this->hash_output) + this->hash_output = this->state.ripemd_128.h.sum; + for (i = 0; i < 4U; i++) { hi = this->state.ripemd_128.h.h32[i]; - this->state.ripemd_128.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.ripemd_128.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.ripemd_128.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.ripemd_128.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.ripemd_128.h.sum; return 0; } @@ -221,6 +223,7 @@ libhashsum_init_ripemd_128_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.ripemd_128, 0, sizeof(this->state.ripemd_128)); this->state.ripemd_128.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_ripemd_160_hasher.3 b/libhashsum_init_ripemd_160_hasher.3 index 94de83d..9a80caa 100644 --- a/libhashsum_init_ripemd_160_hasher.3 +++ b/libhashsum_init_ripemd_160_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_ripemd_160_hasher - initialise state for RIPEMD-160 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_ripemd_160_hasher.c b/libhashsum_init_ripemd_160_hasher.c index edb1c5f..2e510fa 100644 --- a/libhashsum_init_ripemd_160_hasher.c +++ b/libhashsum_init_ripemd_160_hasher.c @@ -161,15 +161,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(this->state.ripemd_160.w2, 0, sizeof(this->state.ripemd_160.w2)); this->state.ripemd_160.count = 0; + if (!this->hash_output) + this->hash_output = this->state.ripemd_160.h.sum; + for (i = 0; i < 5U; i++) { hi = this->state.ripemd_160.h.h32[i]; - this->state.ripemd_160.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.ripemd_160.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.ripemd_160.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.ripemd_160.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.ripemd_160.h.sum; return 0; } @@ -224,6 +226,7 @@ libhashsum_init_ripemd_160_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.ripemd_160, 0, sizeof(this->state.ripemd_160)); this->state.ripemd_160.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_ripemd_256_hasher.3 b/libhashsum_init_ripemd_256_hasher.3 index 12638d8..1d83bce 100644 --- a/libhashsum_init_ripemd_256_hasher.3 +++ b/libhashsum_init_ripemd_256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_ripemd_256_hasher - initialise state for RIPEMD-256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_ripemd_256_hasher.c b/libhashsum_init_ripemd_256_hasher.c index ce3bf14..d9249b4 100644 --- a/libhashsum_init_ripemd_256_hasher.c +++ b/libhashsum_init_ripemd_256_hasher.c @@ -169,15 +169,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(&this->state.ripemd_256.m, 0, sizeof(this->state.ripemd_256.m)); this->state.ripemd_256.count = 0; + if (!this->hash_output) + this->hash_output = this->state.ripemd_256.h.sum; + for (i = 0; i < 8U; i++) { hi = this->state.ripemd_256.h.h32[i]; - this->state.ripemd_256.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.ripemd_256.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.ripemd_256.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.ripemd_256.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.ripemd_256.h.sum; return 0; } @@ -232,6 +234,7 @@ libhashsum_init_ripemd_256_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.ripemd_256, 0, sizeof(this->state.ripemd_256)); this->state.ripemd_256.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_ripemd_320_hasher.3 b/libhashsum_init_ripemd_320_hasher.3 index bcaf00a..41b2c2a 100644 --- a/libhashsum_init_ripemd_320_hasher.3 +++ b/libhashsum_init_ripemd_320_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_ripemd_320_hasher - initialise state for RIPEMD-320 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -88,7 +89,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -114,8 +115,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -147,6 +156,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_ripemd_320_hasher.c b/libhashsum_init_ripemd_320_hasher.c index d5af69a..80e4e23 100644 --- a/libhashsum_init_ripemd_320_hasher.c +++ b/libhashsum_init_ripemd_320_hasher.c @@ -175,15 +175,17 @@ finalise_common(struct libhashsum_hasher *this, uint8_t *m, size_t bytes, unsign memset(this->state.ripemd_320.w2, 0, sizeof(this->state.ripemd_320.w2)); this->state.ripemd_320.count = 0; + if (!this->hash_output) + this->hash_output = this->state.ripemd_320.h.sum; + for (i = 0; i < 10U; i++) { hi = this->state.ripemd_320.h.h32[i]; - this->state.ripemd_320.h.sum[i * 4U + 0U] = (uint8_t)(hi >> 0); - this->state.ripemd_320.h.sum[i * 4U + 1U] = (uint8_t)(hi >> 8); - this->state.ripemd_320.h.sum[i * 4U + 2U] = (uint8_t)(hi >> 16); - this->state.ripemd_320.h.sum[i * 4U + 3U] = (uint8_t)(hi >> 24); + this->hash_output[i * 4U + 0U] = (uint8_t)(hi >> 0); + this->hash_output[i * 4U + 1U] = (uint8_t)(hi >> 8); + this->hash_output[i * 4U + 2U] = (uint8_t)(hi >> 16); + this->hash_output[i * 4U + 3U] = (uint8_t)(hi >> 24); } - this->hash_output = this->state.ripemd_320.h.sum; return 0; } @@ -238,6 +240,7 @@ libhashsum_init_ripemd_320_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; memset(&this->state.ripemd_320, 0, sizeof(this->state.ripemd_320)); this->state.ripemd_320.h.h32[0] = UINT32_C(0x67452301); diff --git a/libhashsum_init_sha0_hasher.3 b/libhashsum_init_sha0_hasher.3 index 521f0cb..571c065 100644 --- a/libhashsum_init_sha0_hasher.3 +++ b/libhashsum_init_sha0_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha0_hasher - initialise state for SHA-0 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -89,7 +90,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -115,8 +116,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -148,6 +157,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha0_hasher.c b/libhashsum_init_sha0_hasher.c index 7f420d8..b7d42a8 100644 --- a/libhashsum_init_sha0_hasher.c +++ b/libhashsum_init_sha0_hasher.c @@ -38,9 +38,11 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; - libsha1_digest(&this->state.sha0.s, m, (bytes << 3) | (size_t)extra_bits, this->state.sha0.sum); + if (!this->hash_output) + this->hash_output = this->state.sha0.sum; + + libsha1_digest(&this->state.sha0.s, m, (bytes << 3) | (size_t)extra_bits, this->hash_output); memset(&this->state.sha0.s, 0, sizeof(this->state.sha0.s)); - this->hash_output = this->state.sha0.sum; return 0; } @@ -66,6 +68,7 @@ libhashsum_init_sha0_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libsha1_init(&this->state.sha0.s, LIBSHA1_0); return 0; diff --git a/libhashsum_init_sha1_hasher.3 b/libhashsum_init_sha1_hasher.3 index 4669f81..fb4d18d 100644 --- a/libhashsum_init_sha1_hasher.3 +++ b/libhashsum_init_sha1_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha1_hasher - initialise state for SHA-1 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -89,7 +90,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -115,8 +116,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -148,6 +157,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha1_hasher.c b/libhashsum_init_sha1_hasher.c index 91bcc15..13020e2 100644 --- a/libhashsum_init_sha1_hasher.c +++ b/libhashsum_init_sha1_hasher.c @@ -38,9 +38,11 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; - libsha1_digest(&this->state.sha1.s, m, (bytes << 3) | (size_t)extra_bits, this->state.sha1.sum); + if (!this->hash_output) + this->hash_output = this->state.sha1.sum; + + libsha1_digest(&this->state.sha1.s, m, (bytes << 3) | (size_t)extra_bits, this->hash_output); memset(&this->state.sha1.s, 0, sizeof(this->state.sha1.s)); - this->hash_output = this->state.sha1.sum; return 0; } @@ -66,6 +68,7 @@ libhashsum_init_sha1_hasher(struct libhashsum_hasher *this) this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libsha1_init(&this->state.sha1.s, LIBSHA1_1); return 0; diff --git a/libhashsum_init_sha2_hasher.3 b/libhashsum_init_sha2_hasher.3 index 618dafc..c1d7d91 100644 --- a/libhashsum_init_sha2_hasher.3 +++ b/libhashsum_init_sha2_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha2_hasher - initialise state for SHA-2 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -127,7 +128,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -153,8 +154,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -186,6 +195,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha2_hasher.c b/libhashsum_init_sha2_hasher.c index f06c59b..7e5aa38 100644 --- a/libhashsum_init_sha2_hasher.c +++ b/libhashsum_init_sha2_hasher.c @@ -38,9 +38,11 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u m = &m[r]; bytes -= r; - libsha2_digest(&this->state.sha2.s, data, (bytes << 3) | extra_bits, this->state.sha2.sum); + if (!this->hash_output) + this->hash_output = this->state.sha2.sum; + + libsha2_digest(&this->state.sha2.s, data, (bytes << 3) | extra_bits, this->hash_output); memset(&this->state.sha2.s, 0, sizeof(this->state.sha2.s)); - this->hash_output = this->state.sha2.sum; return 0; } @@ -95,6 +97,7 @@ libhashsum_init_sha2_hasher(struct libhashsum_hasher *this, unsigned algobits, s this->process = &process; this->finalise_const = &finalise_const; this->finalise = &finalise; + this->stretch = NULL; this->destroy = NULL; libsha2_init(&this->state.sha2.s, algo); return 0; diff --git a/libhashsum_init_sha3_224_hasher.3 b/libhashsum_init_sha3_224_hasher.3 index b6af8cd..ba5a6da 100644 --- a/libhashsum_init_sha3_224_hasher.3 +++ b/libhashsum_init_sha3_224_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha3_224_hasher - initialise state for SHA-3-224 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_sha3_256_hasher.3 b/libhashsum_init_sha3_256_hasher.3 index f26de4d..8e862d2 100644 --- a/libhashsum_init_sha3_256_hasher.3 +++ b/libhashsum_init_sha3_256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha3_256_hasher - initialise state for SHA-3-256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_sha3_384_hasher.3 b/libhashsum_init_sha3_384_hasher.3 index ba82490..8bdcdf2 100644 --- a/libhashsum_init_sha3_384_hasher.3 +++ b/libhashsum_init_sha3_384_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha3_384_hasher - initialise state for SHA-3-384 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_sha3_512_hasher.3 b/libhashsum_init_sha3_512_hasher.3 index 5155ae1..9106b64 100644 --- a/libhashsum_init_sha3_512_hasher.3 +++ b/libhashsum_init_sha3_512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha3_512_hasher - initialise state for SHA-3-512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_sha3_hasher.3 b/libhashsum_init_sha3_hasher.3 index 3aa3612..89ab925 100644 --- a/libhashsum_init_sha3_hasher.3 +++ b/libhashsum_init_sha3_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha3_hasher - initialise state for SHA-3 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -94,7 +95,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -120,8 +121,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -153,6 +162,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_sha_224_hasher.3 b/libhashsum_init_sha_224_hasher.3 index 6ce3e23..b5cffa0 100644 --- a/libhashsum_init_sha_224_hasher.3 +++ b/libhashsum_init_sha_224_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_224_hasher - initialise state for SHA-224 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha_256_hasher.3 b/libhashsum_init_sha_256_hasher.3 index 6d8ee51..edb1209 100644 --- a/libhashsum_init_sha_256_hasher.3 +++ b/libhashsum_init_sha_256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_256_hasher - initialise state for SHA-256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha_384_hasher.3 b/libhashsum_init_sha_384_hasher.3 index 6f31e8c..ad0ab38 100644 --- a/libhashsum_init_sha_384_hasher.3 +++ b/libhashsum_init_sha_384_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_384_hasher - initialise state for SHA-384 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha_512_224_hasher.3 b/libhashsum_init_sha_512_224_hasher.3 index c06d4b1..3810bc2 100644 --- a/libhashsum_init_sha_512_224_hasher.3 +++ b/libhashsum_init_sha_512_224_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_512_224_hasher - initialise state for SHA-512/224 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha_512_256_hasher.3 b/libhashsum_init_sha_512_256_hasher.3 index c162484..76912c7 100644 --- a/libhashsum_init_sha_512_256_hasher.3 +++ b/libhashsum_init_sha_512_256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_512_256_hasher - initialise state for SHA-512/256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_sha_512_hasher.3 b/libhashsum_init_sha_512_hasher.3 index 3c8541d..eba1cd9 100644 --- a/libhashsum_init_sha_512_hasher.3 +++ b/libhashsum_init_sha_512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_sha_512_hasher - initialise state for SHA-512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -90,7 +91,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -116,8 +117,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -149,6 +158,10 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL . +.PP .I hasher->destroy will be set to .IR NULL . diff --git a/libhashsum_init_shake128_hasher.3 b/libhashsum_init_shake128_hasher.3 index e69fabe..f852491 100644 --- a/libhashsum_init_shake128_hasher.3 +++ b/libhashsum_init_shake128_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_shake128_hasher - initialise state for SHAKE128 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_shake256_hasher.3 b/libhashsum_init_shake256_hasher.3 index d9f407e..972e68e 100644 --- a/libhashsum_init_shake256_hasher.3 +++ b/libhashsum_init_shake256_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_shake256_hasher - initialise state for SHAKE256 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_shake512_hasher.3 b/libhashsum_init_shake512_hasher.3 index ba3d5b6..074ec2c 100644 --- a/libhashsum_init_shake512_hasher.3 +++ b/libhashsum_init_shake512_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_shake512_hasher - initialise state for SHAKE512 hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -106,7 +107,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -132,8 +133,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -165,6 +174,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/libhashsum_init_shake_hasher.3 b/libhashsum_init_shake_hasher.3 index e04429f..e551211 100644 --- a/libhashsum_init_shake_hasher.3 +++ b/libhashsum_init_shake_hasher.3 @@ -16,6 +16,7 @@ libhashsum_init_shake_hasher - initialise state for SHAKE hashing size_t (*\fIprocess\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP); int (*\fIfinalise_const\fP)(struct libhashsum_hasher *\fPthis\fP, const void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP); int (*\fIfinalise\fP)(struct libhashsum_hasher *\fPthis\fP, void *\fPdata\fP, size_t \fPbytes\fP, unsigned \fPextra_bits\fP, size_t \fPsize\fP); + void (*\fIstretch\fP)(struct libhashsum_hasher *\fPthis\fP, int \fPskip\fP, void *\fPbuffer\fP); void (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); union libhashsum_state { /* definition omitted */ } \fIstate\fP; }; @@ -120,7 +121,7 @@ no greater than .I hasher->finalise_const will be set to a pointer to the function to call once the entire text being hashed has been loaded, -and to get the hash of the text. It's parameter +and to get the hash of the text. Its parameter .I this shall be set to .IR hasher . @@ -146,8 +147,16 @@ to a pointer to a buffer in containing the binary hash of the processed data. Otherwise, the function will return -1, and set .I errno -to indicate the error. The function will failure -if: +to indicate the error. However, if the user has +already set +.I hasher->hash_output +to a +.RI non- NULL +pointer, the function will output the binary hash +to that pointer instead without redirecting +.I hasher->hash_output +(the application must make sure this buffer is +sufficiently large). The function will failure if: .RS .TP .B EINVAL @@ -179,6 +188,52 @@ shall be set to the size of the buffer is otherwise identical to .IR *hasher->finalise_const . .PP +.I hasher->stretch +will be set to +.IR NULL , +however upon successful completion of +.I *hasher->finalise +or +.IR *hasher->finalise_const , +.I hasher->stretch +will be set to point to a function that can be +used to extend the hash by +.I hasher->hash_size +bytes, and can be called repeated without limitation. +The hash extent will be written to a buffer in +.I hasher->state +(which +.I *hasher->finalize +and +.I *hasher->finalize_const +also write the hash to), and +.I hasher->hash_output +will be set to point to this buffer. +.IR *hasher->stretch 's +parameter +.I this +shall be +.IR hasher . +Its parameter +.I skip +can be set to non-zero if the hash extent should +be discarded +.RI ( hasher->hash_output +will not be set in this case). +Its parameter +.I buffer +shall be +.I NULL +for the above described behaviour, or an sufficiently +large buffer the function shall output the hash extent +to. If +.I buffer +is +.RI non- NULL , +.I hasher->hash_output +will be set to +.IR NULL ). +.PP .I hasher->destroy will be set to a pointer to a function to to call, with diff --git a/misc-tests.c b/misc-tests.c index 0144916..4eca0a6 100644 --- a/misc-tests.c +++ b/misc-tests.c @@ -7,7 +7,7 @@ if ((ASSERTION))\ break;\ fprintf(stderr, "assertion `%s` at line %i failed\n", #ASSERTION, __LINE__);\ - exit(1);\ + exit(2);\ } while (0) @@ -23,6 +23,7 @@ eq(struct libhashsum_hasher *a, struct libhashsum_hasher *b) a->process != b->process || a->finalise_const != b->finalise_const || a->finalise != b->finalise || + a->stretch != b->stretch || a->destroy != b->destroy) return 0; if (a->hash_output && memcpy(a->hash_output, b->hash_output, a->hash_size)) |