]>
Commit | Line | Data |
---|---|---|
b1ab9ed8 | 1 | /* |
d8f41ccd | 2 | * Copyright (c) 2003-2005 Apple Computer, Inc. All Rights Reserved. |
b1ab9ed8 A |
3 | * |
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. | |
9 | * | |
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. | |
17 | */ | |
18 | /* | |
d8f41ccd | 19 | * pbkdDigest.cpp - SHA1/MD5 digest object |
b1ab9ed8 A |
20 | */ |
21 | ||
22 | #include "pbkdDigest.h" | |
23 | #include <Security/cssmerr.h> | |
24 | #include <string.h> | |
25 | ||
26 | /* the casts are necessary to cover the polymorphous context types */ | |
b1ab9ed8 | 27 | DigestOps Md5Ops = { |
d8f41ccd A |
28 | (DigestInitFcn)MD5_Init, |
29 | (DigestUpdateFcn)MD5_Update, | |
30 | (DigestFinalFcn)MD5_Final | |
b1ab9ed8 A |
31 | }; |
32 | DigestOps Sha1Ops = { | |
d8f41ccd A |
33 | (DigestInitFcn)SHA1_Init, |
34 | (DigestUpdateFcn)SHA1_Update, | |
35 | (DigestFinalFcn)SHA1_Final | |
b1ab9ed8 A |
36 | }; |
37 | ||
d8f41ccd | 38 | /* Ops on a DigestCtx */ |
b1ab9ed8 A |
39 | int DigestCtxInit( |
40 | DigestCtx *ctx, | |
d8f41ccd | 41 | CSSM_BOOL isSha1) |
b1ab9ed8 | 42 | { |
d8f41ccd A |
43 | if(isSha1) { |
44 | ctx->ops = &Sha1Ops; | |
45 | } | |
46 | else { | |
47 | ctx->ops = &Md5Ops; | |
b1ab9ed8 | 48 | } |
d8f41ccd | 49 | ctx->isSha1 = isSha1; |
b1ab9ed8 A |
50 | return ctx->ops->init(&ctx->dig); |
51 | } | |
52 | ||
53 | void DigestCtxFree( | |
54 | DigestCtx *ctx) | |
55 | { | |
56 | memset(ctx, 0, sizeof(DigestCtx)); | |
57 | } | |
58 | ||
59 | int DigestCtxUpdate( | |
60 | DigestCtx *ctx, | |
61 | const void *textPtr, | |
62 | uint32 textLen) | |
63 | { | |
64 | return ctx->ops->update(&ctx->dig, textPtr, textLen); | |
65 | } | |
66 | ||
67 | int DigestCtxFinal( | |
68 | DigestCtx *ctx, | |
69 | void *digest) | |
70 | { | |
71 | return ctx->ops->final(digest, &ctx->dig); | |
72 | } |