1e98332fb4fb2f73f4d37c7f1478a74b83fa0712
[openafs.git] / src / rxgk / rxgk.h
1 /* rxgk.h - External interfaces for RXGK */
2 /*
3  * Copyright (C) 2013, 2014 by the Massachusetts Institute of Technology.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  *   notice, this list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in
15  *   the documentation and/or other materials provided with the
16  *   distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31
32 /*
33  * External interfaces for RXGK.
34  */
35
36 #ifndef OPENAFS_RXGK_H
37 #define OPENAFS_RXGK_H
38
39 /* Pull in the com_err table */
40 #include <rx/rxgk_errs.h>
41
42 /* Pull in the protocol description */
43 #include <rx/rxgk_int.h>
44
45 /* RX-internal headers we depend on. */
46 #include <rx/rx_opaque.h>
47
48 /* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but
49  * in 100-nanosecond units. */
50
51 /* Helpers to avoid having to count zeros. */
52 static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) {
53     return seconds * (rxgkTime)10000000;
54 }
55 static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) {
56     return (afs_uint64)atime / 10000000;
57 }
58
59 /** Get the current timestamp as an rxgkTime. */
60 static_inline rxgkTime RXGK_NOW(void)
61 {
62     struct timeval tv;
63     osi_GetTime(&tv);
64     return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10;
65 }
66
67 /* rxgk_key is an opaque type to wrap our RFC3961 implementation's concept
68  * of a key.  It has (at least) the keyblock and length, and enctype. */
69 typedef struct rxgk_key_s * rxgk_key;
70
71 typedef afs_int32 (*rxgk_getkey_func)(void *rock, afs_int32 *kvno,
72                                       afs_int32 *enctype, rxgk_key *key);
73 /* rxgk_server.c */
74 struct rx_securityClass * rxgk_NewServerSecurityObject(void *getkey_rock,
75                                                        rxgk_getkey_func getkey);
76 /* rxgk_client.c */
77 struct rx_securityClass *rxgk_NewClientSecurityObject(RXGK_Level level,
78                                                       afs_int32 enctype,
79                                                       rxgk_key k0,
80                                                       RXGK_Data *token,
81                                                       afsUUID *uuid);
82
83 /* rxgk_crypto_IMPL.c (currently rfc3961 is the only IMPL) */
84 afs_int32 rxgk_make_key(rxgk_key *key_out, void *raw_key, afs_uint32 length,
85                         afs_int32 enctype) AFS_NONNULL();
86 afs_int32 rxgk_copy_key(rxgk_key key_in, rxgk_key *key_out) AFS_NONNULL();
87 afs_int32 rxgk_random_key(afs_int32 *enctype, rxgk_key *key_out) AFS_NONNULL();
88 void rxgk_release_key(rxgk_key *key) AFS_NONNULL();
89 afs_int32 rxgk_mic_length(rxgk_key key, size_t *out) AFS_NONNULL();
90 afs_int32 rxgk_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
91                           RXGK_Data *out) AFS_NONNULL();
92 afs_int32 rxgk_check_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
93                                 RXGK_Data *mic) AFS_NONNULL();
94 afs_int32 rxgk_encrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
95                               RXGK_Data *out) AFS_NONNULL();
96 afs_int32 rxgk_decrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
97                               RXGK_Data *out) AFS_NONNULL();
98 afs_int32 rxgk_derive_tk(rxgk_key *tk, rxgk_key k0, afs_uint32 epoch,
99                          afs_uint32 cid, rxgkTime start_time,
100                          afs_uint32 key_number) AFS_NONNULL();
101 afs_int32 rxgk_cipher_expansion(rxgk_key k0, afs_uint32 *len_out) AFS_NONNULL();
102 afs_int32 rxgk_nonce(RXGK_Data *nonce, afs_uint32 len) AFS_NONNULL();
103
104 /* rxgk_token.c */
105 afs_int32 rxgk_make_token(struct rx_opaque *out, RXGK_TokenInfo *info,
106                           struct rx_opaque *k0, PrAuthName *identities,
107                           int nids, rxgk_key key, afs_int32 kvno,
108                           afs_int32 enctype) AFS_NONNULL((1,2,3,6));
109 afs_int32 rxgk_print_token(struct rx_opaque *out, RXGK_TokenInfo *input_info,
110                            struct rx_opaque *k0, rxgk_key key, afs_int32 kvno,
111                            afs_int32 enctype) AFS_NONNULL();
112 afs_int32 rxgk_print_token_and_key(struct rx_opaque *out,
113                                    RXGK_TokenInfo *input_info, rxgk_key key,
114                                    afs_int32 kvno, afs_int32 enctype,
115                                    rxgk_key *k0_out) AFS_NONNULL();
116
117 #endif /* OPENAFS_RXGK_H */