.TH LIBHASHSUM_INIT_HASHER_FROM_STRING 3 libhashsum .SH NAME libhashsum_init_hasher_from_string - initialise state for hashing .SH SYNOPSIS .nf #include \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_hasher_from_string\fP(struct libhashsum_hasher *\fIhasher\fP, const char *\fIalgorithm\fP); .fi .PP Link with .I -lhashsum .br .I -lsha1 (unless support for SHA-0 and SHA-1 was excluded) .br .I -lsha2 (unless support for SHA-2 was excluded) .br .I -lkeccak (unless support for Keccak, SHA-3, SHAKE, and RawSHAKE was excluded) .br .I -lblake (unless support for BLAKE was excluded). .SH DESCRIPTION The .B libhashsum_init_hasher_from_string function initialises .I *hasher for hashing using a cryptographic hash function and parameters selected using the parameter .I algorithm (see .BR libhashsum_get_algorithm_from_string (3) for more information; for the list of valid parameters, see the output to .I hasher->algorithm_string for the dedicated initialiser function for the selected hash function), and stores hash function information and hashing functions in .IR *hasher . .PP .I hasher->algorithm will be set to the algorithm selected by .I algorithm (which will be .I a after running .IR "libhashsum_get_algorithm_from_string(&a, algorithm)" ). .PP .I hasher->algorithm_string will be set to a string representing the hash function selected using the parameter .IR algorithm . .PP .I hasher->input_block_size will be set to the block size, in bytes. .PP .I hasher->hash_size will be set to the hash size, in bytes. .PP .I hasher->hash_output will be set to .IR NULL . .PP .I hasher->supports_non_whole_bytes will be set to 1 if .I *hasher->finalise and .I *hasher->finalise_const functions support non-zero values in their .I extra_bits parameter, or to 0 otherwise. .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. .TP .B EINVAL .I extra_bits is not 0 but .I hasher->supports_non_whole_bytes was set to 0 by .BR libhashsum_init_hasher . .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 either be set to .I NULL or to a pointer to a function to to call, with .I hasher as the argument, deallocate dynamically allocated data, which may invalidate any pointer in .IR *hasher . .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 and .I algorithm must not be .IR NULL . .SH RETURN VALUE Upon successful completion, the .B libhashsum_init_hasher_from_string 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_hasher_from_string function fails if: .TP .B ENOSYS Support was excluded at compile time. .TP .B ENOSYS The selected algorithm requires a larger (newer) version .B union libhashsum_state (and thus a larger version of .BR "struct libhashsum_hasher" ) than the application is compiled with. .TP .B EINVAL The value of .I algorithm is unrecognised or unsupported. .TP .B EINVAL .I algorithm contains an invalid parameter or an invalid combination of parameters. .TP .B ENOMEM Insufficient memory available. .SH HISTORY libhashsum 1.0. .SH SEE ALSO .BR libhashsum (7), .BR libhashsum_init_hasher (3), .BR libhashsum_get_algorithm_from_string (3)