Lines Matching refs:aead
37 #include <crypto/aead.h>
143 * @key: the aead key
178 * @aead: array of pointers to AEAD keys for encryption/decryption
202 struct tipc_aead __rcu *aead[KEY_MAX + 1];
236 struct tipc_aead *aead;
243 struct tipc_aead *aead;
247 static struct tipc_aead *tipc_aead_get(struct tipc_aead __rcu *aead);
248 static inline void tipc_aead_put(struct tipc_aead *aead);
250 static int tipc_aead_users(struct tipc_aead __rcu *aead);
251 static void tipc_aead_users_inc(struct tipc_aead __rcu *aead, int lim);
252 static void tipc_aead_users_dec(struct tipc_aead __rcu *aead, int lim);
253 static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val);
254 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead);
255 static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
262 static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
267 static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
271 static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
279 struct tipc_aead *aead, u8 pos,
292 static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
377 static struct tipc_aead *tipc_aead_get(struct tipc_aead __rcu *aead)
382 tmp = rcu_dereference(aead);
390 static inline void tipc_aead_put(struct tipc_aead *aead)
392 if (aead && refcount_dec_and_test(&aead->refcnt))
393 call_rcu(&aead->rcu, tipc_aead_free);
402 struct tipc_aead *aead = container_of(rp, struct tipc_aead, rcu);
405 if (aead->cloned) {
406 tipc_aead_put(aead->cloned);
408 head = *get_cpu_ptr(aead->tfm_entry);
409 put_cpu_ptr(aead->tfm_entry);
420 free_percpu(aead->tfm_entry);
421 kfree_sensitive(aead->key);
422 kfree(aead);
425 static int tipc_aead_users(struct tipc_aead __rcu *aead)
431 tmp = rcu_dereference(aead);
439 static void tipc_aead_users_inc(struct tipc_aead __rcu *aead, int lim)
444 tmp = rcu_dereference(aead);
450 static void tipc_aead_users_dec(struct tipc_aead __rcu *aead, int lim)
455 tmp = rcu_dereference(aead);
457 atomic_add_unless(&rcu_dereference(aead)->users, -1, lim);
461 static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
467 tmp = rcu_dereference(aead);
481 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
486 tfm_entry = get_cpu_ptr(aead->tfm_entry);
496 * @aead: returned new TIPC AEAD key handle pointer
507 static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
516 if (unlikely(*aead))
602 *aead = tmp;
621 struct tipc_aead *aead;
633 aead = kzalloc(sizeof(*aead), GFP_ATOMIC);
634 if (unlikely(!aead))
637 aead->tfm_entry = alloc_percpu_gfp(struct tipc_tfm *, GFP_ATOMIC);
638 if (unlikely(!aead->tfm_entry)) {
639 kfree_sensitive(aead);
644 *per_cpu_ptr(aead->tfm_entry, cpu) =
648 memcpy(aead->hint, src->hint, sizeof(src->hint));
649 aead->mode = src->mode;
650 aead->salt = src->salt;
651 aead->authsize = src->authsize;
652 atomic_set(&aead->users, 0);
653 atomic64_set(&aead->seqno, 0);
654 refcount_set(&aead->refcnt, 1);
657 aead->cloned = src;
659 *dst = aead;
714 * @aead: TIPC AEAD key for the message encryption
725 static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
730 struct crypto_aead *tfm = tipc_aead_tfm_next(aead);
743 tailen = len - skb->len + aead->authsize;
796 salt = aead->salt;
797 if (aead->mode == CLUSTER_KEY)
814 tx_ctx->aead = aead;
842 struct tipc_aead *aead = tx_ctx->aead;
843 struct tipc_crypto *tx = aead->crypto;
866 tipc_aead_put(aead);
872 * @aead: TIPC AEAD for the message decryption
881 static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
895 if (unlikely(!aead))
905 tfm = tipc_aead_tfm_next(aead);
921 salt = aead->salt;
922 if (aead->mode == CLUSTER_KEY)
939 rx_ctx->aead = aead;
966 struct tipc_aead *aead = rx_ctx->aead;
967 struct tipc_crypto_stats __percpu *stats = aead->crypto->stats;
968 struct net *net = aead->crypto->net;
982 tipc_crypto_rcv_complete(net, aead, b, &skb, err);
1027 * @aead: TX AEAD key to be used for the message encryption
1034 static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
1053 if (!__rx || aead->mode == CLUSTER_KEY)
1054 seqno = atomic64_inc_return(&aead->seqno);
1073 ehdr->master_key = aead->crypto->key_master;
1126 struct tipc_aead *aead = NULL;
1130 rc = tipc_aead_init(&aead, ukey, mode);
1134 rc = tipc_crypto_key_attach(c, aead, 0, master_key);
1136 tipc_aead_free(&aead->rcu);
1145 * @aead: the new AEAD key pointer
1152 struct tipc_aead *aead, u8 pos,
1168 if (tipc_aead_users(c->aead[key.pending]) > 0)
1190 aead->crypto = c;
1191 aead->gen = (is_tx(c)) ? ++c->key_gen : c->key_gen;
1192 tipc_aead_rcu_replace(c->aead[new_key], aead, &c->lock);
1225 tipc_aead_users_dec(tx->aead[k], 0);
1234 tipc_crypto_key_detach(c->aead[k], &c->lock);
1270 if (tipc_aead_users(rx->aead[key.pending]) > 0)
1274 tmp1 = tipc_aead_rcu_ptr(rx->aead[key.pending], &rx->lock);
1277 rcu_assign_pointer(rx->aead[key.pending], NULL);
1281 tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, lockdep_is_held(&rx->lock));
1288 rcu_assign_pointer(rx->aead[new_pending], tmp1);
1290 rcu_assign_pointer(rx->aead[new_passive], tmp2);
1320 struct tipc_aead *aead = NULL;
1337 aead = tipc_aead_rcu_ptr(tx->aead[KEY_MASTER], &tx->lock);
1345 aead = tipc_aead_rcu_ptr(tx->aead[k], &tx->lock);
1346 if (!aead)
1348 if (aead->mode != CLUSTER_KEY ||
1349 aead == skb_cb->tx_clone_ctx.last) {
1350 aead = NULL;
1354 skb_cb->tx_clone_ctx.last = aead;
1363 if (likely(aead))
1364 WARN_ON(!refcount_inc_not_zero(&aead->refcnt));
1367 return aead;
1430 tipc_aead_users_inc(tx->aead[new], INT_MAX);
1432 tipc_aead_users_dec(tx->aead[cur], 0);
1454 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1535 tipc_aead_put(rcu_dereference(c->aead[k]));
1556 if (key.active && tipc_aead_users(tx->aead[key.active]) > 0)
1558 if (!key.pending || tipc_aead_users(tx->aead[key.pending]) <= 0)
1565 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1575 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) <= 0)
1589 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) > -10)
1593 tipc_crypto_key_detach(rx->aead[key.pending], &rx->lock);
1602 tipc_aead_users(rx->aead[key.active]) > 0)
1611 tipc_aead_users_set(rx->aead[key.pending], 0);
1620 tipc_aead_users(rx->aead[key.passive]) > -10)
1624 tipc_crypto_key_detach(rx->aead[key.passive], &rx->lock);
1693 struct tipc_aead *aead = NULL;
1755 aead = tipc_aead_get(tx->aead[tx_key]);
1756 if (unlikely(!aead))
1758 rc = tipc_ehdr_build(net, aead, tx_key, *skb, __rx);
1760 rc = tipc_aead_encrypt(aead, *skb, b, dst, __dnode);
1783 tipc_aead_put(aead);
1814 struct tipc_aead *aead = NULL;
1839 aead = tipc_crypto_key_pick_tx(tx, rx, *skb, tx_key);
1840 if (aead)
1846 if (!aead)
1847 aead = tipc_aead_get(rx->aead[tx_key]);
1848 rc = tipc_aead_decrypt(net, aead, *skb, b);
1874 rcu_access_pointer(rx->aead[n]));
1888 tipc_crypto_rcv_complete(net, aead, b, skb, rc);
1892 static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
1897 struct tipc_crypto *rx = aead->crypto;
1903 if (unlikely(is_tx(aead->crypto))) {
1905 pr_debug("TX->RX(%s): err %d, aead %p, skb->next %p, flags %x\n",
1906 (rx) ? tipc_node_get_id_str(rx->node) : "-", err, aead,
1908 pr_debug("skb_cb [recurs %d, last %p], tx->aead [%p %p %p]\n",
1910 aead->crypto->aead[1], aead->crypto->aead[2],
1911 aead->crypto->aead[3]);
1935 if (tipc_aead_clone(&tmp, aead) < 0)
1942 tipc_aead_put(aead);
1943 aead = tmp;
1947 tipc_aead_users_dec(aead, INT_MIN);
1952 tipc_aead_users_set(aead, 1);
1967 if (pskb_trim(*skb, (*skb)->len - aead->authsize))
1997 tipc_aead_put(aead);
2078 struct tipc_aead *aead;
2104 aead = rcu_dereference(c->aead[k]);
2105 if (aead)
2108 aead->hint,
2109 (aead->mode == CLUSTER_KEY) ? "c" : "p",
2110 atomic_read(&aead->users),
2111 refcount_read(&aead->refcnt));
2198 struct tipc_aead *aead;
2207 aead = tipc_aead_get(tx->aead[key]);
2208 if (likely(aead)) {
2209 rc = tipc_crypto_key_xmit(tx->net, aead->key,
2210 aead->gen, aead->mode,
2212 tipc_aead_put(aead);
2445 struct tipc_aead *aead;
2453 aead = rcu_dereference(tx->aead[key.active ?: KEY_MASTER]);
2454 if (unlikely(!aead)) {
2461 skey = kmemdup(aead->key, tipc_aead_key_size(aead->key), GFP_ATOMIC);