Bläddra i källkod

Convert stack.h to use inline functions.

Instead of a script which generates macros, emit static inlines in
individual header (or C files). This solves a few issues with the
original setup:

- The documentation was off. We match the documentation now.

- The stack macros did not check constness; see some of the fixes in
  crypto/x509.

- Type errors did not look like usual type errors.

- Any type which participated in STACK_OF had to be made partially
  public. This allows stack types to be defined an internal header or
  even an individual file.

- One could not pass sk_FOO_free into something which expects a function
  pointer.

Thanks to upstream's 411abf2dd3 for the
idea.

Change-Id: Ie5431390ccad761c17596b0e93941b0d7a68f904
Reviewed-on: https://boringssl-review.googlesource.com/16087
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin 7 år sedan
committed by Adam Langley
förälder
incheckning
01f8a8c2d5
22 ändrade filer med 220 tillägg och 4130 borttagningar
  1. +3
    -0
      crypto/asn1/a_strnid.c
  2. +2
    -0
      crypto/ex_data.c
  3. +3
    -0
      crypto/internal.h
  4. +0
    -114
      crypto/stack/make_macros.sh
  5. +2
    -2
      crypto/x509/by_dir.c
  6. +1
    -1
      crypto/x509/x_name.c
  7. +2
    -2
      crypto/x509v3/pcy_int.h
  8. +1
    -1
      crypto/x509v3/pcy_node.c
  9. +1
    -1
      crypto/x509v3/pcy_tree.c
  10. +3
    -1
      include/openssl/asn1.h
  11. +4
    -2
      include/openssl/asn1t.h
  12. +6
    -0
      include/openssl/base.h
  13. +2
    -0
      include/openssl/bio.h
  14. +2
    -0
      include/openssl/conf.h
  15. +4
    -0
      include/openssl/pool.h
  16. +5
    -3
      include/openssl/ssl.h
  17. +142
    -84
      include/openssl/stack.h
  18. +0
    -3892
      include/openssl/stack_macros.h
  19. +15
    -9
      include/openssl/x509.h
  20. +3
    -3
      include/openssl/x509_vfy.h
  21. +17
    -15
      include/openssl/x509v3.h
  22. +2
    -0
      ssl/internal.h

+ 3
- 0
crypto/asn1/a_strnid.c Visa fil

@@ -62,6 +62,9 @@
#include <openssl/err.h>
#include <openssl/mem.h>
#include <openssl/obj.h>
#include <openssl/stack.h>

DEFINE_STACK_OF(ASN1_STRING_TABLE)

static STACK_OF(ASN1_STRING_TABLE) *stable = NULL;
static void st_free(ASN1_STRING_TABLE *tbl);


+ 2
- 0
crypto/ex_data.c Visa fil

@@ -121,6 +121,8 @@
#include "internal.h"


DEFINE_STACK_OF(CRYPTO_EX_DATA_FUNCS)

struct crypto_ex_data_func_st {
long argl; /* Arbitary long */
void *argp; /* Arbitary void pointer */


+ 3
- 0
crypto/internal.h Visa fil

@@ -110,6 +110,7 @@
#define OPENSSL_HEADER_CRYPTO_INTERNAL_H

#include <openssl/ex_data.h>
#include <openssl/stack.h>
#include <openssl/thread.h>

#include <string.h>
@@ -504,6 +505,8 @@ OPENSSL_EXPORT int CRYPTO_set_thread_local(

typedef struct crypto_ex_data_func_st CRYPTO_EX_DATA_FUNCS;

DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)

/* CRYPTO_EX_DATA_CLASS tracks the ex_indices registered for a type which
* supports ex_data. It should defined as a static global within the module
* which defines that type. */


+ 0
- 114
crypto/stack/make_macros.sh Visa fil

@@ -1,114 +0,0 @@
#!/bin/sh

include_dir=../../include/openssl

cat > "${include_dir}/stack_macros.h" << EOF
/* Copyright (c) 2014, Google Inc.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */

#if !defined(IN_STACK_H)
#error "Don't include this file directly. Include stack.h."
#endif

EOF

output_stack () {
type=$1
ptrtype=$2

cat >> "${include_dir}/stack_macros.h" << EOF
/* ${type} */
#define sk_${type}_new(comp)\\
((STACK_OF(${type})*) sk_new(CHECKED_CAST(stack_cmp_func, int (*) (const ${ptrtype} *a, const ${ptrtype} *b), comp)))

#define sk_${type}_new_null()\\
((STACK_OF(${type})*) sk_new_null())

#define sk_${type}_num(sk)\\
sk_num(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk))

#define sk_${type}_zero(sk)\\
sk_zero(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk));

#define sk_${type}_value(sk, i)\\
((${ptrtype}) sk_value(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk), (i)))

#define sk_${type}_set(sk, i, p)\\
((${ptrtype}) sk_set(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (i), CHECKED_CAST(void*, ${ptrtype}, p)))

#define sk_${type}_free(sk)\\
sk_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))

#define sk_${type}_pop_free(sk, free_func)\\
sk_pop_free(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func))

#define sk_${type}_insert(sk, p, where)\\
sk_insert(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p), (where))

#define sk_${type}_delete(sk, where)\\
((${ptrtype}) sk_delete(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (where)))

#define sk_${type}_delete_ptr(sk, p)\\
((${ptrtype}) sk_delete_ptr(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p)))

#define sk_${type}_find(sk, out_index, p)\\
sk_find(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), (out_index), CHECKED_CAST(void*, ${ptrtype}, p))

#define sk_${type}_shift(sk)\\
((${ptrtype}) sk_shift(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)))

#define sk_${type}_push(sk, p)\\
sk_push(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(void*, ${ptrtype}, p))

#define sk_${type}_pop(sk)\\
((${ptrtype}) sk_pop(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk)))

#define sk_${type}_dup(sk)\\
((STACK_OF(${type})*) sk_dup(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk)))

#define sk_${type}_sort(sk)\\
sk_sort(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk))

#define sk_${type}_is_sorted(sk)\\
sk_is_sorted(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk))

#define sk_${type}_set_cmp_func(sk, comp)\\
((int (*) (const ${type} **a, const ${type} **b)) sk_set_cmp_func(CHECKED_CAST(_STACK*, STACK_OF(${type})*, sk), CHECKED_CAST(stack_cmp_func, int (*) (const ${type} **a, const ${type} **b), comp)))

#define sk_${type}_deep_copy(sk, copy_func, free_func)\\
((STACK_OF(${type})*) sk_deep_copy(CHECKED_CAST(const _STACK*, const STACK_OF(${type})*, sk), CHECKED_CAST(void* (*) (void*), ${ptrtype} (*) (${ptrtype}), copy_func), CHECKED_CAST(void (*) (void*), void (*) (${ptrtype}), free_func)))

EOF
}

stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* STACK_OF:' | sed -e 's/.*STACK_OF://' -e 's/ .*//')
const_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* CONST_STACK_OF:' | sed -e 's/.*CONST_STACK_OF://' -e 's/ .*//')
special_stack_types=$(cat "${include_dir}/stack.h" | grep '^ \* SPECIAL_STACK_OF:' | sed -e 's/.*SPECIAL_STACK_OF://' -e 's/ .*//')

for type in $stack_types; do
echo Stack of ${type}
output_stack "${type}" "${type} *"
done

for type in $const_stack_types; do
echo Stack of ${type}
output_stack "${type}" "const ${type} *"
done

for type in $special_stack_types; do
echo Stack of ${type}
output_stack "${type}" "${type}"
done

clang-format -i "${include_dir}/stack_macros.h"

+ 2
- 2
crypto/x509/by_dir.c Visa fil

@@ -84,8 +84,8 @@ typedef struct lookup_dir_st {
STACK_OF(BY_DIR_ENTRY) *dirs;
} BY_DIR;

DECLARE_STACK_OF(BY_DIR_HASH)
DECLARE_STACK_OF(BY_DIR_ENTRY)
DEFINE_STACK_OF(BY_DIR_HASH)
DEFINE_STACK_OF(BY_DIR_ENTRY)

static int dir_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl,
char **ret);


+ 1
- 1
crypto/x509/x_name.c Visa fil

@@ -71,7 +71,7 @@


typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY;
DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY)
DEFINE_STACK_OF(STACK_OF_X509_NAME_ENTRY)

/*
* Maximum length of X509_NAME: much larger than anything we should


+ 2
- 2
crypto/x509v3/pcy_int.h Visa fil

@@ -59,7 +59,7 @@

typedef struct X509_POLICY_DATA_st X509_POLICY_DATA;

DECLARE_STACK_OF(X509_POLICY_DATA)
DEFINE_STACK_OF(X509_POLICY_DATA)

/* Internal structures */

@@ -207,7 +207,7 @@ X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk,
const ASN1_OBJECT *id);

X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
const X509_POLICY_DATA *data,
X509_POLICY_DATA *data,
X509_POLICY_NODE *parent,
X509_POLICY_TREE *tree);
void policy_node_free(X509_POLICY_NODE *node);


+ 1
- 1
crypto/x509v3/pcy_node.c Visa fil

@@ -107,7 +107,7 @@ X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level,
}

X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
const X509_POLICY_DATA *data,
X509_POLICY_DATA *data,
X509_POLICY_NODE *parent,
X509_POLICY_TREE *tree)
{


+ 1
- 1
crypto/x509v3/pcy_tree.c Visa fil

@@ -306,7 +306,7 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
}

static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
const X509_POLICY_DATA *data)
X509_POLICY_DATA *data)
{
X509_POLICY_LEVEL *last = curr - 1;
X509_POLICY_NODE *node;


+ 3
- 1
include/openssl/asn1.h Visa fil

@@ -205,7 +205,7 @@ struct asn1_object_st
int flags; /* Should we free this one */
};

DECLARE_STACK_OF(ASN1_OBJECT)
DEFINE_STACK_OF(ASN1_OBJECT)

#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
/* This indicates that the ASN1_STRING is not a real value but just a place
@@ -480,6 +480,7 @@ typedef const ASN1_ITEM ASN1_ITEM_EXP;
ASN1_STRFLGS_DUMP_UNKNOWN | \
ASN1_STRFLGS_DUMP_DER)

DEFINE_STACK_OF(ASN1_INTEGER)
DECLARE_ASN1_SET_OF(ASN1_INTEGER)

struct asn1_type_st
@@ -512,6 +513,7 @@ struct asn1_type_st
} value;
};

DEFINE_STACK_OF(ASN1_TYPE)
DECLARE_ASN1_SET_OF(ASN1_TYPE)

typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;


+ 4
- 2
include/openssl/asn1t.h Visa fil

@@ -407,10 +407,12 @@ ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE;
typedef struct ASN1_ADB_st ASN1_ADB;

typedef struct asn1_must_be_null_st ASN1_MUST_BE_NULL;

struct ASN1_ADB_st {
unsigned long flags; /* Various flags */
unsigned long offset; /* Offset of selector field */
STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */
ASN1_MUST_BE_NULL *unused;
const ASN1_ADB_TABLE *tbl; /* Table of possible types */
long tblcount; /* Number of entries in tbl */
const ASN1_TEMPLATE *default_tt; /* Type to use if no match */
@@ -850,7 +852,7 @@ DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
DECLARE_ASN1_ITEM(ASN1_SEQUENCE)

DECLARE_STACK_OF(ASN1_VALUE)
DEFINE_STACK_OF(ASN1_VALUE)

/* Functions used internally by the ASN1 code */



+ 6
- 0
include/openssl/base.h Visa fil

@@ -197,6 +197,12 @@ extern "C" {
#define OPENSSL_MSVC_PRAGMA(arg)
#endif

#if defined(__GNUC__)
#define OPENSSL_UNUSED __attribute__((unused))
#else
#define OPENSSL_UNUSED
#endif

#if defined(BORINGSSL_UNSAFE_FUZZER_MODE) && \
!defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
#define BORINGSSL_UNSAFE_DETERMINISTIC_MODE


+ 2
- 0
include/openssl/bio.h Visa fil

@@ -77,6 +77,8 @@ extern "C" {

/* Allocation and freeing. */

DEFINE_STACK_OF(BIO)

/* BIO_new creates a new BIO with the given type and a reference count of one.
* It returns the fresh |BIO|, or NULL on error. */
OPENSSL_EXPORT BIO *BIO_new(const BIO_METHOD *type);


+ 2
- 0
include/openssl/conf.h Visa fil

@@ -89,6 +89,8 @@ struct conf_st {
LHASH_OF(CONF_VALUE) *data;
};

DEFINE_STACK_OF(CONF_VALUE)


/* NCONF_new returns a fresh, empty |CONF|, or NULL on error. The |method|
* argument must be NULL. */


+ 4
- 0
include/openssl/pool.h Visa fil

@@ -17,6 +17,8 @@

#include <openssl/base.h>

#include <openssl/stack.h>

#if defined(__cplusplus)
extern "C" {
#endif
@@ -29,6 +31,8 @@ extern "C" {
* given blob to be kept in memory and referenced from multiple places. */


DEFINE_STACK_OF(CRYPTO_BUFFER)

/* CRYPTO_BUFFER_POOL_new returns a freshly allocated |CRYPTO_BUFFER_POOL| or
* NULL on error. */
OPENSSL_EXPORT CRYPTO_BUFFER_POOL* CRYPTO_BUFFER_POOL_new(void);


+ 5
- 3
include/openssl/ssl.h Visa fil

@@ -1170,7 +1170,7 @@ OPENSSL_EXPORT void SSL_CTX_set_private_key_method(
*
* |SSL_CIPHER| objects represent cipher suites. */

DECLARE_STACK_OF(SSL_CIPHER)
DEFINE_CONST_STACK_OF(SSL_CIPHER)

/* SSL_get_cipher_by_value returns the structure representing a TLS cipher
* suite based on its assigned number, or NULL if unknown. See
@@ -2713,7 +2713,7 @@ struct srtp_protection_profile_st {
unsigned long id;
} /* SRTP_PROTECTION_PROFILE */;

DECLARE_STACK_OF(SRTP_PROTECTION_PROFILE)
DEFINE_CONST_STACK_OF(SRTP_PROTECTION_PROFILE)

/* SRTP_* define constants for SRTP profiles. */
#define SRTP_AES128_CM_SHA1_80 0x0001
@@ -3601,7 +3601,7 @@ struct ssl_comp_st {
char *method;
};

DECLARE_STACK_OF(SSL_COMP)
DEFINE_STACK_OF(SSL_COMP)

/* The following flags do nothing and are included only to make it easier to
* compile code with BoringSSL. */
@@ -4025,6 +4025,8 @@ struct ssl_cipher_preference_list_st {
uint8_t *in_group_flags;
};

DECLARE_STACK_OF(SSL_CUSTOM_EXTENSION)

/* ssl_ctx_st (aka |SSL_CTX|) contains configuration common to several SSL
* connections. */
struct ssl_ctx_st {


+ 142
- 84
include/openssl/stack.h Visa fil

@@ -74,16 +74,16 @@ extern "C" {
* (once) with |DEFINE_STACK_OF(type)| and declared where needed with
* |DECLARE_STACK_OF(type)|. For example:
*
* struct foo {
* typedef struct foo_st {
* int bar;
* };
* } FOO;
*
* DEFINE_STACK_OF(struct foo);
* DEFINE_STACK_OF(FOO);
*
* Although note that the stack will contain /pointers/ to |foo|.
* Although note that the stack will contain /pointers/ to |FOO|.
*
* A macro will be defined for each of the sk_* functions below. For
* STACK_OF(foo), the macros would be sk_foo_new, sk_foo_pop etc. */
* STACK_OF(FOO), the macros would be sk_FOO_new, sk_FOO_pop etc. */


/* stack_cmp_func is a comparison function that returns a value < 0, 0 or > 0
@@ -113,85 +113,6 @@ typedef struct stack_st {

#define DECLARE_STACK_OF(type) STACK_OF(type);

/* The make_macros.sh script in this directory parses the following lines and
* generates the stack_macros.h file that contains macros for the following
* types of stacks:
*
* STACK_OF:ACCESS_DESCRIPTION
* STACK_OF:ASN1_ADB_TABLE
* STACK_OF:ASN1_GENERALSTRING
* STACK_OF:ASN1_INTEGER
* STACK_OF:ASN1_OBJECT
* STACK_OF:ASN1_STRING_TABLE
* STACK_OF:ASN1_TYPE
* STACK_OF:ASN1_VALUE
* STACK_OF:BIO
* STACK_OF:BY_DIR_ENTRY
* STACK_OF:BY_DIR_HASH
* STACK_OF:CONF_VALUE
* STACK_OF:CRYPTO_BUFFER
* STACK_OF:CRYPTO_EX_DATA_FUNCS
* STACK_OF:DIST_POINT
* STACK_OF:GENERAL_NAME
* STACK_OF:GENERAL_NAMES
* STACK_OF:GENERAL_SUBTREE
* STACK_OF:POLICYINFO
* STACK_OF:POLICYQUALINFO
* STACK_OF:POLICY_MAPPING
* STACK_OF:SSL_COMP
* STACK_OF:SSL_CUSTOM_EXTENSION
* STACK_OF:STACK_OF_X509_NAME_ENTRY
* STACK_OF:SXNETID
* STACK_OF:X509
* STACK_OF:X509V3_EXT_METHOD
* STACK_OF:X509_ALGOR
* STACK_OF:X509_ATTRIBUTE
* STACK_OF:X509_CRL
* STACK_OF:X509_EXTENSION
* STACK_OF:X509_INFO
* STACK_OF:X509_LOOKUP
* STACK_OF:X509_NAME
* STACK_OF:X509_NAME_ENTRY
* STACK_OF:X509_OBJECT
* STACK_OF:X509_POLICY_DATA
* STACK_OF:X509_POLICY_NODE
* STACK_OF:X509_PURPOSE
* STACK_OF:X509_REVOKED
* STACK_OF:X509_TRUST
* STACK_OF:X509_VERIFY_PARAM
* STACK_OF:void
*
* Some stacks contain only const structures, so the stack should return const
* pointers to retain type-checking.
*
* CONST_STACK_OF:SRTP_PROTECTION_PROFILE
* CONST_STACK_OF:SSL_CIPHER */


/* Some stacks are special because, although we would like STACK_OF(char *),
* that would actually be a stack of pointers to char*, but we just want to
* point to the string directly. In this case we call them "special" and use
* |DEFINE_SPECIAL_STACK_OF(type)| */
#define DEFINE_SPECIAL_STACK_OF(type, inner) \
STACK_OF(type) { _STACK special_stack; }; \
OPENSSL_COMPILE_ASSERT(sizeof(type) == sizeof(void *), \
special_stack_of_non_pointer_##type);

typedef char *OPENSSL_STRING;

DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING, char)

/* The make_macros.sh script in this directory parses the following lines and
* generates the stack_macros.h file that contains macros for the following
* types of stacks:
*
* SPECIAL_STACK_OF:OPENSSL_STRING */

#define IN_STACK_H
#include <openssl/stack_macros.h>
#undef IN_STACK_H


/* These are the raw stack functions, you shouldn't be using them. Rather you
* should be using the type stack macros implemented above. */

@@ -286,6 +207,143 @@ OPENSSL_EXPORT _STACK *sk_deep_copy(const _STACK *sk,
void (*free_func)(void *));


/* Defining stack types.
*
* This set of macros is used to emit the typed functions that act on a
* |STACK_OF(T)|. */

/* Stack functions must be tagged unused to support file-local stack types.
* Clang's -Wunused-function only allows unused static inline functions if they
* are defined in a header. */

#define DEFINE_STACK_OF_IMPL(name, ptrtype, constptrtype) \
DECLARE_STACK_OF(name); \
\
typedef int (*stack_##name##_cmp_func)(constptrtype *a, constptrtype *b); \
\
static inline OPENSSL_UNUSED STACK_OF(name) * \
sk_##name##_new(stack_##name##_cmp_func comp) { \
return (STACK_OF(name) *)sk_new((stack_cmp_func)comp); \
} \
\
static inline OPENSSL_UNUSED STACK_OF(name) *sk_##name##_new_null(void) { \
return (STACK_OF(name) *)sk_new_null(); \
} \
\
static inline OPENSSL_UNUSED size_t sk_##name##_num( \
const STACK_OF(name) *sk) { \
return sk_num((const _STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED void sk_##name##_zero(STACK_OF(name) *sk) { \
sk_zero((_STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_value( \
const STACK_OF(name) *sk, size_t i) { \
return (ptrtype)sk_value((const _STACK *)sk, i); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_set(STACK_OF(name) *sk, \
size_t i, ptrtype p) { \
return (ptrtype)sk_set((_STACK *)sk, i, (void *)p); \
} \
\
static inline OPENSSL_UNUSED void sk_##name##_free(STACK_OF(name) *sk) { \
sk_free((_STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED void sk_##name##_pop_free( \
STACK_OF(name) *sk, void (*free_func)(ptrtype p)) { \
sk_pop_free((_STACK *)sk, (void (*)(void *))free_func); \
} \
\
static inline OPENSSL_UNUSED size_t sk_##name##_insert( \
STACK_OF(name) *sk, ptrtype p, size_t where) { \
return sk_insert((_STACK *)sk, (void *)p, where); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_delete(STACK_OF(name) *sk, \
size_t where) { \
return (ptrtype)sk_delete((_STACK *)sk, where); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_delete_ptr( \
STACK_OF(name) *sk, ptrtype p) { \
return (ptrtype)sk_delete_ptr((_STACK *)sk, (void *)p); \
} \
\
static inline OPENSSL_UNUSED int sk_##name##_find( \
STACK_OF(name) *sk, size_t *out_index, ptrtype p) { \
return sk_find((_STACK *)sk, out_index, (void *)p); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_shift(STACK_OF(name) *sk) { \
return (ptrtype)sk_shift((_STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED size_t sk_##name##_push(STACK_OF(name) *sk, \
ptrtype p) { \
return sk_push((_STACK *)sk, (void *)p); \
} \
\
static inline OPENSSL_UNUSED ptrtype sk_##name##_pop(STACK_OF(name) *sk) { \
return (ptrtype)sk_pop((_STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED STACK_OF(name) * \
sk_##name##_dup(const STACK_OF(name) *sk) { \
return (STACK_OF(name) *)sk_dup((const _STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED void sk_##name##_sort(STACK_OF(name) *sk) { \
sk_sort((_STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED int sk_##name##_is_sorted( \
const STACK_OF(name) *sk) { \
return sk_is_sorted((const _STACK *)sk); \
} \
\
static inline OPENSSL_UNUSED stack_##name##_cmp_func \
sk_##name##_set_cmp_func(STACK_OF(name) *sk, \
stack_##name##_cmp_func comp) { \
return (stack_##name##_cmp_func)sk_set_cmp_func((_STACK *)sk, \
(stack_cmp_func)comp); \
} \
\
static inline OPENSSL_UNUSED STACK_OF(name) * \
sk_##name##_deep_copy(const STACK_OF(name) *sk, \
ptrtype(*copy_func)(ptrtype), \
void (*free_func)(ptrtype)) { \
return (STACK_OF(name) *)sk_deep_copy((_STACK *)sk, \
(void *(*)(void *))copy_func, \
(void (*)(void *))free_func); \
}

/* DEFINE_STACK_OF defines |STACK_OF(type)| to be a stack whose elements are
* |type| *. */
#define DEFINE_STACK_OF(type) DEFINE_STACK_OF_IMPL(type, type *, const type *)

/* DEFINE_CONST_STACK_OF defines |STACK_OF(type)| to be a stack whose elements
* are const |type| *. */
#define DEFINE_CONST_STACK_OF(type) \
DEFINE_STACK_OF_IMPL(type, const type *, const type *)

/* DEFINE_SPECIAL_STACK_OF defines |STACK_OF(type)| to be a stack whose elements
* are |type|, where |type| must be a typedef for a pointer. */
#define DEFINE_SPECIAL_STACK_OF(type) \
OPENSSL_COMPILE_ASSERT(sizeof(type) == sizeof(void *), \
special_stack_of_non_pointer_##type); \
DEFINE_STACK_OF_IMPL(type, type, const type)


typedef char *OPENSSL_STRING;

DEFINE_STACK_OF(void)
DEFINE_SPECIAL_STACK_OF(OPENSSL_STRING)


#if defined(__cplusplus)
} /* extern C */
#endif


+ 0
- 3892
include/openssl/stack_macros.h
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 15
- 9
include/openssl/x509.h Visa fil

@@ -111,6 +111,7 @@ struct X509_objects_st
int (*i2a)(void);
} /* X509_OBJECTS */;

DEFINE_STACK_OF(X509_ALGOR)
DECLARE_ASN1_SET_OF(X509_ALGOR)

typedef STACK_OF(X509_ALGOR) X509_ALGORS;
@@ -142,7 +143,7 @@ struct X509_name_entry_st
int size; /* temp variable */
} /* X509_NAME_ENTRY */;

DECLARE_STACK_OF(X509_NAME_ENTRY)
DEFINE_STACK_OF(X509_NAME_ENTRY)
DECLARE_ASN1_SET_OF(X509_NAME_ENTRY)

/* we always keep X509_NAMEs in 2 forms. */
@@ -160,7 +161,7 @@ struct X509_name_st
int canon_enclen;
} /* X509_NAME */;

DECLARE_STACK_OF(X509_NAME)
DEFINE_STACK_OF(X509_NAME)

#define X509_EX_V_NETSCAPE_HACK 0x8000
#define X509_EX_V_INIT 0x0001
@@ -173,7 +174,7 @@ struct X509_extension_st

typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;

DECLARE_STACK_OF(X509_EXTENSION)
DEFINE_STACK_OF(X509_EXTENSION)
DECLARE_ASN1_SET_OF(X509_EXTENSION)

/* a sequence of these are used */
@@ -188,7 +189,7 @@ struct x509_attributes_st
} value;
} /* X509_ATTRIBUTE */;

DECLARE_STACK_OF(X509_ATTRIBUTE)
DEFINE_STACK_OF(X509_ATTRIBUTE)
DECLARE_ASN1_SET_OF(X509_ATTRIBUTE)


@@ -240,6 +241,9 @@ struct x509_cert_aux_st
STACK_OF(X509_ALGOR) *other; /* other unspecified info */
} /* X509_CERT_AUX */;

DECLARE_STACK_OF(DIST_POINT)
DECLARE_STACK_OF(GENERAL_NAME)

struct x509_st
{
X509_CINF *cert_info;
@@ -267,7 +271,7 @@ struct x509_st
CRYPTO_MUTEX lock;
} /* X509 */;

DECLARE_STACK_OF(X509)
DEFINE_STACK_OF(X509)
DECLARE_ASN1_SET_OF(X509)

/* This is used for a table of trust checking functions */
@@ -281,7 +285,7 @@ struct x509_trust_st {
void *arg2;
} /* X509_TRUST */;

DECLARE_STACK_OF(X509_TRUST)
DEFINE_STACK_OF(X509_TRUST)

struct x509_cert_pair_st {
X509 *forward;
@@ -403,7 +407,7 @@ struct x509_revoked_st
int sequence; /* load sequence */
};

DECLARE_STACK_OF(X509_REVOKED)
DEFINE_STACK_OF(X509_REVOKED)
DECLARE_ASN1_SET_OF(X509_REVOKED)

struct X509_crl_info_st
@@ -418,6 +422,8 @@ struct X509_crl_info_st
ASN1_ENCODING enc;
} /* X509_CRL_INFO */;

DECLARE_STACK_OF(GENERAL_NAMES)

struct X509_crl_st
{
/* actual signature */
@@ -441,7 +447,7 @@ struct X509_crl_st
void *meth_data;
} /* X509_CRL */;

DECLARE_STACK_OF(X509_CRL)
DEFINE_STACK_OF(X509_CRL)
DECLARE_ASN1_SET_OF(X509_CRL)

struct private_key_st
@@ -476,7 +482,7 @@ struct X509_info_st

} /* X509_INFO */;

DECLARE_STACK_OF(X509_INFO)
DEFINE_STACK_OF(X509_INFO)
#endif

/* The next 2 structures and their 8 routines were sent to me by


+ 3
- 3
include/openssl/x509_vfy.h Visa fil

@@ -129,8 +129,8 @@ typedef struct x509_object_st
} data;
} X509_OBJECT;

DECLARE_STACK_OF(X509_LOOKUP)
DECLARE_STACK_OF(X509_OBJECT)
DEFINE_STACK_OF(X509_LOOKUP)
DEFINE_STACK_OF(X509_OBJECT)

/* This is a static that defines the function interface */
typedef struct x509_lookup_method_st
@@ -173,7 +173,7 @@ struct X509_VERIFY_PARAM_st
X509_VERIFY_PARAM_ID *id; /* opaque ID data */
};

DECLARE_STACK_OF(X509_VERIFY_PARAM)
DEFINE_STACK_OF(X509_VERIFY_PARAM)

/* This is used to hold everything. It is used for all certificate
* validation. Once we have a certificate chain, the 'verify'


+ 17
- 15
include/openssl/x509v3.h Visa fil

@@ -137,7 +137,7 @@ void *db;

typedef struct v3_ext_method X509V3_EXT_METHOD;

DECLARE_STACK_OF(X509V3_EXT_METHOD)
DEFINE_STACK_OF(X509V3_EXT_METHOD)

/* ext_flags values */
#define X509V3_EXT_DYNAMIC 0x1
@@ -201,23 +201,25 @@ union {
} d;
} GENERAL_NAME;

DEFINE_STACK_OF(GENERAL_NAME)
DECLARE_ASN1_SET_OF(GENERAL_NAME)

typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES;

DEFINE_STACK_OF(GENERAL_NAMES)

typedef struct ACCESS_DESCRIPTION_st {
ASN1_OBJECT *method;
GENERAL_NAME *location;
} ACCESS_DESCRIPTION;

DEFINE_STACK_OF(ACCESS_DESCRIPTION)
DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)

typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;

typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE;

DECLARE_STACK_OF(GENERAL_NAME)
DECLARE_ASN1_SET_OF(GENERAL_NAME)

DECLARE_STACK_OF(ACCESS_DESCRIPTION)
DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION)

typedef struct DIST_POINT_NAME_st {
int type;
union {
@@ -251,7 +253,7 @@ int dp_reasons;

typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS;

DECLARE_STACK_OF(DIST_POINT)
DEFINE_STACK_OF(DIST_POINT)
DECLARE_ASN1_SET_OF(DIST_POINT)

struct AUTHORITY_KEYID_st {
@@ -267,7 +269,7 @@ typedef struct SXNET_ID_st {
ASN1_OCTET_STRING *user;
} SXNETID;

DECLARE_STACK_OF(SXNETID)
DEFINE_STACK_OF(SXNETID)
DECLARE_ASN1_SET_OF(SXNETID)

typedef struct SXNET_st {
@@ -294,7 +296,7 @@ typedef struct POLICYQUALINFO_st {
} d;
} POLICYQUALINFO;

DECLARE_STACK_OF(POLICYQUALINFO)
DEFINE_STACK_OF(POLICYQUALINFO)
DECLARE_ASN1_SET_OF(POLICYQUALINFO)

typedef struct POLICYINFO_st {
@@ -304,7 +306,7 @@ typedef struct POLICYINFO_st {

typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES;

DECLARE_STACK_OF(POLICYINFO)
DEFINE_STACK_OF(POLICYINFO)
DECLARE_ASN1_SET_OF(POLICYINFO)

typedef struct POLICY_MAPPING_st {
@@ -312,7 +314,7 @@ typedef struct POLICY_MAPPING_st {
ASN1_OBJECT *subjectDomainPolicy;
} POLICY_MAPPING;

DECLARE_STACK_OF(POLICY_MAPPING)
DEFINE_STACK_OF(POLICY_MAPPING)

typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS;

@@ -322,7 +324,7 @@ typedef struct GENERAL_SUBTREE_st {
ASN1_INTEGER *maximum;
} GENERAL_SUBTREE;

DECLARE_STACK_OF(GENERAL_SUBTREE)
DEFINE_STACK_OF(GENERAL_SUBTREE)

struct NAME_CONSTRAINTS_st {
STACK_OF(GENERAL_SUBTREE) *permittedSubtrees;
@@ -501,7 +503,7 @@ typedef struct x509_purpose_st {
#define X509V3_ADD_DELETE 5L
#define X509V3_ADD_SILENT 0x10

DECLARE_STACK_OF(X509_PURPOSE)
DEFINE_STACK_OF(X509_PURPOSE)

DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS)

@@ -721,7 +723,7 @@ OPENSSL_EXPORT int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*
unsigned long chtype);

OPENSSL_EXPORT void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent);
DECLARE_STACK_OF(X509_POLICY_NODE)
DEFINE_STACK_OF(X509_POLICY_NODE)

/* BEGIN ERROR CODES */
/* The following lines are auto generated by the script mkerr.pl. Any changes


+ 2
- 0
ssl/internal.h Visa fil

@@ -591,6 +591,8 @@ struct ssl_custom_extension {

void SSL_CUSTOM_EXTENSION_free(SSL_CUSTOM_EXTENSION *custom_extension);

DEFINE_STACK_OF(SSL_CUSTOM_EXTENSION)

int custom_ext_add_clienthello(SSL_HANDSHAKE *hs, CBB *extensions);
int custom_ext_parse_serverhello(SSL_HANDSHAKE *hs, int *out_alert,
uint16_t value, const CBS *extension);


Laddar…
Avbryt
Spara