hactool/aes.h

40 lines
1.2 KiB
C
Raw Normal View History

#ifndef HACTOOL_AES_H
#define HACTOOL_AES_H
2018-01-24 17:52:25 +00:00
2018-01-29 18:39:30 +00:00
#include "mbedtls/cipher.h"
#include "mbedtls/cmac.h"
2018-01-24 17:52:25 +00:00
2018-01-29 18:39:30 +00:00
/* Enumerations. */
typedef enum {
AES_MODE_ECB = MBEDTLS_CIPHER_AES_128_ECB,
AES_MODE_CTR = MBEDTLS_CIPHER_AES_128_CTR,
AES_MODE_XTS = MBEDTLS_CIPHER_AES_128_XTS
} aes_mode_t;
typedef enum {
AES_DECRYPT = MBEDTLS_DECRYPT,
AES_ENCRYPT = MBEDTLS_ENCRYPT,
} aes_operation_t;
/* Define structs. */
2018-01-24 17:52:25 +00:00
typedef struct {
2018-01-29 18:39:30 +00:00
mbedtls_cipher_context_t cipher_enc;
mbedtls_cipher_context_t cipher_dec;
2018-01-24 17:52:25 +00:00
} aes_ctx_t;
2018-01-29 18:39:30 +00:00
/* Function prototypes. */
aes_ctx_t *new_aes_ctx(const void *key, unsigned int key_size, aes_mode_t mode);
2018-01-24 17:52:25 +00:00
void free_aes_ctx(aes_ctx_t *ctx);
2018-01-29 18:39:30 +00:00
2018-01-24 17:52:25 +00:00
void aes_setiv(aes_ctx_t *ctx, const void *iv, size_t l);
void aes_encrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l);
void aes_decrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l);
2018-01-24 17:52:25 +00:00
void aes_calculate_cmac(void *dst, void *src, size_t size, const void *key);
void aes_xts_encrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l, size_t sector, size_t sector_size);
void aes_xts_decrypt(aes_ctx_t *ctx, void *dst, const void *src, size_t l, size_t sector, size_t sector_size);
2018-01-24 17:52:25 +00:00
#endif