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