~ubuntu-branches/ubuntu/natty/curl/natty-security

« back to all changes in this revision

Viewing changes to lib/md5.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2010-06-20 13:56:28 UTC
  • mfrom: (3.4.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100620135628-e30tp9jldq6hq985
Tags: 7.21.0-1ubuntu1
* Merge from debian unstable.  Remaining changes: LP: #596334
  - Keep build deps in main:
    - Drop build dependencies: stunnel, libssh2-1-dev
    - Add build-dependency on openssh-server
    - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
 
8
 * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
9
9
 *
10
10
 * This software is licensed as described in the file COPYING, which
11
11
 * you should have received as part of this distribution. The terms
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: md5.c,v 1.15 2009-02-12 20:48:44 danf Exp $
22
21
 ***************************************************************************/
23
22
 
24
23
#include "setup.h"
28
27
#include <string.h>
29
28
 
30
29
#include "curl_md5.h"
 
30
#include "curl_hmac.h"
31
31
 
32
32
#ifdef USE_GNUTLS
33
33
 
34
34
#include <gcrypt.h>
35
35
 
36
 
void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
37
 
                const unsigned char *input)
38
 
{
39
 
  gcry_md_hd_t ctx;
40
 
  gcry_md_open(&ctx, GCRY_MD_MD5, 0);
41
 
  gcry_md_write(ctx, input, (unsigned int)strlen((char *)input));
42
 
  memcpy (outbuffer, gcry_md_read (ctx, 0), 16);
43
 
  gcry_md_close(ctx);
 
36
typedef gcry_md_hd_t MD5_CTX;
 
37
 
 
38
static void MD5_Init(MD5_CTX * ctx)
 
39
{
 
40
  gcry_md_open(ctx, GCRY_MD_MD5, 0);
 
41
}
 
42
 
 
43
static void MD5_Update(MD5_CTX * ctx,
 
44
                       const unsigned char * input,
 
45
                       unsigned int inputLen)
 
46
{
 
47
  gcry_md_write(*ctx, input, inputLen);
 
48
}
 
49
 
 
50
static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
 
51
{
 
52
  memcpy(digest, gcry_md_read(*ctx, 0), 16);
 
53
  gcry_md_close(*ctx);
44
54
}
45
55
 
46
56
#else
359
369
 
360
370
#endif /* USE_SSLEAY */
361
371
 
 
372
#endif /* USE_GNUTLS */
 
373
 
 
374
const HMAC_params Curl_HMAC_MD5[] = {
 
375
  {
 
376
    (HMAC_hinit_func) MD5_Init,           /* Hash initialization function. */
 
377
    (HMAC_hupdate_func) MD5_Update,       /* Hash update function. */
 
378
    (HMAC_hfinal_func) MD5_Final,         /* Hash computation end function. */
 
379
    sizeof(MD5_CTX),                      /* Size of hash context structure. */
 
380
    64,                                   /* Maximum key length. */
 
381
    16                                    /* Result size. */
 
382
  }
 
383
};
 
384
 
 
385
 
362
386
void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
363
387
                const unsigned char *input)
364
388
{
368
392
  MD5_Final(outbuffer, &ctx);
369
393
}
370
394
 
371
 
#endif /* USE_GNUTLS */
372
 
 
373
395
#endif /* CURL_DISABLE_CRYPTO_AUTH */