]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cryptkit/lib/NSMD5Hash.m
Security-58286.31.2.tar.gz
[apple/security.git] / OSX / libsecurity_cryptkit / lib / NSMD5Hash.m
1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
2 *
3 * NOTICE: USE OF THE MATERIALS ACCOMPANYING THIS NOTICE IS SUBJECT
4 * TO THE TERMS OF THE SIGNED "FAST ELLIPTIC ENCRYPTION (FEE) REFERENCE
5 * SOURCE CODE EVALUATION AGREEMENT" BETWEEN APPLE, INC. AND THE
6 * ORIGINAL LICENSEE THAT OBTAINED THESE MATERIALS FROM APPLE,
7 * INC. ANY USE OF THESE MATERIALS NOT PERMITTED BY SUCH AGREEMENT WILL
8 * EXPOSE YOU TO LIABILITY.
9 ***************************************************************************
10 *
11 * NSMD5Hash.h
12 *
13 * Revision History
14 * ----------------
15 * 28 Mar 97 at Apple
16 * Created.
17 */
18
19 /*
20 * Note: our _priv ivar is actually a feeHash pointer.
21 */
22 #import "NSCryptors.h"
23 #import "NSMD5Hash.h"
24 #import "feeHash.h"
25 #import "falloc.h"
26
27 @implementation NSMD5Hash
28
29 + digester
30 {
31 return [[self alloc] init];
32 }
33
34 - init
35 {
36 if(_priv == NULL) {
37 _priv = feeHashAlloc();
38 }
39 else {
40 feeHashReinit(_priv);
41 }
42 return self;
43 }
44
45 - (void)digestData:(NSData *)data
46 {
47 if(_priv == NULL) {
48 return;
49 }
50 feeHashAddData(_priv, [data bytes], [data length]);
51 }
52
53 - (NSData *)messageDigest
54 {
55 unsigned char *cp;
56 NSData *md;
57
58 if(_priv == NULL) {
59 return nil;
60 }
61 cp = feeHashDigest(_priv);
62 md = [NSData dataWithBytes:cp length:feeHashDigestLen()];
63 feeHashReinit(_priv);
64 return md;
65 }
66
67 - (NSData *)digestData:(NSData *)data withSalt:(NSData *)salt
68 {
69 if(_priv == NULL) {
70 return nil;
71 }
72 if(salt != nil) {
73 [self digestData:salt];
74 }
75 [self digestData:data];
76 return [self messageDigest];
77 }
78
79 @end