Lines Matching refs:mc
45 struct crypto_cbc_mac_ctx *mc = to_cbc_mac_ctx(ctx); in crypto_cbc_mac_init() local
47 memset(mc->block, 0, sizeof(mc->block)); in crypto_cbc_mac_init()
48 memset(mc->digest, 0, sizeof(mc->digest)); in crypto_cbc_mac_init()
49 mc->current_block_len = 0; in crypto_cbc_mac_init()
50 mc->is_computed = false; in crypto_cbc_mac_init()
53 return crypto_cipher_init(mc->cbc_ctx, TEE_MODE_ENCRYPT, key, len, in crypto_cbc_mac_init()
54 NULL, 0, mc->block, mc->block_len); in crypto_cbc_mac_init()
65 struct crypto_cbc_mac_ctx *mc = to_cbc_mac_ctx(ctx); in crypto_cbc_mac_update() local
67 if ((mc->current_block_len > 0) && in crypto_cbc_mac_update()
68 (len + mc->current_block_len >= mc->block_len)) { in crypto_cbc_mac_update()
69 size_t pad_len = mc->block_len - mc->current_block_len; in crypto_cbc_mac_update()
71 memcpy(mc->block + mc->current_block_len, data, pad_len); in crypto_cbc_mac_update()
74 res = crypto_cipher_update(mc->cbc_ctx, TEE_MODE_ENCRYPT, in crypto_cbc_mac_update()
75 false, mc->block, mc->block_len, in crypto_cbc_mac_update()
76 mc->digest); in crypto_cbc_mac_update()
79 mc->is_computed = 1; in crypto_cbc_mac_update()
80 mc->current_block_len = 0; in crypto_cbc_mac_update()
83 nblocks = MIN(len / mc->block_len, in crypto_cbc_mac_update()
86 out_tmp = malloc(nblocks * mc->block_len); in crypto_cbc_mac_update()
88 while (len >= mc->block_len) { in crypto_cbc_mac_update()
89 nblocks = MIN(len / mc->block_len, in crypto_cbc_mac_update()
93 out_len = nblocks * mc->block_len; in crypto_cbc_mac_update()
96 out_len = mc->block_len; in crypto_cbc_mac_update()
97 out = mc->digest; in crypto_cbc_mac_update()
101 res = crypto_cipher_update(mc->cbc_ctx, TEE_MODE_ENCRYPT, in crypto_cbc_mac_update()
105 mc->is_computed = 1; in crypto_cbc_mac_update()
108 if (nblocks > 1 && len < mc->block_len) { in crypto_cbc_mac_update()
111 memcpy(mc->digest, out_tmp + out_len - mc->block_len, in crypto_cbc_mac_update()
112 mc->block_len); in crypto_cbc_mac_update()
117 assert(mc->current_block_len + len < mc->block_len); in crypto_cbc_mac_update()
118 memcpy(mc->block + mc->current_block_len, data, len); in crypto_cbc_mac_update()
119 mc->current_block_len += len; in crypto_cbc_mac_update()
130 struct crypto_cbc_mac_ctx *mc = to_cbc_mac_ctx(ctx); in crypto_cbc_mac_final() local
132 if (mc->pkcs5_pad) { in crypto_cbc_mac_final()
138 size_t pad_len = mc->block_len - mc->current_block_len; in crypto_cbc_mac_final()
140 memset(mc->block + mc->current_block_len, pad_len, pad_len); in crypto_cbc_mac_final()
141 mc->current_block_len = 0; in crypto_cbc_mac_final()
142 if (crypto_cbc_mac_update(ctx, mc->block, mc->block_len)) in crypto_cbc_mac_final()
146 if (!mc->is_computed || mc->current_block_len) in crypto_cbc_mac_final()
149 memcpy(digest, mc->digest, MIN(digest_len, mc->block_len)); in crypto_cbc_mac_final()
150 crypto_cipher_final(mc->cbc_ctx); in crypto_cbc_mac_final()
157 struct crypto_cbc_mac_ctx *mc = to_cbc_mac_ctx(ctx); in crypto_cbc_mac_free_ctx() local
159 crypto_cipher_free_ctx(mc->cbc_ctx); in crypto_cbc_mac_free_ctx()
160 free(mc); in crypto_cbc_mac_free_ctx()