]> git.saurik.com Git - apple/security.git/blobdiff - Security/sec/Security/SecOTRMath.h
Security-57031.1.35.tar.gz
[apple/security.git] / Security / sec / Security / SecOTRMath.h
diff --git a/Security/sec/Security/SecOTRMath.h b/Security/sec/Security/SecOTRMath.h
new file mode 100644 (file)
index 0000000..6f966e3
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2011-2012,2014 Apple Inc. All Rights Reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
+ * 
+ * @APPLE_LICENSE_HEADER_END@
+ */
+
+
+#ifndef _SECOTRMATH_H_
+#define _SECOTRMATH_H_
+
+#include <CoreFoundation/CFBase.h>
+
+#include <corecrypto/ccn.h>
+#include <corecrypto/ccaes.h>
+#include <corecrypto/ccmode.h>
+
+#define kOTRAuthKeyBytes 16
+#define kOTRAuthMACKeyBytes 32
+
+#define kOTRMessageKeyBytes 16
+#define kOTRMessageMacKeyBytes 20
+
+#define kExponentiationBits 1536
+#define kExponentiationUnits ccn_nof(kExponentiationBits)
+#define kExponentiationBytes ((kExponentiationBits+7)/8)
+
+#define kSHA256HMAC160Bits  160
+#define kSHA256HMAC160Bytes (kSHA256HMAC160Bits/8)
+
+// Result and exponent are expected to be kExponentiationUnits big.
+void OTRExponentiate(cc_unit* res, const cc_unit* base, const cc_unit* exponent);
+void OTRGroupExponentiate(cc_unit* result, const cc_unit* exponent);
+
+OSStatus GetRandomBytesInLSBs(size_t bytesOfRandomness, size_t n, cc_unit* place);
+OSStatus FillWithRandomBytes(size_t n, cc_unit* place);
+
+typedef enum {
+    kSSID = 0x00,
+    kCs = 0x01,
+    kM1 = 0x02,
+    kM2 = 0x03,
+    kM1Prime = 0x04,
+    kM2Prime = 0x05
+} KeyType;
+
+
+void DeriveOTR256BitsFromS(KeyType whichKey, size_t sSize, const cc_unit* s, size_t keySize, uint8_t* key);
+void DeriveOTR128BitPairFromS(KeyType whichHalf, size_t sSize, const cc_unit* s,
+                              size_t firstKeySize, uint8_t* firstKey,
+                              size_t secondKeySize, uint8_t* secondKey);
+void DeriveOTR64BitsFromS(KeyType whichKey, size_t sSize, const cc_unit* s,
+                          size_t firstKeySize, uint8_t* firstKey);
+
+
+void AES_CTR_HighHalf_Transform(size_t keySize, const uint8_t* key,
+                                uint64_t highHalf,
+                                size_t howMuch, const uint8_t* from,
+                                uint8_t* to);
+
+void AES_CTR_IV0_Transform(size_t keySize, const uint8_t* key,
+                           size_t howMuch, const uint8_t* from,
+                           uint8_t* to);
+
+#endif