Debian Codegraph @

src/lib/crypto/OSSLCMAC.cpp

raw
1 /*
2 * Copyright (c) 2017 SURFnet bv
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /*****************************************************************************
28 OSSLHMAC.cpp
29
30 OpenSSL HMAC implementation
31 *****************************************************************************/
32
33 #include "config.h"
34 #include "OSSLCMAC.h"
35
36 const EVP_CIPHER* OSSLCMACDES::getEVPCipher() const
37 {
38 switch(currentKey->getBitLen())
39 {
40 case 56:
41 ERROR_MSG("Only supporting 3DES");
42 return NULL;
43 case 112:
44 return EVP_des_ede_cbc();
45 case 168:
46 return EVP_des_ede3_cbc();
47 default:
48 break;
49 };
50
51 ERROR_MSG("Invalid DES bit len %i", currentKey->getBitLen());
52
53 return NULL;
54 }
55
56 size_t OSSLCMACDES::getMacSize() const
57 {
58 return 8;
59 }
60
61 const EVP_CIPHER* OSSLCMACAES::getEVPCipher() const
62 {
63 switch(currentKey->getBitLen())
64 {
65 case 128:
66 return EVP_aes_128_cbc();
67 case 192:
68 return EVP_aes_192_cbc();
69 case 256:
70 return EVP_aes_256_cbc();
71 default:
72 break;
73 };
74
75 ERROR_MSG("Invalid AES bit len %i", currentKey->getBitLen());
76
77 return NULL;
78 }
79
80 size_t OSSLCMACAES::getMacSize() const
81 {
82 return 16;
83 }
84