Lines Matching refs:cipher

35     if (ctx->cipher == NULL || ctx->cipher->prov == NULL)
39 if (ctx->cipher->freectx != NULL)
40 ctx->cipher->freectx(ctx->algctx);
53 if (ctx->cipher != NULL) {
54 if (ctx->cipher->cleanup && !ctx->cipher->cleanup(ctx))
56 /* Cleanse cipher context data */
57 if (ctx->cipher_data && ctx->cipher->ctx_size)
58 OPENSSL_cleanse(ctx->cipher_data, ctx->cipher->ctx_size);
83 const EVP_CIPHER *cipher,
108 if (cipher == NULL && ctx->cipher == NULL) {
122 if (ctx->engine && ctx->cipher
123 && (cipher == NULL || cipher->nid == ctx->cipher->nid))
126 if (cipher != NULL && impl == NULL) {
128 tmpimpl = ENGINE_get_cipher_engine(cipher->nid);
140 || (cipher != NULL && cipher->origin == EVP_ORIG_METH)
141 || (cipher == NULL && ctx->cipher != NULL
142 && ctx->cipher->origin == EVP_ORIG_METH)) {
143 if (ctx->cipher == ctx->fetched_cipher)
144 ctx->cipher = NULL;
153 if (cipher != NULL && ctx->cipher != NULL) {
154 if (ctx->cipher->cleanup != NULL && !ctx->cipher->cleanup(ctx))
156 OPENSSL_clear_free(ctx->cipher_data, ctx->cipher->ctx_size);
163 if (cipher != NULL && ctx->cipher != NULL) {
172 if (cipher == NULL)
173 cipher = ctx->cipher;
175 if (cipher->prov == NULL) {
183 cipher->nid == NID_undef ? "NULL"
184 : OBJ_nid2sn(cipher->nid),
189 cipher = provciph;
195 if (cipher->prov != NULL) {
196 if (!EVP_CIPHER_up_ref((EVP_CIPHER *)cipher)) {
201 ctx->fetched_cipher = (EVP_CIPHER *)cipher;
203 ctx->cipher = cipher;
205 ctx->algctx = ctx->cipher->newctx(ossl_provider_ctx(cipher->prov));
215 * the new cipher about it.
258 if (ctx->cipher->einit == NULL) {
263 return ctx->cipher->einit(ctx->algctx,
273 if (ctx->cipher->dinit == NULL) {
278 return ctx->cipher->dinit(ctx->algctx,
290 if (cipher != NULL) {
296 if (ctx->cipher) {
314 const EVP_CIPHER *c = ENGINE_get_cipher(impl, cipher->nid);
325 /* We'll use the ENGINE's private cipher definition */
326 cipher = c;
328 * Store the ENGINE functional reference so we know 'cipher' came
337 ctx->cipher = cipher;
338 if (ctx->cipher->ctx_size) {
339 ctx->cipher_data = OPENSSL_zalloc(ctx->cipher->ctx_size);
341 ctx->cipher = NULL;
348 ctx->key_len = cipher->key_len;
351 if (ctx->cipher->flags & EVP_CIPH_CTRL_INIT) {
353 ctx->cipher = NULL;
362 if (ctx->cipher == NULL)
366 OPENSSL_assert(ctx->cipher->block_size == 1
367 || ctx->cipher->block_size == 8
368 || ctx->cipher->block_size == 16);
419 if (key != NULL || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
420 if (!ctx->cipher->init(ctx, key, iv, enc))
425 ctx->block_mask = ctx->cipher->block_size - 1;
429 int EVP_CipherInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
433 return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, params);
436 int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
439 if (cipher != NULL)
441 return evp_cipher_init_internal(ctx, cipher, NULL, key, iv, enc, NULL);
444 int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
448 return evp_cipher_init_internal(ctx, cipher, impl, key, iv, enc, NULL);
476 int EVP_EncryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
479 return EVP_CipherInit(ctx, cipher, key, iv, 1);
482 int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
486 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1);
489 int EVP_EncryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
493 return EVP_CipherInit_ex2(ctx, cipher, key, iv, 1, params);
496 int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
499 return EVP_CipherInit(ctx, cipher, key, iv, 0);
502 int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
506 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0);
509 int EVP_DecryptInit_ex2(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
513 return EVP_CipherInit_ex2(ctx, cipher, key, iv, 0, params);
562 bl = ctx->cipher->block_size;
564 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
565 /* If block size > 1 then the cipher will have to do this check */
571 i = ctx->cipher->do_cipher(ctx, out, in, inl);
589 if (ctx->cipher->do_cipher(ctx, out, in, inl)) {
622 if (!ctx->cipher->do_cipher(ctx, out, ctx->buf, bl))
632 if (!ctx->cipher->do_cipher(ctx, out, in, inl))
664 if (ctx->cipher == NULL) {
669 if (ctx->cipher->prov == NULL)
672 blocksize = ctx->cipher->block_size;
674 if (ctx->cipher->cupdate == NULL || blocksize < 1) {
679 ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl,
726 if (ctx->cipher == NULL) {
730 if (ctx->cipher->prov == NULL)
735 if (blocksize < 1 || ctx->cipher->cfinal == NULL) {
740 ret = ctx->cipher->cfinal(ctx->algctx, out, &soutl,
756 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
757 ret = ctx->cipher->do_cipher(ctx, out, NULL, 0);
765 b = ctx->cipher->block_size;
784 ret = ctx->cipher->do_cipher(ctx, out, ctx->buf, b);
813 if (ctx->cipher == NULL) {
817 if (ctx->cipher->prov == NULL)
822 if (ctx->cipher->cupdate == NULL || blocksize < 1) {
826 ret = ctx->cipher->cupdate(ctx->algctx, out, &soutl,
843 b = ctx->cipher->block_size;
848 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
854 fix_len = ctx->cipher->do_cipher(ctx, out, in, inl);
947 if (ctx->cipher == NULL) {
952 if (ctx->cipher->prov == NULL)
957 if (blocksize < 1 || ctx->cipher->cfinal == NULL) {
962 ret = ctx->cipher->cfinal(ctx->algctx, out, &soutl,
979 if (ctx->cipher->flags & EVP_CIPH_FLAG_CUSTOM_CIPHER) {
980 i = ctx->cipher->do_cipher(ctx, out, NULL, 0);
988 b = ctx->cipher->block_size;
1019 n = ctx->cipher->block_size - n;
1030 if (c->cipher->prov != NULL) {
1038 /* Check the cipher actually understands this parameter */
1039 if (OSSL_PARAM_locate_const(EVP_CIPHER_settable_ctx_params(c->cipher),
1046 ok = evp_do_ciph_ctx_setparams(c->cipher, c->algctx, params);
1057 if (c->cipher->flags & EVP_CIPH_CUSTOM_KEY_LENGTH)
1061 if ((keylen > 0) && (c->cipher->flags & EVP_CIPH_VARIABLE_LENGTH)) {
1080 if (ctx->cipher != NULL && ctx->cipher->prov == NULL)
1083 ok = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1098 if (ctx == NULL || ctx->cipher == NULL) {
1103 if (ctx->cipher->prov == NULL)
1184 ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1189 ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
1204 ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1211 ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
1226 ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1235 ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
1252 ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1258 ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
1273 ret = evp_do_ciph_ctx_setparams(ctx->cipher, ctx->algctx, params);
1275 ret = evp_do_ciph_ctx_getparams(ctx->cipher, ctx->algctx, params);
1280 if (ctx->cipher->ctrl == NULL) {
1285 ret = ctx->cipher->ctrl(ctx, type, arg, ptr);
1295 int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[])
1297 if (cipher != NULL && cipher->get_params != NULL)
1298 return cipher->get_params(params);
1304 if (ctx->cipher != NULL && ctx->cipher->set_ctx_params != NULL) {
1306 return ctx->cipher->set_ctx_params(ctx->algctx, params);
1313 if (ctx->cipher != NULL && ctx->cipher->get_ctx_params != NULL)
1314 return ctx->cipher->get_ctx_params(ctx->algctx, params);
1318 const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher)
1320 if (cipher != NULL && cipher->gettable_params != NULL)
1321 return cipher->gettable_params(
1322 ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher)));
1326 const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher)
1330 if (cipher != NULL && cipher->settable_ctx_params != NULL) {
1331 provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher));
1332 return cipher->settable_ctx_params(NULL, provctx);
1337 const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher)
1341 if (cipher != NULL && cipher->gettable_ctx_params != NULL) {
1342 provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher));
1343 return cipher->gettable_ctx_params(NULL, provctx);
1352 if (cctx != NULL && cctx->cipher->settable_ctx_params != NULL) {
1353 alg = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher));
1354 return cctx->cipher->settable_ctx_params(cctx->algctx, alg);
1363 if (cctx != NULL && cctx->cipher->gettable_ctx_params != NULL) {
1364 provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher));
1365 return cctx->cipher->gettable_ctx_params(cctx->algctx, provctx);
1373 const EVP_CIPHER *cipher = ctx->cipher;
1376 if (cipher == NULL)
1379 prov = EVP_CIPHER_get0_provider(cipher);
1386 if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
1406 if ((in == NULL) || (in->cipher == NULL)) {
1411 if (in->cipher->prov == NULL)
1414 if (in->cipher->dupctx == NULL) {
1429 out->algctx = in->cipher->dupctx(in->algctx);
1441 /* Make sure it's safe to copy a cipher context using an ENGINE */
1451 if (in->cipher_data && in->cipher->ctx_size) {
1452 out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
1454 out->cipher = NULL;
1458 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
1461 if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY)
1462 if (!in->cipher->ctrl((EVP_CIPHER_CTX *)in, EVP_CTRL_COPY, 0, out)) {
1463 out->cipher = NULL;
1472 EVP_CIPHER *cipher = OPENSSL_zalloc(sizeof(EVP_CIPHER));
1474 if (cipher != NULL) {
1475 cipher->lock = CRYPTO_THREAD_lock_new();
1476 if (cipher->lock == NULL) {
1477 OPENSSL_free(cipher);
1480 cipher->refcnt = 1;
1482 return cipher;
1521 EVP_CIPHER *cipher = NULL;
1524 if ((cipher = evp_cipher_new()) == NULL) {
1530 cipher->nid = NID_undef;
1531 if (!evp_names_do_all(prov, name_id, set_legacy_nid, &cipher->nid)
1532 || cipher->nid == -1) {
1534 EVP_CIPHER_free(cipher);
1539 cipher->name_id = name_id;
1540 if ((cipher->type_name = ossl_algorithm_get1_first_name(algodef)) == NULL) {
1541 EVP_CIPHER_free(cipher);
1544 cipher->description = algodef->algorithm_description;
1549 if (cipher->newctx != NULL)
1551 cipher->newctx = OSSL_FUNC_cipher_newctx(fns);
1555 if (cipher->einit != NULL)
1557 cipher->einit = OSSL_FUNC_cipher_encrypt_init(fns);
1561 if (cipher->dinit != NULL)
1563 cipher->dinit = OSSL_FUNC_cipher_decrypt_init(fns);
1567 if (cipher->cupdate != NULL)
1569 cipher->cupdate = OSSL_FUNC_cipher_update(fns);
1573 if (cipher->cfinal != NULL)
1575 cipher->cfinal = OSSL_FUNC_cipher_final(fns);
1579 if (cipher->ccipher != NULL)
1581 cipher->ccipher = OSSL_FUNC_cipher_cipher(fns);
1584 if (cipher->freectx != NULL)
1586 cipher->freectx = OSSL_FUNC_cipher_freectx(fns);
1590 if (cipher->dupctx != NULL)
1592 cipher->dupctx = OSSL_FUNC_cipher_dupctx(fns);
1595 if (cipher->get_params != NULL)
1597 cipher->get_params = OSSL_FUNC_cipher_get_params(fns);
1600 if (cipher->get_ctx_params != NULL)
1602 cipher->get_ctx_params = OSSL_FUNC_cipher_get_ctx_params(fns);
1605 if (cipher->set_ctx_params != NULL)
1607 cipher->set_ctx_params = OSSL_FUNC_cipher_set_ctx_params(fns);
1610 if (cipher->gettable_params != NULL)
1612 cipher->gettable_params = OSSL_FUNC_cipher_gettable_params(fns);
1615 if (cipher->gettable_ctx_params != NULL)
1617 cipher->gettable_ctx_params =
1621 if (cipher->settable_ctx_params != NULL)
1623 cipher->settable_ctx_params =
1629 || (fnciphcnt == 0 && cipher->ccipher == NULL)
1634 * functions, or a single "cipher" function. In all cases we need both
1637 EVP_CIPHER_free(cipher);
1641 cipher->prov = prov;
1645 if (!evp_cipher_cache_constants(cipher)) {
1646 EVP_CIPHER_free(cipher);
1648 cipher = NULL;
1651 return cipher;
1654 static int evp_cipher_up_ref(void *cipher)
1656 return EVP_CIPHER_up_ref(cipher);
1659 static void evp_cipher_free(void *cipher)
1661 EVP_CIPHER_free(cipher);
1667 EVP_CIPHER *cipher =
1672 return cipher;
1675 int EVP_CIPHER_up_ref(EVP_CIPHER *cipher)
1679 if (cipher->origin == EVP_ORIG_DYNAMIC)
1680 CRYPTO_UP_REF(&cipher->refcnt, &ref, cipher->lock);
1684 void evp_cipher_free_int(EVP_CIPHER *cipher)
1686 OPENSSL_free(cipher->type_name);
1687 ossl_provider_free(cipher->prov);
1688 CRYPTO_THREAD_lock_free(cipher->lock);
1689 OPENSSL_free(cipher);
1692 void EVP_CIPHER_free(EVP_CIPHER *cipher)
1696 if (cipher == NULL || cipher->origin != EVP_ORIG_DYNAMIC)
1699 CRYPTO_DOWN_REF(&cipher->refcnt, &i, cipher->lock);
1702 evp_cipher_free_int(cipher);