Skip to content

Decouple cipher provider logic from EVP_CIPHER* APIs #504

@VladGud

Description

@VladGud

Decouple cipher provider logic from EVP_CIPHER* APIs

Issue Summary

Refactor gost_prov_cipher.c to operate exclusively on internal cipher contexts and descriptors, removing all dependencies on EVP_CIPHER, EVP_CIPHER_CTX, and legacy EVP wrappers. Implement provider-native cipher operations.

Problem Description

The provider cipher implementation wraps ENGINE-based ciphers using EVP_CIPHER_CTX as an intermediate layer, creating unnecessary indirection and dependency on deprecated APIs. This prevents the provider from being truly independent and compatible with OpenSSL builds disabling legacy interfaces.

Current Implementation

  • struct gost_prov_crypt_ctx_st contains EVP_CIPHER *cipher and EVP_CIPHER_CTX *cctx
  • Provider functions like cipher_update, cipher_encrypt_init call EVP_CipherUpdate, EVP_CipherInit_ex
  • Initialization uses GOST_init_cipher() to create EVP wrappers

Required Changes

1. Redefine provider context structure

  • Update struct gost_prov_crypt_ctx_st in gost_prov_cipher.c:
    • Remove EVP_CIPHER *cipher and EVP_CIPHER_CTX *cctx
    • Add void *cipher_data for direct context
    • Add const GOST_cipher *descriptor for method dispatch

2. Implement direct cipher operations

  • Refactor provider functions to call direct cipher methods:
    • cipher_encrypt_init: Call descriptor->init_direct(cipher_data, ...)
    • cipher_update: Call descriptor->do_cipher_direct(cipher_data, ...)
    • cipher_final: Call descriptor->cleanup_direct
    • cipher_get_ctx_params: Extract params directly from cipher_data
    • cipher_set_ctx_params: Set params directly in cipher_data

3. Update context management

  • cipher_newctx: Allocate cipher_data using descriptor->ctx_size; call descriptor->init_direct
  • cipher_freectx: Call descriptor->cleanup_direct(cipher_data); free cipher_data
  • cipher_dupctx: Duplicate cipher_data directly

4. Remove EVP dependencies

  • Eliminate calls to EVP_CIPHER_CTX_new, EVP_CIPHER_CTX_free, EVP_CipherInit_ex, etc.
  • Remove GOST_init_cipher() usage in provider code
  • Handle ASN.1 parameters directly via descriptor->set_asn1_parameters_direct

5. Update cipher dispatch

  • Modify MAKE_FUNCTIONS macro in gost_prov_cipher.c to use direct methods
  • Ensure all OSSL_DISPATCH entries call provider-native functions

Files to Modify

  • gost_prov_cipher.c: Redefine context structure; refactor all functions to use direct cipher methods; remove EVP calls
  • gost_lcl.h: Ensure GOST_cipher structure supports direct dispatch

Acceptance Criteria

  • Provider cipher operations use only internal contexts and descriptors
  • No EVP_CIPHER* or EVP_CIPHER_CTX* calls in gost_prov_cipher.c
  • Provider is independent of ENGINE and EVP wrappers

Testing

  • Provider cipher tests pass without EVP dependencies
  • Encryption/decryption operations work correctly
  • Compatibility with OpenSSL provider API maintained

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions