Debian Codegraph @

src/lib/crypto/BotanMAC.cpp

raw
1 /*
2 * Copyright (c) 2010 .SE (The Internet Infrastructure Foundation)
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 BotanMAC.cpp
29
30 Botan MAC implementation
31 *****************************************************************************/
32
33 #include "config.h"
34 #include "BotanMAC.h"
35
36 std::string BotanHMACMD5::getAlgorithm() const
37 {
38 return "HMAC(MD5)";
39 }
40
41 size_t BotanHMACMD5::getMacSize() const
42 {
43 return 16;
44 }
45
46 std::string BotanHMACSHA1::getAlgorithm() const
47 {
48 return "HMAC(SHA-1)";
49 }
50
51 size_t BotanHMACSHA1::getMacSize() const
52 {
53 return 20;
54 }
55
56 std::string BotanHMACSHA224::getAlgorithm() const
57 {
58 return "HMAC(SHA-224)";
59 }
60
61 size_t BotanHMACSHA224::getMacSize() const
62 {
63 return 28;
64 }
65
66 std::string BotanHMACSHA256::getAlgorithm() const
67 {
68 return "HMAC(SHA-256)";
69 }
70
71 size_t BotanHMACSHA256::getMacSize() const
72 {
73 return 32;
74 }
75
76 std::string BotanHMACSHA384::getAlgorithm() const
77 {
78 return "HMAC(SHA-384)";
79 }
80
81 size_t BotanHMACSHA384::getMacSize() const
82 {
83 return 48;
84 }
85
86 std::string BotanHMACSHA512::getAlgorithm() const
87 {
88 return "HMAC(SHA-512)";
89 }
90
91 size_t BotanHMACSHA512::getMacSize() const
92 {
93 return 64;
94 }
95
96 #ifdef WITH_GOST
97 std::string BotanHMACGOSTR3411::getAlgorithm() const
98 {
99 return "HMAC(GOST-34.11)";
100 }
101
102 size_t BotanHMACGOSTR3411::getMacSize() const
103 {
104 return 32;
105 }
106 #endif
107
108 std::string BotanCMACDES::getAlgorithm() const
109 {
110 switch(currentKey->getBitLen())
111 {
112 case 56:
113 ERROR_MSG("Only supporting 3DES");
114 return "";
115 case 112:
116 case 168:
117 return "CMAC(TripleDES)";
118 default:
119 break;
120 }
121
122 ERROR_MSG("Invalid DES bit len %i", currentKey->getBitLen());
123
124 return "";
125 }
126
127 size_t BotanCMACDES::getMacSize() const
128 {
129 return 8;
130 }
131
132 std::string BotanCMACAES::getAlgorithm() const
133 {
134 switch(currentKey->getBitLen())
135 {
136 case 128:
137 return "CMAC(AES-128)";
138 case 192:
139 return "CMAC(AES-192)";
140 case 256:
141 return "CMAC(AES-256)";
142 default:
143 break;
144 }
145
146 ERROR_MSG("Invalid AES bit len %i", currentKey->getBitLen());
147
148 return "";
149 }
150
151 size_t BotanCMACAES::getMacSize() const
152 {
153 return 16;
154 }