Implement the rxgk server security object routines
[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 #include <rx/rx_identity.h>
48
49 /* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but
50  * in 100-nanosecond units. */
51
52 /* Helpers to avoid having to count zeros. */
53 static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) {
54     return seconds * (rxgkTime)10000000;
55 }
56 static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) {
57     return (afs_uint64)atime / 10000000;
58 }
59
60 /** Get the current timestamp as an rxgkTime. */
61 static_inline rxgkTime RXGK_NOW(void)
62 {
63     struct timeval tv;
64     osi_GetTime(&tv);
65     return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10;
66 }
67
68 /* rxgk_key is an opaque type to wrap our RFC3961 implementation's concept
69  * of a key.  It has (at least) the keyblock and length, and enctype. */
70 typedef struct rxgk_key_s * rxgk_key;
71
72 typedef afs_int32 (*rxgk_getkey_func)(void *rock, afs_int32 *kvno,
73                                       afs_int32 *enctype, rxgk_key *key);
74
75 /* Flags for our rx security stats */
76 #define RXGK_STATS_UNALLOC 0x1
77 #define RXGK_STATS_AUTH    0x2
78
79 /* rxgk_server.c */
80 struct rx_securityClass * rxgk_NewServerSecurityObject(void *getkey_rock,
81                                                        rxgk_getkey_func getkey);
82 afs_int32 rxgk_GetServerInfo(struct rx_connection *conn, RXGK_Level *level,
83                              rxgkTime *expiry, struct rx_identity **identity);
84
85 /* rxgk_client.c */
86 struct rx_securityClass *rxgk_NewClientSecurityObject(RXGK_Level level,
87                                                       afs_int32 enctype,
88                                                       rxgk_key k0,
89                                                       RXGK_Data *token,
90                                                       afsUUID *uuid);
91
92 /* rxgk_crypto_IMPL.c (currently rfc3961 is the only IMPL) */
93 afs_int32 rxgk_make_key(rxgk_key *key_out, void *raw_key, afs_uint32 length,
94                         afs_int32 enctype) AFS_NONNULL();
95 afs_int32 rxgk_copy_key(rxgk_key key_in, rxgk_key *key_out) AFS_NONNULL();
96 afs_int32 rxgk_random_key(afs_int32 *enctype, rxgk_key *key_out) AFS_NONNULL();
97 void rxgk_release_key(rxgk_key *key) AFS_NONNULL();
98 afs_int32 rxgk_mic_length(rxgk_key key, size_t *out) AFS_NONNULL();
99 afs_int32 rxgk_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
100                           RXGK_Data *out) AFS_NONNULL();
101 afs_int32 rxgk_check_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
102                                 RXGK_Data *mic) AFS_NONNULL();
103 afs_int32 rxgk_encrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
104                               RXGK_Data *out) AFS_NONNULL();
105 afs_int32 rxgk_decrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
106                               RXGK_Data *out) AFS_NONNULL();
107 afs_int32 rxgk_derive_tk(rxgk_key *tk, rxgk_key k0, afs_uint32 epoch,
108                          afs_uint32 cid, rxgkTime start_time,
109                          afs_uint32 key_number) AFS_NONNULL();
110 afs_int32 rxgk_cipher_expansion(rxgk_key k0, afs_uint32 *len_out) AFS_NONNULL();
111 afs_int32 rxgk_nonce(RXGK_Data *nonce, afs_uint32 len) AFS_NONNULL();
112
113 /* rxgk_token.c */
114 afs_int32 rxgk_make_token(struct rx_opaque *out, RXGK_TokenInfo *info,
115                           struct rx_opaque *k0, PrAuthName *identities,
116                           int nids, rxgk_key key, afs_int32 kvno,
117                           afs_int32 enctype) AFS_NONNULL((1,2,3,6));
118 afs_int32 rxgk_print_token(struct rx_opaque *out, RXGK_TokenInfo *input_info,
119                            struct rx_opaque *k0, rxgk_key key, afs_int32 kvno,
120                            afs_int32 enctype) AFS_NONNULL();
121 afs_int32 rxgk_print_token_and_key(struct rx_opaque *out,
122                                    RXGK_TokenInfo *input_info, rxgk_key key,
123                                    afs_int32 kvno, afs_int32 enctype,
124                                    rxgk_key *k0_out) AFS_NONNULL();
125
126 #endif /* OPENAFS_RXGK_H */