创建Context并设定Cipher key
创建Cipher context的时候需要提供内存及相关管理函数填充setup.ops,可以提供第三方内存,也可以使用WD提供的BLK内存池接口创建。此处以根据wd_queue申请的test_mempool示例Cipher context的创建过程。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | struct wcrypto_cipher_ctx_setup setup; void *ctx = NULL,*pool = NULL; int block_size = TEST_BLOCK_SIZE; int block_num = TEST_BLOCK_NUM; pool = test_mempool_create(&q, block_size, block_num); memset((void *)&setup, 0, sizeof(setup)); setup.ops.alloc = test_alloc_buf; setup.ops.free = test_free_buf; setup.ops.dma_map = test_ dma_map; setup.ops.dma_unmap = test_ dma_unmap; setup.ops.usr = pool; setup.alg = WCRYPTO_CIPHER_SM4; setup.mode = WCRYPTO_CIPHER_CBC; ctx = wcrypto_create_cipher_ctx(&q, &setup); wcrypto_set_cipher_key(ctx, key, key_len); |
父主题: CIPHER同步接口使用示例