]> git.saurik.com Git - apple/security.git/blob - sec/Security/SecOTRMath.h
Security-55471.14.8.tar.gz
[apple/security.git] / sec / Security / SecOTRMath.h
1 //
2 // OTRMath.h
3 // libsecurity_libSecOTR
4 //
5 // Created by Mitch Adler on 1/28/11.
6 // Copyright 2011 Apple Inc. All rights reserved.
7 //
8
9 #ifndef _SECOTRMATH_H_
10 #define _SECOTRMATH_H_
11
12 #include <CoreFoundation/CFBase.h>
13
14 #include <corecrypto/ccn.h>
15 #include <corecrypto/ccaes.h>
16 #include <corecrypto/ccmode.h>
17
18 #define kOTRAuthKeyBytes 16
19 #define kOTRAuthMACKeyBytes 32
20
21 #define kOTRMessageKeyBytes 16
22 #define kOTRMessageMacKeyBytes 20
23
24 #define kExponentiationBits 1536
25 #define kExponentiationUnits ccn_nof(kExponentiationBits)
26 #define kExponentiationBytes ((kExponentiationBits+7)/8)
27
28 #define kSHA256HMAC160Bits 160
29 #define kSHA256HMAC160Bytes (kSHA256HMAC160Bits/8)
30
31 // Result and exponent are expected to be kExponentiationUnits big.
32 void OTRExponentiate(cc_unit* res, const cc_unit* base, const cc_unit* exponent);
33 void OTRGroupExponentiate(cc_unit* result, const cc_unit* exponent);
34
35 OSStatus GetRandomBytesInLSBs(size_t bytesOfRandomness, size_t n, cc_unit* place);
36 OSStatus FillWithRandomBytes(size_t n, cc_unit* place);
37
38 typedef enum {
39 kSSID = 0x00,
40 kCs = 0x01,
41 kM1 = 0x02,
42 kM2 = 0x03,
43 kM1Prime = 0x04,
44 kM2Prime = 0x05
45 } KeyType;
46
47
48 void DeriveOTR256BitsFromS(KeyType whichKey, size_t sSize, const cc_unit* s, size_t keySize, uint8_t* key);
49 void DeriveOTR128BitPairFromS(KeyType whichHalf, size_t sSize, const cc_unit* s,
50 size_t firstKeySize, uint8_t* firstKey,
51 size_t secondKeySize, uint8_t* secondKey);
52 void DeriveOTR64BitsFromS(KeyType whichKey, size_t sSize, const cc_unit* s,
53 size_t firstKeySize, uint8_t* firstKey);
54
55
56 void AES_CTR_HighHalf_Transform(size_t keySize, const uint8_t* key,
57 uint64_t highHalf,
58 size_t howMuch, const uint8_t* from,
59 uint8_t* to);
60
61 void AES_CTR_IV0_Transform(size_t keySize, const uint8_t* key,
62 size_t howMuch, const uint8_t* from,
63 uint8_t* to);
64
65 #endif