Lines Matching refs:ctx

95 	mbedtls_md_context_t ctx;
99 mbedtls_md_init(&ctx);
102 mbedtls_md_free(&ctx);
105 ret = mbedtls_md_setup(&ctx, info, 1);
107 mbedtls_md_free(&ctx);
110 ret = mbedtls_pkcs5_pbkdf2_hmac(&ctx, (const unsigned char *)pw,
113 mbedtls_md_free(&ctx);
165 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
169 ctx->key_len = key_len;
170 memcpy(ctx->key, key, key_len);
171 memset(ctx->nonce, 0, sizeof(ctx->nonce));
172 ctx->encr_pos = AES_BLOCK_SIZE;
174 ccNoPadding, NULL, key, key_len, NULL, 0, 0, 0, &ctx->ctx);
179 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
181 CCCryptorRef ref = ctx->ctx;
187 r = CCCryptorUpdate(ref, ctx->nonce, AES_BLOCK_SIZE, ctx->encr_buf,
193 aes_ctr_release(archive_crypto_ctx *ctx)
195 memset(ctx->key, 0, ctx->key_len);
196 memset(ctx->nonce, 0, sizeof(ctx->nonce));
203 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
213 ctx->hAlg = NULL;
214 ctx->hKey = NULL;
215 ctx->keyObj = NULL;
264 ctx->hAlg = hAlg;
265 ctx->hKey = hKey;
266 ctx->keyObj = keyObj;
267 ctx->keyObj_len = keyObj_len;
268 ctx->encr_pos = AES_BLOCK_SIZE;
274 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
279 status = BCryptEncrypt(ctx->hKey, (PUCHAR)ctx->nonce, AES_BLOCK_SIZE,
280 NULL, NULL, 0, (PUCHAR)ctx->encr_buf, AES_BLOCK_SIZE,
286 aes_ctr_release(archive_crypto_ctx *ctx)
289 if (ctx->hAlg != NULL) {
290 BCryptCloseAlgorithmProvider(ctx->hAlg, 0);
291 ctx->hAlg = NULL;
292 BCryptDestroyKey(ctx->hKey);
293 ctx->hKey = NULL;
294 HeapFree(GetProcessHeap(), 0, ctx->keyObj);
295 ctx->keyObj = NULL;
297 memset(ctx, 0, sizeof(*ctx));
304 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
306 mbedtls_aes_init(&ctx->ctx);
307 ctx->key_len = key_len;
308 memcpy(ctx->key, key, key_len);
309 memset(ctx->nonce, 0, sizeof(ctx->nonce));
310 ctx->encr_pos = AES_BLOCK_SIZE;
315 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
317 if (mbedtls_aes_setkey_enc(&ctx->ctx, ctx->key,
318 ctx->key_len * 8) != 0)
320 if (mbedtls_aes_crypt_ecb(&ctx->ctx, MBEDTLS_AES_ENCRYPT, ctx->nonce,
321 ctx->encr_buf) != 0)
327 aes_ctr_release(archive_crypto_ctx *ctx)
329 mbedtls_aes_free(&ctx->ctx);
330 memset(ctx, 0, sizeof(*ctx));
337 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
339 ctx->key_len = key_len;
340 memcpy(ctx->key, key, key_len);
341 memset(ctx->nonce, 0, sizeof(ctx->nonce));
342 ctx->encr_pos = AES_BLOCK_SIZE;
343 memset(&ctx->ctx, 0, sizeof(ctx->ctx));
348 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
351 aes_set_encrypt_key(&ctx->ctx, ctx->key_len, ctx->key);
352 aes_encrypt(&ctx->ctx, AES_BLOCK_SIZE, ctx->encr_buf, ctx->nonce);
354 switch(ctx->key_len) {
356 aes128_set_encrypt_key(&ctx->ctx.c128, ctx->key);
357 aes128_encrypt(&ctx->ctx.c128, AES_BLOCK_SIZE, ctx->encr_buf,
358 ctx->nonce);
361 aes192_set_encrypt_key(&ctx->ctx.c192, ctx->key);
362 aes192_encrypt(&ctx->ctx.c192, AES_BLOCK_SIZE, ctx->encr_buf,
363 ctx->nonce);
366 aes256_set_encrypt_key(&ctx->ctx.c256, ctx->key);
367 aes256_encrypt(&ctx->ctx.c256, AES_BLOCK_SIZE, ctx->encr_buf,
368 ctx->nonce);
379 aes_ctr_release(archive_crypto_ctx *ctx)
381 memset(ctx, 0, sizeof(*ctx));
388 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
390 if ((ctx->ctx = EVP_CIPHER_CTX_new()) == NULL)
394 case 16: ctx->type = EVP_aes_128_ecb(); break;
395 case 24: ctx->type = EVP_aes_192_ecb(); break;
396 case 32: ctx->type = EVP_aes_256_ecb(); break;
397 default: ctx->type = NULL; return -1;
400 ctx->key_len = key_len;
401 memcpy(ctx->key, key, key_len);
402 memset(ctx->nonce, 0, sizeof(ctx->nonce));
403 ctx->encr_pos = AES_BLOCK_SIZE;
405 if (!EVP_CIPHER_CTX_reset(ctx->ctx)) {
406 EVP_CIPHER_CTX_free(ctx->ctx);
407 ctx->ctx = NULL;
410 EVP_CIPHER_CTX_init(ctx->ctx);
416 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
421 r = EVP_EncryptInit_ex(ctx->ctx, ctx->type, NULL, ctx->key, NULL);
424 r = EVP_EncryptUpdate(ctx->ctx, ctx->encr_buf, &outl, ctx->nonce,
432 aes_ctr_release(archive_crypto_ctx *ctx)
434 EVP_CIPHER_CTX_free(ctx->ctx);
435 memset(ctx->key, 0, ctx->key_len);
436 memset(ctx->nonce, 0, sizeof(ctx->nonce));
445 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
447 (void)ctx; /* UNUSED */
454 aes_ctr_encrypt_counter(archive_crypto_ctx *ctx)
456 (void)ctx; /* UNUSED */
461 aes_ctr_release(archive_crypto_ctx *ctx)
463 (void)ctx; /* UNUSED */
471 aes_ctr_update(archive_crypto_ctx *ctx, const uint8_t * const in,
474 (void)ctx; /* UNUSED */
479 aes_ctr_encrypt_counter(ctx); /* UNUSED */ /* Fix unused function warning */
485 aes_ctr_increase_counter(archive_crypto_ctx *ctx)
487 uint8_t *const nonce = ctx->nonce;
497 aes_ctr_update(archive_crypto_ctx *ctx, const uint8_t * const in,
500 uint8_t *const ebuf = ctx->encr_buf;
501 unsigned pos = ctx->encr_pos;
507 aes_ctr_increase_counter(ctx);
508 if (aes_ctr_encrypt_counter(ctx) != 0)
514 aes_ctr_increase_counter(ctx);
515 if (aes_ctr_encrypt_counter(ctx) != 0)
525 ctx->encr_pos = pos;