~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/lib/crypto/nss/sha1/shs.c

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
 
/* lib/crypto/nss/sha1/shs.c
3
 
 *
4
 
 * Copyright (c) 2010 Red Hat, Inc.
5
 
 * All Rights Reserved.
6
 
 *
7
 
 * Redistribution and use in source and binary forms, with or without
8
 
 * modification, are permitted provided that the following conditions
9
 
 * are met:
10
 
 *
11
 
 *  * Redistributions of source code must retain the above copyright
12
 
 *    notice, this list of conditions and the following disclaimer.
13
 
 *
14
 
 *  * Redistributions in binary form must reproduce the above
15
 
 *    copyright notice, this list of conditions and the following
16
 
 *    disclaimer in the documentation and/or other materials provided
17
 
 *    with the distribution.
18
 
 *
19
 
 *  * Neither the name of Red Hat, Inc., nor the names of its
20
 
 *    contributors may be used to endorse or promote products derived
21
 
 *    from this software without specific prior written permission.
22
 
 *
23
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
 
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
 
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
 
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
 
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
 
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
 
 */
35
 
 
36
 
#include "k5-int.h"
37
 
#include "shs.h"
38
 
#include "pk11pub.h"
39
 
#include "nss_gen.h"
40
 
 
41
 
/* Initialize the SHS values */
42
 
void shsInit(SHS_INFO *shsInfo)
43
 
{
44
 
    if (k5_nss_init()) {
45
 
        shsInfo->nss_ctxt = NULL;
46
 
        return;
47
 
    }
48
 
    shsInfo->nss_ctxt = PK11_CreateDigestContext(SEC_OID_SHA1);
49
 
    if (shsInfo->nss_ctxt == NULL)
50
 
        return;
51
 
    PK11_DigestBegin((PK11Context *)shsInfo->nss_ctxt);
52
 
}
53
 
 
54
 
/* Update SHS for a block of data */
55
 
void shsUpdate(SHS_INFO *shsInfo, const SHS_BYTE *buffer, unsigned int count)
56
 
{
57
 
    if (shsInfo->nss_ctxt == NULL)
58
 
        return;
59
 
    PK11_DigestOp((PK11Context *)shsInfo->nss_ctxt, buffer, count);
60
 
}
61
 
 
62
 
 
63
 
/* Final wrapup - pad to SHS_DATASIZE-byte boundary with the bit pattern
64
 
 * 1 0* (64-bit count of bits processed, MSB-first) */
65
 
void shsFinal(SHS_INFO *shsInfo)
66
 
{
67
 
   if (shsInfo->nss_ctxt == NULL)
68
 
        return;
69
 
   PK11_DigestFinal((PK11Context *)shsInfo->nss_ctxt, shsInfo->digestBuf,
70
 
                    &shsInfo->digestLen, sizeof (shsInfo->digestBuf));
71
 
   /* Since there is not separate cleanup step, free the context now.
72
 
    * (otherwise we could have reused the context for another MD5 operation
73
 
    * in the future).
74
 
    */
75
 
   PK11_DestroyContext((PK11Context *)shsInfo->nss_ctxt, PR_TRUE);
76
 
   shsInfo->nss_ctxt = NULL;
77
 
}