2 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
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/>.
24 gcrypt_to_cipher (int n
)
26 if (n
== GCRY_CIPHER_AES128
)
27 return PWMD_CIPHER_AES128
;
28 else if (n
== GCRY_CIPHER_AES192
)
29 return PWMD_CIPHER_AES192
;
30 else if (n
== GCRY_CIPHER_AES256
)
31 return PWMD_CIPHER_AES256
;
32 else if (n
== GCRY_CIPHER_SERPENT128
)
33 return PWMD_CIPHER_SERPENT128
;
34 else if (n
== GCRY_CIPHER_SERPENT192
)
35 return PWMD_CIPHER_SERPENT192
;
36 else if (n
== GCRY_CIPHER_SERPENT256
)
37 return PWMD_CIPHER_SERPENT256
;
38 else if (n
== GCRY_CIPHER_CAMELLIA128
)
39 return PWMD_CIPHER_CAMELLIA128
;
40 else if (n
== GCRY_CIPHER_CAMELLIA192
)
41 return PWMD_CIPHER_CAMELLIA192
;
42 else if (n
== GCRY_CIPHER_CAMELLIA256
)
43 return PWMD_CIPHER_CAMELLIA256
;
44 else if (n
== GCRY_CIPHER_BLOWFISH
)
45 return PWMD_CIPHER_BLOWFISH
;
46 else if (n
== GCRY_CIPHER_3DES
)
47 return PWMD_CIPHER_3DES
;
48 else if (n
== GCRY_CIPHER_CAST5
)
49 return PWMD_CIPHER_CAST5
;
50 else if (n
== GCRY_CIPHER_TWOFISH
)
51 return PWMD_CIPHER_TWOFISH
;
52 else if (n
== GCRY_CIPHER_TWOFISH128
)
53 return PWMD_CIPHER_TWOFISH128
;
55 return PWMD_CIPHER_AES256
;
59 cipher_to_gcrypt (int flags
)
64 if (flags
& PWMD_CIPHER_AES128
)
65 return GCRY_CIPHER_AES128
;
66 else if (flags
& PWMD_CIPHER_AES192
)
67 return GCRY_CIPHER_AES192
;
68 else if (flags
& PWMD_CIPHER_AES256
)
69 return GCRY_CIPHER_AES256
;
70 else if (flags
& PWMD_CIPHER_SERPENT128
)
71 return GCRY_CIPHER_SERPENT128
;
72 else if (flags
& PWMD_CIPHER_SERPENT192
)
73 return GCRY_CIPHER_SERPENT192
;
74 else if (flags
& PWMD_CIPHER_SERPENT256
)
75 return GCRY_CIPHER_SERPENT256
;
76 else if (flags
& PWMD_CIPHER_CAMELLIA128
)
77 return GCRY_CIPHER_CAMELLIA128
;
78 else if (flags
& PWMD_CIPHER_CAMELLIA192
)
79 return GCRY_CIPHER_CAMELLIA192
;
80 else if (flags
& PWMD_CIPHER_CAMELLIA256
)
81 return GCRY_CIPHER_CAMELLIA256
;
82 else if (flags
& PWMD_CIPHER_BLOWFISH
)
83 return GCRY_CIPHER_BLOWFISH
;
84 else if (flags
& PWMD_CIPHER_3DES
)
85 return GCRY_CIPHER_3DES
;
86 else if (flags
& PWMD_CIPHER_CAST5
)
87 return GCRY_CIPHER_CAST5
;
88 else if (flags
& PWMD_CIPHER_TWOFISH
)
89 return GCRY_CIPHER_TWOFISH
;
90 else if (flags
& PWMD_CIPHER_TWOFISH128
)
91 return GCRY_CIPHER_TWOFISH128
;
97 cipher_string_to_cipher (const char *str
)
101 if (!strcasecmp (str
, "aes128"))
102 flags
= PWMD_CIPHER_AES128
;
103 else if (!strcasecmp (str
, "aes192"))
104 flags
= PWMD_CIPHER_AES192
;
105 else if (!strcasecmp (str
, "aes256"))
106 flags
= PWMD_CIPHER_AES256
;
107 else if (!strcasecmp (str
, "serpent128"))
108 flags
= PWMD_CIPHER_SERPENT128
;
109 else if (!strcasecmp (str
, "serpent192"))
110 flags
= PWMD_CIPHER_SERPENT192
;
111 else if (!strcasecmp (str
, "serpent256"))
112 flags
= PWMD_CIPHER_SERPENT256
;
113 else if (!strcasecmp (str
, "camellia128"))
114 flags
= PWMD_CIPHER_CAMELLIA128
;
115 else if (!strcasecmp (str
, "camellia192"))
116 flags
= PWMD_CIPHER_CAMELLIA192
;
117 else if (!strcasecmp (str
, "camellia256"))
118 flags
= PWMD_CIPHER_CAMELLIA256
;
119 else if (!strcasecmp (str
, "blowfish"))
120 flags
= PWMD_CIPHER_BLOWFISH
;
121 else if (!strcasecmp (str
, "cast5"))
122 flags
= PWMD_CIPHER_CAST5
;
123 else if (!strcasecmp (str
, "3des"))
124 flags
= PWMD_CIPHER_3DES
;
125 else if (!strcasecmp (str
, "twofish256"))
126 flags
= PWMD_CIPHER_TWOFISH
;
127 else if (!strcasecmp (str
, "twofish128"))
128 flags
= PWMD_CIPHER_TWOFISH128
;
136 cipher_string_to_gcrypt (const char *str
)
138 return cipher_to_gcrypt (cipher_string_to_cipher (str
));
142 set_cipher_flag (uint64_t flags
, int algo
)
144 // Clear all previous cipher bits but keep the flags.
145 flags
&= ~((uint16_t) ((uint32_t) (flags
& 0xFFFFFFFF)));
146 flags
|= gcrypt_to_cipher (algo
);