plibsys 0.0.5
|
Cryptographic hash function. More...
Go to the source code of this file.
Typedefs | |
typedef struct PCryptoHash_ | PCryptoHash |
Opaque data structure for handling a cryptographic hash context. | |
typedef enum PCryptoHashType_ | PCryptoHashType |
Cryptographic hash function types for PCryptoHash. | |
Enumerations | |
enum | PCryptoHashType_ { P_CRYPTO_HASH_TYPE_MD5 = 0 , P_CRYPTO_HASH_TYPE_SHA1 = 1 , P_CRYPTO_HASH_TYPE_SHA2_224 = 2 , P_CRYPTO_HASH_TYPE_SHA2_256 = 3 , P_CRYPTO_HASH_TYPE_SHA2_384 = 4 , P_CRYPTO_HASH_TYPE_SHA2_512 = 5 , P_CRYPTO_HASH_TYPE_SHA3_224 = 6 , P_CRYPTO_HASH_TYPE_SHA3_256 = 7 , P_CRYPTO_HASH_TYPE_SHA3_384 = 8 , P_CRYPTO_HASH_TYPE_SHA3_512 = 9 , P_CRYPTO_HASH_TYPE_GOST = 10 } |
Cryptographic hash function types for PCryptoHash. More... | |
Functions | |
P_LIB_API PCryptoHash * | p_crypto_hash_new (PCryptoHashType type) |
Initializes a new PCryptoHash context. | |
P_LIB_API void | p_crypto_hash_update (PCryptoHash *hash, const puchar *data, psize len) |
Adds a new chunk of data for hashing. | |
P_LIB_API void | p_crypto_hash_reset (PCryptoHash *hash) |
Resets a hash state. | |
P_LIB_API pchar * | p_crypto_hash_get_string (PCryptoHash *hash) |
Gets a hash in a hexidemical representation. | |
P_LIB_API void | p_crypto_hash_get_digest (PCryptoHash *hash, puchar *buf, psize *len) |
Gets a hash in a raw representation. | |
P_LIB_API pssize | p_crypto_hash_get_length (const PCryptoHash *hash) |
Gets a hash digest length depending on its type. | |
P_LIB_API PCryptoHashType | p_crypto_hash_get_type (const PCryptoHash *hash) |
Gets a hash function type. | |
P_LIB_API void | p_crypto_hash_free (PCryptoHash *hash) |
Frees a previously initialized hash context. | |
Cryptographic hash function.
A cryptographic hash function is an algorithm which performs a transformation of the income data to a hash value.
One of the main requirements to all of the cryptographic hashing algorithms is that any (even a considerably small) change in the input data must lead to notable changes in the result hash value. It is the so called avalanche effect. It helps to avoid collisions (the same hash value for different input arrays).
The cryptographic hash function is designed to be a one-way so you couldn't revert the output hash value to the input data back. The length of the resulting hash is a constant value depending on the algorithm being used.
A cryptographic hash works with the incoming data using fixed length blocks so it is possible to feed as many data as required.
The cryptographic hash module supports the following hash functions:
Use p_crypto_hash_new() to initialize a new hash context with one of the mentioned above types. Data for hashing can be added in several chunks using the p_crypto_hash_update() routine. You can add more chunks as long as the hash context is open.
The hash context becomes close in two cases: p_crypto_hash_get_string() or p_crypto_hash_get_digest() was called. After that you can only get a hash in a hexidemical string or in a raw representation.
A hashing algorithm couldn't be changed after the context initialization.
Definition in file pcryptohash.h.
typedef struct PCryptoHash_ PCryptoHash |
Opaque data structure for handling a cryptographic hash context.
Definition at line 85 of file pcryptohash.h.
enum PCryptoHashType_ |
Cryptographic hash function types for PCryptoHash.
Definition at line 88 of file pcryptohash.h.
P_LIB_API void p_crypto_hash_free | ( | PCryptoHash * | hash | ) |
P_LIB_API void p_crypto_hash_get_digest | ( | PCryptoHash * | hash, |
puchar * | buf, | ||
psize * | len ) |
Gets a hash in a raw representation.
hash | PCryptoHash context to get a digest from. | |
buf | Buffer to store the digest with the hash raw representation. | |
[in,out] | len | Size of buf when calling, count of written bytes after. |
P_LIB_API pssize p_crypto_hash_get_length | ( | const PCryptoHash * | hash | ) |
Gets a hash digest length depending on its type.
hash | PCryptoHash context to get the length for. |
P_LIB_API pchar * p_crypto_hash_get_string | ( | PCryptoHash * | hash | ) |
Gets a hash in a hexidemical representation.
hash | PCryptoHash context to get a string from. |
P_LIB_API PCryptoHashType p_crypto_hash_get_type | ( | const PCryptoHash * | hash | ) |
Gets a hash function type.
hash | PCryptoHash context to get the type for. |
P_LIB_API PCryptoHash * p_crypto_hash_new | ( | PCryptoHashType | type | ) |
Initializes a new PCryptoHash context.
type | Hash function type to use, can't be changed later. |
P_LIB_API void p_crypto_hash_reset | ( | PCryptoHash * | hash | ) |
Resets a hash state.
hash | PCryptoHash context to reset. |
After a reset the hash context becomes open for updating, but all previously added data will be lost. A hash function type couldn't be changed during or after the resets.
P_LIB_API void p_crypto_hash_update | ( | PCryptoHash * | hash, |
const puchar * | data, | ||
psize | len ) |
Adds a new chunk of data for hashing.
hash | PCryptoHash context to add data to. |
data | Data to add for hashing. |
len | Data length, in bytes. |