Lines Matching refs:ctx
152 static int32_t HandleError(mbedtls_cipher_context_t *ctx, const char *buf)
157 if (ctx != NULL) {
158 mbedtls_cipher_free(ctx);
189 mbedtls_md_context_t ctx;
191 mbedtls_md_init(&ctx);
195 mbedtls_md_free(&ctx);
198 if (mbedtls_md_setup(&ctx, info, 0) != 0) {
199 mbedtls_md_free(&ctx);
202 if (mbedtls_md_starts(&ctx) != 0) {
203 mbedtls_md_free(&ctx);
206 if (mbedtls_md_update(&ctx, str, len) != 0) {
207 mbedtls_md_free(&ctx);
210 if (mbedtls_md_finish(&ctx, hash) != 0) {
211 mbedtls_md_free(&ctx);
215 mbedtls_md_free(&ctx);
369 mbedtls_cipher_context_t ctx;
371 mbedtls_cipher_init(&ctx);
373 return HandleError(&ctx, "mbedtls_cipher_info_from_type ctr failed");
375 if (mbedtls_cipher_setup(&ctx, info) != 0) {
376 return HandleError(&ctx, "mbedtls_cipher_setup ctr failed");
378 if (mbedtls_cipher_setkey(&ctx, key->key, key->keyLen * BYTES_BIT_NUM, MBEDTLS_ENCRYPT) != 0) {
379 return HandleError(&ctx, "mbedtls_cipher_setkey ctr failed");
381 if (mbedtls_cipher_set_iv(&ctx, key->iv, BLE_BROADCAST_IV_LEN) != 0) {
382 return HandleError(&ctx, "mbedtls_cipher_set_iv ctr failed");
384 if (mbedtls_cipher_update(&ctx, input, inLen, encryptData, &len) != 0) {
385 return HandleError(&ctx, "mbedtls_cipher_update ctr failed");
388 if (mbedtls_cipher_finish(&ctx, encryptData, &len) != 0) {
389 return HandleError(&ctx, "mbedtls_cipher_finish ctr failed");
392 mbedtls_cipher_free(&ctx);