summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EVP_aes_128_ccm.3
blob: 251e805fb0a58fc896bbb3aae2bfa7887b57e19c (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
.\" $OpenBSD: EVP_aes_128_ccm.3,v 1.1 2024/12/20 01:54:03 schwarze Exp $
.\" full merge up to:
.\" OpenSSL EVP_EncryptInit.pod 0874d7f2 Oct 11 13:13:47 2022 +0100
.\" OpenSSL EVP_aes.pod a1ec85c1 Apr 21 10:49:12 2020 +0100
.\"
.\" Copyright (c) 2024 Ingo Schwarze <schwarze@openbsd.org>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
.\" copyright notice and this permission notice appear in all copies.
.\"
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
.\" This file is a derived work containing a few sentences
.\" written by Dr. Stephen Henson <steve@openssl.org>
.\" covered by the following license:
.\"
.\" Copyright (c) 2012 The OpenSSL Project.  All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\"
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\"
.\" 3. All advertising materials mentioning features or use of this
.\"    software must display the following acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
.\"
.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
.\"    endorse or promote products derived from this software without
.\"    prior written permission. For written permission, please contact
.\"    openssl-core@openssl.org.
.\"
.\" 5. Products derived from this software may not be called "OpenSSL"
.\"    nor may "OpenSSL" appear in their names without prior written
.\"    permission of the OpenSSL Project.
.\"
.\" 6. Redistributions of any form whatsoever must retain the following
.\"    acknowledgment:
.\"    "This product includes software developed by the OpenSSL Project
.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
.\" OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd $Mdocdate: December 20 2024 $
.Dt EVP_AES_128_CCM 3
.Os
.Sh NAME
.Nm EVP_aes_128_ccm ,
.Nm EVP_aes_192_ccm ,
.Nm EVP_aes_256_ccm
.Nd EVP AES cipher in Counter with CBC-MAC mode
.Sh SYNOPSIS
.In openssl/evp.h
.Ft const EVP_CIPHER *
.Fn EVP_aes_128_ccm void
.Ft const EVP_CIPHER *
.Fn EVP_aes_192_ccm void
.Ft const EVP_CIPHER *
.Fn EVP_aes_256_ccm void
.Sh DESCRIPTION
.Fn EVP_aes_128_ccm ,
.Fn EVP_aes_192_ccm ,
and
.Fn EVP_aes_256_ccm
provide the Advanced Encryption Standard algorithm for 128, 192 and 256-bit
keys in Counter with CBC-MAC (CCM) mode in the
.Xr evp 3
framework.
This mode supports Authenticated Encryption with Additional Data (AEAD)
and can be used in a number of communication protocols.
Longer keys make precomputation attacks harder at a cost in performance.
.Pp
For CCM mode ciphers, the behaviour of the EVP interface is subtly
altered and several additional
.Xr EVP_CIPHER_CTX_ctrl 3
operations are required to function correctly.
.Pp
The less cumbersome and less error-prone
.Xr EVP_AEAD_CTX_new 3
API does not provide CCM modes.
Some communication protocols support alternatives to CCM, which may
sometimes allow choosing the better API by avoiding CCM.
.Ss Configuration controls
The following two control commands can be issued as soon as
.Xr EVP_EncryptInit 3
has been called with a CCM
.Fa type
and
.Dv NULL
pointers for
.Fa key
and
.Fa iv .
Both commands are optional and override each other.
If issued when a nonce is already set, they silently cause data corruption.
The
.Fa ptr
argument is ignored by both; passing
.Dv NULL
is recommended.
.Bl -tag -width Ds
.It Dv EVP_CTRL_CCM_SET_L
Set the size
.Ms L
of the length field to
.Fa arg
bytes and the size of the nonce to
.No 15 \- Fa arg
bytes.
By default, 8 bytes are used for the length field and 7 for the nonce.
Selecting a smaller size
.Ms L
for the length field reduces des maximum size of messages that can be sent,
but in return allows transmitting more messages with the same key.
It is an error to pass less than 2 or more than the default value of 8 for
.Fa arg .
.It Dv EVP_CTRL_CCM_SET_IVLEN
Set the size of the nonce to
.Fa arg
bytes and the size
.Ms L
of the length field to
.No 15 \- Fa arg
bytes.
By default, 7 bytes are used for the nonce and 8 for the length field.
Selecting a larger size of the nonce allows transmitting more messages with
the same key at the expense of reducing the maximum size for each message.
It is an error to pass more than 13 or less than the default value of 7 for
.Fa arg .
.El
.Pp
After optionally issuing one of the above control commands,
.Xr EVP_EncryptInit 3
can be called a second time, this time passing
.Dv NULL
for the
.Fa type
argument, with the other two arguments pointing to the desired AES key
and to the desired nonce.
.Ss Encryption controls
.Bl -tag -width Ds
.It Dv EVP_CTRL_CCM_SET_TAG
If the
.Fa ptr
argument is
.Dv NULL ,
set the tag length
.Ms M
to
.Fa arg
bytes.
The default value is 12.
Selecting a larger value makes tampering harder for an attacker,
at a small expense of making the messages slightly longer.
Selecting a smaller value is not recommended.
It is an error to pass an odd number for
.Fa arg ,
or a number that is less than 4 or greater than 16, or to pass
.Dv NULL
to
.Fa ptr
when
.Fa ctx
is not configured for encrypting.
Issuing this control command when an encryption key is already configured
silently causes data corruption.
.It Dv EVP_CTRL_CCM_GET_TAG
Store the
.Fa arg
bytes of the tag in the memory provided by the caller starting at
.Fa ptr .
It is an error to issue this control command when
.Fa ctx
is not configured for encrypting, when no data was encrypted yet, with an
.Fa arg
that does not match the configured tag length
.Ms M ,
or when the tag has already been retrieved earlier.
.El
.Pp
Before passing any plaintext data to
.Xr EVP_EncryptUpdate 3 ,
call
.Xr EVP_EncryptUpdate 3
with both
.Fa in
and
.Fa out
set to
.Dv NULL ,
passing the total plaintext length in bytes as
.Fa in_len .
This constructs the first block to be digested with CBC-MAC
and copies the text length to
.Pf * Fa out_len .
It does not check whether
.Fa in_len
exceeds the limit of
.Pf 256\(ha Ms L ;
the most significant bytes of excessive values are silently discarded.
.Pp
It is an error if the
.Fa in_len
argument of the
.Xr EVP_EncryptUpdate 3
call passing the plaintext data does not match the total length
specified ealier.
Splitting the text into more than one chunks to be passed in multiple calls of
.Xr EVP_EncryptUpdate 3
is not supported for CCM.
.Pp
To specify any additional authenticated data (AAD), call
.Xr EVP_EncryptUpdate 3
with the
.Fa out
argument set to
.Dv NULL .
.Ss Decryption controls
.Bl -tag -width Ds
.It Dv EVP_CTRL_CCM_SET_TAG
If the
.Fa ptr
argument is not
.Dv NULL ,
copy
.Fa arg
bytes starting at
.Fa ptr
to the expected CCM tag value.
It is an error to pass an odd number for
.Fa arg ,
or a number that is less than 4 or greater than 16.
Passing a number that does not correspond to the tag length
.Ms M
that was used for encryption does not raise an error right away,
but results in undefined behaviour
and typically causes subsequent authentication failure.
It is also an error to pass a
.Pf non- Dv NULL
.Fa ptr
when
.Fa ctx
is configured for encryption.
.El
.Pp
Before passing any ciphertext data to
.Xr EVP_DecryptUpdate 3 ,
call
.Xr EVP_DecryptUpdate 3
with both
.Fa in
and
.Fa out
set to
.Dv NULL ,
passing the total ciphertext length in bytes as
.Fa in_len .
This constructs the first block to be digested with CBC-MAC
and copies the text length to
.Pf * Fa out_len .
It does not check whether
.Fa in_len
exceeds the limit of
.Pf 256\(ha Ms L ;
the most significant bytes of excessive values are silently discarded.
.Pp
It is an error if the
.Fa in_len
argument of the
.Xr EVP_DecryptUpdate 3
call passing the ciphertext data does not match the total length
specified ealier.
Splitting the text into more than one chunks to be passed in multiple calls of
.Xr EVP_DecryptUpdate 3
is not supported for CCM.
.Pp
To specify any additional authenticated data (AAD), call
.Xr EVP_DecryptUpdate 3
with the
.Fa out
argument set to
.Dv NULL .
.Pp
If the return value of
.Xr EVP_DecryptUpdate 3
does not indicate success, the authentication operation may have failed.
In that case, regard any output data as corrupted.
.Pp
Do not call
.Xr EVP_DecryptFinal 3
when using CCM.
Such a call would not do anything useful, and it would fail
because the tag that was set with
.Dv EVP_CTRL_CCM_SET_TAG
was already consumed by
.Xr EVP_DecryptUpdate 3 .
.Sh RETURN VALUES
These functions return a static constant
.Vt EVP_CIPHER
structure that provides the implementation of the respective AEAD cipher mode.
.Sh SEE ALSO
.Xr AES_encrypt 3 ,
.Xr evp 3 ,
.Xr EVP_aes_128_cbc 3 ,
.Xr EVP_aes_128_gcm 3 ,
.Xr EVP_EncryptInit 3
.Sh STANDARDS
.Rs
.%A Doug Whiting
.%A Russ Housley
.%A Niels Ferguson
.%T Counter with CBC-MAC (CCM)
.%R RFC 3610
.%D September 2003
.Re
.Sh HISTORY
.Fn EVP_aes_128_ccm ,
.Fn EVP_aes_192_ccm ,
and
.Fn EVP_aes_256_ccm
first appeared in OpenSSL 1.0.1 and have been available since
.Ox 5.3 .