void bcal_ctr_encMsg(const void* iv, void* msg, uint32_t msg_len_b, bcal_ctr_ctx_t* ctx){ bcal_ctr_loadIV(iv, ctx); uint16_t blocksize_b; blocksize_b = ctx->blocksize_B*8; while(msg_len_b>blocksize_b){ bcal_ctr_encNext(msg, ctx); msg_len_b -= blocksize_b; msg = (uint8_t*)msg + ctx->blocksize_B; } uint8_t tmp[ctx->blocksize_B]; memcpy(tmp, ctx->in_block, ctx->blocksize_B); bcal_cipher_enc(tmp, &(ctx->cctx)); ctx->inc_func(ctx->in_block, ctx->blocksize_B); tmp[msg_len_b/8] = 0xff00>>(msg_len_b&7); memxor(msg, tmp, (msg_len_b+7)/8); }
void bcal_eax_loadNonce(const void *nonce, uint16_t length_b, bcal_eax_ctx_t *ctx){ bcal_cmac_lastBlock(&(ctx->ntag), nonce, length_b); bcal_cmac_ctx2mac(ctx->nonce, ctx->blocksize_B*8, &(ctx->ntag)); bcal_ctr_loadIV(ctx->nonce, &(ctx->cipher)); }