]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/param_build_set.c
2 * Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 * Key Management utility functions to share functionality between the export()
12 * and get_params() methods.
13 * export() uses OSSL_PARAM_BLD, and get_params() used the OSSL_PARAM[] to
14 * fill in parameter data for the same key and data fields.
17 #include <openssl/core_names.h>
18 #include "internal/param_build_set.h"
20 DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const
, BIGNUM
)
22 int ossl_param_build_set_int(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*p
,
23 const char *key
, int num
)
26 return OSSL_PARAM_BLD_push_int(bld
, key
, num
);
27 p
= OSSL_PARAM_locate(p
, key
);
29 return OSSL_PARAM_set_int(p
, num
);
33 int ossl_param_build_set_utf8_string(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*p
,
34 const char *key
, const char *buf
)
37 return OSSL_PARAM_BLD_push_utf8_string(bld
, key
, buf
, 0);
38 p
= OSSL_PARAM_locate(p
, key
);
40 return OSSL_PARAM_set_utf8_string(p
, buf
);
44 int ossl_param_build_set_octet_string(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*p
,
46 const unsigned char *data
,
50 return OSSL_PARAM_BLD_push_octet_string(bld
, key
, data
, data_len
);
52 p
= OSSL_PARAM_locate(p
, key
);
54 return OSSL_PARAM_set_octet_string(p
, data
, data_len
);
58 int ossl_param_build_set_bn_pad(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*p
,
59 const char *key
, const BIGNUM
*bn
, size_t sz
)
62 return OSSL_PARAM_BLD_push_BN_pad(bld
, key
, bn
, sz
);
63 p
= OSSL_PARAM_locate(p
, key
);
65 if (sz
> p
->data_size
)
67 /* TODO(3.0) Change to use OSSL_PARAM_set_BN_pad */
69 return OSSL_PARAM_set_BN(p
, bn
);
74 int ossl_param_build_set_bn(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*p
,
75 const char *key
, const BIGNUM
*bn
)
78 return OSSL_PARAM_BLD_push_BN(bld
, key
, bn
);
80 p
= OSSL_PARAM_locate(p
, key
);
82 return OSSL_PARAM_set_BN(p
, bn
) > 0;
86 int ossl_param_build_set_multi_key_bn(OSSL_PARAM_BLD
*bld
, OSSL_PARAM
*params
,
88 STACK_OF(BIGNUM_const
) *stk
)
90 int i
, sz
= sk_BIGNUM_const_num(stk
);
95 for (i
= 0; i
< sz
&& names
[i
] != NULL
; ++i
) {
96 if (!OSSL_PARAM_BLD_push_BN(bld
, names
[i
],
97 sk_BIGNUM_const_value(stk
, i
)))
103 for (i
= 0; i
< sz
&& names
[i
] != NULL
; ++i
) {
104 p
= OSSL_PARAM_locate(params
, names
[i
]);
106 if (!OSSL_PARAM_set_BN(p
, sk_BIGNUM_const_value(stk
, i
)))