import libcrypto (LibreSSL 2.5.2)
[unleashed.git] / lib / libcrypto / man / BN_set_bit.3
blob077ca69ce02e0e175c693225d0bcd1aa9f7531c6
1 .\"     $OpenBSD: BN_set_bit.3,v 1.5 2016/12/10 21:13:25 schwarze Exp $
2 .\"     OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3 .\"
4 .\" This file was written by Ulf Moeller <ulf@openssl.org>.
5 .\" Copyright (c) 2000, 2015 The OpenSSL Project.  All rights reserved.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\"
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\"    notice, this list of conditions and the following disclaimer.
13 .\"
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in
16 .\"    the documentation and/or other materials provided with the
17 .\"    distribution.
18 .\"
19 .\" 3. All advertising materials mentioning features or use of this
20 .\"    software must display the following acknowledgment:
21 .\"    "This product includes software developed by the OpenSSL Project
22 .\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23 .\"
24 .\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 .\"    endorse or promote products derived from this software without
26 .\"    prior written permission. For written permission, please contact
27 .\"    openssl-core@openssl.org.
28 .\"
29 .\" 5. Products derived from this software may not be called "OpenSSL"
30 .\"    nor may "OpenSSL" appear in their names without prior written
31 .\"    permission of the OpenSSL Project.
32 .\"
33 .\" 6. Redistributions of any form whatsoever must retain the following
34 .\"    acknowledgment:
35 .\"    "This product includes software developed by the OpenSSL Project
36 .\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37 .\"
38 .\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 .\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 .\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 .\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 .\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 .\" OF THE POSSIBILITY OF SUCH DAMAGE.
50 .\"
51 .Dd $Mdocdate: December 10 2016 $
52 .Dt BN_SET_BIT 3
53 .Os
54 .Sh NAME
55 .Nm BN_set_bit ,
56 .Nm BN_clear_bit ,
57 .Nm BN_is_bit_set ,
58 .Nm BN_mask_bits ,
59 .Nm BN_lshift ,
60 .Nm BN_lshift1 ,
61 .Nm BN_rshift ,
62 .Nm BN_rshift1
63 .Nd bit operations on BIGNUMs
64 .Sh SYNOPSIS
65 .In openssl/bn.h
66 .Ft int
67 .Fo BN_set_bit
68 .Fa "BIGNUM *a"
69 .Fa "int n"
70 .Fc
71 .Ft int
72 .Fo BN_clear_bit
73 .Fa "BIGNUM *a"
74 .Fa "int n"
75 .Fc
76 .Ft int
77 .Fo BN_is_bit_set
78 .Fa "const BIGNUM *a"
79 .Fa "int n"
80 .Fc
81 .Ft int
82 .Fo BN_mask_bits
83 .Fa "BIGNUM *a"
84 .Fa "int n"
85 .Fc
86 .Ft int
87 .Fo BN_lshift
88 .Fa "BIGNUM *r"
89 .Fa "const BIGNUM *a"
90 .Fa "int n"
91 .Fc
92 .Ft int
93 .Fo BN_lshift1
94 .Fa "BIGNUM *r"
95 .Fa "BIGNUM *a"
96 .Fc
97 .Ft int
98 .Fo BN_rshift
99 .Fa "BIGNUM *r"
100 .Fa "BIGNUM *a"
101 .Fa "int n"
103 .Ft int
104 .Fo BN_rshift1
105 .Fa "BIGNUM *r"
106 .Fa "BIGNUM *a"
108 .Sh DESCRIPTION
109 .Fn BN_set_bit
110 sets bit
111 .Fa n
113 .Fa a
114 to 1
115 .Pq Li a|=(1<<n) .
116 The number is expanded if necessary.
118 .Fn BN_clear_bit
119 sets bit
120 .Fa n
122 .Fa a
123 to 0
124 .Pq Li a&=~(1<<n) .
125 An error occurs if
126 .Fa a
127 is shorter than
128 .Fa n
129 bits.
131 .Fn BN_is_bit_set
132 tests if bit
133 .Fa n
135 .Fa a
136 is set.
138 .Fn BN_mask_bits
139 truncates
140 .Fa a
141 to an
142 .Fa n
143 bit number
144 .Pq Li a&=~((~0)>>n) .
145 An error occurs if
146 .Fa a
147 already is shorter than
148 .Fa n
149 bits.
151 .Fn BN_lshift
152 shifts
153 .Fa a
154 left by
155 .Fa n
156 bits and places the result in
157 .Fa r
158 .Pq Li r=a*2^n .
159 Note that
160 .Fa n
161 must be non-negative.
162 .Fn BN_lshift1
163 shifts
164 .Fa a
165 left by one and places the result in
166 .Fa r
167 .Pq Li r=2*a .
169 .Fn BN_rshift
170 shifts
171 .Fa a
172 right by
173 .Fa n
174 bits and places the result in
175 .Fa r
176 .Pq Li r=a/2^n .
177 Note that
178 .Fa n
179 must be non-negative.
180 .Fn BN_rshift1
181 shifts
182 .Fa a
183 right by one and places the result in
184 .Fa r
185 .Pq Li r=a/2 .
187 For the shift functions,
188 .Fa r
190 .Fa a
191 may be the same variable.
192 .Sh RETURN VALUES
193 .Fn BN_is_bit_set
194 returns 1 if the bit is set, 0 otherwise.
196 All other functions return 1 for success, 0 on error.
197 The error codes can be obtained by
198 .Xr ERR_get_error 3 .
199 .Sh SEE ALSO
200 .Xr BN_add 3 ,
201 .Xr BN_new 3 ,
202 .Xr BN_num_bytes 3 ,
203 .Xr BN_set_negative 3 ,
204 .Xr BN_zero 3
205 .Sh HISTORY
206 .Fn BN_set_bit ,
207 .Fn BN_clear_bit ,
208 .Fn BN_is_bit_set ,
209 .Fn BN_mask_bits ,
210 .Fn BN_lshift ,
211 .Fn BN_lshift1 ,
212 .Fn BN_rshift ,
214 .Fn BN_rshift1
215 are available in all versions of SSLeay and OpenSSL.