Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: x86/curve25519 - Remove unused kpp support

Curve25519 is used only via the library API, not the crypto_kpp API. In
preparation for removing the unused crypto_kpp API for Curve25519,
remove the unused "curve25519-x86" kpp algorithm.

Note that the underlying x86_64 optimized Curve25519 code remains fully
supported and accessible via the library API.

It's also worth noting that even if the kpp support for Curve25519 comes
back later, there is no need for arch-specific kpp glue code like this,
as a single kpp algorithm that wraps the library API is sufficient.

Link: https://lore.kernel.org/r/20250906213523.84915-5-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+1 -98
-1
arch/x86/crypto/Kconfig
··· 5 5 config CRYPTO_CURVE25519_X86 6 6 tristate 7 7 depends on 64BIT 8 - select CRYPTO_KPP 9 8 select CRYPTO_LIB_CURVE25519_GENERIC 10 9 select CRYPTO_ARCH_HAVE_LIB_CURVE25519 11 10 default CRYPTO_LIB_CURVE25519_INTERNAL
+1 -97
arch/x86/crypto/curve25519-x86_64.c
··· 5 5 */ 6 6 7 7 #include <crypto/curve25519.h> 8 - #include <crypto/internal/kpp.h> 9 8 10 9 #include <linux/export.h> 11 10 #include <linux/types.h> 12 11 #include <linux/jump_label.h> 13 12 #include <linux/kernel.h> 14 13 #include <linux/module.h> 15 - #include <linux/scatterlist.h> 16 14 17 15 #include <asm/cpufeature.h> 18 16 #include <asm/processor.h> ··· 1611 1613 } 1612 1614 EXPORT_SYMBOL(curve25519_base_arch); 1613 1615 1614 - static int curve25519_set_secret(struct crypto_kpp *tfm, const void *buf, 1615 - unsigned int len) 1616 - { 1617 - u8 *secret = kpp_tfm_ctx(tfm); 1618 - 1619 - if (!len) 1620 - curve25519_generate_secret(secret); 1621 - else if (len == CURVE25519_KEY_SIZE && 1622 - crypto_memneq(buf, curve25519_null_point, CURVE25519_KEY_SIZE)) 1623 - memcpy(secret, buf, CURVE25519_KEY_SIZE); 1624 - else 1625 - return -EINVAL; 1626 - return 0; 1627 - } 1628 - 1629 - static int curve25519_generate_public_key(struct kpp_request *req) 1630 - { 1631 - struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 1632 - const u8 *secret = kpp_tfm_ctx(tfm); 1633 - u8 buf[CURVE25519_KEY_SIZE]; 1634 - int copied, nbytes; 1635 - 1636 - if (req->src) 1637 - return -EINVAL; 1638 - 1639 - curve25519_base_arch(buf, secret); 1640 - 1641 - /* might want less than we've got */ 1642 - nbytes = min_t(size_t, CURVE25519_KEY_SIZE, req->dst_len); 1643 - copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst, 1644 - nbytes), 1645 - buf, nbytes); 1646 - if (copied != nbytes) 1647 - return -EINVAL; 1648 - return 0; 1649 - } 1650 - 1651 - static int curve25519_compute_shared_secret(struct kpp_request *req) 1652 - { 1653 - struct crypto_kpp *tfm = crypto_kpp_reqtfm(req); 1654 - const u8 *secret = kpp_tfm_ctx(tfm); 1655 - u8 public_key[CURVE25519_KEY_SIZE]; 1656 - u8 buf[CURVE25519_KEY_SIZE]; 1657 - int copied, nbytes; 1658 - 1659 - if (!req->src) 1660 - return -EINVAL; 1661 - 1662 - copied = sg_copy_to_buffer(req->src, 1663 - sg_nents_for_len(req->src, 1664 - CURVE25519_KEY_SIZE), 1665 - public_key, CURVE25519_KEY_SIZE); 1666 - if (copied != CURVE25519_KEY_SIZE) 1667 - return -EINVAL; 1668 - 1669 - curve25519_arch(buf, secret, public_key); 1670 - 1671 - /* might want less than we've got */ 1672 - nbytes = min_t(size_t, CURVE25519_KEY_SIZE, req->dst_len); 1673 - copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst, 1674 - nbytes), 1675 - buf, nbytes); 1676 - if (copied != nbytes) 1677 - return -EINVAL; 1678 - return 0; 1679 - } 1680 - 1681 - static unsigned int curve25519_max_size(struct crypto_kpp *tfm) 1682 - { 1683 - return CURVE25519_KEY_SIZE; 1684 - } 1685 - 1686 - static struct kpp_alg curve25519_alg = { 1687 - .base.cra_name = "curve25519", 1688 - .base.cra_driver_name = "curve25519-x86", 1689 - .base.cra_priority = 200, 1690 - .base.cra_module = THIS_MODULE, 1691 - .base.cra_ctxsize = CURVE25519_KEY_SIZE, 1692 - 1693 - .set_secret = curve25519_set_secret, 1694 - .generate_public_key = curve25519_generate_public_key, 1695 - .compute_shared_secret = curve25519_compute_shared_secret, 1696 - .max_size = curve25519_max_size, 1697 - }; 1698 - 1699 - 1700 1616 static int __init curve25519_mod_init(void) 1701 1617 { 1702 1618 if (boot_cpu_has(X86_FEATURE_BMI2) && boot_cpu_has(X86_FEATURE_ADX)) 1703 1619 static_branch_enable(&curve25519_use_bmi2_adx); 1704 - else 1705 - return 0; 1706 - return IS_REACHABLE(CONFIG_CRYPTO_KPP) ? 1707 - crypto_register_kpp(&curve25519_alg) : 0; 1620 + return 0; 1708 1621 } 1709 1622 1710 1623 static void __exit curve25519_mod_exit(void) 1711 1624 { 1712 - if (IS_REACHABLE(CONFIG_CRYPTO_KPP) && 1713 - static_branch_likely(&curve25519_use_bmi2_adx)) 1714 - crypto_unregister_kpp(&curve25519_alg); 1715 1625 } 1716 1626 1717 1627 module_init(curve25519_mod_init); 1718 1628 module_exit(curve25519_mod_exit); 1719 1629 1720 - MODULE_ALIAS_CRYPTO("curve25519"); 1721 - MODULE_ALIAS_CRYPTO("curve25519-x86"); 1722 1630 MODULE_DESCRIPTION("Curve25519 algorithm, ADX optimized"); 1723 1631 MODULE_LICENSE("GPL v2"); 1724 1632 MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");