xref: /openbsd-src/lib/libcrypto/man/BN_copy.3 (revision ad110f3f2f3fa3daf2776f77c7adb6d3e866e18a)
1*ad110f3fSschwarze.\"	$OpenBSD: BN_copy.3,v 1.10 2021/12/06 19:45:27 schwarze Exp $
226b6f712Sschwarze.\"	OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
38974101aSjmc.\"
426b6f712Sschwarze.\" This file was written by Ulf Moeller <ulf@openssl.org>
526b6f712Sschwarze.\" and Matt Caswell <matt@openssl.org>.
626b6f712Sschwarze.\" Copyright (c) 2000, 2015 The OpenSSL Project.  All rights reserved.
726b6f712Sschwarze.\"
826b6f712Sschwarze.\" Redistribution and use in source and binary forms, with or without
926b6f712Sschwarze.\" modification, are permitted provided that the following conditions
1026b6f712Sschwarze.\" are met:
1126b6f712Sschwarze.\"
1226b6f712Sschwarze.\" 1. Redistributions of source code must retain the above copyright
1326b6f712Sschwarze.\"    notice, this list of conditions and the following disclaimer.
1426b6f712Sschwarze.\"
1526b6f712Sschwarze.\" 2. Redistributions in binary form must reproduce the above copyright
1626b6f712Sschwarze.\"    notice, this list of conditions and the following disclaimer in
1726b6f712Sschwarze.\"    the documentation and/or other materials provided with the
1826b6f712Sschwarze.\"    distribution.
1926b6f712Sschwarze.\"
2026b6f712Sschwarze.\" 3. All advertising materials mentioning features or use of this
2126b6f712Sschwarze.\"    software must display the following acknowledgment:
2226b6f712Sschwarze.\"    "This product includes software developed by the OpenSSL Project
2326b6f712Sschwarze.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
2426b6f712Sschwarze.\"
2526b6f712Sschwarze.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
2626b6f712Sschwarze.\"    endorse or promote products derived from this software without
2726b6f712Sschwarze.\"    prior written permission. For written permission, please contact
2826b6f712Sschwarze.\"    openssl-core@openssl.org.
2926b6f712Sschwarze.\"
3026b6f712Sschwarze.\" 5. Products derived from this software may not be called "OpenSSL"
3126b6f712Sschwarze.\"    nor may "OpenSSL" appear in their names without prior written
3226b6f712Sschwarze.\"    permission of the OpenSSL Project.
3326b6f712Sschwarze.\"
3426b6f712Sschwarze.\" 6. Redistributions of any form whatsoever must retain the following
3526b6f712Sschwarze.\"    acknowledgment:
3626b6f712Sschwarze.\"    "This product includes software developed by the OpenSSL Project
3726b6f712Sschwarze.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
3826b6f712Sschwarze.\"
3926b6f712Sschwarze.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
4026b6f712Sschwarze.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4126b6f712Sschwarze.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4226b6f712Sschwarze.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
4326b6f712Sschwarze.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
4426b6f712Sschwarze.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
4526b6f712Sschwarze.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
4626b6f712Sschwarze.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4726b6f712Sschwarze.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4826b6f712Sschwarze.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
4926b6f712Sschwarze.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
5026b6f712Sschwarze.\" OF THE POSSIBILITY OF SUCH DAMAGE.
5126b6f712Sschwarze.\"
52*ad110f3fSschwarze.Dd $Mdocdate: December 6 2021 $
53f1048625Sschwarze.Dt BN_COPY 3
54f1048625Sschwarze.Os
55f1048625Sschwarze.Sh NAME
56f1048625Sschwarze.Nm BN_copy ,
5726b6f712Sschwarze.Nm BN_dup ,
5826b6f712Sschwarze.Nm BN_with_flags
59f1048625Sschwarze.Nd copy BIGNUMs
60f1048625Sschwarze.Sh SYNOPSIS
61f1048625Sschwarze.In openssl/bn.h
62f1048625Sschwarze.Ft BIGNUM *
63f1048625Sschwarze.Fo BN_copy
64f1048625Sschwarze.Fa "BIGNUM *to"
65f1048625Sschwarze.Fa "const BIGNUM *from"
66f1048625Sschwarze.Fc
67f1048625Sschwarze.Ft BIGNUM *
68f1048625Sschwarze.Fo BN_dup
69f1048625Sschwarze.Fa "const BIGNUM *from"
70f1048625Sschwarze.Fc
7126b6f712Sschwarze.Ft void
7226b6f712Sschwarze.Fo BN_with_flags
7326b6f712Sschwarze.Fa "BIGNUM *dest"
7426b6f712Sschwarze.Fa "const BIGNUM *b"
7526b6f712Sschwarze.Fa "int flags"
7626b6f712Sschwarze.Fc
77f1048625Sschwarze.Sh DESCRIPTION
78f1048625Sschwarze.Fn BN_copy
79f1048625Sschwarzecopies
80f1048625Sschwarze.Fa from
81f1048625Sschwarzeto
82f1048625Sschwarze.Fa to .
832d95bc5fSschwarze.Pp
84f1048625Sschwarze.Fn BN_dup
85f1048625Sschwarzecreates a new
86f1048625Sschwarze.Vt BIGNUM
87f1048625Sschwarzecontaining the value
88f1048625Sschwarze.Fa from .
8926b6f712Sschwarze.Pp
9026b6f712Sschwarze.Fn BN_with_flags
9126b6f712Sschwarzecreates a
9226b6f712Sschwarze.Em temporary
9326b6f712Sschwarzeshallow copy of
9426b6f712Sschwarze.Fa b
9526b6f712Sschwarzein
9626b6f712Sschwarze.Fa dest .
9726b6f712SschwarzeIt places significant restrictions on the copied data.
9826b6f712SschwarzeApplications that do not adhere to these restrictions
9926b6f712Sschwarzemay encounter unexpected side effects or crashes.
100*ad110f3fSschwarzeFor that reason, use of this function is discouraged.
10126b6f712Sschwarze.Pp
10226b6f712SschwarzeAny flags provided in
10326b6f712Sschwarze.Fa flags
10426b6f712Sschwarzewill be set in
10526b6f712Sschwarze.Fa dest
10626b6f712Sschwarzein addition to any flags already set in
10726b6f712Sschwarze.Fa b .
10826b6f712SschwarzeFor example, this can be used to create a temporary copy of a
10926b6f712Sschwarze.Vt BIGNUM
11026b6f712Sschwarzewith the
11126b6f712Sschwarze.Dv BN_FLG_CONSTTIME
11226b6f712Sschwarzeflag set for constant time operations.
11326b6f712Sschwarze.Pp
11426b6f712SschwarzeThe temporary copy in
11526b6f712Sschwarze.Fa dest
11626b6f712Sschwarzewill share some internal state with
11726b6f712Sschwarze.Fa b .
11826b6f712SschwarzeFor this reason, the following restrictions apply to the use of
11926b6f712Sschwarze.Fa dest :
12026b6f712Sschwarze.Bl -bullet
12126b6f712Sschwarze.It
12226b6f712Sschwarze.Fa dest
12326b6f712Sschwarzeshould be a newly allocated
12426b6f712Sschwarze.Vt BIGNUM
12526b6f712Sschwarzeobtained via a call to
12626b6f712Sschwarze.Xr BN_new 3 .
12726b6f712SschwarzeIt should not have been used for other purposes or initialised in any way.
12826b6f712Sschwarze.It
12926b6f712Sschwarze.Fa dest
13026b6f712Sschwarzemust only be used in "read-only" operations, i.e. typically those
13126b6f712Sschwarzefunctions where the relevant parameter is declared "const".
13226b6f712Sschwarze.It
13326b6f712Sschwarze.Fa dest
13426b6f712Sschwarzemust be used and freed before any further subsequent use of
13526b6f712Sschwarze.Fa b .
13626b6f712Sschwarze.El
137f1048625Sschwarze.Sh RETURN VALUES
138f1048625Sschwarze.Fn BN_copy
139f1048625Sschwarzereturns
140f1048625Sschwarze.Fa to
14126b6f712Sschwarzeon success or
142f1048625Sschwarze.Dv NULL
143f1048625Sschwarzeon error.
144f1048625Sschwarze.Fn BN_dup
145f1048625Sschwarzereturns the new
14626b6f712Sschwarze.Vt BIGNUM
147f1048625Sschwarzeor
148f1048625Sschwarze.Dv NULL
149f1048625Sschwarzeon error.
150f1048625SschwarzeThe error codes can be obtained by
151f1048625Sschwarze.Xr ERR_get_error 3 .
152f1048625Sschwarze.Sh SEE ALSO
15368d7c31cSschwarze.Xr BN_new 3 ,
15448e9223cSschwarze.Xr BN_set_flags 3
155f1048625Sschwarze.Sh HISTORY
156f1048625Sschwarze.Fn BN_copy
157f1048625Sschwarzeand
158f1048625Sschwarze.Fn BN_dup
15910e00d17Sschwarzefirst appeared in SSLeay 0.5.1 and have been available since
1600c85fcf7Sschwarze.Ox 2.4 .
161d7f39159Sschwarze.Pp
162d7f39159Sschwarze.Fn BN_with_flags
16310e00d17Sschwarzefirst appeared in OpenSSL 0.9.7h and 0.9.8a
16410e00d17Sschwarzeand has been available since
165d7f39159Sschwarze.Ox 4.0 .
166