diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-30 17:20:30 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-30 17:20:30 +0200 |
commit | 87437d71b36518dac5086f8cc92480935e4cf60b (patch) | |
tree | 8cabd9b8871320216d371aa7c0e8774fd06d91f4 /libhashsum_init_sha2_hasher.3 | |
parent | m + add support for z parameter for keccak (diff) | |
download | libhashsum-87437d71b36518dac5086f8cc92480935e4cf60b.tar.gz libhashsum-87437d71b36518dac5086f8cc92480935e4cf60b.tar.bz2 libhashsum-87437d71b36518dac5086f8cc92480935e4cf60b.tar.xz |
m + add man pages
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_sha2_hasher.3 | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/libhashsum_init_sha2_hasher.3 b/libhashsum_init_sha2_hasher.3 new file mode 100644 index 0000000..618dafc --- /dev/null +++ b/libhashsum_init_sha2_hasher.3 @@ -0,0 +1,263 @@ +.TH LIBHASHSUM_INIT_SHA2_HASHER 3 libhashsum +.SH NAME +libhashsum_init_sha2_hasher - initialise state for SHA-2 hashing + +.SH SYNOPSIS +.nf +#include <libhashsum.h> + +\fBstruct libhashsum_hasher\fP { + enum libhashsum_algorithm \fIalgorithm\fP; + const char *\fIalgorithm_string\fP; + size_t \fIinput_block_size\fP; + size_t \fIhash_size\fP; + unsigned char *\fIhash_output\fP; + unsigned char \fIsupports_non_whole_bytes\fP; + 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 (*\fIdestroy\fP)(struct libhashsum_hasher *\fPthis\fP); + union libhashsum_state { /* definition omitted */ } \fIstate\fP; +}; + +int \fBlibhashsum_init_sha2_hasher\fP(struct libhashsum_hasher *\fIhasher\fP, unsigned \fIalgobits\fP, size_t \fIhashbits\fP); +.fi +.PP +Link with +.I -lhashsum +.IR "-lsha2" . + +.SH DESCRIPTION +The +.B libhashsum_init_sha2_hasher +function initialises +.I *hasher +for hashing using the cryptographic hash function SHA-2 +and stores hash function information and hashing functions +for SHA-2 in +.IR *hasher . +.PP +.I algobits +shall be either 32 (for 32-bit family; the SHA-256 family; +which contains SHA-224 and SHA-256) or 64 (for 64-bit family; +the SHA-512 family; which contains SHA-384, SHA-512, +SHA-512/224, and SHA-512/256). +.PP +.I hashbits +shall be the hash size in bits, which shall be either +224 (for SHA-224) or 256 (for SHA-256) if +.I algobits +is 32, or +224 (for SHA-512/224), 256 (for SHA-512/256), +384 (for SHA-384), or 512 (for SHA-512) if +.I algobits +is 64. +.PP +.I hasher->algorithm +will be set to +.IR LIBHASHSUM_SHA_224 , +.IR LIBHASHSUM_SHA_256 , +.IR LIBHASHSUM_SHA_384 , +.IR LIBHASHSUM_SHA_512 , +.IR LIBHASHSUM_SHA_512_224 , +or +.IR LIBHASHSUM_SHA_512_256 , +depending on the values of +.I algobits +and +.IR hashbits . +.PP +.I hasher->algorithm_string +will be set to +.RB \(dq SHA-224 \(dq, +.RB \(dq SHA-256 \(dq, +.RB \(dq SHA-384 \(dq, +.RB \(dq SHA-512 \(dq, +.RB \(dq SHA-512/224 \(dq, +or +.RB \(dq SHA-512/256 \(dq, +depending on the values of +.I algobits +and +.IR hashbits . +.PP +.I hasher->input_block_size +will be set to the block size, in bytes +.RI ( algobits*2 ). +.PP +.I hasher->hash_size +will be set to the hash size, in bytes +.RI ( hashbits/8 ). +.PP +.I hasher->hash_output +will be set to +.IR NULL . +.PP +.I hasher->supports_non_whole_bytes +will be set to 1 +to indicate that the +.I *hasher->finalise +and +.I *hasher->finalise_const +functions support non-zero values in their +.I extra_bits +parameter. +.PP +.I hasher->process +will be set to a pointer to the function to call +to feed, and process, data into the hash function. +Its parameter +.I this +shall be set to +.IR hasher . +Its parameter +.I data +parameter shall be set to the buffer of data to +process, and its parameter +.I bytes +shall set to the number of bytes to process from +.IR data . +.I *hasher->process +will return the number of bytes processed, which +will be a multiple of +.IR hasher->input_block_size +no greater than +.IR bytes . +.PP +.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 +.I this +shall be set to +.IR hasher . +Its parameter +.I data +shall be set to the beginning of any yet unprocessed +data, and its parameter +.I bytes +shall be set to the number of bytes to process from +.IR data . +Its parameter +.I extra_bits +shall be set to the number of bits to process from +the lower bits of the incomplete byte +.IR data[bytes] . +The +.I *hasher->finalise_const +function will return 0 upon successful completion, +and set +.I hasher->hash_output +to a pointer to a buffer in +.I hasher->state +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: +.RS +.TP +.B EINVAL +.I extra_bits +is 8 or greater. +.RE +.PP +.I hasher->finalise +will be set to the pointer to a function that +is an alternative to +.I *hasher->finalise_const +that can support zero-copy provided that the +buffer input as the argument +.I data +is sufficiently large. The +.I *hasher->finalise +function may rewrite +.I data +and shall is does not safe to use for multiple +hashers (if the same text is hashed using multiple +hashers, +.I *hasher->finalise_const +must be used). The +function's parameter +.I size +shall be set to the size of the buffer +.IR data . +.I *hasher->finalise +is otherwise identical to +.IR *hasher->finalise_const . +.PP +.I hasher->destroy +will be set to +.IR NULL . +.PP +.I hasher->state +will be initialised, it shall be treated as +internal to the library's implementation, and +may change between versions. +.PP +.I hasher +must not be +.IR NULL . + +.SH RETURN VALUE +Upon successful completion, the +.B libhashsum_init_sha2_hasher +function returns 0. Otherwise, +the function returns -1 and sets +.I errno +to indicate the error. If -1 +is returned, the state of +.I *hasher +is undefined. + +.SH ERRORS +The +.B libhashsum_init_sha2_hasher +function fails if: +.TP +.B ENOSYS +Support was excluded at compile time. +.TP +.B EINVAL +.I algobits +was neither 32 nor 64. +.TP +.B EINVAL +.I hashbits +was neither 224, 256, 384, nor 512. +.TP +.B EINVAL +.I algobits +was 32 but +.I hashbits +was 384 or 512. + +.SH HISTORY +libhashsum 1.0. + +.SH NOTES +.IR "libhashsum_init_sha2_hasher(hasher, 32, 224)" , +.IR "libhashsum_init_sha2_hasher(hasher, 32, 256)" , +.IR "libhashsum_init_sha2_hasher(hasher, 64, 384)" , +.IR "libhashsum_init_sha2_hasher(hasher, 64, 512)" , +.IR "libhashsum_init_sha2_hasher(hasher, 64, 224)" , +and +.I libhashsum_init_sha2_hasher(hasher, 64, 256) +are equivalent to +.IR libhashsum_init_sha_224_hasher(hasher) , +.IR libhashsum_init_sha_256_hasher(hasher) , +.IR libhashsum_init_sha_384_hasher(hasher) , +.IR libhashsum_init_sha_512_hasher(hasher) , +.IR libhashsum_init_sha_512_224_hasher(hasher) , +and +.I libhashsum_init_sha_512_256_hasher(hasher) +respectively. + +.SH SEE ALSO +.BR libhashsum (7), +.BR libhashsum_init_sha_224_hasher (3), +.BR libhashsum_init_sha_256_hasher (3), +.BR libhashsum_init_sha_384_hasher (3), +.BR libhashsum_init_sha_512_hasher (3), +.BR libhashsum_init_sha_512_224_hasher (3), +.BR libhashsum_init_sha_512_256_hasher (3) |