Lines Matching refs:aead

37 #include <crypto/aead.h>
145 * @key: the aead key
181 * @aead: array of pointers to AEAD keys for encryption/decryption
206 struct tipc_aead __rcu *aead[KEY_MAX + 1];
240 struct tipc_aead *aead;
247 struct tipc_aead *aead;
251 static struct tipc_aead *tipc_aead_get(struct tipc_aead __rcu *aead);
252 static inline void tipc_aead_put(struct tipc_aead *aead);
254 static int tipc_aead_users(struct tipc_aead __rcu *aead);
255 static void tipc_aead_users_inc(struct tipc_aead __rcu *aead, int lim);
256 static void tipc_aead_users_dec(struct tipc_aead __rcu *aead, int lim);
257 static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val);
258 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead);
259 static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
266 static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
271 static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
275 static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
283 struct tipc_aead *aead, u8 pos,
296 static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
383 static struct tipc_aead *tipc_aead_get(struct tipc_aead __rcu *aead)
388 tmp = rcu_dereference(aead);
396 static inline void tipc_aead_put(struct tipc_aead *aead)
398 if (aead && refcount_dec_and_test(&aead->refcnt))
399 call_rcu(&aead->rcu, tipc_aead_free);
408 struct tipc_aead *aead = container_of(rp, struct tipc_aead, rcu);
411 if (aead->cloned) {
412 tipc_aead_put(aead->cloned);
414 head = *get_cpu_ptr(aead->tfm_entry);
415 put_cpu_ptr(aead->tfm_entry);
426 free_percpu(aead->tfm_entry);
427 kfree_sensitive(aead->key);
428 kfree(aead);
431 static int tipc_aead_users(struct tipc_aead __rcu *aead)
437 tmp = rcu_dereference(aead);
445 static void tipc_aead_users_inc(struct tipc_aead __rcu *aead, int lim)
450 tmp = rcu_dereference(aead);
456 static void tipc_aead_users_dec(struct tipc_aead __rcu *aead, int lim)
461 tmp = rcu_dereference(aead);
463 atomic_add_unless(&rcu_dereference(aead)->users, -1, lim);
467 static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
473 tmp = rcu_dereference(aead);
486 * @aead: the AEAD key pointer
488 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
493 tfm_entry = get_cpu_ptr(aead->tfm_entry);
503 * @aead: returned new TIPC AEAD key handle pointer
514 static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
523 if (unlikely(*aead))
609 *aead = tmp;
628 struct tipc_aead *aead;
640 aead = kzalloc(sizeof(*aead), GFP_ATOMIC);
641 if (unlikely(!aead))
644 aead->tfm_entry = alloc_percpu_gfp(struct tipc_tfm *, GFP_ATOMIC);
645 if (unlikely(!aead->tfm_entry)) {
646 kfree_sensitive(aead);
651 *per_cpu_ptr(aead->tfm_entry, cpu) =
655 memcpy(aead->hint, src->hint, sizeof(src->hint));
656 aead->mode = src->mode;
657 aead->salt = src->salt;
658 aead->authsize = src->authsize;
659 atomic_set(&aead->users, 0);
660 atomic64_set(&aead->seqno, 0);
661 refcount_set(&aead->refcnt, 1);
664 aead->cloned = src;
666 *dst = aead;
721 * @aead: TIPC AEAD key for the message encryption
732 static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
737 struct crypto_aead *tfm = tipc_aead_tfm_next(aead);
750 tailen = len - skb->len + aead->authsize;
792 salt = aead->salt;
793 if (aead->mode == CLUSTER_KEY)
810 tx_ctx->aead = aead;
838 struct tipc_aead *aead = tx_ctx->aead;
839 struct tipc_crypto *tx = aead->crypto;
862 tipc_aead_put(aead);
868 * @aead: TIPC AEAD for the message decryption
877 static int tipc_aead_decrypt(struct net *net, struct tipc_aead *aead,
891 if (unlikely(!aead))
901 tfm = tipc_aead_tfm_next(aead);
917 salt = aead->salt;
918 if (aead->mode == CLUSTER_KEY)
935 rx_ctx->aead = aead;
962 struct tipc_aead *aead = rx_ctx->aead;
963 struct tipc_crypto_stats __percpu *stats = aead->crypto->stats;
964 struct net *net = aead->crypto->net;
978 tipc_crypto_rcv_complete(net, aead, b, &skb, err);
1023 * @aead: TX AEAD key to be used for the message encryption
1030 static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
1049 if (!__rx || aead->mode == CLUSTER_KEY)
1050 seqno = atomic64_inc_return(&aead->seqno);
1069 ehdr->master_key = aead->crypto->key_master;
1122 struct tipc_aead *aead = NULL;
1126 rc = tipc_aead_init(&aead, ukey, mode);
1130 rc = tipc_crypto_key_attach(c, aead, 0, master_key);
1132 tipc_aead_free(&aead->rcu);
1141 * @aead: the new AEAD key pointer
1148 struct tipc_aead *aead, u8 pos,
1164 if (tipc_aead_users(c->aead[key.pending]) > 0)
1186 aead->crypto = c;
1187 aead->gen = (is_tx(c)) ? ++c->key_gen : c->key_gen;
1188 tipc_aead_rcu_replace(c->aead[new_key], aead, &c->lock);
1221 tipc_aead_users_dec(tx->aead[k], 0);
1230 tipc_crypto_key_detach(c->aead[k], &c->lock);
1266 if (tipc_aead_users(rx->aead[key.pending]) > 0)
1270 tmp1 = tipc_aead_rcu_ptr(rx->aead[key.pending], &rx->lock);
1273 rcu_assign_pointer(rx->aead[key.pending], NULL);
1277 tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, lockdep_is_held(&rx->lock));
1284 rcu_assign_pointer(rx->aead[new_pending], tmp1);
1286 rcu_assign_pointer(rx->aead[new_passive], tmp2);
1316 struct tipc_aead *aead = NULL;
1333 aead = tipc_aead_rcu_ptr(tx->aead[KEY_MASTER], &tx->lock);
1341 aead = tipc_aead_rcu_ptr(tx->aead[k], &tx->lock);
1342 if (!aead)
1344 if (aead->mode != CLUSTER_KEY ||
1345 aead == skb_cb->tx_clone_ctx.last) {
1346 aead = NULL;
1350 skb_cb->tx_clone_ctx.last = aead;
1359 if (likely(aead))
1360 WARN_ON(!refcount_inc_not_zero(&aead->refcnt));
1363 return aead;
1426 tipc_aead_users_inc(tx->aead[new], INT_MAX);
1428 tipc_aead_users_dec(tx->aead[cur], 0);
1450 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1531 tipc_aead_put(rcu_dereference(c->aead[k]));
1552 if (key.active && tipc_aead_users(tx->aead[key.active]) > 0)
1554 if (!key.pending || tipc_aead_users(tx->aead[key.pending]) <= 0)
1561 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1571 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) <= 0)
1585 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) > -10)
1589 tipc_crypto_key_detach(rx->aead[key.pending], &rx->lock);
1598 tipc_aead_users(rx->aead[key.active]) > 0)
1607 tipc_aead_users_set(rx->aead[key.pending], 0);
1616 tipc_aead_users(rx->aead[key.passive]) > -10)
1620 tipc_crypto_key_detach(rx->aead[key.passive], &rx->lock);
1689 struct tipc_aead *aead = NULL;
1751 aead = tipc_aead_get(tx->aead[tx_key]);
1752 if (unlikely(!aead))
1754 rc = tipc_ehdr_build(net, aead, tx_key, *skb, __rx);
1756 rc = tipc_aead_encrypt(aead, *skb, b, dst, __dnode);
1779 tipc_aead_put(aead);
1810 struct tipc_aead *aead = NULL;
1835 aead = tipc_crypto_key_pick_tx(tx, rx, *skb, tx_key);
1836 if (aead)
1842 if (!aead)
1843 aead = tipc_aead_get(rx->aead[tx_key]);
1844 rc = tipc_aead_decrypt(net, aead, *skb, b);
1870 rcu_access_pointer(rx->aead[n]));
1884 tipc_crypto_rcv_complete(net, aead, b, skb, rc);
1888 static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
1893 struct tipc_crypto *rx = aead->crypto;
1899 if (unlikely(is_tx(aead->crypto))) {
1901 pr_debug("TX->RX(%s): err %d, aead %p, skb->next %p, flags %x\n",
1902 (rx) ? tipc_node_get_id_str(rx->node) : "-", err, aead,
1904 pr_debug("skb_cb [recurs %d, last %p], tx->aead [%p %p %p]\n",
1906 aead->crypto->aead[1], aead->crypto->aead[2],
1907 aead->crypto->aead[3]);
1931 if (tipc_aead_clone(&tmp, aead) < 0)
1938 tipc_aead_put(aead);
1939 aead = tmp;
1943 tipc_aead_users_dec((struct tipc_aead __force __rcu *)aead, INT_MIN);
1948 tipc_aead_users_set((struct tipc_aead __force __rcu *)aead, 1);
1963 if (pskb_trim(*skb, (*skb)->len - aead->authsize))
1993 tipc_aead_put(aead);
2074 struct tipc_aead *aead;
2100 aead = rcu_dereference(c->aead[k]);
2101 if (aead)
2104 aead->hint,
2105 (aead->mode == CLUSTER_KEY) ? "c" : "p",
2106 atomic_read(&aead->users),
2107 refcount_read(&aead->refcnt));
2194 struct tipc_aead *aead;
2203 aead = tipc_aead_get(tx->aead[key]);
2204 if (likely(aead)) {
2205 rc = tipc_crypto_key_xmit(tx->net, aead->key,
2206 aead->gen, aead->mode,
2208 tipc_aead_put(aead);
2441 struct tipc_aead *aead;
2449 aead = rcu_dereference(tx->aead[key.active ?: KEY_MASTER]);
2450 if (unlikely(!aead)) {
2457 skey = kmemdup(aead->key, tipc_aead_key_size(aead->key), GFP_ATOMIC);