| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-04-23 20:55:52 +08:00
										 |  |  |  * Copyright 2010-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-06 20:32:17 +08:00
										 |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							| 
									
										
										
										
											2016-05-18 02:51:04 +08:00
										 |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-14 08:59:11 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * CMAC low level APIs are deprecated for public use, but still ok for internal | 
					
						
							|  |  |  |  * use. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "internal/deprecated.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2015-05-14 22:56:48 +08:00
										 |  |  | #include "internal/cryptlib.h"
 | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | #include <openssl/evp.h>
 | 
					
						
							| 
									
										
										
										
											2019-09-28 06:45:33 +08:00
										 |  |  | #include "crypto/asn1.h"
 | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * CMAC "ASN1" method. This is just here to indicate the maximum CMAC output | 
					
						
							|  |  |  |  * length and to free up a CMAC key. | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int cmac_size(const EVP_PKEY *pkey) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     return EVP_MAX_BLOCK_LENGTH; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void cmac_key_free(EVP_PKEY *pkey) | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-25 03:40:00 +08:00
										 |  |  |     EVP_MAC_CTX *cmctx = EVP_PKEY_get0(pkey); | 
					
						
							| 
									
										
										
										
											2020-06-18 16:26:22 +08:00
										 |  |  |     EVP_MAC *mac = cmctx == NULL ? NULL : EVP_MAC_CTX_mac(cmctx); | 
					
						
							| 
									
										
										
										
											2019-05-07 18:39:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 16:26:22 +08:00
										 |  |  |     EVP_MAC_CTX_free(cmctx); | 
					
						
							| 
									
										
										
										
											2019-05-07 18:39:58 +08:00
										 |  |  |     EVP_MAC_free(mac); | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  | const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = { | 
					
						
							|  |  |  |     EVP_PKEY_CMAC, | 
					
						
							|  |  |  |     EVP_PKEY_CMAC, | 
					
						
							|  |  |  |     0, | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     "CMAC", | 
					
						
							|  |  |  |     "OpenSSL CMAC method", | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     0, 0, 0, 0, | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     0, 0, 0, | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     cmac_size, | 
					
						
							|  |  |  |     0, 0, | 
					
						
							|  |  |  |     0, 0, 0, 0, 0, 0, 0, | 
					
						
							| 
									
										
										
										
											2010-02-08 23:31:35 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-22 11:40:55 +08:00
										 |  |  |     cmac_key_free, | 
					
						
							|  |  |  |     0, | 
					
						
							|  |  |  |     0, 0 | 
					
						
							|  |  |  | }; |