RE: Custom Provider - EVP_CIPHER_fetch fails

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Matt / Hello all,
   Thanks for the support. After some changes, able to do the encryption and decryption.

In test application, fetch is like...
cipher = EVP_CIPHER_fetch(NULL, "ALGO-CUSTOM", NULL);

and the config file looks below (hope this is the expected way):
openssl_conf = openssl_init

[openssl_init]
providers = provider_section
alg_section = evp_properties

[provider_section]
Custom-Prov = Custom-Prov_section
default = default_section

[Custom-Prov_section]
identity = Custom-Prov
module = /userfs/lib/ Custom-Prov.so
activate = 1

[default_section]
activate = 1

However when I want to change the algorithm name to " AES-256-CBC-CTS " (This is the actual implementation), not able to fetch from the custom provider (taking default one). Even I tried to give along with an algo property string in test application and in provider, fetch is failing.

cipher = EVP_CIPHER_fetch(NULL, "AES-256-CBC-CTS", "Custom-Prov=yes");

How can I fetch an cipher algorithm implementation even a default implementation exists ("default" provider may need to co-exist for other operations). Please suggest.

Thank you,
Hareesh

-----Original Message-----
From: Matt Caswell <matt@xxxxxxxxxxx> 
Sent: Tuesday, December 13, 2022 7:49 PM
To: Hareesh Das Ulleri <hareesh.ulleri@xxxxxxx>; openssl-users@xxxxxxxxxxx
Subject: Re: Custom Provider - EVP_CIPHER_fetch fails

[CAUTION]: EXTERNAL EMAIL


On 13/12/2022 09:13, Hareesh Das Ulleri wrote:
> Hello OpenSSL users,
>
>    I am in preparation of a provider (for a custom crypto) by 
> referring OpenSSL 3 design doc

Don't refer to the design doc. It has not been maintained with all the latest tweaks and updates to what was originally envisaged.

> (I use Linux 5.10 + OpenSSL 3.0.7). I believe, the custom provider has 
> all required call backs implemented for the cipher functionalities in 
> its dispatch table.
>

You should refer to the man page for what is required to implement a custom cipher. See:

https://urldefense.com/v3/__https://www.openssl.org/docs/man3.0/man7/provider-cipher.html__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjpEScuW0w$

Note in particular this comment in the man page:

"A cipher algorithm implementation may not implement all of these functions. In order to be a consistent set of functions there must at least be a complete set of "encrypt" functions, or a complete set of "decrypt" functions, or a single "cipher" function. In all cases both the OSSL_FUNC_cipher_newctx and OSSL_FUNC_cipher_freectx functions must be present. All other functions are optional."

So, in other words, you must as a minimum implement OSSL_FUNC_cipher_encrypt_init (or OSSL_FUNC_cipher_decrypt_init), OSSL_FUNC_cipher_update, OSSL_FUNC_cipher_final, OSSL_FUNC_cipher_newctx and OSSL_FUNC_cipher_freectx.

You should probably also read the following pages for general information on writing a provider:

https://urldefense.com/v3/__https://www.openssl.org/docs/man3.0/man7/provider.html__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjr2VgFhFA$
https://urldefense.com/v3/__https://www.openssl.org/docs/man3.0/man7/provider-base.html__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjqmYHiAcQ$

You might also want to refer to Richard Levitte's implementation of the toy Vigenère cipher as a provider here:

https://urldefense.com/v3/__https://github.com/provider-corner/vigenere__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjoTNn-vCA$

>    I have another test application (for encryption and decryption of a 
> text message). At the starting of the app, it calls OSSL_PROVIDER_load 
> and EVP_CIPHER_fetch functions to the custom provider. But 
> unfortunately custom provider fetch function fails…


I suggest calling the OSSL_PROVIDER_available() function to determine whether your custom provider has been successfully loaded:

https://urldefense.com/v3/__https://www.openssl.org/docs/man3.0/man3/OSSL_PROVIDER_available.html__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjqQex0Yvg$

>
> What could be the missing or how to make sure that the custom provider 
> is loaded correctly before calling the fetch function?
>
> cipher = EVP_CIPHER_fetch(NULL, "AES-256-CBC-CTS", NULL);  -> This 
> will work, default provider
>
> cipher = EVP_CIPHER_fetch(NULL, "CUSTOM_ALGO", NULL);  -> returns 
> NULL, custom provider
>
> _Confg file:_
>
> openssl_conf = openssl_init
>
> [openssl_init]
>
> providers = provider_section
>
> [provider_section]
>
> customProv = customProv_section
>
> default = default_sect
>
> [customProv_section]
>
> provider_id = customProv
>
> module_path = /userfs/lib/customProv.so
>
> algorithms = CUSTOM_ALGO
>
> activate = 1
>
> [default_sect]
>
> algorithms = AES-256-CBC-CTS
>
> activate = 1

This config file does not look correct. I guess you based it on some of the examples in the design doc which are out of date.

The man page for config file formats is here:

https://urldefense.com/v3/__https://www.openssl.org/docs/man3.0/man5/config.html__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjooudQYNw$

See the "Provider Configuration" section on that page in particular.

Also worth looking at are some of the test config files used in the OpenSSL code base for loading providers, e.g.

https://urldefense.com/v3/__https://github.com/openssl/openssl/blob/openssl-3.0/test/default-and-legacy.cnf__;!!AYUVhIwY!6U5m1Q3RFPFx8ih3X6UUd7d2rGn85M_2O1G29O1jiYnm8L3aX9Q8HpvSCrZsJGZIRglgUjqOGgUZbA$

Matt


>
> Thank you,
>
> Hareesh
>




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux