1 /* Copyright (c) 1998,2011,2014 Apple Inc. All Rights Reserved.
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 ***************************************************************************
11 * NSDESCryptor.m - DES encrypt/decrypt class
16 * Rewrote using feeDES module.
21 #import <Foundation/Foundation.h>
22 #import "NSDESCryptor.h"
25 #import "ckutilities.h"
26 #import "feeFunctions.h"
29 * Note: Our _priv ivar is actuall a feeDES pointer.
31 @implementation NSDESCryptor
33 + cryptorWithState:(NSData *)s {
34 return [[[self alloc] initWithState:s] autorelease];
37 - (void)setCryptorState:(NSData *)state {
41 feeDESSetState(_priv, [state bytes], [state length]);
44 - initWithState:(NSData *)state {
48 _priv = feeDESNewWithState([state bytes], [state length]);
51 frtn = feeDESSetState(_priv, [state bytes], [state length]);
53 NSLog(@"NSDESCryptor: bad initial state\n");
68 - (void)setBlockMode:(BOOL)yorn {
73 feeDESSetBlockMode(_priv);
76 feeDESSetChainMode(_priv);
80 - (NSData *)encryptData:(NSData *)input {
83 unsigned char *cipherText;
84 unsigned cipherTextLen;
89 frtn = feeDESEncrypt(_priv,
95 NSLog(@"NSDESCryptor encrypt: %s", feeReturnString(frtn));
98 result = [NSData dataWithBytes:cipherText length:cipherTextLen];
103 - (NSData *)decryptData:(NSData *)input {
106 unsigned char *plainText;
107 unsigned plainTextLen;
112 frtn = feeDESDecrypt(_priv,
118 NSLog(@"NSDESCryptor decrypt: %s", feeReturnString(frtn));
121 result = [NSData dataWithBytes:plainText length:plainTextLen];
126 - (unsigned)keyBitsize {
127 return feeDESKeySize(_priv);