2 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2007, 2008, 2009,
3 * 2010 Free Software Foundation, Inc.
7 * This file is part of OpenCDK.
9 * The OpenCDK library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
36 #include "../random.h"
40 _cdk_buftou32 (const byte * buf)
55 _cdk_u32tobuf (u32 u, byte * buf)
67 * @sl: the string list
69 * Release the string list object.
72 cdk_strlist_free (cdk_strlist_t sl)
86 * @list: destination string list
87 * @string: the string to add
89 * Add the given list to the string list.
92 cdk_strlist_add (cdk_strlist_t * list, const char *string)
99 sl = cdk_calloc (1, sizeof *sl + strlen (string) + 2);
102 sl->d = (char *) sl + sizeof (*sl);
103 strcpy (sl->d, string);
110 _cdk_memistr (const char *buf, size_t buflen, const char *sub)
115 for (t = (byte *) buf, n = buflen, s = (byte *) sub; n; t++, n--)
117 if (c_toupper (*t) == c_toupper (*s))
119 for (buf = t++, buflen = n--, s++;
120 n && c_toupper (*t) == c_toupper ((byte) * s); t++, s++, n--)
134 _cdk_map_gnutls_error (int err)
140 case GNUTLS_E_INVALID_REQUEST:
141 return CDK_Inv_Value;
143 return CDK_General_Error;
148 /* Remove all trailing white spaces from the string. */
150 _cdk_trim_string (char *s)
154 (s[len - 1] == '\t' ||
155 s[len - 1] == '\r' ||
156 s[len - 1] == '\n' || s[len - 1] == ' '))
162 _cdk_check_args (int overwrite, const char *in, const char *out)
167 return CDK_Inv_Value;
168 if (strlen (in) == strlen (out) && strcmp (in, out) == 0)
170 if (!overwrite && !stat (out, &stbuf))
182 /* Because the tmpfile() version of wine is not really useful,
183 we implement our own version to avoid problems with 'make check'. */
184 static const char *letters = "abcdefghijklmnopqrstuvwxyz";
185 char buf[512], rnd[24];
189 _gnutls_rnd (GNUTLS_RND_NONCE, rnd, DIM (rnd));
190 for (i = 0; i < DIM (rnd) - 1; i++)
192 char c = letters[(unsigned char) rnd[i] % 26];
195 rnd[DIM (rnd) - 1] = 0;
196 if (!GetTempPath (464, buf))
198 strcat (buf, "_cdk_");
201 /* We need to make sure the file will be deleted when it is closed. */
202 fd = _open (buf, _O_CREAT | _O_EXCL | _O_TEMPORARY |
203 _O_RDWR | _O_BINARY, _S_IREAD | _S_IWRITE);
206 fp = fdopen (fd, "w+b");
221 _gnutls_hash_algo_to_pgp (int algo)
229 case GNUTLS_DIG_SHA1:
231 case GNUTLS_DIG_RMD160:
233 case GNUTLS_DIG_SHA256:
235 case GNUTLS_DIG_SHA384:
237 case GNUTLS_DIG_SHA512:
239 case GNUTLS_DIG_SHA224:
248 _pgp_hash_algo_to_gnutls (int algo)
253 return GNUTLS_DIG_MD5;
255 return GNUTLS_DIG_SHA1;
257 return GNUTLS_DIG_RMD160;
259 return GNUTLS_DIG_MD2;
261 return GNUTLS_DIG_SHA256;
263 return GNUTLS_DIG_SHA384;
265 return GNUTLS_DIG_SHA512;
267 return GNUTLS_DIG_SHA224;
270 return GNUTLS_DIG_NULL;
275 _pgp_cipher_to_gnutls (int cipher)
280 return GNUTLS_CIPHER_IDEA_PGP_CFB;
282 return GNUTLS_CIPHER_3DES_PGP_CFB;
284 return GNUTLS_CIPHER_CAST5_PGP_CFB;
286 return GNUTLS_CIPHER_BLOWFISH_PGP_CFB;
288 return GNUTLS_CIPHER_SAFER_SK128_PGP_CFB;
290 return GNUTLS_CIPHER_AES128_PGP_CFB;
292 return GNUTLS_CIPHER_AES192_PGP_CFB;
294 return GNUTLS_CIPHER_AES256_PGP_CFB;
296 return GNUTLS_CIPHER_TWOFISH_PGP_CFB;
300 return GNUTLS_CIPHER_NULL;
305 _gnutls_cipher_to_pgp (int cipher)
310 case GNUTLS_CIPHER_IDEA_PGP_CFB:
312 case GNUTLS_CIPHER_3DES_PGP_CFB:
314 case GNUTLS_CIPHER_CAST5_PGP_CFB:
316 case GNUTLS_CIPHER_BLOWFISH_PGP_CFB:
318 case GNUTLS_CIPHER_SAFER_SK128_PGP_CFB:
320 case GNUTLS_CIPHER_AES128_PGP_CFB:
322 case GNUTLS_CIPHER_AES192_PGP_CFB:
324 case GNUTLS_CIPHER_AES256_PGP_CFB:
326 case GNUTLS_CIPHER_TWOFISH_PGP_CFB: