#ifndef AWS_CAL_HASH_H_
#define AWS_CAL_HASH_H_
#include <aws/cal/exports.h>
#include <aws/common/byte_buf.h>
#include <aws/common/common.h>
#define AWS_SHA256_LEN 32
#define AWS_SHA1_LEN 20
#define AWS_MD5_LEN 16
struct aws_hash;
struct aws_hash_vtable {
const char *alg_name;
const char *provider;
void (*destroy)(struct aws_hash *hash);
int (*update)(struct aws_hash *hash, const struct aws_byte_cursor *buf);
int (*finalize)(struct aws_hash *hash, struct aws_byte_buf *out);
};
struct aws_hash {
struct aws_allocator *allocator;
struct aws_hash_vtable *vtable;
size_t digest_size;
bool good;
void *impl;
};
typedef struct aws_hash *(aws_hash_new_fn)(struct aws_allocator *allocator);
AWS_EXTERN_C_BEGIN
AWS_CAL_API struct aws_hash *aws_sha256_new(struct aws_allocator *allocator);
AWS_CAL_API struct aws_hash *aws_sha1_new(struct aws_allocator *allocator);
AWS_CAL_API struct aws_hash *aws_md5_new(struct aws_allocator *allocator);
AWS_CAL_API void aws_hash_destroy(struct aws_hash *hash);
AWS_CAL_API int aws_hash_update(struct aws_hash *hash, const struct aws_byte_cursor *to_hash);
AWS_CAL_API int aws_hash_finalize(struct aws_hash *hash, struct aws_byte_buf *output, size_t truncate_to);
AWS_CAL_API int aws_md5_compute(
struct aws_allocator *allocator,
const struct aws_byte_cursor *input,
struct aws_byte_buf *output,
size_t truncate_to);
AWS_CAL_API int aws_sha256_compute(
struct aws_allocator *allocator,
const struct aws_byte_cursor *input,
struct aws_byte_buf *output,
size_t truncate_to);
AWS_CAL_API int aws_sha1_compute(
struct aws_allocator *allocator,
const struct aws_byte_cursor *input,
struct aws_byte_buf *output,
size_t truncate_to);
AWS_CAL_API void aws_set_md5_new_fn(aws_hash_new_fn *fn);
AWS_CAL_API void aws_set_sha256_new_fn(aws_hash_new_fn *fn);
AWS_CAL_API void aws_set_sha1_new_fn(aws_hash_new_fn *fn);
AWS_EXTERN_C_END
#endif