20172017 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. Engine Load Lars Thorsén 2017-08-22 engine_load.xml

This chapter describes the support for loading encryption engines in the crypto application.

Background

OpenSSL exposes an Engine API, which makes it possible to plug in alternative implementations for some or all of the cryptographic operations implemented by OpenSSL. When configured appropriately, OpenSSL calls the engine's implementation of these operations instead of its own.

Typically, OpenSSL engines provide a hardware implementation of specific cryptographic operations. The hardware implementation usually offers improved performance over its software-based counterpart, which is known as cryptographic acceleration.

Use Cases
Dynamically load an engine from default directory

If the engine is located in the OpenSSL/LibreSSL installation engines directory.

1> {ok, Engine} = crypto:engine_load(<<"otp_test_engine">>, [], []). {ok, #Ref}

The file name requirement on the engine dynamic library can differ between SSL versions.

Load an engine with the dynamic engine

Load an engine with the help of the dynamic engine by giving the path to the library.

2> {ok, Engine} = crypto:engine_load(<<"dynamic">>, [{<<"SO_PATH">>, <<"/some/path/otp_test_engine.so">>}, {<<"ID">>, <<"MD5">>}, <<"LOAD">>], []). {ok, #Ref}

The dynamic engine is not supported in LibreSSL from version 2.2.1

Load an engine and replace some methods

Load an engine with the help of the dynamic engine and just replace some engine methods.

3> Methods = crypto:engine_get_all_methods() -- [engine_method_dh,engine_method_rand, engine_method_ciphers,engine_method_digests, engine_method_store, engine_method_pkey_meths, engine_method_pkey_asn1_meths]. [engine_method_rsa,engine_method_dsa, engine_method_ecdh,engine_method_ecdsa] 4> {ok, Engine} = crypto:engine_load(<<"dynamic">>, [{<<"SO_PATH">>, <<"/some/path/otp_test_engine.so">>}, {<<"ID">>, <<"MD5">>}, <<"LOAD">>], [], Methods). {ok, #Ref}
List all engines currently loaded 5> crypto:engine_list(). [<<"dynamic">>, <<"MD5">>]