1 /* rxgk.h - External interfaces for RXGK */
3 * Copyright (C) 2013, 2014 by the Massachusetts Institute of Technology.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
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
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.
33 * External interfaces for RXGK.
36 #ifndef OPENAFS_RXGK_H
37 #define OPENAFS_RXGK_H
39 /* Pull in the com_err table */
40 #include <rx/rxgk_errs.h>
42 /* Pull in the protocol description */
43 #include <rx/rxgk_int.h>
45 /* Pull in our basic type definitions */
46 #include <rx/rxgk_types.h>
48 /* RX-internal headers we depend on. */
49 #include <rx/rx_opaque.h>
50 #include <rx/rx_identity.h>
52 /* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but
53 * in 100-nanosecond units. */
55 /* Helpers to avoid having to count zeros. */
56 static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) {
57 return seconds * (rxgkTime)10000000;
59 static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) {
60 return (afs_uint64)atime / 10000000;
63 /** Get the current timestamp as an rxgkTime. */
64 static_inline rxgkTime RXGK_NOW(void)
68 return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10;
71 typedef afs_int32 (*rxgk_getkey_func)(void *rock, afs_int32 *kvno,
72 afs_int32 *enctype, rxgk_key *key);
74 /* Flags for our rx security stats */
75 #define RXGK_STATS_UNALLOC 0x1
76 #define RXGK_STATS_AUTH 0x2
79 struct rx_securityClass * rxgk_NewServerSecurityObject(void *getkey_rock,
80 rxgk_getkey_func getkey);
81 afs_int32 rxgk_GetServerInfo(struct rx_connection *conn, RXGK_Level *level,
82 rxgkTime *expiry, struct rx_identity **identity);
85 struct rx_securityClass *rxgk_NewClientSecurityObject(RXGK_Level level,
90 /* rxgk_crypto_IMPL.c (currently rfc3961 is the only IMPL) */
91 afs_int32 rxgk_make_key(rxgk_key *key_out, void *raw_key, afs_uint32 length,
92 afs_int32 enctype) AFS_NONNULL();
93 afs_int32 rxgk_copy_key(rxgk_key key_in, rxgk_key *key_out) AFS_NONNULL();
94 afs_int32 rxgk_random_key(afs_int32 *enctype, rxgk_key *key_out) AFS_NONNULL();
95 void rxgk_release_key(rxgk_key *key) AFS_NONNULL();
96 afs_int32 rxgk_mic_length(rxgk_key key, size_t *out) AFS_NONNULL();
97 afs_int32 rxgk_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
98 RXGK_Data *out) AFS_NONNULL();
99 afs_int32 rxgk_check_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
100 RXGK_Data *mic) AFS_NONNULL();
101 afs_int32 rxgk_encrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
102 RXGK_Data *out) AFS_NONNULL();
103 afs_int32 rxgk_decrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
104 RXGK_Data *out) AFS_NONNULL();
105 afs_int32 rxgk_derive_tk(rxgk_key *tk, rxgk_key k0, afs_uint32 epoch,
106 afs_uint32 cid, rxgkTime start_time,
107 afs_uint32 key_number) AFS_NONNULL();
108 afs_int32 rxgk_cipher_expansion(rxgk_key k0, afs_uint32 *len_out) AFS_NONNULL();
109 afs_int32 rxgk_nonce(RXGK_Data *nonce, afs_uint32 len) AFS_NONNULL();
110 int rxgk_enctype_better(afs_int32 old_enctype, afs_int32 new_enctype);
113 afs_int32 rxgk_make_token(struct rx_opaque *out, RXGK_TokenInfo *info,
114 struct rx_opaque *k0, PrAuthName *identities,
115 int nids, rxgk_key key, afs_int32 kvno,
116 afs_int32 enctype) AFS_NONNULL((1,2,3,6));
117 afs_int32 rxgk_print_token(struct rx_opaque *out, RXGK_TokenInfo *input_info,
118 struct rx_opaque *k0, rxgk_key key, afs_int32 kvno,
119 afs_int32 enctype) AFS_NONNULL();
120 afs_int32 rxgk_print_token_and_key(struct rx_opaque *out,
121 RXGK_TokenInfo *input_info, rxgk_key key,
122 afs_int32 kvno, afs_int32 enctype,
123 rxgk_key *k0_out) AFS_NONNULL();
125 #endif /* OPENAFS_RXGK_H */