^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * (C) Copyright 2007 Hewlett-Packard Development Company, L.P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Vlad Yasevich <vladislav.yasevich@hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef __sctp_auth_h__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define __sctp_auth_h__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/refcount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct sctp_endpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct sctp_association;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct sctp_authkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct sctp_hmacalgo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct crypto_shash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Define a generic struct that will hold all the info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * necessary for an HMAC transform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct sctp_hmac {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) __u16 hmac_id; /* one of the above ids */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) char *hmac_name; /* name for loading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) __u16 hmac_len; /* length of the signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* This is generic structure that containst authentication bytes used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * as keying material. It's a what is referred to as byte-vector all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * over SCTP-AUTH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct sctp_auth_bytes {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __u8 data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) /* Definition for a shared key, weather endpoint or association */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct sctp_shared_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct list_head key_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct sctp_auth_bytes *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) refcount_t refcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) __u16 key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __u8 deactivated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define key_for_each(__key, __list_head) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) list_for_each_entry(__key, __list_head, key_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define key_for_each_safe(__key, __tmp, __list_head) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) list_for_each_entry_safe(__key, __tmp, __list_head, key_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static inline void sctp_auth_key_hold(struct sctp_auth_bytes *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (!key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) refcount_inc(&key->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) void sctp_auth_key_put(struct sctp_auth_bytes *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct sctp_shared_key *sctp_auth_shkey_create(__u16 key_id, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) void sctp_auth_destroy_keys(struct list_head *keys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int sctp_auth_asoc_init_active_key(struct sctp_association *asoc, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct sctp_shared_key *sctp_auth_get_shkey(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) __u16 key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int sctp_auth_asoc_copy_shkeys(const struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void sctp_auth_destroy_hmacs(struct crypto_shash *auth_hmacs[]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct sctp_hmac *sctp_auth_get_hmac(__u16 hmac_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct sctp_hmac *sctp_auth_asoc_get_hmac(const struct sctp_association *asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void sctp_auth_asoc_set_default_hmac(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct sctp_hmac_algo_param *hmacs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int sctp_auth_asoc_verify_hmac_id(const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) __be16 hmac_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) int sctp_auth_send_cid(enum sctp_cid chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) const struct sctp_association *asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int sctp_auth_recv_cid(enum sctp_cid chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const struct sctp_association *asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void sctp_auth_calculate_hmac(const struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct sk_buff *skb, struct sctp_auth_chunk *auth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct sctp_shared_key *ep_key, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) void sctp_auth_shkey_release(struct sctp_shared_key *sh_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void sctp_auth_shkey_hold(struct sctp_shared_key *sh_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /* API Helpers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int sctp_auth_ep_add_chunkid(struct sctp_endpoint *ep, __u8 chunk_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int sctp_auth_ep_set_hmacs(struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct sctp_hmacalgo *hmacs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int sctp_auth_set_key(struct sctp_endpoint *ep, struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct sctp_authkey *auth_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int sctp_auth_set_active_key(struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct sctp_association *asoc, __u16 key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int sctp_auth_del_key_id(struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct sctp_association *asoc, __u16 key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int sctp_auth_deact_key_id(struct sctp_endpoint *ep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct sctp_association *asoc, __u16 key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int sctp_auth_init(struct sctp_endpoint *ep, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) void sctp_auth_free(struct sctp_endpoint *ep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #endif