]> git.saurik.com Git - apple/security.git/blob - libsecurity_apple_csp/lib/SHA2_Object.cpp
Security-55163.44.tar.gz
[apple/security.git] / libsecurity_apple_csp / lib / SHA2_Object.cpp
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 /*
26 * SHA2_Object.cpp - SHA2 digest objects
27 * Created 8/12/2004 by dmitch.
28 * Created 2/19/2001 by dmitch.
29 */
30
31 #include "SHA2_Object.h"
32 #include <stdexcept>
33 #include <string.h>
34
35 /***
36 *** SHA224
37 ***/
38 void SHA224Object::digestInit()
39 {
40 mIsDone = false;
41 CC_SHA224_Init(&mCtx);
42 }
43
44 void SHA224Object::digestUpdate(
45 const void *data,
46 size_t len)
47 {
48 CC_SHA224_Update(&mCtx, (const unsigned char *)data, len);
49 }
50
51 void SHA224Object::digestFinal(
52 void *digest)
53 {
54 CC_SHA224_Final((unsigned char *)digest, &mCtx);
55 mIsDone = true;
56 }
57
58 /* use default memberwise init */
59 DigestObject *SHA224Object::digestClone() const
60 {
61 return new SHA224Object(*this);
62 }
63
64 size_t SHA224Object::digestSizeInBytes() const
65 {
66 return CC_SHA224_DIGEST_LENGTH;
67 }
68
69 /***
70 *** SHA256
71 ***/
72 void SHA256Object::digestInit()
73 {
74 mIsDone = false;
75 CC_SHA256_Init(&mCtx);
76 }
77
78 void SHA256Object::digestUpdate(
79 const void *data,
80 size_t len)
81 {
82 CC_SHA256_Update(&mCtx, (const unsigned char *)data, len);
83 }
84
85 void SHA256Object::digestFinal(
86 void *digest)
87 {
88 CC_SHA256_Final((unsigned char *)digest, &mCtx);
89 mIsDone = true;
90 }
91
92 /* use default memberwise init */
93 DigestObject *SHA256Object::digestClone() const
94 {
95 return new SHA256Object(*this);
96 }
97
98 size_t SHA256Object::digestSizeInBytes() const
99 {
100 return CC_SHA256_DIGEST_LENGTH;
101 }
102
103 /***
104 *** SHA384
105 ***/
106 void SHA384Object::digestInit()
107 {
108 mIsDone = false;
109 CC_SHA384_Init(&mCtx);
110 }
111
112 void SHA384Object::digestUpdate(
113 const void *data,
114 size_t len)
115 {
116 CC_SHA384_Update(&mCtx, (const unsigned char *)data, len);
117 }
118
119 void SHA384Object::digestFinal(
120 void *digest)
121 {
122 CC_SHA384_Final((unsigned char *)digest, &mCtx);
123 mIsDone = true;
124 }
125
126 /* use default memberwise init */
127 DigestObject *SHA384Object::digestClone() const
128 {
129 return new SHA384Object(*this);
130 }
131
132 size_t SHA384Object::digestSizeInBytes() const
133 {
134 return CC_SHA384_DIGEST_LENGTH;
135 }
136
137 /***
138 *** SHA512
139 ***/
140 void SHA512Object::digestInit()
141 {
142 mIsDone = false;
143 CC_SHA512_Init(&mCtx);
144 }
145
146 void SHA512Object::digestUpdate(
147 const void *data,
148 size_t len)
149 {
150 CC_SHA512_Update(&mCtx, (const unsigned char *)data, len);
151 }
152
153 void SHA512Object::digestFinal(
154 void *digest)
155 {
156 CC_SHA512_Final((unsigned char *)digest, &mCtx);
157 mIsDone = true;
158 }
159
160 /* use default memberwise init */
161 DigestObject *SHA512Object::digestClone() const
162 {
163 return new SHA512Object(*this);
164 }
165
166 size_t SHA512Object::digestSizeInBytes() const
167 {
168 return CC_SHA512_DIGEST_LENGTH;
169 }
170