68b58e57688c796fa08992fe6679968d33c38858
[openssl.git] / include / openssl / param_build.h
1 /*
2  * Copyright 2019 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 #include <openssl/params.h>
12 #include <openssl/types.h>
13
14 #define OSSL_PARAM_BLD_MAX 25
15
16 typedef struct {
17     const char *key;
18     int type;
19     int secure;
20     size_t size;
21     size_t alloc_blocks;
22     const BIGNUM *bn;
23     const void *string;
24     union {
25         /*
26          * These fields are never directly addressed, but their sizes are
27          * imporant so that all native types can be copied here without overrun.
28          */
29         ossl_intmax_t i;
30         ossl_uintmax_t u;
31         double d;
32     } num;
33 } OSSL_PARAM_BLD_DEF;
34
35 typedef struct {
36     size_t curr;
37     size_t total_blocks;
38     size_t secure_blocks;
39     OSSL_PARAM_BLD_DEF params[OSSL_PARAM_BLD_MAX];
40 } OSSL_PARAM_BLD;
41
42 void OSSL_PARAM_BLD_init(OSSL_PARAM_BLD *bld);
43 OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
44 void OSSL_PARAM_BLD_free(OSSL_PARAM *params);
45
46 int OSSL_PARAM_BLD_push_int(OSSL_PARAM_BLD *bld, const char *key, int val);
47 int OSSL_PARAM_BLD_push_uint(OSSL_PARAM_BLD *bld, const char *key,
48                              unsigned int val);
49 int OSSL_PARAM_BLD_push_long(OSSL_PARAM_BLD *bld, const char *key,
50                              long int val);
51 int OSSL_PARAM_BLD_push_ulong(OSSL_PARAM_BLD *bld, const char *key,
52                               unsigned long int val);
53 int OSSL_PARAM_BLD_push_int32(OSSL_PARAM_BLD *bld, const char *key,
54                               int32_t val);
55 int OSSL_PARAM_BLD_push_uint32(OSSL_PARAM_BLD *bld, const char *key,
56                                uint32_t val);
57 int OSSL_PARAM_BLD_push_int64(OSSL_PARAM_BLD *bld, const char *key,
58                               int64_t val);
59 int OSSL_PARAM_BLD_push_uint64(OSSL_PARAM_BLD *bld, const char *key,
60                                uint64_t val);
61 int OSSL_PARAM_BLD_push_size_t(OSSL_PARAM_BLD *bld, const char *key,
62                                size_t val);
63 int OSSL_PARAM_BLD_push_double(OSSL_PARAM_BLD *bld, const char *key,
64                                double val);
65 int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
66                            const BIGNUM *bn);
67 int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
68                                const BIGNUM *bn, size_t sz);
69 int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
70                                     const char *buf, size_t bsize);
71 int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
72                                  char *buf, size_t bsize);
73 int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
74                                      const void *buf, size_t bsize);
75 int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
76                                   void *buf, size_t bsize);