1*b077aed3SPierre Pronchery /*
2*b077aed3SPierre Pronchery  * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b077aed3SPierre Pronchery  * Copyright (c) 2019, Oracle and/or its affiliates.  All rights reserved.
4*b077aed3SPierre Pronchery  *
5*b077aed3SPierre Pronchery  * Licensed under the Apache License 2.0 (the "License").  You may not use
6*b077aed3SPierre Pronchery  * this file except in compliance with the License.  You can obtain a copy
7*b077aed3SPierre Pronchery  * in the file LICENSE in the source distribution or at
8*b077aed3SPierre Pronchery  * https://www.openssl.org/source/license.html
9*b077aed3SPierre Pronchery  */
10*b077aed3SPierre Pronchery 
11*b077aed3SPierre Pronchery #ifndef OPENSSL_PARAMS_H
12*b077aed3SPierre Pronchery # define OPENSSL_PARAMS_H
13*b077aed3SPierre Pronchery # pragma once
14*b077aed3SPierre Pronchery 
15*b077aed3SPierre Pronchery # include <openssl/core.h>
16*b077aed3SPierre Pronchery # include <openssl/bn.h>
17*b077aed3SPierre Pronchery 
18*b077aed3SPierre Pronchery # ifdef  __cplusplus
19*b077aed3SPierre Pronchery extern "C" {
20*b077aed3SPierre Pronchery # endif
21*b077aed3SPierre Pronchery 
22*b077aed3SPierre Pronchery # define OSSL_PARAM_UNMODIFIED ((size_t)-1)
23*b077aed3SPierre Pronchery 
24*b077aed3SPierre Pronchery # define OSSL_PARAM_END \
25*b077aed3SPierre Pronchery     { NULL, 0, NULL, 0, 0 }
26*b077aed3SPierre Pronchery 
27*b077aed3SPierre Pronchery # define OSSL_PARAM_DEFN(key, type, addr, sz)    \
28*b077aed3SPierre Pronchery     { (key), (type), (addr), (sz), OSSL_PARAM_UNMODIFIED }
29*b077aed3SPierre Pronchery 
30*b077aed3SPierre Pronchery /* Basic parameter types without return sizes */
31*b077aed3SPierre Pronchery # define OSSL_PARAM_int(key, addr) \
32*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int))
33*b077aed3SPierre Pronchery # define OSSL_PARAM_uint(key, addr) \
34*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
35*b077aed3SPierre Pronchery                     sizeof(unsigned int))
36*b077aed3SPierre Pronchery # define OSSL_PARAM_long(key, addr) \
37*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(long int))
38*b077aed3SPierre Pronchery # define OSSL_PARAM_ulong(key, addr) \
39*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
40*b077aed3SPierre Pronchery                     sizeof(unsigned long int))
41*b077aed3SPierre Pronchery # define OSSL_PARAM_int32(key, addr) \
42*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int32_t))
43*b077aed3SPierre Pronchery # define OSSL_PARAM_uint32(key, addr) \
44*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
45*b077aed3SPierre Pronchery                     sizeof(uint32_t))
46*b077aed3SPierre Pronchery # define OSSL_PARAM_int64(key, addr) \
47*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(int64_t))
48*b077aed3SPierre Pronchery # define OSSL_PARAM_uint64(key, addr) \
49*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), \
50*b077aed3SPierre Pronchery                     sizeof(uint64_t))
51*b077aed3SPierre Pronchery # define OSSL_PARAM_size_t(key, addr) \
52*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (addr), sizeof(size_t))
53*b077aed3SPierre Pronchery # define OSSL_PARAM_time_t(key, addr) \
54*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_INTEGER, (addr), sizeof(time_t))
55*b077aed3SPierre Pronchery # define OSSL_PARAM_double(key, addr) \
56*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_REAL, (addr), sizeof(double))
57*b077aed3SPierre Pronchery 
58*b077aed3SPierre Pronchery # define OSSL_PARAM_BN(key, bn, sz) \
59*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UNSIGNED_INTEGER, (bn), (sz))
60*b077aed3SPierre Pronchery # define OSSL_PARAM_utf8_string(key, addr, sz) \
61*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UTF8_STRING, (addr), sz)
62*b077aed3SPierre Pronchery # define OSSL_PARAM_octet_string(key, addr, sz) \
63*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_OCTET_STRING, (addr), sz)
64*b077aed3SPierre Pronchery 
65*b077aed3SPierre Pronchery # define OSSL_PARAM_utf8_ptr(key, addr, sz) \
66*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_UTF8_PTR, (addr), sz)
67*b077aed3SPierre Pronchery # define OSSL_PARAM_octet_ptr(key, addr, sz) \
68*b077aed3SPierre Pronchery     OSSL_PARAM_DEFN((key), OSSL_PARAM_OCTET_PTR, (addr), sz)
69*b077aed3SPierre Pronchery 
70*b077aed3SPierre Pronchery /* Search an OSSL_PARAM array for a matching name */
71*b077aed3SPierre Pronchery OSSL_PARAM *OSSL_PARAM_locate(OSSL_PARAM *p, const char *key);
72*b077aed3SPierre Pronchery const OSSL_PARAM *OSSL_PARAM_locate_const(const OSSL_PARAM *p, const char *key);
73*b077aed3SPierre Pronchery 
74*b077aed3SPierre Pronchery /* Basic parameter type run-time construction */
75*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_int(const char *key, int *buf);
76*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_uint(const char *key, unsigned int *buf);
77*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_long(const char *key, long int *buf);
78*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_ulong(const char *key, unsigned long int *buf);
79*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_int32(const char *key, int32_t *buf);
80*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_uint32(const char *key, uint32_t *buf);
81*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_int64(const char *key, int64_t *buf);
82*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_uint64(const char *key, uint64_t *buf);
83*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_size_t(const char *key, size_t *buf);
84*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_time_t(const char *key, time_t *buf);
85*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_BN(const char *key, unsigned char *buf,
86*b077aed3SPierre Pronchery                                    size_t bsize);
87*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_double(const char *key, double *buf);
88*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_utf8_string(const char *key, char *buf,
89*b077aed3SPierre Pronchery                                             size_t bsize);
90*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_utf8_ptr(const char *key, char **buf,
91*b077aed3SPierre Pronchery                                          size_t bsize);
92*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_octet_string(const char *key, void *buf,
93*b077aed3SPierre Pronchery                                              size_t bsize);
94*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_octet_ptr(const char *key, void **buf,
95*b077aed3SPierre Pronchery                                           size_t bsize);
96*b077aed3SPierre Pronchery OSSL_PARAM OSSL_PARAM_construct_end(void);
97*b077aed3SPierre Pronchery 
98*b077aed3SPierre Pronchery int OSSL_PARAM_allocate_from_text(OSSL_PARAM *to,
99*b077aed3SPierre Pronchery                                   const OSSL_PARAM *paramdefs,
100*b077aed3SPierre Pronchery                                   const char *key, const char *value,
101*b077aed3SPierre Pronchery                                   size_t value_n, int *found);
102*b077aed3SPierre Pronchery 
103*b077aed3SPierre Pronchery int OSSL_PARAM_get_int(const OSSL_PARAM *p, int *val);
104*b077aed3SPierre Pronchery int OSSL_PARAM_get_uint(const OSSL_PARAM *p, unsigned int *val);
105*b077aed3SPierre Pronchery int OSSL_PARAM_get_long(const OSSL_PARAM *p, long int *val);
106*b077aed3SPierre Pronchery int OSSL_PARAM_get_ulong(const OSSL_PARAM *p, unsigned long int *val);
107*b077aed3SPierre Pronchery int OSSL_PARAM_get_int32(const OSSL_PARAM *p, int32_t *val);
108*b077aed3SPierre Pronchery int OSSL_PARAM_get_uint32(const OSSL_PARAM *p, uint32_t *val);
109*b077aed3SPierre Pronchery int OSSL_PARAM_get_int64(const OSSL_PARAM *p, int64_t *val);
110*b077aed3SPierre Pronchery int OSSL_PARAM_get_uint64(const OSSL_PARAM *p, uint64_t *val);
111*b077aed3SPierre Pronchery int OSSL_PARAM_get_size_t(const OSSL_PARAM *p, size_t *val);
112*b077aed3SPierre Pronchery int OSSL_PARAM_get_time_t(const OSSL_PARAM *p, time_t *val);
113*b077aed3SPierre Pronchery 
114*b077aed3SPierre Pronchery int OSSL_PARAM_set_int(OSSL_PARAM *p, int val);
115*b077aed3SPierre Pronchery int OSSL_PARAM_set_uint(OSSL_PARAM *p, unsigned int val);
116*b077aed3SPierre Pronchery int OSSL_PARAM_set_long(OSSL_PARAM *p, long int val);
117*b077aed3SPierre Pronchery int OSSL_PARAM_set_ulong(OSSL_PARAM *p, unsigned long int val);
118*b077aed3SPierre Pronchery int OSSL_PARAM_set_int32(OSSL_PARAM *p, int32_t val);
119*b077aed3SPierre Pronchery int OSSL_PARAM_set_uint32(OSSL_PARAM *p, uint32_t val);
120*b077aed3SPierre Pronchery int OSSL_PARAM_set_int64(OSSL_PARAM *p, int64_t val);
121*b077aed3SPierre Pronchery int OSSL_PARAM_set_uint64(OSSL_PARAM *p, uint64_t val);
122*b077aed3SPierre Pronchery int OSSL_PARAM_set_size_t(OSSL_PARAM *p, size_t val);
123*b077aed3SPierre Pronchery int OSSL_PARAM_set_time_t(OSSL_PARAM *p, time_t val);
124*b077aed3SPierre Pronchery 
125*b077aed3SPierre Pronchery int OSSL_PARAM_get_double(const OSSL_PARAM *p, double *val);
126*b077aed3SPierre Pronchery int OSSL_PARAM_set_double(OSSL_PARAM *p, double val);
127*b077aed3SPierre Pronchery 
128*b077aed3SPierre Pronchery int OSSL_PARAM_get_BN(const OSSL_PARAM *p, BIGNUM **val);
129*b077aed3SPierre Pronchery int OSSL_PARAM_set_BN(OSSL_PARAM *p, const BIGNUM *val);
130*b077aed3SPierre Pronchery 
131*b077aed3SPierre Pronchery int OSSL_PARAM_get_utf8_string(const OSSL_PARAM *p, char **val, size_t max_len);
132*b077aed3SPierre Pronchery int OSSL_PARAM_set_utf8_string(OSSL_PARAM *p, const char *val);
133*b077aed3SPierre Pronchery 
134*b077aed3SPierre Pronchery int OSSL_PARAM_get_octet_string(const OSSL_PARAM *p, void **val, size_t max_len,
135*b077aed3SPierre Pronchery                                 size_t *used_len);
136*b077aed3SPierre Pronchery int OSSL_PARAM_set_octet_string(OSSL_PARAM *p, const void *val, size_t len);
137*b077aed3SPierre Pronchery 
138*b077aed3SPierre Pronchery int OSSL_PARAM_get_utf8_ptr(const OSSL_PARAM *p, const char **val);
139*b077aed3SPierre Pronchery int OSSL_PARAM_set_utf8_ptr(OSSL_PARAM *p, const char *val);
140*b077aed3SPierre Pronchery 
141*b077aed3SPierre Pronchery int OSSL_PARAM_get_octet_ptr(const OSSL_PARAM *p, const void **val,
142*b077aed3SPierre Pronchery                              size_t *used_len);
143*b077aed3SPierre Pronchery int OSSL_PARAM_set_octet_ptr(OSSL_PARAM *p, const void *val,
144*b077aed3SPierre Pronchery                              size_t used_len);
145*b077aed3SPierre Pronchery 
146*b077aed3SPierre Pronchery int OSSL_PARAM_get_utf8_string_ptr(const OSSL_PARAM *p, const char **val);
147*b077aed3SPierre Pronchery int OSSL_PARAM_get_octet_string_ptr(const OSSL_PARAM *p, const void **val,
148*b077aed3SPierre Pronchery                                     size_t *used_len);
149*b077aed3SPierre Pronchery 
150*b077aed3SPierre Pronchery int OSSL_PARAM_modified(const OSSL_PARAM *p);
151*b077aed3SPierre Pronchery void OSSL_PARAM_set_all_unmodified(OSSL_PARAM *p);
152*b077aed3SPierre Pronchery 
153*b077aed3SPierre Pronchery OSSL_PARAM *OSSL_PARAM_dup(const OSSL_PARAM *p);
154*b077aed3SPierre Pronchery OSSL_PARAM *OSSL_PARAM_merge(const OSSL_PARAM *p1, const OSSL_PARAM *p2);
155*b077aed3SPierre Pronchery void OSSL_PARAM_free(OSSL_PARAM *p);
156*b077aed3SPierre Pronchery 
157*b077aed3SPierre Pronchery # ifdef  __cplusplus
158*b077aed3SPierre Pronchery }
159*b077aed3SPierre Pronchery # endif
160*b077aed3SPierre Pronchery #endif
161