improve SSL_CTX_set_tlsext_ticket_key_cb ref impl
[openssl.git] / crypto / cmac / cm_ameth.c
1 /*
2  * Copyright 2010-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9
10 /*
11  * CMAC low level APIs are deprecated for public use, but still ok for internal
12  * use.
13  */
14 #include "internal/deprecated.h"
15
16 #include <stdio.h>
17 #include "internal/cryptlib.h"
18 #include <openssl/evp.h>
19 #include "crypto/asn1.h"
20
21 /*
22  * CMAC "ASN1" method. This is just here to indicate the maximum CMAC output
23  * length and to free up a CMAC key.
24  */
25
26 static int cmac_size(const EVP_PKEY *pkey)
27 {
28     return EVP_MAX_BLOCK_LENGTH;
29 }
30
31 static void cmac_key_free(EVP_PKEY *pkey)
32 {
33     EVP_MAC_CTX *cmctx = EVP_PKEY_get0(pkey);
34     EVP_MAC *mac = cmctx == NULL ? NULL : EVP_MAC_get_ctx_mac(cmctx);
35
36     EVP_MAC_free_ctx(cmctx);
37     EVP_MAC_free(mac);
38 }
39
40 const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = {
41     EVP_PKEY_CMAC,
42     EVP_PKEY_CMAC,
43     0,
44
45     "CMAC",
46     "OpenSSL CMAC method",
47
48     0, 0, 0, 0,
49
50     0, 0, 0,
51
52     cmac_size,
53     0, 0,
54     0, 0, 0, 0, 0, 0, 0,
55
56     cmac_key_free,
57     0,
58     0, 0
59 };