2 * Copyright (c) 2011-2012,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 #include "Security_regressions.h"
27 #include <Security/SecOTRMath.h>
28 #include <Security/SecOTRDHKey.h>
30 int otr_otrdh(int argc
, char *const * argv
)
34 SecOTRFullDHKeyRef aliceFull
= SecOTRFullDHKCreate(kCFAllocatorDefault
);
35 SecOTRPublicDHKeyRef alicePublic
= SecOTRPublicDHKCreateFromFullKey(kCFAllocatorDefault
, aliceFull
);
37 SecOTRFullDHKeyRef bobFull
= SecOTRFullDHKCreate(kCFAllocatorDefault
);
38 SecOTRPublicDHKeyRef bobPublic
= SecOTRPublicDHKCreateFromFullKey(kCFAllocatorDefault
, bobFull
);
40 uint8_t aliceMessageKeys
[2][kOTRMessageKeyBytes
];
41 uint8_t aliceMacKeys
[2][kOTRMessageMacKeyBytes
];
43 SecOTRDHKGenerateOTRKeys(aliceFull
, bobPublic
,
44 aliceMessageKeys
[0], aliceMacKeys
[0],
45 aliceMessageKeys
[1], aliceMacKeys
[1]);
47 uint8_t bobMessageKeys
[2][kOTRMessageKeyBytes
];
48 uint8_t bobMacKeys
[2][kOTRMessageMacKeyBytes
];
50 SecOTRDHKGenerateOTRKeys(bobFull
, alicePublic
,
51 bobMessageKeys
[0], bobMacKeys
[0],
52 bobMessageKeys
[1], bobMacKeys
[1]);
55 ok(0 == memcmp(aliceMessageKeys
[0], bobMessageKeys
[1], sizeof(aliceMessageKeys
[0])), "Mac Keys don't match!!");
56 ok(0 == memcmp(aliceMessageKeys
[1], bobMessageKeys
[0], sizeof(aliceMessageKeys
[1])), "Mac Keys don't match!!");
57 ok(0 == memcmp(aliceMacKeys
[0], bobMacKeys
[1], sizeof(aliceMacKeys
[0])), "Mac Keys don't match!!");
58 ok(0 == memcmp(aliceMacKeys
[1], bobMacKeys
[0], sizeof(aliceMacKeys
[1])), "Mac Keys don't match!!");