Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
aes_cmac.c File Reference
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "aes_cmac.h"
#include "../common/insecure_memzero.h"
Include dependency graph for aes_cmac.c:

Go to the source code of this file.

Functions

void aes_cmac_encrypt (const aes_cmac_context_t *ctx, const uint8_t *message, const uint16_t message_len, uint8_t *mac)
 
uint8_t aes_cmac_init (uint8_t *key, uint16_t key_len, aes_cmac_context_t *ctx)
 
void aes_cmac_destroy (aes_cmac_context_t *ctx)
 

Function Documentation

◆ aes_cmac_destroy()

void aes_cmac_destroy ( aes_cmac_context_t * ctx)

Definition at line 147 of file aes_cmac.c.

147 {
148 if (!ctx)
149 return;
150 aes_destroy(&(ctx->aes_ctx));
152}
void aes_destroy(aes_context *ctx)
Definition aes.c:330
#define insecure_memzero(buf, len)
aes_context aes_ctx
Definition aes_cmac.h:20
Here is the call graph for this function:

◆ aes_cmac_encrypt()

void aes_cmac_encrypt ( const aes_cmac_context_t * ctx,
const uint8_t * message,
const uint16_t message_len,
uint8_t * mac )

Definition at line 85 of file aes_cmac.c.

86 {
87
88 uint8_t n_blocks;
89 uint8_t i;
90 uint8_t remaining_bytes;
91
93 uint8_t *ptr = (uint8_t *) message;
94
95 memcpy(mac, zero, AES_BLOCK_SIZE);
97
98 if (message_len == 0)
99 n_blocks = 0;
100 else
101 n_blocks = (message_len + (AES_BLOCK_SIZE - 1)) / AES_BLOCK_SIZE - 1;
102
103 remaining_bytes = (message_len % AES_BLOCK_SIZE);
104
105 for (i = 0; i < n_blocks; i++) {
106 do_xor(ptr, mac);
107 aes_encrypt(mac, mac, &ctx->aes_ctx);
108 ptr += AES_BLOCK_SIZE;
109 }
110
111 if (remaining_bytes == 0) {
112 if (message != NULL && message_len != 0) {
113 memcpy(M, ptr, AES_BLOCK_SIZE);
114 do_xor(ctx->k1, M);
115 } else {
116 do_pad(M, 0);
117 do_xor(ctx->k2, M);
118 }
119 } else {
120 memcpy(M, ptr, remaining_bytes);
121 do_pad(M, remaining_bytes);
122 do_xor(ctx->k2, M);
123 }
124
125 do_xor(M, mac);
126
127 aes_encrypt(mac, mac, &ctx->aes_ctx);
128}
uint8_t aes_encrypt(uint8_t *in, uint8_t *out, const aes_context *ctx)
Definition aes.c:229
#define AES_BLOCK_SIZE
Definition aes.h:35
unsigned char uint8_t
Definition stdint.h:124
uint8_t k1[AES_BLOCK_SIZE]
Definition aes_cmac.h:21
uint8_t k2[AES_BLOCK_SIZE]
Definition aes_cmac.h:22
memcpy((char *) pInfo->slotDescription, s, l)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ aes_cmac_init()

uint8_t aes_cmac_init ( uint8_t * key,
uint16_t key_len,
aes_cmac_context_t * ctx )

Definition at line 130 of file aes_cmac.c.

130 {
131
133
135
137 aes_encrypt(zero, L, &ctx->aes_ctx);
138
139 cmac_generate_subkey(L, ctx->k1);
140 cmac_generate_subkey(ctx->k1, ctx->k2);
141
142 aes_cmac_encrypt(ctx, zero, AES_BLOCK_SIZE, ctx->mac);
143
144 return 0;
145}
uint8_t aes_set_encrypt_key(uint8_t *key, uint16_t key_len, aes_context *ctx)
Definition aes.c:172
void aes_cmac_encrypt(const aes_cmac_context_t *ctx, const uint8_t *message, const uint16_t message_len, uint8_t *mac)
Definition aes_cmac.c:85
uint8_t mac[AES_BLOCK_SIZE]
Definition aes_cmac.h:23
session operation op sign key_len
Here is the call graph for this function:
Here is the caller graph for this function: