1/*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30#ifndef _NFS_NFS_GSS_CRYPTO_H_
31#define _NFS_NFS_GSS_CRYPTO_H_
32#include <libkern/libkern.h>
33#include <libkern/crypto/sha1.h>
34#include <libkern/crypto/md5.h>
35#include <libkern/crypto/des.h>
36
37#define KG_USAGE_SEAL 22
38#define KG_USAGE_SIGN 23
39#define KG_USAGE_SEQ  24
40
41#define KEY_USAGE_DES3_SEAL (const unsigned char *)"\x00\x00\x00\x16\xaa"
42#define KEY_USAGE_DES3_SIGN (const unsigned char *)"\x00\x00\x00\x17\x99"
43#define KEY_USAGE_DES3_SEQ  (const unsigned char *)"\x00\x00\x00\x18\x55"
44#define KEY_USAGE_LEN 5
45
46typedef struct {
47	SHA1_CTX sha1_ctx;
48	des_cblock dk[3];
49} HMAC_SHA1_DES3KD_CTX;
50
51typedef struct {
52	MD5_CTX md5_ctx;
53	des_cbc_key_schedule *sched;
54} MD5_DESCBC_CTX;
55
56#define MD5_DESCBC_DIGEST_LENGTH 8
57
58__BEGIN_DECLS
59
60void krb5_nfold(unsigned int, const unsigned char *, unsigned int, unsigned char *);
61void des3_make_key(const unsigned char[21], des_cblock[3]);
62int des3_derive_key(des_cblock[3], des_cblock[3], const unsigned char *, int);
63
64void HMAC_SHA1_DES3KD_Init(HMAC_SHA1_DES3KD_CTX *, des_cblock[3], int);
65void HMAC_SHA1_DES3KD_Update(HMAC_SHA1_DES3KD_CTX *, void *, size_t);
66void HMAC_SHA1_DES3KD_Final(void *, HMAC_SHA1_DES3KD_CTX *);
67
68void MD5_DESCBC_Init(MD5_DESCBC_CTX *, des_cbc_key_schedule *);
69void MD5_DESCBC_Update(MD5_DESCBC_CTX *, void *, size_t);
70void MD5_DESCBC_Final(void *, MD5_DESCBC_CTX *);
71
72__END_DECLS
73
74#endif /* _NFS_NFS_GSS_CRYPTO_H_ */
75