Lines Matching full:aead
37 #include <crypto/aead.h>
135 * struct tipc_aead - TIPC AEAD key structure
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,
330 * tipc_aead_key_validate - Validate a AEAD user key
374 static struct tipc_aead *tipc_aead_get(struct tipc_aead __rcu *aead)
379 tmp = rcu_dereference(aead);
387 static inline void tipc_aead_put(struct tipc_aead *aead)
389 if (aead && refcount_dec_and_test(&aead->refcnt))
390 call_rcu(&aead->rcu, tipc_aead_free);
394 * tipc_aead_free - Release AEAD key incl. all the TFMs in the list
399 struct tipc_aead *aead = container_of(rp, struct tipc_aead, rcu);
402 if (aead->cloned) {
403 tipc_aead_put(aead->cloned);
405 head = *get_cpu_ptr(aead->tfm_entry);
406 put_cpu_ptr(aead->tfm_entry);
417 free_percpu(aead->tfm_entry);
418 kfree_sensitive(aead->key);
419 kfree_sensitive(aead);
422 static int tipc_aead_users(struct tipc_aead __rcu *aead)
428 tmp = rcu_dereference(aead);
436 static void tipc_aead_users_inc(struct tipc_aead __rcu *aead, int lim)
441 tmp = rcu_dereference(aead);
447 static void tipc_aead_users_dec(struct tipc_aead __rcu *aead, int lim)
452 tmp = rcu_dereference(aead);
458 static void tipc_aead_users_set(struct tipc_aead __rcu *aead, int val)
464 tmp = rcu_dereference(aead);
477 * @aead: the AEAD key pointer
479 static struct crypto_aead *tipc_aead_tfm_next(struct tipc_aead *aead)
484 tfm_entry = get_cpu_ptr(aead->tfm_entry);
493 * tipc_aead_init - Initiate TIPC AEAD
494 * @aead: returned new TIPC AEAD key handle pointer
501 * Also, all the other AEAD data are also initialized.
505 static int tipc_aead_init(struct tipc_aead **aead, struct tipc_aead_key *ukey,
514 if (unlikely(*aead))
517 /* Allocate a new AEAD */
600 *aead = tmp;
605 * tipc_aead_clone - Clone a TIPC AEAD key
609 * Make a "copy" of the source AEAD key data to the dest, the TFMs list is
619 struct tipc_aead *aead;
631 aead = kzalloc_obj(*aead, GFP_ATOMIC);
632 if (unlikely(!aead))
635 aead->tfm_entry = alloc_percpu_gfp(struct tipc_tfm *, GFP_ATOMIC);
636 if (unlikely(!aead->tfm_entry)) {
637 kfree_sensitive(aead);
642 *per_cpu_ptr(aead->tfm_entry, cpu) =
646 memcpy(aead->hint, src->hint, sizeof(src->hint));
647 aead->mode = src->mode;
648 aead->salt = src->salt;
649 aead->authsize = src->authsize;
650 atomic_set(&aead->users, 0);
651 atomic64_set(&aead->seqno, 0);
652 refcount_set(&aead->refcnt, 1);
655 aead->cloned = src;
657 *dst = aead;
662 * tipc_aead_mem_alloc - Allocate memory for AEAD request operations
666 * @req: returned pointer to AEAD request data
670 * Allocate memory to store the crypto context data, AEAD request, IV and SG
712 * @aead: TIPC AEAD key for the message encryption
723 static int tipc_aead_encrypt(struct tipc_aead *aead, struct sk_buff *skb,
728 struct crypto_aead *tfm = tipc_aead_tfm_next(aead);
741 tailen = len - skb->len + aead->authsize;
763 /* Allocate memory for the AEAD operation */
783 salt = aead->salt;
784 if (aead->mode == CLUSTER_KEY)
801 tx_ctx->aead = aead;
812 if (!maybe_get_net(aead->crypto->net)) {
824 put_net(aead->crypto->net);
837 struct tipc_aead *aead = tx_ctx->aead;
838 struct tipc_crypto *tx = aead->crypto;
861 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))
900 /* Allocate memory for the AEAD operation */
901 tfm = tipc_aead_tfm_next(aead);
917 salt = aead->salt;
918 if (aead->mode == CLUSTER_KEY)
935 rx_ctx->aead = aead;
970 struct tipc_aead *aead = rx_ctx->aead;
971 struct tipc_crypto_stats __percpu *stats = aead->crypto->stats;
972 struct net *net = aead->crypto->net;
986 tipc_crypto_rcv_complete(net, aead, b, &skb, err);
1032 * @aead: TX AEAD key to be used for the message encryption
1039 static int tipc_ehdr_build(struct net *net, struct tipc_aead *aead,
1058 if (!__rx || aead->mode == CLUSTER_KEY)
1059 seqno = atomic64_inc_return(&aead->seqno);
1078 ehdr->master_key = aead->crypto->key_master;
1117 * tipc_crypto_key_init - Initiate a new user / AEAD key
1123 * A new TIPC AEAD key will be allocated and initiated with the specified user
1131 struct tipc_aead *aead = NULL;
1135 rc = tipc_aead_init(&aead, ukey, mode);
1139 rc = tipc_crypto_key_attach(c, aead, 0, master_key);
1141 tipc_aead_free(&aead->rcu);
1148 * tipc_crypto_key_attach - Attach a new AEAD key to TIPC crypto
1149 * @c: TIPC crypto to which the new AEAD key is attached
1150 * @aead: the new AEAD key pointer
1157 struct tipc_aead *aead, u8 pos,
1173 if (tipc_aead_users(c->aead[key.pending]) > 0)
1195 aead->crypto = c;
1196 aead->gen = (is_tx(c)) ? ++c->key_gen : c->key_gen;
1197 tipc_aead_rcu_replace(c->aead[new_key], aead, &c->lock);
1230 tipc_aead_users_dec(tx->aead[k], 0);
1239 tipc_crypto_key_detach(c->aead[k], &c->lock);
1275 if (tipc_aead_users(rx->aead[key.pending]) > 0)
1279 tmp1 = tipc_aead_rcu_ptr(rx->aead[key.pending], &rx->lock);
1282 rcu_assign_pointer(rx->aead[key.pending], NULL);
1286 tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, lockdep_is_held(&rx->lock));
1293 rcu_assign_pointer(rx->aead[new_pending], tmp1);
1295 rcu_assign_pointer(rx->aead[new_passive], tmp2);
1317 * Return: the TX AEAD key handle in case of success, otherwise NULL
1325 struct tipc_aead *aead = NULL;
1342 aead = tipc_aead_rcu_ptr(tx->aead[KEY_MASTER], &tx->lock);
1350 aead = tipc_aead_rcu_ptr(tx->aead[k], &tx->lock);
1351 if (!aead)
1353 if (aead->mode != CLUSTER_KEY ||
1354 aead == skb_cb->tx_clone_ctx.last) {
1355 aead = NULL;
1359 skb_cb->tx_clone_ctx.last = aead;
1368 if (likely(aead))
1369 WARN_ON(!refcount_inc_not_zero(&aead->refcnt));
1372 return aead;
1435 tipc_aead_users_inc(tx->aead[new], INT_MAX);
1437 tipc_aead_users_dec(tx->aead[cur], 0);
1459 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1537 /* Release AEAD keys */
1540 tipc_aead_put(rcu_dereference(c->aead[k]));
1561 if (key.active && tipc_aead_users(tx->aead[key.active]) > 0)
1563 if (!key.pending || tipc_aead_users(tx->aead[key.pending]) <= 0)
1570 tipc_crypto_key_detach(tx->aead[key.active], &tx->lock);
1580 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) <= 0)
1594 if (!key.pending || tipc_aead_users(rx->aead[key.pending]) > -10)
1598 tipc_crypto_key_detach(rx->aead[key.pending], &rx->lock);
1607 tipc_aead_users(rx->aead[key.active]) > 0)
1616 tipc_aead_users_set(rx->aead[key.pending], 0);
1625 tipc_aead_users(rx->aead[key.passive]) > -10)
1629 tipc_crypto_key_detach(rx->aead[key.passive], &rx->lock);
1698 struct tipc_aead *aead = NULL;
1760 aead = tipc_aead_get(tx->aead[tx_key]);
1761 if (unlikely(!aead))
1763 rc = tipc_ehdr_build(net, aead, tx_key, *skb, __rx);
1765 rc = tipc_aead_encrypt(aead, *skb, b, dst, __dnode);
1788 tipc_aead_put(aead);
1819 struct tipc_aead *aead = NULL;
1844 aead = tipc_crypto_key_pick_tx(tx, rx, *skb, tx_key);
1845 if (aead)
1851 if (!aead)
1852 aead = tipc_aead_get(rx->aead[tx_key]);
1853 rc = tipc_aead_decrypt(net, aead, *skb, b);
1879 rcu_access_pointer(rx->aead[n]));
1893 tipc_crypto_rcv_complete(net, aead, b, skb, rc);
1897 static void tipc_crypto_rcv_complete(struct net *net, struct tipc_aead *aead,
1902 struct tipc_crypto *rx = aead->crypto;
1908 if (unlikely(is_tx(aead->crypto))) {
1910 pr_debug("TX->RX(%s): err %d, aead %p, skb->next %p, flags %x\n",
1911 (rx) ? tipc_node_get_id_str(rx->node) : "-", err, aead,
1913 pr_debug("skb_cb [recurs %d, last %p], tx->aead [%p %p %p]\n",
1915 aead->crypto->aead[1], aead->crypto->aead[2],
1916 aead->crypto->aead[3]);
1940 if (tipc_aead_clone(&tmp, aead) < 0)
1947 tipc_aead_put(aead);
1948 aead = tmp;
1952 tipc_aead_users_dec((struct tipc_aead __force __rcu *)aead, INT_MIN);
1957 tipc_aead_users_set((struct tipc_aead __force __rcu *)aead, 1);
1972 if (pskb_trim(*skb, (*skb)->len - aead->authsize))
2002 tipc_aead_put(aead);
2083 struct tipc_aead *aead;
2109 aead = rcu_dereference(c->aead[k]);
2110 if (aead)
2113 aead->hint,
2114 (aead->mode == CLUSTER_KEY) ? "c" : "p",
2115 atomic_read(&aead->users),
2116 refcount_read(&aead->refcnt));
2203 struct tipc_aead *aead;
2212 aead = tipc_aead_get(tx->aead[key]);
2213 if (likely(aead)) {
2214 rc = tipc_crypto_key_xmit(tx->net, aead->key,
2215 aead->gen, aead->mode,
2217 tipc_aead_put(aead);
2450 struct tipc_aead *aead;
2458 aead = rcu_dereference(tx->aead[key.active ?: KEY_MASTER]);
2459 if (unlikely(!aead)) {
2466 skey = kmemdup(aead->key, tipc_aead_key_size(aead->key), GFP_ATOMIC);