1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
14  */
15 
16 #ifndef _SMB_SIGNING_H_
17 #define	_SMB_SIGNING_H_
18 
19 /*
20  * SMB signing routines used in {smb,smb2}_sign.c
21  * Two implementations of these (kernel/user) in:
22  *	uts/common/fs/smbclnt/netsmb/smb_sign_kcf.c
23  *	lib/smbclnt/libfknsmb/common/fksmb_sign_pkcs.c
24  */
25 
26 #ifdef	_KERNEL
27 #include <sys/crypto/api.h>
28 #else
29 #include <security/cryptoki.h>
30 #include <security/pkcs11.h>
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #define	MD5_DIGEST_LENGTH	16	/* MD5 digest length in bytes */
38 #define	SHA256_DIGEST_LENGTH	32	/* SHA256 digest length in bytes */
39 #define	SMB2_SIG_SIZE		16
40 
41 #ifdef	_KERNEL
42 /* KCF variant */
43 typedef crypto_mechanism_t	smb_sign_mech_t;
44 typedef crypto_context_t	smb_sign_ctx_t;
45 #else	/* _KERNEL */
46 /* PKCS11 variant */
47 typedef CK_MECHANISM		smb_sign_mech_t;
48 typedef CK_SESSION_HANDLE	smb_sign_ctx_t;
49 #endif	/* _KERNEL */
50 
51 struct smb_mac_ops;
52 
53 /*
54  * SMB signing routines used in smb_signing.c
55  */
56 
57 int smb_md5_getmech(smb_sign_mech_t *);
58 int smb_md5_init(smb_sign_ctx_t *, smb_sign_mech_t *);
59 int smb_md5_update(smb_sign_ctx_t, void *, size_t);
60 int smb_md5_final(smb_sign_ctx_t, uint8_t *);
61 
62 /*
63  * SMB2 signing routines used in smb2_signing.c
64  */
65 
66 int smb2_hmac_getmech(smb_sign_mech_t *);
67 int smb2_hmac_init(smb_sign_ctx_t *, smb_sign_mech_t *, uint8_t *, size_t);
68 int smb2_hmac_update(smb_sign_ctx_t, uint8_t *, size_t);
69 int smb2_hmac_final(smb_sign_ctx_t, uint8_t *);
70 
71 int smb3_cmac_getmech(smb_sign_mech_t *);
72 int smb3_cmac_init(smb_sign_ctx_t *, smb_sign_mech_t *, uint8_t *, size_t);
73 int smb3_cmac_update(smb_sign_ctx_t, uint8_t *, size_t);
74 int smb3_cmac_final(smb_sign_ctx_t, uint8_t *);
75 
76 #ifdef __cplusplus
77 }
78 #endif
79 
80 #endif /* _SMB_SIGNING_H_ */
81