1 /* crypto-md.c DES crypto functions
2 * Copyright (C) 2002, 2003 Simon Josefsson
3 * Copyright (C) 2003 Nicolas Pouvesle
5 * This file is part of Shishi.
7 * Shishi 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 * Shishi 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 Shishi; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Note: This file is #include'd by crypto.c.
26 md4_checksum (Shishi
* handle
,
30 const char *in
, size_t inlen
, char **out
, size_t * outlen
)
36 gcry_md_open (&hd
, GCRY_MD_MD4
, 0);
38 return SHISHI_CRYPTO_INTERNAL_ERROR
;
40 gcry_md_write (hd
, in
, inlen
);
41 hash
= gcry_md_read (hd
, GCRY_MD_MD4
);
44 shishi_error_printf (handle
, "Libgcrypt failed to compute hash");
45 return SHISHI_CRYPTO_INTERNAL_ERROR
;
48 *outlen
= gcry_md_get_algo_dlen (GCRY_MD_MD4
);
49 *out
= xmemdup (*out
, hash
, *outlen
);
54 char digest
[MD4_DIGEST_SIZE
];
58 md4_update (&md4
, inlen
, in
);
59 md4_digest (&md4
, sizeof (digest
), digest
);
61 *outlen
= MD4_DIGEST_SIZE
;
62 *out
= xmemdup (*out
, digest
, *outlen
);
68 md5_checksum (Shishi
* handle
,
72 const char *in
, size_t inlen
, char **out
, size_t * outlen
)
78 gcry_md_open (&hd
, GCRY_MD_MD5
, 0);
80 return SHISHI_CRYPTO_INTERNAL_ERROR
;
82 gcry_md_write (hd
, in
, inlen
);
83 hash
= gcry_md_read (hd
, GCRY_MD_MD5
);
86 shishi_error_printf (handle
, "Libgcrypt failed to compute hash");
87 return SHISHI_CRYPTO_INTERNAL_ERROR
;
90 *outlen
= gcry_md_get_algo_dlen (GCRY_MD_MD5
);
91 *out
= xmemdup (*out
, hash
, *outlen
);
96 char digest
[MD5_DIGEST_SIZE
];
99 md5_update (&md5
, inlen
, in
);
100 md5_digest (&md5
, sizeof (digest
), digest
);
102 *outlen
= MD5_DIGEST_SIZE
;
103 *out
= xmemdup (*out
, digest
, *outlen
);