BALTECH SDK wrapper functions reference
aes.h
Go to the documentation of this file.
1 
12 #ifndef __AES_H__
13 #define __AES_H__
14 
15 #include "common.h"
16 
20 #define AES_BLOCK_SIZE 16
21 
25 #define AES_KEY_SIZE 16
26 
30 #define AES_KEY_SIZE_BITS 128
31 
35 #define AES_OK 0 // Success
36 #define AES_ERR_INVALID_PARAM 1 // NULL pointer or invalid parameter
37 #define AES_ERR_INVALID_LENGTH 2 // Invalid data length (not block-aligned or zero)
38 #define AES_ERR_CRYPTO_FAILURE 3 // Underlying crypto operation failed
39 
44 typedef struct aes_ctx_t* aes_ctx;
45 
46 
55 aes_ctx aes_create_ctx(const unsigned char key[AES_KEY_SIZE]);
56 
57 
69  aes_ctx ctx,
70  const unsigned char plaintext[AES_BLOCK_SIZE],
71  unsigned char ciphertext[AES_BLOCK_SIZE]
72 );
73 
74 
85 int aes_cbc_encrypt(
86  aes_ctx ctx,
87  const unsigned char * plaintext,
88  size_t plaintext_len,
89  unsigned char * ciphertext,
90  const unsigned char iv[AES_BLOCK_SIZE]
91 );
92 
93 
104 int aes_cbc_decrypt(
105  aes_ctx ctx,
106  const unsigned char * ciphertext,
107  size_t ciphertext_len,
108  unsigned char * plaintext,
109  const unsigned char iv[AES_BLOCK_SIZE]
110 );
111 
112 
124 int aes_cbc_mac(
125  aes_ctx ctx,
126  const unsigned char * plaintext,
127  size_t plaintext_len,
128  unsigned char mac[AES_BLOCK_SIZE]
129 );
130 
131 
138 void aes_destroy_ctx(aes_ctx ctx);
139 
140 
141 #endif // __AES_H__
142 
int aes_cbc_decrypt(aes_ctx ctx, const unsigned char *ciphertext, size_t ciphertext_len, unsigned char *plaintext, const unsigned char iv[AES_BLOCK_SIZE])
Decrypt data using AES-128 in CBC mode.
aes_ctx aes_create_ctx(const unsigned char key[AES_KEY_SIZE])
Create and initialize an AES-128 context from a key.
int aes_cbc_encrypt(aes_ctx ctx, const unsigned char *plaintext, size_t plaintext_len, unsigned char *ciphertext, const unsigned char iv[AES_BLOCK_SIZE])
Encrypt data using AES-128 in CBC mode.
#define AES_BLOCK_SIZE
AES block size in bytes (128 bits)
Definition: aes.h:20
void aes_destroy_ctx(aes_ctx ctx)
Destroy an AES context and securely wipe its memory.
int aes_encrypt_block(aes_ctx ctx, const unsigned char plaintext[AES_BLOCK_SIZE], unsigned char ciphertext[AES_BLOCK_SIZE])
Encrypt a single 16-byte block using AES-128 in ECB mode.
#define AES_KEY_SIZE
AES-128 key size in bytes.
Definition: aes.h:25
Contains the basic defines that are required throughout the BRP library.
int aes_cbc_mac(aes_ctx ctx, const unsigned char *plaintext, size_t plaintext_len, unsigned char mac[AES_BLOCK_SIZE])
Calculate CBC-MAC (Cipher Block Chaining Message Authentication Code).
struct aes_ctx_t * aes_ctx
Opaque AES key schedule type.
Definition: aes.h:44