xref: /freebsd/crypto/openssl/doc/man3/BN_CTX_new.pod (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1=pod
2
3=head1 NAME
4
5BN_CTX_new_ex, BN_CTX_new, BN_CTX_secure_new_ex, BN_CTX_secure_new, BN_CTX_free
6- allocate and free BN_CTX structures
7
8=head1 SYNOPSIS
9
10 #include <openssl/bn.h>
11
12 BN_CTX *BN_CTX_new_ex(OSSL_LIB_CTX *ctx);
13 BN_CTX *BN_CTX_new(void);
14
15 BN_CTX *BN_CTX_secure_new_ex(OSSL_LIB_CTX *ctx);
16 BN_CTX *BN_CTX_secure_new(void);
17
18 void BN_CTX_free(BN_CTX *c);
19
20=head1 DESCRIPTION
21
22A B<BN_CTX> is a structure that holds B<BIGNUM> temporary variables used by
23library functions. Since dynamic memory allocation to create B<BIGNUM>s
24is rather expensive when used in conjunction with repeated subroutine
25calls, the B<BN_CTX> structure is used.
26
27BN_CTX_new_ex() allocates and initializes a B<BN_CTX> structure for the given
28library context B<ctx>. The <ctx> value may be NULL in which case the default
29library context will be used. BN_CTX_new() is the same as BN_CTX_new_ex() except
30that the default library context is always used.
31
32BN_CTX_secure_new_ex() allocates and initializes a B<BN_CTX> structure
33but uses the secure heap (see L<CRYPTO_secure_malloc(3)>) to hold the
34B<BIGNUM>s for the given library context B<ctx>. The <ctx> value may be NULL in
35which case the default library context will be used. BN_CTX_secure_new() is the
36same as BN_CTX_secure_new_ex() except that the default library context is always
37used.
38
39BN_CTX_free() frees the components of the B<BN_CTX> and the structure itself.
40Since BN_CTX_start() is required in order to obtain B<BIGNUM>s from the
41B<BN_CTX>, in most cases BN_CTX_end() must be called before the B<BN_CTX> may
42be freed by BN_CTX_free().  If B<c> is NULL, nothing is done.
43
44A given B<BN_CTX> must only be used by a single thread of execution.  No
45locking is performed, and the internal pool allocator will not properly handle
46multiple threads of execution.
47
48=head1 RETURN VALUES
49
50BN_CTX_new() and BN_CTX_secure_new() return a pointer to the B<BN_CTX>.
51If the allocation fails,
52they return B<NULL> and sets an error code that can be obtained by
53L<ERR_get_error(3)>.
54
55BN_CTX_free() has no return values.
56
57=head1 REMOVED FUNCTIONALITY
58
59 void BN_CTX_init(BN_CTX *c);
60
61BN_CTX_init() is no longer available as of OpenSSL 1.1.0. Applications should
62replace use of BN_CTX_init with BN_CTX_new instead:
63
64 BN_CTX *ctx;
65 ctx = BN_CTX_new();
66 if (!ctx)
67     /* error */
68 ...
69 BN_CTX_free(ctx);
70
71=head1 SEE ALSO
72
73L<ERR_get_error(3)>, L<BN_add(3)>,
74L<BN_CTX_start(3)>
75
76=head1 HISTORY
77
78BN_CTX_init() was removed in OpenSSL 1.1.0.
79
80=head1 COPYRIGHT
81
82Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
83
84Licensed under the Apache License 2.0 (the "License").  You may not use
85this file except in compliance with the License.  You can obtain a copy
86in the file LICENSE in the source distribution or at
87L<https://www.openssl.org/source/license.html>.
88
89=cut
90