Latest update.

This commit is contained in:
2019-09-21 00:43:47 +09:00
parent 2e57f602ae
commit 62515c7d8d
1131 changed files with 47556 additions and 24957 deletions
-116
View File
@@ -1,116 +0,0 @@
/*
* Copyright 2019 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* TODO(3.0) Move this header into provider when dependencies are removed */
#ifndef HEADER_BLAKE2_H
# define HEADER_BLAKE2_H
# include <openssl/opensslconf.h>
# include <openssl/e_os2.h>
# include <stddef.h>
# define BLAKE2S_BLOCKBYTES 64
# define BLAKE2S_OUTBYTES 32
# define BLAKE2S_KEYBYTES 32
# define BLAKE2S_SALTBYTES 8
# define BLAKE2S_PERSONALBYTES 8
# define BLAKE2B_BLOCKBYTES 128
# define BLAKE2B_OUTBYTES 64
# define BLAKE2B_KEYBYTES 64
# define BLAKE2B_SALTBYTES 16
# define BLAKE2B_PERSONALBYTES 16
struct blake2s_param_st {
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
uint8_t fanout; /* 3 */
uint8_t depth; /* 4 */
uint8_t leaf_length[4];/* 8 */
uint8_t node_offset[6];/* 14 */
uint8_t node_depth; /* 15 */
uint8_t inner_length; /* 16 */
uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
};
typedef struct blake2s_param_st BLAKE2S_PARAM;
struct blake2s_ctx_st {
uint32_t h[8];
uint32_t t[2];
uint32_t f[2];
uint8_t buf[BLAKE2S_BLOCKBYTES];
size_t buflen;
size_t outlen;
};
struct blake2b_param_st {
uint8_t digest_length; /* 1 */
uint8_t key_length; /* 2 */
uint8_t fanout; /* 3 */
uint8_t depth; /* 4 */
uint8_t leaf_length[4];/* 8 */
uint8_t node_offset[8];/* 16 */
uint8_t node_depth; /* 17 */
uint8_t inner_length; /* 18 */
uint8_t reserved[14]; /* 32 */
uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
};
typedef struct blake2b_param_st BLAKE2B_PARAM;
struct blake2b_ctx_st {
uint64_t h[8];
uint64_t t[2];
uint64_t f[2];
uint8_t buf[BLAKE2B_BLOCKBYTES];
size_t buflen;
size_t outlen;
};
#define BLAKE2B_DIGEST_LENGTH 64
#define BLAKE2S_DIGEST_LENGTH 32
typedef struct blake2s_ctx_st BLAKE2S_CTX;
typedef struct blake2b_ctx_st BLAKE2B_CTX;
int blake2s256_init(void *ctx);
int blake2b512_init(void *ctx);
int blake2b_init(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P);
int blake2b_init_key(BLAKE2B_CTX *c, const BLAKE2B_PARAM *P, const void *key);
int blake2b_update(BLAKE2B_CTX *c, const void *data, size_t datalen);
int blake2b_final(unsigned char *md, BLAKE2B_CTX *c);
/*
* These setters are internal and do not check the validity of their parameters.
* See blake2b_mac_ctrl for validation logic.
*/
void blake2b_param_init(BLAKE2B_PARAM *P);
void blake2b_param_set_digest_length(BLAKE2B_PARAM *P, uint8_t outlen);
void blake2b_param_set_key_length(BLAKE2B_PARAM *P, uint8_t keylen);
void blake2b_param_set_personal(BLAKE2B_PARAM *P, const uint8_t *personal, size_t length);
void blake2b_param_set_salt(BLAKE2B_PARAM *P, const uint8_t *salt, size_t length);
int blake2s_init(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P);
int blake2s_init_key(BLAKE2S_CTX *c, const BLAKE2S_PARAM *P, const void *key);
int blake2s_update(BLAKE2S_CTX *c, const void *data, size_t datalen);
int blake2s_final(unsigned char *md, BLAKE2S_CTX *c);
void blake2s_param_init(BLAKE2S_PARAM *P);
void blake2s_param_set_digest_length(BLAKE2S_PARAM *P, uint8_t outlen);
void blake2s_param_set_key_length(BLAKE2S_PARAM *P, uint8_t keylen);
void blake2s_param_set_personal(BLAKE2S_PARAM *P, const uint8_t *personal, size_t length);
void blake2s_param_set_salt(BLAKE2S_PARAM *P, const uint8_t *salt, size_t length);
#endif /* HEADER_BLAKE2_H */
+58 -4
View File
@@ -213,18 +213,72 @@ static ossl_inline unsigned char constant_time_eq_int_8(int a, int b)
return constant_time_eq_8((unsigned)(a), (unsigned)(b));
}
/*
* Returns the value unmodified, but avoids optimizations.
* The barriers prevent the compiler from narrowing down the
* possible value range of the mask and ~mask in the select
* statements, which avoids the recognition of the select
* and turning it into a conditional load or branch.
*/
static ossl_inline unsigned int value_barrier(unsigned int a)
{
#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
unsigned int r;
__asm__("" : "=r"(r) : "0"(a));
#else
volatile unsigned int r = a;
#endif
return r;
}
/* Convenience method for uint32_t. */
static ossl_inline uint32_t value_barrier_32(uint32_t a)
{
#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
uint32_t r;
__asm__("" : "=r"(r) : "0"(a));
#else
volatile uint32_t r = a;
#endif
return r;
}
/* Convenience method for uint64_t. */
static ossl_inline uint64_t value_barrier_64(uint64_t a)
{
#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
uint64_t r;
__asm__("" : "=r"(r) : "0"(a));
#else
volatile uint64_t r = a;
#endif
return r;
}
/* Convenience method for size_t. */
static ossl_inline size_t value_barrier_s(size_t a)
{
#if !defined(OPENSSL_NO_ASM) && defined(__GNUC__)
size_t r;
__asm__("" : "=r"(r) : "0"(a));
#else
volatile size_t r = a;
#endif
return r;
}
static ossl_inline unsigned int constant_time_select(unsigned int mask,
unsigned int a,
unsigned int b)
{
return (mask & a) | (~mask & b);
return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
}
static ossl_inline size_t constant_time_select_s(size_t mask,
size_t a,
size_t b)
{
return (mask & a) | (~mask & b);
return (value_barrier_s(mask) & a) | (value_barrier_s(~mask) & b);
}
static ossl_inline unsigned char constant_time_select_8(unsigned char mask,
@@ -249,13 +303,13 @@ static ossl_inline int constant_time_select_int_s(size_t mask, int a, int b)
static ossl_inline uint32_t constant_time_select_32(uint32_t mask, uint32_t a,
uint32_t b)
{
return (mask & a) | (~mask & b);
return (value_barrier_32(mask) & a) | (value_barrier_32(~mask) & b);
}
static ossl_inline uint64_t constant_time_select_64(uint64_t mask, uint64_t a,
uint64_t b)
{
return (mask & a) | (~mask & b);
return (value_barrier_64(mask) & a) | (value_barrier_64(~mask) & b);
}
/*
+10 -6
View File
@@ -32,13 +32,11 @@ typedef struct ossl_method_construct_method_st {
/* Remove a store */
void (*dealloc_tmp_store)(void *store);
/* Get an already existing method from a store */
void *(*get)(OPENSSL_CTX *libctx, void *store,
int operation_id, const char *name, const char *propquery,
void *data);
void *(*get)(OPENSSL_CTX *libctx, void *store, void *data);
/* Store a method in a store */
int (*put)(OPENSSL_CTX *libctx, void *store, void *method,
int operation_id, const char *name, const char *propdef,
void *data);
const OSSL_PROVIDER *prov, int operation_id, const char *name,
const char *propdef, void *data);
/* Construct a new method */
void *(*construct)(const char *name, const OSSL_DISPATCH *fns,
OSSL_PROVIDER *prov, void *data);
@@ -47,8 +45,14 @@ typedef struct ossl_method_construct_method_st {
} OSSL_METHOD_CONSTRUCT_METHOD;
void *ossl_method_construct(OPENSSL_CTX *ctx, int operation_id,
const char *name, const char *properties,
int force_cache,
OSSL_METHOD_CONSTRUCT_METHOD *mcm, void *mcm_data);
void ossl_algorithm_do_all(OPENSSL_CTX *libctx, int operation_id,
OSSL_PROVIDER *provider,
void (*fn)(OSSL_PROVIDER *provider,
const OSSL_ALGORITHM *algo,
int no_store, void *data),
void *data);
#endif
+5 -3
View File
@@ -54,11 +54,8 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
void *align_ptr
typedef struct ex_callback_st EX_CALLBACK;
DEFINE_STACK_OF(EX_CALLBACK)
typedef struct app_mem_info_st APP_INFO;
typedef struct mem_st MEM;
DEFINE_LHASH_OF(MEM);
@@ -87,11 +84,16 @@ DEFINE_LHASH_OF(MEM);
# define HEX_SIZE(type) (sizeof(type)*2)
void OPENSSL_cpuid_setup(void);
#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
defined(__x86_64) || defined(__x86_64__) || \
defined(_M_AMD64) || defined(_M_X64)
extern unsigned int OPENSSL_ia32cap_P[];
#endif
void OPENSSL_showfatal(const char *fmta, ...);
int do_ex_data_init(OPENSSL_CTX *ctx);
void crypto_cleanup_all_ex_data_int(OPENSSL_CTX *ctx);
int openssl_init_fork_handlers(void);
int openssl_get_fork_id(void);
char *ossl_safe_getenv(const char *name);
+55 -55
View File
@@ -11,11 +11,9 @@
#ifndef HEADER_DSOERR_H
# define HEADER_DSOERR_H
# ifndef HEADER_SYMHACKS_H
# include <openssl/symhacks.h>
# endif
# include <openssl/opensslconf.h>
# include <openssl/symhacks.h>
# ifdef __cplusplus
extern "C"
@@ -25,60 +23,62 @@ int ERR_load_DSO_strings(void);
/*
* DSO function codes.
*/
# define DSO_F_DLFCN_BIND_FUNC 100
# define DSO_F_DLFCN_LOAD 102
# define DSO_F_DLFCN_MERGER 130
# define DSO_F_DLFCN_NAME_CONVERTER 123
# define DSO_F_DLFCN_UNLOAD 103
# define DSO_F_DL_BIND_FUNC 104
# define DSO_F_DL_LOAD 106
# define DSO_F_DL_MERGER 131
# define DSO_F_DL_NAME_CONVERTER 124
# define DSO_F_DL_UNLOAD 107
# define DSO_F_DSO_BIND_FUNC 108
# define DSO_F_DSO_CONVERT_FILENAME 126
# define DSO_F_DSO_CTRL 110
# define DSO_F_DSO_FREE 111
# define DSO_F_DSO_GET_FILENAME 127
# define DSO_F_DSO_GLOBAL_LOOKUP 139
# define DSO_F_DSO_LOAD 112
# define DSO_F_DSO_MERGE 132
# define DSO_F_DSO_NEW_METHOD 113
# define DSO_F_DSO_PATHBYADDR 105
# define DSO_F_DSO_SET_FILENAME 129
# define DSO_F_DSO_UP_REF 114
# define DSO_F_VMS_BIND_SYM 115
# define DSO_F_VMS_LOAD 116
# define DSO_F_VMS_MERGER 133
# define DSO_F_VMS_UNLOAD 117
# define DSO_F_WIN32_BIND_FUNC 101
# define DSO_F_WIN32_GLOBALLOOKUP 142
# define DSO_F_WIN32_JOINER 135
# define DSO_F_WIN32_LOAD 120
# define DSO_F_WIN32_MERGER 134
# define DSO_F_WIN32_NAME_CONVERTER 125
# define DSO_F_WIN32_PATHBYADDR 109
# define DSO_F_WIN32_SPLITTER 136
# define DSO_F_WIN32_UNLOAD 121
# if !OPENSSL_API_3
# define DSO_F_DLFCN_BIND_FUNC 0
# define DSO_F_DLFCN_LOAD 0
# define DSO_F_DLFCN_MERGER 0
# define DSO_F_DLFCN_NAME_CONVERTER 0
# define DSO_F_DLFCN_UNLOAD 0
# define DSO_F_DL_BIND_FUNC 0
# define DSO_F_DL_LOAD 0
# define DSO_F_DL_MERGER 0
# define DSO_F_DL_NAME_CONVERTER 0
# define DSO_F_DL_UNLOAD 0
# define DSO_F_DSO_BIND_FUNC 0
# define DSO_F_DSO_CONVERT_FILENAME 0
# define DSO_F_DSO_CTRL 0
# define DSO_F_DSO_FREE 0
# define DSO_F_DSO_GET_FILENAME 0
# define DSO_F_DSO_GLOBAL_LOOKUP 0
# define DSO_F_DSO_LOAD 0
# define DSO_F_DSO_MERGE 0
# define DSO_F_DSO_NEW_METHOD 0
# define DSO_F_DSO_PATHBYADDR 0
# define DSO_F_DSO_SET_FILENAME 0
# define DSO_F_DSO_UP_REF 0
# define DSO_F_VMS_BIND_SYM 0
# define DSO_F_VMS_LOAD 0
# define DSO_F_VMS_MERGER 0
# define DSO_F_VMS_UNLOAD 0
# define DSO_F_WIN32_BIND_FUNC 0
# define DSO_F_WIN32_GLOBALLOOKUP 0
# define DSO_F_WIN32_JOINER 0
# define DSO_F_WIN32_LOAD 0
# define DSO_F_WIN32_MERGER 0
# define DSO_F_WIN32_NAME_CONVERTER 0
# define DSO_F_WIN32_PATHBYADDR 0
# define DSO_F_WIN32_SPLITTER 0
# define DSO_F_WIN32_UNLOAD 0
# endif
/*
* DSO reason codes.
*/
# define DSO_R_CTRL_FAILED 100
# define DSO_R_DSO_ALREADY_LOADED 110
# define DSO_R_EMPTY_FILE_STRUCTURE 113
# define DSO_R_FAILURE 114
# define DSO_R_FILENAME_TOO_BIG 101
# define DSO_R_FINISH_FAILED 102
# define DSO_R_INCORRECT_FILE_SYNTAX 115
# define DSO_R_LOAD_FAILED 103
# define DSO_R_NAME_TRANSLATION_FAILED 109
# define DSO_R_NO_FILENAME 111
# define DSO_R_NULL_HANDLE 104
# define DSO_R_SET_FILENAME_FAILED 112
# define DSO_R_STACK_ERROR 105
# define DSO_R_SYM_FAILURE 106
# define DSO_R_UNLOAD_FAILED 107
# define DSO_R_UNSUPPORTED 108
# define DSO_R_CTRL_FAILED 100
# define DSO_R_DSO_ALREADY_LOADED 110
# define DSO_R_EMPTY_FILE_STRUCTURE 113
# define DSO_R_FAILURE 114
# define DSO_R_FILENAME_TOO_BIG 101
# define DSO_R_FINISH_FAILED 102
# define DSO_R_INCORRECT_FILE_SYNTAX 115
# define DSO_R_LOAD_FAILED 103
# define DSO_R_NAME_TRANSLATION_FAILED 109
# define DSO_R_NO_FILENAME 111
# define DSO_R_NULL_HANDLE 104
# define DSO_R_SET_FILENAME_FAILED 112
# define DSO_R_STACK_ERROR 105
# define DSO_R_SYM_FAILURE 106
# define DSO_R_UNLOAD_FAILED 107
# define DSO_R_UNSUPPORTED 108
#endif
+2
View File
@@ -24,6 +24,8 @@ int ossl_namemap_add(OSSL_NAMEMAP *namemap, int number, const char *name);
* number->name mapping is an iterator.
*/
int ossl_namemap_name2num(const OSSL_NAMEMAP *namemap, const char *name);
const char *ossl_namemap_num2name(const OSSL_NAMEMAP *namemap, int number,
size_t idx);
void ossl_namemap_doall_names(const OSSL_NAMEMAP *namemap, int number,
void (*fn)(const char *name, void *data),
void *data);
+3 -3
View File
@@ -12,19 +12,19 @@
# include <limits.h>
# if (-1 & 3) == 0x03 /* Two's complement */
# if (-1 & 3) == 0x03 /* Two's complement */
# define __MAXUINT__(T) ((T) -1)
# define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T)))
# define __MININT__(T) (-__MAXINT__(T) - 1)
# elif (-1 & 3) == 0x02 /* One's complement */
# elif (-1 & 3) == 0x02 /* One's complement */
# define __MAXUINT__(T) (((T) -1) + 1)
# define __MAXINT__(T) ((T) ((((T) 1) << ((sizeof(T) * CHAR_BIT) - 1)) ^ __MAXUINT__(T)))
# define __MININT__(T) (-__MAXINT__(T))
# elif (-1 & 3) == 0x01 /* Sign/magnitude */
# elif (-1 & 3) == 0x01 /* Sign/magnitude */
# define __MAXINT__(T) ((T) (((((T) 1) << ((sizeof(T) * CHAR_BIT) - 2)) - 1) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 2))))
# define __MAXUINT__(T) ((T) (__MAXINT__(T) | (((T) 1) << ((sizeof(T) * CHAR_BIT) - 1))))
+884
View File
@@ -0,0 +1,884 @@
/*
* Copyright 2015-2018 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#ifndef HEADER_PACKET_LOCL_H
# define HEADER_PACKET_LOCL_H
# include <string.h>
# include <openssl/bn.h>
# include <openssl/buffer.h>
# include <openssl/crypto.h>
# include <openssl/e_os2.h>
# include "internal/numbers.h"
typedef struct {
/* Pointer to where we are currently reading from */
const unsigned char *curr;
/* Number of bytes remaining */
size_t remaining;
} PACKET;
/* Internal unchecked shorthand; don't use outside this file. */
static ossl_inline void packet_forward(PACKET *pkt, size_t len)
{
pkt->curr += len;
pkt->remaining -= len;
}
/*
* Returns the number of bytes remaining to be read in the PACKET
*/
static ossl_inline size_t PACKET_remaining(const PACKET *pkt)
{
return pkt->remaining;
}
/*
* Returns a pointer to the first byte after the packet data.
* Useful for integrating with non-PACKET parsing code.
* Specifically, we use PACKET_end() to verify that a d2i_... call
* has consumed the entire packet contents.
*/
static ossl_inline const unsigned char *PACKET_end(const PACKET *pkt)
{
return pkt->curr + pkt->remaining;
}
/*
* Returns a pointer to the PACKET's current position.
* For use in non-PACKETized APIs.
*/
static ossl_inline const unsigned char *PACKET_data(const PACKET *pkt)
{
return pkt->curr;
}
/*
* Initialise a PACKET with |len| bytes held in |buf|. This does not make a
* copy of the data so |buf| must be present for the whole time that the PACKET
* is being used.
*/
__owur static ossl_inline int PACKET_buf_init(PACKET *pkt,
const unsigned char *buf,
size_t len)
{
/* Sanity check for negative values. */
if (len > (size_t)(SIZE_MAX / 2))
return 0;
pkt->curr = buf;
pkt->remaining = len;
return 1;
}
/* Initialize a PACKET to hold zero bytes. */
static ossl_inline void PACKET_null_init(PACKET *pkt)
{
pkt->curr = NULL;
pkt->remaining = 0;
}
/*
* Returns 1 if the packet has length |num| and its contents equal the |num|
* bytes read from |ptr|. Returns 0 otherwise (lengths or contents not equal).
* If lengths are equal, performs the comparison in constant time.
*/
__owur static ossl_inline int PACKET_equal(const PACKET *pkt, const void *ptr,
size_t num)
{
if (PACKET_remaining(pkt) != num)
return 0;
return CRYPTO_memcmp(pkt->curr, ptr, num) == 0;
}
/*
* Peek ahead and initialize |subpkt| with the next |len| bytes read from |pkt|.
* Data is not copied: the |subpkt| packet will share its underlying buffer with
* the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
*/
__owur static ossl_inline int PACKET_peek_sub_packet(const PACKET *pkt,
PACKET *subpkt, size_t len)
{
if (PACKET_remaining(pkt) < len)
return 0;
return PACKET_buf_init(subpkt, pkt->curr, len);
}
/*
* Initialize |subpkt| with the next |len| bytes read from |pkt|. Data is not
* copied: the |subpkt| packet will share its underlying buffer with the
* original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
*/
__owur static ossl_inline int PACKET_get_sub_packet(PACKET *pkt,
PACKET *subpkt, size_t len)
{
if (!PACKET_peek_sub_packet(pkt, subpkt, len))
return 0;
packet_forward(pkt, len);
return 1;
}
/*
* Peek ahead at 2 bytes in network order from |pkt| and store the value in
* |*data|
*/
__owur static ossl_inline int PACKET_peek_net_2(const PACKET *pkt,
unsigned int *data)
{
if (PACKET_remaining(pkt) < 2)
return 0;
*data = ((unsigned int)(*pkt->curr)) << 8;
*data |= *(pkt->curr + 1);
return 1;
}
/* Equivalent of n2s */
/* Get 2 bytes in network order from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_net_2(PACKET *pkt, unsigned int *data)
{
if (!PACKET_peek_net_2(pkt, data))
return 0;
packet_forward(pkt, 2);
return 1;
}
/* Same as PACKET_get_net_2() but for a size_t */
__owur static ossl_inline int PACKET_get_net_2_len(PACKET *pkt, size_t *data)
{
unsigned int i;
int ret = PACKET_get_net_2(pkt, &i);
if (ret)
*data = (size_t)i;
return ret;
}
/*
* Peek ahead at 3 bytes in network order from |pkt| and store the value in
* |*data|
*/
__owur static ossl_inline int PACKET_peek_net_3(const PACKET *pkt,
unsigned long *data)
{
if (PACKET_remaining(pkt) < 3)
return 0;
*data = ((unsigned long)(*pkt->curr)) << 16;
*data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
*data |= *(pkt->curr + 2);
return 1;
}
/* Equivalent of n2l3 */
/* Get 3 bytes in network order from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_net_3(PACKET *pkt, unsigned long *data)
{
if (!PACKET_peek_net_3(pkt, data))
return 0;
packet_forward(pkt, 3);
return 1;
}
/* Same as PACKET_get_net_3() but for a size_t */
__owur static ossl_inline int PACKET_get_net_3_len(PACKET *pkt, size_t *data)
{
unsigned long i;
int ret = PACKET_get_net_3(pkt, &i);
if (ret)
*data = (size_t)i;
return ret;
}
/*
* Peek ahead at 4 bytes in network order from |pkt| and store the value in
* |*data|
*/
__owur static ossl_inline int PACKET_peek_net_4(const PACKET *pkt,
unsigned long *data)
{
if (PACKET_remaining(pkt) < 4)
return 0;
*data = ((unsigned long)(*pkt->curr)) << 24;
*data |= ((unsigned long)(*(pkt->curr + 1))) << 16;
*data |= ((unsigned long)(*(pkt->curr + 2))) << 8;
*data |= *(pkt->curr + 3);
return 1;
}
/* Equivalent of n2l */
/* Get 4 bytes in network order from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
{
if (!PACKET_peek_net_4(pkt, data))
return 0;
packet_forward(pkt, 4);
return 1;
}
/* Same as PACKET_get_net_4() but for a size_t */
__owur static ossl_inline int PACKET_get_net_4_len(PACKET *pkt, size_t *data)
{
unsigned long i;
int ret = PACKET_get_net_4(pkt, &i);
if (ret)
*data = (size_t)i;
return ret;
}
/* Peek ahead at 1 byte from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_peek_1(const PACKET *pkt,
unsigned int *data)
{
if (!PACKET_remaining(pkt))
return 0;
*data = *pkt->curr;
return 1;
}
/* Get 1 byte from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_1(PACKET *pkt, unsigned int *data)
{
if (!PACKET_peek_1(pkt, data))
return 0;
packet_forward(pkt, 1);
return 1;
}
/* Same as PACKET_get_1() but for a size_t */
__owur static ossl_inline int PACKET_get_1_len(PACKET *pkt, size_t *data)
{
unsigned int i;
int ret = PACKET_get_1(pkt, &i);
if (ret)
*data = (size_t)i;
return ret;
}
/*
* Peek ahead at 4 bytes in reverse network order from |pkt| and store the value
* in |*data|
*/
__owur static ossl_inline int PACKET_peek_4(const PACKET *pkt,
unsigned long *data)
{
if (PACKET_remaining(pkt) < 4)
return 0;
*data = *pkt->curr;
*data |= ((unsigned long)(*(pkt->curr + 1))) << 8;
*data |= ((unsigned long)(*(pkt->curr + 2))) << 16;
*data |= ((unsigned long)(*(pkt->curr + 3))) << 24;
return 1;
}
/* Equivalent of c2l */
/*
* Get 4 bytes in reverse network order from |pkt| and store the value in
* |*data|
*/
__owur static ossl_inline int PACKET_get_4(PACKET *pkt, unsigned long *data)
{
if (!PACKET_peek_4(pkt, data))
return 0;
packet_forward(pkt, 4);
return 1;
}
/*
* Peek ahead at |len| bytes from the |pkt| and store a pointer to them in
* |*data|. This just points at the underlying buffer that |pkt| is using. The
* caller should not free this data directly (it will be freed when the
* underlying buffer gets freed
*/
__owur static ossl_inline int PACKET_peek_bytes(const PACKET *pkt,
const unsigned char **data,
size_t len)
{
if (PACKET_remaining(pkt) < len)
return 0;
*data = pkt->curr;
return 1;
}
/*
* Read |len| bytes from the |pkt| and store a pointer to them in |*data|. This
* just points at the underlying buffer that |pkt| is using. The caller should
* not free this data directly (it will be freed when the underlying buffer gets
* freed
*/
__owur static ossl_inline int PACKET_get_bytes(PACKET *pkt,
const unsigned char **data,
size_t len)
{
if (!PACKET_peek_bytes(pkt, data, len))
return 0;
packet_forward(pkt, len);
return 1;
}
/* Peek ahead at |len| bytes from |pkt| and copy them to |data| */
__owur static ossl_inline int PACKET_peek_copy_bytes(const PACKET *pkt,
unsigned char *data,
size_t len)
{
if (PACKET_remaining(pkt) < len)
return 0;
memcpy(data, pkt->curr, len);
return 1;
}
/*
* Read |len| bytes from |pkt| and copy them to |data|.
* The caller is responsible for ensuring that |data| can hold |len| bytes.
*/
__owur static ossl_inline int PACKET_copy_bytes(PACKET *pkt,
unsigned char *data, size_t len)
{
if (!PACKET_peek_copy_bytes(pkt, data, len))
return 0;
packet_forward(pkt, len);
return 1;
}
/*
* Copy packet data to |dest|, and set |len| to the number of copied bytes.
* If the packet has more than |dest_len| bytes, nothing is copied.
* Returns 1 if the packet data fits in |dest_len| bytes, 0 otherwise.
* Does not forward PACKET position (because it is typically the last thing
* done with a given PACKET).
*/
__owur static ossl_inline int PACKET_copy_all(const PACKET *pkt,
unsigned char *dest,
size_t dest_len, size_t *len)
{
if (PACKET_remaining(pkt) > dest_len) {
*len = 0;
return 0;
}
*len = pkt->remaining;
memcpy(dest, pkt->curr, pkt->remaining);
return 1;
}
/*
* Copy |pkt| bytes to a newly allocated buffer and store a pointer to the
* result in |*data|, and the length in |len|.
* If |*data| is not NULL, the old data is OPENSSL_free'd.
* If the packet is empty, or malloc fails, |*data| will be set to NULL.
* Returns 1 if the malloc succeeds and 0 otherwise.
* Does not forward PACKET position (because it is typically the last thing
* done with a given PACKET).
*/
__owur static ossl_inline int PACKET_memdup(const PACKET *pkt,
unsigned char **data, size_t *len)
{
size_t length;
OPENSSL_free(*data);
*data = NULL;
*len = 0;
length = PACKET_remaining(pkt);
if (length == 0)
return 1;
*data = OPENSSL_memdup(pkt->curr, length);
if (*data == NULL)
return 0;
*len = length;
return 1;
}
/*
* Read a C string from |pkt| and copy to a newly allocated, NUL-terminated
* buffer. Store a pointer to the result in |*data|.
* If |*data| is not NULL, the old data is OPENSSL_free'd.
* If the data in |pkt| does not contain a NUL-byte, the entire data is
* copied and NUL-terminated.
* Returns 1 if the malloc succeeds and 0 otherwise.
* Does not forward PACKET position (because it is typically the last thing done
* with a given PACKET).
*/
__owur static ossl_inline int PACKET_strndup(const PACKET *pkt, char **data)
{
OPENSSL_free(*data);
/* This will succeed on an empty packet, unless pkt->curr == NULL. */
*data = OPENSSL_strndup((const char *)pkt->curr, PACKET_remaining(pkt));
return (*data != NULL);
}
/* Returns 1 if |pkt| contains at least one 0-byte, 0 otherwise. */
static ossl_inline int PACKET_contains_zero_byte(const PACKET *pkt)
{
return memchr(pkt->curr, 0, pkt->remaining) != NULL;
}
/* Move the current reading position forward |len| bytes */
__owur static ossl_inline int PACKET_forward(PACKET *pkt, size_t len)
{
if (PACKET_remaining(pkt) < len)
return 0;
packet_forward(pkt, len);
return 1;
}
/*
* Reads a variable-length vector prefixed with a one-byte length, and stores
* the contents in |subpkt|. |pkt| can equal |subpkt|.
* Data is not copied: the |subpkt| packet will share its underlying buffer with
* the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
* Upon failure, the original |pkt| and |subpkt| are not modified.
*/
__owur static ossl_inline int PACKET_get_length_prefixed_1(PACKET *pkt,
PACKET *subpkt)
{
unsigned int length;
const unsigned char *data;
PACKET tmp = *pkt;
if (!PACKET_get_1(&tmp, &length) ||
!PACKET_get_bytes(&tmp, &data, (size_t)length)) {
return 0;
}
*pkt = tmp;
subpkt->curr = data;
subpkt->remaining = length;
return 1;
}
/*
* Like PACKET_get_length_prefixed_1, but additionally, fails when there are
* leftover bytes in |pkt|.
*/
__owur static ossl_inline int PACKET_as_length_prefixed_1(PACKET *pkt,
PACKET *subpkt)
{
unsigned int length;
const unsigned char *data;
PACKET tmp = *pkt;
if (!PACKET_get_1(&tmp, &length) ||
!PACKET_get_bytes(&tmp, &data, (size_t)length) ||
PACKET_remaining(&tmp) != 0) {
return 0;
}
*pkt = tmp;
subpkt->curr = data;
subpkt->remaining = length;
return 1;
}
/*
* Reads a variable-length vector prefixed with a two-byte length, and stores
* the contents in |subpkt|. |pkt| can equal |subpkt|.
* Data is not copied: the |subpkt| packet will share its underlying buffer with
* the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
* Upon failure, the original |pkt| and |subpkt| are not modified.
*/
__owur static ossl_inline int PACKET_get_length_prefixed_2(PACKET *pkt,
PACKET *subpkt)
{
unsigned int length;
const unsigned char *data;
PACKET tmp = *pkt;
if (!PACKET_get_net_2(&tmp, &length) ||
!PACKET_get_bytes(&tmp, &data, (size_t)length)) {
return 0;
}
*pkt = tmp;
subpkt->curr = data;
subpkt->remaining = length;
return 1;
}
/*
* Like PACKET_get_length_prefixed_2, but additionally, fails when there are
* leftover bytes in |pkt|.
*/
__owur static ossl_inline int PACKET_as_length_prefixed_2(PACKET *pkt,
PACKET *subpkt)
{
unsigned int length;
const unsigned char *data;
PACKET tmp = *pkt;
if (!PACKET_get_net_2(&tmp, &length) ||
!PACKET_get_bytes(&tmp, &data, (size_t)length) ||
PACKET_remaining(&tmp) != 0) {
return 0;
}
*pkt = tmp;
subpkt->curr = data;
subpkt->remaining = length;
return 1;
}
/*
* Reads a variable-length vector prefixed with a three-byte length, and stores
* the contents in |subpkt|. |pkt| can equal |subpkt|.
* Data is not copied: the |subpkt| packet will share its underlying buffer with
* the original |pkt|, so data wrapped by |pkt| must outlive the |subpkt|.
* Upon failure, the original |pkt| and |subpkt| are not modified.
*/
__owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
PACKET *subpkt)
{
unsigned long length;
const unsigned char *data;
PACKET tmp = *pkt;
if (!PACKET_get_net_3(&tmp, &length) ||
!PACKET_get_bytes(&tmp, &data, (size_t)length)) {
return 0;
}
*pkt = tmp;
subpkt->curr = data;
subpkt->remaining = length;
return 1;
}
/* Writeable packets */
typedef struct wpacket_sub WPACKET_SUB;
struct wpacket_sub {
/* The parent WPACKET_SUB if we have one or NULL otherwise */
WPACKET_SUB *parent;
/*
* Offset into the buffer where the length of this WPACKET goes. We use an
* offset in case the buffer grows and gets reallocated.
*/
size_t packet_len;
/* Number of bytes in the packet_len or 0 if we don't write the length */
size_t lenbytes;
/* Number of bytes written to the buf prior to this packet starting */
size_t pwritten;
/* Flags for this sub-packet */
unsigned int flags;
};
typedef struct wpacket_st WPACKET;
struct wpacket_st {
/* The buffer where we store the output data */
BUF_MEM *buf;
/* Fixed sized buffer which can be used as an alternative to buf */
unsigned char *staticbuf;
/*
* Offset into the buffer where we are currently writing. We use an offset
* in case the buffer grows and gets reallocated.
*/
size_t curr;
/* Number of bytes written so far */
size_t written;
/* Maximum number of bytes we will allow to be written to this WPACKET */
size_t maxsize;
/* Our sub-packets (always at least one if not finished) */
WPACKET_SUB *subs;
};
/* Flags */
/* Default */
#define WPACKET_FLAGS_NONE 0
/* Error on WPACKET_close() if no data written to the WPACKET */
#define WPACKET_FLAGS_NON_ZERO_LENGTH 1
/*
* Abandon all changes on WPACKET_close() if no data written to the WPACKET,
* i.e. this does not write out a zero packet length
*/
#define WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH 2
/*
* Initialise a WPACKET with the buffer in |buf|. The buffer must exist
* for the whole time that the WPACKET is being used. Additionally |lenbytes| of
* data is preallocated at the start of the buffer to store the length of the
* WPACKET once we know it.
*/
int WPACKET_init_len(WPACKET *pkt, BUF_MEM *buf, size_t lenbytes);
/*
* Same as WPACKET_init_len except there is no preallocation of the WPACKET
* length.
*/
int WPACKET_init(WPACKET *pkt, BUF_MEM *buf);
/*
* Same as WPACKET_init_len except there is no underlying buffer. No data is
* ever actually written. We just keep track of how much data would have been
* written if a buffer was there.
*/
int WPACKET_init_null(WPACKET *pkt, size_t lenbytes);
/*
* Same as WPACKET_init_len except we do not use a growable BUF_MEM structure.
* A fixed buffer of memory |buf| of size |len| is used instead. A failure will
* occur if you attempt to write beyond the end of the buffer
*/
int WPACKET_init_static_len(WPACKET *pkt, unsigned char *buf, size_t len,
size_t lenbytes);
/*
* Set the flags to be applied to the current sub-packet
*/
int WPACKET_set_flags(WPACKET *pkt, unsigned int flags);
/*
* Closes the most recent sub-packet. It also writes out the length of the
* packet to the required location (normally the start of the WPACKET) if
* appropriate. The top level WPACKET should be closed using WPACKET_finish()
* instead of this function.
*/
int WPACKET_close(WPACKET *pkt);
/*
* The same as WPACKET_close() but only for the top most WPACKET. Additionally
* frees memory resources for this WPACKET.
*/
int WPACKET_finish(WPACKET *pkt);
/*
* Iterate through all the sub-packets and write out their lengths as if they
* were being closed. The lengths will be overwritten with the final lengths
* when the sub-packets are eventually closed (which may be different if more
* data is added to the WPACKET). This function fails if a sub-packet is of 0
* length and WPACKET_FLAGS_ABANDON_ON_ZERO_LENGTH is set.
*/
int WPACKET_fill_lengths(WPACKET *pkt);
/*
* Initialise a new sub-packet. Additionally |lenbytes| of data is preallocated
* at the start of the sub-packet to store its length once we know it. Don't
* call this directly. Use the convenience macros below instead.
*/
int WPACKET_start_sub_packet_len__(WPACKET *pkt, size_t lenbytes);
/*
* Convenience macros for calling WPACKET_start_sub_packet_len with different
* lengths
*/
#define WPACKET_start_sub_packet_u8(pkt) \
WPACKET_start_sub_packet_len__((pkt), 1)
#define WPACKET_start_sub_packet_u16(pkt) \
WPACKET_start_sub_packet_len__((pkt), 2)
#define WPACKET_start_sub_packet_u24(pkt) \
WPACKET_start_sub_packet_len__((pkt), 3)
#define WPACKET_start_sub_packet_u32(pkt) \
WPACKET_start_sub_packet_len__((pkt), 4)
/*
* Same as WPACKET_start_sub_packet_len__() except no bytes are pre-allocated
* for the sub-packet length.
*/
int WPACKET_start_sub_packet(WPACKET *pkt);
/*
* Allocate bytes in the WPACKET for the output. This reserves the bytes
* and counts them as "written", but doesn't actually do the writing. A pointer
* to the allocated bytes is stored in |*allocbytes|. |allocbytes| may be NULL.
* WARNING: the allocated bytes must be filled in immediately, without further
* WPACKET_* calls. If not then the underlying buffer may be realloc'd and
* change its location.
*/
int WPACKET_allocate_bytes(WPACKET *pkt, size_t len,
unsigned char **allocbytes);
/*
* The same as WPACKET_allocate_bytes() except additionally a new sub-packet is
* started for the allocated bytes, and then closed immediately afterwards. The
* number of length bytes for the sub-packet is in |lenbytes|. Don't call this
* directly. Use the convenience macros below instead.
*/
int WPACKET_sub_allocate_bytes__(WPACKET *pkt, size_t len,
unsigned char **allocbytes, size_t lenbytes);
/*
* Convenience macros for calling WPACKET_sub_allocate_bytes with different
* lengths
*/
#define WPACKET_sub_allocate_bytes_u8(pkt, len, bytes) \
WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 1)
#define WPACKET_sub_allocate_bytes_u16(pkt, len, bytes) \
WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 2)
#define WPACKET_sub_allocate_bytes_u24(pkt, len, bytes) \
WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 3)
#define WPACKET_sub_allocate_bytes_u32(pkt, len, bytes) \
WPACKET_sub_allocate_bytes__((pkt), (len), (bytes), 4)
/*
* The same as WPACKET_allocate_bytes() except the reserved bytes are not
* actually counted as written. Typically this will be for when we don't know
* how big arbitrary data is going to be up front, but we do know what the
* maximum size will be. If this function is used, then it should be immediately
* followed by a WPACKET_allocate_bytes() call before any other WPACKET
* functions are called (unless the write to the allocated bytes is abandoned).
*
* For example: If we are generating a signature, then the size of that
* signature may not be known in advance. We can use WPACKET_reserve_bytes() to
* handle this:
*
* if (!WPACKET_sub_reserve_bytes_u16(&pkt, EVP_PKEY_size(pkey), &sigbytes1)
* || EVP_SignFinal(md_ctx, sigbytes1, &siglen, pkey) <= 0
* || !WPACKET_sub_allocate_bytes_u16(&pkt, siglen, &sigbytes2)
* || sigbytes1 != sigbytes2)
* goto err;
*/
int WPACKET_reserve_bytes(WPACKET *pkt, size_t len, unsigned char **allocbytes);
/*
* The "reserve_bytes" equivalent of WPACKET_sub_allocate_bytes__()
*/
int WPACKET_sub_reserve_bytes__(WPACKET *pkt, size_t len,
unsigned char **allocbytes, size_t lenbytes);
/*
* Convenience macros for WPACKET_sub_reserve_bytes with different lengths
*/
#define WPACKET_sub_reserve_bytes_u8(pkt, len, bytes) \
WPACKET_reserve_bytes__((pkt), (len), (bytes), 1)
#define WPACKET_sub_reserve_bytes_u16(pkt, len, bytes) \
WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 2)
#define WPACKET_sub_reserve_bytes_u24(pkt, len, bytes) \
WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 3)
#define WPACKET_sub_reserve_bytes_u32(pkt, len, bytes) \
WPACKET_sub_reserve_bytes__((pkt), (len), (bytes), 4)
/*
* Write the value stored in |val| into the WPACKET. The value will consume
* |bytes| amount of storage. An error will occur if |val| cannot be
* accommodated in |bytes| storage, e.g. attempting to write the value 256 into
* 1 byte will fail. Don't call this directly. Use the convenience macros below
* instead.
*/
int WPACKET_put_bytes__(WPACKET *pkt, unsigned int val, size_t bytes);
/*
* Convenience macros for calling WPACKET_put_bytes with different
* lengths
*/
#define WPACKET_put_bytes_u8(pkt, val) \
WPACKET_put_bytes__((pkt), (val), 1)
#define WPACKET_put_bytes_u16(pkt, val) \
WPACKET_put_bytes__((pkt), (val), 2)
#define WPACKET_put_bytes_u24(pkt, val) \
WPACKET_put_bytes__((pkt), (val), 3)
#define WPACKET_put_bytes_u32(pkt, val) \
WPACKET_put_bytes__((pkt), (val), 4)
/* Set a maximum size that we will not allow the WPACKET to grow beyond */
int WPACKET_set_max_size(WPACKET *pkt, size_t maxsize);
/* Copy |len| bytes of data from |*src| into the WPACKET. */
int WPACKET_memcpy(WPACKET *pkt, const void *src, size_t len);
/* Set |len| bytes of data to |ch| into the WPACKET. */
int WPACKET_memset(WPACKET *pkt, int ch, size_t len);
/*
* Copy |len| bytes of data from |*src| into the WPACKET and prefix with its
* length (consuming |lenbytes| of data for the length). Don't call this
* directly. Use the convenience macros below instead.
*/
int WPACKET_sub_memcpy__(WPACKET *pkt, const void *src, size_t len,
size_t lenbytes);
/* Convenience macros for calling WPACKET_sub_memcpy with different lengths */
#define WPACKET_sub_memcpy_u8(pkt, src, len) \
WPACKET_sub_memcpy__((pkt), (src), (len), 1)
#define WPACKET_sub_memcpy_u16(pkt, src, len) \
WPACKET_sub_memcpy__((pkt), (src), (len), 2)
#define WPACKET_sub_memcpy_u24(pkt, src, len) \
WPACKET_sub_memcpy__((pkt), (src), (len), 3)
#define WPACKET_sub_memcpy_u32(pkt, src, len) \
WPACKET_sub_memcpy__((pkt), (src), (len), 4)
/*
* Return the total number of bytes written so far to the underlying buffer
* including any storage allocated for length bytes
*/
int WPACKET_get_total_written(WPACKET *pkt, size_t *written);
/*
* Returns the length of the current sub-packet. This excludes any bytes
* allocated for the length itself.
*/
int WPACKET_get_length(WPACKET *pkt, size_t *len);
/*
* Returns a pointer to the current write location, but does not allocate any
* bytes.
*/
unsigned char *WPACKET_get_curr(WPACKET *pkt);
/* Returns true if the underlying buffer is actually NULL */
int WPACKET_is_null_buf(WPACKET *pkt);
/* Release resources in a WPACKET if a failure has occurred. */
void WPACKET_cleanup(WPACKET *pkt);
#endif /* HEADER_PACKET_LOCL_H */
+78
View File
@@ -0,0 +1,78 @@
/*
* Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright (c) 2019, Oracle and/or its affiliates. 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
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/params.h>
#include <openssl/ossl_typ.h>
#define OSSL_PARAM_BLD_MAX 10
typedef struct {
const char *key;
int type;
int secure;
size_t size;
size_t alloc_blocks;
const BIGNUM *bn;
const void *string;
union {
/*
* These fields are never directly addressed, but their sizes are
* imporant so that all native types can be copied here without overrun.
*/
ossl_intmax_t i;
ossl_uintmax_t u;
double d;
} num;
} OSSL_PARAM_BLD_DEF;
typedef struct {
size_t curr;
size_t total_blocks;
size_t secure_blocks;
OSSL_PARAM_BLD_DEF params[OSSL_PARAM_BLD_MAX];
} OSSL_PARAM_BLD;
void ossl_param_bld_init(OSSL_PARAM_BLD *bld);
OSSL_PARAM *ossl_param_bld_to_param(OSSL_PARAM_BLD *bld);
void ossl_param_bld_free(OSSL_PARAM *params);
OSSL_PARAM *ossl_param_bld_to_param_ex(OSSL_PARAM_BLD *bld,
OSSL_PARAM *params, size_t param_n,
void *data, size_t data_n,
void *secure, size_t secure_n);
int ossl_param_bld_push_int(OSSL_PARAM_BLD *bld, const char *key, int val);
int ossl_param_bld_push_uint(OSSL_PARAM_BLD *bld, const char *key,
unsigned int val);
int ossl_param_bld_push_long(OSSL_PARAM_BLD *bld, const char *key,
long int val);
int ossl_param_bld_push_ulong(OSSL_PARAM_BLD *bld, const char *key,
unsigned long int val);
int ossl_param_bld_push_int32(OSSL_PARAM_BLD *bld, const char *key,
int32_t val);
int ossl_param_bld_push_uint32(OSSL_PARAM_BLD *bld, const char *key,
uint32_t val);
int ossl_param_bld_push_int64(OSSL_PARAM_BLD *bld, const char *key,
int64_t val);
int ossl_param_bld_push_uint64(OSSL_PARAM_BLD *bld, const char *key,
uint64_t val);
int ossl_param_bld_push_size_t(OSSL_PARAM_BLD *bld, const char *key,
size_t val);
int ossl_param_bld_push_double(OSSL_PARAM_BLD *bld, const char *key,
double val);
int ossl_param_bld_push_BN(OSSL_PARAM_BLD *bld, const char *key,
const BIGNUM *bn);
int ossl_param_bld_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
const char *buf, size_t bsize);
int ossl_param_bld_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
char *buf, size_t bsize);
int ossl_param_bld_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
const void *buf, size_t bsize);
int ossl_param_bld_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
void *buf, size_t bsize);
+9 -5
View File
@@ -15,14 +15,18 @@
typedef struct ossl_method_store_st OSSL_METHOD_STORE;
/* Initialisation */
int ossl_property_parse_init(OPENSSL_CTX *ctx);
/* Implementation store functions */
OSSL_METHOD_STORE *ossl_method_store_new(OPENSSL_CTX *ctx);
void ossl_method_store_free(OSSL_METHOD_STORE *store);
int ossl_method_store_add(OSSL_METHOD_STORE *store, int nid,
const char *properties, void *implementation,
void (*implementation_destruct)(void *));
int ossl_method_store_remove(OSSL_METHOD_STORE *store,
int nid, const void *implementation);
int ossl_method_store_add(OSSL_METHOD_STORE *store, const OSSL_PROVIDER *prov,
int nid, const char *properties, void *method,
int (*method_up_ref)(void *),
void (*method_destruct)(void *));
int ossl_method_store_remove(OSSL_METHOD_STORE *store, int nid,
const void *method);
int ossl_method_store_fetch(OSSL_METHOD_STORE *store, int nid,
const char *prop_query, void **result);
int ossl_method_store_set_global_properties(OSSL_METHOD_STORE *store,
+13 -11
View File
@@ -11,9 +11,9 @@
#ifndef HEADER_PROPERR_H
# define HEADER_PROPERR_H
# ifndef HEADER_SYMHACKS_H
# include <openssl/symhacks.h>
# endif
# include <openssl/opensslconf.h>
# include <openssl/symhacks.h>
# ifdef __cplusplus
extern "C"
@@ -23,14 +23,16 @@ int ERR_load_PROP_strings(void);
/*
* PROP function codes.
*/
# define PROP_F_OSSL_PARSE_PROPERTY 100
# define PROP_F_OSSL_PARSE_QUERY 101
# define PROP_F_PARSE_HEX 102
# define PROP_F_PARSE_NAME 103
# define PROP_F_PARSE_NUMBER 104
# define PROP_F_PARSE_OCT 105
# define PROP_F_PARSE_STRING 106
# define PROP_F_PARSE_UNQUOTED 107
# if !OPENSSL_API_3
# define PROP_F_OSSL_PARSE_PROPERTY 0
# define PROP_F_OSSL_PARSE_QUERY 0
# define PROP_F_PARSE_HEX 0
# define PROP_F_PARSE_NAME 0
# define PROP_F_PARSE_NUMBER 0
# define PROP_F_PARSE_OCT 0
# define PROP_F_PARSE_STRING 0
# define PROP_F_PARSE_UNQUOTED 0
# endif
/*
* PROP reason codes.
+8 -3
View File
@@ -26,9 +26,11 @@ extern "C" {
*/
/* Provider Object finder, constructor and destructor */
OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name);
OSSL_PROVIDER *ossl_provider_find(OPENSSL_CTX *libctx, const char *name,
int noconfig);
OSSL_PROVIDER *ossl_provider_new(OPENSSL_CTX *libctx, const char *name,
OSSL_provider_init_fn *init_function);
OSSL_provider_init_fn *init_function,
int noconfig);
int ossl_provider_up_ref(OSSL_PROVIDER *prov);
void ossl_provider_free(OSSL_PROVIDER *prov);
@@ -44,6 +46,8 @@ int ossl_provider_add_parameter(OSSL_PROVIDER *prov, const char *name,
* Inactivation is done by freeing the Provider
*/
int ossl_provider_activate(OSSL_PROVIDER *prov);
/* Check if the provider is available */
int ossl_provider_available(OSSL_PROVIDER *prov);
/* Return pointer to the provider's context */
void *ossl_provider_ctx(const OSSL_PROVIDER *prov);
@@ -59,10 +63,11 @@ const char *ossl_provider_name(const OSSL_PROVIDER *prov);
const DSO *ossl_provider_dso(const OSSL_PROVIDER *prov);
const char *ossl_provider_module_name(const OSSL_PROVIDER *prov);
const char *ossl_provider_module_path(const OSSL_PROVIDER *prov);
OPENSSL_CTX *ossl_provider_library_context(const OSSL_PROVIDER *prov);
/* Thin wrappers around calls to the provider */
void ossl_provider_teardown(const OSSL_PROVIDER *prov);
const OSSL_ITEM *ossl_provider_get_param_types(const OSSL_PROVIDER *prov);
const OSSL_PARAM *ossl_provider_gettable_params(const OSSL_PROVIDER *prov);
int ossl_provider_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[]);
const OSSL_ALGORITHM *ossl_provider_query_operation(const OSSL_PROVIDER *prov,
int operation_id,
+15
View File
@@ -73,6 +73,21 @@ static __inline__ int CRYPTO_DOWN_REF(int *val, int *ret, void *lock)
__atomic_thread_fence(__ATOMIC_ACQUIRE);
return 1;
}
# elif defined(__ICL) && defined(_WIN32)
# define HAVE_ATOMICS 1
typedef volatile int CRYPTO_REF_COUNT;
static __inline int CRYPTO_UP_REF(volatile int *val, int *ret, void *lock)
{
*ret = _InterlockedExchangeAdd((void *)val, 1) + 1;
return 1;
}
static __inline int CRYPTO_DOWN_REF(volatile int *val, int *ret, void *lock)
{
*ret = _InterlockedExchangeAdd((void *)val, -1) - 1;
return 1;
}
# elif defined(_MSC_VER) && _MSC_VER>=1200
+6 -3
View File
@@ -14,9 +14,12 @@
# if defined(OPENSSL_SYS_VMS)
/* ossl_provider_get_param_types vs OSSL_PROVIDER_get_param_types */
# undef ossl_provider_get_param_types
# define ossl_provider_get_param_types ossl_int_prov_get_param_types
/* ossl_provider_available vs OSSL_PROVIDER_available */
# undef ossl_provider_available
# define ossl_provider_available ossl_int_prov_available
/* ossl_provider_gettable_params vs OSSL_PROVIDER_gettable_params */
# undef ossl_provider_gettable_params
# define ossl_provider_gettable_params ossl_int_prov_gettable_params
/* ossl_provider_get_params vs OSSL_PROVIDER_get_params */
# undef ossl_provider_get_params
# define ossl_provider_get_params ossl_int_prov_get_params