void bcal_cbc_decNext(void *block, bcal_cbc_ctx_t *ctx){ uint8_t tmp[ctx->blocksize_B]; memcpy(tmp, block, ctx->blocksize_B); bcal_cipher_dec(block, &(ctx->cctx)); memxor(block, ctx->prev_block, ctx->blocksize_B); memcpy(ctx->prev_block, tmp, ctx->blocksize_B); }
void testrun_test_aes(void){ uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }; uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34 }; aes128_ctx_t ctx; aes128_init(key, &ctx); cli_putstr("\r\n\r\n cipher test (FIPS 197):\r\n key: "); cli_hexdump(key, 16); cli_putstr("\r\n plaintext: "); cli_hexdump(data, 16); aes128_enc(data, &ctx); cli_putstr("\r\n ciphertext: "); cli_hexdump(data, 16); aes128_dec(data, &ctx); cli_putstr("\r\n plaintext: "); cli_hexdump(data, 16); cli_putstr("\r\n testing bcal:"); bcgen_ctx_t bcal_ctx; uint8_t r; r = bcal_cipher_init(&aes128_desc, key, 128, &bcal_ctx); cli_putstr("\r\n init = 0x"); cli_hexdump(&r, 1); bcal_cipher_enc(data, &bcal_ctx); cli_putstr("\r\n ciphertext: "); cli_hexdump(data, 16); bcal_cipher_dec(data, &bcal_ctx); cli_putstr("\r\n plaintext: "); cli_hexdump(data, 16); bcal_cipher_free(&bcal_ctx); }
void bcal_cbc_decRand(void *block, const void *prev_block, bcal_cbc_ctx_t *ctx){ bcal_cipher_dec(block, &(ctx->cctx)); memxor(block, prev_block, ctx->blocksize_B); }