]> git.saurik.com Git - apple/security.git/blob - libsecurity_ssl/lib/symCipher.h
Security-55471.14.tar.gz
[apple/security.git] / libsecurity_ssl / lib / symCipher.h
1 /*
2 * Copyright (c) 1999-2001,2005-2008,2010-2012 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 * symCipher.h - symmetric cipher module
26 */
27
28 #ifndef _SYM_CIPHER_H_
29 #define _SYM_CIPHER_H_
30
31 #include <sys/types.h>
32 #include <stdint.h>
33 #include "cipherSpecs.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #define MASTER_SECRET_LEN 48 /* master secret = 3 x MD5 hashes concatenated */
40
41 /* SSL V2 - mac secret is the size of symmetric key, not digest */
42 #define MAX_SYMKEY_SIZE 24
43
44 typedef enum
45 {
46 streamCipherType,
47 blockCipherType,
48 aeadCipherType
49 } CipherType;
50
51 typedef struct {
52 SSL_CipherAlgorithm keyAlg;
53 CipherType cipherType;
54 uint8_t keySize; /* Sizes are in bytes */
55 uint8_t ivSize;
56 uint8_t blockSize;
57 } SSLSymmetricCipherParams;
58
59
60 /* All symmetric ciphers go thru these callouts. */
61 struct SymCipherContext;
62 typedef struct SymCipherContext *SymCipherContext;
63
64 typedef int (*SSLKeyFunc)(
65 const SSLSymmetricCipherParams *params,
66 int encrypting,
67 uint8_t *key,
68 uint8_t *iv,
69 SymCipherContext *cipherCtx);
70 typedef int (*SSLSetIVFunc)(
71 const uint8_t *iv,
72 size_t len,
73 SymCipherContext cipherCtx);
74 typedef int (*SSLAddADD)(
75 const uint8_t *src,
76 size_t len,
77 SymCipherContext cipherCtx);
78 typedef int (*SSLCryptFunc)(
79 const uint8_t *src,
80 uint8_t *dest,
81 size_t len,
82 SymCipherContext cipherCtx);
83 typedef int (*SSLFinishFunc)(
84 SymCipherContext cipherCtx);
85 typedef int (*SSLAEADDoneFunc)(
86 uint8_t *mac,
87 size_t *macLen,
88 SymCipherContext cipherCtx);
89
90 /* Statically defined description of a symmetric cipher. */
91 typedef struct {
92 SSLKeyFunc initialize;
93 SSLCryptFunc encrypt;
94 SSLCryptFunc decrypt;
95 } Cipher;
96
97 typedef struct {
98 SSLKeyFunc initialize;
99 SSLSetIVFunc setIV;
100 SSLAddADD update;
101 SSLCryptFunc encrypt;
102 SSLCryptFunc decrypt;
103 SSLAEADDoneFunc done;
104 uint8_t macSize;
105 } AEADCipher;
106
107
108 typedef struct SSLSymmetricCipher {
109 const SSLSymmetricCipherParams *params;
110 SSLFinishFunc finish;
111 union {
112 const Cipher cipher; /* stream or block cipher type */
113 const AEADCipher aead; /* aeadCipherType */
114 } c;
115 } SSLSymmetricCipher;
116
117 extern const SSLSymmetricCipher SSLCipherNull;
118 extern const SSLSymmetricCipher SSLCipherRC2_40;
119 extern const SSLSymmetricCipher SSLCipherRC2_128;
120 extern const SSLSymmetricCipher SSLCipherRC4_40;
121 extern const SSLSymmetricCipher SSLCipherRC4_128;
122 extern const SSLSymmetricCipher SSLCipherDES40_CBC;
123 extern const SSLSymmetricCipher SSLCipherDES_CBC;
124 extern const SSLSymmetricCipher SSLCipher3DES_CBC;
125 extern const SSLSymmetricCipher SSLCipherAES_128_CBC;
126 extern const SSLSymmetricCipher SSLCipherAES_256_CBC;
127 extern const SSLSymmetricCipher SSLCipherAES_128_GCM;
128 extern const SSLSymmetricCipher SSLCipherAES_256_GCM;
129
130 /* Those are defined in symCipherParams.c */
131 extern const SSLSymmetricCipherParams SSLCipherNullParams;
132 extern const SSLSymmetricCipherParams SSLCipherRC2_40Params;
133 extern const SSLSymmetricCipherParams SSLCipherRC2_128Params;
134 extern const SSLSymmetricCipherParams SSLCipherRC4_40Params;
135 extern const SSLSymmetricCipherParams SSLCipherRC4_128Params;
136 extern const SSLSymmetricCipherParams SSLCipherDES40_CBCParams;
137 extern const SSLSymmetricCipherParams SSLCipherDES_CBCParams;
138 extern const SSLSymmetricCipherParams SSLCipher3DES_CBCParams;
139 extern const SSLSymmetricCipherParams SSLCipherAES_128_CBCParams;
140 extern const SSLSymmetricCipherParams SSLCipherAES_256_CBCParams;
141 extern const SSLSymmetricCipherParams SSLCipherAES_128_GCMParams;
142 extern const SSLSymmetricCipherParams SSLCipherAES_256_GCMParams;
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif /* _SYM_CIPHER_H_ */