]> git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/tls_hmac.h
Security-163.tar.gz
[apple/security.git] / SecureTransport / privateInc / tls_hmac.h
1 /*
2 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 /*
20 File: tls_hmac.h
21
22 Contains: Declarations of HMAC routines used by TLS
23
24 Written by: Doug Mitchell
25 */
26
27 #ifndef _TLS_HMAC_H_
28 #define _TLS_HMAC_H_
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include "ssl.h"
35 #include "sslPriv.h"
36
37 /* forward declaration of HMAC object */
38 struct HMACReference;
39
40 /* Opaque reference to an HMAC session context */
41 struct HMACContext;
42 typedef struct HMACContext *HMACContextRef;
43
44 /* The HMAC algorithms we support */
45 typedef enum {
46 HA_Null = 0, // i.e., uninitialized
47 HA_SHA1,
48 HA_MD5
49 } HMAC_Algs;
50
51 /* For convenience..the max size of HMAC, in bytes, this module will ever return */
52 #define TLS_HMAC_MAX_SIZE 20
53
54 /* Create an HMAC session */
55 typedef OSStatus (*HMAC_AllocFcn) (
56 const struct HMACReference *hmac,
57 SSLContext *ctx,
58 const void *keyPtr,
59 unsigned keyLen,
60 HMACContextRef *hmacCtx); // RETURNED
61
62 /* Free a session */
63 typedef OSStatus (*HMAC_FreeFcn) (
64 HMACContextRef hmacCtx);
65
66 /* Reusable init, using same key */
67 typedef OSStatus (*HMAC_InitFcn) (
68 HMACContextRef hmacCtx);
69
70 /* normal crypt ops */
71 typedef OSStatus (*HMAC_UpdateFcn) (
72 HMACContextRef hmacCtx,
73 const void *data,
74 unsigned dataLen);
75
76 typedef OSStatus (*HMAC_FinalFcn) (
77 HMACContextRef hmacCtx,
78 void *hmac, // mallocd by caller
79 unsigned *hmacLen); // IN/OUT
80
81 /* one-shot */
82 typedef OSStatus (*HMAC_HmacFcn) (
83 HMACContextRef hmacCtx,
84 const void *data,
85 unsigned dataLen,
86 void *hmac, // mallocd by caller
87 unsigned *hmacLen); // IN/OUT
88
89 typedef struct HMACReference {
90 UInt32 macSize;
91 HMAC_Algs alg;
92 HMAC_AllocFcn alloc;
93 HMAC_FreeFcn free;
94 HMAC_InitFcn init;
95 HMAC_UpdateFcn update;
96 HMAC_FinalFcn final;
97 HMAC_HmacFcn hmac;
98 } HMACReference;
99
100 extern const HMACReference TlsHmacNull;
101 extern const HMACReference TlsHmacSHA1;
102 extern const HMACReference TlsHmacMD5;
103
104 #ifdef __cplusplus
105 }
106 #endif
107 #endif /* _TLS_HMAC_H_ */