1/* 2 * Copyright (c) 1999-2001,2005-2008,2010-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 * 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 36extern "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 44typedef enum 45{ 46 streamCipherType, 47 blockCipherType, 48 aeadCipherType 49} CipherType; 50 51typedef 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. */ 61struct SymCipherContext; 62typedef struct SymCipherContext *SymCipherContext; 63 64typedef int (*SSLKeyFunc)( 65 const SSLSymmetricCipherParams *params, 66 int encrypting, 67 uint8_t *key, 68 uint8_t *iv, 69 SymCipherContext *cipherCtx); 70typedef int (*SSLSetIVFunc)( 71 const uint8_t *iv, 72 size_t len, 73 SymCipherContext cipherCtx); 74typedef int (*SSLAddADD)( 75 const uint8_t *src, 76 size_t len, 77 SymCipherContext cipherCtx); 78typedef int (*SSLCryptFunc)( 79 const uint8_t *src, 80 uint8_t *dest, 81 size_t len, 82 SymCipherContext cipherCtx); 83typedef int (*SSLFinishFunc)( 84 SymCipherContext cipherCtx); 85typedef int (*SSLAEADDoneFunc)( 86 uint8_t *mac, 87 size_t *macLen, 88 SymCipherContext cipherCtx); 89 90/* Statically defined description of a symmetric cipher. */ 91typedef struct { 92 SSLKeyFunc initialize; 93 SSLCryptFunc encrypt; 94 SSLCryptFunc decrypt; 95} Cipher; 96 97typedef 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 108typedef 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 117extern const SSLSymmetricCipher SSLCipherNull; 118extern const SSLSymmetricCipher SSLCipherRC2_40; 119extern const SSLSymmetricCipher SSLCipherRC2_128; 120extern const SSLSymmetricCipher SSLCipherRC4_40; 121extern const SSLSymmetricCipher SSLCipherRC4_128; 122extern const SSLSymmetricCipher SSLCipherDES40_CBC; 123extern const SSLSymmetricCipher SSLCipherDES_CBC; 124extern const SSLSymmetricCipher SSLCipher3DES_CBC; 125extern const SSLSymmetricCipher SSLCipherAES_128_CBC; 126extern const SSLSymmetricCipher SSLCipherAES_256_CBC; 127extern const SSLSymmetricCipher SSLCipherAES_128_GCM; 128extern const SSLSymmetricCipher SSLCipherAES_256_GCM; 129 130/* Those are defined in symCipherParams.c */ 131extern const SSLSymmetricCipherParams SSLCipherNullParams; 132extern const SSLSymmetricCipherParams SSLCipherRC2_40Params; 133extern const SSLSymmetricCipherParams SSLCipherRC2_128Params; 134extern const SSLSymmetricCipherParams SSLCipherRC4_40Params; 135extern const SSLSymmetricCipherParams SSLCipherRC4_128Params; 136extern const SSLSymmetricCipherParams SSLCipherDES40_CBCParams; 137extern const SSLSymmetricCipherParams SSLCipherDES_CBCParams; 138extern const SSLSymmetricCipherParams SSLCipher3DES_CBCParams; 139extern const SSLSymmetricCipherParams SSLCipherAES_128_CBCParams; 140extern const SSLSymmetricCipherParams SSLCipherAES_256_CBCParams; 141extern const SSLSymmetricCipherParams SSLCipherAES_128_GCMParams; 142extern const SSLSymmetricCipherParams SSLCipherAES_256_GCMParams; 143 144#ifdef __cplusplus 145} 146#endif 147 148#endif /* _SYM_CIPHER_H_ */ 149