1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
/* lib/crypto/nss/sha1/shs.c
4
* Copyright (c) 2010 Red Hat, Inc.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
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.
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.
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.
41
/* Initialize the SHS values */
42
void shsInit(SHS_INFO *shsInfo)
45
shsInfo->nss_ctxt = NULL;
48
shsInfo->nss_ctxt = PK11_CreateDigestContext(SEC_OID_SHA1);
49
if (shsInfo->nss_ctxt == NULL)
51
PK11_DigestBegin((PK11Context *)shsInfo->nss_ctxt);
54
/* Update SHS for a block of data */
55
void shsUpdate(SHS_INFO *shsInfo, const SHS_BYTE *buffer, unsigned int count)
57
if (shsInfo->nss_ctxt == NULL)
59
PK11_DigestOp((PK11Context *)shsInfo->nss_ctxt, buffer, count);
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)
67
if (shsInfo->nss_ctxt == NULL)
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
75
PK11_DestroyContext((PK11Context *)shsInfo->nss_ctxt, PR_TRUE);
76
shsInfo->nss_ctxt = NULL;