diff options
author | Nikias Bassen | 2024-06-15 20:31:37 +0200 |
---|---|---|
committer | Nikias Bassen | 2024-06-15 20:31:37 +0200 |
commit | 510ca0e0dfc88acda8b86bfbfe44f4eec2e1b7d6 (patch) | |
tree | cd3d0867a1f25138e30fec712b7dcf56086eb96f /include/libimobiledevice-glue | |
parent | 14c2e4b64b2bd6189d06d858bf4898d3a9f5a6e4 (diff) | |
download | libimobiledevice-glue-510ca0e0dfc88acda8b86bfbfe44f4eec2e1b7d6.tar.gz libimobiledevice-glue-510ca0e0dfc88acda8b86bfbfe44f4eec2e1b7d6.tar.bz2 |
Add SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 functions to interface
Diffstat (limited to 'include/libimobiledevice-glue')
-rw-r--r-- | include/libimobiledevice-glue/sha.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/include/libimobiledevice-glue/sha.h b/include/libimobiledevice-glue/sha.h new file mode 100644 index 0000000..3a00578 --- /dev/null +++ b/include/libimobiledevice-glue/sha.h @@ -0,0 +1,86 @@ +#ifndef __SHA_H +#define __SHA_H + +#include <stddef.h> +#include <stdint.h> + +#include <libimobiledevice-glue/glue.h> + +/* LibTomCrypt, modular cryptographic library -- Tom St Denis + * + * LibTomCrypt is a library that provides various cryptographic + * algorithms in a highly modular and flexible manner. + * + * The library is free for all purposes without any express + * guarantee it works. + * + * Tom St Denis, tomstdenis@gmail.com, http://libtom.org + */ + +/* SHA-1 */ +typedef struct sha1_context_ { + uint64_t length; + uint32_t state[5]; + size_t curlen; + unsigned char buf[64]; +} sha1_context; + +#define SHA1_DIGEST_LENGTH 20 + +LIMD_GLUE_API int sha1_init(sha1_context * md); +LIMD_GLUE_API int sha1_final(sha1_context * md, unsigned char *out); +LIMD_GLUE_API int sha1_update(sha1_context * md, const void *data, size_t inlen); +LIMD_GLUE_API int sha1(const unsigned char *message, size_t message_len, unsigned char *out); + +/* SHA-256 */ +typedef struct sha256_context_ { + uint64_t length; + uint32_t state[8]; + size_t curlen; + unsigned char buf[64]; + int num_dwords; +} sha256_context; + +#define SHA256_DIGEST_LENGTH 32 + +LIMD_GLUE_API int sha256_init(sha256_context * md); +LIMD_GLUE_API int sha256_final(sha256_context * md, unsigned char *out); +LIMD_GLUE_API int sha256_update(sha256_context * md, const void *data, size_t inlen); +LIMD_GLUE_API int sha256(const unsigned char *message, size_t message_len, unsigned char *out); + +/* SHA-224 */ +#define sha224_context sha256_context + +#define SHA224_DIGEST_LENGTH 28 + +LIMD_GLUE_API int sha224_init(sha224_context * md); +LIMD_GLUE_API int sha224_final(sha224_context * md, unsigned char *out); +LIMD_GLUE_API int sha224_update(sha224_context * md, const void *data, size_t inlen); +LIMD_GLUE_API int sha224(const unsigned char *message, size_t message_len, unsigned char *out); + +/* SHA-512 */ +typedef struct sha512_context_ { + uint64_t length, state[8]; + size_t curlen; + unsigned char buf[128]; + int num_qwords; +} sha512_context; + +#define SHA512_DIGEST_LENGTH 64 + +LIMD_GLUE_API int sha512_init(sha512_context * md); +LIMD_GLUE_API int sha512_final(sha512_context * md, unsigned char *out); +LIMD_GLUE_API int sha512_update(sha512_context * md, const void *data, size_t inlen); +LIMD_GLUE_API int sha512(const unsigned char *message, size_t message_len, unsigned char *out); + +/* SHA-384 */ +#define sha384_context sha512_context + +#define SHA384_DIGEST_LENGTH 48 + +LIMD_GLUE_API int sha384_init(sha384_context * md); +LIMD_GLUE_API int sha384_final(sha384_context * md, unsigned char *out); +LIMD_GLUE_API int sha384_update(sha384_context * md, const void *data, size_t inlen); +LIMD_GLUE_API int sha384(const unsigned char *message, size_t message_len, unsigned char *out); + +#endif |