]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/SecOTRSessionPriv.h
Security-58286.260.20.tar.gz
[apple/security.git] / OSX / sec / Security / SecOTRSessionPriv.h
1 /*
2 * Copyright (c) 2011-2014 Apple 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 #ifndef _SECOTRSESSIONPRIV_H_
26 #define _SECOTRSESSIONPRIV_H_
27
28 #include <CoreFoundation/CFBase.h>
29 #include <CoreFoundation/CFRuntime.h>
30 #include <CoreFoundation/CFDate.h>
31
32 #include <Security/SecOTR.h>
33 #include <corecrypto/ccn.h>
34 #include <corecrypto/ccmode.h>
35 #include <corecrypto/ccsha1.h>
36
37 #include <CommonCrypto/CommonDigest.h>
38
39 #include <dispatch/dispatch.h>
40
41 #include <Security/SecOTRMath.h>
42 #include <Security/SecOTRDHKey.h>
43 #include <Security/SecOTRSession.h>
44
45 __BEGIN_DECLS
46
47 typedef enum {
48 kIdle,
49 kAwaitingDHKey,
50 kAwaitingRevealSignature,
51 kAwaitingSignature,
52 kDone
53 } SecOTRAuthState;
54
55 struct _SecOTRCacheElement {
56 uint8_t _fullKeyHash[CCSHA1_OUTPUT_SIZE];
57 uint8_t _publicKeyHash[CCSHA1_OUTPUT_SIZE];
58
59 uint8_t _sendMacKey[kOTRMessageMacKeyBytes];
60 uint8_t _sendEncryptionKey[kOTRMessageKeyBytes];
61
62 uint8_t _receiveMacKey[kOTRMessageMacKeyBytes];
63 uint8_t _receiveEncryptionKey[kOTRMessageKeyBytes];
64
65 uint64_t _counter;
66 uint64_t _theirCounter;
67
68 };
69 typedef struct _SecOTRCacheElement SecOTRCacheElement;
70
71 #define kOTRKeyCacheSize 4
72 #define kSecondsPerMinute 60
73
74 struct _SecOTRSession {
75 CFRuntimeBase _base;
76
77 SecOTRAuthState _state;
78
79 SecOTRFullIdentityRef _me;
80 SecOTRPublicIdentityRef _them;
81
82 uint8_t _r[kOTRAuthKeyBytes];
83
84 CFDataRef _receivedDHMessage;
85 CFDataRef _receivedDHKeyMessage;
86
87 uint32_t _keyID;
88 SecOTRFullDHKeyRef _myKey;
89 SecOTRFullDHKeyRef _myNextKey;
90
91 uint32_t _theirKeyID;
92 SecOTRPublicDHKeyRef _theirPreviousKey;
93 SecOTRPublicDHKeyRef _theirKey;
94
95 CFMutableDataRef _macKeysToExpose;
96
97 dispatch_queue_t _queue;
98
99 SecOTRCacheElement _keyCache[kOTRKeyCacheSize];
100
101 bool _textOutput;
102 bool _compactAppleMessages;
103 bool _includeHashes;
104 uint64_t _stallSeconds;
105
106 bool _stallingTheirRoll;
107 CFAbsoluteTime _timeToRoll;
108
109 bool _missedAck;
110 bool _receivedAck;
111 };
112
113 CFDataRef SecOTRCopyIncomingBytes(CFDataRef incomingMessage);
114 void SecOTRPrepareOutgoingBytes(CFMutableDataRef destinationMessage, CFMutableDataRef protectedMessage);
115
116 OSStatus SecOTRSetupInitialRemoteKey(SecOTRSessionRef session, SecOTRPublicDHKeyRef CF_CONSUMED initialKey);
117 void SOSOTRSRoll(SecOTRSessionRef session);
118 int SecOTRSGetKeyID(SecOTRSessionRef session);
119 int SecOTRSGetTheirKeyID(SecOTRSessionRef session);
120 void SecOTRSKickTimeToRoll(SecOTRSessionRef session);
121
122 __END_DECLS
123
124 #endif