18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* SCTP kernel implementation 38c2ecf20Sopenharmony_ci * (C) Copyright 2007 Hewlett-Packard Development Company, L.P. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This file is part of the SCTP kernel implementation 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Please send any bug reports or fixes you make to the 88c2ecf20Sopenharmony_ci * email address(es): 98c2ecf20Sopenharmony_ci * lksctp developers <linux-sctp@vger.kernel.org> 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Written or modified by: 128c2ecf20Sopenharmony_ci * Vlad Yasevich <vladislav.yasevich@hp.com> 138c2ecf20Sopenharmony_ci */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#ifndef __sctp_auth_h__ 168c2ecf20Sopenharmony_ci#define __sctp_auth_h__ 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <linux/list.h> 198c2ecf20Sopenharmony_ci#include <linux/refcount.h> 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_cistruct sctp_endpoint; 228c2ecf20Sopenharmony_cistruct sctp_association; 238c2ecf20Sopenharmony_cistruct sctp_authkey; 248c2ecf20Sopenharmony_cistruct sctp_hmacalgo; 258c2ecf20Sopenharmony_cistruct crypto_shash; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* 288c2ecf20Sopenharmony_ci * Define a generic struct that will hold all the info 298c2ecf20Sopenharmony_ci * necessary for an HMAC transform 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_cistruct sctp_hmac { 328c2ecf20Sopenharmony_ci __u16 hmac_id; /* one of the above ids */ 338c2ecf20Sopenharmony_ci char *hmac_name; /* name for loading */ 348c2ecf20Sopenharmony_ci __u16 hmac_len; /* length of the signature */ 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci/* This is generic structure that containst authentication bytes used 388c2ecf20Sopenharmony_ci * as keying material. It's a what is referred to as byte-vector all 398c2ecf20Sopenharmony_ci * over SCTP-AUTH 408c2ecf20Sopenharmony_ci */ 418c2ecf20Sopenharmony_cistruct sctp_auth_bytes { 428c2ecf20Sopenharmony_ci refcount_t refcnt; 438c2ecf20Sopenharmony_ci __u32 len; 448c2ecf20Sopenharmony_ci __u8 data[]; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* Definition for a shared key, weather endpoint or association */ 488c2ecf20Sopenharmony_cistruct sctp_shared_key { 498c2ecf20Sopenharmony_ci struct list_head key_list; 508c2ecf20Sopenharmony_ci struct sctp_auth_bytes *key; 518c2ecf20Sopenharmony_ci refcount_t refcnt; 528c2ecf20Sopenharmony_ci __u16 key_id; 538c2ecf20Sopenharmony_ci __u8 deactivated; 548c2ecf20Sopenharmony_ci}; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define key_for_each(__key, __list_head) \ 578c2ecf20Sopenharmony_ci list_for_each_entry(__key, __list_head, key_list) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define key_for_each_safe(__key, __tmp, __list_head) \ 608c2ecf20Sopenharmony_ci list_for_each_entry_safe(__key, __tmp, __list_head, key_list) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic inline void sctp_auth_key_hold(struct sctp_auth_bytes *key) 638c2ecf20Sopenharmony_ci{ 648c2ecf20Sopenharmony_ci if (!key) 658c2ecf20Sopenharmony_ci return; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci refcount_inc(&key->refcnt); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid sctp_auth_key_put(struct sctp_auth_bytes *key); 718c2ecf20Sopenharmony_cistruct sctp_shared_key *sctp_auth_shkey_create(__u16 key_id, gfp_t gfp); 728c2ecf20Sopenharmony_civoid sctp_auth_destroy_keys(struct list_head *keys); 738c2ecf20Sopenharmony_ciint sctp_auth_asoc_init_active_key(struct sctp_association *asoc, gfp_t gfp); 748c2ecf20Sopenharmony_cistruct sctp_shared_key *sctp_auth_get_shkey( 758c2ecf20Sopenharmony_ci const struct sctp_association *asoc, 768c2ecf20Sopenharmony_ci __u16 key_id); 778c2ecf20Sopenharmony_ciint sctp_auth_asoc_copy_shkeys(const struct sctp_endpoint *ep, 788c2ecf20Sopenharmony_ci struct sctp_association *asoc, 798c2ecf20Sopenharmony_ci gfp_t gfp); 808c2ecf20Sopenharmony_ciint sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp); 818c2ecf20Sopenharmony_civoid sctp_auth_destroy_hmacs(struct crypto_shash *auth_hmacs[]); 828c2ecf20Sopenharmony_cistruct sctp_hmac *sctp_auth_get_hmac(__u16 hmac_id); 838c2ecf20Sopenharmony_cistruct sctp_hmac *sctp_auth_asoc_get_hmac(const struct sctp_association *asoc); 848c2ecf20Sopenharmony_civoid sctp_auth_asoc_set_default_hmac(struct sctp_association *asoc, 858c2ecf20Sopenharmony_ci struct sctp_hmac_algo_param *hmacs); 868c2ecf20Sopenharmony_ciint sctp_auth_asoc_verify_hmac_id(const struct sctp_association *asoc, 878c2ecf20Sopenharmony_ci __be16 hmac_id); 888c2ecf20Sopenharmony_ciint sctp_auth_send_cid(enum sctp_cid chunk, 898c2ecf20Sopenharmony_ci const struct sctp_association *asoc); 908c2ecf20Sopenharmony_ciint sctp_auth_recv_cid(enum sctp_cid chunk, 918c2ecf20Sopenharmony_ci const struct sctp_association *asoc); 928c2ecf20Sopenharmony_civoid sctp_auth_calculate_hmac(const struct sctp_association *asoc, 938c2ecf20Sopenharmony_ci struct sk_buff *skb, struct sctp_auth_chunk *auth, 948c2ecf20Sopenharmony_ci struct sctp_shared_key *ep_key, gfp_t gfp); 958c2ecf20Sopenharmony_civoid sctp_auth_shkey_release(struct sctp_shared_key *sh_key); 968c2ecf20Sopenharmony_civoid sctp_auth_shkey_hold(struct sctp_shared_key *sh_key); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* API Helpers */ 998c2ecf20Sopenharmony_ciint sctp_auth_ep_add_chunkid(struct sctp_endpoint *ep, __u8 chunk_id); 1008c2ecf20Sopenharmony_ciint sctp_auth_ep_set_hmacs(struct sctp_endpoint *ep, 1018c2ecf20Sopenharmony_ci struct sctp_hmacalgo *hmacs); 1028c2ecf20Sopenharmony_ciint sctp_auth_set_key(struct sctp_endpoint *ep, struct sctp_association *asoc, 1038c2ecf20Sopenharmony_ci struct sctp_authkey *auth_key); 1048c2ecf20Sopenharmony_ciint sctp_auth_set_active_key(struct sctp_endpoint *ep, 1058c2ecf20Sopenharmony_ci struct sctp_association *asoc, __u16 key_id); 1068c2ecf20Sopenharmony_ciint sctp_auth_del_key_id(struct sctp_endpoint *ep, 1078c2ecf20Sopenharmony_ci struct sctp_association *asoc, __u16 key_id); 1088c2ecf20Sopenharmony_ciint sctp_auth_deact_key_id(struct sctp_endpoint *ep, 1098c2ecf20Sopenharmony_ci struct sctp_association *asoc, __u16 key_id); 1108c2ecf20Sopenharmony_ciint sctp_auth_init(struct sctp_endpoint *ep, gfp_t gfp); 1118c2ecf20Sopenharmony_civoid sctp_auth_free(struct sctp_endpoint *ep); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci#endif 114