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 /* RX-internal headers we depend on. */
46 #include <rx/rx_opaque.h>
47 #include <rx/rx_identity.h>
49 /* rxgkTime is defined in rxgk_int.xg. rxgkTime values are unix timestamps, but
50 * in 100-nanosecond units. */
52 /* Helpers to avoid having to count zeros. */
53 static_inline rxgkTime secondsToRxgkTime(afs_uint64 seconds) {
54 return seconds * (rxgkTime)10000000;
56 static_inline afs_uint64 rxgkTimeToSeconds(rxgkTime atime) {
57 return (afs_uint64)atime / 10000000;
60 /** Get the current timestamp as an rxgkTime. */
61 static_inline rxgkTime RXGK_NOW(void)
65 return secondsToRxgkTime(tv.tv_sec) + (rxgkTime)tv.tv_usec * 10;
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;
72 typedef afs_int32 (*rxgk_getkey_func)(void *rock, afs_int32 *kvno,
73 afs_int32 *enctype, rxgk_key *key);
75 /* Flags for our rx security stats */
76 #define RXGK_STATS_UNALLOC 0x1
77 #define RXGK_STATS_AUTH 0x2
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);
86 struct rx_securityClass *rxgk_NewClientSecurityObject(RXGK_Level level,
91 /* rxgk_crypto_IMPL.c (currently rfc3961 is the only IMPL) */
92 afs_int32 rxgk_make_key(rxgk_key *key_out, void *raw_key, afs_uint32 length,
93 afs_int32 enctype) AFS_NONNULL();
94 afs_int32 rxgk_copy_key(rxgk_key key_in, rxgk_key *key_out) AFS_NONNULL();
95 afs_int32 rxgk_random_key(afs_int32 *enctype, rxgk_key *key_out) AFS_NONNULL();
96 void rxgk_release_key(rxgk_key *key) AFS_NONNULL();
97 afs_int32 rxgk_mic_length(rxgk_key key, size_t *out) AFS_NONNULL();
98 afs_int32 rxgk_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
99 RXGK_Data *out) AFS_NONNULL();
100 afs_int32 rxgk_check_mic_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
101 RXGK_Data *mic) AFS_NONNULL();
102 afs_int32 rxgk_encrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
103 RXGK_Data *out) AFS_NONNULL();
104 afs_int32 rxgk_decrypt_in_key(rxgk_key key, afs_int32 usage, RXGK_Data *in,
105 RXGK_Data *out) AFS_NONNULL();
106 afs_int32 rxgk_derive_tk(rxgk_key *tk, rxgk_key k0, afs_uint32 epoch,
107 afs_uint32 cid, rxgkTime start_time,
108 afs_uint32 key_number) AFS_NONNULL();
109 afs_int32 rxgk_cipher_expansion(rxgk_key k0, afs_uint32 *len_out) AFS_NONNULL();
110 afs_int32 rxgk_nonce(RXGK_Data *nonce, afs_uint32 len) AFS_NONNULL();
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 */