summaryrefslogtreecommitdiffstats
path: root/crypto/engine
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-01-22 03:29:12 +0000
committerMatt Caswell <matt@openssl.org>2015-01-22 09:31:38 +0000
commitae5c8664e587f2445c8e4eb436cffbb64af4f6b8 (patch)
tree6d5b2cbee6396484f83126f8c7e7a36b9777a652 /crypto/engine
parentaae3233e1e08e9f11742f8f351af5c98cd8add16 (diff)
Run util/openssl-format-source -v -c .
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'crypto/engine')
-rw-r--r--crypto/engine/eng_all.c128
-rw-r--r--crypto/engine/eng_cnf.c331
-rw-r--r--crypto/engine/eng_cryptodev.c2313
-rw-r--r--crypto/engine/eng_ctrl.c620
-rw-r--r--crypto/engine/eng_dyn.c917
-rw-r--r--crypto/engine/eng_err.c206
-rw-r--r--crypto/engine/eng_fat.c175
-rw-r--r--crypto/engine/eng_init.c171
-rw-r--r--crypto/engine/eng_int.h220
-rw-r--r--crypto/engine/eng_lib.c427
-rw-r--r--crypto/engine/eng_list.c618
-rw-r--r--crypto/engine/eng_openssl.c491
-rw-r--r--crypto/engine/eng_pkey.c226
-rw-r--r--crypto/engine/eng_rdrand.c142
-rw-r--r--crypto/engine/eng_rsax.c863
-rw-r--r--crypto/engine/eng_table.c475
-rw-r--r--crypto/engine/engine.h1154
-rw-r--r--crypto/engine/enginetest.c406
-rw-r--r--crypto/engine/tb_asnmth.c302
-rw-r--r--crypto/engine/tb_cipher.c124
-rw-r--r--crypto/engine/tb_dh.c84
-rw-r--r--crypto/engine/tb_digest.c124
-rw-r--r--crypto/engine/tb_dsa.c84
-rw-r--r--crypto/engine/tb_ecdh.c84
-rw-r--r--crypto/engine/tb_ecdsa.c84
-rw-r--r--crypto/engine/tb_pkmeth.c161
-rw-r--r--crypto/engine/tb_rand.c84
-rw-r--r--crypto/engine/tb_rsa.c84
-rw-r--r--crypto/engine/tb_store.c84
29 files changed, 5710 insertions, 5472 deletions
diff --git a/crypto/engine/eng_all.c b/crypto/engine/eng_all.c
index 37ddcf9e12..195a3a9554 100644
--- a/crypto/engine/eng_all.c
+++ b/crypto/engine/eng_all.c
@@ -1,6 +1,7 @@
/* crypto/engine/eng_all.c -*- mode: C; c-file-style: "eay" -*- */
-/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
- * project 2000.
+/*
+ * Written by Richard Levitte <richard@levitte.org> for the OpenSSL project
+ * 2000.
*/
/* ====================================================================
* Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
@@ -10,7 +11,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -60,73 +61,76 @@
#include "eng_int.h"
void ENGINE_load_builtin_engines(void)
- {
- /* Some ENGINEs need this */
- OPENSSL_cpuid_setup();
+{
+ /* Some ENGINEs need this */
+ OPENSSL_cpuid_setup();
#if 0
- /* There's no longer any need for an "openssl" ENGINE unless, one day,
- * it is the *only* way for standard builtin implementations to be be
- * accessed (ie. it would be possible to statically link binaries with
- * *no* builtin implementations). */
- ENGINE_load_openssl();
+ /*
+ * There's no longer any need for an "openssl" ENGINE unless, one day, it
+ * is the *only* way for standard builtin implementations to be be
+ * accessed (ie. it would be possible to statically link binaries with
+ * *no* builtin implementations).
+ */
+ ENGINE_load_openssl();
#endif
#if !defined(OPENSSL_NO_HW) && (defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV))
- ENGINE_load_cryptodev();
+ ENGINE_load_cryptodev();
#endif
#ifndef OPENSSL_NO_RDRAND
- ENGINE_load_rdrand();
+ ENGINE_load_rdrand();
#endif
- ENGINE_load_dynamic();
+ ENGINE_load_dynamic();
#ifndef OPENSSL_NO_STATIC_ENGINE
-#ifndef OPENSSL_NO_HW
-#ifndef OPENSSL_NO_HW_4758_CCA
- ENGINE_load_4758cca();
-#endif
-#ifndef OPENSSL_NO_HW_AEP
- ENGINE_load_aep();
-#endif
-#ifndef OPENSSL_NO_HW_ATALLA
- ENGINE_load_atalla();
-#endif
-#ifndef OPENSSL_NO_HW_CSWIFT
- ENGINE_load_cswift();
-#endif
-#ifndef OPENSSL_NO_HW_NCIPHER
- ENGINE_load_chil();
-#endif
-#ifndef OPENSSL_NO_HW_NURON
- ENGINE_load_nuron();
-#endif
-#ifndef OPENSSL_NO_HW_SUREWARE
- ENGINE_load_sureware();
-#endif
-#ifndef OPENSSL_NO_HW_UBSEC
- ENGINE_load_ubsec();
-#endif
-#ifndef OPENSSL_NO_HW_PADLOCK
- ENGINE_load_padlock();
-#endif
-#endif
-#ifndef OPENSSL_NO_GOST
- ENGINE_load_gost();
-#endif
-#ifndef OPENSSL_NO_GMP
- ENGINE_load_gmp();
-#endif
-#if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
- ENGINE_load_capi();
-#endif
-#endif
- ENGINE_register_all_complete();
- }
+# ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_4758_CCA
+ ENGINE_load_4758cca();
+# endif
+# ifndef OPENSSL_NO_HW_AEP
+ ENGINE_load_aep();
+# endif
+# ifndef OPENSSL_NO_HW_ATALLA
+ ENGINE_load_atalla();
+# endif
+# ifndef OPENSSL_NO_HW_CSWIFT
+ ENGINE_load_cswift();
+# endif
+# ifndef OPENSSL_NO_HW_NCIPHER
+ ENGINE_load_chil();
+# endif
+# ifndef OPENSSL_NO_HW_NURON
+ ENGINE_load_nuron();
+# endif
+# ifndef OPENSSL_NO_HW_SUREWARE
+ ENGINE_load_sureware();
+# endif
+# ifndef OPENSSL_NO_HW_UBSEC
+ ENGINE_load_ubsec();
+# endif
+# ifndef OPENSSL_NO_HW_PADLOCK
+ ENGINE_load_padlock();
+# endif
+# endif
+# ifndef OPENSSL_NO_GOST
+ ENGINE_load_gost();
+# endif
+# ifndef OPENSSL_NO_GMP
+ ENGINE_load_gmp();
+# endif
+# if defined(OPENSSL_SYS_WIN32) && !defined(OPENSSL_NO_CAPIENG)
+ ENGINE_load_capi();
+# endif
+#endif
+ ENGINE_register_all_complete();
+}
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(HAVE_CRYPTODEV)
-void ENGINE_setup_bsd_cryptodev(void) {
- static int bsd_cryptodev_default_loaded = 0;
- if (!bsd_cryptodev_default_loaded) {
- ENGINE_load_cryptodev();
- ENGINE_register_all_complete();
- }
- bsd_cryptodev_default_loaded=1;
+void ENGINE_setup_bsd_cryptodev(void)
+{
+ static int bsd_cryptodev_default_loaded = 0;
+ if (!bsd_cryptodev_default_loaded) {
+ ENGINE_load_cryptodev();
+ ENGINE_register_all_complete();
+ }
+ bsd_cryptodev_default_loaded = 1;
}
#endif
diff --git a/crypto/engine/eng_cnf.c b/crypto/engine/eng_cnf.c
index 95c4070015..f09bec4e9a 100644
--- a/crypto/engine/eng_cnf.c
+++ b/crypto/engine/eng_cnf.c
@@ -1,6 +1,7 @@
/* eng_cnf.c */
-/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
- * project 2001.
+/*
+ * Written by Stephen Henson (steve@openssl.org) for the OpenSSL project
+ * 2001.
*/
/* ====================================================================
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
@@ -10,7 +11,7 @@
* are met:
*
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
+ * notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
@@ -64,196 +65,178 @@
/* ENGINE config module */
static char *skip_dot(char *name)
- {
- char *p;
- p = strchr(name, '.');
- if (p)
- return p + 1;
- return name;
- }
+{
+ char *p;
+ p = strchr(name, '.');
+ if (p)
+ return p + 1;
+ return name;
+}
static STACK_OF(ENGINE) *initialized_engines = NULL;
static int int_engine_init(ENGINE *e)
- {
- if (!ENGINE_init(e))
- return 0;
- if (!initialized_engines)
- initialized_engines = sk_ENGINE_new_null();
- if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e))
- {
- ENGINE_finish(e);
- return 0;
- }
- return 1;
- }
-
+{
+ if (!ENGINE_init(e))
+ return 0;
+ if (!initialized_engines)
+ initialized_engines = sk_ENGINE_new_null();
+ if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) {
+ ENGINE_finish(e);
+ return 0;
+ }
+ return 1;
+}
static int int_engine_configure(char *name, char *value, const CONF *cnf)
- {
- int i;
- int ret = 0;
- long do_init = -1;
- STACK_OF(CONF_VALUE) *ecmds;
- CONF_VALUE *ecmd = NULL;
- char *ctrlname, *ctrlvalue;
- ENGINE *e = NULL;
- int soft = 0;
-
- name = skip_dot(name);
+{
+ int i;
+ int ret = 0;
+ long do_init = -1;
+ STACK_OF(CONF_VALUE) *ecmds;
+ CONF_VALUE *ecmd = NULL;
+ char *ctrlname, *ctrlvalue;
+ ENGINE *e = NULL;
+ int soft = 0;
+
+ name = skip_dot(name);
#ifdef ENGINE_CONF_DEBUG
- fprintf(stderr, "Configuring engine %s\n", name);
+ fprintf(stderr, "Configuring engine %s\n", name);
#endif
- /* Value is a section containing ENGINE commands */
- ecmds = NCONF_get_section(cnf, value);
-
- if (!ecmds)
- {
- ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
- return 0;
- }
-
- for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
- {
- ecmd = sk_CONF_VALUE_value(ecmds, i);
- ctrlname = skip_dot(ecmd->name);
- ctrlvalue = ecmd->value;
+ /* Value is a section containing ENGINE commands */
+ ecmds = NCONF_get_section(cnf, value);
+
+ if (!ecmds) {
+ ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE,
+ ENGINE_R_ENGINE_SECTION_ERROR);
+ return 0;
+ }
+
+ for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) {
+ ecmd = sk_CONF_VALUE_value(ecmds, i);
+ ctrlname = skip_dot(ecmd->name);
+ ctrlvalue = ecmd->value;
#ifdef ENGINE_CONF_DEBUG
- fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
+ fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname,
+ ctrlvalue);
#endif
- /* First handle some special pseudo ctrls */
-
- /* Override engine name to use */
- if (!strcmp(ctrlname, "engine_id"))
- name = ctrlvalue;
- else if (!strcmp(ctrlname, "soft_load"))
- soft = 1;
- /* Load a dynamic ENGINE */
- else if (!strcmp(ctrlname, "dynamic_path"))
- {
- e = ENGINE_by_id("dynamic");
- if (!e)
- goto err;
- if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
- goto err;
- if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
- goto err;
- if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
- goto err;
- }
- /* ... add other pseudos here ... */
- else
- {
- /* At this point we need an ENGINE structural reference
- * if we don't already have one.
- */
- if (!e)
- {
- e = ENGINE_by_id(name);
- if (!e && soft)
- {
- ERR_clear_error();
- return 1;
- }
- if (!e)
- goto err;
- }
- /* Allow "EMPTY" to mean no value: this allows a valid
- * "value" to be passed to ctrls of type NO_INPUT
- */
- if (!strcmp(ctrlvalue, "EMPTY"))
- ctrlvalue = NULL;
- if (!strcmp(ctrlname, "init"))
- {
- if (!NCONF_get_number_e(cnf, value, "init", &do_init))
- goto err;
- if (do_init == 1)
- {
- if (!int_engine_init(e))
- goto err;
- }
- else if (do_init != 0)
- {
- ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
- goto err;
- }
- }
- else if (!strcmp(ctrlname, "default_algorithms"))
- {
- if (!ENGINE_set_default_string(e, ctrlvalue))
- goto err;
- }
- else if (!ENGINE_ctrl_cmd_string(e,
- ctrlname, ctrlvalue, 0))
- goto err;
- }
-
-
-
- }
- if (e && (do_init == -1) && !int_engine_init(e))
- {
- ecmd = NULL;
- goto err;
- }
- ret = 1;
- err:
- if (ret != 1)
- {
- ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_CONFIGURATION_ERROR);
- if (ecmd)
- ERR_add_error_data(6, "section=", ecmd->section,
- ", name=", ecmd->name,
- ", value=", ecmd->value);
- }
- if (e)
- ENGINE_free(e);
- return ret;
- }
-
+ /* First handle some special pseudo ctrls */
+
+ /* Override engine name to use */
+ if (!strcmp(ctrlname, "engine_id"))
+ name = ctrlvalue;
+ else if (!strcmp(ctrlname, "soft_load"))
+ soft = 1;
+ /* Load a dynamic ENGINE */
+ else if (!strcmp(ctrlname, "dynamic_path")) {
+ e = ENGINE_by_id("dynamic");
+ if (!e)
+ goto err;
+ if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
+ goto err;
+ if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
+ goto err;
+ if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
+ goto err;
+ }
+ /* ... add other pseudos here ... */
+ else {
+ /*
+ * At this point we need an ENGINE structural reference if we
+ * don't already have one.
+ */
+ if (!e) {
+ e = ENGINE_by_id(name);
+ if (!e && soft) {
+ ERR_clear_error();
+ return 1;
+ }
+ if (!e)
+ goto err;
+ }
+ /*
+ * Allow "EMPTY" to mean no value: this allows a valid "value" to
+ * be passed to ctrls of type NO_INPUT
+ */
+ if (!strcmp(ctrlvalue, "EMPTY"))
+ ctrlvalue = NULL;
+ if (!strcmp(ctrlname, "init")) {
+ if (!NCONF_get_number_e(cnf, value, "init", &do_init))
+ goto err;
+ if (do_init == 1) {
+ if (!int_engine_init(e))
+ goto err;
+ } else if (do_init != 0) {
+ ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE,
+ ENGINE_R_INVALID_INIT_VALUE);
+ goto err;
+ }
+ } else if (!strcmp(ctrlname, "default_algorithms")) {
+ if (!ENGINE_set_default_string(e, ctrlvalue))
+ goto err;
+ } else if (!ENGINE_ctrl_cmd_string(e, ctrlname, ctrlvalue, 0))
+ goto err;
+ }
+
+ }
+ if (e && (do_init == -1) && !int_engine_init(e)) {
+ ecmd = NULL;
+ goto err;
+ }
+ ret = 1;
+ err:
+ if (ret != 1) {
+ ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE,
+ ENGINE_R_ENGINE_CONFIGURATION_ERROR);
+ if (ecmd)
+ ERR_add_error_data(6, "section=", ecmd->section,
+ ", name=", ecmd->name,
+ ", value=", ecmd->value);
+ }
+ if (e)
+ ENGINE_free(e);
+ return ret;
+}
static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
- {
- STACK_OF(CONF_VALUE) *elist;
- CONF_VALUE *cval;
- int i;
+{
+ STACK_OF(CONF_VALUE) *elist;
+ CONF_VALUE *cval;
+ int i;
#ifdef ENGINE_CONF_DEBUG
- fprintf(stderr, "Called engine module: name %s, value %s\n",
- CONF_imodule_get_name(md), CONF_imodule_get_value(md));
+ fprintf(stderr, "Called engine module: name %s, value %s\n",
+ CONF_imodule_get_name(md), CONF_imodule_get_value(md));
#endif
- /* Value is a section containing ENGINEs to configure */
- elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
+ /* Value is a section containing ENGINEs to configure */
+ elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
- if (!elist)
- {
- ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
- return 0;
- }
+ if (!elist) {
+ ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT,
+ ENGINE_R_ENGINES_SECTION_ERROR);
+ return 0;
+ }
- for (i = 0; i < sk_CONF_VALUE_num(elist); i++)
- {
- cval = sk_CONF_VALUE_value(elist, i);
- if (!int_engine_configure(cval->name, cval->value, cnf))
- return 0;
- }
+ for (i = 0; i < sk_CONF_VALUE_num(elist); i++) {
+ cval = sk_CONF_VALUE_value(elist, i);
+ if (!int_engine_configure(cval->name, cval->value, cnf))
+ return 0;
+ }
- return 1;
- }
+ return 1;
+}
static void int_engine_module_finish(CONF_IMODULE *md)
- {
- ENGINE *e;
- while ((e = sk_ENGINE_pop(initialized_engines)))
- ENGINE_finish(e);
- sk_ENGINE_free(initialized_engines);
- initialized_engines = NULL;
- }
-
+{
+ ENGINE *e;
+ while ((e = sk_ENGINE_pop(initialized_engines)))
+ ENGINE_finish(e);
+ sk_ENGINE_free(initialized_engines);
+ initialized_engines = NULL;
+}
void ENGINE_add_conf_module(void)
- {
- CONF_module_add("engines",
- int_engine_module_init,
- int_engine_module_finish);
- }
+{
+ CONF_module_add("engines",
+ int_engine_module_init, int_engine_module_finish);
+}
diff --git a/crypto/engine/eng_cryptodev.c b/crypto/engine/eng_cryptodev.c
index 568e131615..926d95c0d7 100644
--- a/crypto/engine/eng_cryptodev.c
+++ b/crypto/engine/eng_cryptodev.c
@@ -32,8 +32,8 @@
#include <openssl/bn.h>
#if (defined(__unix__) || defined(unix)) && !defined(USG) && \
- (defined(OpenBSD) || defined(__FreeBSD__))
-#include <sys/param.h>
+ (defined(OpenBSD) || defined(__FreeBSD__))
+# include <sys/param.h>
# if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041)
# define HAVE_CRYPTODEV
# endif
@@ -44,42 +44,39 @@
#ifndef HAVE_CRYPTODEV
-void
-ENGINE_load_cryptodev(void)
+void ENGINE_load_cryptodev(void)
{
- /* This is a NOP on platforms without /dev/crypto */
- return;
+ /* This is a NOP on platforms without /dev/crypto */
+ return;
}
-#else
-
-#include <sys/types.h>
-#include <crypto/cryptodev.h>
-#include <openssl/dh.h>
-#include <openssl/dsa.h>
-#include <openssl/err.h>
-#include <openssl/rsa.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <syslog.h>
-#include <errno.h>
-#include <string.h>
-
-struct dev_crypto_state {
- struct session_op d_sess;
- int d_fd;
+#else
-#ifdef USE_CRYPTODEV_DIGESTS
- char dummy_mac_key[HASH_MAX_LEN];
+# include <sys/types.h>
+# include <crypto/cryptodev.h>
+# include <openssl/dh.h>
+# include <openssl/dsa.h>
+# include <openssl/err.h>
+# include <openssl/rsa.h>
+# include <sys/ioctl.h>
+# include <errno.h>
+# include <stdio.h>
+# include <unistd.h>
+# include <fcntl.h>
+# include <stdarg.h>
+# include <syslog.h>
+# include <errno.h>
+# include <string.h>
- unsigned char digest_res[HASH_MAX_LEN];
- char *mac_data;
- int mac_len;
-#endif
+struct dev_crypto_state {
+ struct session_op d_sess;
+ int d_fd;
+# ifdef USE_CRYPTODEV_DIGESTS
+ char dummy_mac_key[HASH_MAX_LEN];
+ unsigned char digest_res[HASH_MAX_LEN];
+ char *mac_data;
+ int mac_len;
+# endif
};
static u_int32_t cryptodev_asymfeat = 0;
@@ -88,152 +85,196 @@ static int get_asym_dev_crypto(void);
static int open_dev_crypto(void);
static int get_dev_crypto(void);
static int get_cryptodev_ciphers(const int **cnids);
-#ifdef USE_CRYPTODEV_DIGESTS
+# ifdef USE_CRYPTODEV_DIGESTS
static int get_cryptodev_digests(const int **cnids);
-#endif
+# endif
static int cryptodev_usable_ciphers(const int **nids);
static int cryptodev_usable_digests(const int **nids);
static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
- const unsigned char *in, size_t inl);
+ const unsigned char *in, size_t inl);
static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
- const unsigned char *iv, int enc);
+ const unsigned char *iv, int enc);
static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx);
static int cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
- const int **nids, int nid);
+ const int **nids, int nid);
static int cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
- const int **nids, int nid);
+ const int **nids, int nid);
static int bn2crparam(const BIGNUM *a, struct crparam *crp);
static int crparam2bn(struct crparam *crp, BIGNUM *a);
static void zapparams(struct crypt_kop *kop);
static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r,
- int slen, BIGNUM *s);
+ int slen, BIGNUM *s);
static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
- const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
-static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I,
- RSA *rsa, BN_CTX *ctx);
-static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
+ const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
+ BN_MONT_CTX *m_ctx);
+static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
+ BN_CTX *ctx);
+static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
+ BN_CTX *ctx);
static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
- const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
+ const BIGNUM *p, const BIGNUM *m,
+ BN_CTX *ctx, BN_MONT_CTX *m_ctx);
static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g,
- BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p,
- BN_CTX *ctx, BN_MONT_CTX *mont);
-static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst,
- int dlen, DSA *dsa);
+ BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2,
+ BIGNUM *p, BN_CTX *ctx,
+ BN_MONT_CTX *mont);
+static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen,
+ DSA *dsa);
static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len,
- DSA_SIG *sig, DSA *dsa);
+ DSA_SIG *sig, DSA *dsa);
static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
- const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
- BN_MONT_CTX *m_ctx);
-static int cryptodev_dh_compute_key(unsigned char *key,
- const BIGNUM *pub_key, DH *dh);
+ const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
+ BN_MONT_CTX *m_ctx);
+static int cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key,
+ DH *dh);
static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p,
- void (*f)(void));
+ void (*f) (void));
void ENGINE_load_cryptodev(void);
static const ENGINE_CMD_DEFN cryptodev_defns[] = {
- { 0, NULL, NULL, 0 }
+ {0, NULL, NULL, 0}
};
static struct {
- int id;
- int nid;
- int ivmax;
- int keylen;
+ int id;
+ int nid;
+ int ivmax;
+ int keylen;
} ciphers[] = {
- { CRYPTO_ARC4, NID_rc4, 0, 16, },
- { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
- { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
- { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, },
- { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, },
- { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, },
-#ifdef CRYPTO_AES_CTR
- { CRYPTO_AES_CTR, NID_aes_128_ctr, 14, 16, },
- { CRYPTO_AES_CTR, NID_aes_192_ctr, 14, 24, },
- { CRYPTO_AES_CTR, NID_aes_256_ctr, 14, 32, },
-#endif
- { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
- { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, },
- { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
- { 0, NID_undef, 0, 0, },
+ {
+ CRYPTO_ARC4, NID_rc4, 0, 16,
+ },
+ {
+ CRYPTO_DES_CBC, NID_des_cbc, 8, 8,
+ },
+ {
+ CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24,
+ },
+ {
+ CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16,
+ },
+ {
+ CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24,
+ },
+ {
+ CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32,
+ },
+# ifdef CRYPTO_AES_CTR
+ {
+ CRYPTO_AES_CTR, NID_aes_128_ctr, 14, 16,
+ },
+ {
+ CRYPTO_AES_CTR, NID_aes_192_ctr, 14, 24,
+ },
+ {
+ CRYPTO_AES_CTR, NID_aes_256_ctr, 14, 32,
+ },
+# endif
+ {
+ CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16,
+ },
+ {
+ CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16,
+ },
+ {
+ CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0,
+ },
+ {
+ 0, NID_undef, 0, 0,
+ },
};
-#ifdef USE_CRYPTODEV_DIGESTS
+# ifdef USE_CRYPTODEV_DIGESTS
static struct {
- int id;
- int nid;
- int keylen;
+ int id;
+ int nid;
+ int keylen;
} digests[] = {
- { CRYPTO_MD5_HMAC, NID_hmacWithMD5, 16},
- { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, 20},
- { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, 16/*?*/},
- { CRYPTO_MD5_KPDK, NID_undef, 0},
- { CRYPTO_SHA1_KPDK, NID_undef, 0},
- { CRYPTO_MD5, NID_md5, 16},
- { CRYPTO_SHA1, NID_sha1, 20},
- { 0, NID_undef, 0},
+ {
+ CRYPTO_MD5_HMAC, NID_hmacWithMD5, 16
+ },
+ {
+ CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, 20
+ },
+ {
+ CRYPTO_RIPEMD160_HMAC, NID_ripemd160, 16
+ /* ? */
+ },
+ {
+ CRYPTO_MD5_KPDK, NID_undef, 0
+ },
+ {
+ CRYPTO_SHA1_KPDK, NID_undef, 0
+ },
+ {
+ CRYPTO_MD5, NID_md5, 16
+ },
+ {
+ CRYPTO_SHA1, NID_sha1, 20
+ },
+ {
+ 0, NID_undef, 0
+ },
};
-#endif
+# endif
/*
* Return a fd if /dev/crypto seems usable, 0 otherwise.
*/
-static int
-open_dev_crypto(void)
+static int open_dev_crypto(void)
{
- static int fd = -1;
-
- if (fd == -1) {
- if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
- return (-1);
- /* close on exec */
- if (fcntl(fd, F_SETFD, 1) == -1) {
- close(fd);
- fd = -1;
- return (-1);
- }
- }
- return (fd);
+ static int fd = -1;
+
+ if (fd == -1) {
+ if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
+ return (-1);
+ /* close on exec */
+ if (fcntl(fd, F_SETFD, 1) == -1) {
+ close(fd);
+ fd = -1;
+ return (-1);
+ }
+ }
+ return (fd);
}
-static int
-get_dev_crypto(void)
+static int get_dev_crypto(void)
{
- int fd, retfd;
-
- if ((fd = open_dev_crypto()) == -1)
- return (-1);
-#ifndef CRIOGET_NOT_NEEDED
- if (ioctl(fd, CRIOGET, &retfd) == -1)
- return (-1);
-
- /* close on exec */
- if (fcntl(retfd, F_SETFD, 1) == -1) {
- close(retfd);
- return (-1);
- }
-#else
- retfd = fd;
-#endif
- return (retfd);
+ int fd, retfd;
+
+ if ((fd = open_dev_crypto()) == -1)
+ return (-1);
+# ifndef CRIOGET_NOT_NEEDED
+ if (ioctl(fd, CRIOGET, &retfd) == -1)
+ return (-1);
+
+ /* close on exec */
+ if (fcntl(retfd, F_SETFD, 1) == -1) {
+ close(retfd);
+ return (-1);
+ }
+# else
+ retfd = fd;
+# endif
+ return (retfd);
}
static void put_dev_crypto(int fd)
{
-#ifndef CRIOGET_NOT_NEEDED
- close(fd);
-#endif
+# ifndef CRIOGET_NOT_NEEDED
+ close(fd);
+# endif
}
/* Caching version for asym operations */
-static int
-get_asym_dev_crypto(void)
+static int get_asym_dev_crypto(void)
{
- static int fd = -1;
+ static int fd = -1;
- if (fd == -1)
- fd = get_dev_crypto();
-