2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3 Ben Kibbey <bjk@luxsci.net>
5 This file is part of pwmd.
7 Pwmd is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 2 of the License, or
10 (at your option) any later version.
12 Pwmd is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
34 gcrypt_to_cipher (int n
)
36 if (n
== GCRY_CIPHER_AES128
)
37 return PWMD_CIPHER_AES128
;
38 else if (n
== GCRY_CIPHER_AES192
)
39 return PWMD_CIPHER_AES192
;
40 else if (n
== GCRY_CIPHER_AES256
)
41 return PWMD_CIPHER_AES256
;
42 else if (n
== GCRY_CIPHER_SERPENT128
)
43 return PWMD_CIPHER_SERPENT128
;
44 else if (n
== GCRY_CIPHER_SERPENT192
)
45 return PWMD_CIPHER_SERPENT192
;
46 else if (n
== GCRY_CIPHER_SERPENT256
)
47 return PWMD_CIPHER_SERPENT256
;
48 else if (n
== GCRY_CIPHER_CAMELLIA128
)
49 return PWMD_CIPHER_CAMELLIA128
;
50 else if (n
== GCRY_CIPHER_CAMELLIA192
)
51 return PWMD_CIPHER_CAMELLIA192
;
52 else if (n
== GCRY_CIPHER_CAMELLIA256
)
53 return PWMD_CIPHER_CAMELLIA256
;
54 else if (n
== GCRY_CIPHER_BLOWFISH
)
55 return PWMD_CIPHER_BLOWFISH
;
56 else if (n
== GCRY_CIPHER_3DES
)
57 return PWMD_CIPHER_3DES
;
58 else if (n
== GCRY_CIPHER_CAST5
)
59 return PWMD_CIPHER_CAST5
;
60 else if (n
== GCRY_CIPHER_TWOFISH
)
61 return PWMD_CIPHER_TWOFISH
;
62 else if (n
== GCRY_CIPHER_TWOFISH128
)
63 return PWMD_CIPHER_TWOFISH128
;
65 return PWMD_CIPHER_AES256
;
69 cipher_to_gcrypt (int flags
)
74 if (flags
& PWMD_CIPHER_AES128
)
75 return GCRY_CIPHER_AES128
;
76 else if (flags
& PWMD_CIPHER_AES192
)
77 return GCRY_CIPHER_AES192
;
78 else if (flags
& PWMD_CIPHER_AES256
)
79 return GCRY_CIPHER_AES256
;
80 else if (flags
& PWMD_CIPHER_SERPENT128
)
81 return GCRY_CIPHER_SERPENT128
;
82 else if (flags
& PWMD_CIPHER_SERPENT192
)
83 return GCRY_CIPHER_SERPENT192
;
84 else if (flags
& PWMD_CIPHER_SERPENT256
)
85 return GCRY_CIPHER_SERPENT256
;
86 else if (flags
& PWMD_CIPHER_CAMELLIA128
)
87 return GCRY_CIPHER_CAMELLIA128
;
88 else if (flags
& PWMD_CIPHER_CAMELLIA192
)
89 return GCRY_CIPHER_CAMELLIA192
;
90 else if (flags
& PWMD_CIPHER_CAMELLIA256
)
91 return GCRY_CIPHER_CAMELLIA256
;
92 else if (flags
& PWMD_CIPHER_BLOWFISH
)
93 return GCRY_CIPHER_BLOWFISH
;
94 else if (flags
& PWMD_CIPHER_3DES
)
95 return GCRY_CIPHER_3DES
;
96 else if (flags
& PWMD_CIPHER_CAST5
)
97 return GCRY_CIPHER_CAST5
;
98 else if (flags
& PWMD_CIPHER_TWOFISH
)
99 return GCRY_CIPHER_TWOFISH
;
100 else if (flags
& PWMD_CIPHER_TWOFISH128
)
101 return GCRY_CIPHER_TWOFISH128
;
107 cipher_string_to_cipher (const char *str
)
111 if (!strcasecmp (str
, "aes128"))
112 flags
= PWMD_CIPHER_AES128
;
113 else if (!strcasecmp (str
, "aes192"))
114 flags
= PWMD_CIPHER_AES192
;
115 else if (!strcasecmp (str
, "aes256"))
116 flags
= PWMD_CIPHER_AES256
;
117 else if (!strcasecmp (str
, "serpent128"))
118 flags
= PWMD_CIPHER_SERPENT128
;
119 else if (!strcasecmp (str
, "serpent192"))
120 flags
= PWMD_CIPHER_SERPENT192
;
121 else if (!strcasecmp (str
, "serpent256"))
122 flags
= PWMD_CIPHER_SERPENT256
;
123 else if (!strcasecmp (str
, "camellia128"))
124 flags
= PWMD_CIPHER_CAMELLIA128
;
125 else if (!strcasecmp (str
, "camellia192"))
126 flags
= PWMD_CIPHER_CAMELLIA192
;
127 else if (!strcasecmp (str
, "camellia256"))
128 flags
= PWMD_CIPHER_CAMELLIA256
;
129 else if (!strcasecmp (str
, "blowfish"))
130 flags
= PWMD_CIPHER_BLOWFISH
;
131 else if (!strcasecmp (str
, "cast5"))
132 flags
= PWMD_CIPHER_CAST5
;
133 else if (!strcasecmp (str
, "3des"))
134 flags
= PWMD_CIPHER_3DES
;
135 else if (!strcasecmp (str
, "twofish256"))
136 flags
= PWMD_CIPHER_TWOFISH
;
137 else if (!strcasecmp (str
, "twofish128"))
138 flags
= PWMD_CIPHER_TWOFISH128
;
146 cipher_string_to_gcrypt (const char *str
)
148 return cipher_to_gcrypt (cipher_string_to_cipher (str
));
152 set_cipher_flag (uint64_t flags
, int algo
)
154 // Clear all previous cipher bits but keep the flags.
155 flags
&= ~((uint16_t) ((uint32_t) (flags
& 0xFFFFFFFF)));
156 flags
|= gcrypt_to_cipher (algo
);