#pragma once
#include "uefi.h"

/* SHA-256 */
void sha256(const void *data, uint32_t len, uint8_t out[32]);
void sha256_init(void *ctx);
void sha256_update(void *ctx, const void *data, uint32_t len);
void sha256_final(void *ctx, uint8_t out[32]);
#define SHA256_CTX_SIZE 128

/* HMAC-SHA-256 */
void hmac_sha256(const uint8_t *key, uint32_t key_len,
                 const uint8_t *data, uint32_t data_len,
                 uint8_t out[32]);

/* AES-128 */
void aes128_encrypt_block(const uint8_t in[16], uint8_t out[16],
                          const uint8_t key[16]);
void aes128_init_keys(const uint8_t key[16], void *ctx);
#define AES128_CTX_SIZE 176

/* AES-128-GCM */
int  aes128_gcm_encrypt(const uint8_t key[16], const uint8_t iv[12],
                        const uint8_t *plain, uint32_t plain_len,
                        const uint8_t *aad, uint32_t aad_len,
                        uint8_t *cipher, uint8_t tag[16]);
int  aes128_gcm_decrypt(const uint8_t key[16], const uint8_t iv[12],
                        const uint8_t *cipher, uint32_t cipher_len,
                        const uint8_t *aad, uint32_t aad_len,
                        uint8_t *plain, const uint8_t tag[16]);

/* TLS PRF (Pseudo-Random Function) based on HMAC-SHA-256 */
void tls_prf(const uint8_t *secret, uint32_t secret_len,
             const char *label,
             const uint8_t *seed, uint32_t seed_len,
             uint8_t *out, uint32_t out_len);

/* Random */
void crypto_random(void *buf, uint32_t len);
