2 * Copyright (c) 2011-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _SECOTRSESSIONPRIV_H_
26 #define _SECOTRSESSIONPRIV_H_
28 #include <CoreFoundation/CFBase.h>
29 #include <CoreFoundation/CFRuntime.h>
30 #include <CoreFoundation/CFDate.h>
32 #include <Security/SecOTR.h>
33 #include <corecrypto/ccn.h>
34 #include <corecrypto/ccmode.h>
35 #include <corecrypto/ccsha1.h>
37 #include <CommonCrypto/CommonDigest.h>
39 #include <dispatch/dispatch.h>
41 #include <Security/SecOTRMath.h>
42 #include <Security/SecOTRDHKey.h>
43 #include <Security/SecOTRSession.h>
50 kAwaitingRevealSignature
,
55 struct _SecOTRCacheElement
{
56 uint8_t _fullKeyHash
[CCSHA1_OUTPUT_SIZE
];
57 uint8_t _publicKeyHash
[CCSHA1_OUTPUT_SIZE
];
59 uint8_t _sendMacKey
[kOTRMessageMacKeyBytes
];
60 uint8_t _sendEncryptionKey
[kOTRMessageKeyBytes
];
62 uint8_t _receiveMacKey
[kOTRMessageMacKeyBytes
];
63 uint8_t _receiveEncryptionKey
[kOTRMessageKeyBytes
];
66 uint64_t _theirCounter
;
69 typedef struct _SecOTRCacheElement SecOTRCacheElement
;
71 #define kOTRKeyCacheSize 4
72 #define kSecondsPerMinute 60
74 struct _SecOTRSession
{
77 SecOTRAuthState _state
;
79 SecOTRFullIdentityRef _me
;
80 SecOTRPublicIdentityRef _them
;
82 uint8_t _r
[kOTRAuthKeyBytes
];
84 CFDataRef _receivedDHMessage
;
85 CFDataRef _receivedDHKeyMessage
;
88 SecOTRFullDHKeyRef _myKey
;
89 SecOTRFullDHKeyRef _myNextKey
;
92 SecOTRPublicDHKeyRef _theirPreviousKey
;
93 SecOTRPublicDHKeyRef _theirKey
;
95 CFMutableDataRef _macKeysToExpose
;
97 dispatch_queue_t _queue
;
99 SecOTRCacheElement _keyCache
[kOTRKeyCacheSize
];
102 bool _compactAppleMessages
;
104 uint64_t _stallSeconds
;
106 bool _stallingTheirRoll
;
107 CFAbsoluteTime _timeToRoll
;
113 CFDataRef
SecOTRCopyIncomingBytes(CFDataRef incomingMessage
);
114 void SecOTRPrepareOutgoingBytes(CFMutableDataRef destinationMessage
, CFMutableDataRef protectedMessage
);
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
);