]> git.saurik.com Git - apple/security.git/blob - SecureTransport/privateInc/tls_hmac.h
Security-54.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 //#include "sslctx.h"
37 #include "sslerrs.h"
38
39 /* forward declaration of HMAC object */
40 struct HMACReference;
41
42 /* Opaque reference to an HMAC session context */
43 struct HMACContext;
44 typedef struct HMACContext *HMACContextRef;
45
46 /* The HMAC algorithms we support */
47 typedef enum {
48 HA_Null = 0, // i.e., uninitialized
49 HA_SHA1,
50 HA_MD5
51 } HMAC_Algs;
52
53 /* For convenience..the max size of HMAC, in bytes, this module will ever return */
54 #define TLS_HMAC_MAX_SIZE 20
55
56 /* Create an HMAC session */
57 typedef SSLErr (*HMAC_AllocFcn) (
58 const struct HMACReference *hmac,
59 SSLContext *ctx,
60 const void *keyPtr,
61 unsigned keyLen,
62 HMACContextRef *hmacCtx); // RETURNED
63
64 /* Free a session */
65 typedef SSLErr (*HMAC_FreeFcn) (
66 HMACContextRef hmacCtx);
67
68 /* Reusable init, using same key */
69 typedef SSLErr (*HMAC_InitFcn) (
70 HMACContextRef hmacCtx);
71
72 /* normal crypt ops */
73 typedef SSLErr (*HMAC_UpdateFcn) (
74 HMACContextRef hmacCtx,
75 const void *data,
76 unsigned dataLen);
77
78 typedef SSLErr (*HMAC_FinalFcn) (
79 HMACContextRef hmacCtx,
80 void *hmac, // mallocd by caller
81 unsigned *hmacLen); // IN/OUT
82
83 /* one-shot */
84 typedef SSLErr (*HMAC_HmacFcn) (
85 HMACContextRef hmacCtx,
86 const void *data,
87 unsigned dataLen,
88 void *hmac, // mallocd by caller
89 unsigned *hmacLen); // IN/OUT
90
91 typedef struct HMACReference {
92 UInt32 macSize;
93 HMAC_Algs alg;
94 HMAC_AllocFcn alloc;
95 HMAC_FreeFcn free;
96 HMAC_InitFcn init;
97 HMAC_UpdateFcn update;
98 HMAC_FinalFcn final;
99 HMAC_HmacFcn hmac;
100 } HMACReference;
101
102 extern const HMACReference TlsHmacNull;
103 extern const HMACReference TlsHmacSHA1;
104 extern const HMACReference TlsHmacMD5;
105
106 #ifdef __cplusplus
107 }
108 #endif
109 #endif /* _TLS_HMAC_H_ */