summaryrefslogtreecommitdiff
path: root/lib/libcrypto/man/BN_set_bit.3
blob: 4a199cd0d0699f791f65f26c2e1edc193efeac47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
.Dd $Mdocdate: February 23 2015 $
.Dt BN_SET_BIT 3
.Os
.Sh NAME
.Nm BN_set_bit ,
.Nm BN_clear_bit ,
.Nm BN_is_bit_set ,
.Nm BN_mask_bits ,
.Nm BN_lshift ,
.Nm BN_lshift1 ,
.Nm BN_rshift ,
.Nm BN_rshift1
.Nd bit operations on BIGNUMs
.Sh SYNOPSIS
.In openssl/bn.h
.Ft int
.Fo BN_set_bit
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_clear_bit
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_is_bit_set
.Fa "const BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_mask_bits
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_lshift
.Fa "BIGNUM *r"
.Fa "const BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_lshift1
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fc
.Ft int
.Fo BN_rshift
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fa "int n"
.Fc
.Ft int
.Fo BN_rshift1
.Fa "BIGNUM *r"
.Fa "BIGNUM *a"
.Fc
.Sh DESCRIPTION
.Fn BN_set_bit
sets bit
.Fa n
in
.Fa a
to 1
.Pq Li a|=(1<<n) .
The number is expanded if necessary.
.Pp
.Fn BN_clear_bit
sets bit
.Fa n
in
.Fa a
to 0
.Pq Li a&=~(1<<n) .
An error occurs if
.Fa a
is shorter than
.Fa n
bits.
.Pp
.Fn BN_is_bit_set
tests if bit
.Fa n
in
.Fa a
is set.
.Pp
.Fn BN_mask_bits
truncates
.Fa a
to an
.Fa n
bit number
.Pq Li a&=~((~0)>>n) .
An error occurs if
.Fa a
already is shorter than
.Fa n
bits.
.Pp
.Fn BN_lshift
shifts
.Fa a
left by
.Fa n
bits and places the result in
.Fa r
.Pq Li r=a*2^n .
.Fn BN_lshift1
shifts
.Fa a
left by one and places the result in
.Fa r
.Pq Li r=2*a .
.Pp
.Fn BN_rshift
shifts
.Fa a
right by
.Fa n
bits and places the result in
.Fa r
.Pq Li r=a/2^n .
.Fn BN_rshift1
shifts
.Fa a
right by one and places the result in
.Fa r
.Pq Li r=a/2 .
.Pp
For the shift functions,
.Fa r
and
.Fa a
may be the same variable.
.Sh RETURN VALUES
.Fn BN_is_bit_set
returns 1 if the bit is set, 0 otherwise.
.Pp
All other functions return 1 for success, 0 on error.
The error codes can be obtained by
.Xr ERR_get_error 3 .
.Sh SEE ALSO
.Xr bn 3 ,
.Xr BN_add 3 ,
.Xr BN_num_bytes 3
.Sh HISTORY
.Fn BN_set_bit ,
.Fn BN_clear_bit ,
.Fn BN_is_bit_set ,
.Fn BN_mask_bits ,
.Fn BN_lshift ,
.Fn BN_lshift1 ,
.Fn BN_rshift ,
and
.Fn BN_rshift1
are available in all versions of SSLeay and OpenSSL.