]>
git.saurik.com Git - apple/security.git/blob - AppleCSP/PBKDF2/pbkdDigest.cpp
2 * Copyright (c) 2003 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please
7 * obtain a copy of the License at http://www.apple.com/publicsource and
8 * read it before using this file.
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
12 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
13 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
15 * Please see the License for the specific language governing rights and
16 * limitations under the License.
19 * pbkdDigest.cpp - SHA1/MD5 digest object for HMAC and PBE routines
22 #include "pbkdDigest.h"
23 #include <Security/cssmerr.h>
26 /* Ops on a DigestCtx */
27 /* Note caller has to memset(0) the DigestCtx before using */
28 CSSM_RETURN
DigestCtxInit(
33 if(ctx
->dig
.sha1Context
== NULL
) {
34 ctx
->dig
.sha1Context
= sha1Alloc();
35 if(ctx
->dig
.sha1Context
== NULL
) {
36 return CSSMERR_CSP_MEMORY_ERROR
;
40 sha1Reinit(ctx
->dig
.sha1Context
);
44 MD5Init(&ctx
->dig
.md5Context
);
54 sha1Free(ctx
->dig
.sha1Context
);
56 memset(ctx
, 0, sizeof(DigestCtx
));
65 sha1AddData(ctx
->dig
.sha1Context
, (unsigned char *)textPtr
, textLen
);
68 MD5Update(&ctx
->dig
.md5Context
, (unsigned char *)textPtr
, textLen
);
77 sha1GetDigest(ctx
->dig
.sha1Context
, (unsigned char *)digest
);
80 MD5Final(&ctx
->dig
.md5Context
, (unsigned char *)digest
);