37 #include <linux/slab.h>
38 #include <linux/types.h>
51 .hmac_name=
"hmac(sha1)",
58 #if defined (CONFIG_CRYPTO_SHA256) || defined (CONFIG_CRYPTO_SHA256_MODULE)
60 .hmac_id = SCTP_AUTH_HMAC_ID_SHA256,
61 .hmac_name=
"hmac(sha256)",
110 INIT_LIST_HEAD(&new->key_list);
133 if (list_empty(keys))
138 sctp_auth_shkey_free(ep_key);
165 diff = vector1->
len - vector2->
len;
167 longer = (diff > 0) ? vector1->
data : vector2->
data;
173 for (i = 0; i <
abs(diff); i++ ) {
218 memcpy(new->data + offset, chunks,
234 return sctp_auth_make_key_vector(
246 return sctp_auth_make_key_vector(asoc->
peer.peer_random,
247 asoc->
peer.peer_chunks,
248 asoc->
peer.peer_hmacs,
272 auth_len = first_vector->
len + last_vector->
len;
274 auth_len += ep_key->
key->len;
276 secret = sctp_auth_create_key(auth_len, gfp);
282 offset += ep_key->
key->len;
286 offset += first_vector->
len;
321 local_key_vector = sctp_auth_make_local_vector(asoc, gfp);
322 peer_key_vector = sctp_auth_make_peer_vector(asoc, gfp);
324 if (!peer_key_vector || !local_key_vector)
340 cmp = sctp_auth_compare_vectors(local_key_vector,
343 first_vector = local_key_vector;
344 last_vector = peer_key_vector;
346 first_vector = peer_key_vector;
347 last_vector = local_key_vector;
350 secret = sctp_auth_asoc_set_secret(ep_key, first_vector, last_vector,
353 kfree(local_key_vector);
354 kfree(peer_key_vector);
377 new->key = sh_key->
key;
378 sctp_auth_key_hold(new->key);
402 if (!net->sctp.auth_enable || !asoc->
peer.auth_capable)
413 secret = sctp_auth_asoc_create_secret(asoc, ep_key, gfp);
433 if (key->
key_id == key_id)
454 if (!net->sctp.auth_enable) {
476 if (!sctp_hmac_list[
id].hmac_name)
484 tfm = crypto_alloc_hash(sctp_hmac_list[
id].hmac_name, 0,
511 crypto_free_hash(auth_hmacs[i]);
519 return &sctp_hmac_list[
hmac_id];
539 hmacs = asoc->
peer.peer_hmacs;
544 for (i = 0; i < n_elt; i++) {
558 if (!sctp_hmac_list[
id].hmac_name) {
569 return &sctp_hmac_list[
id];
572 static int __sctp_auth_find_hmacid(
__be16 *hmacs,
int n_elts,
__be16 hmac_id)
577 for (i = 0; i < n_elts; i++) {
578 if (hmac_id == hmacs[i]) {
600 return __sctp_auth_find_hmacid(hmacs->
hmac_ids, n_elt, hmac_id);
624 for (i = 0; i < n_params; i++) {
658 for (i = 0; !found && i < len; i++) {
659 switch (param->
chunks[i]) {
667 if (param->
chunks[i] == chunk)
683 net = sock_net(asoc->
base.sk);
684 if (!net->sctp.auth_enable || !asoc->
peer.auth_capable)
687 return __sctp_auth_cid(chunk, asoc->
peer.peer_chunks);
697 net = sock_net(asoc->
base.sk);
698 if (!net->sctp.auth_enable)
701 return __sctp_auth_cid(chunk,
743 asoc_key = sctp_auth_asoc_create_secret(asoc, ep_key, gfp);
751 end = skb_tail_pointer(skb);
752 sg_init_one(&sg, auth, end - (
unsigned char *)auth);
754 desc.
tfm = asoc->
ep->auth_hmacs[hmac_id];
758 if (crypto_hash_setkey(desc.
tfm, &asoc_key->
data[0], asoc_key->
len))
761 crypto_hash_digest(&desc, &sg, sg.
length, digest);
778 if (__sctp_auth_cid(chunk_id, p))
787 p->
chunks[nchunks] = chunk_id;
812 if (!sctp_hmac_list[
id].hmac_name)
878 list_add(&cur_key->
key_list, sh_keys);
881 sctp_auth_key_hold(key);
886 sctp_auth_shkey_free(cur_key);
906 if (key->
key_id == key_id) {
948 if (key->
key_id == key_id) {
959 sctp_auth_shkey_free(key);