return param_push_num(bld, key, &num, sizeof(num), OSSL_PARAM_REAL);
}
-int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
- const BIGNUM *bn)
-{
- return OSSL_PARAM_BLD_push_BN_pad(bld, key, bn,
- bn == NULL ? 0 : BN_num_bytes(bn));
-}
-
-int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
- const BIGNUM *bn, size_t sz)
+static int push_BN(OSSL_PARAM_BLD *bld, const char *key,
+ const BIGNUM *bn, size_t sz, int type)
{
int n, secure = 0;
OSSL_PARAM_BLD_DEF *pd;
+ if (!ossl_assert(type == OSSL_PARAM_UNSIGNED_INTEGER
+ || type == OSSL_PARAM_INTEGER))
+ return 0;
+
if (bn != NULL) {
- if (BN_is_negative(bn)) {
+ if (type == OSSL_PARAM_UNSIGNED_INTEGER && BN_is_negative(bn)) {
ERR_raise_data(ERR_LIB_CRYPTO, ERR_R_UNSUPPORTED,
- "Negative big numbers are unsupported for OSSL_PARAM");
+ "Negative big numbers are unsupported for OSSL_PARAM_UNSIGNED_INTEGER");
return 0;
}
if (BN_get_flags(bn, BN_FLG_SECURE) == BN_FLG_SECURE)
secure = 1;
}
- pd = param_push(bld, key, sz, sz, OSSL_PARAM_UNSIGNED_INTEGER, secure);
+ pd = param_push(bld, key, sz, sz, type, secure);
if (pd == NULL)
return 0;
pd->bn = bn;
return 1;
}
+int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
+ const BIGNUM *bn)
+{
+ if (BN_is_negative(bn))
+ return push_BN(bld, key, bn, bn == NULL ? 0 : BN_num_bytes(bn) + 1,
+ OSSL_PARAM_INTEGER);
+ return push_BN(bld, key, bn, bn == NULL ? 0 : BN_num_bytes(bn),
+ OSSL_PARAM_UNSIGNED_INTEGER);
+}
+
+int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
+ const BIGNUM *bn, size_t sz)
+{
+ if (BN_is_negative(bn))
+ return push_BN(bld, key, bn, bn == NULL ? 0 : BN_num_bytes(bn),
+ OSSL_PARAM_INTEGER);
+ return push_BN(bld, key, bn, sz, OSSL_PARAM_UNSIGNED_INTEGER);
+}
+
int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
const char *buf, size_t bsize)
{
param[i].data = p;
if (pd->bn != NULL) {
/* BIGNUM */
- BN_bn2nativepad(pd->bn, (unsigned char *)p, pd->size);
+ if (pd->type == OSSL_PARAM_UNSIGNED_INTEGER)
+ BN_bn2nativepad(pd->bn, (unsigned char *)p, pd->size);
+ else
+ BN_signed_bn2native(pd->bn, (unsigned char *)p, pd->size);
} else if (pd->type == OSSL_PARAM_OCTET_PTR
|| pd->type == OSSL_PARAM_UTF8_PTR) {
/* PTR */
argument.
I<val> is stored by value and an expression or auto variable can be used.
+When B<I<TYPE>> denotes an integer type, signed integer types will normally
+get the OSSL_PARAM type B<OSSL_PARAM_INTEGER> params.
+When B<I<TYPE>> denotes an unsigned integer type will get the OSSL_PARAM type
+B<OSSL_PARAM_UNSIGNED_INTEGER>.
+
OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
that holds the specified BIGNUM I<bn>.
+When the I<bn> is zero or positive, its OSSL_PARAM type becomes
+B<OSSL_PARAM_UNSIGNED_INTEGER>.
+When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
will also be securely allocated.
The I<bn> argument is stored by reference and the underlying BIGNUM object
that holds the specified BIGNUM I<bn>.
The object will be padded to occupy exactly I<sz> bytes, if insufficient space
is specified an error results.
+When the I<bn> is zero or positive, its OSSL_PARAM type becomes
+B<OSSL_PARAM_UNSIGNED_INTEGER>.
+When the I<bn> is negative, its OSSL_PARAM type becomes B<OSSL_PARAM_INTEGER>.
If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
will also be securely allocated.
The I<bn> argument is stored by reference and the underlying BIGNUM object
=head1 NOTES
-OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() currently only
-support nonnegative B<BIGNUM>s. They return an error on negative B<BIGNUM>s.
+OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() only
+support nonnegative B<BIGNUM>s. They return an error on negative
+B<BIGNUM>s.
+To pass signed B<BIGNUM>s, use OSSL_PARAM_BLD_push_signed_BN().
=head1 EXAMPLES
const char *key, const BIGNUM *bn);
int ossl_param_build_set_bn_pad(OSSL_PARAM_BLD *bld, OSSL_PARAM *p,
const char *key, const BIGNUM *bn, size_t sz);
+int ossl_param_build_set_signed_bn(OSSL_PARAM_BLD *bld, OSSL_PARAM *p,
+ const char *key, const BIGNUM *bn);
+int ossl_param_build_set_signed_bn_pad(OSSL_PARAM_BLD *bld, OSSL_PARAM *p,
+ const char *key, const BIGNUM *bn,
+ size_t sz);
int ossl_param_build_set_multi_key_bn(OSSL_PARAM_BLD *bld, OSSL_PARAM *p,
const char *names[],
STACK_OF(BIGNUM_const) *stk);