diff options
| author | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:30:35 +0000 |
|---|---|---|
| committer | Enji Cooper <ngie@FreeBSD.org> | 2026-01-29 01:30:35 +0000 |
| commit | 677808048e318ef0c4ad69c0c2cc8d82167bffbe (patch) | |
| tree | bef7f1ad0365b42b56b6b8082996024b8483b96b /engines | |
| parent | 12b8f7324509729dbf5c06c0e8fbc4723d3eefb3 (diff) | |
Diffstat (limited to 'engines')
| -rw-r--r-- | engines/e_afalg.c | 256 | ||||
| -rw-r--r-- | engines/e_afalg.h | 71 | ||||
| -rw-r--r-- | engines/e_afalg_err.c | 34 | ||||
| -rw-r--r-- | engines/e_afalg_err.h | 36 | ||||
| -rw-r--r-- | engines/e_capi.c | 640 | ||||
| -rw-r--r-- | engines/e_capi_err.c | 80 | ||||
| -rw-r--r-- | engines/e_capi_err.h | 72 | ||||
| -rw-r--r-- | engines/e_dasync.c | 436 | ||||
| -rw-r--r-- | engines/e_dasync_err.c | 4 | ||||
| -rw-r--r-- | engines/e_dasync_err.h | 14 | ||||
| -rw-r--r-- | engines/e_devcrypto.c | 317 | ||||
| -rw-r--r-- | engines/e_loader_attic.c | 503 | ||||
| -rw-r--r-- | engines/e_loader_attic_err.c | 38 | ||||
| -rw-r--r-- | engines/e_loader_attic_err.h | 34 | ||||
| -rw-r--r-- | engines/e_ossltest.c | 248 | ||||
| -rw-r--r-- | engines/e_ossltest_err.c | 4 | ||||
| -rw-r--r-- | engines/e_ossltest_err.h | 14 | ||||
| -rw-r--r-- | engines/e_padlock.c | 315 |
18 files changed, 1515 insertions, 1601 deletions
diff --git a/engines/e_afalg.c b/engines/e_afalg.c index 58d58ef24ec4..ce6684f7b0f2 100644 --- a/engines/e_afalg.c +++ b/engines/e_afalg.c @@ -12,7 +12,7 @@ /* Required for vmsplice */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE +#define _GNU_SOURCE #endif #include <stdio.h> #include <string.h> @@ -25,68 +25,69 @@ #include <sys/socket.h> #include <linux/version.h> -#define K_MAJ 4 -#define K_MIN1 1 -#define K_MIN2 0 -#if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2) || \ - !defined(AF_ALG) -# ifndef PEDANTIC -# warning "AFALG ENGINE requires Kernel Headers >= 4.1.0" -# warning "Skipping Compilation of AFALG engine" -# endif +#define K_MAJ 4 +#define K_MIN1 1 +#define K_MIN2 0 +#if LINUX_VERSION_CODE < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2) || !defined(AF_ALG) +#ifndef PEDANTIC +#warning "AFALG ENGINE requires Kernel Headers >= 4.1.0" +#warning "Skipping Compilation of AFALG engine" +#endif void engine_load_afalg_int(void); void engine_load_afalg_int(void) { } #else -# include <linux/if_alg.h> -# include <fcntl.h> -# include <sys/utsname.h> +#include <linux/if_alg.h> +#include <fcntl.h> +#include <sys/utsname.h> -# include <linux/aio_abi.h> -# include <sys/syscall.h> -# include <errno.h> +#include <linux/aio_abi.h> +#include <sys/syscall.h> +#include <errno.h> +/* clang-format off */ # include "e_afalg.h" # include "e_afalg_err.c" +/* clang-format on */ -# ifndef SOL_ALG -# define SOL_ALG 279 -# endif +#ifndef SOL_ALG +#define SOL_ALG 279 +#endif -# ifdef ALG_ZERO_COPY -# ifndef SPLICE_F_GIFT -# define SPLICE_F_GIFT (0x08) -# endif -# endif +#ifdef ALG_ZERO_COPY +#ifndef SPLICE_F_GIFT +#define SPLICE_F_GIFT (0x08) +#endif +#endif -# define ALG_AES_IV_LEN 16 -# define ALG_IV_LEN(len) (sizeof(struct af_alg_iv) + (len)) -# define ALG_OP_TYPE unsigned int -# define ALG_OP_LEN (sizeof(ALG_OP_TYPE)) +#define ALG_AES_IV_LEN 16 +#define ALG_IV_LEN(len) (sizeof(struct af_alg_iv) + (len)) +#define ALG_OP_TYPE unsigned int +#define ALG_OP_LEN (sizeof(ALG_OP_TYPE)) -# ifdef OPENSSL_NO_DYNAMIC_ENGINE +#ifdef OPENSSL_NO_DYNAMIC_ENGINE void engine_load_afalg_int(void); -# endif +#endif /* Local Linkage Functions */ static int afalg_init_aio(afalg_aio *aio); static int afalg_fin_cipher_aio(afalg_aio *ptr, int sfd, - unsigned char *buf, size_t len); + unsigned char *buf, size_t len); static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, - const char *ciphername); + const char *ciphername); static int afalg_destroy(ENGINE *e); static int afalg_init(ENGINE *e); static int afalg_finish(ENGINE *e); static const EVP_CIPHER *afalg_aes_cbc(int nid); static cbc_handles *get_cipher_handle(int nid); static int afalg_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid); + const int **nids, int nid); static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *iv, int enc); static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); + const unsigned char *in, size_t inl); static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx); static int afalg_chk_platform(void); @@ -100,9 +101,9 @@ static int afalg_cipher_nids[] = { NID_aes_256_cbc, }; -static cbc_handles cbc_handle[] = {{AES_KEY_SIZE_128, NULL}, - {AES_KEY_SIZE_192, NULL}, - {AES_KEY_SIZE_256, NULL}}; +static cbc_handles cbc_handle[] = { { AES_KEY_SIZE_128, NULL }, + { AES_KEY_SIZE_192, NULL }, + { AES_KEY_SIZE_256, NULL } }; static ossl_inline int io_setup(unsigned n, aio_context_t *ctx) { @@ -125,21 +126,20 @@ static ossl_inline int io_read(aio_context_t ctx, long n, struct iocb **iocb) } /* A version of 'struct timespec' with 32-bit time_t and nanoseconds. */ -struct __timespec32 -{ - __kernel_long_t tv_sec; - __kernel_long_t tv_nsec; +struct __timespec32 { + __kernel_long_t tv_sec; + __kernel_long_t tv_nsec; }; static ossl_inline int io_getevents(aio_context_t ctx, long min, long max, - struct io_event *events, - struct timespec *timeout) + struct io_event *events, + struct timespec *timeout) { #if defined(__NR_io_pgetevents_time64) /* Check if we are a 32-bit architecture with a 64-bit time_t */ if (sizeof(*timeout) != sizeof(struct __timespec32)) { int ret = syscall(__NR_io_pgetevents_time64, ctx, min, max, events, - timeout, NULL); + timeout, NULL); if (ret == 0 || errno != ENOSYS) return ret; } @@ -162,8 +162,8 @@ static ossl_inline int io_getevents(aio_context_t ctx, long min, long max, if (timeout && timeout->tv_sec == (long)timeout->tv_sec) { struct __timespec32 ts32; - ts32.tv_sec = (__kernel_long_t) timeout->tv_sec; - ts32.tv_nsec = (__kernel_long_t) timeout->tv_nsec; + ts32.tv_sec = (__kernel_long_t)timeout->tv_sec; + ts32.tv_nsec = (__kernel_long_t)timeout->tv_nsec; return syscall(__NR_io_getevents, ctx, min, max, events, &ts32); } else { @@ -177,7 +177,7 @@ static ossl_inline int io_getevents(aio_context_t ctx, long min, long max, } static void afalg_waitfd_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, - OSSL_ASYNC_FD waitfd, void *custom) + OSSL_ASYNC_FD waitfd, void *custom) { close(waitfd); } @@ -198,7 +198,7 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) } /* Get waitfd from ASYNC_WAIT_CTX if it is already set */ ret = ASYNC_WAIT_CTX_get_fd(waitctx, engine_afalg_id, - &aio->efd, &custom); + &aio->efd, &custom); if (ret == 0) { /* * waitfd is not set in ASYNC_WAIT_CTX, create a new one @@ -207,14 +207,14 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) aio->efd = eventfd(0); if (aio->efd == -1) { ALG_PERR("%s(%d): Failed to get eventfd : ", __FILE__, - __LINE__); + __LINE__); AFALGerr(AFALG_F_AFALG_SETUP_ASYNC_EVENT_NOTIFICATION, - AFALG_R_EVENTFD_FAILED); + AFALG_R_EVENTFD_FAILED); return 0; } ret = ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_afalg_id, - aio->efd, custom, - afalg_waitfd_cleanup); + aio->efd, custom, + afalg_waitfd_cleanup); if (ret == 0) { ALG_WARN("%s(%d): Failed to set wait fd", __FILE__, __LINE__); close(aio->efd); @@ -223,7 +223,7 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) /* make fd non-blocking in async mode */ if (fcntl(aio->efd, F_SETFL, O_NONBLOCK) != 0) { ALG_WARN("%s(%d): Failed to set event fd as NONBLOCKING", - __FILE__, __LINE__); + __FILE__, __LINE__); } } aio->mode = MODE_ASYNC; @@ -233,7 +233,7 @@ static int afalg_setup_async_event_notification(afalg_aio *aio) if (aio->efd == -1) { ALG_PERR("%s(%d): Failed to get eventfd : ", __FILE__, __LINE__); AFALGerr(AFALG_F_AFALG_SETUP_ASYNC_EVENT_NOTIFICATION, - AFALG_R_EVENTFD_FAILED); + AFALG_R_EVENTFD_FAILED); return 0; } aio->mode = MODE_SYNC; @@ -262,7 +262,7 @@ static int afalg_init_aio(afalg_aio *aio) } static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, - size_t len) + size_t len) { int r; int retry = 0; @@ -320,7 +320,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, return 0; } else if (r == 0 || eval <= 0) { ALG_WARN("%s(%d): eventfd read %d bytes, eval = %lu\n", __FILE__, - __LINE__, r, eval); + __LINE__, r, eval); } if (eval > 0) { @@ -335,7 +335,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, /* Get results of AIO read */ r = io_getevents(aio->aio_ctx, 1, MAX_INFLIGHTS, - events, &timeout); + events, &timeout); if (r > 0) { /* * events.res indicates the actual status of the operation. @@ -350,7 +350,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, r = io_read(aio->aio_ctx, 1, &cb); if (r < 0) { ALG_PERR("%s(%d): retry %d for io_read failed : ", - __FILE__, __LINE__, retry); + __FILE__, __LINE__, retry); return 0; } continue; @@ -359,9 +359,8 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, * Retries exceed for -EBUSY or unrecoverable error * condition for this instance of operation. */ - ALG_WARN - ("%s(%d): Crypto Operation failed with code %lld\n", - __FILE__, __LINE__, events[0].res); + ALG_WARN("%s(%d): Crypto Operation failed with code %lld\n", + __FILE__, __LINE__, events[0].res); return 0; } } @@ -372,7 +371,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, return 0; } else { ALG_WARN("%s(%d): io_geteventd read 0 bytes\n", __FILE__, - __LINE__); + __LINE__); } } } while (!done); @@ -381,7 +380,7 @@ static int afalg_fin_cipher_aio(afalg_aio *aio, int sfd, unsigned char *buf, } static ossl_inline void afalg_set_op_sk(struct cmsghdr *cmsg, - const ALG_OP_TYPE op) + const ALG_OP_TYPE op) { cmsg->cmsg_level = SOL_ALG; cmsg->cmsg_type = ALG_SET_OP; @@ -390,7 +389,7 @@ static ossl_inline void afalg_set_op_sk(struct cmsghdr *cmsg, } static void afalg_set_iv_sk(struct cmsghdr *cmsg, const unsigned char *iv, - const unsigned int len) + const unsigned int len) { struct af_alg_iv *aiv; @@ -403,7 +402,7 @@ static void afalg_set_iv_sk(struct cmsghdr *cmsg, const unsigned char *iv, } static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key, - const int klen) + const int klen) { int ret; ret = setsockopt(actx->bfd, SOL_ALG, ALG_SET_KEY, key, klen); @@ -416,7 +415,7 @@ static ossl_inline int afalg_set_key(afalg_ctx *actx, const unsigned char *key, } static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, - const char *ciphername) + const char *ciphername) { struct sockaddr_alg sa; int r = -1; @@ -425,8 +424,8 @@ static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, memset(&sa, 0, sizeof(sa)); sa.salg_family = AF_ALG; - OPENSSL_strlcpy((char *) sa.salg_type, ciphertype, sizeof(sa.salg_type)); - OPENSSL_strlcpy((char *) sa.salg_name, ciphername, sizeof(sa.salg_name)); + OPENSSL_strlcpy((char *)sa.salg_type, ciphertype, sizeof(sa.salg_type)); + OPENSSL_strlcpy((char *)sa.salg_name, ciphername, sizeof(sa.salg_name)); actx->bfd = socket(AF_ALG, SOCK_SEQPACKET, 0); if (actx->bfd == -1) { @@ -451,7 +450,7 @@ static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, return 1; - err: +err: if (actx->bfd >= 0) close(actx->bfd); if (actx->sfd >= 0) @@ -461,16 +460,16 @@ static int afalg_create_sk(afalg_ctx *actx, const char *ciphertype, } static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, - size_t inl, const unsigned char *iv, - unsigned int enc) + size_t inl, const unsigned char *iv, + unsigned int enc) { struct msghdr msg; struct cmsghdr *cmsg; struct iovec iov; ssize_t sbytes; -# ifdef ALG_ZERO_COPY +#ifdef ALG_ZERO_COPY int ret; -# endif +#endif char cbuf[CMSG_SPACE(ALG_IV_LEN(ALG_AES_IV_LEN)) + CMSG_SPACE(ALG_OP_LEN)]; memset(&msg, 0, sizeof(msg)); @@ -493,7 +492,7 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, msg.msg_flags = MSG_MORE; -# ifdef ALG_ZERO_COPY +#ifdef ALG_ZERO_COPY /* * ZERO_COPY mode * Works best when buffer is 4k aligned @@ -508,7 +507,7 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, sbytes = sendmsg(actx->sfd, &msg, 0); if (sbytes < 0) { ALG_PERR("%s(%d): sendmsg failed for zero copy cipher operation : ", - __FILE__, __LINE__); + __FILE__, __LINE__); return 0; } @@ -527,7 +526,7 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, ALG_PERR("%s(%d): splice failed : ", __FILE__, __LINE__); return 0; } -# else +#else msg.msg_iovlen = 1; msg.msg_iov = &iov; @@ -535,22 +534,22 @@ static int afalg_start_cipher_sk(afalg_ctx *actx, const unsigned char *in, sbytes = sendmsg(actx->sfd, &msg, 0); if (sbytes < 0) { ALG_PERR("%s(%d): sendmsg failed for cipher operation : ", __FILE__, - __LINE__); + __LINE__); return 0; } - if (sbytes != (ssize_t) inl) { + if (sbytes != (ssize_t)inl) { ALG_WARN("Cipher operation send bytes %zd != inlen %zd\n", sbytes, - inl); + inl); return 0; } -# endif +#endif return 1; } static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { int ciphertype; int ret, len; @@ -582,13 +581,13 @@ static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, break; default: ALG_WARN("%s(%d): Unsupported Cipher type %d\n", __FILE__, __LINE__, - ciphertype); + ciphertype); return 0; } if (ALG_AES_IV_LEN != EVP_CIPHER_CTX_get_iv_length(ctx)) { ALG_WARN("%s(%d): Unsupported IV length :%d\n", __FILE__, __LINE__, - EVP_CIPHER_CTX_get_iv_length(ctx)); + EVP_CIPHER_CTX_get_iv_length(ctx)); return 0; } @@ -607,9 +606,9 @@ static int afalg_cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, if (afalg_init_aio(&actx->aio) == 0) goto err; -# ifdef ALG_ZERO_COPY +#ifdef ALG_ZERO_COPY pipe(actx->zc_pipe); -# endif +#endif actx->init_done = MAGIC_INIT_NUM; @@ -622,7 +621,7 @@ err: } static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { afalg_ctx *actx; int ret; @@ -630,14 +629,14 @@ static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, if (ctx == NULL || out == NULL || in == NULL) { ALG_WARN("NULL parameter passed to function %s(%d)\n", __FILE__, - __LINE__); + __LINE__); return 0; } - actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx); + actx = (afalg_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) { ALG_WARN("%s afalg ctx passed\n", - ctx == NULL ? "NULL" : "Uninitialised"); + ctx == NULL ? "NULL" : "Uninitialised"); return 0; } @@ -651,8 +650,8 @@ static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, /* Send input data to kernel space */ ret = afalg_start_cipher_sk(actx, (unsigned char *)in, inl, - EVP_CIPHER_CTX_iv(ctx), - EVP_CIPHER_CTX_is_encrypting(ctx)); + EVP_CIPHER_CTX_iv(ctx), + EVP_CIPHER_CTX_is_encrypting(ctx)); if (ret < 1) { return 0; } @@ -664,7 +663,7 @@ static int afalg_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, if (EVP_CIPHER_CTX_is_encrypting(ctx)) { memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), out + (inl - ALG_AES_IV_LEN), - ALG_AES_IV_LEN); + ALG_AES_IV_LEN); } else { memcpy(EVP_CIPHER_CTX_iv_noconst(ctx), nxtiv, ALG_AES_IV_LEN); } @@ -678,20 +677,20 @@ static int afalg_cipher_cleanup(EVP_CIPHER_CTX *ctx) if (ctx == NULL) { ALG_WARN("NULL parameter passed to function %s(%d)\n", __FILE__, - __LINE__); + __LINE__); return 0; } - actx = (afalg_ctx *) EVP_CIPHER_CTX_get_cipher_data(ctx); + actx = (afalg_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); if (actx == NULL || actx->init_done != MAGIC_INIT_NUM) return 1; close(actx->sfd); close(actx->bfd); -# ifdef ALG_ZERO_COPY +#ifdef ALG_ZERO_COPY close(actx->zc_pipe[0]); close(actx->zc_pipe[1]); -# endif +#endif /* close efd in sync mode, async mode is closed in afalg_waitfd_cleanup() */ if (actx->aio.mode == MODE_SYNC) close(actx->aio.efd); @@ -719,33 +718,32 @@ static const EVP_CIPHER *afalg_aes_cbc(int nid) cbc_handles *cipher_handle = get_cipher_handle(nid); if (cipher_handle == NULL) - return NULL; + return NULL; if (cipher_handle->_hidden == NULL - && ((cipher_handle->_hidden = - EVP_CIPHER_meth_new(nid, - AES_BLOCK_SIZE, - cipher_handle->key_size)) == NULL - || !EVP_CIPHER_meth_set_iv_length(cipher_handle->_hidden, - AES_IV_LEN) - || !EVP_CIPHER_meth_set_flags(cipher_handle->_hidden, - EVP_CIPH_CBC_MODE | - EVP_CIPH_FLAG_DEFAULT_ASN1) - || !EVP_CIPHER_meth_set_init(cipher_handle->_hidden, - afalg_cipher_init) - || !EVP_CIPHER_meth_set_do_cipher(cipher_handle->_hidden, - afalg_do_cipher) - || !EVP_CIPHER_meth_set_cleanup(cipher_handle->_hidden, - afalg_cipher_cleanup) - || !EVP_CIPHER_meth_set_impl_ctx_size(cipher_handle->_hidden, - sizeof(afalg_ctx)))) { + && ((cipher_handle->_hidden = EVP_CIPHER_meth_new(nid, + AES_BLOCK_SIZE, + cipher_handle->key_size)) + == NULL + || !EVP_CIPHER_meth_set_iv_length(cipher_handle->_hidden, + AES_IV_LEN) + || !EVP_CIPHER_meth_set_flags(cipher_handle->_hidden, + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1) + || !EVP_CIPHER_meth_set_init(cipher_handle->_hidden, + afalg_cipher_init) + || !EVP_CIPHER_meth_set_do_cipher(cipher_handle->_hidden, + afalg_do_cipher) + || !EVP_CIPHER_meth_set_cleanup(cipher_handle->_hidden, + afalg_cipher_cleanup) + || !EVP_CIPHER_meth_set_impl_ctx_size(cipher_handle->_hidden, + sizeof(afalg_ctx)))) { EVP_CIPHER_meth_free(cipher_handle->_hidden); - cipher_handle->_hidden= NULL; + cipher_handle->_hidden = NULL; } return cipher_handle->_hidden; } static int afalg_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid) + const int **nids, int nid) { int r = 1; @@ -787,7 +785,7 @@ static int bind_afalg(ENGINE *e) * now, as bind_aflag can only be called by one thread at a * time. */ - for(i = 0; i < OSSL_NELEM(afalg_cipher_nids); i++) { + for (i = 0; i < OSSL_NELEM(afalg_cipher_nids); i++) { if (afalg_aes_cbc(afalg_cipher_nids[i]) == NULL) { AFALGerr(AFALG_F_BIND_AFALG, AFALG_R_INIT_FAILED); return 0; @@ -802,7 +800,7 @@ static int bind_afalg(ENGINE *e) return 1; } -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE static int bind_helper(ENGINE *e, const char *id) { if (id && (strcmp(id, engine_afalg_id) != 0)) @@ -819,8 +817,8 @@ static int bind_helper(ENGINE *e, const char *id) } IMPLEMENT_DYNAMIC_CHECK_FN() - IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) -# endif +IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) +#endif static int afalg_chk_platform(void) { @@ -834,7 +832,7 @@ static int afalg_chk_platform(void) ret = uname(&ut); if (ret != 0) { AFALGerr(AFALG_F_AFALG_CHK_PLATFORM, - AFALG_R_FAILED_TO_GET_PLATFORM_INFO); + AFALG_R_FAILED_TO_GET_PLATFORM_INFO); return 0; } @@ -847,11 +845,11 @@ static int afalg_chk_platform(void) if (KERNEL_VERSION(kver[0], kver[1], kver[2]) < KERNEL_VERSION(K_MAJ, K_MIN1, K_MIN2)) { ALG_ERR("ASYNC AFALG not supported this kernel(%d.%d.%d)\n", - kver[0], kver[1], kver[2]); + kver[0], kver[1], kver[2]); ALG_ERR("ASYNC AFALG requires kernel version %d.%d.%d or later\n", - K_MAJ, K_MIN1, K_MIN2); + K_MAJ, K_MIN1, K_MIN2); AFALGerr(AFALG_F_AFALG_CHK_PLATFORM, - AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG); + AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG); return 0; } @@ -866,7 +864,7 @@ static int afalg_chk_platform(void) return 1; } -# ifdef OPENSSL_NO_DYNAMIC_ENGINE +#ifdef OPENSSL_NO_DYNAMIC_ENGINE static ENGINE *engine_afalg(void) { ENGINE *ret = ENGINE_new(); @@ -903,7 +901,7 @@ void engine_load_afalg_int(void) */ ERR_pop_to_mark(); } -# endif +#endif static int afalg_init(ENGINE *e) { @@ -918,7 +916,7 @@ static int afalg_finish(ENGINE *e) static int free_cbc(void) { short unsigned int i; - for(i = 0; i < OSSL_NELEM(afalg_cipher_nids); i++) { + for (i = 0; i < OSSL_NELEM(afalg_cipher_nids); i++) { EVP_CIPHER_meth_free(cbc_handle[i]._hidden); cbc_handle[i]._hidden = NULL; } @@ -932,4 +930,4 @@ static int afalg_destroy(ENGINE *e) return 1; } -#endif /* KERNEL VERSION */ +#endif /* KERNEL VERSION */ diff --git a/engines/e_afalg.h b/engines/e_afalg.h index b8e4911d21ef..e8ccf9515e9a 100644 --- a/engines/e_afalg.h +++ b/engines/e_afalg.h @@ -8,44 +8,43 @@ */ #ifndef OSSL_ENGINES_E_AFALG_H -# define OSSL_ENGINES_E_AFALG_H +#define OSSL_ENGINES_E_AFALG_H -# if defined(__GNUC__) && __GNUC__ >= 4 && \ - (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) -# pragma GCC diagnostic ignored "-Wvariadic-macros" -# endif +#if defined(__GNUC__) && __GNUC__ >= 4 && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) +#pragma GCC diagnostic ignored "-Wvariadic-macros" +#endif -# ifdef ALG_DEBUG -# define ALG_DGB(x, ...) fprintf(stderr, "ALG_DBG: " x, __VA_ARGS__) -# define ALG_INFO(x, ...) fprintf(stderr, "ALG_INFO: " x, __VA_ARGS__) -# define ALG_WARN(x, ...) fprintf(stderr, "ALG_WARN: " x, __VA_ARGS__) -# else -# define ALG_DGB(x, ...) -# define ALG_INFO(x, ...) -# define ALG_WARN(x, ...) -# endif +#ifdef ALG_DEBUG +#define ALG_DGB(x, ...) fprintf(stderr, "ALG_DBG: " x, __VA_ARGS__) +#define ALG_INFO(x, ...) fprintf(stderr, "ALG_INFO: " x, __VA_ARGS__) +#define ALG_WARN(x, ...) fprintf(stderr, "ALG_WARN: " x, __VA_ARGS__) +#else +#define ALG_DGB(x, ...) +#define ALG_INFO(x, ...) +#define ALG_WARN(x, ...) +#endif -# define ALG_ERR(x, ...) fprintf(stderr, "ALG_ERR: " x, __VA_ARGS__) -# define ALG_PERR(x, ...) \ - do { \ - fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \ - perror(NULL); \ - } while(0) -# define ALG_PWARN(x, ...) \ - do { \ - fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \ - perror(NULL); \ - } while(0) +#define ALG_ERR(x, ...) fprintf(stderr, "ALG_ERR: " x, __VA_ARGS__) +#define ALG_PERR(x, ...) \ + do { \ + fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \ + perror(NULL); \ + } while (0) +#define ALG_PWARN(x, ...) \ + do { \ + fprintf(stderr, "ALG_PERR: " x, __VA_ARGS__); \ + perror(NULL); \ + } while (0) -# ifndef AES_BLOCK_SIZE -# define AES_BLOCK_SIZE 16 -# endif -# define AES_KEY_SIZE_128 16 -# define AES_KEY_SIZE_192 24 -# define AES_KEY_SIZE_256 32 -# define AES_IV_LEN 16 +#ifndef AES_BLOCK_SIZE +#define AES_BLOCK_SIZE 16 +#endif +#define AES_KEY_SIZE_128 16 +#define AES_KEY_SIZE_192 24 +#define AES_KEY_SIZE_256 32 +#define AES_IV_LEN 16 -# define MAX_INFLIGHTS 1 +#define MAX_INFLIGHTS 1 typedef enum { MODE_UNINIT = 0, @@ -79,15 +78,15 @@ typedef struct afalg_aio_st afalg_aio; * MAGIC Number to identify correct initialisation * of afalg_ctx. */ -# define MAGIC_INIT_NUM 0x1890671 +#define MAGIC_INIT_NUM 0x1890671 struct afalg_ctx_st { int init_done; int sfd; int bfd; -# ifdef ALG_ZERO_COPY +#ifdef ALG_ZERO_COPY int zc_pipe[2]; -# endif +#endif afalg_aio aio; }; diff --git a/engines/e_afalg_err.c b/engines/e_afalg_err.c index 47a3d034e50d..f7e47f21a572 100644 --- a/engines/e_afalg_err.c +++ b/engines/e_afalg_err.c @@ -14,23 +14,23 @@ #ifndef OPENSSL_NO_ERR static ERR_STRING_DATA AFALG_str_reasons[] = { - {ERR_PACK(0, 0, AFALG_R_EVENTFD_FAILED), "eventfd failed"}, - {ERR_PACK(0, 0, AFALG_R_FAILED_TO_GET_PLATFORM_INFO), - "failed to get platform info"}, - {ERR_PACK(0, 0, AFALG_R_INIT_FAILED), "init failed"}, - {ERR_PACK(0, 0, AFALG_R_IO_SETUP_FAILED), "io setup failed"}, - {ERR_PACK(0, 0, AFALG_R_KERNEL_DOES_NOT_SUPPORT_AFALG), - "kernel does not support afalg"}, - {ERR_PACK(0, 0, AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG), - "kernel does not support async afalg"}, - {ERR_PACK(0, 0, AFALG_R_MEM_ALLOC_FAILED), "mem alloc failed"}, - {ERR_PACK(0, 0, AFALG_R_SOCKET_ACCEPT_FAILED), "socket accept failed"}, - {ERR_PACK(0, 0, AFALG_R_SOCKET_BIND_FAILED), "socket bind failed"}, - {ERR_PACK(0, 0, AFALG_R_SOCKET_CREATE_FAILED), "socket create failed"}, - {ERR_PACK(0, 0, AFALG_R_SOCKET_OPERATION_FAILED), - "socket operation failed"}, - {ERR_PACK(0, 0, AFALG_R_SOCKET_SET_KEY_FAILED), "socket set key failed"}, - {0, NULL} + { ERR_PACK(0, 0, AFALG_R_EVENTFD_FAILED), "eventfd failed" }, + { ERR_PACK(0, 0, AFALG_R_FAILED_TO_GET_PLATFORM_INFO), + "failed to get platform info" }, + { ERR_PACK(0, 0, AFALG_R_INIT_FAILED), "init failed" }, + { ERR_PACK(0, 0, AFALG_R_IO_SETUP_FAILED), "io setup failed" }, + { ERR_PACK(0, 0, AFALG_R_KERNEL_DOES_NOT_SUPPORT_AFALG), + "kernel does not support afalg" }, + { ERR_PACK(0, 0, AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG), + "kernel does not support async afalg" }, + { ERR_PACK(0, 0, AFALG_R_MEM_ALLOC_FAILED), "mem alloc failed" }, + { ERR_PACK(0, 0, AFALG_R_SOCKET_ACCEPT_FAILED), "socket accept failed" }, + { ERR_PACK(0, 0, AFALG_R_SOCKET_BIND_FAILED), "socket bind failed" }, + { ERR_PACK(0, 0, AFALG_R_SOCKET_CREATE_FAILED), "socket create failed" }, + { ERR_PACK(0, 0, AFALG_R_SOCKET_OPERATION_FAILED), + "socket operation failed" }, + { ERR_PACK(0, 0, AFALG_R_SOCKET_SET_KEY_FAILED), "socket set key failed" }, + { 0, NULL } }; #endif diff --git a/engines/e_afalg_err.h b/engines/e_afalg_err.h index 2070c04a1c11..b843be0c10dc 100644 --- a/engines/e_afalg_err.h +++ b/engines/e_afalg_err.h @@ -9,30 +9,28 @@ */ #ifndef OSSL_E_AFALG_ERR_H -# define OSSL_E_AFALG_ERR_H -# pragma once +#define OSSL_E_AFALG_ERR_H +#pragma once -# include <openssl/opensslconf.h> -# include <openssl/symhacks.h> - - -# define AFALGerr(f, r) ERR_AFALG_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) +#include <openssl/opensslconf.h> +#include <openssl/symhacks.h> +#define AFALGerr(f, r) ERR_AFALG_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) /* * AFALG reason codes. */ -# define AFALG_R_EVENTFD_FAILED 108 -# define AFALG_R_FAILED_TO_GET_PLATFORM_INFO 111 -# define AFALG_R_INIT_FAILED 100 -# define AFALG_R_IO_SETUP_FAILED 105 -# define AFALG_R_KERNEL_DOES_NOT_SUPPORT_AFALG 101 -# define AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG 107 -# define AFALG_R_MEM_ALLOC_FAILED 102 -# define AFALG_R_SOCKET_ACCEPT_FAILED 110 -# define AFALG_R_SOCKET_BIND_FAILED 103 -# define AFALG_R_SOCKET_CREATE_FAILED 109 -# define AFALG_R_SOCKET_OPERATION_FAILED 104 -# define AFALG_R_SOCKET_SET_KEY_FAILED 106 +#define AFALG_R_EVENTFD_FAILED 108 +#define AFALG_R_FAILED_TO_GET_PLATFORM_INFO 111 +#define AFALG_R_INIT_FAILED 100 +#define AFALG_R_IO_SETUP_FAILED 105 +#define AFALG_R_KERNEL_DOES_NOT_SUPPORT_AFALG 101 +#define AFALG_R_KERNEL_DOES_NOT_SUPPORT_ASYNC_AFALG 107 +#define AFALG_R_MEM_ALLOC_FAILED 102 +#define AFALG_R_SOCKET_ACCEPT_FAILED 110 +#define AFALG_R_SOCKET_BIND_FAILED 103 +#define AFALG_R_SOCKET_CREATE_FAILED 109 +#define AFALG_R_SOCKET_OPERATION_FAILED 104 +#define AFALG_R_SOCKET_SET_KEY_FAILED 106 #endif diff --git a/engines/e_capi.c b/engines/e_capi.c index 6f223a692273..f8df830de279 100644 --- a/engines/e_capi.c +++ b/engines/e_capi.c @@ -11,28 +11,28 @@ #define OPENSSL_SUPPRESS_DEPRECATED #ifdef _WIN32 -# ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0400 -# endif -# include <windows.h> -# include <wincrypt.h> +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0400 +#endif +#include <windows.h> +#include <wincrypt.h> -# include <stdio.h> -# include <string.h> -# include <stdlib.h> -# include <malloc.h> -# ifndef alloca -# define alloca _alloca -# endif +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <malloc.h> +#ifndef alloca +#define alloca _alloca +#endif -# include <openssl/crypto.h> +#include <openssl/crypto.h> -# ifndef OPENSSL_NO_CAPIENG +#ifndef OPENSSL_NO_CAPIENG -# include <openssl/buffer.h> -# include <openssl/bn.h> -# include <openssl/rsa.h> -# include <openssl/dsa.h> +#include <openssl/buffer.h> +#include <openssl/bn.h> +#include <openssl/rsa.h> +#include <openssl/dsa.h> /* * This module uses several "new" interfaces, among which is @@ -46,61 +46,61 @@ * Yes, it's rather "weak" test and if compilation fails, * then re-configure with -DOPENSSL_NO_CAPIENG. */ -# if defined(CERT_KEY_PROV_INFO_PROP_ID) && \ - defined(CERT_STORE_PROV_SYSTEM_A) && \ - defined(CERT_STORE_READONLY_FLAG) -# define __COMPILE_CAPIENG -# endif /* CERT_KEY_PROV_INFO_PROP_ID */ -# endif /* OPENSSL_NO_CAPIENG */ -#endif /* _WIN32 */ +#if defined(CERT_KEY_PROV_INFO_PROP_ID) && defined(CERT_STORE_PROV_SYSTEM_A) && defined(CERT_STORE_READONLY_FLAG) +#define __COMPILE_CAPIENG +#endif /* CERT_KEY_PROV_INFO_PROP_ID */ +#endif /* OPENSSL_NO_CAPIENG */ +#endif /* _WIN32 */ #ifdef __COMPILE_CAPIENG -# undef X509_EXTENSIONS +#undef X509_EXTENSIONS /* Definitions which may be missing from earlier version of headers */ -# ifndef CERT_STORE_OPEN_EXISTING_FLAG -# define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000 -# endif +#ifndef CERT_STORE_OPEN_EXISTING_FLAG +#define CERT_STORE_OPEN_EXISTING_FLAG 0x00004000 +#endif -# ifndef CERT_STORE_CREATE_NEW_FLAG -# define CERT_STORE_CREATE_NEW_FLAG 0x00002000 -# endif +#ifndef CERT_STORE_CREATE_NEW_FLAG +#define CERT_STORE_CREATE_NEW_FLAG 0x00002000 +#endif -# ifndef CERT_SYSTEM_STORE_CURRENT_USER -# define CERT_SYSTEM_STORE_CURRENT_USER 0x00010000 -# endif +#ifndef CERT_SYSTEM_STORE_CURRENT_USER +#define CERT_SYSTEM_STORE_CURRENT_USER 0x00010000 +#endif -# ifndef ALG_SID_SHA_256 -# define ALG_SID_SHA_256 12 -# endif -# ifndef ALG_SID_SHA_384 -# define ALG_SID_SHA_384 13 -# endif -# ifndef ALG_SID_SHA_512 -# define ALG_SID_SHA_512 14 -# endif +#ifndef ALG_SID_SHA_256 +#define ALG_SID_SHA_256 12 +#endif +#ifndef ALG_SID_SHA_384 +#define ALG_SID_SHA_384 13 +#endif +#ifndef ALG_SID_SHA_512 +#define ALG_SID_SHA_512 14 +#endif -# ifndef CALG_SHA_256 -# define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256) -# endif -# ifndef CALG_SHA_384 -# define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384) -# endif -# ifndef CALG_SHA_512 -# define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512) -# endif +#ifndef CALG_SHA_256 +#define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256) +#endif +#ifndef CALG_SHA_384 +#define CALG_SHA_384 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_384) +#endif +#ifndef CALG_SHA_512 +#define CALG_SHA_512 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_512) +#endif -# ifndef PROV_RSA_AES -# define PROV_RSA_AES 24 -# endif +#ifndef PROV_RSA_AES +#define PROV_RSA_AES 24 +#endif -# include <openssl/engine.h> -# include <openssl/pem.h> -# include <openssl/x509v3.h> +#include <openssl/engine.h> +#include <openssl/pem.h> +#include <openssl/x509v3.h> +/* clang-format off */ # include "e_capi_err.h" # include "e_capi_err.c" +/* clang-format on */ static const char *engine_capi_id = "capi"; static const char *engine_capi_name = "CryptoAPI ENGINE"; @@ -119,42 +119,42 @@ int capi_list_certs(CAPI_CTX *ctx, BIO *out, char *storename); void capi_free_key(CAPI_KEY *key); static PCCERT_CONTEXT capi_find_cert(CAPI_CTX *ctx, const char *id, - HCERTSTORE hstore); + HCERTSTORE hstore); CAPI_KEY *capi_find_key(CAPI_CTX *ctx, const char *id); static EVP_PKEY *capi_load_privkey(ENGINE *eng, const char *key_id, - UI_METHOD *ui_method, void *callback_data); + UI_METHOD *ui_method, void *callback_data); static int capi_rsa_sign(int dtype, const unsigned char *m, - unsigned int m_len, unsigned char *sigret, - unsigned int *siglen, const RSA *rsa); + unsigned int m_len, unsigned char *sigret, + unsigned int *siglen, const RSA *rsa); static int capi_rsa_priv_enc(int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, int padding); + unsigned char *to, RSA *rsa, int padding); static int capi_rsa_priv_dec(int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, int padding); + unsigned char *to, RSA *rsa, int padding); static int capi_rsa_free(RSA *rsa); -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA static DSA_SIG *capi_dsa_do_sign(const unsigned char *digest, int dlen, - DSA *dsa); + DSA *dsa); static int capi_dsa_free(DSA *dsa); -# endif +#endif static int capi_load_ssl_client_cert(ENGINE *e, SSL *ssl, - STACK_OF(X509_NAME) *ca_dn, X509 **pcert, - EVP_PKEY **pkey, STACK_OF(X509) **pother, - UI_METHOD *ui_method, - void *callback_data); + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, + EVP_PKEY **pkey, STACK_OF(X509) **pother, + UI_METHOD *ui_method, + void *callback_data); static int cert_select_simple(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs); -# ifdef OPENSSL_CAPIENG_DIALOG +#ifdef OPENSSL_CAPIENG_DIALOG static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs); -# endif +#endif void engine_load_capi_int(void); typedef PCCERT_CONTEXT(WINAPI *CERTDLG)(HCERTSTORE, HWND, LPCWSTR, - LPCWSTR, DWORD, DWORD, void *); + LPCWSTR, DWORD, DWORD, void *); typedef HWND(WINAPI *GETCONSWIN)(void); /* @@ -162,8 +162,8 @@ typedef HWND(WINAPI *GETCONSWIN)(void); * global options and affects how other functions behave. */ -# define CAPI_DBG_TRACE 2 -# define CAPI_DBG_ERROR 1 +#define CAPI_DBG_TRACE 2 +#define CAPI_DBG_ERROR 1 struct CAPI_CTX_st { int debug_level; @@ -178,19 +178,19 @@ struct CAPI_CTX_st { /* System store flags */ DWORD store_flags; /* Lookup string meanings in load_private_key */ -# define CAPI_LU_SUBSTR 1 /* Substring of subject: uses "storename" */ -# define CAPI_LU_FNAME 2 /* Friendly name: uses storename */ -# define CAPI_LU_CONTNAME 3 /* Container name: uses cspname, keytype */ +#define CAPI_LU_SUBSTR 1 /* Substring of subject: uses "storename" */ +#define CAPI_LU_FNAME 2 /* Friendly name: uses storename */ +#define CAPI_LU_CONTNAME 3 /* Container name: uses cspname, keytype */ int lookup_method; /* Info to dump with dumpcerts option */ -# define CAPI_DMP_SUMMARY 0x1 /* Issuer and serial name strings */ -# define CAPI_DMP_FNAME 0x2 /* Friendly name */ -# define CAPI_DMP_FULL 0x4 /* Full X509_print dump */ -# define CAPI_DMP_PEM 0x8 /* Dump PEM format certificate */ -# define CAPI_DMP_PSKEY 0x10 /* Dump pseudo key (if possible) */ -# define CAPI_DMP_PKEYINFO 0x20 /* Dump key info (if possible) */ +#define CAPI_DMP_SUMMARY 0x1 /* Issuer and serial name strings */ +#define CAPI_DMP_FNAME 0x2 /* Friendly name */ +#define CAPI_DMP_FULL 0x4 /* Full X509_print dump */ +#define CAPI_DMP_PEM 0x8 /* Dump PEM format certificate */ +#define CAPI_DMP_PSKEY 0x10 /* Dump pseudo key (if possible) */ +#define CAPI_DMP_PKEYINFO 0x20 /* Dump key info (if possible) */ DWORD dump_flags; - int (*client_cert_select) (ENGINE *e, SSL *ssl, STACK_OF(X509) *certs); + int (*client_cert_select)(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs); CERTDLG certselectdlg; GETCONSWIN getconswindow; }; @@ -198,84 +198,84 @@ struct CAPI_CTX_st { static CAPI_CTX *capi_ctx_new(void); static void capi_ctx_free(CAPI_CTX *ctx); static int capi_ctx_set_provname(CAPI_CTX *ctx, LPSTR pname, DWORD type, - int check); + int check); static int capi_ctx_set_provname_idx(CAPI_CTX *ctx, int idx); -# define CAPI_CMD_LIST_CERTS ENGINE_CMD_BASE -# define CAPI_CMD_LOOKUP_CERT (ENGINE_CMD_BASE + 1) -# define CAPI_CMD_DEBUG_LEVEL (ENGINE_CMD_BASE + 2) -# define CAPI_CMD_DEBUG_FILE (ENGINE_CMD_BASE + 3) -# define CAPI_CMD_KEYTYPE (ENGINE_CMD_BASE + 4) -# define CAPI_CMD_LIST_CSPS (ENGINE_CMD_BASE + 5) -# define CAPI_CMD_SET_CSP_IDX (ENGINE_CMD_BASE + 6) -# define CAPI_CMD_SET_CSP_NAME (ENGINE_CMD_BASE + 7) -# define CAPI_CMD_SET_CSP_TYPE (ENGINE_CMD_BASE + 8) -# define CAPI_CMD_LIST_CONTAINERS (ENGINE_CMD_BASE + 9) -# define CAPI_CMD_LIST_OPTIONS (ENGINE_CMD_BASE + 10) -# define CAPI_CMD_LOOKUP_METHOD (ENGINE_CMD_BASE + 11) -# define CAPI_CMD_STORE_NAME (ENGINE_CMD_BASE + 12) -# define CAPI_CMD_STORE_FLAGS (ENGINE_CMD_BASE + 13) +#define CAPI_CMD_LIST_CERTS ENGINE_CMD_BASE +#define CAPI_CMD_LOOKUP_CERT (ENGINE_CMD_BASE + 1) +#define CAPI_CMD_DEBUG_LEVEL (ENGINE_CMD_BASE + 2) +#define CAPI_CMD_DEBUG_FILE (ENGINE_CMD_BASE + 3) +#define CAPI_CMD_KEYTYPE (ENGINE_CMD_BASE + 4) +#define CAPI_CMD_LIST_CSPS (ENGINE_CMD_BASE + 5) +#define CAPI_CMD_SET_CSP_IDX (ENGINE_CMD_BASE + 6) +#define CAPI_CMD_SET_CSP_NAME (ENGINE_CMD_BASE + 7) +#define CAPI_CMD_SET_CSP_TYPE (ENGINE_CMD_BASE + 8) +#define CAPI_CMD_LIST_CONTAINERS (ENGINE_CMD_BASE + 9) +#define CAPI_CMD_LIST_OPTIONS (ENGINE_CMD_BASE + 10) +#define CAPI_CMD_LOOKUP_METHOD (ENGINE_CMD_BASE + 11) +#define CAPI_CMD_STORE_NAME (ENGINE_CMD_BASE + 12) +#define CAPI_CMD_STORE_FLAGS (ENGINE_CMD_BASE + 13) static const ENGINE_CMD_DEFN capi_cmd_defns[] = { - {CAPI_CMD_LIST_CERTS, - "list_certs", - "List all certificates in store", - ENGINE_CMD_FLAG_NO_INPUT}, - {CAPI_CMD_LOOKUP_CERT, - "lookup_cert", - "Lookup and output certificates", - ENGINE_CMD_FLAG_STRING}, - {CAPI_CMD_DEBUG_LEVEL, - "debug_level", - "debug level (1=errors, 2=trace)", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_DEBUG_FILE, - "debug_file", - "debugging filename)", - ENGINE_CMD_FLAG_STRING}, - {CAPI_CMD_KEYTYPE, - "key_type", - "Key type: 1=AT_KEYEXCHANGE (default), 2=AT_SIGNATURE", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_LIST_CSPS, - "list_csps", - "List all CSPs", - ENGINE_CMD_FLAG_NO_INPUT}, - {CAPI_CMD_SET_CSP_IDX, - "csp_idx", - "Set CSP by index", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_SET_CSP_NAME, - "csp_name", - "Set CSP name, (default CSP used if not specified)", - ENGINE_CMD_FLAG_STRING}, - {CAPI_CMD_SET_CSP_TYPE, - "csp_type", - "Set CSP type, (default RSA_PROV_FULL)", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_LIST_CONTAINERS, - "list_containers", - "list container names", - ENGINE_CMD_FLAG_NO_INPUT}, - {CAPI_CMD_LIST_OPTIONS, - "list_options", - "Set list options (1=summary,2=friendly name, 4=full printout, 8=PEM output, 16=XXX, " - "32=private key info)", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_LOOKUP_METHOD, - "lookup_method", - "Set key lookup method (1=substring, 2=friendlyname, 3=container name)", - ENGINE_CMD_FLAG_NUMERIC}, - {CAPI_CMD_STORE_NAME, - "store_name", - "certificate store name, default \"MY\"", - ENGINE_CMD_FLAG_STRING}, - {CAPI_CMD_STORE_FLAGS, - "store_flags", - "Certificate store flags: 1 = system store", - ENGINE_CMD_FLAG_NUMERIC}, + { CAPI_CMD_LIST_CERTS, + "list_certs", + "List all certificates in store", + ENGINE_CMD_FLAG_NO_INPUT }, + { CAPI_CMD_LOOKUP_CERT, + "lookup_cert", + "Lookup and output certificates", + ENGINE_CMD_FLAG_STRING }, + { CAPI_CMD_DEBUG_LEVEL, + "debug_level", + "debug level (1=errors, 2=trace)", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_DEBUG_FILE, + "debug_file", + "debugging filename)", + ENGINE_CMD_FLAG_STRING }, + { CAPI_CMD_KEYTYPE, + "key_type", + "Key type: 1=AT_KEYEXCHANGE (default), 2=AT_SIGNATURE", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_LIST_CSPS, + "list_csps", + "List all CSPs", + ENGINE_CMD_FLAG_NO_INPUT }, + { CAPI_CMD_SET_CSP_IDX, + "csp_idx", + "Set CSP by index", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_SET_CSP_NAME, + "csp_name", + "Set CSP name, (default CSP used if not specified)", + ENGINE_CMD_FLAG_STRING }, + { CAPI_CMD_SET_CSP_TYPE, + "csp_type", + "Set CSP type, (default RSA_PROV_FULL)", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_LIST_CONTAINERS, + "list_containers", + "list container names", + ENGINE_CMD_FLAG_NO_INPUT }, + { CAPI_CMD_LIST_OPTIONS, + "list_options", + "Set list options (1=summary,2=friendly name, 4=full printout, 8=PEM output, 16=XXX, " + "32=private key info)", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_LOOKUP_METHOD, + "lookup_method", + "Set key lookup method (1=substring, 2=friendlyname, 3=container name)", + ENGINE_CMD_FLAG_NUMERIC }, + { CAPI_CMD_STORE_NAME, + "store_name", + "certificate store name, default \"MY\"", + ENGINE_CMD_FLAG_STRING }, + { CAPI_CMD_STORE_FLAGS, + "store_flags", + "Certificate store flags: 1 = system store", + ENGINE_CMD_FLAG_NUMERIC }, - {0, NULL, NULL, 0} + { 0, NULL, NULL, 0 } }; static int capi_idx = -1; @@ -283,7 +283,7 @@ static int rsa_capi_idx = -1; static int dsa_capi_idx = -1; static int cert_capi_idx = -1; -static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) +static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) { int ret = 1; CAPI_CTX *ctx; @@ -392,27 +392,24 @@ static int capi_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) BIO_free(out); return ret; - } static RSA_METHOD *capi_rsa_method = NULL; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA static DSA_METHOD *capi_dsa_method = NULL; -# endif +#endif static int use_aes_csp = 0; -static const WCHAR rsa_aes_cspname[] = - L"Microsoft Enhanced RSA and AES Cryptographic Provider"; -static const WCHAR rsa_enh_cspname[] = - L"Microsoft Enhanced Cryptographic Provider v1.0"; +static const WCHAR rsa_aes_cspname[] = L"Microsoft Enhanced RSA and AES Cryptographic Provider"; +static const WCHAR rsa_enh_cspname[] = L"Microsoft Enhanced Cryptographic Provider v1.0"; static int capi_init(ENGINE *e) { CAPI_CTX *ctx; const RSA_METHOD *ossl_rsa_meth; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA const DSA_METHOD *ossl_dsa_meth; -# endif +#endif HCRYPTPROV hprov; if (capi_idx < 0) { @@ -425,36 +422,36 @@ static int capi_init(ENGINE *e) /* Setup RSA_METHOD */ rsa_capi_idx = RSA_get_ex_new_index(0, NULL, NULL, NULL, 0); ossl_rsa_meth = RSA_PKCS1_OpenSSL(); - if ( !RSA_meth_set_pub_enc(capi_rsa_method, - RSA_meth_get_pub_enc(ossl_rsa_meth)) + if (!RSA_meth_set_pub_enc(capi_rsa_method, + RSA_meth_get_pub_enc(ossl_rsa_meth)) || !RSA_meth_set_pub_dec(capi_rsa_method, - RSA_meth_get_pub_dec(ossl_rsa_meth)) + RSA_meth_get_pub_dec(ossl_rsa_meth)) || !RSA_meth_set_priv_enc(capi_rsa_method, capi_rsa_priv_enc) || !RSA_meth_set_priv_dec(capi_rsa_method, capi_rsa_priv_dec) || !RSA_meth_set_mod_exp(capi_rsa_method, - RSA_meth_get_mod_exp(ossl_rsa_meth)) + RSA_meth_get_mod_exp(ossl_rsa_meth)) || !RSA_meth_set_bn_mod_exp(capi_rsa_method, - RSA_meth_get_bn_mod_exp(ossl_rsa_meth)) + RSA_meth_get_bn_mod_exp(ossl_rsa_meth)) || !RSA_meth_set_finish(capi_rsa_method, capi_rsa_free) || !RSA_meth_set_sign(capi_rsa_method, capi_rsa_sign)) { goto memerr; } -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA /* Setup DSA Method */ dsa_capi_idx = DSA_get_ex_new_index(0, NULL, NULL, NULL, 0); ossl_dsa_meth = DSA_OpenSSL(); - if ( !DSA_meth_set_sign(capi_dsa_method, capi_dsa_do_sign) + if (!DSA_meth_set_sign(capi_dsa_method, capi_dsa_do_sign) || !DSA_meth_set_verify(capi_dsa_method, - DSA_meth_get_verify(ossl_dsa_meth)) + DSA_meth_get_verify(ossl_dsa_meth)) || !DSA_meth_set_finish(capi_dsa_method, capi_dsa_free) || !DSA_meth_set_mod_exp(capi_dsa_method, - DSA_meth_get_mod_exp(ossl_dsa_meth)) + DSA_meth_get_mod_exp(ossl_dsa_meth)) || !DSA_meth_set_bn_mod_exp(capi_dsa_method, - DSA_meth_get_bn_mod_exp(ossl_dsa_meth))) { + DSA_meth_get_bn_mod_exp(ossl_dsa_meth))) { goto memerr; } -# endif +#endif } ctx = capi_ctx_new(); @@ -463,32 +460,30 @@ static int capi_init(ENGINE *e) ENGINE_set_ex_data(e, capi_idx, ctx); -# ifdef OPENSSL_CAPIENG_DIALOG +#ifdef OPENSSL_CAPIENG_DIALOG { HMODULE cryptui = LoadLibrary(TEXT("CRYPTUI.DLL")); HMODULE kernel = GetModuleHandle(TEXT("KERNEL32.DLL")); if (cryptui) - ctx->certselectdlg = - (CERTDLG) GetProcAddress(cryptui, - "CryptUIDlgSelectCertificateFromStore"); + ctx->certselectdlg = (CERTDLG)GetProcAddress(cryptui, + "CryptUIDlgSelectCertificateFromStore"); if (kernel) - ctx->getconswindow = - (GETCONSWIN) GetProcAddress(kernel, "GetConsoleWindow"); + ctx->getconswindow = (GETCONSWIN)GetProcAddress(kernel, "GetConsoleWindow"); if (cryptui && !OPENSSL_isservice()) ctx->client_cert_select = cert_select_dialog; } -# endif +#endif /* See if there is RSA+AES CSP */ if (CryptAcquireContextW(&hprov, NULL, rsa_aes_cspname, PROV_RSA_AES, - CRYPT_VERIFYCONTEXT)) { + CRYPT_VERIFYCONTEXT)) { use_aes_csp = 1; CryptReleaseContext(hprov, 0); } return 1; - memerr: +memerr: CAPIerr(CAPI_F_CAPI_INIT, ERR_R_MALLOC_FAILURE); return 0; @@ -499,10 +494,10 @@ static int capi_destroy(ENGINE *e) { RSA_meth_free(capi_rsa_method); capi_rsa_method = NULL; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA DSA_meth_free(capi_dsa_method); capi_dsa_method = NULL; -# endif +#endif ERR_unload_CAPI_strings(); return 1; } @@ -535,11 +530,11 @@ static int bind_capi(ENGINE *e) capi_rsa_method = RSA_meth_new("CryptoAPI RSA method", 0); if (capi_rsa_method == NULL) return 0; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA capi_dsa_method = DSA_meth_new("CryptoAPI DSA method", 0); if (capi_dsa_method == NULL) goto memerr; -# endif +#endif if (!ENGINE_set_id(e, engine_capi_id) || !ENGINE_set_name(e, engine_capi_name) || !ENGINE_set_flags(e, ENGINE_FLAGS_NO_REGISTER_ALL) @@ -547,29 +542,29 @@ static int bind_capi(ENGINE *e) || !ENGINE_set_finish_function(e, capi_finish) || !ENGINE_set_destroy_function(e, capi_destroy) || !ENGINE_set_RSA(e, capi_rsa_method) -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA || !ENGINE_set_DSA(e, capi_dsa_method) -# endif +#endif || !ENGINE_set_load_privkey_function(e, capi_load_privkey) || !ENGINE_set_load_ssl_client_cert_function(e, - capi_load_ssl_client_cert) + capi_load_ssl_client_cert) || !ENGINE_set_cmd_defns(e, capi_cmd_defns) || !ENGINE_set_ctrl_function(e, capi_ctrl)) goto memerr; ERR_load_CAPI_strings(); return 1; - memerr: +memerr: RSA_meth_free(capi_rsa_method); capi_rsa_method = NULL; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA DSA_meth_free(capi_dsa_method); capi_dsa_method = NULL; -# endif +#endif return 0; } -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE static int bind_helper(ENGINE *e, const char *id) { if (id && (strcmp(id, engine_capi_id) != 0)) @@ -581,7 +576,7 @@ static int bind_helper(ENGINE *e, const char *id) IMPLEMENT_DYNAMIC_CHECK_FN() IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) -# else +#else static ENGINE *engine_capi(void) { ENGINE *ret = ENGINE_new(); @@ -614,7 +609,7 @@ void engine_load_capi_int(void) */ ERR_pop_to_mark(); } -# endif +#endif static int lend_tobn(BIGNUM *bn, unsigned char *bin, int binlen) { @@ -663,7 +658,7 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY *key) goto err; } - bh = (BLOBHEADER *) pubkey; + bh = (BLOBHEADER *)pubkey; if (bh->bType != PUBLICKEYBLOB) { CAPIerr(CAPI_F_CAPI_GET_PKEY, CAPI_R_INVALID_PUBLIC_KEY_BLOB); goto err; @@ -673,12 +668,12 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY *key) DWORD rsa_modlen; BIGNUM *e = NULL, *n = NULL; unsigned char *rsa_modulus; - rp = (RSAPUBKEY *) (bh + 1); + rp = (RSAPUBKEY *)(bh + 1); if (rp->magic != 0x31415352) { char magstr[10]; BIO_snprintf(magstr, 10, "%lx", rp->magic); CAPIerr(CAPI_F_CAPI_GET_PKEY, - CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER); + CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER); ERR_add_error_data(2, "magic=0x", magstr); goto err; } @@ -713,18 +708,18 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY *key) EVP_PKEY_assign_RSA(ret, rkey); rkey = NULL; -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA } else if (bh->aiKeyAlg == CALG_DSS_SIGN) { DSSPUBKEY *dp; DWORD dsa_plen; unsigned char *btmp; BIGNUM *p, *q, *g, *pub_key; - dp = (DSSPUBKEY *) (bh + 1); + dp = (DSSPUBKEY *)(bh + 1); if (dp->magic != 0x31535344) { char magstr[10]; BIO_snprintf(magstr, 10, "%lx", dp->magic); CAPIerr(CAPI_F_CAPI_GET_PKEY, - CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER); + CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER); ERR_add_error_data(2, "magic=0x", magstr); goto err; } @@ -766,35 +761,34 @@ static EVP_PKEY *capi_get_pkey(ENGINE *eng, CAPI_KEY *key) EVP_PKEY_assign_DSA(ret, dkey); dkey = NULL; -# endif +#endif } else { char algstr[10]; BIO_snprintf(algstr, 10, "%ux", bh->aiKeyAlg); CAPIerr(CAPI_F_CAPI_GET_PKEY, - CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM); + CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM); ERR_add_error_data(2, "aiKeyAlg=0x", algstr); goto err; } - err: +err: OPENSSL_free(pubkey); if (!ret) { RSA_free(rkey); -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA DSA_free(dkey); -# endif +#endif } return ret; - memerr: +memerr: CAPIerr(CAPI_F_CAPI_GET_PKEY, ERR_R_MALLOC_FAILURE); goto err; - } static EVP_PKEY *capi_load_privkey(ENGINE *eng, const char *key_id, - UI_METHOD *ui_method, void *callback_data) + UI_METHOD *ui_method, void *callback_data) { CAPI_CTX *ctx; CAPI_KEY *key; @@ -816,20 +810,19 @@ static EVP_PKEY *capi_load_privkey(ENGINE *eng, const char *key_id, if (!ret) capi_free_key(key); return ret; - } /* CryptoAPI RSA operations */ int capi_rsa_priv_enc(int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, int padding) + unsigned char *to, RSA *rsa, int padding) { CAPIerr(CAPI_F_CAPI_RSA_PRIV_ENC, CAPI_R_FUNCTION_NOT_SUPPORTED); return -1; } int capi_rsa_sign(int dtype, const unsigned char *m, unsigned int m_len, - unsigned char *sigret, unsigned int *siglen, const RSA *rsa) + unsigned char *sigret, unsigned int *siglen, const RSA *rsa) { ALG_ID alg; HCRYPTHASH hash; @@ -873,14 +866,13 @@ int capi_rsa_sign(int dtype, const unsigned char *m, unsigned int m_len, case NID_md5_sha1: alg = CALG_SSL3_SHAMD5; break; - default: - { - char algstr[10]; - BIO_snprintf(algstr, 10, "%x", dtype); - CAPIerr(CAPI_F_CAPI_RSA_SIGN, CAPI_R_UNSUPPORTED_ALGORITHM_NID); - ERR_add_error_data(2, "NID=0x", algstr); - return -1; - } + default: { + char algstr[10]; + BIO_snprintf(algstr, 10, "%x", dtype); + CAPIerr(CAPI_F_CAPI_RSA_SIGN, CAPI_R_UNSUPPORTED_ALGORITHM_NID); + ERR_add_error_data(2, "NID=0x", algstr); + return -1; + } } /* Create the hash object */ @@ -917,14 +909,14 @@ int capi_rsa_sign(int dtype, const unsigned char *m, unsigned int m_len, /* Now cleanup */ - err: +err: CryptDestroyHash(hash); return ret; } int capi_rsa_priv_dec(int flen, const unsigned char *from, - unsigned char *to, RSA *rsa, int padding) + unsigned char *to, RSA *rsa, int padding) { int i; unsigned char *tmpbuf; @@ -955,14 +947,13 @@ int capi_rsa_priv_dec(int flen, const unsigned char *from, flags = CRYPT_DECRYPT_RSA_NO_PADDING_CHECK; break; #endif - default: - { - char errstr[10]; - BIO_snprintf(errstr, 10, "%d", padding); - CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_UNSUPPORTED_PADDING); - ERR_add_error_data(2, "padding=", errstr); - return -1; - } + default: { + char errstr[10]; + BIO_snprintf(errstr, 10, "%d", padding); + CAPIerr(CAPI_F_CAPI_RSA_PRIV_DEC, CAPI_R_UNSUPPORTED_PADDING); + ERR_add_error_data(2, "padding=", errstr); + return -1; + } } /* Create temp reverse order version of input */ @@ -999,11 +990,11 @@ static int capi_rsa_free(RSA *rsa) return 1; } -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA /* CryptoAPI DSA operations */ static DSA_SIG *capi_dsa_do_sign(const unsigned char *digest, int dlen, - DSA *dsa) + DSA *dsa) { HCRYPTHASH hash; DWORD slen; @@ -1064,7 +1055,7 @@ static DSA_SIG *capi_dsa_do_sign(const unsigned char *digest, int dlen, /* Now cleanup */ - err: +err: OPENSSL_cleanse(csigbuf, 40); CryptDestroyHash(hash); return ret; @@ -1078,10 +1069,10 @@ static int capi_dsa_free(DSA *dsa) DSA_set_ex_data(dsa, dsa_capi_idx, 0); return 1; } -# endif +#endif static void capi_vtrace(CAPI_CTX *ctx, int level, char *format, - va_list argptr) + va_list argptr) { BIO *out; @@ -1128,8 +1119,8 @@ static char *wide_to_asc(LPCWSTR wstr) len_1 = wcslen(wstr) + 1; if (len_1 > INT_MAX) { - CAPIerr(CAPI_F_WIDE_TO_ASC, CAPI_R_FUNCTION_NOT_SUPPORTED); - return NULL; + CAPIerr(CAPI_F_WIDE_TO_ASC, CAPI_R_FUNCTION_NOT_SUPPORTED); + return NULL; } len_0 = (int)len_1; /* WideCharToMultiByte expects int */ @@ -1152,7 +1143,7 @@ static char *wide_to_asc(LPCWSTR wstr) } static int capi_get_provname(CAPI_CTX *ctx, LPSTR *pname, DWORD *ptype, - DWORD idx) + DWORD idx) { DWORD len, err; LPTSTR name; @@ -1188,7 +1179,7 @@ static int capi_get_provname(CAPI_CTX *ctx, LPSTR *pname, DWORD *ptype, *pname = (char *)name; } CAPI_trace(ctx, "capi_get_provname, returned name=%s, type=%d\n", *pname, - *ptype); + *ptype); return 1; } @@ -1221,13 +1212,13 @@ static int capi_list_containers(CAPI_CTX *ctx, BIO *out) LPWSTR cspname = NULL; CAPI_trace(ctx, "Listing containers CSP=%s, type = %d\n", ctx->cspname, - ctx->csptype); + ctx->csptype); if (ctx->cspname != NULL) { if ((clen = MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, - NULL, 0))) { + NULL, 0))) { cspname = alloca(clen * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, (WCHAR *)cspname, - clen); + clen); } if (cspname == NULL) { CAPIerr(CAPI_F_CAPI_LIST_CONTAINERS, ERR_R_MALLOC_FAILURE); @@ -1236,14 +1227,14 @@ static int capi_list_containers(CAPI_CTX *ctx, BIO *out) } } if (!CryptAcquireContextW(&hprov, NULL, cspname, ctx->csptype, - CRYPT_VERIFYCONTEXT)) { + CRYPT_VERIFYCONTEXT)) { CAPIerr(CAPI_F_CAPI_LIST_CONTAINERS, - CAPI_R_CRYPTACQUIRECONTEXT_ERROR); + CAPI_R_CRYPTACQUIRECONTEXT_ERROR); capi_addlasterror(); return 0; } if (!CryptGetProvParam(hprov, PP_ENUMCONTAINERS, NULL, &buflen, - CRYPT_FIRST)) { + CRYPT_FIRST)) { CAPIerr(CAPI_F_CAPI_LIST_CONTAINERS, CAPI_R_ENUMCONTAINERS_ERROR); capi_addlasterror(); CryptReleaseContext(hprov, 0); @@ -1267,7 +1258,7 @@ static int capi_list_containers(CAPI_CTX *ctx, BIO *out) else flags = 0; if (!CryptGetProvParam(hprov, PP_ENUMCONTAINERS, (BYTE *)cname, - &clen, flags)) { + &clen, flags)) { err = GetLastError(); if (err == ERROR_NO_MORE_ITEMS) goto done; @@ -1276,18 +1267,18 @@ static int capi_list_containers(CAPI_CTX *ctx, BIO *out) goto err; } CAPI_trace(ctx, "Container name %s, len=%d, index=%d, flags=%d\n", - cname, clen, idx, flags); + cname, clen, idx, flags); if (!cname[0] && (clen == buflen)) { CAPI_trace(ctx, "Enumerate bug: using workaround\n"); goto done; } BIO_printf(out, "%lu. %s\n", idx, cname); } - err: +err: ret = 0; - done: +done: OPENSSL_free(cname); CryptReleaseContext(hprov, 0); @@ -1295,13 +1286,13 @@ static int capi_list_containers(CAPI_CTX *ctx, BIO *out) } static CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX *ctx, - PCCERT_CONTEXT cert) + PCCERT_CONTEXT cert) { DWORD len; CRYPT_KEY_PROV_INFO *pinfo; if (!CertGetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, - NULL, &len)) + NULL, &len)) return NULL; pinfo = OPENSSL_malloc(len); if (pinfo == NULL) { @@ -1309,9 +1300,9 @@ static CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX *ctx, return NULL; } if (!CertGetCertificateContextProperty(cert, CERT_KEY_PROV_INFO_PROP_ID, - pinfo, &len)) { + pinfo, &len)) { CAPIerr(CAPI_F_CAPI_GET_PROV_INFO, - CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO); + CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO); capi_addlasterror(); OPENSSL_free(pinfo); return NULL; @@ -1320,7 +1311,7 @@ static CRYPT_KEY_PROV_INFO *capi_get_prov_info(CAPI_CTX *ctx, } static void capi_dump_prov_info(CAPI_CTX *ctx, BIO *out, - CRYPT_KEY_PROV_INFO *pinfo) + CRYPT_KEY_PROV_INFO *pinfo) { char *provname = NULL, *contname = NULL; @@ -1335,10 +1326,10 @@ static void capi_dump_prov_info(CAPI_CTX *ctx, BIO *out, BIO_printf(out, " Private Key Info:\n"); BIO_printf(out, " Provider Name: %s, Provider Type %lu\n", provname, - pinfo->dwProvType); + pinfo->dwProvType); BIO_printf(out, " Container Name: %s, Key Type %lu\n", contname, - pinfo->dwKeySpec); - err: + pinfo->dwKeySpec); +err: OPENSSL_free(provname); OPENSSL_free(contname); } @@ -1350,13 +1341,13 @@ static char *capi_cert_get_fname(CAPI_CTX *ctx, PCCERT_CONTEXT cert) CAPI_trace(ctx, "capi_cert_get_fname\n"); if (!CertGetCertificateContextProperty(cert, CERT_FRIENDLY_NAME_PROP_ID, - NULL, &dlen)) + NULL, &dlen)) return NULL; wfname = OPENSSL_malloc(dlen); if (wfname == NULL) return NULL; if (CertGetCertificateContextProperty(cert, CERT_FRIENDLY_NAME_PROP_ID, - wfname, &dlen)) { + wfname, &dlen)) { char *fname = wide_to_asc(wfname); OPENSSL_free(wfname); return fname; @@ -1421,7 +1412,7 @@ static HCERTSTORE capi_open_store(CAPI_CTX *ctx, char *storename) CAPI_trace(ctx, "Opening certificate store %s\n", storename); hstore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, 0, - ctx->store_flags, storename); + ctx->store_flags, storename); if (!hstore) { CAPIerr(CAPI_F_CAPI_OPEN_STORE, CAPI_R_ERROR_OPENING_STORE); capi_addlasterror(); @@ -1462,13 +1453,13 @@ int capi_list_certs(CAPI_CTX *ctx, BIO *out, char *id) capi_dump_cert(ctx, out, cert); } } - err: +err: CertCloseStore(hstore, 0); return ret; } static PCCERT_CONTEXT capi_find_cert(CAPI_CTX *ctx, const char *id, - HCERTSTORE hstore) + HCERTSTORE hstore) { PCCERT_CONTEXT cert = NULL; char *fname = NULL; @@ -1476,7 +1467,7 @@ static PCCERT_CONTEXT capi_find_cert(CAPI_CTX *ctx, const char *id, switch (ctx->lookup_method) { case CAPI_LU_SUBSTR: return CertFindCertificateInStore(hstore, X509_ASN_ENCODING, 0, - CERT_FIND_SUBJECT_STR_A, id, NULL); + CERT_FIND_SUBJECT_STR_A, id, NULL); case CAPI_LU_FNAME: for (;;) { cert = CertEnumCertificatesInStore(hstore, cert); @@ -1499,8 +1490,8 @@ static PCCERT_CONTEXT capi_find_cert(CAPI_CTX *ctx, const char *id, } static CAPI_KEY *capi_get_key(CAPI_CTX *ctx, const WCHAR *contname, - const WCHAR *provname, DWORD ptype, - DWORD keyspec) + const WCHAR *provname, DWORD ptype, + DWORD keyspec) { DWORD dwFlags = 0; CAPI_KEY *key = OPENSSL_malloc(sizeof(*key)); @@ -1508,8 +1499,7 @@ static CAPI_KEY *capi_get_key(CAPI_CTX *ctx, const WCHAR *contname, if (key == NULL) return NULL; /* If PROV_RSA_AES supported use it instead */ - if (ptype == PROV_RSA_FULL && use_aes_csp && - wcscmp(provname, rsa_enh_cspname) == 0) { + if (ptype == PROV_RSA_FULL && use_aes_csp && wcscmp(provname, rsa_enh_cspname) == 0) { provname = rsa_aes_cspname; ptype = PROV_RSA_AES; } @@ -1522,14 +1512,14 @@ static CAPI_KEY *capi_get_key(CAPI_CTX *ctx, const WCHAR *contname, char *_provname = wide_to_asc(provname); CAPI_trace(ctx, "capi_get_key, contname=%s, provname=%s, type=%d\n", - _contname, _provname, ptype); + _contname, _provname, ptype); OPENSSL_free(_provname); OPENSSL_free(_contname); } if (ctx->store_flags & CERT_SYSTEM_STORE_LOCAL_MACHINE) dwFlags = CRYPT_MACHINE_KEYSET; if (!CryptAcquireContextW(&key->hprov, contname, provname, ptype, - dwFlags)) { + dwFlags)) { CAPIerr(CAPI_F_CAPI_GET_KEY, CAPI_R_CRYPTACQUIRECONTEXT_ERROR); capi_addlasterror(); goto err; @@ -1544,7 +1534,7 @@ static CAPI_KEY *capi_get_key(CAPI_CTX *ctx, const WCHAR *contname, key->pcert = NULL; return key; - err: +err: OPENSSL_free(key); return NULL; } @@ -1558,7 +1548,7 @@ static CAPI_KEY *capi_get_cert_key(CAPI_CTX *ctx, PCCERT_CONTEXT cert) if (pinfo != NULL) key = capi_get_key(ctx, pinfo->pwszContainerName, pinfo->pwszProvName, - pinfo->dwProvType, pinfo->dwKeySpec); + pinfo->dwProvType, pinfo->dwKeySpec); OPENSSL_free(pinfo); return key; @@ -1584,23 +1574,14 @@ CAPI_KEY *capi_find_key(CAPI_CTX *ctx, const char *id) CertCloseStore(hstore, 0); break; - case CAPI_LU_CONTNAME: - { - WCHAR *contname, *provname; - DWORD len; + case CAPI_LU_CONTNAME: { + WCHAR *contname, *provname; + DWORD len; - if ((len = MultiByteToWideChar(CP_ACP, 0, id, -1, NULL, 0)) && - (contname = alloca(len * sizeof(WCHAR)), - MultiByteToWideChar(CP_ACP, 0, id, -1, contname, len)) && - (len = MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, - NULL, 0)) && - (provname = alloca(len * sizeof(WCHAR)), - MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, - provname, len))) - key = capi_get_key(ctx, contname, provname, - ctx->csptype, ctx->keytype); - } - break; + if ((len = MultiByteToWideChar(CP_ACP, 0, id, -1, NULL, 0)) && (contname = alloca(len * sizeof(WCHAR)), MultiByteToWideChar(CP_ACP, 0, id, -1, contname, len)) && (len = MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, NULL, 0)) && (provname = alloca(len * sizeof(WCHAR)), MultiByteToWideChar(CP_ACP, 0, ctx->cspname, -1, provname, len))) + key = capi_get_key(ctx, contname, provname, + ctx->csptype, ctx->keytype); + } break; } return key; @@ -1630,8 +1611,7 @@ static CAPI_CTX *capi_ctx_new(void) ctx->csptype = PROV_RSA_FULL; ctx->dump_flags = CAPI_DMP_SUMMARY | CAPI_DMP_FNAME; ctx->keytype = AT_KEYEXCHANGE; - ctx->store_flags = CERT_STORE_OPEN_EXISTING_FLAG | - CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER; + ctx->store_flags = CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_CURRENT_USER; ctx->lookup_method = CAPI_LU_SUBSTR; ctx->client_cert_select = cert_select_simple; return ctx; @@ -1650,7 +1630,7 @@ static void capi_ctx_free(CAPI_CTX *ctx) } static int capi_ctx_set_provname(CAPI_CTX *ctx, LPSTR pname, DWORD type, - int check) + int check) { LPSTR tmpcspname; @@ -1664,10 +1644,9 @@ static int capi_ctx_set_provname(CAPI_CTX *ctx, LPSTR pname, DWORD type, name = alloca(len * sizeof(WCHAR)); MultiByteToWideChar(CP_ACP, 0, pname, -1, (WCHAR *)name, len); } - if (name == NULL || !CryptAcquireContextW(&hprov, NULL, name, type, - CRYPT_VERIFYCONTEXT)) { + if (name == NULL || !CryptAcquireContextW(&hprov, NULL, name, type, CRYPT_VERIFYCONTEXT)) { CAPIerr(CAPI_F_CAPI_CTX_SET_PROVNAME, - CAPI_R_CRYPTACQUIRECONTEXT_ERROR); + CAPI_R_CRYPTACQUIRECONTEXT_ERROR); capi_addlasterror(); return 0; } @@ -1712,10 +1691,10 @@ static int cert_issuer_match(STACK_OF(X509_NAME) *ca_dn, X509 *x) } static int capi_load_ssl_client_cert(ENGINE *e, SSL *ssl, - STACK_OF(X509_NAME) *ca_dn, X509 **pcert, - EVP_PKEY **pkey, STACK_OF(X509) **pother, - UI_METHOD *ui_method, - void *callback_data) + STACK_OF(X509_NAME) *ca_dn, X509 **pcert, + EVP_PKEY **pkey, STACK_OF(X509) **pother, + UI_METHOD *ui_method, + void *callback_data) { STACK_OF(X509) *certs = NULL; X509 *x; @@ -1810,7 +1789,6 @@ static int capi_load_ssl_client_cert(ENGINE *e, SSL *ssl, X509_set_ex_data(*pcert, cert_capi_idx, NULL); return 1; - } /* Simple client cert selection function: always select first */ @@ -1820,7 +1798,7 @@ static int cert_select_simple(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) return 0; } -# ifdef OPENSSL_CAPIENG_DIALOG +#ifdef OPENSSL_CAPIENG_DIALOG /* * More complex cert selection function, using standard function @@ -1832,15 +1810,16 @@ static int cert_select_simple(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) * versions of headers. */ -# ifndef CRYPTUI_SELECT_LOCATION_COLUMN -# define CRYPTUI_SELECT_LOCATION_COLUMN 0x000000010 -# define CRYPTUI_SELECT_INTENDEDUSE_COLUMN 0x000000004 -# endif +#ifndef CRYPTUI_SELECT_LOCATION_COLUMN +#define CRYPTUI_SELECT_LOCATION_COLUMN 0x000000010 +#define CRYPTUI_SELECT_INTENDEDUSE_COLUMN 0x000000004 +#endif -# define dlg_title L"OpenSSL Application SSL Client Certificate Selection" -# define dlg_prompt L"Select a certificate to use for authentication" -# define dlg_columns CRYPTUI_SELECT_LOCATION_COLUMN \ - |CRYPTUI_SELECT_INTENDEDUSE_COLUMN +#define dlg_title L"OpenSSL Application SSL Client Certificate Selection" +#define dlg_prompt L"Select a certificate to use for authentication" +#define dlg_columns \ + CRYPTUI_SELECT_LOCATION_COLUMN \ + | CRYPTUI_SELECT_INTENDEDUSE_COLUMN static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) { @@ -1856,7 +1835,7 @@ static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) ctx = ENGINE_get_ex_data(e, capi_idx); /* Create an in memory store of certificates */ dstore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, - CERT_STORE_CREATE_NEW_FLAG, NULL); + CERT_STORE_CREATE_NEW_FLAG, NULL); if (!dstore) { CAPIerr(CAPI_F_CERT_SELECT_DIALOG, CAPI_R_ERROR_CREATING_STORE); capi_addlasterror(); @@ -1868,12 +1847,11 @@ static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) key = X509_get_ex_data(x, cert_capi_idx); if (!CertAddCertificateContextToStore(dstore, key->pcert, - CERT_STORE_ADD_NEW, NULL)) { + CERT_STORE_ADD_NEW, NULL)) { CAPIerr(CAPI_F_CERT_SELECT_DIALOG, CAPI_R_ERROR_ADDING_CERT); capi_addlasterror(); goto err; } - } hwnd = GetForegroundWindow(); if (!hwnd) @@ -1882,46 +1860,44 @@ static int cert_select_dialog(ENGINE *e, SSL *ssl, STACK_OF(X509) *certs) hwnd = ctx->getconswindow(); /* Call dialog to select one */ cert = ctx->certselectdlg(dstore, hwnd, dlg_title, dlg_prompt, - dlg_columns, 0, NULL); + dlg_columns, 0, NULL); /* Find matching cert from list */ if (cert) { for (i = 0; i < sk_X509_num(certs); i++) { x = sk_X509_value(certs, i); key = X509_get_ex_data(x, cert_capi_idx); - if (CertCompareCertificate - (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, cert->pCertInfo, - key->pcert->pCertInfo)) { + if (CertCompareCertificate(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, cert->pCertInfo, + key->pcert->pCertInfo)) { idx = i; break; } } } - err: +err: if (dstore) CertCloseStore(dstore, 0); return idx; - } -# endif +#endif -#else /* !__COMPILE_CAPIENG */ -# include <openssl/engine.h> -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#else /* !__COMPILE_CAPIENG */ +#include <openssl/engine.h> +#ifndef OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_EXPORT - int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); +int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); OPENSSL_EXPORT - int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) +int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; } IMPLEMENT_DYNAMIC_CHECK_FN() -# else +#else void engine_load_capi_int(void); void engine_load_capi_int(void) { } -# endif +#endif #endif diff --git a/engines/e_capi_err.c b/engines/e_capi_err.c index 1d7636562e9b..ed3feac0e104 100644 --- a/engines/e_capi_err.c +++ b/engines/e_capi_err.c @@ -14,46 +14,46 @@ #ifndef OPENSSL_NO_ERR static ERR_STRING_DATA CAPI_str_reasons[] = { - {ERR_PACK(0, 0, CAPI_R_CANT_CREATE_HASH_OBJECT), "cant create hash object"}, - {ERR_PACK(0, 0, CAPI_R_CANT_FIND_CAPI_CONTEXT), "cant find capi context"}, - {ERR_PACK(0, 0, CAPI_R_CANT_GET_KEY), "cant get key"}, - {ERR_PACK(0, 0, CAPI_R_CANT_SET_HASH_VALUE), "cant set hash value"}, - {ERR_PACK(0, 0, CAPI_R_CRYPTACQUIRECONTEXT_ERROR), - "cryptacquirecontext error"}, - {ERR_PACK(0, 0, CAPI_R_CRYPTENUMPROVIDERS_ERROR), - "cryptenumproviders error"}, - {ERR_PACK(0, 0, CAPI_R_DECRYPT_ERROR), "decrypt error"}, - {ERR_PACK(0, 0, CAPI_R_ENGINE_NOT_INITIALIZED), "engine not initialized"}, - {ERR_PACK(0, 0, CAPI_R_ENUMCONTAINERS_ERROR), "enumcontainers error"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_ADDING_CERT), "error adding cert"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_CREATING_STORE), "error creating store"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_GETTING_FRIENDLY_NAME), - "error getting friendly name"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO), - "error getting key provider info"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_OPENING_STORE), "error opening store"}, - {ERR_PACK(0, 0, CAPI_R_ERROR_SIGNING_HASH), "error signing hash"}, - {ERR_PACK(0, 0, CAPI_R_FILE_OPEN_ERROR), "file open error"}, - {ERR_PACK(0, 0, CAPI_R_FUNCTION_NOT_SUPPORTED), "function not supported"}, - {ERR_PACK(0, 0, CAPI_R_GETUSERKEY_ERROR), "getuserkey error"}, - {ERR_PACK(0, 0, CAPI_R_INVALID_DIGEST_LENGTH), "invalid digest length"}, - {ERR_PACK(0, 0, CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER), - "invalid dsa public key blob magic number"}, - {ERR_PACK(0, 0, CAPI_R_INVALID_LOOKUP_METHOD), "invalid lookup method"}, - {ERR_PACK(0, 0, CAPI_R_INVALID_PUBLIC_KEY_BLOB), "invalid public key blob"}, - {ERR_PACK(0, 0, CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER), - "invalid rsa public key blob magic number"}, - {ERR_PACK(0, 0, CAPI_R_PUBKEY_EXPORT_ERROR), "pubkey export error"}, - {ERR_PACK(0, 0, CAPI_R_PUBKEY_EXPORT_LENGTH_ERROR), - "pubkey export length error"}, - {ERR_PACK(0, 0, CAPI_R_UNKNOWN_COMMAND), "unknown command"}, - {ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_ALGORITHM_NID), - "unsupported algorithm nid"}, - {ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_PADDING), "unsupported padding"}, - {ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM), - "unsupported public key algorithm"}, - {ERR_PACK(0, 0, CAPI_R_WIN32_ERROR), "win32 error"}, - {0, NULL} + { ERR_PACK(0, 0, CAPI_R_CANT_CREATE_HASH_OBJECT), "cant create hash object" }, + { ERR_PACK(0, 0, CAPI_R_CANT_FIND_CAPI_CONTEXT), "cant find capi context" }, + { ERR_PACK(0, 0, CAPI_R_CANT_GET_KEY), "cant get key" }, + { ERR_PACK(0, 0, CAPI_R_CANT_SET_HASH_VALUE), "cant set hash value" }, + { ERR_PACK(0, 0, CAPI_R_CRYPTACQUIRECONTEXT_ERROR), + "cryptacquirecontext error" }, + { ERR_PACK(0, 0, CAPI_R_CRYPTENUMPROVIDERS_ERROR), + "cryptenumproviders error" }, + { ERR_PACK(0, 0, CAPI_R_DECRYPT_ERROR), "decrypt error" }, + { ERR_PACK(0, 0, CAPI_R_ENGINE_NOT_INITIALIZED), "engine not initialized" }, + { ERR_PACK(0, 0, CAPI_R_ENUMCONTAINERS_ERROR), "enumcontainers error" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_ADDING_CERT), "error adding cert" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_CREATING_STORE), "error creating store" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_GETTING_FRIENDLY_NAME), + "error getting friendly name" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO), + "error getting key provider info" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_OPENING_STORE), "error opening store" }, + { ERR_PACK(0, 0, CAPI_R_ERROR_SIGNING_HASH), "error signing hash" }, + { ERR_PACK(0, 0, CAPI_R_FILE_OPEN_ERROR), "file open error" }, + { ERR_PACK(0, 0, CAPI_R_FUNCTION_NOT_SUPPORTED), "function not supported" }, + { ERR_PACK(0, 0, CAPI_R_GETUSERKEY_ERROR), "getuserkey error" }, + { ERR_PACK(0, 0, CAPI_R_INVALID_DIGEST_LENGTH), "invalid digest length" }, + { ERR_PACK(0, 0, CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER), + "invalid dsa public key blob magic number" }, + { ERR_PACK(0, 0, CAPI_R_INVALID_LOOKUP_METHOD), "invalid lookup method" }, + { ERR_PACK(0, 0, CAPI_R_INVALID_PUBLIC_KEY_BLOB), "invalid public key blob" }, + { ERR_PACK(0, 0, CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER), + "invalid rsa public key blob magic number" }, + { ERR_PACK(0, 0, CAPI_R_PUBKEY_EXPORT_ERROR), "pubkey export error" }, + { ERR_PACK(0, 0, CAPI_R_PUBKEY_EXPORT_LENGTH_ERROR), + "pubkey export length error" }, + { ERR_PACK(0, 0, CAPI_R_UNKNOWN_COMMAND), "unknown command" }, + { ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_ALGORITHM_NID), + "unsupported algorithm nid" }, + { ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_PADDING), "unsupported padding" }, + { ERR_PACK(0, 0, CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM), + "unsupported public key algorithm" }, + { ERR_PACK(0, 0, CAPI_R_WIN32_ERROR), "win32 error" }, + { 0, NULL } }; #endif diff --git a/engines/e_capi_err.h b/engines/e_capi_err.h index cd80c9be89f1..4240c36e03df 100644 --- a/engines/e_capi_err.h +++ b/engines/e_capi_err.h @@ -9,48 +9,46 @@ */ #ifndef OSSL_E_CAPI_ERR_H -# define OSSL_E_CAPI_ERR_H -# pragma once +#define OSSL_E_CAPI_ERR_H +#pragma once -# include <openssl/opensslconf.h> -# include <openssl/symhacks.h> - - -# define CAPIerr(f, r) ERR_CAPI_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) +#include <openssl/opensslconf.h> +#include <openssl/symhacks.h> +#define CAPIerr(f, r) ERR_CAPI_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) /* * CAPI reason codes. */ -# define CAPI_R_CANT_CREATE_HASH_OBJECT 100 -# define CAPI_R_CANT_FIND_CAPI_CONTEXT 101 -# define CAPI_R_CANT_GET_KEY 102 -# define CAPI_R_CANT_SET_HASH_VALUE 103 -# define CAPI_R_CRYPTACQUIRECONTEXT_ERROR 104 -# define CAPI_R_CRYPTENUMPROVIDERS_ERROR 105 -# define CAPI_R_DECRYPT_ERROR 106 -# define CAPI_R_ENGINE_NOT_INITIALIZED 107 -# define CAPI_R_ENUMCONTAINERS_ERROR 108 -# define CAPI_R_ERROR_ADDING_CERT 109 -# define CAPI_R_ERROR_CREATING_STORE 110 -# define CAPI_R_ERROR_GETTING_FRIENDLY_NAME 111 -# define CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO 112 -# define CAPI_R_ERROR_OPENING_STORE 113 -# define CAPI_R_ERROR_SIGNING_HASH 114 -# define CAPI_R_FILE_OPEN_ERROR 115 -# define CAPI_R_FUNCTION_NOT_SUPPORTED 116 -# define CAPI_R_GETUSERKEY_ERROR 117 -# define CAPI_R_INVALID_DIGEST_LENGTH 118 -# define CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER 119 -# define CAPI_R_INVALID_LOOKUP_METHOD 120 -# define CAPI_R_INVALID_PUBLIC_KEY_BLOB 121 -# define CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER 122 -# define CAPI_R_PUBKEY_EXPORT_ERROR 123 -# define CAPI_R_PUBKEY_EXPORT_LENGTH_ERROR 124 -# define CAPI_R_UNKNOWN_COMMAND 125 -# define CAPI_R_UNSUPPORTED_ALGORITHM_NID 126 -# define CAPI_R_UNSUPPORTED_PADDING 127 -# define CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM 128 -# define CAPI_R_WIN32_ERROR 129 +#define CAPI_R_CANT_CREATE_HASH_OBJECT 100 +#define CAPI_R_CANT_FIND_CAPI_CONTEXT 101 +#define CAPI_R_CANT_GET_KEY 102 +#define CAPI_R_CANT_SET_HASH_VALUE 103 +#define CAPI_R_CRYPTACQUIRECONTEXT_ERROR 104 +#define CAPI_R_CRYPTENUMPROVIDERS_ERROR 105 +#define CAPI_R_DECRYPT_ERROR 106 +#define CAPI_R_ENGINE_NOT_INITIALIZED 107 +#define CAPI_R_ENUMCONTAINERS_ERROR 108 +#define CAPI_R_ERROR_ADDING_CERT 109 +#define CAPI_R_ERROR_CREATING_STORE 110 +#define CAPI_R_ERROR_GETTING_FRIENDLY_NAME 111 +#define CAPI_R_ERROR_GETTING_KEY_PROVIDER_INFO 112 +#define CAPI_R_ERROR_OPENING_STORE 113 +#define CAPI_R_ERROR_SIGNING_HASH 114 +#define CAPI_R_FILE_OPEN_ERROR 115 +#define CAPI_R_FUNCTION_NOT_SUPPORTED 116 +#define CAPI_R_GETUSERKEY_ERROR 117 +#define CAPI_R_INVALID_DIGEST_LENGTH 118 +#define CAPI_R_INVALID_DSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER 119 +#define CAPI_R_INVALID_LOOKUP_METHOD 120 +#define CAPI_R_INVALID_PUBLIC_KEY_BLOB 121 +#define CAPI_R_INVALID_RSA_PUBLIC_KEY_BLOB_MAGIC_NUMBER 122 +#define CAPI_R_PUBKEY_EXPORT_ERROR 123 +#define CAPI_R_PUBKEY_EXPORT_LENGTH_ERROR 124 +#define CAPI_R_UNKNOWN_COMMAND 125 +#define CAPI_R_UNSUPPORTED_ALGORITHM_NID 126 +#define CAPI_R_UNSUPPORTED_PADDING 127 +#define CAPI_R_UNSUPPORTED_PUBLIC_KEY_ALGORITHM 128 +#define CAPI_R_WIN32_ERROR 129 #endif diff --git a/engines/e_dasync.c b/engines/e_dasync.c index 329d618f5552..311da64b8979 100644 --- a/engines/e_dasync.c +++ b/engines/e_dasync.c @@ -1,5 +1,5 @@ /* - * Copyright 2015-2024 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2015-2026 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -13,14 +13,14 @@ /* * SHA-1 low level APIs are deprecated for public use, but still ok for * internal use. Note, that due to symbols not being exported, only the - * #defines and strucures can be accessed, in this case SHA_CBLOCK and + * #defines and structures can be accessed, in this case SHA_CBLOCK and * sizeof(SHA_CTX). */ #include "internal/deprecated.h" #include <openssl/opensslconf.h> #if defined(_WIN32) -# include <windows.h> +#include <windows.h> #endif #include <stdio.h> @@ -38,38 +38,38 @@ #include <openssl/modes.h> #if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS) -# undef ASYNC_POSIX -# define ASYNC_POSIX -# include <unistd.h> +#undef ASYNC_POSIX +#define ASYNC_POSIX +#include <unistd.h> #elif defined(_WIN32) -# undef ASYNC_WIN -# define ASYNC_WIN +#undef ASYNC_WIN +#define ASYNC_WIN #endif +/* clang-format off */ #include "e_dasync_err.c" +/* clang-format on */ /* Engine Id and Name */ static const char *engine_dasync_id = "dasync"; static const char *engine_dasync_name = "Dummy Async engine support"; - /* Engine Lifetime functions */ static int dasync_destroy(ENGINE *e); static int dasync_init(ENGINE *e); static int dasync_finish(ENGINE *e); void engine_load_dasync_int(void); - /* Set up digests. Just SHA1 for now */ static int dasync_digests(ENGINE *e, const EVP_MD **digest, - const int **nids, int nid); + const int **nids, int nid); static void dummy_pause_job(void); /* SHA1 */ static int dasync_sha1_init(EVP_MD_CTX *ctx); static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md); /* @@ -106,7 +106,7 @@ static int dasync_digest_nids(const int **nids) /* RSA */ static int dasync_pkey(ENGINE *e, EVP_PKEY_METHOD **pmeth, - const int **pnids, int nid); + const int **pnids, int nid); static int dasync_rsa_init(EVP_PKEY_CTX *ctx); static void dasync_rsa_cleanup(EVP_PKEY_CTX *ctx); @@ -116,15 +116,15 @@ static int dasync_rsa_keygen_init(EVP_PKEY_CTX *ctx); static int dasync_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey); static int dasync_rsa_encrypt_init(EVP_PKEY_CTX *ctx); static int dasync_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen); + size_t *outlen, const unsigned char *in, + size_t inlen); static int dasync_rsa_decrypt_init(EVP_PKEY_CTX *ctx); static int dasync_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen); + size_t *outlen, const unsigned char *in, + size_t inlen); static int dasync_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2); static int dasync_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, - const char *value); + const char *value); static EVP_PKEY_METHOD *dasync_rsa; static const EVP_PKEY_METHOD *dasync_rsa_orig; @@ -132,31 +132,31 @@ static const EVP_PKEY_METHOD *dasync_rsa_orig; /* AES */ static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr); + void *ptr); static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *iv, int enc); static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); + const unsigned char *in, size_t inl); static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx); static int dasync_aes256_ctr_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr); + void *ptr); static int dasync_aes256_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *iv, int enc); static int dasync_aes256_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); + const unsigned char *in, size_t inl); static int dasync_aes256_ctr_cleanup(EVP_CIPHER_CTX *ctx); static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, - int arg, void *ptr); + int arg, void *ptr); static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, - int enc); + const unsigned char *key, + const unsigned char *iv, + int enc); static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, - unsigned char *out, - const unsigned char *in, - size_t inl); + unsigned char *out, + const unsigned char *in, + size_t inl); static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx); struct dasync_pipeline_ctx { @@ -214,7 +214,7 @@ static void destroy_ciphers(void) } static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid); + const int **nids, int nid); static int dasync_cipher_nids[] = { NID_aes_128_cbc, @@ -229,20 +229,21 @@ static int bind_dasync(ENGINE *e) ; if ((dasync_rsa_orig = EVP_PKEY_meth_find(EVP_PKEY_RSA)) == NULL || (dasync_rsa = EVP_PKEY_meth_new(EVP_PKEY_RSA, - EVP_PKEY_FLAG_AUTOARGLEN)) == NULL) + EVP_PKEY_FLAG_AUTOARGLEN)) + == NULL) return 0; EVP_PKEY_meth_set_init(dasync_rsa, dasync_rsa_init); EVP_PKEY_meth_set_cleanup(dasync_rsa, dasync_rsa_cleanup); EVP_PKEY_meth_set_paramgen(dasync_rsa, dasync_rsa_paramgen_init, - dasync_rsa_paramgen); + dasync_rsa_paramgen); EVP_PKEY_meth_set_keygen(dasync_rsa, dasync_rsa_keygen_init, - dasync_rsa_keygen); + dasync_rsa_keygen); EVP_PKEY_meth_set_encrypt(dasync_rsa, dasync_rsa_encrypt_init, - dasync_rsa_encrypt); + dasync_rsa_encrypt); EVP_PKEY_meth_set_decrypt(dasync_rsa, dasync_rsa_decrypt_init, - dasync_rsa_decrypt); + dasync_rsa_decrypt); EVP_PKEY_meth_set_ctrl(dasync_rsa, dasync_rsa_ctrl, - dasync_rsa_ctrl_str); + dasync_rsa_ctrl_str); /* Ensure the dasync error handling is set up */ ERR_load_DASYNC_strings(); @@ -268,7 +269,7 @@ static int bind_dasync(ENGINE *e) || !EVP_MD_meth_set_result_size(_hidden_sha1_md, SHA_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(_hidden_sha1_md, SHA_CBLOCK) || !EVP_MD_meth_set_app_datasize(_hidden_sha1_md, - sizeof(EVP_MD *) + sizeof(SHA_CTX)) + sizeof(EVP_MD *) + sizeof(SHA_CTX)) || !EVP_MD_meth_set_flags(_hidden_sha1_md, EVP_MD_FLAG_DIGALGID_ABSENT) || !EVP_MD_meth_set_init(_hidden_sha1_md, dasync_sha1_init) || !EVP_MD_meth_set_update(_hidden_sha1_md, dasync_sha1_update) @@ -278,75 +279,75 @@ static int bind_dasync(ENGINE *e) } _hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc, - 16 /* block size */, - 16 /* key len */); + 16 /* block size */, + 16 /* key len */); if (_hidden_aes_128_cbc == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16) - || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc, - EVP_CIPH_FLAG_DEFAULT_ASN1 - | EVP_CIPH_CBC_MODE - | EVP_CIPH_FLAG_PIPELINE - | EVP_CIPH_CUSTOM_COPY) - || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc, - dasync_aes128_init_key) - || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc, - dasync_aes128_cbc_cipher) - || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc, - dasync_aes128_cbc_cleanup) - || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc, - dasync_aes128_cbc_ctrl) - || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc, - sizeof(struct dasync_pipeline_ctx))) { + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc, 16) + || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc, + EVP_CIPH_FLAG_DEFAULT_ASN1 + | EVP_CIPH_CBC_MODE + | EVP_CIPH_FLAG_PIPELINE + | EVP_CIPH_CUSTOM_COPY) + || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc, + dasync_aes128_init_key) + || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc, + dasync_aes128_cbc_cipher) + || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc, + dasync_aes128_cbc_cleanup) + || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc, + dasync_aes128_cbc_ctrl) + || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc, + sizeof(struct dasync_pipeline_ctx))) { EVP_CIPHER_meth_free(_hidden_aes_128_cbc); _hidden_aes_128_cbc = NULL; } _hidden_aes_256_ctr = EVP_CIPHER_meth_new(NID_aes_256_ctr, - 1 /* block size */, - 32 /* key len */); + 1 /* block size */, + 32 /* key len */); if (_hidden_aes_256_ctr == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_256_ctr,16) - || !EVP_CIPHER_meth_set_flags(_hidden_aes_256_ctr, - EVP_CIPH_FLAG_DEFAULT_ASN1 - | EVP_CIPH_CTR_MODE - | EVP_CIPH_FLAG_PIPELINE - | EVP_CIPH_CUSTOM_COPY) - || !EVP_CIPHER_meth_set_init(_hidden_aes_256_ctr, - dasync_aes256_init_key) - || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_256_ctr, - dasync_aes256_ctr_cipher) - || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_256_ctr, - dasync_aes256_ctr_cleanup) - || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_256_ctr, - dasync_aes256_ctr_ctrl) - || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_256_ctr, - sizeof(struct dasync_pipeline_ctx))) { + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_256_ctr, 16) + || !EVP_CIPHER_meth_set_flags(_hidden_aes_256_ctr, + EVP_CIPH_FLAG_DEFAULT_ASN1 + | EVP_CIPH_CTR_MODE + | EVP_CIPH_FLAG_PIPELINE + | EVP_CIPH_CUSTOM_COPY) + || !EVP_CIPHER_meth_set_init(_hidden_aes_256_ctr, + dasync_aes256_init_key) + || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_256_ctr, + dasync_aes256_ctr_cipher) + || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_256_ctr, + dasync_aes256_ctr_cleanup) + || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_256_ctr, + dasync_aes256_ctr_ctrl) + || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_256_ctr, + sizeof(struct dasync_pipeline_ctx))) { EVP_CIPHER_meth_free(_hidden_aes_256_ctr); _hidden_aes_256_ctr = NULL; } _hidden_aes_128_cbc_hmac_sha1 = EVP_CIPHER_meth_new( - NID_aes_128_cbc_hmac_sha1, - 16 /* block size */, - 16 /* key len */); + NID_aes_128_cbc_hmac_sha1, + 16 /* block size */, + 16 /* key len */); if (_hidden_aes_128_cbc_hmac_sha1 == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16) - || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1, - EVP_CIPH_CBC_MODE - | EVP_CIPH_FLAG_DEFAULT_ASN1 - | EVP_CIPH_FLAG_AEAD_CIPHER - | EVP_CIPH_FLAG_PIPELINE - | EVP_CIPH_CUSTOM_COPY) - || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1, - dasync_aes128_cbc_hmac_sha1_init_key) - || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1, - dasync_aes128_cbc_hmac_sha1_cipher) - || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1, - dasync_aes128_cbc_hmac_sha1_cleanup) - || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1, - dasync_aes128_cbc_hmac_sha1_ctrl) - || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1, - sizeof(struct dasync_pipeline_ctx))) { + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1, 16) + || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1, + EVP_CIPH_CBC_MODE + | EVP_CIPH_FLAG_DEFAULT_ASN1 + | EVP_CIPH_FLAG_AEAD_CIPHER + | EVP_CIPH_FLAG_PIPELINE + | EVP_CIPH_CUSTOM_COPY) + || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1, + dasync_aes128_cbc_hmac_sha1_init_key) + || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1, + dasync_aes128_cbc_hmac_sha1_cipher) + || !EVP_CIPHER_meth_set_cleanup(_hidden_aes_128_cbc_hmac_sha1, + dasync_aes128_cbc_hmac_sha1_cleanup) + || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1, + dasync_aes128_cbc_hmac_sha1_ctrl) + || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1, + sizeof(struct dasync_pipeline_ctx))) { EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1); _hidden_aes_128_cbc_hmac_sha1 = NULL; } @@ -364,7 +365,7 @@ static void destroy_pkey(void) dasync_rsa = NULL; } -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE static int bind_helper(ENGINE *e, const char *id) { if (id && (strcmp(id, engine_dasync_id) != 0)) @@ -375,8 +376,8 @@ static int bind_helper(ENGINE *e, const char *id) } IMPLEMENT_DYNAMIC_CHECK_FN() - IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) -# endif +IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) +#endif static ENGINE *engine_dasync(void) { @@ -415,13 +416,11 @@ static int dasync_init(ENGINE *e) return 1; } - static int dasync_finish(ENGINE *e) { return 1; } - static int dasync_destroy(ENGINE *e) { destroy_digests(); @@ -432,7 +431,7 @@ static int dasync_destroy(ENGINE *e) } static int dasync_pkey(ENGINE *e, EVP_PKEY_METHOD **pmeth, - const int **pnids, int nid) + const int **pnids, int nid) { static const int rnid = EVP_PKEY_RSA; @@ -451,7 +450,7 @@ static int dasync_pkey(ENGINE *e, EVP_PKEY_METHOD **pmeth, } static int dasync_digests(ENGINE *e, const EVP_MD **digest, - const int **nids, int nid) + const int **nids, int nid) { int ok = 1; if (!digest) { @@ -472,14 +471,13 @@ static int dasync_digests(ENGINE *e, const EVP_MD **digest, } static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid) + const int **nids, int nid) { int ok = 1; if (cipher == NULL) { /* We are returning a list of supported nids */ *nids = dasync_cipher_nids; - return (sizeof(dasync_cipher_nids) - - 1) / sizeof(dasync_cipher_nids[0]); + return (sizeof(dasync_cipher_nids) - 1) / sizeof(dasync_cipher_nids[0]); } /* We are being asked for a specific cipher */ switch (nid) { @@ -501,7 +499,7 @@ static int dasync_ciphers(ENGINE *e, const EVP_CIPHER **cipher, } static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, - OSSL_ASYNC_FD readfd, void *pvwritefd) + OSSL_ASYNC_FD readfd, void *pvwritefd) { OSSL_ASYNC_FD *pwritefd = (OSSL_ASYNC_FD *)pvwritefd; #if defined(ASYNC_WIN) @@ -516,12 +514,13 @@ static void wait_cleanup(ASYNC_WAIT_CTX *ctx, const void *key, #define DUMMY_CHAR 'X' -static void dummy_pause_job(void) { +static void dummy_pause_job(void) +{ ASYNC_JOB *job; ASYNC_WAIT_CTX *waitctx; ASYNC_callback_fn callback; - void * callback_arg; - OSSL_ASYNC_FD pipefds[2] = {0, 0}; + void *callback_arg; + OSSL_ASYNC_FD pipefds[2] = { 0, 0 }; OSSL_ASYNC_FD *writefd; #if defined(ASYNC_WIN) DWORD numwritten, numread; @@ -546,9 +545,8 @@ static void dummy_pause_job(void) { return; } - if (ASYNC_WAIT_CTX_get_fd(waitctx, engine_dasync_id, &pipefds[0], - (void **)&writefd)) { + (void **)&writefd)) { pipefds[1] = *writefd; } else { writefd = OPENSSL_malloc(sizeof(*writefd)); @@ -568,7 +566,7 @@ static void dummy_pause_job(void) { *writefd = pipefds[1]; if (!ASYNC_WAIT_CTX_set_wait_fd(waitctx, engine_dasync_id, pipefds[0], - writefd, wait_cleanup)) { + writefd, wait_cleanup)) { wait_cleanup(waitctx, engine_dasync_id, pipefds[0], writefd); return; } @@ -609,7 +607,7 @@ static int dasync_sha1_init(EVP_MD_CTX *ctx) } static int dasync_sha1_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { dummy_pause_job(); @@ -626,107 +624,102 @@ static int dasync_sha1_final(EVP_MD_CTX *ctx, unsigned char *md) /* Cipher helper functions */ static int dasync_cipher_ctrl_helper(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr, int aeadcapable, - const EVP_CIPHER *ciph) + void *ptr, int aeadcapable, + const EVP_CIPHER *ciph) { int ret; - struct dasync_pipeline_ctx *pipe_ctx = - (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct dasync_pipeline_ctx *pipe_ctx = (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); if (pipe_ctx == NULL) return 0; switch (type) { - case EVP_CTRL_COPY: - { - size_t sz = EVP_CIPHER_impl_ctx_size(ciph); - void *inner_cipher_data = OPENSSL_malloc(sz); + case EVP_CTRL_COPY: { + size_t sz = EVP_CIPHER_impl_ctx_size(ciph); + void *inner_cipher_data = OPENSSL_malloc(sz); - if (inner_cipher_data == NULL) - return -1; - memcpy(inner_cipher_data, pipe_ctx->inner_cipher_data, sz); - pipe_ctx->inner_cipher_data = inner_cipher_data; - } - break; - - case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: - pipe_ctx->numpipes = arg; - pipe_ctx->outbufs = (unsigned char **)ptr; - break; + if (inner_cipher_data == NULL) + return -1; + memcpy(inner_cipher_data, pipe_ctx->inner_cipher_data, sz); + pipe_ctx->inner_cipher_data = inner_cipher_data; + } break; - case EVP_CTRL_SET_PIPELINE_INPUT_BUFS: - pipe_ctx->numpipes = arg; - pipe_ctx->inbufs = (unsigned char **)ptr; - break; + case EVP_CTRL_SET_PIPELINE_OUTPUT_BUFS: + pipe_ctx->numpipes = arg; + pipe_ctx->outbufs = (unsigned char **)ptr; + break; - case EVP_CTRL_SET_PIPELINE_INPUT_LENS: - pipe_ctx->numpipes = arg; - pipe_ctx->lens = (size_t *)ptr; - break; + case EVP_CTRL_SET_PIPELINE_INPUT_BUFS: + pipe_ctx->numpipes = arg; + pipe_ctx->inbufs = (unsigned char **)ptr; + break; - case EVP_CTRL_AEAD_SET_MAC_KEY: - if (!aeadcapable) - return -1; - EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data); - ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1()) - (ctx, type, arg, ptr); - EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx); - return ret; + case EVP_CTRL_SET_PIPELINE_INPUT_LENS: + pipe_ctx->numpipes = arg; + pipe_ctx->lens = (size_t *)ptr; + break; - case EVP_CTRL_AEAD_TLS1_AAD: - { - unsigned char *p = ptr; - unsigned int len; + case EVP_CTRL_AEAD_SET_MAC_KEY: + if (!aeadcapable) + return -1; + EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data); + ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_cbc_hmac_sha1())(ctx, type, arg, ptr); + EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx); + return ret; - if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN) - return -1; + case EVP_CTRL_AEAD_TLS1_AAD: { + unsigned char *p = ptr; + unsigned int len; - if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES) - return -1; + if (!aeadcapable || arg != EVP_AEAD_TLS1_AAD_LEN) + return -1; - memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr, - EVP_AEAD_TLS1_AAD_LEN); - pipe_ctx->aadctr++; + if (pipe_ctx->aadctr >= SSL_MAX_PIPELINES) + return -1; - len = p[arg - 2] << 8 | p[arg - 1]; + memcpy(pipe_ctx->tlsaad[pipe_ctx->aadctr], ptr, + EVP_AEAD_TLS1_AAD_LEN); + pipe_ctx->aadctr++; - if (EVP_CIPHER_CTX_is_encrypting(ctx)) { - if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) { - if (len < AES_BLOCK_SIZE) - return 0; - len -= AES_BLOCK_SIZE; - } + len = p[arg - 2] << 8 | p[arg - 1]; - return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE) - & -AES_BLOCK_SIZE) - len; - } else { - return SHA_DIGEST_LENGTH; + if (EVP_CIPHER_CTX_is_encrypting(ctx)) { + if ((p[arg - 4] << 8 | p[arg - 3]) >= TLS1_1_VERSION) { + if (len < AES_BLOCK_SIZE) + return 0; + len -= AES_BLOCK_SIZE; } + + return ((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE) + & -AES_BLOCK_SIZE) + - len; + } else { + return SHA_DIGEST_LENGTH; } + } - default: - return 0; + default: + return 0; } return 1; } static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, int enc, - const EVP_CIPHER *cipher) + const unsigned char *key, + const unsigned char *iv, int enc, + const EVP_CIPHER *cipher) { int ret; - struct dasync_pipeline_ctx *pipe_ctx = - (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct dasync_pipeline_ctx *pipe_ctx = (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); if (pipe_ctx->inner_cipher_data == NULL - && EVP_CIPHER_impl_ctx_size(cipher) != 0) { + && EVP_CIPHER_impl_ctx_size(cipher) != 0) { pipe_ctx->inner_cipher_data = OPENSSL_zalloc( EVP_CIPHER_impl_ctx_size(cipher)); if (pipe_ctx->inner_cipher_data == NULL) { DASYNCerr(DASYNC_F_DASYNC_CIPHER_INIT_KEY_HELPER, - ERR_R_MALLOC_FAILURE); + ERR_R_MALLOC_FAILURE); return 0; } } @@ -742,13 +735,12 @@ static int dasync_cipher_init_key_helper(EVP_CIPHER_CTX *ctx, } static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl, - const EVP_CIPHER *cipher) + const unsigned char *in, size_t inl, + const EVP_CIPHER *cipher) { int ret = 1; unsigned int i, pipes; - struct dasync_pipeline_ctx *pipe_ctx = - (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct dasync_pipeline_ctx *pipe_ctx = (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); pipes = pipe_ctx->numpipes; EVP_CIPHER_CTX_set_cipher_data(ctx, pipe_ctx->inner_cipher_data); @@ -756,26 +748,21 @@ static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out, if (pipe_ctx->aadctr != 0) { if (pipe_ctx->aadctr != 1) return -1; - EVP_CIPHER_meth_get_ctrl(cipher) - (ctx, EVP_CTRL_AEAD_TLS1_AAD, - EVP_AEAD_TLS1_AAD_LEN, - pipe_ctx->tlsaad[0]); + EVP_CIPHER_meth_get_ctrl(cipher)(ctx, EVP_CTRL_AEAD_TLS1_AAD, + EVP_AEAD_TLS1_AAD_LEN, + pipe_ctx->tlsaad[0]); } - ret = EVP_CIPHER_meth_get_do_cipher(cipher) - (ctx, out, in, inl); + ret = EVP_CIPHER_meth_get_do_cipher(cipher)(ctx, out, in, inl); } else { if (pipe_ctx->aadctr > 0 && pipe_ctx->aadctr != pipes) return -1; for (i = 0; i < pipes; i++) { if (pipe_ctx->aadctr > 0) { - EVP_CIPHER_meth_get_ctrl(cipher) - (ctx, EVP_CTRL_AEAD_TLS1_AAD, - EVP_AEAD_TLS1_AAD_LEN, - pipe_ctx->tlsaad[i]); + EVP_CIPHER_meth_get_ctrl(cipher)(ctx, EVP_CTRL_AEAD_TLS1_AAD, + EVP_AEAD_TLS1_AAD_LEN, + pipe_ctx->tlsaad[i]); } - ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher) - (ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i], - pipe_ctx->lens[i]); + ret = ret && EVP_CIPHER_meth_get_do_cipher(cipher)(ctx, pipe_ctx->outbufs[i], pipe_ctx->inbufs[i], pipe_ctx->lens[i]); } pipe_ctx->numpipes = 0; } @@ -785,13 +772,12 @@ static int dasync_cipher_helper(EVP_CIPHER_CTX *ctx, unsigned char *out, } static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx, - const EVP_CIPHER *cipher) + const EVP_CIPHER *cipher) { - struct dasync_pipeline_ctx *pipe_ctx = - (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct dasync_pipeline_ctx *pipe_ctx = (struct dasync_pipeline_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); OPENSSL_clear_free(pipe_ctx->inner_cipher_data, - EVP_CIPHER_impl_ctx_size(cipher)); + EVP_CIPHER_impl_ctx_size(cipher)); return 1; } @@ -801,19 +787,19 @@ static int dasync_cipher_cleanup_helper(EVP_CIPHER_CTX *ctx, */ static int dasync_aes128_cbc_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr) + void *ptr) { return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0, EVP_aes_128_cbc()); } static int dasync_aes128_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_128_cbc()); } static int dasync_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc()); } @@ -824,19 +810,19 @@ static int dasync_aes128_cbc_cleanup(EVP_CIPHER_CTX *ctx) } static int dasync_aes256_ctr_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr) + void *ptr) { return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 0, EVP_aes_256_ctr()); } static int dasync_aes256_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { return dasync_cipher_init_key_helper(ctx, key, iv, enc, EVP_aes_256_ctr()); } static int dasync_aes256_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_256_ctr()); } @@ -846,34 +832,33 @@ static int dasync_aes256_ctr_cleanup(EVP_CIPHER_CTX *ctx) return dasync_cipher_cleanup_helper(ctx, EVP_aes_256_ctr()); } - /* * AES128 CBC HMAC SHA1 Implementation */ static int dasync_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, - int arg, void *ptr) + int arg, void *ptr) { return dasync_cipher_ctrl_helper(ctx, type, arg, ptr, 1, EVP_aes_128_cbc_hmac_sha1()); } static int dasync_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, - int enc) + const unsigned char *key, + const unsigned char *iv, + int enc) { /* * We can safely assume that EVP_aes_128_cbc_hmac_sha1() != NULL, * see comment before the definition of dasync_aes_128_cbc_hmac_sha1(). */ return dasync_cipher_init_key_helper(ctx, key, iv, enc, - EVP_aes_128_cbc_hmac_sha1()); + EVP_aes_128_cbc_hmac_sha1()); } static int dasync_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, - unsigned char *out, - const unsigned char *in, - size_t inl) + unsigned char *out, + const unsigned char *in, + size_t inl) { return dasync_cipher_helper(ctx, out, in, inl, EVP_aes_128_cbc_hmac_sha1()); } @@ -887,7 +872,6 @@ static int dasync_aes128_cbc_hmac_sha1_cleanup(EVP_CIPHER_CTX *ctx) return dasync_cipher_cleanup_helper(ctx, EVP_aes_128_cbc_hmac_sha1()); } - /* * RSA implementation */ @@ -955,12 +939,12 @@ static int dasync_rsa_encrypt_init(EVP_PKEY_CTX *ctx) } static int dasync_rsa_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen) + size_t *outlen, const unsigned char *in, + size_t inlen) { static int (*pencryptfn)(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen); + size_t *outlen, const unsigned char *in, + size_t inlen); if (pencryptfn == NULL) EVP_PKEY_meth_get_encrypt(dasync_rsa_orig, NULL, &pencryptfn); @@ -977,12 +961,12 @@ static int dasync_rsa_decrypt_init(EVP_PKEY_CTX *ctx) } static int dasync_rsa_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen) + size_t *outlen, const unsigned char *in, + size_t inlen) { static int (*pdecrypt)(EVP_PKEY_CTX *ctx, unsigned char *out, - size_t *outlen, const unsigned char *in, - size_t inlen); + size_t *outlen, const unsigned char *in, + size_t inlen); if (pdecrypt == NULL) EVP_PKEY_meth_get_decrypt(dasync_rsa_orig, NULL, &pdecrypt); @@ -999,10 +983,10 @@ static int dasync_rsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) } static int dasync_rsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, - const char *value) + const char *value) { static int (*pctrl_str)(EVP_PKEY_CTX *ctx, const char *type, - const char *value); + const char *value); if (pctrl_str == NULL) EVP_PKEY_meth_get_ctrl(dasync_rsa_orig, NULL, &pctrl_str); diff --git a/engines/e_dasync_err.c b/engines/e_dasync_err.c index 16021f3196dd..eba72fa859ba 100644 --- a/engines/e_dasync_err.c +++ b/engines/e_dasync_err.c @@ -14,8 +14,8 @@ #ifndef OPENSSL_NO_ERR static ERR_STRING_DATA DASYNC_str_reasons[] = { - {ERR_PACK(0, 0, DASYNC_R_INIT_FAILED), "init failed"}, - {0, NULL} + { ERR_PACK(0, 0, DASYNC_R_INIT_FAILED), "init failed" }, + { 0, NULL } }; #endif diff --git a/engines/e_dasync_err.h b/engines/e_dasync_err.h index 7a067c6037a6..bb774f02c649 100644 --- a/engines/e_dasync_err.h +++ b/engines/e_dasync_err.h @@ -9,19 +9,17 @@ */ #ifndef OSSL_E_DASYNC_ERR_H -# define OSSL_E_DASYNC_ERR_H -# pragma once +#define OSSL_E_DASYNC_ERR_H +#pragma once -# include <openssl/opensslconf.h> -# include <openssl/symhacks.h> - - -# define DASYNCerr(f, r) ERR_DASYNC_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) +#include <openssl/opensslconf.h> +#include <openssl/symhacks.h> +#define DASYNCerr(f, r) ERR_DASYNC_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) /* * DASYNC reason codes. */ -# define DASYNC_R_INIT_FAILED 100 +#define DASYNC_R_INIT_FAILED 100 #endif diff --git a/engines/e_devcrypto.c b/engines/e_devcrypto.c index b42317522730..8274fc338e42 100644 --- a/engines/e_devcrypto.c +++ b/engines/e_devcrypto.c @@ -29,7 +29,7 @@ /* #define ENGINE_DEVCRYPTO_DEBUG */ #if CRYPTO_ALGORITHM_MIN < CRYPTO_ALGORITHM_MAX -# define CHECK_BSD_STYLE_MACROS +#define CHECK_BSD_STYLE_MACROS #endif #define engine_devcrypto_id "devcrypto" @@ -51,8 +51,8 @@ typedef struct session_op session_op_t; */ static int cfd = -1; #define DEVCRYPTO_REQUIRE_ACCELERATED 0 /* require confirmation of acceleration */ -#define DEVCRYPTO_USE_SOFTWARE 1 /* allow software drivers */ -#define DEVCRYPTO_REJECT_SOFTWARE 2 /* only disallow confirmed software drivers */ +#define DEVCRYPTO_USE_SOFTWARE 1 /* allow software drivers */ +#define DEVCRYPTO_REJECT_SOFTWARE 2 /* only disallow confirmed software drivers */ #define DEVCRYPTO_DEFAULT_USE_SOFTDRIVERS DEVCRYPTO_REJECT_SOFTWARE static int use_softdrivers = DEVCRYPTO_DEFAULT_USE_SOFTDRIVERS; @@ -63,17 +63,17 @@ static int use_softdrivers = DEVCRYPTO_DEFAULT_USE_SOFTDRIVERS; */ struct driver_info_st { enum devcrypto_status_t { - DEVCRYPTO_STATUS_FAILURE = -3, /* unusable for other reason */ - DEVCRYPTO_STATUS_NO_CIOCCPHASH = -2, /* hash state copy not supported */ + DEVCRYPTO_STATUS_FAILURE = -3, /* unusable for other reason */ + DEVCRYPTO_STATUS_NO_CIOCCPHASH = -2, /* hash state copy not supported */ DEVCRYPTO_STATUS_NO_CIOCGSESSION = -1, /* session open failed */ - DEVCRYPTO_STATUS_UNKNOWN = 0, /* not tested yet */ - DEVCRYPTO_STATUS_USABLE = 1 /* algo can be used */ + DEVCRYPTO_STATUS_UNKNOWN = 0, /* not tested yet */ + DEVCRYPTO_STATUS_USABLE = 1 /* algo can be used */ } status; enum devcrypto_accelerated_t { - DEVCRYPTO_NOT_ACCELERATED = -1, /* software implemented */ - DEVCRYPTO_ACCELERATION_UNKNOWN = 0, /* acceleration support unknown */ - DEVCRYPTO_ACCELERATED = 1 /* hardware accelerated */ + DEVCRYPTO_NOT_ACCELERATED = -1, /* software implemented */ + DEVCRYPTO_ACCELERATION_UNKNOWN = 0, /* acceleration support unknown */ + DEVCRYPTO_ACCELERATED = 1 /* hardware accelerated */ } accelerated; char *driver_name; @@ -83,7 +83,8 @@ struct driver_info_st { void engine_load_devcrypto_int(void); #endif -static int clean_devcrypto_session(session_op_t *sess) { +static int clean_devcrypto_session(session_op_t *sess) +{ if (ioctl(cfd, CIOCFSESSION, &sess->ses) < 0) { ERR_raise_data(ERR_LIB_SYS, errno, "calling ioctl()"); return 0; @@ -104,8 +105,8 @@ static int clean_devcrypto_session(session_op_t *sess) { struct cipher_ctx { session_op_t sess; - int op; /* COP_ENCRYPT or COP_DECRYPT */ - unsigned long mode; /* EVP_CIPH_*_MODE */ + int op; /* COP_ENCRYPT or COP_DECRYPT */ + unsigned long mode; /* EVP_CIPH_*_MODE */ /* to handle ctr mode being a stream cipher */ unsigned char partial[EVP_MAX_BLOCK_LENGTH]; @@ -141,7 +142,7 @@ static const struct cipher_data_st { { NID_aes_192_ctr, 16, 192 / 8, 16, EVP_CIPH_CTR_MODE, CRYPTO_AES_CTR }, { NID_aes_256_ctr, 16, 256 / 8, 16, EVP_CIPH_CTR_MODE, CRYPTO_AES_CTR }, #endif -#if 0 /* Not yet supported */ +#if 0 /* Not yet supported */ { NID_aes_128_xts, 16, 128 / 8 * 2, 16, EVP_CIPH_XTS_MODE, CRYPTO_AES_XTS }, { NID_aes_256_xts, 16, 256 / 8 * 2, 16, EVP_CIPH_XTS_MODE, CRYPTO_AES_XTS }, #endif @@ -150,18 +151,18 @@ static const struct cipher_data_st { { NID_aes_192_ecb, 16, 192 / 8, 0, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB }, { NID_aes_256_ecb, 16, 256 / 8, 0, EVP_CIPH_ECB_MODE, CRYPTO_AES_ECB }, #endif -#if 0 /* Not yet supported */ +#if 0 /* Not yet supported */ { NID_aes_128_gcm, 16, 128 / 8, 16, EVP_CIPH_GCM_MODE, CRYPTO_AES_GCM }, { NID_aes_192_gcm, 16, 192 / 8, 16, EVP_CIPH_GCM_MODE, CRYPTO_AES_GCM }, { NID_aes_256_gcm, 16, 256 / 8, 16, EVP_CIPH_GCM_MODE, CRYPTO_AES_GCM }, #endif #ifndef OPENSSL_NO_CAMELLIA { NID_camellia_128_cbc, 16, 128 / 8, 16, EVP_CIPH_CBC_MODE, - CRYPTO_CAMELLIA_CBC }, + CRYPTO_CAMELLIA_CBC }, { NID_camellia_192_cbc, 16, 192 / 8, 16, EVP_CIPH_CBC_MODE, - CRYPTO_CAMELLIA_CBC }, + CRYPTO_CAMELLIA_CBC }, { NID_camellia_256_cbc, 16, 256 / 8, 16, EVP_CIPH_CBC_MODE, - CRYPTO_CAMELLIA_CBC }, + CRYPTO_CAMELLIA_CBC }, #endif }; @@ -202,17 +203,14 @@ static const struct cipher_data_st *get_cipher_data(int nid) */ static int cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { - struct cipher_ctx *cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); - const struct cipher_data_st *cipher_d = - get_cipher_data(EVP_CIPHER_CTX_get_nid(ctx)); + struct cipher_ctx *cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + const struct cipher_data_st *cipher_d = get_cipher_data(EVP_CIPHER_CTX_get_nid(ctx)); int ret; /* cleanup a previous session */ - if (cipher_ctx->sess.ses != 0 && - clean_devcrypto_session(&cipher_ctx->sess) == 0) + if (cipher_ctx->sess.ses != 0 && clean_devcrypto_session(&cipher_ctx->sess) == 0) return 0; cipher_ctx->sess.cipher = cipher_d->devcryptoid; @@ -222,9 +220,7 @@ static int cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, cipher_ctx->mode = cipher_d->flags & EVP_CIPH_MODE; cipher_ctx->blocksize = cipher_d->blocksize; #ifdef CIOCGSESSION2 - cipher_ctx->sess.crid = (use_softdrivers == DEVCRYPTO_USE_SOFTWARE) ? - CRYPTO_FLAG_SOFTWARE | CRYPTO_FLAG_HARDWARE : - CRYPTO_FLAG_HARDWARE; + cipher_ctx->sess.crid = (use_softdrivers == DEVCRYPTO_USE_SOFTWARE) ? CRYPTO_FLAG_SOFTWARE | CRYPTO_FLAG_HARDWARE : CRYPTO_FLAG_HARDWARE; ret = ioctl(cfd, CIOCGSESSION2, &cipher_ctx->sess); #else ret = ioctl(cfd, CIOCGSESSION, &cipher_ctx->sess); @@ -238,10 +234,9 @@ static int cipher_init(EVP_CIPHER_CTX *ctx, const unsigned char *key, } static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { - struct cipher_ctx *cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct cipher_ctx *cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); struct crypt_op cryp; unsigned char *iv = EVP_CIPHER_CTX_iv_noconst(ctx); #if !defined(COP_FLAG_WRITE_IV) @@ -301,11 +296,11 @@ static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, case EVP_CIPH_CTR_MODE: nblocks = (inl + cipher_ctx->blocksize - 1) - / cipher_ctx->blocksize; + / cipher_ctx->blocksize; do { ivlen--; nblocks += iv[ivlen]; - iv[ivlen] = (uint8_t) nblocks; + iv[ivlen] = (uint8_t)nblocks; nblocks >>= 8; } while (ivlen); break; @@ -319,10 +314,9 @@ static int cipher_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } static int ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { - struct cipher_ctx *cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct cipher_ctx *cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); size_t nblocks, len; /* initial partial block */ @@ -333,8 +327,8 @@ static int ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } /* full blocks */ - if (inl > (unsigned int) cipher_ctx->blocksize) { - nblocks = inl/cipher_ctx->blocksize; + if (inl > (unsigned int)cipher_ctx->blocksize) { + nblocks = inl / cipher_ctx->blocksize; len = nblocks * cipher_ctx->blocksize; if (cipher_do_cipher(ctx, out, in, len) < 1) return 0; @@ -347,11 +341,12 @@ static int ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, if (inl) { memset(cipher_ctx->partial, 0, cipher_ctx->blocksize); if (cipher_do_cipher(ctx, cipher_ctx->partial, cipher_ctx->partial, - cipher_ctx->blocksize) < 1) + cipher_ctx->blocksize) + < 1) return 0; while (inl--) { out[cipher_ctx->num] = in[cipher_ctx->num] - ^ cipher_ctx->partial[cipher_ctx->num]; + ^ cipher_ctx->partial[cipher_ctx->num]; cipher_ctx->num++; } } @@ -359,10 +354,9 @@ static int ctr_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, return 1; } -static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void* p2) +static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void *p2) { - struct cipher_ctx *cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct cipher_ctx *cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); EVP_CIPHER_CTX *to_ctx = (EVP_CIPHER_CTX *)p2; struct cipher_ctx *to_cipher_ctx; @@ -372,11 +366,10 @@ static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void* p2) if (cipher_ctx == NULL) return 1; /* when copying the context, a new session needs to be initialized */ - to_cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(to_ctx); + to_cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(to_ctx); memset(&to_cipher_ctx->sess, 0, sizeof(to_cipher_ctx->sess)); return cipher_init(to_ctx, (void *)cipher_ctx->sess.key, EVP_CIPHER_CTX_iv(ctx), - (cipher_ctx->op == COP_ENCRYPT)); + (cipher_ctx->op == COP_ENCRYPT)); case EVP_CTRL_INIT: memset(&cipher_ctx->sess, 0, sizeof(cipher_ctx->sess)); @@ -391,8 +384,7 @@ static int cipher_ctrl(EVP_CIPHER_CTX *ctx, int type, int p1, void* p2) static int cipher_cleanup(EVP_CIPHER_CTX *ctx) { - struct cipher_ctx *cipher_ctx = - (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); + struct cipher_ctx *cipher_ctx = (struct cipher_ctx *)EVP_CIPHER_CTX_get_cipher_data(ctx); return clean_devcrypto_session(&cipher_ctx->sess); } @@ -405,21 +397,22 @@ static int cipher_cleanup(EVP_CIPHER_CTX *ctx) */ static int known_cipher_nids[OSSL_NELEM(cipher_data)]; static int known_cipher_nids_amount = -1; /* -1 indicates not yet initialised */ -static EVP_CIPHER *known_cipher_methods[OSSL_NELEM(cipher_data)] = { NULL, }; +static EVP_CIPHER *known_cipher_methods[OSSL_NELEM(cipher_data)] = { + NULL, +}; static int selected_ciphers[OSSL_NELEM(cipher_data)]; static struct driver_info_st cipher_driver_info[OSSL_NELEM(cipher_data)]; - static int devcrypto_test_cipher(size_t cipher_data_index) { return (cipher_driver_info[cipher_data_index].status == DEVCRYPTO_STATUS_USABLE - && selected_ciphers[cipher_data_index] == 1 - && (cipher_driver_info[cipher_data_index].accelerated - == DEVCRYPTO_ACCELERATED - || use_softdrivers == DEVCRYPTO_USE_SOFTWARE - || (cipher_driver_info[cipher_data_index].accelerated - != DEVCRYPTO_NOT_ACCELERATED - && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE))); + && selected_ciphers[cipher_data_index] == 1 + && (cipher_driver_info[cipher_data_index].accelerated + == DEVCRYPTO_ACCELERATED + || use_softdrivers == DEVCRYPTO_USE_SOFTWARE + || (cipher_driver_info[cipher_data_index].accelerated + != DEVCRYPTO_NOT_ACCELERATED + && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE))); } static void prepare_cipher_methods(void) @@ -440,7 +433,7 @@ static void prepare_cipher_methods(void) sess.key = (void *)"01234567890123456789012345678901234567890123456789"; for (i = 0, known_cipher_nids_amount = 0; - i < OSSL_NELEM(cipher_data); i++) { + i < OSSL_NELEM(cipher_data); i++) { selected_ciphers[i] = 1; /* @@ -474,28 +467,25 @@ static void prepare_cipher_methods(void) cipher_mode = cipher_data[i].flags & EVP_CIPH_MODE; - if ((known_cipher_methods[i] = - EVP_CIPHER_meth_new(cipher_data[i].nid, - cipher_mode == EVP_CIPH_CTR_MODE ? 1 : - cipher_data[i].blocksize, - cipher_data[i].keylen)) == NULL + if ((known_cipher_methods[i] = EVP_CIPHER_meth_new(cipher_data[i].nid, + cipher_mode == EVP_CIPH_CTR_MODE ? 1 : cipher_data[i].blocksize, + cipher_data[i].keylen)) + == NULL || !EVP_CIPHER_meth_set_iv_length(known_cipher_methods[i], - cipher_data[i].ivlen) + cipher_data[i].ivlen) || !EVP_CIPHER_meth_set_flags(known_cipher_methods[i], - cipher_data[i].flags - | EVP_CIPH_CUSTOM_COPY - | EVP_CIPH_CTRL_INIT - | EVP_CIPH_FLAG_DEFAULT_ASN1) + cipher_data[i].flags + | EVP_CIPH_CUSTOM_COPY + | EVP_CIPH_CTRL_INIT + | EVP_CIPH_FLAG_DEFAULT_ASN1) || !EVP_CIPHER_meth_set_init(known_cipher_methods[i], cipher_init) || !EVP_CIPHER_meth_set_do_cipher(known_cipher_methods[i], - cipher_mode == EVP_CIPH_CTR_MODE ? - ctr_do_cipher : - cipher_do_cipher) + cipher_mode == EVP_CIPH_CTR_MODE ? ctr_do_cipher : cipher_do_cipher) || !EVP_CIPHER_meth_set_ctrl(known_cipher_methods[i], cipher_ctrl) || !EVP_CIPHER_meth_set_cleanup(known_cipher_methods[i], - cipher_cleanup) + cipher_cleanup) || !EVP_CIPHER_meth_set_impl_ctx_size(known_cipher_methods[i], - sizeof(struct cipher_ctx))) { + sizeof(struct cipher_ctx))) { cipher_driver_info[i].status = DEVCRYPTO_STATUS_FAILURE; EVP_CIPHER_meth_free(known_cipher_methods[i]); known_cipher_methods[i] = NULL; @@ -505,17 +495,15 @@ static void prepare_cipher_methods(void) cipher_driver_info[i].accelerated = accelerated; fop.crid = sess.crid; if (ioctl(cfd, CIOCFINDDEV, &fop) == 0) { - cipher_driver_info[i].driver_name = - OPENSSL_strndup(fop.name, sizeof(fop.name)); + cipher_driver_info[i].driver_name = OPENSSL_strndup(fop.name, sizeof(fop.name)); } #elif defined(CIOCGSESSINFO) siop.ses = sess.ses; if (ioctl(cfd, CIOCGSESSINFO, &siop) < 0) { cipher_driver_info[i].accelerated = DEVCRYPTO_ACCELERATION_UNKNOWN; } else { - cipher_driver_info[i].driver_name = - OPENSSL_strndup(siop.cipher_info.cra_driver_name, - CRYPTODEV_MAX_ALG_NAME); + cipher_driver_info[i].driver_name = OPENSSL_strndup(siop.cipher_info.cra_driver_name, + CRYPTODEV_MAX_ALG_NAME); if (!(siop.flags & SIOP_FLAG_KERNEL_DRIVER_ONLY)) cipher_driver_info[i].accelerated = DEVCRYPTO_NOT_ACCELERATED; else @@ -525,8 +513,7 @@ static void prepare_cipher_methods(void) } ioctl(cfd, CIOCFSESSION, &sess.ses); if (devcrypto_test_cipher(i)) { - known_cipher_nids[known_cipher_nids_amount++] = - cipher_data[i].nid; + known_cipher_nids[known_cipher_nids_amount++] = cipher_data[i].nid; } } } @@ -578,7 +565,7 @@ static void destroy_all_cipher_methods(void) } static int devcrypto_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid) + const int **nids, int nid) { if (cipher == NULL) return get_cipher_nids(nids); @@ -623,22 +610,21 @@ static void dump_cipher_info(void) size_t i; const char *name; - fprintf (stderr, "Information about ciphers supported by the /dev/crypto" - " engine:\n"); + fprintf(stderr, "Information about ciphers supported by the /dev/crypto" + " engine:\n"); #ifndef CIOCGSESSINFO fprintf(stderr, "CIOCGSESSINFO (session info call) unavailable\n"); #endif for (i = 0; i < OSSL_NELEM(cipher_data); i++) { name = OBJ_nid2sn(cipher_data[i].nid); - fprintf (stderr, "Cipher %s, NID=%d, /dev/crypto info: id=%d, ", - name ? name : "unknown", cipher_data[i].nid, - cipher_data[i].devcryptoid); - if (cipher_driver_info[i].status == DEVCRYPTO_STATUS_NO_CIOCGSESSION ) { - fprintf (stderr, "CIOCGSESSION (session open call) failed\n"); + fprintf(stderr, "Cipher %s, NID=%d, /dev/crypto info: id=%d, ", + name ? name : "unknown", cipher_data[i].nid, + cipher_data[i].devcryptoid); + if (cipher_driver_info[i].status == DEVCRYPTO_STATUS_NO_CIOCGSESSION) { + fprintf(stderr, "CIOCGSESSION (session open call) failed\n"); continue; } - fprintf (stderr, "driver=%s ", cipher_driver_info[i].driver_name ? - cipher_driver_info[i].driver_name : "unknown"); + fprintf(stderr, "driver=%s ", cipher_driver_info[i].driver_name ? cipher_driver_info[i].driver_name : "unknown"); if (cipher_driver_info[i].accelerated == DEVCRYPTO_ACCELERATED) fprintf(stderr, "(hw accelerated)"); else if (cipher_driver_info[i].accelerated == DEVCRYPTO_NOT_ACCELERATED) @@ -646,7 +632,7 @@ static void dump_cipher_info(void) else fprintf(stderr, "(acceleration status unknown)"); if (cipher_driver_info[i].status == DEVCRYPTO_STATUS_FAILURE) - fprintf (stderr, ". Cipher setup failed"); + fprintf(stderr, ". Cipher setup failed"); fprintf(stderr, "\n"); } fprintf(stderr, "\n"); @@ -689,9 +675,9 @@ static const struct digest_data_st { #endif { NID_sha1, SHA_CBLOCK, 20, CRYPTO_SHA1 }, #ifndef OPENSSL_NO_RMD160 -# if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_RIPEMD160) +#if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_RIPEMD160) { NID_ripemd160, /* RIPEMD160_CBLOCK */ 64, 20, CRYPTO_RIPEMD160 }, -# endif +#endif #endif #if !defined(CHECK_BSD_STYLE_MACROS) || defined(CRYPTO_SHA2_224) { NID_sha224, SHA256_CBLOCK, 224 / 8, CRYPTO_SHA2_224 }, @@ -745,10 +731,8 @@ static const struct digest_data_st *get_digest_data(int nid) static int digest_init(EVP_MD_CTX *ctx) { - struct digest_ctx *digest_ctx = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); - const struct digest_data_st *digest_d = - get_digest_data(EVP_MD_CTX_get_type(ctx)); + struct digest_ctx *digest_ctx = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); + const struct digest_data_st *digest_d = get_digest_data(EVP_MD_CTX_get_type(ctx)); digest_ctx->init_called = 1; @@ -762,7 +746,7 @@ static int digest_init(EVP_MD_CTX *ctx) } static int digest_op(struct digest_ctx *ctx, const void *src, size_t srclen, - void *res, unsigned int flags) + void *res, unsigned int flags) { struct crypt_op cryp; @@ -778,8 +762,7 @@ static int digest_op(struct digest_ctx *ctx, const void *src, size_t srclen, static int digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) { - struct digest_ctx *digest_ctx = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); + struct digest_ctx *digest_ctx = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); if (count == 0) return 1; @@ -800,8 +783,7 @@ static int digest_update(EVP_MD_CTX *ctx, const void *data, size_t count) static int digest_final(EVP_MD_CTX *ctx, unsigned char *md) { - struct digest_ctx *digest_ctx = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); + struct digest_ctx *digest_ctx = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); if (md == NULL || digest_ctx == NULL) return 0; @@ -818,10 +800,8 @@ static int digest_final(EVP_MD_CTX *ctx, unsigned char *md) static int digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) { - struct digest_ctx *digest_from = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(from); - struct digest_ctx *digest_to = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(to); + struct digest_ctx *digest_from = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(from); + struct digest_ctx *digest_to = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(to); struct cphash_op cphash; if (digest_from == NULL || digest_from->init_called != 1) @@ -843,8 +823,7 @@ static int digest_copy(EVP_MD_CTX *to, const EVP_MD_CTX *from) static int digest_cleanup(EVP_MD_CTX *ctx) { - struct digest_ctx *digest_ctx = - (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); + struct digest_ctx *digest_ctx = (struct digest_ctx *)EVP_MD_CTX_get0_md_data(ctx); if (digest_ctx == NULL) return 1; @@ -860,20 +839,22 @@ static int digest_cleanup(EVP_MD_CTX *ctx) */ static int known_digest_nids[OSSL_NELEM(digest_data)]; static int known_digest_nids_amount = -1; /* -1 indicates not yet initialised */ -static EVP_MD *known_digest_methods[OSSL_NELEM(digest_data)] = { NULL, }; +static EVP_MD *known_digest_methods[OSSL_NELEM(digest_data)] = { + NULL, +}; static int selected_digests[OSSL_NELEM(digest_data)]; static struct driver_info_st digest_driver_info[OSSL_NELEM(digest_data)]; static int devcrypto_test_digest(size_t digest_data_index) { return (digest_driver_info[digest_data_index].status == DEVCRYPTO_STATUS_USABLE - && selected_digests[digest_data_index] == 1 - && (digest_driver_info[digest_data_index].accelerated - == DEVCRYPTO_ACCELERATED - || use_softdrivers == DEVCRYPTO_USE_SOFTWARE - || (digest_driver_info[digest_data_index].accelerated - != DEVCRYPTO_NOT_ACCELERATED - && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE))); + && selected_digests[digest_data_index] == 1 + && (digest_driver_info[digest_data_index].accelerated + == DEVCRYPTO_ACCELERATED + || use_softdrivers == DEVCRYPTO_USE_SOFTWARE + || (digest_driver_info[digest_data_index].accelerated + != DEVCRYPTO_NOT_ACCELERATED + && use_softdrivers == DEVCRYPTO_REJECT_SOFTWARE))); } static void rebuild_known_digest_nids(ENGINE *e) @@ -903,7 +884,7 @@ static void prepare_digest_methods(void) memset(&sess2, 0, sizeof(sess2)); for (i = 0, known_digest_nids_amount = 0; i < OSSL_NELEM(digest_data); - i++) { + i++) { selected_digests[i] = 1; @@ -923,9 +904,8 @@ static void prepare_digest_methods(void) if (ioctl(cfd, CIOCGSESSINFO, &siop) < 0) { digest_driver_info[i].accelerated = DEVCRYPTO_ACCELERATION_UNKNOWN; } else { - digest_driver_info[i].driver_name = - OPENSSL_strndup(siop.hash_info.cra_driver_name, - CRYPTODEV_MAX_ALG_NAME); + digest_driver_info[i].driver_name = OPENSSL_strndup(siop.hash_info.cra_driver_name, + CRYPTODEV_MAX_ALG_NAME); if (siop.flags & SIOP_FLAG_KERNEL_DRIVER_ONLY) digest_driver_info[i].accelerated = DEVCRYPTO_ACCELERATED; else @@ -946,25 +926,26 @@ static void prepare_digest_methods(void) goto finish; } if ((known_digest_methods[i] = EVP_MD_meth_new(digest_data[i].nid, - NID_undef)) == NULL + NID_undef)) + == NULL || !EVP_MD_meth_set_input_blocksize(known_digest_methods[i], - digest_data[i].blocksize) + digest_data[i].blocksize) || !EVP_MD_meth_set_result_size(known_digest_methods[i], - digest_data[i].digestlen) + digest_data[i].digestlen) || !EVP_MD_meth_set_init(known_digest_methods[i], digest_init) || !EVP_MD_meth_set_update(known_digest_methods[i], digest_update) || !EVP_MD_meth_set_final(known_digest_methods[i], digest_final) || !EVP_MD_meth_set_copy(known_digest_methods[i], digest_copy) || !EVP_MD_meth_set_cleanup(known_digest_methods[i], digest_cleanup) || !EVP_MD_meth_set_app_datasize(known_digest_methods[i], - sizeof(struct digest_ctx))) { + sizeof(struct digest_ctx))) { digest_driver_info[i].status = DEVCRYPTO_STATUS_FAILURE; EVP_MD_meth_free(known_digest_methods[i]); known_digest_methods[i] = NULL; goto finish; } digest_driver_info[i].status = DEVCRYPTO_STATUS_USABLE; -finish: + finish: ioctl(cfd, CIOCFSESSION, &sess1.ses); if (sess2.ses != 0) ioctl(cfd, CIOCFSESSION, &sess2.ses); @@ -1008,7 +989,7 @@ static void destroy_all_digest_methods(void) } static int devcrypto_digests(ENGINE *e, const EVP_MD **digest, - const int **nids, int nid) + const int **nids, int nid) { if (digest == NULL) return get_digest_nids(nids); @@ -1053,20 +1034,20 @@ static void dump_digest_info(void) size_t i; const char *name; - fprintf (stderr, "Information about digests supported by the /dev/crypto" - " engine:\n"); + fprintf(stderr, "Information about digests supported by the /dev/crypto" + " engine:\n"); #ifndef CIOCGSESSINFO fprintf(stderr, "CIOCGSESSINFO (session info call) unavailable\n"); #endif for (i = 0; i < OSSL_NELEM(digest_data); i++) { name = OBJ_nid2sn(digest_data[i].nid); - fprintf (stderr, "Digest %s, NID=%d, /dev/crypto info: id=%d, driver=%s", - name ? name : "unknown", digest_data[i].nid, - digest_data[i].devcryptoid, - digest_driver_info[i].driver_name ? digest_driver_info[i].driver_name : "unknown"); + fprintf(stderr, "Digest %s, NID=%d, /dev/crypto info: id=%d, driver=%s", + name ? name : "unknown", digest_data[i].nid, + digest_data[i].devcryptoid, + digest_driver_info[i].driver_name ? digest_driver_info[i].driver_name : "unknown"); if (digest_driver_info[i].status == DEVCRYPTO_STATUS_NO_CIOCGSESSION) { - fprintf (stderr, ". CIOCGSESSION (session open) failed\n"); + fprintf(stderr, ". CIOCGSESSION (session open) failed\n"); continue; } if (digest_driver_info[i].accelerated == DEVCRYPTO_ACCELERATED) @@ -1076,7 +1057,7 @@ static void dump_digest_info(void) else fprintf(stderr, " (acceleration status unknown)"); if (cipher_driver_info[i].status == DEVCRYPTO_STATUS_FAILURE) - fprintf (stderr, ". Cipher setup failed\n"); + fprintf(stderr, ". Cipher setup failed\n"); else if (digest_driver_info[i].status == DEVCRYPTO_STATUS_NO_CIOCCPHASH) fprintf(stderr, ", CIOCCPHASH failed\n"); else @@ -1100,38 +1081,33 @@ static void dump_digest_info(void) static const ENGINE_CMD_DEFN devcrypto_cmds[] = { #if defined(CIOCGSESSINFO) || defined(CIOCGSESSION2) - {DEVCRYPTO_CMD_USE_SOFTDRIVERS, - "USE_SOFTDRIVERS", - "specifies whether to use software (not accelerated) drivers (" - OPENSSL_MSTR(DEVCRYPTO_REQUIRE_ACCELERATED) "=use only accelerated drivers, " - OPENSSL_MSTR(DEVCRYPTO_USE_SOFTWARE) "=allow all drivers, " - OPENSSL_MSTR(DEVCRYPTO_REJECT_SOFTWARE) - "=use if acceleration can't be determined) [default=" - OPENSSL_MSTR(DEVCRYPTO_DEFAULT_USE_SOFTDRIVERS) "]", - ENGINE_CMD_FLAG_NUMERIC}, + { DEVCRYPTO_CMD_USE_SOFTDRIVERS, + "USE_SOFTDRIVERS", + "specifies whether to use software (not accelerated) drivers (" OPENSSL_MSTR(DEVCRYPTO_REQUIRE_ACCELERATED) "=use only accelerated drivers, " OPENSSL_MSTR(DEVCRYPTO_USE_SOFTWARE) "=allow all drivers, " OPENSSL_MSTR(DEVCRYPTO_REJECT_SOFTWARE) "=use if acceleration can't be determined) [default=" OPENSSL_MSTR(DEVCRYPTO_DEFAULT_USE_SOFTDRIVERS) "]", + ENGINE_CMD_FLAG_NUMERIC }, #endif - {DEVCRYPTO_CMD_CIPHERS, - "CIPHERS", - "either ALL, NONE, or a comma-separated list of ciphers to enable [default=ALL]", - ENGINE_CMD_FLAG_STRING}, + { DEVCRYPTO_CMD_CIPHERS, + "CIPHERS", + "either ALL, NONE, or a comma-separated list of ciphers to enable [default=ALL]", + ENGINE_CMD_FLAG_STRING }, #ifdef IMPLEMENT_DIGEST - {DEVCRYPTO_CMD_DIGESTS, - "DIGESTS", - "either ALL, NONE, or a comma-separated list of digests to enable [default=ALL]", - ENGINE_CMD_FLAG_STRING}, + { DEVCRYPTO_CMD_DIGESTS, + "DIGESTS", + "either ALL, NONE, or a comma-separated list of digests to enable [default=ALL]", + ENGINE_CMD_FLAG_STRING }, #endif - {DEVCRYPTO_CMD_DUMP_INFO, - "DUMP_INFO", - "dump info about each algorithm to stderr; use 'openssl engine -pre DUMP_INFO devcrypto'", - ENGINE_CMD_FLAG_NO_INPUT}, + { DEVCRYPTO_CMD_DUMP_INFO, + "DUMP_INFO", + "dump info about each algorithm to stderr; use 'openssl engine -pre DUMP_INFO devcrypto'", + ENGINE_CMD_FLAG_NO_INPUT }, - {0, NULL, NULL, 0} + { 0, NULL, NULL, 0 } }; -static int devcrypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) +static int devcrypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) { int *new_list; switch (cmd) { @@ -1161,10 +1137,10 @@ static int devcrypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) return 1; if (OPENSSL_strcasecmp((const char *)p, "ALL") == 0) { devcrypto_select_all_ciphers(selected_ciphers); - } else if (OPENSSL_strcasecmp((const char*)p, "NONE") == 0) { + } else if (OPENSSL_strcasecmp((const char *)p, "NONE") == 0) { memset(selected_ciphers, 0, sizeof(selected_ciphers)); } else { - new_list=OPENSSL_zalloc(sizeof(selected_ciphers)); + new_list = OPENSSL_zalloc(sizeof(selected_ciphers)); if (!CONF_parse_list(p, ',', 1, cryptodev_select_cipher_cb, new_list)) { OPENSSL_free(new_list); return 0; @@ -1181,10 +1157,10 @@ static int devcrypto_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f) (void)) return 1; if (OPENSSL_strcasecmp((const char *)p, "ALL") == 0) { devcrypto_select_all_digests(selected_digests); - } else if (OPENSSL_strcasecmp((const char*)p, "NONE") == 0) { + } else if (OPENSSL_strcasecmp((const char *)p, "NONE") == 0) { memset(selected_digests, 0, sizeof(selected_digests)); } else { - new_list=OPENSSL_zalloc(sizeof(selected_digests)); + new_list = OPENSSL_zalloc(sizeof(selected_digests)); if (!CONF_parse_list(p, ',', 1, cryptodev_select_digest_cb, new_list)) { OPENSSL_free(new_list); return 0; @@ -1275,7 +1251,8 @@ static int devcrypto_unload(ENGINE *e) return 1; } -static int bind_devcrypto(ENGINE *e) { +static int bind_devcrypto(ENGINE *e) +{ if (!ENGINE_set_id(e, engine_devcrypto_id) || !ENGINE_set_name(e, "/dev/crypto engine") @@ -1315,17 +1292,17 @@ static int bind_devcrypto(ENGINE *e) { */ #if 0 && ENGINE_set_RSA(e, devcrypto_rsa) -# ifndef OPENSSL_NO_DSA +#ifndef OPENSSL_NO_DSA && ENGINE_set_DSA(e, devcrypto_dsa) -# endif -# ifndef OPENSSL_NO_DH +#endif +#ifndef OPENSSL_NO_DH && ENGINE_set_DH(e, devcrypto_dh) -# endif -# ifndef OPENSSL_NO_EC +#endif +#ifndef OPENSSL_NO_EC && ENGINE_set_EC(e, devcrypto_ec) -# endif #endif - ); +#endif + ); } #ifdef OPENSSL_NO_DYNAMIC_ENGINE @@ -1353,7 +1330,7 @@ void engine_load_devcrypto_int(void) * If the "add" worked, it gets a structural reference. So either way, we * release our just-created reference. */ - ENGINE_free(e); /* Loose our local reference */ + ENGINE_free(e); /* Loose our local reference */ /* * If the "add" didn't work, it was probably a conflict because it was * already added (eg. someone calling ENGINE_load_blah then calling diff --git a/engines/e_loader_attic.c b/engines/e_loader_attic.c index 08c9c16cbbfd..89fe21e40c7b 100644 --- a/engines/e_loader_attic.c +++ b/engines/e_loader_attic.c @@ -20,33 +20,35 @@ #include <assert.h> #include <openssl/bio.h> -#include <openssl/dsa.h> /* For d2i_DSAPrivateKey */ +#include <openssl/dsa.h> /* For d2i_DSAPrivateKey */ #include <openssl/err.h> #include <openssl/evp.h> #include <openssl/pem.h> -#include <openssl/pkcs12.h> /* For the PKCS8 stuff o.O */ -#include <openssl/rsa.h> /* For d2i_RSAPrivateKey */ +#include <openssl/pkcs12.h> /* For the PKCS8 stuff o.O */ +#include <openssl/rsa.h> /* For d2i_RSAPrivateKey */ #include <openssl/safestack.h> #include <openssl/store.h> #include <openssl/ui.h> #include <openssl/engine.h> -#include <openssl/x509.h> /* For the PKCS8 stuff o.O */ -#include "internal/asn1.h" /* For asn1_d2i_read_bio */ +#include <openssl/x509.h> /* For the PKCS8 stuff o.O */ +#include "internal/asn1.h" /* For asn1_d2i_read_bio */ #include "internal/o_dir.h" #include "internal/cryptlib.h" -#include "crypto/ctype.h" /* For ossl_isdigit */ -#include "crypto/pem.h" /* For PVK and "blob" PEM headers */ +#include "crypto/ctype.h" /* For ossl_isdigit */ +#include "crypto/pem.h" /* For PVK and "blob" PEM headers */ +/* clang-format off */ #include "e_loader_attic_err.c" +/* clang-format on */ DEFINE_STACK_OF(OSSL_STORE_INFO) #ifdef _WIN32 -# define stat _stat +#define stat _stat #endif #ifndef S_ISDIR -# define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR) +#define S_ISDIR(a) (((a) & S_IFMT) == S_IFDIR) #endif /*- @@ -55,8 +57,8 @@ DEFINE_STACK_OF(OSSL_STORE_INFO) */ static char *file_get_pass(const UI_METHOD *ui_method, char *pass, - size_t maxsize, const char *desc, const char *info, - void *data) + size_t maxsize, const char *desc, const char *info, + void *data) { UI *ui = UI_new(); char *prompt = NULL; @@ -74,7 +76,8 @@ static char *file_get_pass(const UI_METHOD *ui_method, char *pass, ATTICerr(0, ERR_R_MALLOC_FAILURE); pass = NULL; } else if (UI_add_input_string(ui, prompt, UI_INPUT_FLAG_DEFAULT_PWD, - pass, 0, maxsize - 1) <= 0) { + pass, 0, maxsize - 1) + <= 0) { ATTICerr(0, ERR_R_UI_LIB); pass = NULL; } else { @@ -105,8 +108,8 @@ struct pem_pass_data { }; static int file_fill_pem_pass_data(struct pem_pass_data *pass_data, - const char *desc, const char *info, - const UI_METHOD *ui_method, void *ui_data) + const char *desc, const char *info, + const UI_METHOD *ui_method, void *ui_data) { if (pass_data == NULL) return 0; @@ -122,8 +125,8 @@ static int file_get_pem_pass(char *buf, int num, int w, void *data) { struct pem_pass_data *pass_data = data; char *pass = file_get_pass(pass_data->ui_method, buf, num, - pass_data->prompt_desc, pass_data->prompt_info, - pass_data->data); + pass_data->prompt_desc, pass_data->prompt_info, + pass_data->data); return pass == NULL ? 0 : strlen(pass); } @@ -161,7 +164,7 @@ static int check_suffix(const char *str, const char *suffix) * new PEM name. */ /* Negative numbers are never used for public OSSL_STORE_INFO types */ -#define STORE_INFO_EMBEDDED -1 +#define STORE_INFO_EMBEDDED -1 /* This is the embedded data */ struct embedded_st { @@ -188,7 +191,7 @@ static void store_info_free(OSSL_STORE_INFO *info) } static OSSL_STORE_INFO *new_EMBEDDED(const char *new_pem_name, - BUF_MEM *embedded) + BUF_MEM *embedded) { OSSL_STORE_INFO *info = NULL; struct embedded_st *data = NULL; @@ -201,8 +204,7 @@ static OSSL_STORE_INFO *new_EMBEDDED(const char *new_pem_name, } data->blob = embedded; - data->pem_name = - new_pem_name == NULL ? NULL : OPENSSL_strdup(new_pem_name); + data->pem_name = new_pem_name == NULL ? NULL : OPENSSL_strdup(new_pem_name); if (new_pem_name != NULL && data->pem_name == NULL) { ATTICerr(0, ERR_R_MALLOC_FAILURE); @@ -257,14 +259,14 @@ static OSSL_STORE_INFO *new_EMBEDDED(const char *new_pem_name, * a OSSL_STORE_INFO */ typedef OSSL_STORE_INFO *(*file_try_decode_fn)(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **handler_ctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq); + const char *pem_header, + const unsigned char *blob, + size_t len, void **handler_ctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq); /* * The eof function should return 1 if there's no more data to be found * with the handler_ctx, otherwise 0. This is only used when the handler is @@ -294,14 +296,14 @@ typedef struct file_handler_st { * then serving them one piece at a time. */ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; STACK_OF(OSSL_STORE_INFO) *ctx = *pctx; @@ -329,8 +331,9 @@ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, pass = ""; } else { if ((pass = file_get_pass(ui_method, tpass, PEM_BUFSIZE, - "PKCS12 import", uri, - ui_data)) == NULL) { + "PKCS12 import", uri, + ui_data)) + == NULL) { ATTICerr(0, ATTIC_R_PASSPHRASE_CALLBACK_ERROR); goto p12_end; } @@ -389,7 +392,7 @@ static OSSL_STORE_INFO *try_decode_PKCS12(const char *pem_name, *pctx = ctx; } } - p12_end: + p12_end: PKCS12_free(p12); if (ctx == NULL) return NULL; @@ -429,15 +432,15 @@ static FILE_HANDLER PKCS12_handler = { * decoding process will then start over with the new blob. */ static OSSL_STORE_INFO *try_decode_PKCS8Encrypted(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, - const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, + const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { X509_SIG *p8 = NULL; char kbuf[PEM_BUFSIZE]; @@ -466,15 +469,16 @@ static OSSL_STORE_INFO *try_decode_PKCS8Encrypted(const char *pem_name, } if ((pass = file_get_pass(ui_method, kbuf, PEM_BUFSIZE, - "PKCS8 decrypt pass phrase", uri, - ui_data)) == NULL) { + "PKCS8 decrypt pass phrase", uri, + ui_data)) + == NULL) { ATTICerr(0, ATTIC_R_BAD_PASSWORD_READ); goto nop8; } X509_SIG_get0(p8, &dalg, &doct); if (!PKCS12_pbe_crypt(dalg, pass, strlen(pass), doct->data, doct->length, - &new_data, &new_data_len, 0)) + &new_data, &new_data_len, 0)) goto nop8; mem->data = (char *)new_data; @@ -489,7 +493,7 @@ static OSSL_STORE_INFO *try_decode_PKCS8Encrypted(const char *pem_name, } return store_info; - nop8: +nop8: X509_SIG_free(p8); BUF_MEM_free(mem); return NULL; @@ -506,14 +510,14 @@ static FILE_HANDLER PKCS8Encrypted_handler = { * the PEM name). */ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; EVP_PKEY *pkey = NULL; @@ -521,8 +525,7 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, if (pem_name != NULL) { if (strcmp(pem_name, PEM_STRING_PKCS8INF) == 0) { - PKCS8_PRIV_KEY_INFO *p8inf = - d2i_PKCS8_PRIV_KEY_INFO(NULL, &blob, len); + PKCS8_PRIV_KEY_INFO *p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &blob, len); *matchcount = 1; if (p8inf != NULL) @@ -534,12 +537,13 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, if ((slen = check_suffix(pem_name, "PRIVATE KEY")) > 0 && (ameth = EVP_PKEY_asn1_find_str(NULL, pem_name, - slen)) != NULL + slen)) + != NULL && EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, - ameth)) { + ameth)) { *matchcount = 1; pkey = d2i_PrivateKey_ex(pkey_id, NULL, &blob, len, - libctx, propq); + libctx, propq); } } } else { @@ -548,8 +552,7 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, ENGINE *curengine = ENGINE_get_first(); while (curengine != NULL) { - ENGINE_PKEY_ASN1_METHS_PTR asn1meths = - ENGINE_get_pkey_asn1_meths(curengine); + ENGINE_PKEY_ASN1_METHS_PTR asn1meths = ENGINE_get_pkey_asn1_meths(curengine); if (asn1meths != NULL) { const int *nids = NULL; @@ -563,15 +566,15 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, if (!asn1meths(curengine, &ameth2, NULL, nids[i]) || !EVP_PKEY_asn1_get0_info(&pkey_id, NULL, - &pkey_flags, NULL, NULL, - ameth2) + &pkey_flags, NULL, NULL, + ameth2) || (pkey_flags & ASN1_PKEY_ALIAS) != 0) continue; ERR_set_mark(); /* prevent flooding error queue */ tmp_pkey = d2i_PrivateKey_ex(pkey_id, NULL, - &tmp_blob, len, - libctx, propq); + &tmp_blob, len, + libctx, propq); if (tmp_pkey != NULL) { if (pkey != NULL) EVP_PKEY_free(tmp_pkey); @@ -593,13 +596,13 @@ static OSSL_STORE_INFO *try_decode_PrivateKey(const char *pem_name, ameth = EVP_PKEY_asn1_get0(i); if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, &pkey_flags, NULL, - NULL, ameth) + NULL, ameth) || (pkey_flags & ASN1_PKEY_ALIAS) != 0) continue; ERR_set_mark(); /* prevent flooding error queue */ tmp_pkey = d2i_PrivateKey_ex(pkey_id, NULL, &tmp_blob, len, - libctx, propq); + libctx, propq); if (tmp_pkey != NULL) { if (pkey != NULL) EVP_PKEY_free(tmp_pkey); @@ -635,14 +638,14 @@ static FILE_HANDLER PrivateKey_handler = { * Public key decoder. Only supports SubjectPublicKeyInfo formatted keys. */ static OSSL_STORE_INFO *try_decode_PUBKEY(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; EVP_PKEY *pkey = NULL; @@ -671,14 +674,14 @@ static FILE_HANDLER PUBKEY_handler = { * Key parameter decoder. */ static OSSL_STORE_INFO *try_decode_params(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; EVP_PKEY *pkey = NULL; @@ -691,7 +694,7 @@ static OSSL_STORE_INFO *try_decode_params(const char *pem_name, if ((slen = check_suffix(pem_name, "PARAMETERS")) > 0 && (ameth = EVP_PKEY_asn1_find_str(NULL, pem_name, slen)) != NULL && EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, NULL, NULL, - ameth)) { + ameth)) { *matchcount = 1; pkey = d2i_KeyParams(pkey_id, NULL, &blob, len); } @@ -705,7 +708,7 @@ static OSSL_STORE_INFO *try_decode_params(const char *pem_name, ameth = EVP_PKEY_asn1_get0(i); if (!EVP_PKEY_asn1_get0_info(&pkey_id, NULL, &pkey_flags, NULL, - NULL, ameth) + NULL, ameth) || (pkey_flags & ASN1_PKEY_ALIAS) != 0) continue; @@ -748,15 +751,15 @@ static FILE_HANDLER params_handler = { * X.509 certificate decoder. */ static OSSL_STORE_INFO *try_decode_X509Certificate(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, - const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, + const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; X509 *cert = NULL; @@ -774,7 +777,7 @@ static OSSL_STORE_INFO *try_decode_X509Certificate(const char *pem_name, if (strcmp(pem_name, PEM_STRING_X509_TRUSTED) == 0) ignore_trusted = 0; else if (strcmp(pem_name, PEM_STRING_X509_OLD) != 0 - && strcmp(pem_name, PEM_STRING_X509) != 0) + && strcmp(pem_name, PEM_STRING_X509) != 0) /* No match */ return NULL; *matchcount = 1; @@ -805,14 +808,14 @@ static FILE_HANDLER X509Certificate_handler = { * X.509 CRL decoder. */ static OSSL_STORE_INFO *try_decode_X509CRL(const char *pem_name, - const char *pem_header, - const unsigned char *blob, - size_t len, void **pctx, - int *matchcount, - const UI_METHOD *ui_method, - void *ui_data, const char *uri, - OSSL_LIB_CTX *libctx, - const char *propq) + const char *pem_header, + const unsigned char *blob, + size_t len, void **pctx, + int *matchcount, + const UI_METHOD *ui_method, + void *ui_data, const char *uri, + OSSL_LIB_CTX *libctx, + const char *propq) { OSSL_STORE_INFO *store_info = NULL; X509_CRL *crl = NULL; @@ -853,22 +856,21 @@ static const FILE_HANDLER *file_handlers[] = { &PrivateKey_handler, }; - /*- * The loader itself * ----------------- */ struct ossl_store_loader_ctx_st { - char *uri; /* The URI we currently try to load */ + char *uri; /* The URI we currently try to load */ enum { is_raw = 0, is_pem, is_dir } type; int errcnt; -#define FILE_FLAG_SECMEM (1<<0) -#define FILE_FLAG_ATTACHED (1<<1) +#define FILE_FLAG_SECMEM (1 << 0) +#define FILE_FLAG_ATTACHED (1 << 1) unsigned int flags; union { struct { /* Used with is_raw and is_pem */ @@ -929,7 +931,9 @@ static void OSSL_STORE_LOADER_CTX_free(OSSL_STORE_LOADER_CTX *ctx) static int file_find_type(OSSL_STORE_LOADER_CTX *ctx) { BIO *buff = NULL; - char peekbuf[4096] = { 0, }; + char peekbuf[4096] = { + 0, + }; if ((buff = BIO_new(BIO_f_buffer())) == NULL) return 0; @@ -943,16 +947,15 @@ static int file_find_type(OSSL_STORE_LOADER_CTX *ctx) return 1; } -static OSSL_STORE_LOADER_CTX *file_open_ex - (const OSSL_STORE_LOADER *loader, const char *uri, - OSSL_LIB_CTX *libctx, const char *propq, - const UI_METHOD *ui_method, void *ui_data) +static OSSL_STORE_LOADER_CTX *file_open_ex(const OSSL_STORE_LOADER *loader, const char *uri, + OSSL_LIB_CTX *libctx, const char *propq, + const UI_METHOD *ui_method, void *ui_data) { OSSL_STORE_LOADER_CTX *ctx = NULL; struct stat st; struct { const char *path; - unsigned int check_absolute:1; + unsigned int check_absolute : 1; } path_data[2]; size_t path_data_n = 0, i; const char *path; @@ -973,7 +976,7 @@ static OSSL_STORE_LOADER_CTX *file_open_ex const char *p = &uri[5]; if (strncmp(&uri[5], "//", 2) == 0) { - path_data_n--; /* Invalidate using the full URI */ + path_data_n--; /* Invalidate using the full URI */ if (OPENSSL_strncasecmp(&uri[7], "localhost/", 10) == 0) { p = &uri[16]; } else if (uri[7] == '/') { @@ -1000,7 +1003,6 @@ static OSSL_STORE_LOADER_CTX *file_open_ex path_data[path_data_n++].path = p; } - for (i = 0, path = NULL; path == NULL && i < path_data_n; i++) { /* * If the scheme "file" was an explicit part of the URI, the path must @@ -1014,8 +1016,8 @@ static OSSL_STORE_LOADER_CTX *file_open_ex if (stat(path_data[i].path, &st) < 0) { ERR_raise_data(ERR_LIB_SYS, errno, - "calling stat(%s)", - path_data[i].path); + "calling stat(%s)", + path_data[i].path); } else { path = path_data[i].path; } @@ -1049,7 +1051,7 @@ static OSSL_STORE_LOADER_CTX *file_open_ex ctx->_.dir.end_reached = 1; } } else if ((ctx->_.file.file = BIO_new_file(path, "rb")) == NULL - || !file_find_type(ctx)) { + || !file_find_type(ctx)) { BIO_free_all(ctx->_.file.file); goto err; } @@ -1063,22 +1065,20 @@ static OSSL_STORE_LOADER_CTX *file_open_ex ctx->libctx = libctx; return ctx; - err: +err: OSSL_STORE_LOADER_CTX_free(ctx); return NULL; } -static OSSL_STORE_LOADER_CTX *file_open - (const OSSL_STORE_LOADER *loader, const char *uri, - const UI_METHOD *ui_method, void *ui_data) +static OSSL_STORE_LOADER_CTX *file_open(const OSSL_STORE_LOADER *loader, const char *uri, + const UI_METHOD *ui_method, void *ui_data) { return file_open_ex(loader, uri, NULL, NULL, ui_method, ui_data); } -static OSSL_STORE_LOADER_CTX *file_attach - (const OSSL_STORE_LOADER *loader, BIO *bp, - OSSL_LIB_CTX *libctx, const char *propq, - const UI_METHOD *ui_method, void *ui_data) +static OSSL_STORE_LOADER_CTX *file_attach(const OSSL_STORE_LOADER *loader, BIO *bp, + OSSL_LIB_CTX *libctx, const char *propq, + const UI_METHOD *ui_method, void *ui_data) { OSSL_STORE_LOADER_CTX *ctx = NULL; @@ -1107,24 +1107,22 @@ static int file_ctrl(OSSL_STORE_LOADER_CTX *ctx, int cmd, va_list args) int ret = 1; switch (cmd) { - case OSSL_STORE_C_USE_SECMEM: - { - int on = *(va_arg(args, int *)); + case OSSL_STORE_C_USE_SECMEM: { + int on = *(va_arg(args, int *)); - switch (on) { - case 0: - ctx->flags &= ~FILE_FLAG_SECMEM; - break; - case 1: - ctx->flags |= FILE_FLAG_SECMEM; - break; - default: - ATTICerr(0, ERR_R_PASSED_INVALID_ARGUMENT); - ret = 0; - break; - } + switch (on) { + case 0: + ctx->flags &= ~FILE_FLAG_SECMEM; + break; + case 1: + ctx->flags |= FILE_FLAG_SECMEM; + break; + default: + ATTICerr(0, ERR_R_PASSED_INVALID_ARGUMENT); + ret = 0; + break; } - break; + } break; default: break; } @@ -1139,7 +1137,7 @@ static int file_expect(OSSL_STORE_LOADER_CTX *ctx, int expected) } static int file_find(OSSL_STORE_LOADER_CTX *ctx, - const OSSL_STORE_SEARCH *search) + const OSSL_STORE_SEARCH *search) { /* * If ctx == NULL, the library is looking to know if this loader supports @@ -1158,9 +1156,9 @@ static int file_find(OSSL_STORE_LOADER_CTX *ctx, } hash = X509_NAME_hash_ex(OSSL_STORE_SEARCH_get0_name(search), - NULL, NULL, NULL); + NULL, NULL, NULL); BIO_snprintf(ctx->_.dir.search_name, sizeof(ctx->_.dir.search_name), - "%08lx", hash); + "%08lx", hash); return 1; } @@ -1170,87 +1168,84 @@ static int file_find(OSSL_STORE_LOADER_CTX *ctx, } static OSSL_STORE_INFO *file_load_try_decode(OSSL_STORE_LOADER_CTX *ctx, - const char *pem_name, - const char *pem_header, - unsigned char *data, size_t len, - const UI_METHOD *ui_method, - void *ui_data, int *matchcount) + const char *pem_name, + const char *pem_header, + unsigned char *data, size_t len, + const UI_METHOD *ui_method, + void *ui_data, int *matchcount) { OSSL_STORE_INFO *result = NULL; BUF_MEM *new_mem = NULL; char *new_pem_name = NULL; int t = 0; - again: - { - size_t i = 0; - void *handler_ctx = NULL; - const FILE_HANDLER **matching_handlers = - OPENSSL_zalloc(sizeof(*matching_handlers) - * OSSL_NELEM(file_handlers)); +again: { + size_t i = 0; + void *handler_ctx = NULL; + const FILE_HANDLER **matching_handlers = OPENSSL_zalloc(sizeof(*matching_handlers) + * OSSL_NELEM(file_handlers)); - if (matching_handlers == NULL) { - ATTICerr(0, ERR_R_MALLOC_FAILURE); - goto err; - } + if (matching_handlers == NULL) { + ATTICerr(0, ERR_R_MALLOC_FAILURE); + goto err; + } - *matchcount = 0; - for (i = 0; i < OSSL_NELEM(file_handlers); i++) { - const FILE_HANDLER *handler = file_handlers[i]; - int try_matchcount = 0; - void *tmp_handler_ctx = NULL; - OSSL_STORE_INFO *tmp_result; - unsigned long err; + *matchcount = 0; + for (i = 0; i < OSSL_NELEM(file_handlers); i++) { + const FILE_HANDLER *handler = file_handlers[i]; + int try_matchcount = 0; + void *tmp_handler_ctx = NULL; + OSSL_STORE_INFO *tmp_result; + unsigned long err; - ERR_set_mark(); - tmp_result = - handler->try_decode(pem_name, pem_header, data, len, - &tmp_handler_ctx, &try_matchcount, - ui_method, ui_data, ctx->uri, - ctx->libctx, ctx->propq); - /* avoid flooding error queue with low-level ASN.1 parse errors */ - err = ERR_peek_last_error(); - if (ERR_GET_LIB(err) == ERR_LIB_ASN1 - && ERR_GET_REASON(err) == ERR_R_NESTED_ASN1_ERROR) - ERR_pop_to_mark(); - else - ERR_clear_last_mark(); + ERR_set_mark(); + tmp_result = handler->try_decode(pem_name, pem_header, data, len, + &tmp_handler_ctx, &try_matchcount, + ui_method, ui_data, ctx->uri, + ctx->libctx, ctx->propq); + /* avoid flooding error queue with low-level ASN.1 parse errors */ + err = ERR_peek_last_error(); + if (ERR_GET_LIB(err) == ERR_LIB_ASN1 + && ERR_GET_REASON(err) == ERR_R_NESTED_ASN1_ERROR) + ERR_pop_to_mark(); + else + ERR_clear_last_mark(); - if (try_matchcount > 0) { + if (try_matchcount > 0) { - matching_handlers[*matchcount] = handler; + matching_handlers[*matchcount] = handler; - if (handler_ctx) - handler->destroy_ctx(&handler_ctx); - handler_ctx = tmp_handler_ctx; + if (handler_ctx) + handler->destroy_ctx(&handler_ctx); + handler_ctx = tmp_handler_ctx; - if ((*matchcount += try_matchcount) > 1) { - /* more than one match => ambiguous, kill any result */ - store_info_free(result); - store_info_free(tmp_result); - if (handler->destroy_ctx != NULL) - handler->destroy_ctx(&handler_ctx); - handler_ctx = NULL; - tmp_result = NULL; - result = NULL; - } - if (result == NULL) - result = tmp_result; - if (result == NULL) /* e.g., PKCS#12 file decryption error */ - break; + if ((*matchcount += try_matchcount) > 1) { + /* more than one match => ambiguous, kill any result */ + store_info_free(result); + store_info_free(tmp_result); + if (handler->destroy_ctx != NULL) + handler->destroy_ctx(&handler_ctx); + handler_ctx = NULL; + tmp_result = NULL; + result = NULL; } + if (result == NULL) + result = tmp_result; + if (result == NULL) /* e.g., PKCS#12 file decryption error */ + break; } + } - if (result != NULL - && *matchcount == 1 && matching_handlers[0]->repeatable) { - ctx->_.file.last_handler = matching_handlers[0]; - ctx->_.file.last_handler_ctx = handler_ctx; - } - - OPENSSL_free(matching_handlers); + if (result != NULL + && *matchcount == 1 && matching_handlers[0]->repeatable) { + ctx->_.file.last_handler = matching_handlers[0]; + ctx->_.file.last_handler_ctx = handler_ctx; } - err: + OPENSSL_free(matching_handlers); +} + +err: OPENSSL_free(new_pem_name); BUF_MEM_free(new_mem); @@ -1275,19 +1270,18 @@ static OSSL_STORE_INFO *file_load_try_decode(OSSL_STORE_LOADER_CTX *ctx, } static OSSL_STORE_INFO *file_load_try_repeat(OSSL_STORE_LOADER_CTX *ctx, - const UI_METHOD *ui_method, - void *ui_data) + const UI_METHOD *ui_method, + void *ui_data) { OSSL_STORE_INFO *result = NULL; int try_matchcount = 0; if (ctx->_.file.last_handler != NULL) { - result = - ctx->_.file.last_handler->try_decode(NULL, NULL, NULL, 0, - &ctx->_.file.last_handler_ctx, - &try_matchcount, - ui_method, ui_data, ctx->uri, - ctx->libctx, ctx->propq); + result = ctx->_.file.last_handler->try_decode(NULL, NULL, NULL, 0, + &ctx->_.file.last_handler_ctx, + &try_matchcount, + ui_method, ui_data, ctx->uri, + ctx->libctx, ctx->propq); if (result == NULL) { ctx->_.file.last_handler->destroy_ctx(&ctx->_.file.last_handler_ctx); @@ -1306,13 +1300,13 @@ static void pem_free_flag(void *pem_data, int secure, size_t num) OPENSSL_free(pem_data); } static int file_read_pem(BIO *bp, char **pem_name, char **pem_header, - unsigned char **data, long *len, - const UI_METHOD *ui_method, void *ui_data, - const char *uri, int secure) + unsigned char **data, long *len, + const UI_METHOD *ui_method, void *ui_data, + const char *uri, int secure) { int i = secure ? PEM_read_bio_ex(bp, pem_name, pem_header, data, len, - PEM_FLAG_SECURE | PEM_FLAG_EAY_COMPATIBLE) + PEM_FLAG_SECURE | PEM_FLAG_EAY_COMPATIBLE) : PEM_read_bio(bp, pem_name, pem_header, data, len); if (i <= 0) @@ -1330,9 +1324,9 @@ static int file_read_pem(BIO *bp, char **pem_name, char **pem_header, if (!PEM_get_EVP_CIPHER_INFO(*pem_header, &cipher) || !file_fill_pem_pass_data(&pass_data, "PEM pass phrase", uri, - ui_method, ui_data) + ui_method, ui_data) || !PEM_do_header(&cipher, *data, len, file_get_pem_pass, - &pass_data)) { + &pass_data)) { return 0; } } @@ -1347,13 +1341,16 @@ static OSSL_STORE_INFO *file_try_read_msblob(BIO *bp, int *matchcount) { unsigned int magic = 0, bitlen = 0; int isdss = 0; - unsigned char peekbuf[16] = { 0, }; + unsigned char peekbuf[16] = { + 0, + }; const unsigned char *p = peekbuf; if (BIO_buffer_peek(bp, peekbuf, sizeof(peekbuf)) <= 0) return 0; if (ossl_do_blob_header(&p, sizeof(peekbuf), &magic, &bitlen, - &isdss, &ispub) <= 0) + &isdss, &ispub) + <= 0) return 0; } @@ -1375,14 +1372,16 @@ static OSSL_STORE_INFO *file_try_read_msblob(BIO *bp, int *matchcount) } static OSSL_STORE_INFO *file_try_read_PVK(BIO *bp, const UI_METHOD *ui_method, - void *ui_data, const char *uri, - int *matchcount) + void *ui_data, const char *uri, + int *matchcount) { OSSL_STORE_INFO *result = NULL; { unsigned int saltlen = 0, keylen = 0; - unsigned char peekbuf[24] = { 0, }; + unsigned char peekbuf[24] = { + 0, + }; const unsigned char *p = peekbuf; if (BIO_buffer_peek(bp, peekbuf, sizeof(peekbuf)) <= 0) @@ -1398,7 +1397,7 @@ static OSSL_STORE_INFO *file_try_read_PVK(BIO *bp, const UI_METHOD *ui_method, struct pem_pass_data pass_data; if (!file_fill_pem_pass_data(&pass_data, "PVK pass phrase", uri, - ui_method, ui_data) + ui_method, ui_data) || (tmp = b2i_PVK_bio(bp, file_get_pem_pass, &pass_data)) == NULL || (result = OSSL_STORE_INFO_new_PKEY(tmp)) == NULL) { EVP_PKEY_free(tmp); @@ -1424,7 +1423,7 @@ static int file_read_asn1(BIO *bp, unsigned char **data, long *len) } static int file_name_to_uri(OSSL_STORE_LOADER_CTX *ctx, const char *name, - char **data) + char **data) { assert(name != NULL); assert(data != NULL); @@ -1511,8 +1510,8 @@ static int file_name_check(OSSL_STORE_LOADER_CTX *ctx, const char *name) static int file_eof(OSSL_STORE_LOADER_CTX *ctx); static int file_error(OSSL_STORE_LOADER_CTX *ctx); static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, - const UI_METHOD *ui_method, - void *ui_data) + const UI_METHOD *ui_method, + void *ui_data) { OSSL_STORE_INFO *result = NULL; @@ -1557,7 +1556,7 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, } else { int matchcount = -1; - again: + again: result = file_load_try_repeat(ctx, ui_method, ui_data); if (result != NULL) return result; @@ -1566,25 +1565,27 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, return NULL; do { - char *pem_name = NULL; /* PEM record name */ - char *pem_header = NULL; /* PEM record header */ + char *pem_name = NULL; /* PEM record name */ + char *pem_header = NULL; /* PEM record header */ unsigned char *data = NULL; /* DER encoded data */ - long len = 0; /* DER encoded data length */ + long len = 0; /* DER encoded data length */ matchcount = -1; if (ctx->type == is_pem) { if (!file_read_pem(ctx->_.file.file, &pem_name, &pem_header, - &data, &len, ui_method, ui_data, ctx->uri, - (ctx->flags & FILE_FLAG_SECMEM) != 0)) { + &data, &len, ui_method, ui_data, ctx->uri, + (ctx->flags & FILE_FLAG_SECMEM) != 0)) { ctx->errcnt++; goto endloop; } } else { if ((result = file_try_read_msblob(ctx->_.file.file, - &matchcount)) != NULL + &matchcount)) + != NULL || (result = file_try_read_PVK(ctx->_.file.file, - ui_method, ui_data, ctx->uri, - &matchcount)) != NULL) + ui_method, ui_data, ctx->uri, + &matchcount)) + != NULL) goto endloop; if (!file_read_asn1(ctx->_.file.file, &data, &len)) { @@ -1594,7 +1595,7 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, } result = file_load_try_decode(ctx, pem_name, pem_header, data, len, - ui_method, ui_data, &matchcount); + ui_method, ui_data, &matchcount); if (result != NULL) goto endloop; @@ -1624,7 +1625,7 @@ static OSSL_STORE_INFO *file_load(OSSL_STORE_LOADER_CTX *ctx, if (matchcount > 0) ctx->errcnt++; - endloop: + endloop: pem_free_flag(pem_name, (ctx->flags & FILE_FLAG_SECMEM) != 0, 0); pem_free_flag(pem_header, (ctx->flags & FILE_FLAG_SECMEM) != 0, 0); pem_free_flag(data, (ctx->flags & FILE_FLAG_SECMEM) != 0, len); @@ -1702,13 +1703,11 @@ static int loader_attic_init(ENGINE *e) return 1; } - static int loader_attic_finish(ENGINE *e) { return 1; } - static int loader_attic_destroy(ENGINE *e) { OSSL_STORE_LOADER *loader = OSSL_STORE_unregister_loader("file"); @@ -1757,7 +1756,7 @@ static int bind_loader_attic(ENGINE *e) } #ifdef OPENSSL_NO_DYNAMIC_ENGINE -# error "Only allowed as dynamically shared object" +#error "Only allowed as dynamically shared object" #endif static int bind_helper(ENGINE *e, const char *id) @@ -1770,4 +1769,4 @@ static int bind_helper(ENGINE *e, const char *id) } IMPLEMENT_DYNAMIC_CHECK_FN() - IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) +IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) diff --git a/engines/e_loader_attic_err.c b/engines/e_loader_attic_err.c index d7c71463d8cc..749b0b415bac 100644 --- a/engines/e_loader_attic_err.c +++ b/engines/e_loader_attic_err.c @@ -14,25 +14,25 @@ #ifndef OPENSSL_NO_ERR static ERR_STRING_DATA ATTIC_str_reasons[] = { - {ERR_PACK(0, 0, ATTIC_R_AMBIGUOUS_CONTENT_TYPE), "ambiguous content type"}, - {ERR_PACK(0, 0, ATTIC_R_BAD_PASSWORD_READ), "bad password read"}, - {ERR_PACK(0, 0, ATTIC_R_ERROR_VERIFYING_PKCS12_MAC), - "error verifying pkcs12 mac"}, - {ERR_PACK(0, 0, ATTIC_R_INIT_FAILED), "init failed"}, - {ERR_PACK(0, 0, ATTIC_R_PASSPHRASE_CALLBACK_ERROR), - "passphrase callback error"}, - {ERR_PACK(0, 0, ATTIC_R_PATH_MUST_BE_ABSOLUTE), "path must be absolute"}, - {ERR_PACK(0, 0, ATTIC_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES), - "search only supported for directories"}, - {ERR_PACK(0, 0, ATTIC_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED), - "ui process interrupted or cancelled"}, - {ERR_PACK(0, 0, ATTIC_R_UNSUPPORTED_CONTENT_TYPE), - "unsupported content type"}, - {ERR_PACK(0, 0, ATTIC_R_UNSUPPORTED_SEARCH_TYPE), - "unsupported search type"}, - {ERR_PACK(0, 0, ATTIC_R_URI_AUTHORITY_UNSUPPORTED), - "uri authority unsupported"}, - {0, NULL} + { ERR_PACK(0, 0, ATTIC_R_AMBIGUOUS_CONTENT_TYPE), "ambiguous content type" }, + { ERR_PACK(0, 0, ATTIC_R_BAD_PASSWORD_READ), "bad password read" }, + { ERR_PACK(0, 0, ATTIC_R_ERROR_VERIFYING_PKCS12_MAC), + "error verifying pkcs12 mac" }, + { ERR_PACK(0, 0, ATTIC_R_INIT_FAILED), "init failed" }, + { ERR_PACK(0, 0, ATTIC_R_PASSPHRASE_CALLBACK_ERROR), + "passphrase callback error" }, + { ERR_PACK(0, 0, ATTIC_R_PATH_MUST_BE_ABSOLUTE), "path must be absolute" }, + { ERR_PACK(0, 0, ATTIC_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES), + "search only supported for directories" }, + { ERR_PACK(0, 0, ATTIC_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED), + "ui process interrupted or cancelled" }, + { ERR_PACK(0, 0, ATTIC_R_UNSUPPORTED_CONTENT_TYPE), + "unsupported content type" }, + { ERR_PACK(0, 0, ATTIC_R_UNSUPPORTED_SEARCH_TYPE), + "unsupported search type" }, + { ERR_PACK(0, 0, ATTIC_R_URI_AUTHORITY_UNSUPPORTED), + "uri authority unsupported" }, + { 0, NULL } }; #endif diff --git a/engines/e_loader_attic_err.h b/engines/e_loader_attic_err.h index b4a144f4cbca..eab95c102d53 100644 --- a/engines/e_loader_attic_err.h +++ b/engines/e_loader_attic_err.h @@ -9,29 +9,27 @@ */ #ifndef OSSL_E_LOADER_ATTIC_ERR_H -# define OSSL_E_LOADER_ATTIC_ERR_H -# pragma once +#define OSSL_E_LOADER_ATTIC_ERR_H +#pragma once -# include <openssl/opensslconf.h> -# include <openssl/symhacks.h> - - -# define ATTICerr(f, r) ERR_ATTIC_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) +#include <openssl/opensslconf.h> +#include <openssl/symhacks.h> +#define ATTICerr(f, r) ERR_ATTIC_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) /* * ATTIC reason codes. */ -# define ATTIC_R_AMBIGUOUS_CONTENT_TYPE 100 -# define ATTIC_R_BAD_PASSWORD_READ 101 -# define ATTIC_R_ERROR_VERIFYING_PKCS12_MAC 102 -# define ATTIC_R_INIT_FAILED 103 -# define ATTIC_R_PASSPHRASE_CALLBACK_ERROR 104 -# define ATTIC_R_PATH_MUST_BE_ABSOLUTE 105 -# define ATTIC_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES 106 -# define ATTIC_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED 107 -# define ATTIC_R_UNSUPPORTED_CONTENT_TYPE 108 -# define ATTIC_R_UNSUPPORTED_SEARCH_TYPE 109 -# define ATTIC_R_URI_AUTHORITY_UNSUPPORTED 110 +#define ATTIC_R_AMBIGUOUS_CONTENT_TYPE 100 +#define ATTIC_R_BAD_PASSWORD_READ 101 +#define ATTIC_R_ERROR_VERIFYING_PKCS12_MAC 102 +#define ATTIC_R_INIT_FAILED 103 +#define ATTIC_R_PASSPHRASE_CALLBACK_ERROR 104 +#define ATTIC_R_PATH_MUST_BE_ABSOLUTE 105 +#define ATTIC_R_SEARCH_ONLY_SUPPORTED_FOR_DIRECTORIES 106 +#define ATTIC_R_UI_PROCESS_INTERRUPTED_OR_CANCELLED 107 +#define ATTIC_R_UNSUPPORTED_CONTENT_TYPE 108 +#define ATTIC_R_UNSUPPORTED_SEARCH_TYPE 109 +#define ATTIC_R_URI_AUTHORITY_UNSUPPORTED 110 #endif diff --git a/engines/e_ossltest.c b/engines/e_ossltest.c index c925d2c5a6a7..0024c37843e9 100644 --- a/engines/e_ossltest.c +++ b/engines/e_ossltest.c @@ -40,29 +40,29 @@ #include <openssl/pem.h> #include <crypto/evp.h> +/* clang-format off */ #include "e_ossltest_err.c" +/* clang-format on */ /* Engine Id and Name */ static const char *engine_ossltest_id = "ossltest"; static const char *engine_ossltest_name = "OpenSSL Test engine support"; - /* Engine Lifetime functions */ static int ossltest_destroy(ENGINE *e); static int ossltest_init(ENGINE *e); static int ossltest_finish(ENGINE *e); void ENGINE_load_ossltest(void); - /* Set up digests */ static int ossltest_digests(ENGINE *e, const EVP_MD **digest, - const int **nids, int nid); + const int **nids, int nid); static const RAND_METHOD *ossltest_rand_method(void); /* MD5 */ static int digest_md5_init(EVP_MD_CTX *ctx); static int digest_md5_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int digest_md5_final(EVP_MD_CTX *ctx, unsigned char *md); static EVP_MD *_hidden_md5_md = NULL; @@ -75,7 +75,7 @@ static const EVP_MD *digest_md5(void) || !EVP_MD_meth_set_result_size(md, MD5_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(md, MD5_CBLOCK) || !EVP_MD_meth_set_app_datasize(md, - sizeof(EVP_MD *) + sizeof(MD5_CTX)) + sizeof(EVP_MD *) + sizeof(MD5_CTX)) || !EVP_MD_meth_set_flags(md, 0) || !EVP_MD_meth_set_init(md, digest_md5_init) || !EVP_MD_meth_set_update(md, digest_md5_update) @@ -91,7 +91,7 @@ static const EVP_MD *digest_md5(void) /* SHA1 */ static int digest_sha1_init(EVP_MD_CTX *ctx); static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int digest_sha1_final(EVP_MD_CTX *ctx, unsigned char *md); static EVP_MD *_hidden_sha1_md = NULL; @@ -104,7 +104,7 @@ static const EVP_MD *digest_sha1(void) || !EVP_MD_meth_set_result_size(md, SHA_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(md, SHA_CBLOCK) || !EVP_MD_meth_set_app_datasize(md, - sizeof(EVP_MD *) + sizeof(SHA_CTX)) + sizeof(EVP_MD *) + sizeof(SHA_CTX)) || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_DIGALGID_ABSENT) || !EVP_MD_meth_set_init(md, digest_sha1_init) || !EVP_MD_meth_set_update(md, digest_sha1_update) @@ -120,7 +120,7 @@ static const EVP_MD *digest_sha1(void) /* SHA256 */ static int digest_sha256_init(EVP_MD_CTX *ctx); static int digest_sha256_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int digest_sha256_final(EVP_MD_CTX *ctx, unsigned char *md); static EVP_MD *_hidden_sha256_md = NULL; @@ -133,7 +133,7 @@ static const EVP_MD *digest_sha256(void) || !EVP_MD_meth_set_result_size(md, SHA256_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(md, SHA256_CBLOCK) || !EVP_MD_meth_set_app_datasize(md, - sizeof(EVP_MD *) + sizeof(SHA256_CTX)) + sizeof(EVP_MD *) + sizeof(SHA256_CTX)) || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_DIGALGID_ABSENT) || !EVP_MD_meth_set_init(md, digest_sha256_init) || !EVP_MD_meth_set_update(md, digest_sha256_update) @@ -149,12 +149,12 @@ static const EVP_MD *digest_sha256(void) /* SHA384/SHA512 */ static int digest_sha384_init(EVP_MD_CTX *ctx); static int digest_sha384_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int digest_sha384_final(EVP_MD_CTX *ctx, unsigned char *md); static int digest_sha512_init(EVP_MD_CTX *ctx); static int digest_sha512_update(EVP_MD_CTX *ctx, const void *data, - size_t count); + size_t count); static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md); static EVP_MD *_hidden_sha384_md = NULL; @@ -167,7 +167,7 @@ static const EVP_MD *digest_sha384(void) || !EVP_MD_meth_set_result_size(md, SHA384_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(md, SHA512_CBLOCK) || !EVP_MD_meth_set_app_datasize(md, - sizeof(EVP_MD *) + sizeof(SHA512_CTX)) + sizeof(EVP_MD *) + sizeof(SHA512_CTX)) || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_DIGALGID_ABSENT) || !EVP_MD_meth_set_init(md, digest_sha384_init) || !EVP_MD_meth_set_update(md, digest_sha384_update) @@ -189,7 +189,7 @@ static const EVP_MD *digest_sha512(void) || !EVP_MD_meth_set_result_size(md, SHA512_DIGEST_LENGTH) || !EVP_MD_meth_set_input_blocksize(md, SHA512_CBLOCK) || !EVP_MD_meth_set_app_datasize(md, - sizeof(EVP_MD *) + sizeof(SHA512_CTX)) + sizeof(EVP_MD *) + sizeof(SHA512_CTX)) || !EVP_MD_meth_set_flags(md, EVP_MD_FLAG_DIGALGID_ABSENT) || !EVP_MD_meth_set_init(md, digest_sha512_init) || !EVP_MD_meth_set_update(md, digest_sha512_update) @@ -241,7 +241,7 @@ static int ossltest_digest_nids(const int **nids) /* Setup ciphers */ static int ossltest_ciphers(ENGINE *, const EVP_CIPHER **, - const int **, int); + const int **, int); static int ossltest_cipher_nids[] = { NID_aes_128_cbc, NID_aes_128_gcm, @@ -251,30 +251,30 @@ static int ossltest_cipher_nids[] = { /* AES128 */ static int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *key, + const unsigned char *iv, int enc); static int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); + const unsigned char *in, size_t inl); static int ossltest_aes128_gcm_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *key, + const unsigned char *iv, int enc); static int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl); + const unsigned char *in, size_t inl); static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr); + void *ptr); static int ossltest_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, - int enc); + const unsigned char *key, + const unsigned char *iv, + int enc); static int ossltest_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, - unsigned char *out, - const unsigned char *in, - size_t inl); + unsigned char *out, + const unsigned char *in, + size_t inl); static int ossltest_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, - int arg, void *ptr); + int arg, void *ptr); typedef struct { - size_t payload_length; /* AAD length in decrypt case */ + size_t payload_length; /* AAD length in decrypt case */ unsigned int tls_ver; } EVP_AES_HMAC_SHA1; @@ -283,18 +283,19 @@ static const EVP_CIPHER *ossltest_aes_128_cbc(void) { if (_hidden_aes_128_cbc == NULL && ((_hidden_aes_128_cbc = EVP_CIPHER_meth_new(NID_aes_128_cbc, - 16 /* block size */, - 16 /* key len */)) == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc,16) + 16 /* block size */, + 16 /* key len */)) + == NULL + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc, 16) || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc, - EVP_CIPH_FLAG_DEFAULT_ASN1 - | EVP_CIPH_CBC_MODE) + EVP_CIPH_FLAG_DEFAULT_ASN1 + | EVP_CIPH_CBC_MODE) || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc, - ossltest_aes128_init_key) + ossltest_aes128_init_key) || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc, - ossltest_aes128_cbc_cipher) + ossltest_aes128_cbc_cipher) || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc, - EVP_CIPHER_impl_ctx_size(EVP_aes_128_cbc())))) { + EVP_CIPHER_impl_ctx_size(EVP_aes_128_cbc())))) { EVP_CIPHER_meth_free(_hidden_aes_128_cbc); _hidden_aes_128_cbc = NULL; } @@ -303,28 +304,29 @@ static const EVP_CIPHER *ossltest_aes_128_cbc(void) static EVP_CIPHER *_hidden_aes_128_gcm = NULL; -#define AES_GCM_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 \ - | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ - | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT \ - | EVP_CIPH_CUSTOM_COPY |EVP_CIPH_FLAG_AEAD_CIPHER \ - | EVP_CIPH_GCM_MODE) +#define AES_GCM_FLAGS (EVP_CIPH_FLAG_DEFAULT_ASN1 \ + | EVP_CIPH_CUSTOM_IV | EVP_CIPH_FLAG_CUSTOM_CIPHER \ + | EVP_CIPH_ALWAYS_CALL_INIT | EVP_CIPH_CTRL_INIT \ + | EVP_CIPH_CUSTOM_COPY | EVP_CIPH_FLAG_AEAD_CIPHER \ + | EVP_CIPH_GCM_MODE) static const EVP_CIPHER *ossltest_aes_128_gcm(void) { if (_hidden_aes_128_gcm == NULL && ((_hidden_aes_128_gcm = EVP_CIPHER_meth_new(NID_aes_128_gcm, - 1 /* block size */, - 16 /* key len */)) == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_gcm,12) + 1 /* block size */, + 16 /* key len */)) + == NULL + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_gcm, 12) || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_gcm, AES_GCM_FLAGS) || !EVP_CIPHER_meth_set_init(_hidden_aes_128_gcm, - ossltest_aes128_gcm_init_key) + ossltest_aes128_gcm_init_key) || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_gcm, - ossltest_aes128_gcm_cipher) + ossltest_aes128_gcm_cipher) || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_gcm, - ossltest_aes128_gcm_ctrl) + ossltest_aes128_gcm_ctrl) || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_gcm, - EVP_CIPHER_impl_ctx_size(EVP_aes_128_gcm())))) { + EVP_CIPHER_impl_ctx_size(EVP_aes_128_gcm())))) { EVP_CIPHER_meth_free(_hidden_aes_128_gcm); _hidden_aes_128_gcm = NULL; } @@ -337,25 +339,25 @@ static const EVP_CIPHER *ossltest_aes_128_cbc_hmac_sha1(void) { if (_hidden_aes_128_cbc_hmac_sha1 == NULL && ((_hidden_aes_128_cbc_hmac_sha1 - = EVP_CIPHER_meth_new(NID_aes_128_cbc_hmac_sha1, - 16 /* block size */, - 16 /* key len */)) == NULL - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1,16) + = EVP_CIPHER_meth_new(NID_aes_128_cbc_hmac_sha1, + 16 /* block size */, + 16 /* key len */)) + == NULL + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_128_cbc_hmac_sha1, 16) || !EVP_CIPHER_meth_set_flags(_hidden_aes_128_cbc_hmac_sha1, - EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1 | - EVP_CIPH_FLAG_AEAD_CIPHER) + EVP_CIPH_CBC_MODE | EVP_CIPH_FLAG_DEFAULT_ASN1 | EVP_CIPH_FLAG_AEAD_CIPHER) || !EVP_CIPHER_meth_set_init(_hidden_aes_128_cbc_hmac_sha1, - ossltest_aes128_cbc_hmac_sha1_init_key) + ossltest_aes128_cbc_hmac_sha1_init_key) || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_128_cbc_hmac_sha1, - ossltest_aes128_cbc_hmac_sha1_cipher) + ossltest_aes128_cbc_hmac_sha1_cipher) || !EVP_CIPHER_meth_set_ctrl(_hidden_aes_128_cbc_hmac_sha1, - ossltest_aes128_cbc_hmac_sha1_ctrl) + ossltest_aes128_cbc_hmac_sha1_ctrl) || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_128_cbc_hmac_sha1, - EVP_CIPH_FLAG_DEFAULT_ASN1 ? NULL : EVP_CIPHER_set_asn1_iv) + EVP_CIPH_FLAG_DEFAULT_ASN1 ? NULL : EVP_CIPHER_set_asn1_iv) || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_128_cbc_hmac_sha1, - EVP_CIPH_FLAG_DEFAULT_ASN1 ? NULL : EVP_CIPHER_get_asn1_iv) + EVP_CIPH_FLAG_DEFAULT_ASN1 ? NULL : EVP_CIPHER_get_asn1_iv) || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_128_cbc_hmac_sha1, - sizeof(EVP_AES_HMAC_SHA1)))) { + sizeof(EVP_AES_HMAC_SHA1)))) { EVP_CIPHER_meth_free(_hidden_aes_128_cbc_hmac_sha1); _hidden_aes_128_cbc_hmac_sha1 = NULL; } @@ -374,7 +376,7 @@ static void destroy_ciphers(void) /* Key loading */ static EVP_PKEY *load_key(ENGINE *eng, const char *key_id, int pub, - UI_METHOD *ui_method, void *ui_data) + UI_METHOD *ui_method, void *ui_data) { BIO *in; EVP_PKEY *key; @@ -384,7 +386,7 @@ static EVP_PKEY *load_key(ENGINE *eng, const char *key_id, int pub, key_id += 3; fprintf(stderr, "[ossltest]Loading %s key %s\n", - pub ? "Public" : "Private", key_id); + pub ? "Public" : "Private", key_id); in = BIO_new_file(key_id, "r"); if (!in) return NULL; @@ -397,18 +399,17 @@ static EVP_PKEY *load_key(ENGINE *eng, const char *key_id, int pub, } static EVP_PKEY *ossltest_load_privkey(ENGINE *eng, const char *key_id, - UI_METHOD *ui_method, void *ui_data) + UI_METHOD *ui_method, void *ui_data) { return load_key(eng, key_id, 0, ui_method, ui_data); } static EVP_PKEY *ossltest_load_pubkey(ENGINE *eng, const char *key_id, - UI_METHOD *ui_method, void *ui_data) + UI_METHOD *ui_method, void *ui_data) { return load_key(eng, key_id, 1, ui_method, ui_data); } - static int bind_ossltest(ENGINE *e) { /* Ensure the ossltest error handling is set up */ @@ -442,7 +443,7 @@ static int bind_helper(ENGINE *e, const char *id) } IMPLEMENT_DYNAMIC_CHECK_FN() - IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) +IMPLEMENT_DYNAMIC_BIND_FN(bind_helper) #endif static ENGINE *engine_ossltest(void) @@ -468,19 +469,16 @@ void ENGINE_load_ossltest(void) ERR_clear_error(); } - static int ossltest_init(ENGINE *e) { return 1; } - static int ossltest_finish(ENGINE *e) { return 1; } - static int ossltest_destroy(ENGINE *e) { destroy_digests(); @@ -490,7 +488,7 @@ static int ossltest_destroy(ENGINE *e) } static int ossltest_digests(ENGINE *e, const EVP_MD **digest, - const int **nids, int nid) + const int **nids, int nid) { int ok = 1; if (!digest) { @@ -523,14 +521,14 @@ static int ossltest_digests(ENGINE *e, const EVP_MD **digest, } static int ossltest_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid) + const int **nids, int nid) { int ok = 1; if (!cipher) { /* We are returning a list of supported nids */ *nids = ossltest_cipher_nids; return (sizeof(ossltest_cipher_nids) - 1) - / sizeof(ossltest_cipher_nids[0]); + / sizeof(ossltest_cipher_nids[0]); } /* We are being asked for a specific cipher */ switch (nid) { @@ -555,7 +553,7 @@ static void fill_known_data(unsigned char *md, unsigned int len) { unsigned int i; - for (i=0; i<len; i++) { + for (i = 0; i < len; i++) { md[i] = (unsigned char)(i & 0xff); } } @@ -568,11 +566,11 @@ static void fill_known_data(unsigned char *md, unsigned int len) */ static int digest_md5_init(EVP_MD_CTX *ctx) { - return EVP_MD_meth_get_init(EVP_md5())(ctx); + return EVP_MD_meth_get_init(EVP_md5())(ctx); } static int digest_md5_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { return EVP_MD_meth_get_update(EVP_md5())(ctx, data, count); } @@ -596,7 +594,7 @@ static int digest_sha1_init(EVP_MD_CTX *ctx) } static int digest_sha1_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { return EVP_MD_meth_get_update(EVP_sha1())(ctx, data, count); } @@ -620,7 +618,7 @@ static int digest_sha256_init(EVP_MD_CTX *ctx) } static int digest_sha256_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { return EVP_MD_meth_get_update(EVP_sha256())(ctx, data, count); } @@ -644,7 +642,7 @@ static int digest_sha384_init(EVP_MD_CTX *ctx) } static int digest_sha384_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { return EVP_MD_meth_get_update(EVP_sha384())(ctx, data, count); } @@ -668,7 +666,7 @@ static int digest_sha512_init(EVP_MD_CTX *ctx) } static int digest_sha512_update(EVP_MD_CTX *ctx, const void *data, - size_t count) + size_t count) { return EVP_MD_meth_get_update(EVP_sha512())(ctx, data, count); } @@ -688,14 +686,14 @@ static int digest_sha512_final(EVP_MD_CTX *ctx, unsigned char *md) */ static int ossltest_aes128_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *key, + const unsigned char *iv, int enc) { - return EVP_CIPHER_meth_get_init(EVP_aes_128_cbc()) (ctx, key, iv, enc); + return EVP_CIPHER_meth_get_init(EVP_aes_128_cbc())(ctx, key, iv, enc); } static int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { unsigned char *tmpbuf; int ret; @@ -722,14 +720,14 @@ static int ossltest_aes128_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } static int ossltest_aes128_gcm_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *key, + const unsigned char *iv, int enc) { - return EVP_CIPHER_meth_get_init(EVP_aes_128_gcm()) (ctx, key, iv, enc); + return EVP_CIPHER_meth_get_init(EVP_aes_128_gcm())(ctx, key, iv, enc); } static int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, - const unsigned char *in, size_t inl) + const unsigned char *in, size_t inl) { unsigned char *tmpbuf = OPENSSL_malloc(inl); @@ -753,7 +751,7 @@ static int ossltest_aes128_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, } static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, - void *ptr) + void *ptr) { /* Pass the ctrl down */ int ret = EVP_CIPHER_meth_get_ctrl(EVP_aes_128_gcm())(ctx, type, arg, ptr); @@ -761,7 +759,7 @@ static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, if (ret <= 0) return ret; - switch(type) { + switch (type) { case EVP_CTRL_AEAD_GET_TAG: /* Always give the same tag */ memset(ptr, 0, EVP_GCM_TLS_TAG_LEN); @@ -774,13 +772,13 @@ static int ossltest_aes128_gcm_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, return 1; } -#define NO_PAYLOAD_LENGTH ((size_t)-1) -# define data(ctx) ((EVP_AES_HMAC_SHA1 *)EVP_CIPHER_CTX_get_cipher_data(ctx)) +#define NO_PAYLOAD_LENGTH ((size_t)-1) +#define data(ctx) ((EVP_AES_HMAC_SHA1 *)EVP_CIPHER_CTX_get_cipher_data(ctx)) static int ossltest_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, - const unsigned char *inkey, - const unsigned char *iv, - int enc) + const unsigned char *inkey, + const unsigned char *iv, + int enc) { EVP_AES_HMAC_SHA1 *key = data(ctx); key->payload_length = NO_PAYLOAD_LENGTH; @@ -788,9 +786,9 @@ static int ossltest_aes128_cbc_hmac_sha1_init_key(EVP_CIPHER_CTX *ctx, } static int ossltest_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, - unsigned char *out, - const unsigned char *in, - size_t len) + unsigned char *out, + const unsigned char *in, + size_t len) { EVP_AES_HMAC_SHA1 *key = data(ctx); unsigned int l; @@ -804,14 +802,12 @@ static int ossltest_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, if (EVP_CIPHER_CTX_is_encrypting(ctx)) { if (plen == NO_PAYLOAD_LENGTH) plen = len; - else if (len != - ((plen + SHA_DIGEST_LENGTH + - AES_BLOCK_SIZE) & -AES_BLOCK_SIZE)) + else if (len != ((plen + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE) & -AES_BLOCK_SIZE)) return 0; memmove(out, in, plen); - if (plen != len) { /* "TLS" mode of operation */ + if (plen != len) { /* "TLS" mode of operation */ /* calculate HMAC and append it to payload */ fill_known_data(out + plen, SHA_DIGEST_LENGTH); @@ -853,7 +849,7 @@ static int ossltest_aes128_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, } static int ossltest_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, - int arg, void *ptr) + int arg, void *ptr) { EVP_AES_HMAC_SHA1 *key = data(ctx); @@ -861,36 +857,34 @@ static int ossltest_aes128_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, case EVP_CTRL_AEAD_SET_MAC_KEY: return 1; - case EVP_CTRL_AEAD_TLS1_AAD: - { - unsigned char *p = ptr; - unsigned int len; + case EVP_CTRL_AEAD_TLS1_AAD: { + unsigned char *p = ptr; + unsigned int len; - if (arg != EVP_AEAD_TLS1_AAD_LEN) - return -1; + if (arg != EVP_AEAD_TLS1_AAD_LEN) + return -1; - len = p[arg - 2] << 8 | p[arg - 1]; - key->tls_ver = p[arg - 4] << 8 | p[arg - 3]; + len = p[arg - 2] << 8 | p[arg - 1]; + key->tls_ver = p[arg - 4] << 8 | p[arg - 3]; - if (EVP_CIPHER_CTX_is_encrypting(ctx)) { - key->payload_length = len; - if (key->tls_ver >= TLS1_1_VERSION) { - if (len < AES_BLOCK_SIZE) - return 0; - len -= AES_BLOCK_SIZE; - p[arg - 2] = len >> 8; - p[arg - 1] = len; - } + if (EVP_CIPHER_CTX_is_encrypting(ctx)) { + key->payload_length = len; + if (key->tls_ver >= TLS1_1_VERSION) { + if (len < AES_BLOCK_SIZE) + return 0; + len -= AES_BLOCK_SIZE; + p[arg - 2] = len >> 8; + p[arg - 1] = len; + } - return (int)(((len + SHA_DIGEST_LENGTH + - AES_BLOCK_SIZE) & -AES_BLOCK_SIZE) - - len); - } else { - key->payload_length = arg; + return (int)(((len + SHA_DIGEST_LENGTH + AES_BLOCK_SIZE) & -AES_BLOCK_SIZE) + - len); + } else { + key->payload_length = arg; - return SHA_DIGEST_LENGTH; - } + return SHA_DIGEST_LENGTH; } + } default: return -1; } diff --git a/engines/e_ossltest_err.c b/engines/e_ossltest_err.c index f229aeb4384c..d43b715dd5cf 100644 --- a/engines/e_ossltest_err.c +++ b/engines/e_ossltest_err.c @@ -14,8 +14,8 @@ #ifndef OPENSSL_NO_ERR static ERR_STRING_DATA OSSLTEST_str_reasons[] = { - {ERR_PACK(0, 0, OSSLTEST_R_INIT_FAILED), "init failed"}, - {0, NULL} + { ERR_PACK(0, 0, OSSLTEST_R_INIT_FAILED), "init failed" }, + { 0, NULL } }; #endif diff --git a/engines/e_ossltest_err.h b/engines/e_ossltest_err.h index c89409079be7..75dbeeeee7b5 100644 --- a/engines/e_ossltest_err.h +++ b/engines/e_ossltest_err.h @@ -9,19 +9,17 @@ */ #ifndef OSSL_E_OSSLTEST_ERR_H -# define OSSL_E_OSSLTEST_ERR_H -# pragma once +#define OSSL_E_OSSLTEST_ERR_H +#pragma once -# include <openssl/opensslconf.h> -# include <openssl/symhacks.h> - - -# define OSSLTESTerr(f, r) ERR_OSSLTEST_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) +#include <openssl/opensslconf.h> +#include <openssl/symhacks.h> +#define OSSLTESTerr(f, r) ERR_OSSLTEST_error(0, (r), OPENSSL_FILE, OPENSSL_LINE) /* * OSSLTEST reason codes. */ -# define OSSLTEST_R_INIT_FAILED 100 +#define OSSLTEST_R_INIT_FAILED 100 #endif diff --git a/engines/e_padlock.c b/engines/e_padlock.c index 7e0cfc21fc9b..fc66d45d3d12 100644 --- a/engines/e_padlock.c +++ b/engines/e_padlock.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2023 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 2004-2026 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -32,20 +32,20 @@ * doesn't exist elsewhere, but it even can't be compiled on other platforms! */ -# undef COMPILE_PADLOCKENG -# if defined(PADLOCK_ASM) -# define COMPILE_PADLOCKENG -# ifdef OPENSSL_NO_DYNAMIC_ENGINE +#undef COMPILE_PADLOCKENG +#if defined(PADLOCK_ASM) +#define COMPILE_PADLOCKENG +#ifdef OPENSSL_NO_DYNAMIC_ENGINE static ENGINE *ENGINE_padlock(void); -# endif -# endif +#endif +#endif -# ifdef OPENSSL_NO_DYNAMIC_ENGINE +#ifdef OPENSSL_NO_DYNAMIC_ENGINE void engine_load_padlock_int(void); void engine_load_padlock_int(void) { /* On non-x86 CPUs it just returns. */ -# ifdef COMPILE_PADLOCKENG +#ifdef COMPILE_PADLOCKENG ENGINE *toadd = ENGINE_padlock(); if (!toadd) return; @@ -62,12 +62,12 @@ void engine_load_padlock_int(void) * ENGINE_load_builtin_engines() perhaps). */ ERR_pop_to_mark(); -# endif +#endif } -# endif +#endif -# ifdef COMPILE_PADLOCKENG +#ifdef COMPILE_PADLOCKENG /* Function for ENGINE detection and control */ static int padlock_available(void); @@ -78,7 +78,7 @@ static RAND_METHOD padlock_rand; /* Cipher Stuff */ static int padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, - const int **nids, int nid); + const int **nids, int nid); /* Engine names */ static const char *padlock_id = "padlock"; @@ -104,16 +104,12 @@ static int padlock_bind_helper(ENGINE *e) /* Generate a nice engine name with available features */ BIO_snprintf(padlock_name, sizeof(padlock_name), - "VIA PadLock (%s, %s)", - padlock_use_rng ? "RNG" : "no-RNG", - padlock_use_ace ? "ACE" : "no-ACE"); + "VIA PadLock (%s, %s)", + padlock_use_rng ? "RNG" : "no-RNG", + padlock_use_ace ? "ACE" : "no-ACE"); /* Register everything or return with an error */ - if (!ENGINE_set_id(e, padlock_id) || - !ENGINE_set_name(e, padlock_name) || - !ENGINE_set_init_function(e, padlock_init) || - (padlock_use_ace && !ENGINE_set_ciphers(e, padlock_ciphers)) || - (padlock_use_rng && !ENGINE_set_RAND(e, &padlock_rand))) { + if (!ENGINE_set_id(e, padlock_id) || !ENGINE_set_name(e, padlock_name) || !ENGINE_set_init_function(e, padlock_init) || (padlock_use_ace && !ENGINE_set_ciphers(e, padlock_ciphers)) || (padlock_use_rng && !ENGINE_set_RAND(e, &padlock_rand))) { return 0; } @@ -121,7 +117,7 @@ static int padlock_bind_helper(ENGINE *e) return 1; } -# ifdef OPENSSL_NO_DYNAMIC_ENGINE +#ifdef OPENSSL_NO_DYNAMIC_ENGINE /* Constructor */ static ENGINE *ENGINE_padlock(void) { @@ -138,7 +134,7 @@ static ENGINE *ENGINE_padlock(void) return eng; } -# endif +#endif /* Check availability of the engine */ static int padlock_init(ENGINE *e) @@ -146,24 +142,26 @@ static int padlock_init(ENGINE *e) return (padlock_use_rng || padlock_use_ace); } -# ifndef AES_ASM +#ifndef AES_ASM static int padlock_aes_set_encrypt_key(const unsigned char *userKey, - const int bits, - AES_KEY *key); + const int bits, + AES_KEY *key); static int padlock_aes_set_decrypt_key(const unsigned char *userKey, - const int bits, - AES_KEY *key); -# define AES_ASM -# define AES_set_encrypt_key padlock_aes_set_encrypt_key -# define AES_set_decrypt_key padlock_aes_set_decrypt_key + const int bits, + AES_KEY *key); +#define AES_ASM +#define AES_set_encrypt_key padlock_aes_set_encrypt_key +#define AES_set_decrypt_key padlock_aes_set_decrypt_key +/* clang-format off */ # include "../crypto/aes/aes_core.c" -# endif +/* clang-format on */ +#endif /* * This stuff is needed if this ENGINE is being compiled into a * self-contained shared-library. */ -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE static int padlock_bind_fn(ENGINE *e, const char *id) { if (id && (strcmp(id, padlock_id) != 0)) { @@ -179,38 +177,38 @@ static int padlock_bind_fn(ENGINE *e, const char *id) IMPLEMENT_DYNAMIC_CHECK_FN() IMPLEMENT_DYNAMIC_BIND_FN(padlock_bind_fn) -# endif /* !OPENSSL_NO_DYNAMIC_ENGINE */ +#endif /* !OPENSSL_NO_DYNAMIC_ENGINE */ /* ===== Here comes the "real" engine ===== */ /* Some AES-related constants */ -# define AES_BLOCK_SIZE 16 -# define AES_KEY_SIZE_128 16 -# define AES_KEY_SIZE_192 24 -# define AES_KEY_SIZE_256 32 - /* - * Here we store the status information relevant to the current context. - */ - /* - * BIG FAT WARNING: Inline assembler in PADLOCK_XCRYPT_ASM() depends on - * the order of items in this structure. Don't blindly modify, reorder, - * etc! - */ +#define AES_BLOCK_SIZE 16 +#define AES_KEY_SIZE_128 16 +#define AES_KEY_SIZE_192 24 +#define AES_KEY_SIZE_256 32 +/* + * Here we store the status information relevant to the current context. + */ +/* + * BIG FAT WARNING: Inline assembler in PADLOCK_XCRYPT_ASM() depends on + * the order of items in this structure. Don't blindly modify, reorder, + * etc! + */ struct padlock_cipher_data { unsigned char iv[AES_BLOCK_SIZE]; /* Initialization vector */ union { unsigned int pad[4]; struct { - int rounds:4; - int dgst:1; /* n/a in C3 */ - int align:1; /* n/a in C3 */ - int ciphr:1; /* n/a in C3 */ - unsigned int keygen:1; - int interm:1; - unsigned int encdec:1; - int ksize:2; + int rounds : 4; + int dgst : 1; /* n/a in C3 */ + int align : 1; /* n/a in C3 */ + int ciphr : 1; /* n/a in C3 */ /* codespell:ignore */ + unsigned int keygen : 1; + int interm : 1; /* codespell:ignore */ + unsigned int encdec : 1; + int ksize : 2; } b; - } cword; /* Control word */ - AES_KEY ks; /* Encryption key */ + } cword; /* Control word */ + AES_KEY ks; /* Encryption key */ }; /* Interface to assembler module */ @@ -219,17 +217,17 @@ void padlock_key_bswap(AES_KEY *key); void padlock_verify_context(struct padlock_cipher_data *ctx); void padlock_reload_key(void); void padlock_aes_block(void *out, const void *inp, - struct padlock_cipher_data *ctx); + struct padlock_cipher_data *ctx); int padlock_ecb_encrypt(void *out, const void *inp, - struct padlock_cipher_data *ctx, size_t len); + struct padlock_cipher_data *ctx, size_t len); int padlock_cbc_encrypt(void *out, const void *inp, - struct padlock_cipher_data *ctx, size_t len); + struct padlock_cipher_data *ctx, size_t len); int padlock_cfb_encrypt(void *out, const void *inp, - struct padlock_cipher_data *ctx, size_t len); + struct padlock_cipher_data *ctx, size_t len); int padlock_ofb_encrypt(void *out, const void *inp, - struct padlock_cipher_data *ctx, size_t len); + struct padlock_cipher_data *ctx, size_t len); int padlock_ctr32_encrypt(void *out, const void *inp, - struct padlock_cipher_data *ctx, size_t len); + struct padlock_cipher_data *ctx, size_t len); int padlock_xstore(void *out, int edx); void padlock_sha1_oneshot(void *ctx, const void *inp, size_t len); void padlock_sha1(void *ctx, const void *inp, size_t len); @@ -252,29 +250,29 @@ static int padlock_available(void) /* ===== AES encryption/decryption ===== */ -# if defined(NID_aes_128_cfb128) && ! defined (NID_aes_128_cfb) -# define NID_aes_128_cfb NID_aes_128_cfb128 -# endif +#if defined(NID_aes_128_cfb128) && !defined(NID_aes_128_cfb) +#define NID_aes_128_cfb NID_aes_128_cfb128 +#endif -# if defined(NID_aes_128_ofb128) && ! defined (NID_aes_128_ofb) -# define NID_aes_128_ofb NID_aes_128_ofb128 -# endif +#if defined(NID_aes_128_ofb128) && !defined(NID_aes_128_ofb) +#define NID_aes_128_ofb NID_aes_128_ofb128 +#endif -# if defined(NID_aes_192_cfb128) && ! defined (NID_aes_192_cfb) -# define NID_aes_192_cfb NID_aes_192_cfb128 -# endif +#if defined(NID_aes_192_cfb128) && !defined(NID_aes_192_cfb) +#define NID_aes_192_cfb NID_aes_192_cfb128 +#endif -# if defined(NID_aes_192_ofb128) && ! defined (NID_aes_192_ofb) -# define NID_aes_192_ofb NID_aes_192_ofb128 -# endif +#if defined(NID_aes_192_ofb128) && !defined(NID_aes_192_ofb) +#define NID_aes_192_ofb NID_aes_192_ofb128 +#endif -# if defined(NID_aes_256_cfb128) && ! defined (NID_aes_256_cfb) -# define NID_aes_256_cfb NID_aes_256_cfb128 -# endif +#if defined(NID_aes_256_cfb128) && !defined(NID_aes_256_cfb) +#define NID_aes_256_cfb NID_aes_256_cfb128 +#endif -# if defined(NID_aes_256_ofb128) && ! defined (NID_aes_256_ofb) -# define NID_aes_256_ofb NID_aes_256_ofb128 -# endif +#if defined(NID_aes_256_ofb128) && !defined(NID_aes_256_ofb) +#define NID_aes_256_ofb NID_aes_256_ofb128 +#endif /* List of supported ciphers. */ static const int padlock_cipher_nids[] = { @@ -297,29 +295,27 @@ static const int padlock_cipher_nids[] = { NID_aes_256_ctr }; -static int padlock_cipher_nids_num = (sizeof(padlock_cipher_nids) / - sizeof(padlock_cipher_nids[0])); +static int padlock_cipher_nids_num = (sizeof(padlock_cipher_nids) / sizeof(padlock_cipher_nids[0])); /* Function prototypes ... */ static int padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc); + const unsigned char *iv, int enc); -# define NEAREST_ALIGNED(ptr) ( (unsigned char *)(ptr) + \ - ( (0x10 - ((size_t)(ptr) & 0x0F)) & 0x0F ) ) -# define ALIGNED_CIPHER_DATA(ctx) ((struct padlock_cipher_data *)\ +#define NEAREST_ALIGNED(ptr) ((unsigned char *)(ptr) + ((0x10 - ((size_t)(ptr) & 0x0F)) & 0x0F)) +#define ALIGNED_CIPHER_DATA(ctx) ((struct padlock_cipher_data *) \ NEAREST_ALIGNED(EVP_CIPHER_CTX_get_cipher_data(ctx))) static int padlock_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, - const unsigned char *in_arg, size_t nbytes) + const unsigned char *in_arg, size_t nbytes) { return padlock_ecb_encrypt(out_arg, in_arg, - ALIGNED_CIPHER_DATA(ctx), nbytes); + ALIGNED_CIPHER_DATA(ctx), nbytes); } static int padlock_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, - const unsigned char *in_arg, size_t nbytes) + const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); int ret; @@ -332,22 +328,23 @@ padlock_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, static int padlock_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, - const unsigned char *in_arg, size_t nbytes) + const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); size_t chunk; - if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */ + if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */ unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx); if (chunk >= AES_BLOCK_SIZE) - return 0; /* bogus value */ + return 0; /* bogus value */ if (EVP_CIPHER_CTX_is_encrypting(ctx)) while (chunk < AES_BLOCK_SIZE && nbytes != 0) { ivp[chunk] = *(out_arg++) = *(in_arg++) ^ ivp[chunk]; chunk++, nbytes--; - } else + } + else while (chunk < AES_BLOCK_SIZE && nbytes != 0) { unsigned char c = *(in_arg++); *(out_arg++) = c ^ ivp[chunk]; @@ -403,7 +400,7 @@ padlock_cfb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, static int padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, - const unsigned char *in_arg, size_t nbytes) + const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); size_t chunk; @@ -411,11 +408,11 @@ padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, /* * ctx->num is maintained in byte-oriented modes, such as CFB and OFB... */ - if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */ + if ((chunk = EVP_CIPHER_CTX_get_num(ctx))) { /* borrow chunk variable */ unsigned char *ivp = EVP_CIPHER_CTX_iv_noconst(ctx); if (chunk >= AES_BLOCK_SIZE) - return 0; /* bogus value */ + return 0; /* bogus value */ while (chunk < AES_BLOCK_SIZE && nbytes != 0) { *(out_arg++) = *(in_arg++) ^ ivp[chunk]; @@ -442,9 +439,9 @@ padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, out_arg += chunk; in_arg += chunk; EVP_CIPHER_CTX_set_num(ctx, nbytes); - padlock_reload_key(); /* empirically found */ + padlock_reload_key(); /* empirically found */ padlock_aes_block(ivp, ivp, cdata); - padlock_reload_key(); /* empirically found */ + padlock_reload_key(); /* empirically found */ while (nbytes) { *(out_arg++) = *(in_arg++) ^ *ivp; ivp++, nbytes--; @@ -457,9 +454,9 @@ padlock_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, } static void padlock_ctr32_encrypt_glue(const unsigned char *in, - unsigned char *out, size_t blocks, - struct padlock_cipher_data *ctx, - const unsigned char *ivec) + unsigned char *out, size_t blocks, + struct padlock_cipher_data *ctx, + const unsigned char *ivec) { memcpy(ctx->iv, ivec, AES_BLOCK_SIZE); padlock_ctr32_encrypt(out, in, ctx, AES_BLOCK_SIZE * blocks); @@ -467,7 +464,7 @@ static void padlock_ctr32_encrypt_glue(const unsigned char *in, static int padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, - const unsigned char *in_arg, size_t nbytes) + const unsigned char *in_arg, size_t nbytes) { struct padlock_cipher_data *cdata = ALIGNED_CIPHER_DATA(ctx); int n = EVP_CIPHER_CTX_get_num(ctx); @@ -478,52 +475,52 @@ padlock_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out_arg, num = (unsigned int)n; CRYPTO_ctr128_encrypt_ctr32(in_arg, out_arg, nbytes, - cdata, EVP_CIPHER_CTX_iv_noconst(ctx), - EVP_CIPHER_CTX_buf_noconst(ctx), &num, - (ctr128_f) padlock_ctr32_encrypt_glue); + cdata, EVP_CIPHER_CTX_iv_noconst(ctx), + EVP_CIPHER_CTX_buf_noconst(ctx), &num, + (ctr128_f)padlock_ctr32_encrypt_glue); EVP_CIPHER_CTX_set_num(ctx, (size_t)num); return 1; } -# define EVP_CIPHER_block_size_ECB AES_BLOCK_SIZE -# define EVP_CIPHER_block_size_CBC AES_BLOCK_SIZE -# define EVP_CIPHER_block_size_OFB 1 -# define EVP_CIPHER_block_size_CFB 1 -# define EVP_CIPHER_block_size_CTR 1 +#define EVP_CIPHER_block_size_ECB AES_BLOCK_SIZE +#define EVP_CIPHER_block_size_CBC AES_BLOCK_SIZE +#define EVP_CIPHER_block_size_OFB 1 +#define EVP_CIPHER_block_size_CFB 1 +#define EVP_CIPHER_block_size_CTR 1 /* * Declaring so many ciphers by hand would be a pain. Instead introduce a bit * of preprocessor magic :-) */ -# define DECLARE_AES_EVP(ksize,lmode,umode) \ -static EVP_CIPHER *_hidden_aes_##ksize##_##lmode = NULL; \ -static const EVP_CIPHER *padlock_aes_##ksize##_##lmode(void) \ -{ \ - if (_hidden_aes_##ksize##_##lmode == NULL \ - && ((_hidden_aes_##ksize##_##lmode = \ - EVP_CIPHER_meth_new(NID_aes_##ksize##_##lmode, \ - EVP_CIPHER_block_size_##umode, \ - AES_KEY_SIZE_##ksize)) == NULL \ - || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_##ksize##_##lmode, \ - AES_BLOCK_SIZE) \ - || !EVP_CIPHER_meth_set_flags(_hidden_aes_##ksize##_##lmode, \ - 0 | EVP_CIPH_##umode##_MODE) \ - || !EVP_CIPHER_meth_set_init(_hidden_aes_##ksize##_##lmode, \ - padlock_aes_init_key) \ - || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_##ksize##_##lmode, \ - padlock_##lmode##_cipher) \ - || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_##ksize##_##lmode, \ - sizeof(struct padlock_cipher_data) + 16) \ - || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_##ksize##_##lmode, \ - EVP_CIPHER_set_asn1_iv) \ - || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_##ksize##_##lmode, \ - EVP_CIPHER_get_asn1_iv))) { \ - EVP_CIPHER_meth_free(_hidden_aes_##ksize##_##lmode); \ - _hidden_aes_##ksize##_##lmode = NULL; \ - } \ - return _hidden_aes_##ksize##_##lmode; \ -} +#define DECLARE_AES_EVP(ksize, lmode, umode) \ + static EVP_CIPHER *_hidden_aes_##ksize##_##lmode = NULL; \ + static const EVP_CIPHER *padlock_aes_##ksize##_##lmode(void) \ + { \ + if (_hidden_aes_##ksize##_##lmode == NULL \ + && ((_hidden_aes_##ksize##_##lmode = EVP_CIPHER_meth_new(NID_aes_##ksize##_##lmode, \ + EVP_CIPHER_block_size_##umode, \ + AES_KEY_SIZE_##ksize)) \ + == NULL \ + || !EVP_CIPHER_meth_set_iv_length(_hidden_aes_##ksize##_##lmode, \ + AES_BLOCK_SIZE) \ + || !EVP_CIPHER_meth_set_flags(_hidden_aes_##ksize##_##lmode, \ + 0 | EVP_CIPH_##umode##_MODE) \ + || !EVP_CIPHER_meth_set_init(_hidden_aes_##ksize##_##lmode, \ + padlock_aes_init_key) \ + || !EVP_CIPHER_meth_set_do_cipher(_hidden_aes_##ksize##_##lmode, \ + padlock_##lmode##_cipher) \ + || !EVP_CIPHER_meth_set_impl_ctx_size(_hidden_aes_##ksize##_##lmode, \ + sizeof(struct padlock_cipher_data) + 16) \ + || !EVP_CIPHER_meth_set_set_asn1_params(_hidden_aes_##ksize##_##lmode, \ + EVP_CIPHER_set_asn1_iv) \ + || !EVP_CIPHER_meth_set_get_asn1_params(_hidden_aes_##ksize##_##lmode, \ + EVP_CIPHER_get_asn1_iv))) { \ + EVP_CIPHER_meth_free(_hidden_aes_##ksize##_##lmode); \ + _hidden_aes_##ksize##_##lmode = NULL; \ + } \ + return _hidden_aes_##ksize##_##lmode; \ + } DECLARE_AES_EVP(128, ecb, ECB) DECLARE_AES_EVP(128, cbc, CBC) @@ -545,7 +542,7 @@ DECLARE_AES_EVP(256, ctr, CTR) static int padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, - int nid) + int nid) { /* No specific cipher => return a list of supported nids ... */ if (!cipher) { @@ -615,14 +612,14 @@ padlock_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, /* Prepare the encryption key for PadLock usage */ static int padlock_aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, - const unsigned char *iv, int enc) + const unsigned char *iv, int enc) { struct padlock_cipher_data *cdata; int key_len = EVP_CIPHER_CTX_get_key_length(ctx) * 8; unsigned long mode = EVP_CIPHER_CTX_get_mode(ctx); if (key == NULL) - return 0; /* ERROR */ + return 0; /* ERROR */ cdata = ALIGNED_CIPHER_DATA(ctx); memset(cdata, 0, sizeof(*cdata)); @@ -699,28 +696,28 @@ static int padlock_rand_bytes(unsigned char *output, int count) while (count >= 8) { eax = padlock_xstore(output, 0); if (!(eax & (1 << 6))) - return 0; /* RNG disabled */ + return 0; /* RNG disabled */ /* this ---vv--- covers DC bias, Raw Bits and String Filter */ if (eax & (0x1F << 10)) return 0; if ((eax & 0x1F) == 0) - continue; /* no data, retry... */ + continue; /* no data, retry... */ if ((eax & 0x1F) != 8) - return 0; /* fatal failure... */ + return 0; /* fatal failure... */ output += 8; count -= 8; } while (count > 0) { eax = padlock_xstore(&buf, 3); if (!(eax & (1 << 6))) - return 0; /* RNG disabled */ + return 0; /* RNG disabled */ /* this ---vv--- covers DC bias, Raw Bits and String Filter */ if (eax & (0x1F << 10)) return 0; if ((eax & 0x1F) == 0) - continue; /* no data, retry... */ + continue; /* no data, retry... */ if ((eax & 0x1F) != 1) - return 0; /* fatal failure... */ + return 0; /* fatal failure... */ *output++ = (unsigned char)buf; count--; } @@ -737,27 +734,27 @@ static int padlock_rand_status(void) /* Prepare structure for registration */ static RAND_METHOD padlock_rand = { - NULL, /* seed */ - padlock_rand_bytes, /* bytes */ - NULL, /* cleanup */ - NULL, /* add */ - padlock_rand_bytes, /* pseudorand */ - padlock_rand_status, /* rand status */ + NULL, /* seed */ + padlock_rand_bytes, /* bytes */ + NULL, /* cleanup */ + NULL, /* add */ + padlock_rand_bytes, /* pseudorand */ + padlock_rand_status, /* rand status */ }; -# endif /* COMPILE_PADLOCKENG */ -#endif /* !OPENSSL_NO_PADLOCKENG */ +#endif /* COMPILE_PADLOCKENG */ +#endif /* !OPENSSL_NO_PADLOCKENG */ #if defined(OPENSSL_NO_PADLOCKENG) || !defined(COMPILE_PADLOCKENG) -# ifndef OPENSSL_NO_DYNAMIC_ENGINE +#ifndef OPENSSL_NO_DYNAMIC_ENGINE OPENSSL_EXPORT - int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); +int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns); OPENSSL_EXPORT - int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) +int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { return 0; } IMPLEMENT_DYNAMIC_CHECK_FN() -# endif +#endif #endif |
