Commit 7e5363ab authored by Rich Salz's avatar Rich Salz Committed by Rich Salz
Browse files

Rewrite crypto/ex_data

Removed ability to set ex_data impl at runtime.  This removed these
three functions:
    const CRYPTO_EX_DATA_IMPL *CRYPTO_get_ex_data_implementation(void);
    int CRYPTO_set_ex_data_implementation(const CRYPTO_EX_DATA_IMPL *i);
    int CRYPTO_ex_data_new_class(void);
It is no longer possible to change the ex_data implementation at
runtime.  (Luckily those functions were never documented :)

Also removed the ability to add new exdata "classes."  We don't believe
this received much (if any) use, since you can't add it to OpenSSL objects,
and there are probably better (native) methods for developers to add
their own extensible data, if they really need that.

Replaced the internal hash table (of per-"class" stacks) with a simple
indexed array.  Reserved an index for "app" application.

Each API used to take the lock twice; now it only locks once.

Use local stack storage for function pointers, rather than malloc,
if possible (i.e., number of ex_data items is under a dozen).

Make CRYPTO_EX_DATA_FUNCS opaque/internal.

Also fixes RT3710; index zero is reserved.

Reviewed-by: default avatarRichard Levitte <levitte@openssl.org>
parent f7d53487
Loading
Loading
Loading
Loading
+4 −1
Changes for crypto/cpt_err.c: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
/* crypto/cpt_err.c */
/* ====================================================================
 * Copyright (c) 1999-2011 The OpenSSL Project.  All rights reserved.
 * Copyright (c) 1999-2015 The OpenSSL Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
@@ -70,9 +70,12 @@
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_CRYPTO,0,reason)

static ERR_STRING_DATA CRYPTO_str_functs[] = {
    {ERR_FUNC(CRYPTO_F_CRYPTO_DUP_EX_DATA), "CRYPTO_dup_ex_data"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_FREE_EX_DATA), "CRYPTO_free_ex_data"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX), "CRYPTO_get_ex_new_index"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID), "CRYPTO_get_new_dynlockid"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_GET_NEW_LOCKID), "CRYPTO_get_new_lockid"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_NEW_EX_DATA), "CRYPTO_new_ex_data"},
    {ERR_FUNC(CRYPTO_F_CRYPTO_SET_EX_DATA), "CRYPTO_set_ex_data"},
    {ERR_FUNC(CRYPTO_F_DEF_ADD_INDEX), "DEF_ADD_INDEX"},
    {ERR_FUNC(CRYPTO_F_DEF_GET_CLASS), "DEF_GET_CLASS"},
+0 −1
Changes for crypto/engine/eng_dyn.c: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -512,7 +512,6 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
     * would also increase opaqueness.
     */
    fns.static_state = ENGINE_get_static_state();
    fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
    CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
                             &fns.mem_fns.realloc_cb, &fns.mem_fns.free_cb);
    fns.lock_fns.lock_locking_cb = CRYPTO_get_locking_callback();
+140 −375

File changed.

Preview size limit exceeded, changes collapsed.

+10 −35

File changed.

Preview size limit exceeded, changes collapsed.

+0 −3
Changes for include/openssl/engine.h: 0 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -776,7 +776,6 @@ typedef struct st_dynamic_LOCK_fns {
/* The top-level structure */
typedef struct st_dynamic_fns {
    void *static_state;
    const CRYPTO_EX_DATA_IMPL *ex_data_fns;
    dynamic_MEM_fns mem_fns;
    dynamic_LOCK_fns lock_fns;
} dynamic_fns;
@@ -834,8 +833,6 @@ typedef int (*dynamic_bind_engine) (ENGINE *e, const char *id,
                CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
                CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
                CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
                if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
                        return 0; \
        skip_cbs: \
                if(!fn(e,id)) return 0; \
                return 1; }
Loading