Creating a Context and Setting a Cipher Key
When creating a cipher context, you need to provide the memory and related management functions to fill in setup.ops. You can provide third-party memory or use the BLK memory pool interface provided by the WD to create the cipher context. The following describes how to create a cipher context based on test_mempool applied by wd_queue.
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); |
Parent topic: Cipher Synchronization Interface Usage Examples