Lines Matching refs:ctx
52 void mbedtls_block_cipher_free(mbedtls_block_cipher_context_t *ctx) in mbedtls_block_cipher_free() argument
54 if (ctx == NULL) { in mbedtls_block_cipher_free()
59 if (ctx->engine == MBEDTLS_BLOCK_CIPHER_ENGINE_PSA) { in mbedtls_block_cipher_free()
60 psa_destroy_key(ctx->psa_key_id); in mbedtls_block_cipher_free()
64 switch (ctx->id) { in mbedtls_block_cipher_free()
67 mbedtls_aes_free(&ctx->ctx.aes); in mbedtls_block_cipher_free()
72 mbedtls_aria_free(&ctx->ctx.aria); in mbedtls_block_cipher_free()
77 mbedtls_camellia_free(&ctx->ctx.camellia); in mbedtls_block_cipher_free()
83 ctx->id = MBEDTLS_BLOCK_CIPHER_ID_NONE; in mbedtls_block_cipher_free()
86 int mbedtls_block_cipher_setup(mbedtls_block_cipher_context_t *ctx, in mbedtls_block_cipher_setup() argument
89 ctx->id = (cipher_id == MBEDTLS_CIPHER_ID_AES) ? MBEDTLS_BLOCK_CIPHER_ID_AES : in mbedtls_block_cipher_setup()
95 psa_key_type_t psa_key_type = psa_key_type_from_block_cipher_id(ctx->id); in mbedtls_block_cipher_setup()
98 ctx->engine = MBEDTLS_BLOCK_CIPHER_ENGINE_PSA; in mbedtls_block_cipher_setup()
101 ctx->engine = MBEDTLS_BLOCK_CIPHER_ENGINE_LEGACY; in mbedtls_block_cipher_setup()
104 switch (ctx->id) { in mbedtls_block_cipher_setup()
107 mbedtls_aes_init(&ctx->ctx.aes); in mbedtls_block_cipher_setup()
112 mbedtls_aria_init(&ctx->ctx.aria); in mbedtls_block_cipher_setup()
117 mbedtls_camellia_init(&ctx->ctx.camellia); in mbedtls_block_cipher_setup()
121 ctx->id = MBEDTLS_BLOCK_CIPHER_ID_NONE; in mbedtls_block_cipher_setup()
126 int mbedtls_block_cipher_setkey(mbedtls_block_cipher_context_t *ctx, in mbedtls_block_cipher_setkey() argument
131 if (ctx->engine == MBEDTLS_BLOCK_CIPHER_ENGINE_PSA) { in mbedtls_block_cipher_setkey()
135 psa_set_key_type(&key_attr, psa_key_type_from_block_cipher_id(ctx->id)); in mbedtls_block_cipher_setkey()
140 status = psa_import_key(&key_attr, key, PSA_BITS_TO_BYTES(key_bitlen), &ctx->psa_key_id); in mbedtls_block_cipher_setkey()
150 switch (ctx->id) { in mbedtls_block_cipher_setkey()
153 return mbedtls_aes_setkey_enc(&ctx->ctx.aes, key, key_bitlen); in mbedtls_block_cipher_setkey()
157 return mbedtls_aria_setkey_enc(&ctx->ctx.aria, key, key_bitlen); in mbedtls_block_cipher_setkey()
161 return mbedtls_camellia_setkey_enc(&ctx->ctx.camellia, key, key_bitlen); in mbedtls_block_cipher_setkey()
168 int mbedtls_block_cipher_encrypt(mbedtls_block_cipher_context_t *ctx, in mbedtls_block_cipher_encrypt() argument
173 if (ctx->engine == MBEDTLS_BLOCK_CIPHER_ENGINE_PSA) { in mbedtls_block_cipher_encrypt()
177 status = psa_cipher_encrypt(ctx->psa_key_id, PSA_ALG_ECB_NO_PADDING, in mbedtls_block_cipher_encrypt()
186 switch (ctx->id) { in mbedtls_block_cipher_encrypt()
189 return mbedtls_aes_crypt_ecb(&ctx->ctx.aes, MBEDTLS_AES_ENCRYPT, in mbedtls_block_cipher_encrypt()
194 return mbedtls_aria_crypt_ecb(&ctx->ctx.aria, input, output); in mbedtls_block_cipher_encrypt()
198 return mbedtls_camellia_crypt_ecb(&ctx->ctx.camellia, in mbedtls_block_cipher_encrypt()