]> git.saurik.com Git - apple/security.git/blob - Security/sec/Security/Regressions/otr/otr-otrdh.c
b2bde0c9b7f802294860d336f5f1a9708c770b99
[apple/security.git] / Security / sec / Security / Regressions / otr / otr-otrdh.c
1 /*
2 * Copyright (c) 2011-2012,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 #include "Security_regressions.h"
26
27 #include <Security/SecOTRMath.h>
28 #include <Security/SecOTRDHKey.h>
29
30 int otr_otrdh(int argc, char *const * argv)
31 {
32 plan_tests(4);
33
34 SecOTRFullDHKeyRef aliceFull = SecOTRFullDHKCreate(kCFAllocatorDefault);
35 SecOTRPublicDHKeyRef alicePublic = SecOTRPublicDHKCreateFromFullKey(kCFAllocatorDefault, aliceFull);
36
37 SecOTRFullDHKeyRef bobFull = SecOTRFullDHKCreate(kCFAllocatorDefault);
38 SecOTRPublicDHKeyRef bobPublic = SecOTRPublicDHKCreateFromFullKey(kCFAllocatorDefault, bobFull);
39
40 uint8_t aliceMessageKeys[2][kOTRMessageKeyBytes];
41 uint8_t aliceMacKeys[2][kOTRMessageMacKeyBytes];
42
43 SecOTRDHKGenerateOTRKeys(aliceFull, bobPublic,
44 aliceMessageKeys[0], aliceMacKeys[0],
45 aliceMessageKeys[1], aliceMacKeys[1]);
46
47 uint8_t bobMessageKeys[2][kOTRMessageKeyBytes];
48 uint8_t bobMacKeys[2][kOTRMessageMacKeyBytes];
49
50 SecOTRDHKGenerateOTRKeys(bobFull, alicePublic,
51 bobMessageKeys[0], bobMacKeys[0],
52 bobMessageKeys[1], bobMacKeys[1]);
53
54
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!!");
59
60 return 0;
61 }