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