~ubuntu-branches/ubuntu/oneiric/gnutls26/oneiric

« back to all changes in this revision

Viewing changes to lib/gnutls_hash_int.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2008 Free Software Foundation
 
2
 * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free Software
 
3
 * Foundation, Inc.
3
4
 *
4
5
 * Author: Nikos Mavrogiannopoulos
5
6
 *
6
 
 * This file is part of GNUTLS.
 
7
 * This file is part of GnuTLS.
7
8
 *
8
 
 * The GNUTLS library is free software; you can redistribute it and/or
 
9
 * The GnuTLS is free software; you can redistribute it and/or
9
10
 * modify it under the terms of the GNU Lesser General Public License
10
11
 * as published by the Free Software Foundation; either version 2.1 of
11
12
 * the License, or (at your option) any later version.
61
62
_gnutls_hash_init (digest_hd_st * dig, gnutls_digest_algorithm_t algorithm)
62
63
{
63
64
  int result;
64
 
  gnutls_crypto_single_digest_st *cc = NULL;
 
65
  const gnutls_crypto_digest_st *cc = NULL;
65
66
 
66
67
  dig->algorithm = algorithm;
67
68
 
72
73
    {
73
74
      dig->registered = 1;
74
75
      dig->hd.rh.cc = cc;
75
 
      if (cc->init (&dig->hd.rh.ctx) < 0)
 
76
      if (cc->init (algorithm, &dig->hd.rh.ctx) < 0)
76
77
        {
77
78
          gnutls_assert ();
78
79
          return GNUTLS_E_HASH_FAILED;
79
80
        }
 
81
      dig->active = 1;
80
82
      return 0;
81
83
    }
82
84
 
89
91
      return result;
90
92
    }
91
93
 
 
94
  dig->active = 1;
92
95
  return 0;
93
96
}
94
97
 
101
104
}
102
105
 
103
106
int
104
 
_gnutls_hash (const digest_hd_st * handle, const void *text, size_t textlen)
 
107
_gnutls_hash (digest_hd_st * handle, const void *text, size_t textlen)
105
108
{
106
109
  if (textlen > 0)
107
110
    {
119
122
{
120
123
  int result;
121
124
 
 
125
  memset (dst, 0, sizeof (*dst));
122
126
  dst->algorithm = src->algorithm;
123
 
  dst->key = NULL;              /* it's a hash anyway */
124
 
  dst->keysize = 0;
125
127
  dst->registered = src->registered;
 
128
  dst->active = 1;
126
129
 
127
130
  if (src->registered)
128
131
    {
165
168
void
166
169
_gnutls_hash_deinit (digest_hd_st * handle, void *digest)
167
170
{
168
 
  _gnutls_hash_output (handle, digest);
 
171
  if (handle->active != 1)
 
172
    {
 
173
      return;
 
174
    }
 
175
 
 
176
  if (digest != NULL)
 
177
    _gnutls_hash_output (handle, digest);
 
178
 
 
179
  handle->active = 0;
169
180
 
170
181
  if (handle->registered && handle->hd.rh.ctx != NULL)
171
182
    {
242
253
                   const void *key, int keylen)
243
254
{
244
255
  int result;
245
 
  gnutls_crypto_single_mac_st *cc = NULL;
 
256
  const gnutls_crypto_mac_st *cc = NULL;
246
257
 
247
258
  dig->algorithm = algorithm;
248
259
  dig->key = key;
256
267
      dig->registered = 1;
257
268
 
258
269
      dig->hd.rh.cc = cc;
259
 
      if (cc->init (&dig->hd.rh.ctx) < 0)
 
270
      if (cc->init (algorithm, &dig->hd.rh.ctx) < 0)
260
271
        {
261
272
          gnutls_assert ();
262
273
          return GNUTLS_E_HASH_FAILED;
269
280
          return GNUTLS_E_HASH_FAILED;
270
281
        }
271
282
 
 
283
      dig->active = 1;
272
284
      return 0;
273
285
    }
274
286
 
283
295
 
284
296
  _gnutls_mac_ops.setkey (dig->hd.gc, key, keylen);
285
297
 
 
298
  dig->active = 1;
286
299
  return 0;
287
300
}
288
301
 
289
302
int
290
 
_gnutls_hmac (const digest_hd_st * handle, const void *text, size_t textlen)
 
303
_gnutls_hmac (digest_hd_st * handle, const void *text, size_t textlen)
291
304
{
292
305
  if (textlen > 0)
293
306
    {
323
336
void
324
337
_gnutls_hmac_deinit (digest_hd_st * handle, void *digest)
325
338
{
326
 
  _gnutls_hmac_output (handle, digest);
327
 
 
 
339
  if (handle->active != 1)
 
340
    {
 
341
      return;
 
342
    }
 
343
 
 
344
  if (digest)
 
345
    _gnutls_hmac_output (handle, digest);
 
346
 
 
347
  handle->active = 0;
328
348
  if (handle->registered && handle->hd.rh.ctx != NULL)
329
349
    {
330
350
      handle->hd.rh.cc->deinit (handle->hd.rh.ctx);
398
418
  if (padsize == 0)
399
419
    {
400
420
      gnutls_assert ();
 
421
      _gnutls_hash_deinit (handle, NULL);
401
422
      return;
402
423
    }
403
424
 
407
428
  if (rc < 0)
408
429
    {
409
430
      gnutls_assert ();
 
431
      _gnutls_hash_deinit (handle, NULL);
410
432
      return;
411
433
    }
412
434