mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-18 23:09:29 +02:00
Merge tag 'v7.2-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
Pull crypto updates from Herbert Xu:
"API:
- Drop support for off-CPU cryptography in af_alg
- Document that af_alg is *always* slower
- Document the deprecation of af_alg
- Remove zero-copy support from skcipher and aead in af_alg
- Cap AEAD AD length to 0x80000000 in af_alg
- Free default RNG on module exit
Algorithms:
- Fix vli multiplication carry overflow in ecc
- Drop unused cipher_null crypto_alg
- Remove unused variants of drbg
- Use lib/crypto in drbg
- Use memcpy_from/to_sglist in authencesn
- Allow authenc(hmac(sha{256,384}),cts(cbc(aes))) in FIPS mode
- Disallow RSA PKCS#1 SHA-1 sig algs in FIPS mode
- Filter out async aead implementations at alloc in krb5
- Fix non-parallel fallback by rstoring callback in pcrypt
- Validate poly1305 template argument in chacha20poly1305
Drivers:
- Add sysfs PCI reset support to qat
- Add KPT support for GEN6 devices to qat
- Remove unused character device and ioctls from qat
- Add support for hw access via SMCC to mtk
- Remove prng support from crypto4xx
- Remove prng support from hisi-trng
- Remove prng support from sun4i-ss
- Remove prng support from xilinx-trng
- Remove loongson-rng
- Remove exynos-rng
Others:
- Remove support for AIO on sockets"
* tag 'v7.2-p1' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6: (196 commits)
crypto: tegra - fix refcount leak in tegra_se_host1x_submit()
crypto: rng - Free default RNG on module exit
crypto: testmgr - allow authenc(hmac(sha{256,384}),cts(cbc(aes))) in FIPS mode
hwrng: jh7110 - fix refcount leak in starfive_trng_read()
crypto: atmel-ecc - drop dead code in atmel_ecdh_max_size
crypto: cavium/cpt - fix DMA cleanup using wrong loop index
crypto: marvell/octeontx - fix DMA cleanup using wrong loop index
MAINTAINERS: make myself the maintainer of the Qualcomm QCE driver
crypto: amcc - convert irq_of_parse_and_map to platform_get_irq
crypto: sun4i-ss - Remove insecure and unused rng_alg
hwrng: xilinx - Move xilinx-rng into drivers/char/hw_random/
crypto: xilinx-trng - Replace crypto_drbg_ctr_df() with HMAC-SHA512
crypto: xilinx-trng - Fix return value of xtrng_hwrng_trng_read()
crypto: xilinx-trng - Remove crypto_rng interface
crypto: exynos-rng - Remove exynos-rng driver
hwrng: hisi-trng - Move hisi-trng into drivers/char/hw_random/
crypto: hisi-trng - Remove crypto_rng interface
crypto: loongson - Remove broken and unused loongson-rng
crypto: crypto4xx - Remove insecure and unused rng_alg
crypto: qat - validate RSA CRT component lengths
...
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
Directory containing attributes related to the QAT Key Protection
|
||||
Technology (KPT) feature. KPT allows cryptographic keys to be used
|
||||
by the accelerator without being exposed in plaintext to the host.
|
||||
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/enable
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) Enables or disables Key Protection Technology (KPT).
|
||||
|
||||
Write 1 to enable KPT, or 0 to disable it.
|
||||
|
||||
Example usage::
|
||||
|
||||
# cat /sys/bus/pci/devices/<BDF>/qat_kpt/enable
|
||||
0
|
||||
# echo 1 > /sys/bus/pci/devices/<BDF>/qat_kpt/enable
|
||||
|
||||
This attribute is only available on devices that support KPT.
|
||||
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_fn
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) Configures the maximum number of KPT symmetric wrapping keys
|
||||
(SWKs) that a Virtual Function (VF) may be associated with.
|
||||
|
||||
Valid values range from 0 to 128. A value of 0 indicates no limit.
|
||||
|
||||
Example usage::
|
||||
|
||||
# cat /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_fn
|
||||
128
|
||||
# echo 128 > /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_fn
|
||||
|
||||
This attribute is only available on devices that support KPT.
|
||||
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_pasid
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) Configures the maximum number of KPT symmetric wrapping keys
|
||||
(SWKs) per Process Address Space ID (PASID).
|
||||
|
||||
Valid values range from 0 to 128. A value of 0 indicates no limit.
|
||||
|
||||
Example usage::
|
||||
|
||||
# cat /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_pasid
|
||||
128
|
||||
# echo 128 > /sys/bus/pci/devices/<BDF>/qat_kpt/swk_cnt_per_pasid
|
||||
|
||||
This attribute is only available on devices that support KPT.
|
||||
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/swk_max_ttl
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) Configures the maximum Time To Live (TTL) for KPT symmetric
|
||||
wrapping keys (SWK).
|
||||
|
||||
Valid values range from 0 to 31536000 seconds. A value of 0
|
||||
indicates that the SWK TTL is unlimited.
|
||||
|
||||
Example usage::
|
||||
|
||||
# cat /sys/bus/pci/devices/<BDF>/qat_kpt/swk_max_ttl
|
||||
1000
|
||||
# echo 1000 > /sys/bus/pci/devices/<BDF>/qat_kpt/swk_max_ttl
|
||||
|
||||
This attribute is only available on devices that support KPT.
|
||||
|
||||
What: /sys/bus/pci/devices/<BDF>/qat_kpt/swk_shared
|
||||
Date: August 2026
|
||||
KernelVersion: 7.2
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) Controls shared mode for KPT symmetric wrapping keys (SWK).
|
||||
|
||||
Write 1 to enable shared mode, or 0 to disable it (non-shared mode).
|
||||
|
||||
Example usage::
|
||||
|
||||
# cat /sys/bus/pci/devices/<BDF>/qat_kpt/swk_shared
|
||||
0
|
||||
# echo 1 > /sys/bus/pci/devices/<BDF>/qat_kpt/swk_shared
|
||||
|
||||
This attribute is only available on devices that support KPT.
|
||||
@@ -209,7 +209,7 @@ Date: January 2024
|
||||
KernelVersion: 6.7
|
||||
Contact: qat-linux@intel.com
|
||||
Description:
|
||||
(RW) This file will return the remaining capability for a
|
||||
(RW) This file will return the remaining capacity for a
|
||||
particular service/sla. This is the remaining value that a new
|
||||
SLA can be set to or a current SLA can be increased with.
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ Code Example For Random Number Generator Usage
|
||||
static int get_random_numbers(u8 *buf, unsigned int len)
|
||||
{
|
||||
struct crypto_rng *rng = NULL;
|
||||
char *drbg = "drbg_nopr_sha256"; /* Hash DRBG with SHA-256, no PR */
|
||||
char *drbg = "stdrng";
|
||||
int ret;
|
||||
|
||||
if (!buf || !len) {
|
||||
|
||||
@@ -4,26 +4,88 @@ User Space Interface
|
||||
Introduction
|
||||
------------
|
||||
|
||||
The concepts of the kernel crypto API visible to kernel space is fully
|
||||
applicable to the user space interface as well. Therefore, the kernel
|
||||
crypto API high level discussion for the in-kernel use cases applies
|
||||
here as well.
|
||||
AF_ALG provides unprivileged userspace programs access to arbitrary hash,
|
||||
symmetric cipher, AEAD, and RNG algorithms that are implemented in kernel-mode
|
||||
code.
|
||||
|
||||
The major difference, however, is that user space can only act as a
|
||||
consumer and never as a provider of a transformation or cipher
|
||||
algorithm.
|
||||
AF_ALG is insecure and is deprecated. Originally added to the kernel in 2010,
|
||||
most kernel developers now consider it to be a mistake. Support for hardware
|
||||
accelerators, which was the original purpose of AF_ALG, has been removed.
|
||||
|
||||
The following covers the user space interface exported by the kernel
|
||||
crypto API. A working example of this description is libkcapi that can
|
||||
be obtained from [1]. That library can be used by user space
|
||||
applications that require cryptographic services from the kernel.
|
||||
AF_ALG continues to be supported only for backwards compatibility. On systems
|
||||
where no programs using AF_ALG remain, the support for it should be disabled by
|
||||
disabling ``CONFIG_CRYPTO_USER_API_*``.
|
||||
|
||||
Some details of the in-kernel kernel crypto API aspects do not apply to
|
||||
user space, however. This includes the difference between synchronous
|
||||
and asynchronous invocations. The user space API call is fully
|
||||
synchronous.
|
||||
Deprecation
|
||||
-----------
|
||||
|
||||
[1] https://www.chronox.de/libkcapi/index.html
|
||||
AF_ALG was originally intended to provide userspace programs access to crypto
|
||||
accelerators that they wouldn't otherwise have access to.
|
||||
|
||||
However, that capability turned out to not be useful on very many systems. More
|
||||
significantly, the actual implementation exposes a vastly greater amount of
|
||||
functionality than that. It actually provides access to all software algorithms.
|
||||
|
||||
This includes arbitrary compositions of different algorithms created via a
|
||||
complex template system, as well as algorithms that only make sense as internal
|
||||
implementation details of other algorithms. In the past, it also included full
|
||||
zero-copy support, which was difficult for the kernel to implement securely.
|
||||
|
||||
Ultimately, these algorithms are just math computations. They use the same
|
||||
instructions that userspace programs already have access to, just accessed in a
|
||||
much more convoluted and less efficient way.
|
||||
|
||||
Indeed, userspace code is nearly always what is being used anyway. These same
|
||||
algorithms are widely implemented in userspace crypto libraries.
|
||||
|
||||
Even when zero-copy and off-CPU accelerators were supported, AF_ALG was usually
|
||||
much slower than optimized software cryptography in userspace. This was
|
||||
especially true for the small message sizes usually seen in performance-critical
|
||||
workloads. While it was possible to demonstrate performance wins for hashing
|
||||
large files on embedded devices, it is hard to imagine a situation where this
|
||||
would be performance-critical.
|
||||
|
||||
Nowadays, AF_ALG no longer supports zero-copy or off-CPU accelerators.
|
||||
Therefore, it is *always* slower than an optimized userspace implementation,
|
||||
even for large messages. The only possible advantage left is that it avoids
|
||||
duplicating code between kernel and userspace. However, userspace
|
||||
implementations, especially hardware-accelerated ones, do not need to be large.
|
||||
Just because OpenSSL is huge does not mean that all userspace cryptography
|
||||
libraries are.
|
||||
|
||||
Meanwhile, AF_ALG hasn't been withstanding modern vulnerability discovery tools
|
||||
such as syzbot and large language models. It receives a steady stream of CVEs.
|
||||
Some of the examples include:
|
||||
|
||||
- CVE-2026-31677
|
||||
- CVE-2026-31431 (https://copy.fail)
|
||||
- CVE-2025-38079
|
||||
- CVE-2025-37808
|
||||
- CVE-2024-26824
|
||||
- CVE-2022-48781
|
||||
- CVE-2019-8912
|
||||
- CVE-2018-14619
|
||||
- CVE-2017-18075
|
||||
- CVE-2017-17806
|
||||
- CVE-2017-17805
|
||||
- CVE-2016-10147
|
||||
- CVE-2015-8970
|
||||
- CVE-2015-3331
|
||||
- CVE-2014-9644
|
||||
- CVE-2013-7421
|
||||
- CVE-2011-4081
|
||||
|
||||
Hardware accelerator drivers are frequently buggy. To reduce attack surface,
|
||||
AF_ALG now only provides access to algorithms implemented in software. This
|
||||
means that AF_ALG no longer fulfills its original purpose.
|
||||
|
||||
It is recommended that, whenever possible, userspace programs be migrated to
|
||||
userspace crypto code (which again, is what is normally used anyway) and
|
||||
``CONFIG_CRYPTO_USER_API_*`` be disabled. On systems that use SELinux, SELinux
|
||||
can also be used to restrict the use of AF_ALG to trusted programs.
|
||||
|
||||
The remainder of this documentation provides the historical documentation for
|
||||
the deprecated AF_ALG interface.
|
||||
|
||||
User Space API General Remarks
|
||||
------------------------------
|
||||
@@ -297,7 +359,7 @@ follows:
|
||||
struct sockaddr_alg sa = {
|
||||
.salg_family = AF_ALG,
|
||||
.salg_type = "rng", /* this selects the random number generator */
|
||||
.salg_name = "drbg_nopr_sha256" /* this is the RNG name */
|
||||
.salg_name = "stdrng" /* this is the RNG name */
|
||||
};
|
||||
|
||||
|
||||
@@ -327,33 +389,10 @@ CRYPTO_USER_API_RNG_CAVP option:
|
||||
Zero-Copy Interface
|
||||
-------------------
|
||||
|
||||
In addition to the send/write/read/recv system call family, the AF_ALG
|
||||
interface can be accessed with the zero-copy interface of
|
||||
splice/vmsplice. As the name indicates, the kernel tries to avoid a copy
|
||||
operation into kernel space.
|
||||
|
||||
The zero-copy operation requires data to be aligned at the page
|
||||
boundary. Non-aligned data can be used as well, but may require more
|
||||
operations of the kernel which would defeat the speed gains obtained
|
||||
from the zero-copy interface.
|
||||
|
||||
The system-inherent limit for the size of one zero-copy operation is 16
|
||||
pages. If more data is to be sent to AF_ALG, user space must slice the
|
||||
input into segments with a maximum size of 16 pages.
|
||||
|
||||
Zero-copy can be used with the following code example (a complete
|
||||
working example is provided with libkcapi):
|
||||
|
||||
::
|
||||
|
||||
int pipes[2];
|
||||
|
||||
pipe(pipes);
|
||||
/* input data in iov */
|
||||
vmsplice(pipes[1], iov, iovlen, SPLICE_F_GIFT);
|
||||
/* opfd is the file descriptor returned from accept() system call */
|
||||
splice(pipes[0], NULL, opfd, NULL, ret, 0);
|
||||
read(opfd, out, outlen);
|
||||
AF_ALG used to have zero-copy support, but it was removed due to it being a
|
||||
frequent source of vulnerabilities. For backwards compatibility the splice()
|
||||
and sendfile() system calls are still supported, but the kernel will make an
|
||||
internal copy of the data before passing it to the crypto code.
|
||||
|
||||
|
||||
Setsockopt Interface
|
||||
|
||||
@@ -14,6 +14,7 @@ properties:
|
||||
items:
|
||||
- enum:
|
||||
- qcom,eliza-inline-crypto-engine
|
||||
- qcom,hawi-inline-crypto-engine
|
||||
- qcom,kaanapali-inline-crypto-engine
|
||||
- qcom,milos-inline-crypto-engine
|
||||
- qcom,qcs8300-inline-crypto-engine
|
||||
|
||||
@@ -17,11 +17,14 @@ properties:
|
||||
- qcom,prng-ee # 8996 and later using EE
|
||||
- items:
|
||||
- enum:
|
||||
- qcom,glymur-trng
|
||||
- qcom,hawi-trng
|
||||
- qcom,ipq5332-trng
|
||||
- qcom,ipq5424-trng
|
||||
- qcom,ipq9574-trng
|
||||
- qcom,kaanapali-trng
|
||||
- qcom,milos-trng
|
||||
- qcom,nord-trng
|
||||
- qcom,qcs615-trng
|
||||
- qcom,qcs8300-trng
|
||||
- qcom,sa8255p-trng
|
||||
|
||||
@@ -45,7 +45,11 @@ properties:
|
||||
|
||||
- items:
|
||||
- enum:
|
||||
- qcom,eliza-qce
|
||||
- qcom,glymur-qce
|
||||
- qcom,kaanapali-qce
|
||||
- qcom,milos-qce
|
||||
- qcom,nord-qce
|
||||
- qcom,qcs615-qce
|
||||
- qcom,qcs8300-qce
|
||||
- qcom,sa8775p-qce
|
||||
|
||||
@@ -11,12 +11,13 @@ maintainers:
|
||||
|
||||
properties:
|
||||
$nodename:
|
||||
pattern: "^rng@[0-9a-f]+$"
|
||||
pattern: "^rng(@[0-9a-f]+)?$"
|
||||
|
||||
compatible:
|
||||
oneOf:
|
||||
- enum:
|
||||
- mediatek,mt7623-rng
|
||||
- mediatek,mt7981-rng
|
||||
- items:
|
||||
- enum:
|
||||
- mediatek,mt7622-rng
|
||||
@@ -25,6 +26,11 @@ properties:
|
||||
- mediatek,mt8365-rng
|
||||
- mediatek,mt8516-rng
|
||||
- const: mediatek,mt7623-rng
|
||||
- items:
|
||||
- enum:
|
||||
- mediatek,mt7987-rng
|
||||
- mediatek,mt7988-rng
|
||||
- const: mediatek,mt7981-rng
|
||||
|
||||
reg:
|
||||
maxItems: 1
|
||||
@@ -38,18 +44,37 @@ properties:
|
||||
|
||||
required:
|
||||
- compatible
|
||||
- reg
|
||||
- clocks
|
||||
- clock-names
|
||||
|
||||
allOf:
|
||||
- if:
|
||||
properties:
|
||||
compatible:
|
||||
contains:
|
||||
const: mediatek,mt7981-rng
|
||||
then:
|
||||
properties:
|
||||
reg: false
|
||||
clocks: false
|
||||
clock-names: false
|
||||
else:
|
||||
required:
|
||||
- reg
|
||||
- clocks
|
||||
- clock-names
|
||||
|
||||
additionalProperties: false
|
||||
|
||||
examples:
|
||||
- |
|
||||
#include <dt-bindings/clock/mt2701-clk.h>
|
||||
rng: rng@1020f000 {
|
||||
compatible = "mediatek,mt7623-rng";
|
||||
reg = <0x1020f000 0x1000>;
|
||||
clocks = <&infracfg CLK_INFRA_TRNG>;
|
||||
clock-names = "rng";
|
||||
|
||||
rng@1020f000 {
|
||||
compatible = "mediatek,mt7623-rng";
|
||||
reg = <0x1020f000 0x1000>;
|
||||
clocks = <&infracfg CLK_INFRA_TRNG>;
|
||||
clock-names = "rng";
|
||||
};
|
||||
- |
|
||||
rng {
|
||||
compatible = "mediatek,mt7981-rng";
|
||||
};
|
||||
|
||||
@@ -67,8 +67,10 @@ properties:
|
||||
- arduino,unoq-mcu
|
||||
# Temperature monitoring of Astera Labs PT5161L PCIe retimer
|
||||
- asteralabs,pt5161l
|
||||
# i2c h/w elliptic curve crypto module
|
||||
# ATECC508A - i2c h/w elliptic curve crypto module
|
||||
- atmel,atecc508a
|
||||
# ATECC608B - i2c h/w elliptic curve crypto module
|
||||
- atmel,atecc608b
|
||||
# ATSHA204 - i2c h/w symmetric crypto module
|
||||
- atmel,atsha204
|
||||
# ATSHA204A - i2c h/w symmetric crypto module
|
||||
|
||||
@@ -229,7 +229,6 @@ Code Seq# Include File Comments
|
||||
<mailto:gregkh@linuxfoundation.org>
|
||||
'a' all linux/atm*.h, linux/sonet.h ATM on linux
|
||||
<http://lrcwww.epfl.ch/>
|
||||
'a' 00-0F drivers/crypto/qat/qat_common/adf_cfg_common.h conflict! qat driver
|
||||
'b' 00-FF conflict! bit3 vme host bridge
|
||||
<mailto:natalia@nikhefk.nikhef.nl>
|
||||
'b' 00-0F linux/dma-buf.h conflict!
|
||||
|
||||
+4
-13
@@ -11721,7 +11721,7 @@ F: drivers/mfd/hi6421-spmi-pmic.c
|
||||
HISILICON TRUE RANDOM NUMBER GENERATOR V2 SUPPORT
|
||||
M: Weili Qian <qianweili@huawei.com>
|
||||
S: Maintained
|
||||
F: drivers/crypto/hisilicon/trng/trng.c
|
||||
F: drivers/char/hw_random/hisi-trng-v2.c
|
||||
|
||||
HISILICON V3XX SPI NOR FLASH Controller Driver
|
||||
M: Yang Shen <shenyang39@huawei.com>
|
||||
@@ -15090,7 +15090,6 @@ M: Qunqin Zhao <zhaoqunqin@loongson.cn>
|
||||
L: linux-crypto@vger.kernel.org
|
||||
S: Maintained
|
||||
F: drivers/char/tpm/tpm_loongson.c
|
||||
F: drivers/crypto/loongson/
|
||||
F: drivers/mfd/loongson-se.c
|
||||
F: include/linux/mfd/loongson-se.h
|
||||
|
||||
@@ -21968,10 +21967,10 @@ F: Documentation/devicetree/bindings/opp/opp-v2-kryo-cpu.yaml
|
||||
F: drivers/cpufreq/qcom-cpufreq-nvmem.c
|
||||
|
||||
QUALCOMM CRYPTO DRIVERS
|
||||
M: Thara Gopinath <thara.gopinath@gmail.com>
|
||||
M: Bartosz Golaszewski <brgl@kernel.org>
|
||||
L: linux-crypto@vger.kernel.org
|
||||
L: linux-arm-msm@vger.kernel.org
|
||||
S: Maintained
|
||||
S: Supported
|
||||
F: Documentation/devicetree/bindings/crypto/qcom-qce.yaml
|
||||
F: drivers/crypto/qce/
|
||||
|
||||
@@ -23797,14 +23796,6 @@ F: Documentation/devicetree/bindings/mailbox/google,gs101-mbox.yaml
|
||||
F: drivers/mailbox/exynos-mailbox.c
|
||||
F: include/linux/mailbox/exynos-message.h
|
||||
|
||||
SAMSUNG EXYNOS PSEUDO RANDOM NUMBER GENERATOR (RNG) DRIVER
|
||||
M: Krzysztof Kozlowski <krzk@kernel.org>
|
||||
L: linux-crypto@vger.kernel.org
|
||||
L: linux-samsung-soc@vger.kernel.org
|
||||
S: Maintained
|
||||
F: Documentation/devicetree/bindings/rng/samsung,exynos4-rng.yaml
|
||||
F: drivers/crypto/exynos-rng.c
|
||||
|
||||
SAMSUNG EXYNOS TRUE RANDOM NUMBER GENERATOR (TRNG) DRIVER
|
||||
M: Łukasz Stelmach <l.stelmach@samsung.com>
|
||||
L: linux-samsung-soc@vger.kernel.org
|
||||
@@ -29315,7 +29306,7 @@ XILINX TRNG DRIVER
|
||||
M: Mounika Botcha <mounika.botcha@amd.com>
|
||||
M: Harsh Jain <h.jain@amd.com>
|
||||
S: Maintained
|
||||
F: drivers/crypto/xilinx/xilinx-trng.c
|
||||
F: drivers/char/hw_random/xilinx-trng.c
|
||||
|
||||
XILINX UARTLITE SERIAL DRIVER
|
||||
M: Peter Korsgaard <jacmet@sunsite.dk>
|
||||
|
||||
@@ -364,7 +364,6 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=m
|
||||
CONFIG_CRYPTO_USER_API_RNG=m
|
||||
CONFIG_CRYPTO_USER_API_AEAD=m
|
||||
CONFIG_CRYPTO_AES_ARM_BS=m
|
||||
CONFIG_CRYPTO_DEV_EXYNOS_RNG=y
|
||||
CONFIG_CRYPTO_DEV_S5P=y
|
||||
CONFIG_DMA_CMA=y
|
||||
CONFIG_CMA_SIZE_MBYTES=96
|
||||
|
||||
@@ -1329,7 +1329,6 @@ CONFIG_CRYPTO_AES_ARM_BS=m
|
||||
CONFIG_CRYPTO_AES_ARM_CE=m
|
||||
CONFIG_CRYPTO_DEV_SUN4I_SS=m
|
||||
CONFIG_CRYPTO_DEV_FSL_CAAM=m
|
||||
CONFIG_CRYPTO_DEV_EXYNOS_RNG=m
|
||||
CONFIG_CRYPTO_DEV_S5P=m
|
||||
CONFIG_CRYPTO_DEV_ATMEL_AES=m
|
||||
CONFIG_CRYPTO_DEV_ATMEL_TDES=m
|
||||
|
||||
@@ -170,7 +170,6 @@ CONFIG_ROOT_NFS=y
|
||||
CONFIG_NLS_CODEPAGE_437=y
|
||||
CONFIG_NLS_ISO8859_1=y
|
||||
CONFIG_CRYPTO_DEV_SUN4I_SS=y
|
||||
CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG=y
|
||||
CONFIG_CRYPTO_DEV_SUN8I_CE=y
|
||||
CONFIG_CRYPTO_DEV_SUN8I_SS=y
|
||||
CONFIG_DMA_CMA=y
|
||||
|
||||
@@ -551,6 +551,8 @@ CONFIG_IPMI_DEVICE_INTERFACE=m
|
||||
CONFIG_IPMI_SI=m
|
||||
CONFIG_HW_RANDOM=y
|
||||
CONFIG_HW_RANDOM_VIRTIO=y
|
||||
CONFIG_HW_RANDOM_HISI_TRNG=m
|
||||
CONFIG_HW_RANDOM_XILINX=m
|
||||
CONFIG_TCG_TPM=y
|
||||
CONFIG_TCG_TIS=m
|
||||
CONFIG_TCG_TIS_SPI=m
|
||||
@@ -1956,14 +1958,12 @@ CONFIG_CRYPTO_DEV_FSL_DPAA2_CAAM=m
|
||||
CONFIG_CRYPTO_DEV_QCE=m
|
||||
CONFIG_CRYPTO_DEV_QCOM_RNG=m
|
||||
CONFIG_CRYPTO_DEV_TEGRA=m
|
||||
CONFIG_CRYPTO_DEV_XILINX_TRNG=m
|
||||
CONFIG_CRYPTO_DEV_ZYNQMP_AES=m
|
||||
CONFIG_CRYPTO_DEV_ZYNQMP_SHA3=m
|
||||
CONFIG_CRYPTO_DEV_CCREE=m
|
||||
CONFIG_CRYPTO_DEV_HISI_SEC2=m
|
||||
CONFIG_CRYPTO_DEV_HISI_ZIP=m
|
||||
CONFIG_CRYPTO_DEV_HISI_HPRE=m
|
||||
CONFIG_CRYPTO_DEV_HISI_TRNG=m
|
||||
CONFIG_CRYPTO_DEV_SA2UL=m
|
||||
CONFIG_DMA_RESTRICTED_POOL=y
|
||||
CONFIG_CMA_SIZE_MBYTES=32
|
||||
|
||||
@@ -197,8 +197,6 @@ endif
|
||||
libs-y += arch/loongarch/lib/
|
||||
libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
|
||||
|
||||
drivers-y += arch/loongarch/crypto/
|
||||
|
||||
# suspend and hibernation support
|
||||
drivers-$(CONFIG_PM) += arch/loongarch/power/
|
||||
|
||||
|
||||
@@ -1091,7 +1091,6 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=m
|
||||
CONFIG_CRYPTO_USER_API_RNG=m
|
||||
CONFIG_CRYPTO_USER_API_AEAD=m
|
||||
CONFIG_CRYPTO_DEV_VIRTIO=m
|
||||
CONFIG_CRYPTO_DEV_LOONGSON_RNG=m
|
||||
CONFIG_DMA_CMA=y
|
||||
CONFIG_CMA_SIZE_MBYTES=0
|
||||
CONFIG_PRINTK_TIME=y
|
||||
|
||||
@@ -1124,7 +1124,6 @@ CONFIG_CRYPTO_USER_API_SKCIPHER=m
|
||||
CONFIG_CRYPTO_USER_API_RNG=m
|
||||
CONFIG_CRYPTO_USER_API_AEAD=m
|
||||
CONFIG_CRYPTO_DEV_VIRTIO=m
|
||||
CONFIG_CRYPTO_DEV_LOONGSON_RNG=m
|
||||
CONFIG_DMA_CMA=y
|
||||
CONFIG_DMA_NUMA_CMA=y
|
||||
CONFIG_CMA_SIZE_MBYTES=0
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
menu "Accelerated Cryptographic Algorithms for CPU (loongarch)"
|
||||
|
||||
endmenu
|
||||
@@ -1,4 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# Makefile for LoongArch crypto files..
|
||||
#
|
||||
@@ -350,8 +350,6 @@ OBJCOPYFLAGS += --remove-section=.reginfo
|
||||
libs-y += arch/mips/lib/
|
||||
libs-$(CONFIG_MIPS_FP_SUPPORT) += arch/mips/math-emu/
|
||||
|
||||
drivers-y += arch/mips/crypto/
|
||||
|
||||
# suspend and hibernation support
|
||||
drivers-$(CONFIG_PM) += arch/mips/power/
|
||||
|
||||
|
||||
@@ -199,8 +199,6 @@ CONFIG_CRYPTO_LZO=m
|
||||
CONFIG_CRYPTO_842=m
|
||||
CONFIG_CRYPTO_LZ4=m
|
||||
CONFIG_CRYPTO_LZ4HC=m
|
||||
CONFIG_CRYPTO_DRBG_HASH=y
|
||||
CONFIG_CRYPTO_DRBG_CTR=y
|
||||
# CONFIG_CRYPTO_HW is not set
|
||||
CONFIG_MAGIC_SYSRQ=y
|
||||
# CONFIG_FTRACE is not set
|
||||
|
||||
@@ -194,8 +194,6 @@ CONFIG_CRYPTO_LZO=m
|
||||
CONFIG_CRYPTO_842=m
|
||||
CONFIG_CRYPTO_LZ4=m
|
||||
CONFIG_CRYPTO_LZ4HC=m
|
||||
CONFIG_CRYPTO_DRBG_HASH=y
|
||||
CONFIG_CRYPTO_DRBG_CTR=y
|
||||
# CONFIG_CRYPTO_HW is not set
|
||||
CONFIG_FRAME_WARN=2048
|
||||
CONFIG_MAGIC_SYSRQ=y
|
||||
|
||||
@@ -194,8 +194,6 @@ CONFIG_CRYPTO_LZO=m
|
||||
CONFIG_CRYPTO_842=m
|
||||
CONFIG_CRYPTO_LZ4=m
|
||||
CONFIG_CRYPTO_LZ4HC=m
|
||||
CONFIG_CRYPTO_DRBG_HASH=y
|
||||
CONFIG_CRYPTO_DRBG_CTR=y
|
||||
# CONFIG_CRYPTO_HW is not set
|
||||
CONFIG_FRAME_WARN=2048
|
||||
CONFIG_MAGIC_SYSRQ=y
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
poly1305-core.S
|
||||
@@ -1,5 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
menu "Accelerated Cryptographic Algorithms for CPU (mips)"
|
||||
|
||||
endmenu
|
||||
@@ -1,5 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# Makefile for MIPS crypto files..
|
||||
#
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <crypto/aes.h>
|
||||
#include <linux/minmax.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/types.h>
|
||||
@@ -140,7 +141,7 @@ static int ppc_ecb_crypt(struct skcipher_request *req, bool enc)
|
||||
err = skcipher_walk_virt(&walk, req, false);
|
||||
|
||||
while ((nbytes = walk.nbytes) != 0) {
|
||||
nbytes = min_t(unsigned int, nbytes, MAX_BYTES);
|
||||
nbytes = min(nbytes, MAX_BYTES);
|
||||
nbytes = round_down(nbytes, AES_BLOCK_SIZE);
|
||||
|
||||
spe_begin();
|
||||
@@ -179,7 +180,7 @@ static int ppc_cbc_crypt(struct skcipher_request *req, bool enc)
|
||||
err = skcipher_walk_virt(&walk, req, false);
|
||||
|
||||
while ((nbytes = walk.nbytes) != 0) {
|
||||
nbytes = min_t(unsigned int, nbytes, MAX_BYTES);
|
||||
nbytes = min(nbytes, MAX_BYTES);
|
||||
nbytes = round_down(nbytes, AES_BLOCK_SIZE);
|
||||
|
||||
spe_begin();
|
||||
@@ -220,7 +221,7 @@ static int ppc_ctr_crypt(struct skcipher_request *req)
|
||||
err = skcipher_walk_virt(&walk, req, false);
|
||||
|
||||
while ((nbytes = walk.nbytes) != 0) {
|
||||
nbytes = min_t(unsigned int, nbytes, MAX_BYTES);
|
||||
nbytes = min(nbytes, MAX_BYTES);
|
||||
if (nbytes < walk.total)
|
||||
nbytes = round_down(nbytes, AES_BLOCK_SIZE);
|
||||
|
||||
@@ -248,7 +249,7 @@ static int ppc_xts_crypt(struct skcipher_request *req, bool enc)
|
||||
twk = ctx->key_twk;
|
||||
|
||||
while ((nbytes = walk.nbytes) != 0) {
|
||||
nbytes = min_t(unsigned int, nbytes, MAX_BYTES);
|
||||
nbytes = min(nbytes, MAX_BYTES);
|
||||
nbytes = round_down(nbytes, AES_BLOCK_SIZE);
|
||||
|
||||
spe_begin();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <crypto/scatterwalk.h>
|
||||
#include <crypto/xts.h>
|
||||
#include <linux/linkage.h>
|
||||
#include <linux/minmax.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
asmlinkage void aes_ecb_encrypt_zvkned(const struct crypto_aes_ctx *key,
|
||||
@@ -266,8 +267,7 @@ static int riscv64_aes_ctr_crypt(struct skcipher_request *req)
|
||||
* operation into two at the point where the overflow
|
||||
* will occur. After the first part, add the carry bit.
|
||||
*/
|
||||
p1_nbytes = min_t(unsigned int, nbytes,
|
||||
(nblocks - ctr32) * AES_BLOCK_SIZE);
|
||||
p1_nbytes = min(nbytes, (nblocks - ctr32) * AES_BLOCK_SIZE);
|
||||
aes_ctr32_crypt_zvkned_zvkb(ctx, walk.src.virt.addr,
|
||||
walk.dst.virt.addr,
|
||||
p1_nbytes, req->iv);
|
||||
|
||||
+57
-63
@@ -1113,44 +1113,16 @@ endmenu
|
||||
|
||||
menu "Random number generation"
|
||||
|
||||
menuconfig CRYPTO_DRBG_MENU
|
||||
config CRYPTO_DRBG
|
||||
tristate "NIST SP800-90A DRBG (Deterministic Random Bit Generator)"
|
||||
select CRYPTO_JITTERENTROPY
|
||||
select CRYPTO_LIB_SHA512
|
||||
select CRYPTO_RNG
|
||||
help
|
||||
DRBG (Deterministic Random Bit Generator) (NIST SP800-90A)
|
||||
|
||||
In the following submenu, one or more of the DRBG types must be selected.
|
||||
|
||||
if CRYPTO_DRBG_MENU
|
||||
|
||||
config CRYPTO_DRBG_HMAC
|
||||
bool
|
||||
default y
|
||||
select CRYPTO_HMAC
|
||||
select CRYPTO_SHA512
|
||||
|
||||
config CRYPTO_DRBG_HASH
|
||||
bool "Hash_DRBG"
|
||||
select CRYPTO_SHA256
|
||||
help
|
||||
Hash_DRBG variant as defined in NIST SP800-90A.
|
||||
|
||||
This uses the SHA-1, SHA-256, SHA-384, or SHA-512 hash algorithms.
|
||||
|
||||
config CRYPTO_DRBG_CTR
|
||||
bool "CTR_DRBG"
|
||||
select CRYPTO_DF80090A
|
||||
help
|
||||
CTR_DRBG variant as defined in NIST SP800-90A.
|
||||
|
||||
This uses the AES cipher algorithm with the counter block mode.
|
||||
|
||||
config CRYPTO_DRBG
|
||||
tristate
|
||||
default CRYPTO_DRBG_MENU
|
||||
select CRYPTO_RNG
|
||||
select CRYPTO_JITTERENTROPY
|
||||
|
||||
endif # if CRYPTO_DRBG_MENU
|
||||
Enable this only if you need it for a FIPS 140 certification.
|
||||
It's otherwise redundant with the kernel's regular RNG.
|
||||
|
||||
config CRYPTO_JITTERENTROPY
|
||||
tristate "CPU Jitter Non-Deterministic RNG (Random Number Generator)"
|
||||
@@ -1274,50 +1246,69 @@ config CRYPTO_KDF800108_CTR
|
||||
select CRYPTO_HMAC
|
||||
select CRYPTO_SHA256
|
||||
|
||||
config CRYPTO_DF80090A
|
||||
tristate
|
||||
select CRYPTO_AES
|
||||
select CRYPTO_CTR
|
||||
|
||||
endmenu
|
||||
menu "Userspace interface"
|
||||
menu "Userspace interface (deprecated)"
|
||||
|
||||
config CRYPTO_USER_API
|
||||
tristate
|
||||
|
||||
config CRYPTO_USER_API_HASH
|
||||
tristate "Hash algorithms"
|
||||
tristate "Hash algorithms (deprecated)"
|
||||
depends on NET
|
||||
select CRYPTO_HASH
|
||||
select CRYPTO_USER_API
|
||||
help
|
||||
Enable the userspace interface for hash algorithms.
|
||||
Enable the AF_ALG userspace interface for hash algorithms. This
|
||||
provides unprivileged userspace programs access to arbitrary hash
|
||||
algorithms implemented in the kernel's privileged execution context.
|
||||
|
||||
See Documentation/crypto/userspace-if.rst and
|
||||
https://www.chronox.de/libkcapi/html/index.html
|
||||
This interface is deprecated and is supported only for backwards
|
||||
compatibility. It regularly has vulnerabilities, and the capabilities
|
||||
it provides are redundant with userspace crypto libraries.
|
||||
|
||||
Enable this only if needed for support for a program that hasn't yet
|
||||
been converted to userspace crypto, for example iwd.
|
||||
|
||||
See also Documentation/crypto/userspace-if.rst
|
||||
|
||||
config CRYPTO_USER_API_SKCIPHER
|
||||
tristate "Symmetric key cipher algorithms"
|
||||
tristate "Symmetric key cipher algorithms (deprecated)"
|
||||
depends on NET
|
||||
select CRYPTO_SKCIPHER
|
||||
select CRYPTO_USER_API
|
||||
help
|
||||
Enable the userspace interface for symmetric key cipher algorithms.
|
||||
Enable the AF_ALG userspace interface for symmetric key algorithms.
|
||||
This provides unprivileged userspace programs access to arbitrary
|
||||
symmetric key algorithms implemented in the kernel's privileged
|
||||
execution context.
|
||||
|
||||
See Documentation/crypto/userspace-if.rst and
|
||||
https://www.chronox.de/libkcapi/html/index.html
|
||||
This interface is deprecated and is supported only for backwards
|
||||
compatibility. It regularly has vulnerabilities, and the capabilities
|
||||
it provides are redundant with userspace crypto libraries.
|
||||
|
||||
Enable this only if needed for support for a program that hasn't yet
|
||||
been converted to userspace crypto, for example iwd, or cryptsetup
|
||||
with certain algorithms.
|
||||
|
||||
See also Documentation/crypto/userspace-if.rst
|
||||
|
||||
config CRYPTO_USER_API_RNG
|
||||
tristate "RNG (random number generator) algorithms"
|
||||
tristate "Random number generation algorithms (deprecated)"
|
||||
depends on NET
|
||||
select CRYPTO_RNG
|
||||
select CRYPTO_USER_API
|
||||
help
|
||||
Enable the userspace interface for RNG (random number generator)
|
||||
algorithms.
|
||||
Enable the AF_ALG userspace interface for random number generation
|
||||
(RNG) algorithms. This provides unprivileged userspace programs
|
||||
access to arbitrary RNG algorithms implemented in the kernel's
|
||||
privileged execution context.
|
||||
|
||||
See Documentation/crypto/userspace-if.rst and
|
||||
https://www.chronox.de/libkcapi/html/index.html
|
||||
This interface is deprecated and is supported only for backwards
|
||||
compatibility. It regularly has vulnerabilities, and the capabilities
|
||||
it provides are redundant with userspace crypto libraries as well as
|
||||
the normal kernel RNG (e.g., /dev/urandom and getrandom(2)).
|
||||
|
||||
See also Documentation/crypto/userspace-if.rst
|
||||
|
||||
config CRYPTO_USER_API_RNG_CAVP
|
||||
bool "Enable CAVP testing of DRBG"
|
||||
@@ -1332,16 +1323,25 @@ config CRYPTO_USER_API_RNG_CAVP
|
||||
no unless you know what this is.
|
||||
|
||||
config CRYPTO_USER_API_AEAD
|
||||
tristate "AEAD cipher algorithms"
|
||||
tristate "AEAD cipher algorithms (deprecated)"
|
||||
depends on NET
|
||||
select CRYPTO_AEAD
|
||||
select CRYPTO_SKCIPHER
|
||||
select CRYPTO_USER_API
|
||||
help
|
||||
Enable the userspace interface for AEAD cipher algorithms.
|
||||
Enable the AF_ALG userspace interface for authenticated encryption
|
||||
with associated data (AEAD) algorithms. This provides unprivileged
|
||||
userspace programs access to arbitrary AEAD algorithms implemented in
|
||||
the kernel's privileged execution context.
|
||||
|
||||
See Documentation/crypto/userspace-if.rst and
|
||||
https://www.chronox.de/libkcapi/html/index.html
|
||||
This interface is deprecated and is supported only for backwards
|
||||
compatibility. It regularly has vulnerabilities, and the capabilities
|
||||
it provides are redundant with userspace crypto libraries.
|
||||
|
||||
Enable this only if needed for support for a program that hasn't yet
|
||||
been converted to userspace crypto, for example iwd.
|
||||
|
||||
See also Documentation/crypto/userspace-if.rst
|
||||
|
||||
config CRYPTO_USER_API_ENABLE_OBSOLETE
|
||||
bool "Obsolete cryptographic algorithms"
|
||||
@@ -1361,12 +1361,6 @@ endif
|
||||
if ARM64
|
||||
source "arch/arm64/crypto/Kconfig"
|
||||
endif
|
||||
if LOONGARCH
|
||||
source "arch/loongarch/crypto/Kconfig"
|
||||
endif
|
||||
if MIPS
|
||||
source "arch/mips/crypto/Kconfig"
|
||||
endif
|
||||
if PPC
|
||||
source "arch/powerpc/crypto/Kconfig"
|
||||
endif
|
||||
|
||||
+5
-2
@@ -178,6 +178,11 @@ obj-$(CONFIG_CRYPTO_ZSTD) += zstd.o
|
||||
obj-$(CONFIG_CRYPTO_ECC) += ecc.o
|
||||
obj-$(CONFIG_CRYPTO_ESSIV) += essiv.o
|
||||
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124949
|
||||
ifeq ($(CONFIG_ARM)$(CONFIG_KASAN_STACK)$(CONFIG_CC_IS_GCC),yyy)
|
||||
CFLAGS_ecc.o += $(call cc-option,-Wframe-larger-than=1536)
|
||||
endif
|
||||
|
||||
ecdh_generic-y += ecdh.o
|
||||
ecdh_generic-y += ecdh_helper.o
|
||||
obj-$(CONFIG_CRYPTO_ECDH) += ecdh_generic.o
|
||||
@@ -203,6 +208,4 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o
|
||||
#
|
||||
obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o
|
||||
|
||||
obj-$(CONFIG_CRYPTO_DF80090A) += df_sp80090a.o
|
||||
|
||||
obj-$(CONFIG_CRYPTO_KRB5) += krb5/
|
||||
|
||||
+3
-5
@@ -51,11 +51,9 @@ static inline struct acomp_alg *crypto_acomp_alg(struct crypto_acomp *tfm)
|
||||
static int __maybe_unused crypto_acomp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_acomp racomp;
|
||||
|
||||
memset(&racomp, 0, sizeof(racomp));
|
||||
|
||||
strscpy(racomp.type, "acomp", sizeof(racomp.type));
|
||||
struct crypto_report_acomp racomp = {
|
||||
.type = "acomp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_ACOMP, sizeof(racomp), &racomp);
|
||||
}
|
||||
|
||||
+4
-6
@@ -136,13 +136,11 @@ static int crypto_aead_init_tfm(struct crypto_tfm *tfm)
|
||||
static int __maybe_unused crypto_aead_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_aead raead;
|
||||
struct aead_alg *aead = container_of(alg, struct aead_alg, base);
|
||||
|
||||
memset(&raead, 0, sizeof(raead));
|
||||
|
||||
strscpy(raead.type, "aead", sizeof(raead.type));
|
||||
strscpy(raead.geniv, "<none>", sizeof(raead.geniv));
|
||||
struct crypto_report_aead raead = {
|
||||
.type = "aead",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
raead.blocksize = alg->cra_blocksize;
|
||||
raead.maxauthsize = aead->maxauthsize;
|
||||
|
||||
+28
-78
@@ -181,7 +181,7 @@ static int alg_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int add
|
||||
if (IS_ERR(type))
|
||||
return PTR_ERR(type);
|
||||
|
||||
private = type->bind(sa->salg_name, sa->salg_feat, sa->salg_mask);
|
||||
private = type->bind(sa->salg_name);
|
||||
if (IS_ERR(private)) {
|
||||
module_put(type->owner);
|
||||
return PTR_ERR(private);
|
||||
@@ -584,6 +584,8 @@ static int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
|
||||
if (cmsg->cmsg_len < CMSG_LEN(sizeof(u32)))
|
||||
return -EINVAL;
|
||||
con->aead_assoclen = *(u32 *)CMSG_DATA(cmsg);
|
||||
if (con->aead_assoclen >= 0x80000000u)
|
||||
return -EINVAL;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -973,7 +975,7 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
||||
ssize_t plen;
|
||||
|
||||
/* use the existing memory in an allocated page */
|
||||
if (ctx->merge && !(msg->msg_flags & MSG_SPLICE_PAGES)) {
|
||||
if (ctx->merge) {
|
||||
sgl = list_entry(ctx->tsgl_list.prev,
|
||||
struct af_alg_tsgl, list);
|
||||
sg = sgl->sg + sgl->cur - 1;
|
||||
@@ -1017,60 +1019,37 @@ int af_alg_sendmsg(struct socket *sock, struct msghdr *msg, size_t size,
|
||||
if (sgl->cur)
|
||||
sg_unmark_end(sg + sgl->cur - 1);
|
||||
|
||||
if (msg->msg_flags & MSG_SPLICE_PAGES) {
|
||||
struct sg_table sgtable = {
|
||||
.sgl = sg,
|
||||
.nents = sgl->cur,
|
||||
.orig_nents = sgl->cur,
|
||||
};
|
||||
do {
|
||||
struct page *pg;
|
||||
unsigned int i = sgl->cur;
|
||||
|
||||
plen = extract_iter_to_sg(&msg->msg_iter, len, &sgtable,
|
||||
MAX_SGL_ENTS - sgl->cur, 0);
|
||||
if (plen < 0) {
|
||||
err = plen;
|
||||
plen = min_t(size_t, len, PAGE_SIZE);
|
||||
|
||||
pg = alloc_page(GFP_KERNEL);
|
||||
if (!pg) {
|
||||
err = -ENOMEM;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
for (; sgl->cur < sgtable.nents; sgl->cur++)
|
||||
get_page(sg_page(&sg[sgl->cur]));
|
||||
sg_assign_page(sg + i, pg);
|
||||
|
||||
err = memcpy_from_msg(page_address(sg_page(sg + i)),
|
||||
msg, plen);
|
||||
if (err) {
|
||||
__free_page(sg_page(sg + i));
|
||||
sg_assign_page(sg + i, NULL);
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
sg[i].length = plen;
|
||||
len -= plen;
|
||||
ctx->used += plen;
|
||||
copied += plen;
|
||||
size -= plen;
|
||||
} else {
|
||||
do {
|
||||
struct page *pg;
|
||||
unsigned int i = sgl->cur;
|
||||
sgl->cur++;
|
||||
} while (len && sgl->cur < MAX_SGL_ENTS);
|
||||
|
||||
plen = min_t(size_t, len, PAGE_SIZE);
|
||||
|
||||
pg = alloc_page(GFP_KERNEL);
|
||||
if (!pg) {
|
||||
err = -ENOMEM;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
sg_assign_page(sg + i, pg);
|
||||
|
||||
err = memcpy_from_msg(
|
||||
page_address(sg_page(sg + i)),
|
||||
msg, plen);
|
||||
if (err) {
|
||||
__free_page(sg_page(sg + i));
|
||||
sg_assign_page(sg + i, NULL);
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
sg[i].length = plen;
|
||||
len -= plen;
|
||||
ctx->used += plen;
|
||||
copied += plen;
|
||||
size -= plen;
|
||||
sgl->cur++;
|
||||
} while (len && sgl->cur < MAX_SGL_ENTS);
|
||||
|
||||
ctx->merge = plen & (PAGE_SIZE - 1);
|
||||
}
|
||||
ctx->merge = plen & (PAGE_SIZE - 1);
|
||||
|
||||
if (!size)
|
||||
sg_mark_end(sg + sgl->cur - 1);
|
||||
@@ -1106,35 +1085,6 @@ void af_alg_free_resources(struct af_alg_async_req *areq)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(af_alg_free_resources);
|
||||
|
||||
/**
|
||||
* af_alg_async_cb - AIO callback handler
|
||||
* @data: async request completion data
|
||||
* @err: if non-zero, error result to be returned via ki_complete();
|
||||
* otherwise return the AIO output length via ki_complete().
|
||||
*
|
||||
* This handler cleans up the struct af_alg_async_req upon completion of the
|
||||
* AIO operation.
|
||||
*
|
||||
* The number of bytes to be generated with the AIO operation must be set
|
||||
* in areq->outlen before the AIO callback handler is invoked.
|
||||
*/
|
||||
void af_alg_async_cb(void *data, int err)
|
||||
{
|
||||
struct af_alg_async_req *areq = data;
|
||||
struct sock *sk = areq->sk;
|
||||
struct kiocb *iocb = areq->iocb;
|
||||
unsigned int resultlen;
|
||||
|
||||
/* Buffer size written by crypto operation. */
|
||||
resultlen = areq->outlen;
|
||||
|
||||
af_alg_free_resources(areq);
|
||||
sock_put(sk);
|
||||
|
||||
iocb->ki_complete(iocb, err ? err : (int)resultlen);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(af_alg_async_cb);
|
||||
|
||||
/**
|
||||
* af_alg_poll - poll system call handler
|
||||
* @file: file pointer
|
||||
@@ -1175,8 +1125,8 @@ struct af_alg_async_req *af_alg_alloc_areq(struct sock *sk,
|
||||
struct af_alg_ctx *ctx = alg_sk(sk)->private;
|
||||
struct af_alg_async_req *areq;
|
||||
|
||||
/* Only one AIO request can be in flight. */
|
||||
if (ctx->inflight)
|
||||
/* Only one request can be in flight. */
|
||||
if (WARN_ON_ONCE(ctx->inflight))
|
||||
return ERR_PTR(-EBUSY);
|
||||
|
||||
areq = sock_kmalloc(sk, areqlen, GFP_KERNEL);
|
||||
|
||||
+3
-5
@@ -789,11 +789,9 @@ static void crypto_ahash_free_instance(struct crypto_instance *inst)
|
||||
static int __maybe_unused crypto_ahash_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_hash rhash;
|
||||
|
||||
memset(&rhash, 0, sizeof(rhash));
|
||||
|
||||
strscpy(rhash.type, "ahash", sizeof(rhash.type));
|
||||
struct crypto_report_hash rhash = {
|
||||
.type = "ahash",
|
||||
};
|
||||
|
||||
rhash.blocksize = alg->cra_blocksize;
|
||||
rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
|
||||
|
||||
+3
-5
@@ -36,11 +36,9 @@ struct crypto_akcipher_sync_data {
|
||||
static int __maybe_unused crypto_akcipher_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_akcipher rakcipher;
|
||||
|
||||
memset(&rakcipher, 0, sizeof(rakcipher));
|
||||
|
||||
strscpy(rakcipher.type, "akcipher", sizeof(rakcipher.type));
|
||||
struct crypto_report_akcipher rakcipher = {
|
||||
.type = "akcipher",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER,
|
||||
sizeof(rakcipher), &rakcipher);
|
||||
|
||||
+14
-37
@@ -9,10 +9,10 @@
|
||||
* The following concept of the memory management is used:
|
||||
*
|
||||
* The kernel maintains two SGLs, the TX SGL and the RX SGL. The TX SGL is
|
||||
* filled by user space with the data submitted via sendmsg (maybe with
|
||||
* MSG_SPLICE_PAGES). Filling up the TX SGL does not cause a crypto operation
|
||||
* -- the data will only be tracked by the kernel. Upon receipt of one recvmsg
|
||||
* call, the caller must provide a buffer which is tracked with the RX SGL.
|
||||
* filled by user space with the data submitted via sendmsg. Filling up the TX
|
||||
* SGL does not cause a crypto operation -- the data will only be tracked by the
|
||||
* kernel. Upon receipt of one recvmsg call, the caller must provide a buffer
|
||||
* which is tracked with the RX SGL.
|
||||
*
|
||||
* During the processing of the recvmsg operation, the cipher request is
|
||||
* allocated and prepared. As part of the recvmsg operation, the processed
|
||||
@@ -197,37 +197,14 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
|
||||
aead_request_set_ad(&areq->cra_u.aead_req, ctx->aead_assoclen);
|
||||
aead_request_set_tfm(&areq->cra_u.aead_req, tfm);
|
||||
|
||||
if (msg->msg_iocb && !is_sync_kiocb(msg->msg_iocb)) {
|
||||
/* AIO operation */
|
||||
sock_hold(sk);
|
||||
areq->iocb = msg->msg_iocb;
|
||||
|
||||
/* Remember output size that will be generated. */
|
||||
areq->outlen = outlen;
|
||||
|
||||
aead_request_set_callback(&areq->cra_u.aead_req,
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP,
|
||||
af_alg_async_cb, areq);
|
||||
err = ctx->enc ? crypto_aead_encrypt(&areq->cra_u.aead_req) :
|
||||
crypto_aead_decrypt(&areq->cra_u.aead_req);
|
||||
|
||||
/* AIO operation in progress */
|
||||
if (err == -EINPROGRESS)
|
||||
return -EIOCBQUEUED;
|
||||
|
||||
sock_put(sk);
|
||||
} else {
|
||||
/* Synchronous operation */
|
||||
aead_request_set_callback(&areq->cra_u.aead_req,
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP |
|
||||
CRYPTO_TFM_REQ_MAY_BACKLOG,
|
||||
crypto_req_done, &ctx->wait);
|
||||
err = crypto_wait_req(ctx->enc ?
|
||||
crypto_aead_encrypt(&areq->cra_u.aead_req) :
|
||||
crypto_aead_decrypt(&areq->cra_u.aead_req),
|
||||
&ctx->wait);
|
||||
}
|
||||
|
||||
aead_request_set_callback(&areq->cra_u.aead_req,
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP |
|
||||
CRYPTO_TFM_REQ_MAY_BACKLOG,
|
||||
crypto_req_done, &ctx->wait);
|
||||
err = crypto_wait_req(ctx->enc ?
|
||||
crypto_aead_encrypt(&areq->cra_u.aead_req) :
|
||||
crypto_aead_decrypt(&areq->cra_u.aead_req),
|
||||
&ctx->wait);
|
||||
|
||||
free:
|
||||
af_alg_free_resources(areq);
|
||||
@@ -365,9 +342,9 @@ static struct proto_ops algif_aead_ops_nokey = {
|
||||
.poll = af_alg_poll,
|
||||
};
|
||||
|
||||
static void *aead_bind(const char *name, u32 type, u32 mask)
|
||||
static void *aead_bind(const char *name)
|
||||
{
|
||||
return crypto_alloc_aead(name, type, mask);
|
||||
return crypto_alloc_aead(name, 0, AF_ALG_CRYPTOAPI_MASK);
|
||||
}
|
||||
|
||||
static void aead_release(void *private)
|
||||
|
||||
+2
-2
@@ -380,9 +380,9 @@ static struct proto_ops algif_hash_ops_nokey = {
|
||||
.accept = hash_accept_nokey,
|
||||
};
|
||||
|
||||
static void *hash_bind(const char *name, u32 type, u32 mask)
|
||||
static void *hash_bind(const char *name)
|
||||
{
|
||||
return crypto_alloc_ahash(name, type, mask);
|
||||
return crypto_alloc_ahash(name, 0, AF_ALG_CRYPTOAPI_MASK);
|
||||
}
|
||||
|
||||
static void hash_release(void *private)
|
||||
|
||||
+2
-2
@@ -197,7 +197,7 @@ static struct proto_ops __maybe_unused algif_rng_test_ops = {
|
||||
.sendmsg = rng_test_sendmsg,
|
||||
};
|
||||
|
||||
static void *rng_bind(const char *name, u32 type, u32 mask)
|
||||
static void *rng_bind(const char *name)
|
||||
{
|
||||
struct rng_parent_ctx *pctx;
|
||||
struct crypto_rng *rng;
|
||||
@@ -206,7 +206,7 @@ static void *rng_bind(const char *name, u32 type, u32 mask)
|
||||
if (!pctx)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
|
||||
rng = crypto_alloc_rng(name, type, mask);
|
||||
rng = crypto_alloc_rng(name, 0, AF_ALG_CRYPTOAPI_MASK);
|
||||
if (IS_ERR(rng)) {
|
||||
kfree(pctx);
|
||||
return ERR_CAST(rng);
|
||||
|
||||
+14
-52
@@ -79,20 +79,6 @@ static int algif_skcipher_export(struct sock *sk, struct skcipher_request *req)
|
||||
return err;
|
||||
}
|
||||
|
||||
static void algif_skcipher_done(void *data, int err)
|
||||
{
|
||||
struct af_alg_async_req *areq = data;
|
||||
struct sock *sk = areq->sk;
|
||||
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
err = algif_skcipher_export(sk, &areq->cra_u.skcipher_req);
|
||||
|
||||
out:
|
||||
af_alg_async_cb(data, err);
|
||||
}
|
||||
|
||||
static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
|
||||
size_t ignored, int flags)
|
||||
{
|
||||
@@ -171,43 +157,19 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
|
||||
cflags |= CRYPTO_SKCIPHER_REQ_CONT;
|
||||
}
|
||||
|
||||
if (msg->msg_iocb && !is_sync_kiocb(msg->msg_iocb)) {
|
||||
/* AIO operation */
|
||||
sock_hold(sk);
|
||||
areq->iocb = msg->msg_iocb;
|
||||
skcipher_request_set_callback(&areq->cra_u.skcipher_req,
|
||||
cflags |
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP |
|
||||
CRYPTO_TFM_REQ_MAY_BACKLOG,
|
||||
crypto_req_done, &ctx->wait);
|
||||
err = crypto_wait_req(ctx->enc ?
|
||||
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
|
||||
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req),
|
||||
&ctx->wait);
|
||||
|
||||
/* Remember output size that will be generated. */
|
||||
areq->outlen = len;
|
||||
|
||||
skcipher_request_set_callback(&areq->cra_u.skcipher_req,
|
||||
cflags |
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP,
|
||||
algif_skcipher_done, areq);
|
||||
err = ctx->enc ?
|
||||
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
|
||||
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req);
|
||||
|
||||
/* AIO operation in progress */
|
||||
if (err == -EINPROGRESS)
|
||||
return -EIOCBQUEUED;
|
||||
|
||||
sock_put(sk);
|
||||
} else {
|
||||
/* Synchronous operation */
|
||||
skcipher_request_set_callback(&areq->cra_u.skcipher_req,
|
||||
cflags |
|
||||
CRYPTO_TFM_REQ_MAY_SLEEP |
|
||||
CRYPTO_TFM_REQ_MAY_BACKLOG,
|
||||
crypto_req_done, &ctx->wait);
|
||||
err = crypto_wait_req(ctx->enc ?
|
||||
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
|
||||
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req),
|
||||
&ctx->wait);
|
||||
|
||||
if (!err)
|
||||
err = algif_skcipher_export(
|
||||
sk, &areq->cra_u.skcipher_req);
|
||||
}
|
||||
if (!err)
|
||||
err = algif_skcipher_export(
|
||||
sk, &areq->cra_u.skcipher_req);
|
||||
|
||||
free:
|
||||
af_alg_free_resources(areq);
|
||||
@@ -345,9 +307,9 @@ static struct proto_ops algif_skcipher_ops_nokey = {
|
||||
.poll = af_alg_poll,
|
||||
};
|
||||
|
||||
static void *skcipher_bind(const char *name, u32 type, u32 mask)
|
||||
static void *skcipher_bind(const char *name)
|
||||
{
|
||||
return crypto_alloc_skcipher(name, type, mask);
|
||||
return crypto_alloc_skcipher(name, 0, AF_ALG_CRYPTOAPI_MASK);
|
||||
}
|
||||
|
||||
static void skcipher_release(void *private)
|
||||
|
||||
@@ -95,7 +95,6 @@ config FIPS_SIGNATURE_SELFTEST
|
||||
verification code, using some built in data. This is required
|
||||
for FIPS.
|
||||
depends on KEYS
|
||||
depends on ASYMMETRIC_KEY_TYPE
|
||||
depends on PKCS7_MESSAGE_PARSER=X509_CERTIFICATE_PARSER
|
||||
depends on X509_CERTIFICATE_PARSER
|
||||
depends on CRYPTO_RSA
|
||||
|
||||
@@ -305,6 +305,8 @@ static int pefile_digest_pe_contents(const void *pebuf, unsigned int pelen,
|
||||
|
||||
if (pelen > hashed_bytes) {
|
||||
tmp = hashed_bytes + ctx->certs_size;
|
||||
if (tmp <= hashed_bytes || pelen < tmp)
|
||||
return -ELIBBAD;
|
||||
ret = crypto_shash_update(desc,
|
||||
pebuf + hashed_bytes,
|
||||
pelen - tmp);
|
||||
|
||||
@@ -20,7 +20,7 @@ int x509_load_certificate_list(const u8 cert_list[],
|
||||
*/
|
||||
if (end - p < 4)
|
||||
goto dodgy_cert;
|
||||
if (p[0] != 0x30 &&
|
||||
if (p[0] != 0x30 ||
|
||||
p[1] != 0x82)
|
||||
goto dodgy_cert;
|
||||
plen = (p[2] << 8) | p[3];
|
||||
|
||||
+16
-17
@@ -94,11 +94,11 @@ static int crypto_authenc_esn_genicv_tail(struct aead_request *req,
|
||||
u32 tmp[2];
|
||||
|
||||
/* Move high-order bits of sequence number back. */
|
||||
scatterwalk_map_and_copy(tmp, dst, 4, 4, 0);
|
||||
scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0);
|
||||
scatterwalk_map_and_copy(tmp, dst, 0, 8, 1);
|
||||
memcpy_from_sglist(tmp, dst, 4, 4);
|
||||
memcpy_from_sglist(tmp + 1, dst, assoclen + cryptlen, 4);
|
||||
memcpy_to_sglist(dst, 0, tmp, 8);
|
||||
|
||||
scatterwalk_map_and_copy(hash, dst, assoclen + cryptlen, authsize, 1);
|
||||
memcpy_to_sglist(dst, assoclen + cryptlen, hash, authsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ static int crypto_authenc_esn_genicv(struct aead_request *req,
|
||||
return 0;
|
||||
|
||||
/* Move high-order bits of sequence number to the end. */
|
||||
scatterwalk_map_and_copy(tmp, dst, 0, 8, 0);
|
||||
scatterwalk_map_and_copy(tmp, dst, 4, 4, 1);
|
||||
scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
|
||||
memcpy_from_sglist(tmp, dst, 0, 8);
|
||||
memcpy_to_sglist(dst, 4, tmp, 4);
|
||||
memcpy_to_sglist(dst, assoclen + cryptlen, tmp + 1, 4);
|
||||
|
||||
sg_init_table(areq_ctx->dst, 2);
|
||||
dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
|
||||
@@ -217,9 +217,9 @@ static int crypto_authenc_esn_decrypt_tail(struct aead_request *req,
|
||||
|
||||
if (src == dst) {
|
||||
/* Move high-order bits of sequence number back. */
|
||||
scatterwalk_map_and_copy(tmp, dst, 4, 4, 0);
|
||||
scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0);
|
||||
scatterwalk_map_and_copy(tmp, dst, 0, 8, 1);
|
||||
memcpy_from_sglist(tmp, dst, 4, 4);
|
||||
memcpy_from_sglist(tmp + 1, dst, assoclen + cryptlen, 4);
|
||||
memcpy_to_sglist(dst, 0, tmp, 8);
|
||||
} else
|
||||
memcpy_sglist(dst, src, assoclen);
|
||||
|
||||
@@ -274,18 +274,17 @@ static int crypto_authenc_esn_decrypt(struct aead_request *req)
|
||||
goto tail;
|
||||
|
||||
cryptlen -= authsize;
|
||||
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen,
|
||||
authsize, 0);
|
||||
memcpy_from_sglist(ihash, req->src, assoclen + cryptlen, authsize);
|
||||
|
||||
/* Move high-order bits of sequence number to the end. */
|
||||
scatterwalk_map_and_copy(tmp, src, 0, 8, 0);
|
||||
memcpy_from_sglist(tmp, src, 0, 8);
|
||||
if (src == dst) {
|
||||
scatterwalk_map_and_copy(tmp, dst, 4, 4, 1);
|
||||
scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1);
|
||||
memcpy_to_sglist(dst, 4, tmp, 4);
|
||||
memcpy_to_sglist(dst, assoclen + cryptlen, tmp + 1, 4);
|
||||
dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
|
||||
} else {
|
||||
scatterwalk_map_and_copy(tmp, dst, 0, 4, 1);
|
||||
scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen - 4, 4, 1);
|
||||
memcpy_to_sglist(dst, 0, tmp, 4);
|
||||
memcpy_to_sglist(dst, assoclen + cryptlen - 4, tmp + 1, 4);
|
||||
|
||||
src = scatterwalk_ffwd(areq_ctx->src, src, 8);
|
||||
dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4);
|
||||
|
||||
@@ -375,6 +375,7 @@ static int chachapoly_create(struct crypto_template *tmpl, struct rtattr **tb,
|
||||
struct aead_instance *inst;
|
||||
struct chachapoly_instance_ctx *ctx;
|
||||
struct skcipher_alg_common *chacha;
|
||||
const char *poly_name;
|
||||
int err;
|
||||
|
||||
if (ivsize > CHACHAPOLY_IV_SIZE)
|
||||
@@ -396,9 +397,15 @@ static int chachapoly_create(struct crypto_template *tmpl, struct rtattr **tb,
|
||||
goto err_free_inst;
|
||||
chacha = crypto_spawn_skcipher_alg_common(&ctx->chacha);
|
||||
|
||||
poly_name = crypto_attr_alg_name(tb[2]);
|
||||
if (IS_ERR(poly_name)) {
|
||||
err = PTR_ERR(poly_name);
|
||||
goto err_free_inst;
|
||||
}
|
||||
|
||||
err = -EINVAL;
|
||||
if (strcmp(crypto_attr_alg_name(tb[2]), "poly1305") &&
|
||||
strcmp(crypto_attr_alg_name(tb[2]), "poly1305-generic"))
|
||||
if (strcmp(poly_name, "poly1305") &&
|
||||
strcmp(poly_name, "poly1305-generic"))
|
||||
goto err_free_inst;
|
||||
/* Need 16-byte IV size, including Initial Block Counter value */
|
||||
if (chacha->ivsize != CHACHA_IV_SIZE)
|
||||
|
||||
+2
-33
@@ -50,15 +50,6 @@ static int null_skcipher_setkey(struct crypto_skcipher *tfm, const u8 *key,
|
||||
unsigned int keylen)
|
||||
{ return 0; }
|
||||
|
||||
static int null_setkey(struct crypto_tfm *tfm, const u8 *key,
|
||||
unsigned int keylen)
|
||||
{ return 0; }
|
||||
|
||||
static void null_crypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
|
||||
{
|
||||
memcpy(dst, src, NULL_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
static int null_skcipher_crypt(struct skcipher_request *req)
|
||||
{
|
||||
if (req->src != req->dst)
|
||||
@@ -97,35 +88,16 @@ static struct skcipher_alg skcipher_null = {
|
||||
.decrypt = null_skcipher_crypt,
|
||||
};
|
||||
|
||||
static struct crypto_alg cipher_null = {
|
||||
.cra_name = "cipher_null",
|
||||
.cra_driver_name = "cipher_null-generic",
|
||||
.cra_flags = CRYPTO_ALG_TYPE_CIPHER,
|
||||
.cra_blocksize = NULL_BLOCK_SIZE,
|
||||
.cra_ctxsize = 0,
|
||||
.cra_module = THIS_MODULE,
|
||||
.cra_u = { .cipher = {
|
||||
.cia_min_keysize = NULL_KEY_SIZE,
|
||||
.cia_max_keysize = NULL_KEY_SIZE,
|
||||
.cia_setkey = null_setkey,
|
||||
.cia_encrypt = null_crypt,
|
||||
.cia_decrypt = null_crypt } }
|
||||
};
|
||||
|
||||
MODULE_ALIAS_CRYPTO("digest_null");
|
||||
MODULE_ALIAS_CRYPTO("cipher_null");
|
||||
MODULE_ALIAS_CRYPTO("ecb(cipher_null)");
|
||||
|
||||
static int __init crypto_null_mod_init(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret = crypto_register_alg(&cipher_null);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
ret = crypto_register_shash(&digest_null);
|
||||
if (ret < 0)
|
||||
goto out_unregister_algs;
|
||||
goto out;
|
||||
|
||||
ret = crypto_register_skcipher(&skcipher_null);
|
||||
if (ret < 0)
|
||||
@@ -135,15 +107,12 @@ static int __init crypto_null_mod_init(void)
|
||||
|
||||
out_unregister_shash:
|
||||
crypto_unregister_shash(&digest_null);
|
||||
out_unregister_algs:
|
||||
crypto_unregister_alg(&cipher_null);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void __exit crypto_null_mod_fini(void)
|
||||
{
|
||||
crypto_unregister_alg(&cipher_null);
|
||||
crypto_unregister_shash(&digest_null);
|
||||
crypto_unregister_skcipher(&skcipher_null);
|
||||
}
|
||||
|
||||
@@ -70,11 +70,9 @@ static struct crypto_alg *crypto_alg_match(struct crypto_user_alg *p, int exact)
|
||||
|
||||
static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_cipher rcipher;
|
||||
|
||||
memset(&rcipher, 0, sizeof(rcipher));
|
||||
|
||||
strscpy(rcipher.type, "cipher", sizeof(rcipher.type));
|
||||
struct crypto_report_cipher rcipher = {
|
||||
.type = "cipher",
|
||||
};
|
||||
|
||||
rcipher.blocksize = alg->cra_blocksize;
|
||||
rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
|
||||
@@ -103,10 +101,10 @@ static int crypto_report_one(struct crypto_alg *alg,
|
||||
if (nla_put_u32(skb, CRYPTOCFGA_PRIORITY_VAL, alg->cra_priority))
|
||||
goto nla_put_failure;
|
||||
if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
|
||||
struct crypto_report_larval rl;
|
||||
struct crypto_report_larval rl = {
|
||||
.type = "larval",
|
||||
};
|
||||
|
||||
memset(&rl, 0, sizeof(rl));
|
||||
strscpy(rl.type, "larval", sizeof(rl.type));
|
||||
if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL, sizeof(rl), &rl))
|
||||
goto nla_put_failure;
|
||||
goto out;
|
||||
|
||||
@@ -1,222 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
/*
|
||||
* NIST SP800-90A DRBG derivation function
|
||||
*
|
||||
* Copyright (C) 2014, Stephan Mueller <smueller@chronox.de>
|
||||
*/
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/df_sp80090a.h>
|
||||
#include <crypto/internal/drbg.h>
|
||||
|
||||
static void drbg_kcapi_sym(struct aes_enckey *aeskey, unsigned char *outval,
|
||||
const struct drbg_string *in, u8 blocklen_bytes)
|
||||
{
|
||||
/* there is only component in *in */
|
||||
BUG_ON(in->len < blocklen_bytes);
|
||||
aes_encrypt(aeskey, outval, in->buf);
|
||||
}
|
||||
|
||||
/* BCC function for CTR DRBG as defined in 10.4.3 */
|
||||
|
||||
static void drbg_ctr_bcc(struct aes_enckey *aeskey,
|
||||
unsigned char *out, const unsigned char *key,
|
||||
struct list_head *in,
|
||||
u8 blocklen_bytes,
|
||||
u8 keylen)
|
||||
{
|
||||
struct drbg_string *curr = NULL;
|
||||
struct drbg_string data;
|
||||
short cnt = 0;
|
||||
|
||||
drbg_string_fill(&data, out, blocklen_bytes);
|
||||
|
||||
/* 10.4.3 step 2 / 4 */
|
||||
aes_prepareenckey(aeskey, key, keylen);
|
||||
list_for_each_entry(curr, in, list) {
|
||||
const unsigned char *pos = curr->buf;
|
||||
size_t len = curr->len;
|
||||
/* 10.4.3 step 4.1 */
|
||||
while (len) {
|
||||
/* 10.4.3 step 4.2 */
|
||||
if (blocklen_bytes == cnt) {
|
||||
cnt = 0;
|
||||
drbg_kcapi_sym(aeskey, out, &data, blocklen_bytes);
|
||||
}
|
||||
out[cnt] ^= *pos;
|
||||
pos++;
|
||||
cnt++;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
/* 10.4.3 step 4.2 for last block */
|
||||
if (cnt)
|
||||
drbg_kcapi_sym(aeskey, out, &data, blocklen_bytes);
|
||||
}
|
||||
|
||||
/*
|
||||
* scratchpad usage: drbg_ctr_update is interlinked with crypto_drbg_ctr_df
|
||||
* (and drbg_ctr_bcc, but this function does not need any temporary buffers),
|
||||
* the scratchpad is used as follows:
|
||||
* drbg_ctr_update:
|
||||
* temp
|
||||
* start: drbg->scratchpad
|
||||
* length: drbg_statelen(drbg) + drbg_blocklen(drbg)
|
||||
* note: the cipher writing into this variable works
|
||||
* blocklen-wise. Now, when the statelen is not a multiple
|
||||
* of blocklen, the generateion loop below "spills over"
|
||||
* by at most blocklen. Thus, we need to give sufficient
|
||||
* memory.
|
||||
* df_data
|
||||
* start: drbg->scratchpad +
|
||||
* drbg_statelen(drbg) + drbg_blocklen(drbg)
|
||||
* length: drbg_statelen(drbg)
|
||||
*
|
||||
* crypto_drbg_ctr_df:
|
||||
* pad
|
||||
* start: df_data + drbg_statelen(drbg)
|
||||
* length: drbg_blocklen(drbg)
|
||||
* iv
|
||||
* start: pad + drbg_blocklen(drbg)
|
||||
* length: drbg_blocklen(drbg)
|
||||
* temp
|
||||
* start: iv + drbg_blocklen(drbg)
|
||||
* length: drbg_satelen(drbg) + drbg_blocklen(drbg)
|
||||
* note: temp is the buffer that the BCC function operates
|
||||
* on. BCC operates blockwise. drbg_statelen(drbg)
|
||||
* is sufficient when the DRBG state length is a multiple
|
||||
* of the block size. For AES192 (and maybe other ciphers)
|
||||
* this is not correct and the length for temp is
|
||||
* insufficient (yes, that also means for such ciphers,
|
||||
* the final output of all BCC rounds are truncated).
|
||||
* Therefore, add drbg_blocklen(drbg) to cover all
|
||||
* possibilities.
|
||||
* refer to crypto_drbg_ctr_df_datalen() to get required length
|
||||
*/
|
||||
|
||||
/* Derivation Function for CTR DRBG as defined in 10.4.2 */
|
||||
int crypto_drbg_ctr_df(struct aes_enckey *aeskey,
|
||||
unsigned char *df_data, size_t bytes_to_return,
|
||||
struct list_head *seedlist,
|
||||
u8 blocklen_bytes,
|
||||
u8 statelen)
|
||||
{
|
||||
unsigned char L_N[8];
|
||||
/* S3 is input */
|
||||
struct drbg_string S1, S2, S4, cipherin;
|
||||
LIST_HEAD(bcc_list);
|
||||
unsigned char *pad = df_data + statelen;
|
||||
unsigned char *iv = pad + blocklen_bytes;
|
||||
unsigned char *temp = iv + blocklen_bytes;
|
||||
size_t padlen = 0;
|
||||
unsigned int templen = 0;
|
||||
/* 10.4.2 step 7 */
|
||||
unsigned int i = 0;
|
||||
/* 10.4.2 step 8 */
|
||||
const unsigned char *K = (unsigned char *)
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07"
|
||||
"\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17"
|
||||
"\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f";
|
||||
unsigned char *X;
|
||||
size_t generated_len = 0;
|
||||
size_t inputlen = 0;
|
||||
struct drbg_string *seed = NULL;
|
||||
u8 keylen;
|
||||
|
||||
memset(pad, 0, blocklen_bytes);
|
||||
memset(iv, 0, blocklen_bytes);
|
||||
keylen = statelen - blocklen_bytes;
|
||||
/* 10.4.2 step 1 is implicit as we work byte-wise */
|
||||
|
||||
/* 10.4.2 step 2 */
|
||||
if ((512 / 8) < bytes_to_return)
|
||||
return -EINVAL;
|
||||
|
||||
/* 10.4.2 step 2 -- calculate the entire length of all input data */
|
||||
list_for_each_entry(seed, seedlist, list)
|
||||
inputlen += seed->len;
|
||||
drbg_cpu_to_be32(inputlen, &L_N[0]);
|
||||
|
||||
/* 10.4.2 step 3 */
|
||||
drbg_cpu_to_be32(bytes_to_return, &L_N[4]);
|
||||
|
||||
/* 10.4.2 step 5: length is L_N, input_string, one byte, padding */
|
||||
padlen = (inputlen + sizeof(L_N) + 1) % (blocklen_bytes);
|
||||
/* wrap the padlen appropriately */
|
||||
if (padlen)
|
||||
padlen = blocklen_bytes - padlen;
|
||||
/*
|
||||
* pad / padlen contains the 0x80 byte and the following zero bytes.
|
||||
* As the calculated padlen value only covers the number of zero
|
||||
* bytes, this value has to be incremented by one for the 0x80 byte.
|
||||
*/
|
||||
padlen++;
|
||||
pad[0] = 0x80;
|
||||
|
||||
/* 10.4.2 step 4 -- first fill the linked list and then order it */
|
||||
drbg_string_fill(&S1, iv, blocklen_bytes);
|
||||
list_add_tail(&S1.list, &bcc_list);
|
||||
drbg_string_fill(&S2, L_N, sizeof(L_N));
|
||||
list_add_tail(&S2.list, &bcc_list);
|
||||
list_splice_tail(seedlist, &bcc_list);
|
||||
drbg_string_fill(&S4, pad, padlen);
|
||||
list_add_tail(&S4.list, &bcc_list);
|
||||
|
||||
/* 10.4.2 step 9 */
|
||||
while (templen < (keylen + (blocklen_bytes))) {
|
||||
/*
|
||||
* 10.4.2 step 9.1 - the padding is implicit as the buffer
|
||||
* holds zeros after allocation -- even the increment of i
|
||||
* is irrelevant as the increment remains within length of i
|
||||
*/
|
||||
drbg_cpu_to_be32(i, iv);
|
||||
/* 10.4.2 step 9.2 -- BCC and concatenation with temp */
|
||||
drbg_ctr_bcc(aeskey, temp + templen, K, &bcc_list,
|
||||
blocklen_bytes, keylen);
|
||||
/* 10.4.2 step 9.3 */
|
||||
i++;
|
||||
templen += blocklen_bytes;
|
||||
}
|
||||
|
||||
/* 10.4.2 step 11 */
|
||||
X = temp + (keylen);
|
||||
drbg_string_fill(&cipherin, X, blocklen_bytes);
|
||||
|
||||
/* 10.4.2 step 12: overwriting of outval is implemented in next step */
|
||||
|
||||
/* 10.4.2 step 13 */
|
||||
aes_prepareenckey(aeskey, temp, keylen);
|
||||
while (generated_len < bytes_to_return) {
|
||||
short blocklen = 0;
|
||||
/*
|
||||
* 10.4.2 step 13.1: the truncation of the key length is
|
||||
* implicit as the key is only drbg_blocklen in size based on
|
||||
* the implementation of the cipher function callback
|
||||
*/
|
||||
drbg_kcapi_sym(aeskey, X, &cipherin, blocklen_bytes);
|
||||
blocklen = (blocklen_bytes <
|
||||
(bytes_to_return - generated_len)) ?
|
||||
blocklen_bytes :
|
||||
(bytes_to_return - generated_len);
|
||||
/* 10.4.2 step 13.2 and 14 */
|
||||
memcpy(df_data + generated_len, X, blocklen);
|
||||
generated_len += blocklen;
|
||||
}
|
||||
|
||||
memset(iv, 0, blocklen_bytes);
|
||||
memset(temp, 0, statelen + blocklen_bytes);
|
||||
memset(pad, 0, blocklen_bytes);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_drbg_ctr_df);
|
||||
|
||||
MODULE_IMPORT_NS("CRYPTO_INTERNAL");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_AUTHOR("Stephan Mueller <smueller@chronox.de>");
|
||||
MODULE_DESCRIPTION("Derivation Function conformant to SP800-90A");
|
||||
+266
-1553
File diff suppressed because it is too large
Load Diff
+20
-11
@@ -393,14 +393,26 @@ static uint128_t mul_64_64(u64 left, u64 right)
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint128_t add_128_128(uint128_t a, uint128_t b)
|
||||
/* Calculate addition with overflow checking. Returns true on wrap-around,
|
||||
* false otherwise.
|
||||
*/
|
||||
static bool check_add_128_128_overflow(uint128_t *result, uint128_t a,
|
||||
uint128_t b)
|
||||
{
|
||||
uint128_t result;
|
||||
bool carry;
|
||||
|
||||
result.m_low = a.m_low + b.m_low;
|
||||
result.m_high = a.m_high + b.m_high + (result.m_low < a.m_low);
|
||||
result->m_low = a.m_low + b.m_low;
|
||||
carry = (result->m_low < a.m_low);
|
||||
|
||||
return result;
|
||||
result->m_high = a.m_high + b.m_high + carry;
|
||||
|
||||
/* Using constant-time bitwise arithmetic to prevent timing
|
||||
* side-channels.
|
||||
*/
|
||||
carry = (result->m_high < a.m_high) |
|
||||
((result->m_high == a.m_high) & carry);
|
||||
|
||||
return carry;
|
||||
}
|
||||
|
||||
static void vli_mult(u64 *result, const u64 *left, const u64 *right,
|
||||
@@ -425,9 +437,7 @@ static void vli_mult(u64 *result, const u64 *left, const u64 *right,
|
||||
uint128_t product;
|
||||
|
||||
product = mul_64_64(left[i], right[k - i]);
|
||||
|
||||
r01 = add_128_128(r01, product);
|
||||
r2 += (r01.m_high < product.m_high);
|
||||
r2 += check_add_128_128_overflow(&r01, r01, product);
|
||||
}
|
||||
|
||||
result[k] = r01.m_low;
|
||||
@@ -450,7 +460,7 @@ static void vli_umult(u64 *result, const u64 *left, u32 right,
|
||||
uint128_t product;
|
||||
|
||||
product = mul_64_64(left[k], right);
|
||||
r01 = add_128_128(r01, product);
|
||||
check_add_128_128_overflow(&r01, r01, product);
|
||||
/* no carry */
|
||||
result[k] = r01.m_low;
|
||||
r01.m_low = r01.m_high;
|
||||
@@ -487,8 +497,7 @@ static void vli_square(u64 *result, const u64 *left, unsigned int ndigits)
|
||||
product.m_low <<= 1;
|
||||
}
|
||||
|
||||
r01 = add_128_128(r01, product);
|
||||
r2 += (r01.m_high < product.m_high);
|
||||
r2 += check_add_128_128_overflow(&r01, r01, product);
|
||||
}
|
||||
|
||||
result[k] = r01.m_low;
|
||||
|
||||
+1
-6
@@ -145,7 +145,7 @@ int ecrdsa_param_curve(void *context, size_t hdrlen, unsigned char tag,
|
||||
struct ecrdsa_ctx *ctx = context;
|
||||
|
||||
ctx->curve_oid = look_up_OID(value, vlen);
|
||||
if (!ctx->curve_oid)
|
||||
if (ctx->curve_oid == OID__NR)
|
||||
return -EINVAL;
|
||||
ctx->curve = get_curve_by_oid(ctx->curve_oid);
|
||||
return 0;
|
||||
@@ -259,16 +259,11 @@ static unsigned int ecrdsa_max_size(struct crypto_sig *tfm)
|
||||
return 2 * ctx->pub_key.ndigits * sizeof(u64);
|
||||
}
|
||||
|
||||
static void ecrdsa_exit_tfm(struct crypto_sig *tfm)
|
||||
{
|
||||
}
|
||||
|
||||
static struct sig_alg ecrdsa_alg = {
|
||||
.verify = ecrdsa_verify,
|
||||
.set_pub_key = ecrdsa_set_pub_key,
|
||||
.key_size = ecrdsa_key_size,
|
||||
.max_size = ecrdsa_max_size,
|
||||
.exit = ecrdsa_exit_tfm,
|
||||
.base = {
|
||||
.cra_name = "ecrdsa",
|
||||
.cra_driver_name = "ecrdsa-generic",
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Design
|
||||
* ======
|
||||
*
|
||||
* See https://www.chronox.de/jent.html
|
||||
* See https://www.chronox.de/jent/
|
||||
*
|
||||
* License
|
||||
* =======
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
/*
|
||||
* This Jitterentropy RNG is based on the jitterentropy library
|
||||
* version 3.4.0 provided at https://www.chronox.de/jent.html
|
||||
* version 3.4.0 provided at https://www.chronox.de/jent/
|
||||
*/
|
||||
|
||||
#ifdef __OPTIMIZE__
|
||||
@@ -775,7 +775,7 @@ int jent_entropy_init(unsigned int osr, unsigned int flags,
|
||||
* delta even when called shortly after each other -- this
|
||||
* implies that we also have a high resolution timer
|
||||
*/
|
||||
if (!delta || (end_time == start_time)) {
|
||||
if (!delta) {
|
||||
ret = JENT_ECOARSETIME;
|
||||
goto out;
|
||||
}
|
||||
|
||||
+3
-5
@@ -20,11 +20,9 @@
|
||||
static int __maybe_unused crypto_kpp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_kpp rkpp;
|
||||
|
||||
memset(&rkpp, 0, sizeof(rkpp));
|
||||
|
||||
strscpy(rkpp.type, "kpp", sizeof(rkpp.type));
|
||||
struct crypto_report_kpp rkpp = {
|
||||
.type = "kpp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_KPP, sizeof(rkpp), &rkpp);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ struct crypto_aead *krb5_prepare_encryption(const struct krb5_enctype *krb5,
|
||||
struct crypto_aead *ci = NULL;
|
||||
int ret = -ENOMEM;
|
||||
|
||||
ci = crypto_alloc_aead(krb5->encrypt_name, 0, 0);
|
||||
ci = crypto_alloc_aead(krb5->encrypt_name, 0, CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(ci)) {
|
||||
ret = PTR_ERR(ci);
|
||||
if (ret == -ENOENT)
|
||||
|
||||
+4
-6
@@ -264,12 +264,10 @@ static int __maybe_unused crypto_lskcipher_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct lskcipher_alg *skcipher = __crypto_lskcipher_alg(alg);
|
||||
struct crypto_report_blkcipher rblkcipher;
|
||||
|
||||
memset(&rblkcipher, 0, sizeof(rblkcipher));
|
||||
|
||||
strscpy(rblkcipher.type, "lskcipher", sizeof(rblkcipher.type));
|
||||
strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
|
||||
struct crypto_report_blkcipher rblkcipher = {
|
||||
.type = "lskcipher",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
rblkcipher.blocksize = alg->cra_blocksize;
|
||||
rblkcipher.min_keysize = skcipher->co.min_keysize;
|
||||
|
||||
@@ -122,6 +122,8 @@ static int pcrypt_aead_encrypt(struct aead_request *req)
|
||||
return -EINPROGRESS;
|
||||
if (err == -EBUSY) {
|
||||
/* try non-parallel mode */
|
||||
aead_request_set_callback(creq, flags, req->base.complete,
|
||||
req->base.data);
|
||||
return crypto_aead_encrypt(creq);
|
||||
}
|
||||
|
||||
@@ -173,6 +175,8 @@ static int pcrypt_aead_decrypt(struct aead_request *req)
|
||||
return -EINPROGRESS;
|
||||
if (err == -EBUSY) {
|
||||
/* try non-parallel mode */
|
||||
aead_request_set_callback(creq, flags, req->base.complete,
|
||||
req->base.data);
|
||||
return crypto_aead_decrypt(creq);
|
||||
}
|
||||
|
||||
|
||||
+14
-5
@@ -65,11 +65,9 @@ static unsigned int seedsize(struct crypto_alg *alg)
|
||||
static int __maybe_unused crypto_rng_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_rng rrng;
|
||||
|
||||
memset(&rrng, 0, sizeof(rrng));
|
||||
|
||||
strscpy(rrng.type, "rng", sizeof(rrng.type));
|
||||
struct crypto_report_rng rrng = {
|
||||
.type = "rng",
|
||||
};
|
||||
|
||||
rrng.seedsize = seedsize(alg);
|
||||
|
||||
@@ -232,5 +230,16 @@ void crypto_unregister_rngs(struct rng_alg *algs, int count)
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(crypto_unregister_rngs);
|
||||
|
||||
static void __exit rng_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = crypto_del_default_rng();
|
||||
if (err)
|
||||
pr_err("Failed delete default RNG: %d\n", err);
|
||||
}
|
||||
|
||||
module_exit(rng_exit);
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("Random Number Generator");
|
||||
|
||||
+3
-5
@@ -48,11 +48,9 @@ static DECLARE_WORK(scomp_scratch_work, scomp_scratch_workfn);
|
||||
static int __maybe_unused crypto_scomp_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_comp rscomp;
|
||||
|
||||
memset(&rscomp, 0, sizeof(rscomp));
|
||||
|
||||
strscpy(rscomp.type, "scomp", sizeof(rscomp.type));
|
||||
struct crypto_report_comp rscomp = {
|
||||
.type = "scomp",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
|
||||
sizeof(rscomp), &rscomp);
|
||||
|
||||
+3
-5
@@ -333,12 +333,10 @@ static void crypto_shash_free_instance(struct crypto_instance *inst)
|
||||
static int __maybe_unused crypto_shash_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_hash rhash;
|
||||
struct shash_alg *salg = __crypto_shash_alg(alg);
|
||||
|
||||
memset(&rhash, 0, sizeof(rhash));
|
||||
|
||||
strscpy(rhash.type, "shash", sizeof(rhash.type));
|
||||
struct crypto_report_hash rhash = {
|
||||
.type = "shash",
|
||||
};
|
||||
|
||||
rhash.blocksize = alg->cra_blocksize;
|
||||
rhash.digestsize = salg->digestsize;
|
||||
|
||||
+3
-3
@@ -53,9 +53,9 @@ static void __maybe_unused crypto_sig_show(struct seq_file *m,
|
||||
static int __maybe_unused crypto_sig_report(struct sk_buff *skb,
|
||||
struct crypto_alg *alg)
|
||||
{
|
||||
struct crypto_report_sig rsig = {};
|
||||
|
||||
strscpy(rsig.type, "sig", sizeof(rsig.type));
|
||||
struct crypto_report_sig rsig = {
|
||||
.type = "sig",
|
||||
};
|
||||
|
||||
return nla_put(skb, CRYPTOCFGA_REPORT_SIG, sizeof(rsig), &rsig);
|
||||
}
|
||||
|
||||
+4
-6
@@ -591,12 +591,10 @@ static int __maybe_unused crypto_skcipher_report(
|
||||
struct sk_buff *skb, struct crypto_alg *alg)
|
||||
{
|
||||
struct skcipher_alg *skcipher = __crypto_skcipher_alg(alg);
|
||||
struct crypto_report_blkcipher rblkcipher;
|
||||
|
||||
memset(&rblkcipher, 0, sizeof(rblkcipher));
|
||||
|
||||
strscpy(rblkcipher.type, "skcipher", sizeof(rblkcipher.type));
|
||||
strscpy(rblkcipher.geniv, "<none>", sizeof(rblkcipher.geniv));
|
||||
struct crypto_report_blkcipher rblkcipher = {
|
||||
.type = "skcipher",
|
||||
.geniv = "<none>",
|
||||
};
|
||||
|
||||
rblkcipher.blocksize = alg->cra_blocksize;
|
||||
rblkcipher.min_keysize = skcipher->min_keysize;
|
||||
|
||||
+29
-133
@@ -28,13 +28,12 @@
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/uio.h>
|
||||
#include <crypto/rng.h>
|
||||
#include <crypto/drbg.h>
|
||||
#include <crypto/akcipher.h>
|
||||
#include <crypto/kpp.h>
|
||||
#include <crypto/acompress.h>
|
||||
#include <crypto/sig.h>
|
||||
#include <crypto/internal/cipher.h>
|
||||
#include <crypto/internal/rng.h>
|
||||
#include <crypto/internal/simd.h>
|
||||
|
||||
#include "internal.h"
|
||||
@@ -3482,13 +3481,11 @@ static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
|
||||
return err;
|
||||
}
|
||||
|
||||
static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
|
||||
const char *driver, u32 type, u32 mask)
|
||||
static int drbg_cavs_test(const struct drbg_testvec *test, const char *driver,
|
||||
u32 type, u32 mask)
|
||||
{
|
||||
int ret = -EAGAIN;
|
||||
struct crypto_rng *drng;
|
||||
struct drbg_test_data test_data;
|
||||
struct drbg_string addtl, pers, testentropy;
|
||||
unsigned char *buf = kzalloc(test->expectedlen, GFP_KERNEL);
|
||||
|
||||
if (!buf)
|
||||
@@ -3504,39 +3501,34 @@ static int drbg_cavs_test(const struct drbg_testvec *test, int pr,
|
||||
return PTR_ERR(drng);
|
||||
}
|
||||
|
||||
test_data.testentropy = &testentropy;
|
||||
drbg_string_fill(&testentropy, test->entropy, test->entropylen);
|
||||
drbg_string_fill(&pers, test->pers, test->perslen);
|
||||
ret = crypto_drbg_reset_test(drng, &pers, &test_data);
|
||||
crypto_rng_set_entropy(drng, test->entropy, test->entropylen);
|
||||
ret = crypto_rng_reset(drng, test->pers, test->perslen);
|
||||
if (ret) {
|
||||
printk(KERN_ERR "alg: drbg: Failed to reset rng\n");
|
||||
printk(KERN_ERR "alg: drbg: Failed to instantiate rng\n");
|
||||
goto outbuf;
|
||||
}
|
||||
|
||||
drbg_string_fill(&addtl, test->addtla, test->addtllen);
|
||||
if (pr) {
|
||||
drbg_string_fill(&testentropy, test->entpra, test->entprlen);
|
||||
ret = crypto_drbg_get_bytes_addtl_test(drng,
|
||||
buf, test->expectedlen, &addtl, &test_data);
|
||||
} else {
|
||||
ret = crypto_drbg_get_bytes_addtl(drng,
|
||||
buf, test->expectedlen, &addtl);
|
||||
if (test->ent_reseed_len) {
|
||||
crypto_rng_set_entropy(drng, test->ent_reseed,
|
||||
test->ent_reseed_len);
|
||||
ret = crypto_rng_reset(drng, test->addtl_reseed,
|
||||
test->addtl_reseed_len);
|
||||
if (ret) {
|
||||
printk(KERN_ERR "alg: drbg: Failed to reseed rng\n");
|
||||
goto outbuf;
|
||||
}
|
||||
}
|
||||
|
||||
ret = crypto_rng_generate(drng, test->addtla, test->addtllen,
|
||||
buf, test->expectedlen);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "alg: drbg: could not obtain random data for "
|
||||
"driver %s\n", driver);
|
||||
goto outbuf;
|
||||
}
|
||||
|
||||
drbg_string_fill(&addtl, test->addtlb, test->addtllen);
|
||||
if (pr) {
|
||||
drbg_string_fill(&testentropy, test->entprb, test->entprlen);
|
||||
ret = crypto_drbg_get_bytes_addtl_test(drng,
|
||||
buf, test->expectedlen, &addtl, &test_data);
|
||||
} else {
|
||||
ret = crypto_drbg_get_bytes_addtl(drng,
|
||||
buf, test->expectedlen, &addtl);
|
||||
}
|
||||
ret = crypto_rng_generate(drng, test->addtlb, test->addtllen,
|
||||
buf, test->expectedlen);
|
||||
if (ret < 0) {
|
||||
printk(KERN_ERR "alg: drbg: could not obtain random data for "
|
||||
"driver %s\n", driver);
|
||||
@@ -3556,16 +3548,12 @@ static int alg_test_drbg(const struct alg_test_desc *desc, const char *driver,
|
||||
u32 type, u32 mask)
|
||||
{
|
||||
int err = 0;
|
||||
int pr = 0;
|
||||
int i = 0;
|
||||
const struct drbg_testvec *template = desc->suite.drbg.vecs;
|
||||
unsigned int tcount = desc->suite.drbg.count;
|
||||
|
||||
if (0 == memcmp(driver, "drbg_pr_", 8))
|
||||
pr = 1;
|
||||
|
||||
for (i = 0; i < tcount; i++) {
|
||||
err = drbg_cavs_test(&template[i], pr, driver, type, mask);
|
||||
err = drbg_cavs_test(&template[i], driver, type, mask);
|
||||
if (err) {
|
||||
printk(KERN_ERR "alg: drbg: Test %d failed for %s\n",
|
||||
i, driver);
|
||||
@@ -4215,6 +4203,7 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
.alg = "authenc(hmac(sha256),cts(cbc(aes)))",
|
||||
.generic_driver = "authenc(hmac-sha256-lib,cts(cbc(aes-lib)))",
|
||||
.test = alg_test_aead,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.aead = __VECS(krb5_test_aes128_cts_hmac_sha256_128)
|
||||
}
|
||||
@@ -4256,6 +4245,7 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
.alg = "authenc(hmac(sha384),cts(cbc(aes)))",
|
||||
.generic_driver = "authenc(hmac-sha384-lib,cts(cbc(aes-lib)))",
|
||||
.test = alg_test_aead,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.aead = __VECS(krb5_test_aes256_cts_hmac_sha384_192)
|
||||
}
|
||||
@@ -4653,42 +4643,6 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
}, {
|
||||
.alg = "digest_null",
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "drbg_nopr_ctr_aes128",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_ctr_aes128_tv_template)
|
||||
}
|
||||
}, {
|
||||
.alg = "drbg_nopr_ctr_aes192",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_ctr_aes192_tv_template)
|
||||
}
|
||||
}, {
|
||||
.alg = "drbg_nopr_ctr_aes256",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_ctr_aes256_tv_template)
|
||||
}
|
||||
}, {
|
||||
.alg = "drbg_nopr_hmac_sha256",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_hmac_sha256_tv_template)
|
||||
}
|
||||
}, {
|
||||
/*
|
||||
* There is no need to specifically test the DRBG with every
|
||||
* backend cipher -- covered by drbg_nopr_hmac_sha512 test
|
||||
*/
|
||||
.alg = "drbg_nopr_hmac_sha384",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1
|
||||
}, {
|
||||
.alg = "drbg_nopr_hmac_sha512",
|
||||
.test = alg_test_drbg,
|
||||
@@ -4696,70 +4650,6 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_hmac_sha512_tv_template)
|
||||
}
|
||||
}, {
|
||||
.alg = "drbg_nopr_sha256",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_nopr_sha256_tv_template)
|
||||
}
|
||||
}, {
|
||||
/* covered by drbg_nopr_sha256 test */
|
||||
.alg = "drbg_nopr_sha384",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1
|
||||
}, {
|
||||
.alg = "drbg_nopr_sha512",
|
||||
.fips_allowed = 1,
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "drbg_pr_ctr_aes128",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_pr_ctr_aes128_tv_template)
|
||||
}
|
||||
}, {
|
||||
/* covered by drbg_pr_ctr_aes128 test */
|
||||
.alg = "drbg_pr_ctr_aes192",
|
||||
.fips_allowed = 1,
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "drbg_pr_ctr_aes256",
|
||||
.fips_allowed = 1,
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "drbg_pr_hmac_sha256",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_pr_hmac_sha256_tv_template)
|
||||
}
|
||||
}, {
|
||||
/* covered by drbg_pr_hmac_sha256 test */
|
||||
.alg = "drbg_pr_hmac_sha384",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1
|
||||
}, {
|
||||
.alg = "drbg_pr_hmac_sha512",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1,
|
||||
}, {
|
||||
.alg = "drbg_pr_sha256",
|
||||
.test = alg_test_drbg,
|
||||
.fips_allowed = 1,
|
||||
.suite = {
|
||||
.drbg = __VECS(drbg_pr_sha256_tv_template)
|
||||
}
|
||||
}, {
|
||||
/* covered by drbg_pr_sha256 test */
|
||||
.alg = "drbg_pr_sha384",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1
|
||||
}, {
|
||||
.alg = "drbg_pr_sha512",
|
||||
.fips_allowed = 1,
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "ecb(aes)",
|
||||
.generic_driver = "ecb(aes-lib)",
|
||||
@@ -5295,6 +5185,9 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
.suite = {
|
||||
.sig = __VECS(pkcs1_rsa_none_tv_template)
|
||||
}
|
||||
}, {
|
||||
.alg = "pkcs1(rsa,sha1)",
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "pkcs1(rsa,sha224)",
|
||||
.test = alg_test_null,
|
||||
@@ -5330,6 +5223,9 @@ static const struct alg_test_desc alg_test_descs[] = {
|
||||
.alg = "pkcs1pad(rsa)",
|
||||
.test = alg_test_null,
|
||||
.fips_allowed = 1,
|
||||
}, {
|
||||
.alg = "pkcs1pad(rsa,sha1)",
|
||||
.test = alg_test_null,
|
||||
}, {
|
||||
.alg = "rfc3686(ctr(aes))",
|
||||
.generic_driver = "rfc3686(ctr(aes-lib))",
|
||||
|
||||
+203
-877
File diff suppressed because it is too large
Load Diff
@@ -373,6 +373,16 @@ config HW_RANDOM_HISTB
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called histb-rng.
|
||||
|
||||
config HW_RANDOM_HISI_TRNG
|
||||
tristate "HiSilicon True Random Number Generator support"
|
||||
depends on ARM64 && ACPI
|
||||
help
|
||||
This driver provides kernel-side support for the True Random Number
|
||||
Generator hardware found on some HiSilicon SoCs.
|
||||
|
||||
To compile this driver as a module, choose M here: the module will be
|
||||
called hisi-trng-v2.
|
||||
|
||||
config HW_RANDOM_ST
|
||||
tristate "ST Microelectronics HW Random Number Generator support"
|
||||
depends on ARCH_STI || COMPILE_TEST
|
||||
@@ -615,6 +625,17 @@ config HW_RANDOM_ROCKCHIP
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config HW_RANDOM_XILINX
|
||||
tristate "Support for Xilinx True Random Generator"
|
||||
depends on ZYNQMP_FIRMWARE || COMPILE_TEST
|
||||
select CRYPTO_LIB_SHA512
|
||||
help
|
||||
Xilinx Versal SoC driver provides kernel-side support for True Random Number
|
||||
Generator and Pseudo random Number in CTR_DRBG mode as defined in NIST SP800-90A.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called xilinx-trng.
|
||||
|
||||
endif # HW_RANDOM
|
||||
|
||||
config UML_RANDOM
|
||||
|
||||
@@ -31,6 +31,7 @@ obj-$(CONFIG_HW_RANDOM_PSERIES) += pseries-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_POWERNV) += powernv-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_HISI) += hisi-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_HISTB) += histb-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_HISI_TRNG) += hisi-trng-v2.o
|
||||
obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_BCM74110) += bcm74110-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_IPROC_RNG200) += iproc-rng200.o
|
||||
@@ -52,3 +53,4 @@ obj-$(CONFIG_HW_RANDOM_CN10K) += cn10k-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_POLARFIRE_SOC) += mpfs-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_ROCKCHIP) += rockchip-rng.o
|
||||
obj-$(CONFIG_HW_RANDOM_JH7110) += jh7110-trng.o
|
||||
obj-$(CONFIG_HW_RANDOM_XILINX) += xilinx-trng.o
|
||||
|
||||
@@ -47,9 +47,9 @@
|
||||
* want to register another driver on the same PCI id.
|
||||
*/
|
||||
static const struct pci_device_id pci_tbl[] = {
|
||||
{ PCI_VDEVICE(AMD, 0x7443), 0, },
|
||||
{ PCI_VDEVICE(AMD, 0x746b), 0, },
|
||||
{ 0, }, /* terminate list */
|
||||
{ PCI_VDEVICE(AMD, 0x7443) },
|
||||
{ PCI_VDEVICE(AMD, 0x746b) },
|
||||
{ } /* terminate list */
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, pci_tbl);
|
||||
|
||||
|
||||
@@ -73,8 +73,8 @@ static void cavium_rng_remove(struct pci_dev *pdev)
|
||||
}
|
||||
|
||||
static const struct pci_device_id cavium_rng_pf_id_table[] = {
|
||||
{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa018), 0, 0, 0}, /* Thunder RNM */
|
||||
{0,},
|
||||
{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, 0xa018) }, /* Thunder RNM */
|
||||
{ },
|
||||
};
|
||||
|
||||
MODULE_DEVICE_TABLE(pci, cavium_rng_pf_id_table);
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
#include <linux/sched/signal.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/workqueue.h>
|
||||
|
||||
#define RNG_MODULE_NAME "hw_random"
|
||||
|
||||
#define RNG_BUFFER_SIZE (SMP_CACHE_BYTES < 32 ? 32 : SMP_CACHE_BYTES)
|
||||
#define RNG_BUFFER_SIZE MAX(32, SMP_CACHE_BYTES)
|
||||
|
||||
static struct hwrng __rcu *current_rng;
|
||||
/* the current rng has been explicitly chosen by user via sysfs */
|
||||
@@ -54,13 +55,9 @@ module_param(default_quality, ushort, 0644);
|
||||
MODULE_PARM_DESC(default_quality,
|
||||
"default maximum entropy content of hwrng per 1024 bits of input");
|
||||
|
||||
static void drop_current_rng(void);
|
||||
static int hwrng_init(struct hwrng *rng);
|
||||
static int hwrng_fillfn(void *unused);
|
||||
|
||||
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
|
||||
int wait);
|
||||
|
||||
static size_t rng_buffer_size(void)
|
||||
{
|
||||
return RNG_BUFFER_SIZE;
|
||||
@@ -214,8 +211,8 @@ static int rng_dev_open(struct inode *inode, struct file *filp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size,
|
||||
int wait) {
|
||||
static inline int rng_get_data(struct hwrng *rng, u8 *buffer, size_t size, bool wait)
|
||||
{
|
||||
int present;
|
||||
|
||||
BUG_ON(!mutex_is_locked(&reading_mutex));
|
||||
@@ -418,21 +415,17 @@ static ssize_t rng_available_show(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
int err;
|
||||
struct hwrng *rng;
|
||||
int len = 0;
|
||||
|
||||
err = mutex_lock_interruptible(&rng_mutex);
|
||||
if (err)
|
||||
if (mutex_lock_interruptible(&rng_mutex))
|
||||
return -ERESTARTSYS;
|
||||
buf[0] = '\0';
|
||||
list_for_each_entry(rng, &rng_list, list) {
|
||||
strlcat(buf, rng->name, PAGE_SIZE);
|
||||
strlcat(buf, " ", PAGE_SIZE);
|
||||
}
|
||||
strlcat(buf, "none\n", PAGE_SIZE);
|
||||
list_for_each_entry(rng, &rng_list, list)
|
||||
len += sysfs_emit_at(buf, len, "%s ", rng->name);
|
||||
len += sysfs_emit_at(buf, len, "none\n");
|
||||
mutex_unlock(&rng_mutex);
|
||||
|
||||
return strlen(buf);
|
||||
return len;
|
||||
}
|
||||
|
||||
static ssize_t rng_selected_show(struct device *dev,
|
||||
@@ -538,8 +531,7 @@ static int hwrng_fillfn(void *unused)
|
||||
}
|
||||
|
||||
mutex_lock(&reading_mutex);
|
||||
rc = rng_get_data(rng, rng_fillbuf,
|
||||
rng_buffer_size(), 1);
|
||||
rc = rng_get_data(rng, rng_fillbuf, rng_buffer_size(), true);
|
||||
if (current_quality != rng->quality)
|
||||
rng->quality = current_quality; /* obsolete */
|
||||
quality = rng->quality;
|
||||
|
||||
@@ -46,8 +46,8 @@
|
||||
* want to register another driver on the same PCI id.
|
||||
*/
|
||||
static const struct pci_device_id pci_tbl[] = {
|
||||
{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_LX_AES), 0, },
|
||||
{ 0, }, /* terminate list */
|
||||
{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_LX_AES) },
|
||||
{ } /* terminate list */
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, pci_tbl);
|
||||
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/* Copyright (c) 2019 HiSilicon Limited. */
|
||||
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/hw_random.h>
|
||||
#include <linux/io.h>
|
||||
#include <linux/iopoll.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/random.h>
|
||||
|
||||
#define HISI_TRNG_REG 0x00F0
|
||||
#define HISI_TRNG_BYTES 4
|
||||
#define HISI_TRNG_QUALITY 512
|
||||
#define SLEEP_US 10
|
||||
#define TIMEOUT_US 10000
|
||||
|
||||
struct hisi_trng {
|
||||
void __iomem *base;
|
||||
struct hwrng rng;
|
||||
};
|
||||
|
||||
static int hisi_trng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
|
||||
{
|
||||
struct hisi_trng *trng;
|
||||
int currsize = 0;
|
||||
u32 val = 0;
|
||||
int ret;
|
||||
|
||||
trng = container_of(rng, struct hisi_trng, rng);
|
||||
|
||||
do {
|
||||
ret = readl_poll_timeout(trng->base + HISI_TRNG_REG, val,
|
||||
val, SLEEP_US, TIMEOUT_US);
|
||||
if (ret)
|
||||
return currsize;
|
||||
|
||||
if (max - currsize >= HISI_TRNG_BYTES) {
|
||||
memcpy(buf + currsize, &val, HISI_TRNG_BYTES);
|
||||
currsize += HISI_TRNG_BYTES;
|
||||
if (currsize == max)
|
||||
return currsize;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* copy remaining bytes */
|
||||
memcpy(buf + currsize, &val, max - currsize);
|
||||
currsize = max;
|
||||
} while (currsize < max);
|
||||
|
||||
return currsize;
|
||||
}
|
||||
|
||||
static int hisi_trng_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct hisi_trng *trng;
|
||||
int ret;
|
||||
|
||||
trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL);
|
||||
if (!trng)
|
||||
return -ENOMEM;
|
||||
|
||||
trng->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(trng->base))
|
||||
return PTR_ERR(trng->base);
|
||||
|
||||
trng->rng.name = pdev->name;
|
||||
trng->rng.read = hisi_trng_read;
|
||||
trng->rng.quality = HISI_TRNG_QUALITY;
|
||||
|
||||
ret = devm_hwrng_register(&pdev->dev, &trng->rng);
|
||||
if (ret)
|
||||
dev_err(&pdev->dev, "failed to register hwrng: %d!\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct acpi_device_id hisi_trng_acpi_match[] = {
|
||||
{ "HISI02B3", 0 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(acpi, hisi_trng_acpi_match);
|
||||
|
||||
static struct platform_driver hisi_trng_driver = {
|
||||
.probe = hisi_trng_probe,
|
||||
.driver = {
|
||||
.name = "hisi-trng-v2",
|
||||
.acpi_match_table = ACPI_PTR(hisi_trng_acpi_match),
|
||||
},
|
||||
};
|
||||
|
||||
module_platform_driver(hisi_trng_driver);
|
||||
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_AUTHOR("Weili Qian <qianweili@huawei.com>");
|
||||
MODULE_AUTHOR("Zaibo Xu <xuzaibo@huawei.com>");
|
||||
MODULE_DESCRIPTION("HiSilicon true random number generator V2 driver");
|
||||
@@ -256,19 +256,22 @@ static int starfive_trng_read(struct hwrng *rng, void *buf, size_t max, bool wai
|
||||
|
||||
if (wait) {
|
||||
ret = starfive_trng_wait_idle(trng);
|
||||
if (ret)
|
||||
return -ETIMEDOUT;
|
||||
if (ret) {
|
||||
ret = -ETIMEDOUT;
|
||||
goto out_put;
|
||||
}
|
||||
}
|
||||
|
||||
ret = starfive_trng_cmd(trng, STARFIVE_CTRL_GENE_RANDNUM, wait);
|
||||
if (ret)
|
||||
return ret;
|
||||
goto out_put;
|
||||
|
||||
memcpy_fromio(buf, trng->base + STARFIVE_RAND0, max);
|
||||
ret = max;
|
||||
|
||||
out_put:
|
||||
pm_runtime_put_sync_autosuspend(trng->dev);
|
||||
|
||||
return max;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int starfive_trng_probe(struct platform_device *pdev)
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
* Driver for Mediatek Hardware Random Number Generator
|
||||
*
|
||||
* Copyright (C) 2017 Sean Wang <sean.wang@mediatek.com>
|
||||
* Copyright (C) 2026 Daniel Golle <daniel@makrotopia.org>
|
||||
*/
|
||||
#define MTK_RNG_DEV KBUILD_MODNAME
|
||||
|
||||
#include <linux/arm-smccc.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/err.h>
|
||||
@@ -17,6 +19,7 @@
|
||||
#include <linux/of.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/pm_runtime.h>
|
||||
#include <linux/soc/mediatek/mtk_sip_svc.h>
|
||||
|
||||
/* Runtime PM autosuspend timeout: */
|
||||
#define RNG_AUTOSUSPEND_TIMEOUT 100
|
||||
@@ -30,6 +33,11 @@
|
||||
|
||||
#define RNG_DATA 0x08
|
||||
|
||||
/* Driver feature flags */
|
||||
#define MTK_RNG_SMC BIT(0)
|
||||
|
||||
#define MTK_SIP_KERNEL_GET_RND MTK_SIP_SMC_CMD(0x550)
|
||||
|
||||
#define to_mtk_rng(p) container_of(p, struct mtk_rng, rng)
|
||||
|
||||
struct mtk_rng {
|
||||
@@ -37,6 +45,7 @@ struct mtk_rng {
|
||||
struct clk *clk;
|
||||
struct hwrng rng;
|
||||
struct device *dev;
|
||||
unsigned long flags;
|
||||
};
|
||||
|
||||
static int mtk_rng_init(struct hwrng *rng)
|
||||
@@ -103,6 +112,56 @@ static int mtk_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait)
|
||||
return retval || !wait ? retval : -EIO;
|
||||
}
|
||||
|
||||
static int mtk_rng_read_smc(struct hwrng *rng, void *buf, size_t max,
|
||||
bool wait)
|
||||
{
|
||||
struct arm_smccc_res res;
|
||||
int retval = 0;
|
||||
|
||||
while (max >= sizeof(u32)) {
|
||||
arm_smccc_smc(MTK_SIP_KERNEL_GET_RND, 0, 0, 0, 0, 0, 0, 0,
|
||||
&res);
|
||||
if (res.a0)
|
||||
break;
|
||||
|
||||
*(u32 *)buf = res.a1;
|
||||
retval += sizeof(u32);
|
||||
buf += sizeof(u32);
|
||||
max -= sizeof(u32);
|
||||
}
|
||||
|
||||
return retval || !wait ? retval : -EIO;
|
||||
}
|
||||
|
||||
static bool mtk_rng_hw_accessible(struct mtk_rng *priv)
|
||||
{
|
||||
u32 val;
|
||||
int err;
|
||||
|
||||
err = clk_prepare_enable(priv->clk);
|
||||
if (err)
|
||||
return false;
|
||||
|
||||
val = readl(priv->base + RNG_CTRL);
|
||||
val |= RNG_EN;
|
||||
writel(val, priv->base + RNG_CTRL);
|
||||
|
||||
val = readl(priv->base + RNG_CTRL);
|
||||
|
||||
if (val & RNG_EN) {
|
||||
/* HW is accessible, clean up: disable RNG and clock */
|
||||
writel(val & ~RNG_EN, priv->base + RNG_CTRL);
|
||||
clk_disable_unprepare(priv->clk);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* If TF-A blocks direct access, the register reads back as 0.
|
||||
* Leave the clock enabled as TF-A needs it.
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
static int mtk_rng_probe(struct platform_device *pdev)
|
||||
{
|
||||
int ret;
|
||||
@@ -114,23 +173,42 @@ static int mtk_rng_probe(struct platform_device *pdev)
|
||||
|
||||
priv->dev = &pdev->dev;
|
||||
priv->rng.name = pdev->name;
|
||||
#ifndef CONFIG_PM
|
||||
priv->rng.init = mtk_rng_init;
|
||||
priv->rng.cleanup = mtk_rng_cleanup;
|
||||
#endif
|
||||
priv->rng.read = mtk_rng_read;
|
||||
priv->rng.quality = 900;
|
||||
priv->flags = (unsigned long)device_get_match_data(&pdev->dev);
|
||||
|
||||
priv->clk = devm_clk_get(&pdev->dev, "rng");
|
||||
if (IS_ERR(priv->clk)) {
|
||||
ret = PTR_ERR(priv->clk);
|
||||
dev_err(&pdev->dev, "no clock for device: %d\n", ret);
|
||||
return ret;
|
||||
if (!(priv->flags & MTK_RNG_SMC)) {
|
||||
priv->clk = devm_clk_get(&pdev->dev, "rng");
|
||||
if (IS_ERR(priv->clk)) {
|
||||
ret = PTR_ERR(priv->clk);
|
||||
dev_err(&pdev->dev, "no clock for device: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
priv->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(priv->base))
|
||||
return PTR_ERR(priv->base);
|
||||
|
||||
if (IS_ENABLED(CONFIG_HAVE_ARM_SMCCC) &&
|
||||
of_device_is_compatible(pdev->dev.of_node,
|
||||
"mediatek,mt7986-rng") &&
|
||||
!mtk_rng_hw_accessible(priv)) {
|
||||
priv->flags |= MTK_RNG_SMC;
|
||||
dev_info(&pdev->dev,
|
||||
"HW RNG not MMIO accessible, using SMC\n");
|
||||
}
|
||||
}
|
||||
|
||||
priv->base = devm_platform_ioremap_resource(pdev, 0);
|
||||
if (IS_ERR(priv->base))
|
||||
return PTR_ERR(priv->base);
|
||||
if (priv->flags & MTK_RNG_SMC) {
|
||||
if (!IS_ENABLED(CONFIG_HAVE_ARM_SMCCC))
|
||||
return -ENODEV;
|
||||
priv->rng.read = mtk_rng_read_smc;
|
||||
} else {
|
||||
#ifndef CONFIG_PM
|
||||
priv->rng.init = mtk_rng_init;
|
||||
priv->rng.cleanup = mtk_rng_cleanup;
|
||||
#endif
|
||||
priv->rng.read = mtk_rng_read;
|
||||
}
|
||||
|
||||
ret = devm_hwrng_register(&pdev->dev, &priv->rng);
|
||||
if (ret) {
|
||||
@@ -139,12 +217,15 @@ static int mtk_rng_probe(struct platform_device *pdev)
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_set_drvdata(&pdev->dev, priv);
|
||||
pm_runtime_set_autosuspend_delay(&pdev->dev, RNG_AUTOSUSPEND_TIMEOUT);
|
||||
pm_runtime_use_autosuspend(&pdev->dev);
|
||||
ret = devm_pm_runtime_enable(&pdev->dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (!(priv->flags & MTK_RNG_SMC)) {
|
||||
dev_set_drvdata(&pdev->dev, priv);
|
||||
pm_runtime_set_autosuspend_delay(&pdev->dev,
|
||||
RNG_AUTOSUSPEND_TIMEOUT);
|
||||
pm_runtime_use_autosuspend(&pdev->dev);
|
||||
ret = devm_pm_runtime_enable(&pdev->dev);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
dev_info(&pdev->dev, "registered RNG driver\n");
|
||||
|
||||
@@ -181,8 +262,11 @@ static const struct dev_pm_ops mtk_rng_pm_ops = {
|
||||
#endif /* CONFIG_PM */
|
||||
|
||||
static const struct of_device_id mtk_rng_match[] = {
|
||||
{ .compatible = "mediatek,mt7986-rng" },
|
||||
{ .compatible = "mediatek,mt7623-rng" },
|
||||
{ .compatible = "mediatek,mt7981-rng", .data = (void *)MTK_RNG_SMC },
|
||||
{ .compatible = "mediatek,mt7986-rng" },
|
||||
{ .compatible = "mediatek,mt7987-rng", .data = (void *)MTK_RNG_SMC },
|
||||
{ .compatible = "mediatek,mt7988-rng", .data = (void *)MTK_RNG_SMC },
|
||||
{},
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, mtk_rng_match);
|
||||
@@ -200,4 +284,5 @@ module_platform_driver(mtk_rng_driver);
|
||||
|
||||
MODULE_DESCRIPTION("Mediatek Random Number Generator Driver");
|
||||
MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
|
||||
MODULE_AUTHOR("Daniel Golle <daniel@makrotopia.org>");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc.
|
||||
*/
|
||||
|
||||
#include <crypto/sha2.h>
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/firmware/xlnx-zynqmp.h>
|
||||
#include <linux/hw_random.h>
|
||||
@@ -14,14 +14,8 @@
|
||||
#include <linux/iopoll.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/mod_devicetable.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/df_sp80090a.h>
|
||||
#include <crypto/internal/drbg.h>
|
||||
#include <crypto/internal/cipher.h>
|
||||
#include <crypto/internal/rng.h>
|
||||
|
||||
/* TRNG Registers Offsets */
|
||||
#define TRNG_STATUS_OFFSET 0x4U
|
||||
@@ -47,7 +41,6 @@
|
||||
|
||||
/* Sizes in bytes */
|
||||
#define TRNG_SEED_LEN_BYTES 48U
|
||||
#define TRNG_ENTROPY_SEED_LEN_BYTES 64U
|
||||
#define TRNG_SEC_STRENGTH_SHIFT 5U
|
||||
#define TRNG_SEC_STRENGTH_BYTES BIT(TRNG_SEC_STRENGTH_SHIFT)
|
||||
#define TRNG_BYTES_PER_REG 4U
|
||||
@@ -59,18 +52,9 @@
|
||||
struct xilinx_rng {
|
||||
void __iomem *rng_base;
|
||||
struct device *dev;
|
||||
unsigned char *scratchpadbuf;
|
||||
struct aes_enckey *aeskey;
|
||||
struct mutex lock; /* Protect access to TRNG device */
|
||||
struct hwrng trng;
|
||||
};
|
||||
|
||||
struct xilinx_rng_ctx {
|
||||
struct xilinx_rng *rng;
|
||||
};
|
||||
|
||||
static struct xilinx_rng *xilinx_rng_dev;
|
||||
|
||||
static void xtrng_readwrite32(void __iomem *addr, u32 mask, u8 value)
|
||||
{
|
||||
u32 val;
|
||||
@@ -183,29 +167,30 @@ static void xtrng_enable_entropy(struct xilinx_rng *rng)
|
||||
|
||||
static int xtrng_reseed_internal(struct xilinx_rng *rng)
|
||||
{
|
||||
u8 entropy[TRNG_ENTROPY_SEED_LEN_BYTES];
|
||||
struct drbg_string data;
|
||||
LIST_HEAD(seedlist);
|
||||
static const u8 default_salt[SHA512_DIGEST_SIZE];
|
||||
u8 entropy[SHA512_DIGEST_SIZE] __aligned(4);
|
||||
u32 val;
|
||||
int ret;
|
||||
|
||||
drbg_string_fill(&data, entropy, TRNG_SEED_LEN_BYTES);
|
||||
list_add_tail(&data.list, &seedlist);
|
||||
memset(entropy, 0, sizeof(entropy));
|
||||
xtrng_enable_entropy(rng);
|
||||
|
||||
/* collect random data to use it as entropy (input for DF) */
|
||||
/* Collect some output from the TRNG. */
|
||||
static_assert(sizeof(entropy) >= TRNG_SEED_LEN_BYTES);
|
||||
ret = xtrng_collect_random_data(rng, entropy, TRNG_SEED_LEN_BYTES, true);
|
||||
if (ret != TRNG_SEED_LEN_BYTES)
|
||||
return -EINVAL;
|
||||
ret = crypto_drbg_ctr_df(rng->aeskey, rng->scratchpadbuf,
|
||||
TRNG_SEED_LEN_BYTES, &seedlist, AES_BLOCK_SIZE,
|
||||
TRNG_SEED_LEN_BYTES);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Extract entropy from the TRNG output using HKDF-SHA512-Extract. */
|
||||
hmac_sha512_usingrawkey(default_salt, sizeof(default_salt), entropy,
|
||||
TRNG_SEED_LEN_BYTES, entropy);
|
||||
|
||||
/* Write the extracted entropy to the hardware. */
|
||||
xtrng_write_multiple_registers(rng->rng_base + TRNG_EXT_SEED_OFFSET,
|
||||
(u32 *)rng->scratchpadbuf, TRNG_NUM_INIT_REGS);
|
||||
(u32 *)entropy, TRNG_NUM_INIT_REGS);
|
||||
|
||||
/* Clear the entropy from the stack. */
|
||||
memzero_explicit(entropy, sizeof(entropy));
|
||||
|
||||
/* select reseed operation */
|
||||
iowrite32(TRNG_CTRL_PRNGXS_MASK, rng->rng_base + TRNG_CTRL_OFFSET);
|
||||
|
||||
@@ -246,71 +231,25 @@ static int xtrng_random_bytes_generate(struct xilinx_rng *rng, u8 *rand_buf_ptr,
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
static int xtrng_trng_generate(struct crypto_rng *tfm, const u8 *src, u32 slen,
|
||||
u8 *dst, u32 dlen)
|
||||
{
|
||||
struct xilinx_rng_ctx *ctx = crypto_rng_ctx(tfm);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&ctx->rng->lock);
|
||||
ret = xtrng_random_bytes_generate(ctx->rng, dst, dlen, true);
|
||||
mutex_unlock(&ctx->rng->lock);
|
||||
|
||||
return ret < 0 ? ret : 0;
|
||||
}
|
||||
|
||||
static int xtrng_trng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xtrng_trng_init(struct crypto_tfm *rtfm)
|
||||
{
|
||||
struct xilinx_rng_ctx *ctx = crypto_tfm_ctx(rtfm);
|
||||
|
||||
ctx->rng = xilinx_rng_dev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct rng_alg xtrng_trng_alg = {
|
||||
.generate = xtrng_trng_generate,
|
||||
.seed = xtrng_trng_seed,
|
||||
.seedsize = 0,
|
||||
.base = {
|
||||
.cra_name = "stdrng",
|
||||
.cra_driver_name = "xilinx-trng",
|
||||
.cra_priority = 300,
|
||||
.cra_ctxsize = sizeof(struct xilinx_rng_ctx),
|
||||
.cra_module = THIS_MODULE,
|
||||
.cra_init = xtrng_trng_init,
|
||||
},
|
||||
};
|
||||
|
||||
static int xtrng_hwrng_trng_read(struct hwrng *hwrng, void *data, size_t max, bool wait)
|
||||
{
|
||||
u8 buf[TRNG_SEC_STRENGTH_BYTES];
|
||||
struct xilinx_rng *rng;
|
||||
int ret = -EINVAL, i = 0;
|
||||
int ret = 0, i = 0;
|
||||
|
||||
rng = container_of(hwrng, struct xilinx_rng, trng);
|
||||
/* Return in case wait not set and lock not available. */
|
||||
if (!mutex_trylock(&rng->lock) && !wait)
|
||||
return 0;
|
||||
else if (!mutex_is_locked(&rng->lock) && wait)
|
||||
mutex_lock(&rng->lock);
|
||||
|
||||
while (i < max) {
|
||||
ret = xtrng_random_bytes_generate(rng, buf, TRNG_SEC_STRENGTH_BYTES, wait);
|
||||
if (ret < 0)
|
||||
if (ret < 0) {
|
||||
if (i == 0)
|
||||
return ret;
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(data + i, buf, min_t(int, ret, (max - i)));
|
||||
i += min_t(int, ret, (max - i));
|
||||
}
|
||||
mutex_unlock(&rng->lock);
|
||||
|
||||
return ret;
|
||||
return i;
|
||||
}
|
||||
|
||||
static int xtrng_hwrng_register(struct hwrng *trng)
|
||||
@@ -335,7 +274,6 @@ static void xtrng_hwrng_unregister(struct hwrng *trng)
|
||||
static int xtrng_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct xilinx_rng *rng;
|
||||
size_t sb_size;
|
||||
int ret;
|
||||
|
||||
rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
|
||||
@@ -349,46 +287,21 @@ static int xtrng_probe(struct platform_device *pdev)
|
||||
return PTR_ERR(rng->rng_base);
|
||||
}
|
||||
|
||||
rng->aeskey = devm_kzalloc(&pdev->dev, sizeof(*rng->aeskey), GFP_KERNEL);
|
||||
if (!rng->aeskey)
|
||||
return -ENOMEM;
|
||||
|
||||
sb_size = crypto_drbg_ctr_df_datalen(TRNG_SEED_LEN_BYTES, AES_BLOCK_SIZE);
|
||||
rng->scratchpadbuf = devm_kzalloc(&pdev->dev, sb_size, GFP_KERNEL);
|
||||
if (!rng->scratchpadbuf) {
|
||||
ret = -ENOMEM;
|
||||
goto end;
|
||||
}
|
||||
|
||||
xtrng_trng_reset(rng->rng_base);
|
||||
ret = xtrng_reseed_internal(rng);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "TRNG Seed fail\n");
|
||||
goto end;
|
||||
}
|
||||
|
||||
xilinx_rng_dev = rng;
|
||||
mutex_init(&rng->lock);
|
||||
ret = crypto_register_rng(&xtrng_trng_alg);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "Crypto Random device registration failed: %d\n", ret);
|
||||
goto end;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = xtrng_hwrng_register(&rng->trng);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "HWRNG device registration failed: %d\n", ret);
|
||||
goto crypto_rng_free;
|
||||
return ret;
|
||||
}
|
||||
platform_set_drvdata(pdev, rng);
|
||||
|
||||
return 0;
|
||||
|
||||
crypto_rng_free:
|
||||
crypto_unregister_rng(&xtrng_trng_alg);
|
||||
|
||||
end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void xtrng_remove(struct platform_device *pdev)
|
||||
@@ -398,13 +311,11 @@ static void xtrng_remove(struct platform_device *pdev)
|
||||
|
||||
rng = platform_get_drvdata(pdev);
|
||||
xtrng_hwrng_unregister(&rng->trng);
|
||||
crypto_unregister_rng(&xtrng_trng_alg);
|
||||
xtrng_write_multiple_registers(rng->rng_base + TRNG_EXT_SEED_OFFSET, zero,
|
||||
TRNG_NUM_INIT_REGS);
|
||||
xtrng_write_multiple_registers(rng->rng_base + TRNG_PER_STRNG_OFFSET, zero,
|
||||
TRNG_NUM_INIT_REGS);
|
||||
xtrng_hold_reset(rng->rng_base);
|
||||
xilinx_rng_dev = NULL;
|
||||
}
|
||||
|
||||
static const struct of_device_id xtrng_of_match[] = {
|
||||
+2
-35
@@ -301,7 +301,6 @@ config CRYPTO_DEV_PPC4XX
|
||||
select CRYPTO_CCM
|
||||
select CRYPTO_CTR
|
||||
select CRYPTO_GCM
|
||||
select CRYPTO_RNG
|
||||
select CRYPTO_SKCIPHER
|
||||
help
|
||||
This option allows you to have support for AMCC crypto acceleration.
|
||||
@@ -316,7 +315,7 @@ config HW_RANDOM_PPC4XX
|
||||
|
||||
config CRYPTO_DEV_OMAP
|
||||
tristate "Support for OMAP crypto HW accelerators"
|
||||
depends on ARCH_OMAP2PLUS
|
||||
depends on ARCH_OMAP2PLUS || COMPILE_TEST
|
||||
help
|
||||
OMAP processors have various crypto HW accelerators. Select this if
|
||||
you want to use the OMAP modules for any of the crypto algorithms.
|
||||
@@ -352,7 +351,7 @@ config CRYPTO_DEV_OMAP_AES
|
||||
|
||||
config CRYPTO_DEV_OMAP_DES
|
||||
tristate "Support for OMAP DES/3DES hw engine"
|
||||
depends on ARCH_OMAP2PLUS
|
||||
depends on ARCH_OMAP2PLUS || COMPILE_TEST
|
||||
select CRYPTO_LIB_DES
|
||||
select CRYPTO_SKCIPHER
|
||||
select CRYPTO_ENGINE
|
||||
@@ -375,21 +374,6 @@ config CRYPTO_DEV_SAHARA
|
||||
This option enables support for the SAHARA HW crypto accelerator
|
||||
found in some Freescale i.MX chips.
|
||||
|
||||
config CRYPTO_DEV_EXYNOS_RNG
|
||||
tristate "Exynos HW pseudo random number generator support"
|
||||
depends on ARCH_EXYNOS || COMPILE_TEST
|
||||
depends on HAS_IOMEM
|
||||
select CRYPTO_RNG
|
||||
help
|
||||
This driver provides kernel-side support through the
|
||||
cryptographic API for the pseudo random number generator hardware
|
||||
found on Exynos SoCs.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called exynos-rng.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config CRYPTO_DEV_S5P
|
||||
tristate "Support for Samsung S5PV210/Exynos crypto accelerator"
|
||||
depends on ARCH_S5PV210 || ARCH_EXYNOS || COMPILE_TEST
|
||||
@@ -404,7 +388,6 @@ config CRYPTO_DEV_S5P
|
||||
config CRYPTO_DEV_EXYNOS_HASH
|
||||
bool "Support for Samsung Exynos HASH accelerator"
|
||||
depends on CRYPTO_DEV_S5P
|
||||
depends on !CRYPTO_DEV_EXYNOS_RNG && CRYPTO_DEV_EXYNOS_RNG!=m
|
||||
select CRYPTO_SHA1
|
||||
select CRYPTO_MD5
|
||||
select CRYPTO_SHA256
|
||||
@@ -412,8 +395,6 @@ config CRYPTO_DEV_EXYNOS_HASH
|
||||
Select this to offload Exynos from HASH MD5/SHA1/SHA256.
|
||||
This will select software SHA1, MD5 and SHA256 as they are
|
||||
needed for small and zero-size messages.
|
||||
HASH algorithms will be disabled if EXYNOS_RNG
|
||||
is enabled due to hw conflict.
|
||||
|
||||
config CRYPTO_DEV_NX
|
||||
bool "Support for IBM PowerPC Nest (NX) cryptographic acceleration"
|
||||
@@ -718,19 +699,6 @@ config CRYPTO_DEV_TEGRA
|
||||
Select this to enable Tegra Security Engine which accelerates various
|
||||
AES encryption/decryption and HASH algorithms.
|
||||
|
||||
config CRYPTO_DEV_XILINX_TRNG
|
||||
tristate "Support for Xilinx True Random Generator"
|
||||
depends on ZYNQMP_FIRMWARE || COMPILE_TEST
|
||||
select CRYPTO_DF80090A
|
||||
select CRYPTO_RNG
|
||||
select HW_RANDOM
|
||||
help
|
||||
Xilinx Versal SoC driver provides kernel-side support for True Random Number
|
||||
Generator and Pseudo random Number in CTR_DRBG mode as defined in NIST SP800-90A.
|
||||
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called xilinx-trng.
|
||||
|
||||
config CRYPTO_DEV_ZYNQMP_AES
|
||||
tristate "Support for Xilinx ZynqMP AES hw accelerator"
|
||||
depends on ZYNQMP_FIRMWARE || COMPILE_TEST
|
||||
@@ -846,7 +814,6 @@ config CRYPTO_DEV_CCREE
|
||||
If unsure say Y.
|
||||
|
||||
source "drivers/crypto/hisilicon/Kconfig"
|
||||
source "drivers/crypto/loongson/Kconfig"
|
||||
|
||||
source "drivers/crypto/amlogic/Kconfig"
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ obj-$(CONFIG_CRYPTO_DEV_ATMEL_SHA204A) += atmel-sha204a.o
|
||||
obj-$(CONFIG_CRYPTO_DEV_CCP) += ccp/
|
||||
obj-$(CONFIG_CRYPTO_DEV_CCREE) += ccree/
|
||||
obj-$(CONFIG_CRYPTO_DEV_CHELSIO) += chelsio/
|
||||
obj-$(CONFIG_CRYPTO_DEV_EXYNOS_RNG) += exynos-rng.o
|
||||
obj-$(CONFIG_CRYPTO_DEV_FSL_CAAM_COMMON) += caam/
|
||||
obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
|
||||
obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
|
||||
@@ -43,7 +42,6 @@ obj-y += inside-secure/
|
||||
obj-$(CONFIG_CRYPTO_DEV_ARTPEC6) += axis/
|
||||
obj-y += xilinx/
|
||||
obj-y += hisilicon/
|
||||
obj-y += loongson/
|
||||
obj-$(CONFIG_CRYPTO_DEV_AMLOGIC_GXL) += amlogic/
|
||||
obj-y += intel/
|
||||
obj-y += starfive/
|
||||
|
||||
@@ -14,7 +14,6 @@ config CRYPTO_DEV_SUN4I_SS
|
||||
select CRYPTO_SHA1
|
||||
select CRYPTO_AES
|
||||
select CRYPTO_LIB_DES
|
||||
select CRYPTO_RNG
|
||||
select CRYPTO_SKCIPHER
|
||||
help
|
||||
Some Allwinner SoC have a crypto accelerator named
|
||||
@@ -25,14 +24,6 @@ config CRYPTO_DEV_SUN4I_SS
|
||||
To compile this driver as a module, choose M here: the module
|
||||
will be called sun4i-ss.
|
||||
|
||||
config CRYPTO_DEV_SUN4I_SS_PRNG
|
||||
bool "Support for Allwinner Security System PRNG"
|
||||
depends on CRYPTO_DEV_SUN4I_SS
|
||||
select CRYPTO_RNG
|
||||
help
|
||||
Select this option if you want to provide kernel-side support for
|
||||
the Pseudo-Random Number Generator found in the Security System.
|
||||
|
||||
config CRYPTO_DEV_SUN4I_SS_DEBUG
|
||||
bool "Enable sun4i-ss stats"
|
||||
depends on CRYPTO_DEV_SUN4I_SS
|
||||
@@ -50,7 +41,6 @@ config CRYPTO_DEV_SUN8I_CE
|
||||
select CRYPTO_CBC
|
||||
select CRYPTO_AES
|
||||
select CRYPTO_DES
|
||||
select CRYPTO_RNG
|
||||
depends on CRYPTO_DEV_ALLWINNER
|
||||
depends on PM
|
||||
help
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sun4i-ss.o
|
||||
sun4i-ss-y += sun4i-ss-core.o sun4i-ss-hash.o sun4i-ss-cipher.o
|
||||
sun4i-ss-$(CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG) += sun4i-ss-prng.o
|
||||
|
||||
@@ -213,23 +213,6 @@ static struct sun4i_ss_alg_template ss_algs[] = {
|
||||
}
|
||||
}
|
||||
},
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
|
||||
{
|
||||
.type = CRYPTO_ALG_TYPE_RNG,
|
||||
.alg.rng = {
|
||||
.base = {
|
||||
.cra_name = "stdrng",
|
||||
.cra_driver_name = "sun4i_ss_rng",
|
||||
.cra_priority = 300,
|
||||
.cra_ctxsize = 0,
|
||||
.cra_module = THIS_MODULE,
|
||||
},
|
||||
.generate = sun4i_ss_prng_generate,
|
||||
.seed = sun4i_ss_prng_seed,
|
||||
.seedsize = SS_SEED_LEN / BITS_PER_BYTE,
|
||||
}
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
static int sun4i_ss_debugfs_show(struct seq_file *seq, void *v)
|
||||
@@ -247,12 +230,6 @@ static int sun4i_ss_debugfs_show(struct seq_file *seq, void *v)
|
||||
ss_algs[i].stat_req, ss_algs[i].stat_opti, ss_algs[i].stat_fb,
|
||||
ss_algs[i].stat_bytes);
|
||||
break;
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
seq_printf(seq, "%s %s reqs=%lu tsize=%lu\n",
|
||||
ss_algs[i].alg.rng.base.cra_driver_name,
|
||||
ss_algs[i].alg.rng.base.cra_name,
|
||||
ss_algs[i].stat_req, ss_algs[i].stat_bytes);
|
||||
break;
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
seq_printf(seq, "%s %s reqs=%lu\n",
|
||||
ss_algs[i].alg.hash.halg.base.cra_driver_name,
|
||||
@@ -471,13 +448,6 @@ static int sun4i_ss_probe(struct platform_device *pdev)
|
||||
goto error_alg;
|
||||
}
|
||||
break;
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
err = crypto_register_rng(&ss_algs[i].alg.rng);
|
||||
if (err) {
|
||||
dev_err(ss->dev, "Fail to register %s\n",
|
||||
ss_algs[i].alg.rng.base.cra_name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,9 +467,6 @@ error_alg:
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
crypto_unregister_ahash(&ss_algs[i].alg.hash);
|
||||
break;
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
crypto_unregister_rng(&ss_algs[i].alg.rng);
|
||||
break;
|
||||
}
|
||||
}
|
||||
error_pm:
|
||||
@@ -520,9 +487,6 @@ static void sun4i_ss_remove(struct platform_device *pdev)
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
crypto_unregister_ahash(&ss_algs[i].alg.hash);
|
||||
break;
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
crypto_unregister_rng(&ss_algs[i].alg.rng);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include "sun4i-ss.h"
|
||||
|
||||
int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
|
||||
unsigned int slen)
|
||||
{
|
||||
struct sun4i_ss_alg_template *algt;
|
||||
struct rng_alg *alg = crypto_rng_alg(tfm);
|
||||
|
||||
algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
|
||||
memcpy(algt->ss->seed, seed, slen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
|
||||
unsigned int slen, u8 *dst, unsigned int dlen)
|
||||
{
|
||||
struct sun4i_ss_alg_template *algt;
|
||||
struct rng_alg *alg = crypto_rng_alg(tfm);
|
||||
int i, err;
|
||||
u32 v;
|
||||
u32 *data = (u32 *)dst;
|
||||
const u32 mode = SS_OP_PRNG | SS_PRNG_CONTINUE | SS_ENABLED;
|
||||
size_t len;
|
||||
struct sun4i_ss_ctx *ss;
|
||||
unsigned int todo = (dlen / 4) * 4;
|
||||
|
||||
algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
|
||||
ss = algt->ss;
|
||||
|
||||
err = pm_runtime_resume_and_get(ss->dev);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN4I_SS_DEBUG)) {
|
||||
algt->stat_req++;
|
||||
algt->stat_bytes += todo;
|
||||
}
|
||||
|
||||
spin_lock_bh(&ss->slock);
|
||||
|
||||
writel(mode, ss->base + SS_CTL);
|
||||
|
||||
while (todo > 0) {
|
||||
/* write the seed */
|
||||
for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++)
|
||||
writel(ss->seed[i], ss->base + SS_KEY0 + i * 4);
|
||||
|
||||
/* Read the random data */
|
||||
len = min_t(size_t, SS_DATA_LEN / BITS_PER_BYTE, todo);
|
||||
readsl(ss->base + SS_TXFIFO, data, len / 4);
|
||||
data += len / 4;
|
||||
todo -= len;
|
||||
|
||||
/* Update the seed */
|
||||
for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++) {
|
||||
v = readl(ss->base + SS_KEY0 + i * 4);
|
||||
ss->seed[i] = v;
|
||||
}
|
||||
}
|
||||
|
||||
writel(0, ss->base + SS_CTL);
|
||||
spin_unlock_bh(&ss->slock);
|
||||
|
||||
pm_runtime_put(ss->dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -31,8 +31,6 @@
|
||||
#include <crypto/internal/skcipher.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/internal/des.h>
|
||||
#include <crypto/internal/rng.h>
|
||||
#include <crypto/rng.h>
|
||||
|
||||
#define SS_CTL 0x00
|
||||
#define SS_KEY0 0x04
|
||||
@@ -62,10 +60,6 @@
|
||||
|
||||
/* SS_CTL configuration values */
|
||||
|
||||
/* PRNG generator mode - bit 15 */
|
||||
#define SS_PRNG_ONESHOT (0 << 15)
|
||||
#define SS_PRNG_CONTINUE (1 << 15)
|
||||
|
||||
/* IV mode for hash */
|
||||
#define SS_IV_ARBITRARY (1 << 14)
|
||||
|
||||
@@ -94,14 +88,10 @@
|
||||
#define SS_OP_3DES (2 << 4)
|
||||
#define SS_OP_SHA1 (3 << 4)
|
||||
#define SS_OP_MD5 (4 << 4)
|
||||
#define SS_OP_PRNG (5 << 4)
|
||||
|
||||
/* Data end bit - bit 2 */
|
||||
#define SS_DATA_END (1 << 2)
|
||||
|
||||
/* PRNG start bit - bit 1 */
|
||||
#define SS_PRNG_START (1 << 1)
|
||||
|
||||
/* SS Enable bit - bit 0 */
|
||||
#define SS_DISABLED (0 << 0)
|
||||
#define SS_ENABLED (1 << 0)
|
||||
@@ -128,9 +118,6 @@
|
||||
#define SS_RXFIFO_EMP_INT_ENABLE (1 << 2)
|
||||
#define SS_TXFIFO_AVA_INT_ENABLE (1 << 0)
|
||||
|
||||
#define SS_SEED_LEN 192
|
||||
#define SS_DATA_LEN 160
|
||||
|
||||
/*
|
||||
* struct ss_variant - Describe SS hardware variant
|
||||
* @sha1_in_be: The SHA1 digest is given by SS in BE, and so need to be inverted.
|
||||
@@ -151,9 +138,6 @@ struct sun4i_ss_ctx {
|
||||
char buf[4 * SS_RX_MAX];/* buffer for linearize SG src */
|
||||
char bufo[4 * SS_TX_MAX]; /* buffer for linearize SG dst */
|
||||
spinlock_t slock; /* control the use of the device */
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN4I_SS_PRNG
|
||||
u32 seed[SS_SEED_LEN / BITS_PER_LONG];
|
||||
#endif
|
||||
struct dentry *dbgfs_dir;
|
||||
struct dentry *dbgfs_stats;
|
||||
};
|
||||
@@ -164,7 +148,6 @@ struct sun4i_ss_alg_template {
|
||||
union {
|
||||
struct skcipher_alg crypto;
|
||||
struct ahash_alg hash;
|
||||
struct rng_alg rng;
|
||||
} alg;
|
||||
struct sun4i_ss_ctx *ss;
|
||||
unsigned long stat_req;
|
||||
@@ -231,6 +214,3 @@ int sun4i_ss_des_setkey(struct crypto_skcipher *tfm, const u8 *key,
|
||||
unsigned int keylen);
|
||||
int sun4i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
|
||||
unsigned int keylen);
|
||||
int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
|
||||
unsigned int slen, u8 *dst, unsigned int dlen);
|
||||
int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
|
||||
|
||||
@@ -676,6 +676,7 @@ static int sun8i_ce_debugfs_show(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, "\tFallback due to SG numbers: %lu\n",
|
||||
ce_algs[i].stat_fb_maxsg);
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
seq_printf(seq, "%s %s reqs=%lu fallback=%lu\n",
|
||||
ce_algs[i].alg.hash.base.halg.base.cra_driver_name,
|
||||
@@ -692,12 +693,15 @@ static int sun8i_ce_debugfs_show(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, "\tFallback due to SG numbers: %lu\n",
|
||||
ce_algs[i].stat_fb_maxsg);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
seq_printf(seq, "%s %s reqs=%lu bytes=%lu\n",
|
||||
ce_algs[i].alg.rng.base.cra_driver_name,
|
||||
ce_algs[i].alg.rng.base.cra_name,
|
||||
ce_algs[i].stat_req, ce_algs[i].stat_bytes);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if defined(CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG) && \
|
||||
@@ -905,6 +909,7 @@ static int sun8i_ce_register_algs(struct sun8i_ce_dev *ce)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
id = ce_algs[i].ce_algo_id;
|
||||
ce_method = ce->variant->alg_hash[id];
|
||||
@@ -925,6 +930,8 @@ static int sun8i_ce_register_algs(struct sun8i_ce_dev *ce)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
if (ce->variant->prng == CE_ID_NOTSUPP) {
|
||||
dev_info(ce->dev,
|
||||
@@ -942,6 +949,7 @@ static int sun8i_ce_register_algs(struct sun8i_ce_dev *ce)
|
||||
ce_algs[i].ce = NULL;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ce_algs[i].ce = NULL;
|
||||
dev_err(ce->dev, "ERROR: tried to register an unknown algo\n");
|
||||
@@ -963,16 +971,20 @@ static void sun8i_ce_unregister_algs(struct sun8i_ce_dev *ce)
|
||||
ce_algs[i].alg.skcipher.base.base.cra_name);
|
||||
crypto_engine_unregister_skcipher(&ce_algs[i].alg.skcipher);
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
dev_info(ce->dev, "Unregister %d %s\n", i,
|
||||
ce_algs[i].alg.hash.base.halg.base.cra_name);
|
||||
crypto_engine_unregister_ahash(&ce_algs[i].alg.hash);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
dev_info(ce->dev, "Unregister %d %s\n", i,
|
||||
ce_algs[i].alg.rng.base.cra_name);
|
||||
crypto_unregister_rng(&ce_algs[i].alg.rng);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,12 +501,15 @@ static int sun8i_ss_debugfs_show(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, "\tFallback due to SG numbers: %lu\n",
|
||||
ss_algs[i].stat_fb_sgnum);
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
seq_printf(seq, "%s %s reqs=%lu tsize=%lu\n",
|
||||
ss_algs[i].alg.rng.base.cra_driver_name,
|
||||
ss_algs[i].alg.rng.base.cra_name,
|
||||
ss_algs[i].stat_req, ss_algs[i].stat_bytes);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
seq_printf(seq, "%s %s reqs=%lu fallback=%lu\n",
|
||||
ss_algs[i].alg.hash.base.halg.base.cra_driver_name,
|
||||
@@ -523,6 +526,7 @@ static int sun8i_ss_debugfs_show(struct seq_file *seq, void *v)
|
||||
seq_printf(seq, "\tFallback due to SG numbers: %lu\n",
|
||||
ss_algs[i].stat_fb_sgnum);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -707,6 +711,7 @@ static int sun8i_ss_register_algs(struct sun8i_ss_dev *ss)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
err = crypto_register_rng(&ss_algs[i].alg.rng);
|
||||
if (err) {
|
||||
@@ -715,6 +720,8 @@ static int sun8i_ss_register_algs(struct sun8i_ss_dev *ss)
|
||||
ss_algs[i].ss = NULL;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
id = ss_algs[i].ss_algo_id;
|
||||
ss_method = ss->variant->alg_hash[id];
|
||||
@@ -735,6 +742,7 @@ static int sun8i_ss_register_algs(struct sun8i_ss_dev *ss)
|
||||
return err;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ss_algs[i].ss = NULL;
|
||||
dev_err(ss->dev, "ERROR: tried to register an unknown algo\n");
|
||||
@@ -756,16 +764,20 @@ static void sun8i_ss_unregister_algs(struct sun8i_ss_dev *ss)
|
||||
ss_algs[i].alg.skcipher.base.base.cra_name);
|
||||
crypto_engine_unregister_skcipher(&ss_algs[i].alg.skcipher);
|
||||
break;
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_PRNG
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
dev_info(ss->dev, "Unregister %d %s\n", i,
|
||||
ss_algs[i].alg.rng.base.cra_name);
|
||||
crypto_unregister_rng(&ss_algs[i].alg.rng);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_HASH
|
||||
case CRYPTO_ALG_TYPE_AHASH:
|
||||
dev_info(ss->dev, "Unregister %d %s\n", i,
|
||||
ss_algs[i].alg.hash.base.halg.base.cra_name);
|
||||
crypto_engine_unregister_ahash(&ss_algs[i].alg.hash);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,9 @@
|
||||
#include <crypto/ctr.h>
|
||||
#include <crypto/gcm.h>
|
||||
#include <crypto/sha1.h>
|
||||
#include <crypto/rng.h>
|
||||
#include <crypto/scatterwalk.h>
|
||||
#include <crypto/skcipher.h>
|
||||
#include <crypto/internal/aead.h>
|
||||
#include <crypto/internal/rng.h>
|
||||
#include <crypto/internal/skcipher.h>
|
||||
#include "crypto4xx_reg_def.h"
|
||||
#include "crypto4xx_core.h"
|
||||
@@ -985,10 +983,6 @@ static int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
|
||||
rc = crypto_register_aead(&alg->alg.u.aead);
|
||||
break;
|
||||
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
rc = crypto_register_rng(&alg->alg.u.rng);
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = crypto_register_skcipher(&alg->alg.u.cipher);
|
||||
break;
|
||||
@@ -1014,10 +1008,6 @@ static void crypto4xx_unregister_alg(struct crypto4xx_device *sec_dev)
|
||||
crypto_unregister_aead(&alg->alg.u.aead);
|
||||
break;
|
||||
|
||||
case CRYPTO_ALG_TYPE_RNG:
|
||||
crypto_unregister_rng(&alg->alg.u.rng);
|
||||
break;
|
||||
|
||||
default:
|
||||
crypto_unregister_skcipher(&alg->alg.u.cipher);
|
||||
}
|
||||
@@ -1076,69 +1066,6 @@ static irqreturn_t crypto4xx_ce_interrupt_handler_revb(int irq, void *data)
|
||||
PPC4XX_TMO_ERR_INT);
|
||||
}
|
||||
|
||||
static int ppc4xx_prng_data_read(struct crypto4xx_device *dev,
|
||||
u8 *data, unsigned int max)
|
||||
{
|
||||
unsigned int i, curr = 0;
|
||||
u32 val[2];
|
||||
|
||||
do {
|
||||
/* trigger PRN generation */
|
||||
writel(PPC4XX_PRNG_CTRL_AUTO_EN,
|
||||
dev->ce_base + CRYPTO4XX_PRNG_CTRL);
|
||||
|
||||
for (i = 0; i < 1024; i++) {
|
||||
/* usually 19 iterations are enough */
|
||||
if ((readl(dev->ce_base + CRYPTO4XX_PRNG_STAT) &
|
||||
CRYPTO4XX_PRNG_STAT_BUSY))
|
||||
continue;
|
||||
|
||||
val[0] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_0);
|
||||
val[1] = readl_be(dev->ce_base + CRYPTO4XX_PRNG_RES_1);
|
||||
break;
|
||||
}
|
||||
if (i == 1024)
|
||||
return -ETIMEDOUT;
|
||||
|
||||
if ((max - curr) >= 8) {
|
||||
memcpy(data, &val, 8);
|
||||
data += 8;
|
||||
curr += 8;
|
||||
} else {
|
||||
/* copy only remaining bytes */
|
||||
memcpy(data, &val, max - curr);
|
||||
break;
|
||||
}
|
||||
} while (curr < max);
|
||||
|
||||
return curr;
|
||||
}
|
||||
|
||||
static int crypto4xx_prng_generate(struct crypto_rng *tfm,
|
||||
const u8 *src, unsigned int slen,
|
||||
u8 *dstn, unsigned int dlen)
|
||||
{
|
||||
struct rng_alg *alg = crypto_rng_alg(tfm);
|
||||
struct crypto4xx_alg *amcc_alg;
|
||||
struct crypto4xx_device *dev;
|
||||
int ret;
|
||||
|
||||
amcc_alg = container_of(alg, struct crypto4xx_alg, alg.u.rng);
|
||||
dev = amcc_alg->dev;
|
||||
|
||||
mutex_lock(&dev->core_dev->rng_lock);
|
||||
ret = ppc4xx_prng_data_read(dev, dstn, dlen);
|
||||
mutex_unlock(&dev->core_dev->rng_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int crypto4xx_prng_seed(struct crypto_rng *tfm, const u8 *seed,
|
||||
unsigned int slen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Supported Crypto Algorithms
|
||||
*/
|
||||
@@ -1268,18 +1195,6 @@ static struct crypto4xx_alg_common crypto4xx_alg[] = {
|
||||
.cra_module = THIS_MODULE,
|
||||
},
|
||||
} },
|
||||
{ .type = CRYPTO_ALG_TYPE_RNG, .u.rng = {
|
||||
.base = {
|
||||
.cra_name = "stdrng",
|
||||
.cra_driver_name = "crypto4xx_rng",
|
||||
.cra_priority = 300,
|
||||
.cra_ctxsize = 0,
|
||||
.cra_module = THIS_MODULE,
|
||||
},
|
||||
.generate = crypto4xx_prng_generate,
|
||||
.seed = crypto4xx_prng_seed,
|
||||
.seedsize = 0,
|
||||
} },
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -1353,9 +1268,6 @@ static int crypto4xx_probe(struct platform_device *ofdev)
|
||||
core_dev->dev->core_dev = core_dev;
|
||||
core_dev->dev->is_revb = is_revb;
|
||||
core_dev->device = dev;
|
||||
rc = devm_mutex_init(&ofdev->dev, &core_dev->rng_lock);
|
||||
if (rc)
|
||||
return rc;
|
||||
spin_lock_init(&core_dev->lock);
|
||||
INIT_LIST_HEAD(&core_dev->dev->alg_list);
|
||||
ratelimit_default_init(&core_dev->dev->aead_ratelimit);
|
||||
@@ -1382,7 +1294,11 @@ static int crypto4xx_probe(struct platform_device *ofdev)
|
||||
}
|
||||
|
||||
/* Register for Crypto isr, Crypto Engine IRQ */
|
||||
core_dev->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
|
||||
core_dev->irq = platform_get_irq(ofdev, 0);
|
||||
if (core_dev->irq < 0) {
|
||||
rc = core_dev->irq;
|
||||
goto err_iomap;
|
||||
}
|
||||
rc = devm_request_irq(&ofdev->dev, core_dev->irq,
|
||||
is_revb ? crypto4xx_ce_interrupt_handler_revb :
|
||||
crypto4xx_ce_interrupt_handler,
|
||||
|
||||
@@ -14,10 +14,8 @@
|
||||
#define __CRYPTO4XX_CORE_H__
|
||||
|
||||
#include <linux/ratelimit.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/scatterlist.h>
|
||||
#include <crypto/internal/aead.h>
|
||||
#include <crypto/internal/rng.h>
|
||||
#include <crypto/internal/skcipher.h>
|
||||
#include "crypto4xx_reg_def.h"
|
||||
#include "crypto4xx_sa.h"
|
||||
@@ -108,10 +106,9 @@ struct crypto4xx_core_device {
|
||||
struct crypto4xx_device *dev;
|
||||
struct hwrng *trng;
|
||||
u32 int_status;
|
||||
u32 irq;
|
||||
int irq;
|
||||
struct tasklet_struct tasklet;
|
||||
spinlock_t lock;
|
||||
struct mutex rng_lock;
|
||||
};
|
||||
|
||||
struct crypto4xx_ctx {
|
||||
@@ -135,7 +132,6 @@ struct crypto4xx_alg_common {
|
||||
union {
|
||||
struct skcipher_alg cipher;
|
||||
struct aead_alg aead;
|
||||
struct rng_alg rng;
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
@@ -90,20 +90,9 @@
|
||||
#define CRYPTO4XX_BYTE_ORDER_CFG 0x000600d8
|
||||
#define CRYPTO4XX_ENDIAN_CFG 0x000600d8
|
||||
|
||||
#define CRYPTO4XX_PRNG_STAT 0x00070000
|
||||
#define CRYPTO4XX_PRNG_STAT_BUSY 0x1
|
||||
#define CRYPTO4XX_PRNG_CTRL 0x00070004
|
||||
#define CRYPTO4XX_PRNG_SEED_L 0x00070008
|
||||
#define CRYPTO4XX_PRNG_SEED_H 0x0007000c
|
||||
|
||||
#define CRYPTO4XX_PRNG_RES_0 0x00070020
|
||||
#define CRYPTO4XX_PRNG_RES_1 0x00070024
|
||||
#define CRYPTO4XX_PRNG_RES_2 0x00070028
|
||||
#define CRYPTO4XX_PRNG_RES_3 0x0007002C
|
||||
|
||||
#define CRYPTO4XX_PRNG_LFSR_L 0x00070030
|
||||
#define CRYPTO4XX_PRNG_LFSR_H 0x00070034
|
||||
|
||||
/*
|
||||
* Initialize CRYPTO ENGINE registers, and memory bases.
|
||||
*/
|
||||
|
||||
@@ -291,8 +291,8 @@ static int meson_crypto_probe(struct platform_device *pdev)
|
||||
return 0;
|
||||
error_alg:
|
||||
meson_unregister_algs(mc);
|
||||
error_flow:
|
||||
meson_free_chanlist(mc, MAXFLOW - 1);
|
||||
error_flow:
|
||||
clk_disable_unprepare(mc->busclk);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ static void atmel_ecdh_done(struct atmel_i2c_work_data *work_data, void *areq,
|
||||
goto free_work_data;
|
||||
|
||||
/* might want less than we've got */
|
||||
n_sz = min_t(size_t, ATMEL_ECC_NIST_P256_N_SIZE, req->dst_len);
|
||||
n_sz = min(ATMEL_ECC_NIST_P256_N_SIZE, req->dst_len);
|
||||
|
||||
/* copy the shared secret */
|
||||
copied = sg_copy_from_buffer(req->dst, sg_nents_for_len(req->dst, n_sz),
|
||||
@@ -150,7 +150,7 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)
|
||||
return -EINVAL;
|
||||
|
||||
/* might want less than we've got */
|
||||
nbytes = min_t(size_t, ATMEL_ECC_PUBKEY_SIZE, req->dst_len);
|
||||
nbytes = min(ATMEL_ECC_PUBKEY_SIZE, req->dst_len);
|
||||
|
||||
/* public key was saved at private key generation */
|
||||
copied = sg_copy_from_buffer(req->dst,
|
||||
@@ -284,15 +284,7 @@ static unsigned int atmel_ecdh_max_size(struct crypto_kpp *tfm)
|
||||
{
|
||||
struct atmel_ecdh_ctx *ctx = kpp_tfm_ctx(tfm);
|
||||
|
||||
if (ctx->fallback)
|
||||
return crypto_kpp_maxsize(ctx->fallback);
|
||||
|
||||
/*
|
||||
* The device only supports NIST P256 ECC keys. The public key size will
|
||||
* always be the same. Use a macro for the key size to avoid unnecessary
|
||||
* computations.
|
||||
*/
|
||||
return ATMEL_ECC_PUBKEY_SIZE;
|
||||
return crypto_kpp_maxsize(ctx->fallback);
|
||||
}
|
||||
|
||||
static struct kpp_alg atmel_ecdh_nist_p256 = {
|
||||
@@ -368,19 +360,16 @@ static void atmel_ecc_remove(struct i2c_client *client)
|
||||
spin_unlock(&driver_data.i2c_list_lock);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static const struct of_device_id atmel_ecc_dt_ids[] = {
|
||||
{
|
||||
.compatible = "atmel,atecc508a",
|
||||
}, {
|
||||
/* sentinel */
|
||||
}
|
||||
{ .compatible = "atmel,atecc508a", },
|
||||
{ .compatible = "atmel,atecc608b", },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, atmel_ecc_dt_ids);
|
||||
#endif
|
||||
|
||||
static const struct i2c_device_id atmel_ecc_id[] = {
|
||||
{ "atecc508a" },
|
||||
{ .name = "atecc508a" },
|
||||
{ .name = "atecc608b" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, atmel_ecc_id);
|
||||
@@ -388,7 +377,7 @@ MODULE_DEVICE_TABLE(i2c, atmel_ecc_id);
|
||||
static struct i2c_driver atmel_ecc_driver = {
|
||||
.driver = {
|
||||
.name = "atmel-ecc",
|
||||
.of_match_table = of_match_ptr(atmel_ecc_dt_ids),
|
||||
.of_match_table = atmel_ecc_dt_ids,
|
||||
},
|
||||
.probe = atmel_ecc_probe,
|
||||
.remove = atmel_ecc_remove,
|
||||
|
||||
@@ -294,7 +294,7 @@ void atmel_i2c_enqueue(struct atmel_i2c_work_data *work_data,
|
||||
void *areq, int status),
|
||||
void *areq)
|
||||
{
|
||||
work_data->cbk = (void *)cbk;
|
||||
work_data->cbk = cbk;
|
||||
work_data->areq = areq;
|
||||
|
||||
INIT_WORK(&work_data->work, atmel_i2c_work_handler);
|
||||
|
||||
@@ -305,12 +305,12 @@ static size_t atmel_sha_append_sg(struct atmel_sha_reqctx *ctx)
|
||||
size_t count;
|
||||
|
||||
while ((ctx->bufcnt < ctx->buflen) && ctx->total) {
|
||||
count = min(ctx->sg->length - ctx->offset, ctx->total);
|
||||
count = min(count, ctx->buflen - ctx->bufcnt);
|
||||
count = min3(ctx->sg->length - ctx->offset, ctx->total,
|
||||
ctx->buflen - ctx->bufcnt);
|
||||
|
||||
if (count <= 0) {
|
||||
if (count == 0) {
|
||||
/*
|
||||
* Check if count <= 0 because the buffer is full or
|
||||
* Check if count == 0 because the buffer is full or
|
||||
* because the sg length is 0. In the latest case,
|
||||
* check if there is another sg in the list, a 0 length
|
||||
* sg doesn't necessarily mean the end of the sg list.
|
||||
@@ -1724,8 +1724,7 @@ static int atmel_sha_hmac_setup(struct atmel_sha_dev *dd,
|
||||
return atmel_sha_hmac_prehash_key(dd, key, keylen);
|
||||
|
||||
/* Prepare ipad. */
|
||||
memcpy((u8 *)hmac->ipad, key, keylen);
|
||||
memset((u8 *)hmac->ipad + keylen, 0, bs - keylen);
|
||||
memcpy_and_pad(hmac->ipad, bs, key, keylen, 0);
|
||||
return atmel_sha_hmac_compute_ipad_hash(dd);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
#include <linux/workqueue.h>
|
||||
#include "atmel-i2c.h"
|
||||
|
||||
/*
|
||||
* According to review by Bill Cox [1], the ATSHA204 has very low entropy.
|
||||
* [1] https://www.metzdowd.com/pipermail/cryptography/2014-December/023858.html
|
||||
*/
|
||||
static const unsigned short atsha204_quality = 1;
|
||||
|
||||
static void atmel_sha204a_rng_done(struct atmel_i2c_work_data *work_data,
|
||||
void *areq, int status)
|
||||
{
|
||||
@@ -48,8 +54,8 @@ static int atmel_sha204a_rng_read_nonblocking(struct hwrng *rng, void *data,
|
||||
|
||||
if (rng->priv) {
|
||||
work_data = (struct atmel_i2c_work_data *)rng->priv;
|
||||
max = min(sizeof(work_data->cmd.data), max);
|
||||
memcpy(data, &work_data->cmd.data, max);
|
||||
max = min(RANDOM_RSP_SIZE - CMD_OVERHEAD_SIZE, max);
|
||||
memcpy(data, &work_data->cmd.data[RSP_DATA_IDX], max);
|
||||
rng->priv = 0;
|
||||
} else {
|
||||
work_data = kmalloc_obj(*work_data, GFP_ATOMIC);
|
||||
@@ -87,8 +93,8 @@ static int atmel_sha204a_rng_read(struct hwrng *rng, void *data, size_t max,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
max = min(sizeof(cmd.data), max);
|
||||
memcpy(data, cmd.data, max);
|
||||
max = min(RANDOM_RSP_SIZE - CMD_OVERHEAD_SIZE, max);
|
||||
memcpy(data, &cmd.data[RSP_DATA_IDX], max);
|
||||
|
||||
return max;
|
||||
}
|
||||
@@ -158,6 +164,7 @@ static const struct attribute_group atmel_sha204a_groups = {
|
||||
static int atmel_sha204a_probe(struct i2c_client *client)
|
||||
{
|
||||
struct atmel_i2c_client_priv *i2c_priv;
|
||||
const unsigned short *quality;
|
||||
int ret;
|
||||
|
||||
ret = atmel_i2c_probe(client);
|
||||
@@ -171,19 +178,19 @@ static int atmel_sha204a_probe(struct i2c_client *client)
|
||||
i2c_priv->hwrng.name = dev_name(&client->dev);
|
||||
i2c_priv->hwrng.read = atmel_sha204a_rng_read;
|
||||
|
||||
/*
|
||||
* According to review by Bill Cox [1], this HWRNG has very low entropy.
|
||||
* [1] https://www.metzdowd.com/pipermail/cryptography/2014-December/023858.html
|
||||
*/
|
||||
i2c_priv->hwrng.quality = 1;
|
||||
quality = i2c_get_match_data(client);
|
||||
if (quality)
|
||||
i2c_priv->hwrng.quality = *quality;
|
||||
|
||||
ret = devm_hwrng_register(&client->dev, &i2c_priv->hwrng);
|
||||
if (ret)
|
||||
dev_warn(&client->dev, "failed to register RNG (%d)\n", ret);
|
||||
if (ret) {
|
||||
dev_err(&client->dev, "failed to register RNG (%d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = sysfs_create_group(&client->dev.kobj, &atmel_sha204a_groups);
|
||||
if (ret) {
|
||||
dev_err(&client->dev, "failed to register sysfs entry\n");
|
||||
dev_err(&client->dev, "failed to create sysfs group (%d)\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -194,25 +201,24 @@ static void atmel_sha204a_remove(struct i2c_client *client)
|
||||
{
|
||||
struct atmel_i2c_client_priv *i2c_priv = i2c_get_clientdata(client);
|
||||
|
||||
sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);
|
||||
devm_hwrng_unregister(&client->dev, &i2c_priv->hwrng);
|
||||
atmel_i2c_flush_queue();
|
||||
|
||||
sysfs_remove_group(&client->dev.kobj, &atmel_sha204a_groups);
|
||||
|
||||
kfree((void *)i2c_priv->hwrng.priv);
|
||||
}
|
||||
|
||||
static const struct of_device_id atmel_sha204a_dt_ids[] __maybe_unused = {
|
||||
{ .compatible = "atmel,atsha204", },
|
||||
{ .compatible = "atmel,atsha204a", },
|
||||
{ /* sentinel */ }
|
||||
static const struct of_device_id atmel_sha204a_dt_ids[] = {
|
||||
{ .compatible = "atmel,atsha204" },
|
||||
{ .compatible = "atmel,atsha204a" },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, atmel_sha204a_dt_ids);
|
||||
|
||||
static const struct i2c_device_id atmel_sha204a_id[] = {
|
||||
{ "atsha204" },
|
||||
{ "atsha204a" },
|
||||
{ /* sentinel */ }
|
||||
{ .name = "atsha204", .driver_data = (kernel_ulong_t)&atsha204_quality },
|
||||
{ .name = "atsha204a", .driver_data = (kernel_ulong_t)NULL },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, atmel_sha204a_id);
|
||||
|
||||
@@ -222,7 +228,7 @@ static struct i2c_driver atmel_sha204a_driver = {
|
||||
.id_table = atmel_sha204a_id,
|
||||
|
||||
.driver.name = "atmel-sha204a",
|
||||
.driver.of_match_table = of_match_ptr(atmel_sha204a_dt_ids),
|
||||
.driver.of_match_table = atmel_sha204a_dt_ids,
|
||||
};
|
||||
|
||||
static int __init atmel_sha204a_init(void)
|
||||
|
||||
@@ -706,22 +706,19 @@ artpec6_crypto_setup_out_descr(struct artpec6_crypto_req_common *common,
|
||||
void *dst, unsigned int len, bool eop,
|
||||
bool use_short)
|
||||
{
|
||||
if (use_short && len < 7) {
|
||||
dma_addr_t dma_addr;
|
||||
int ret;
|
||||
|
||||
if (use_short && len < 7)
|
||||
return artpec6_crypto_setup_out_descr_short(common, dst, len,
|
||||
eop);
|
||||
} else {
|
||||
int ret;
|
||||
dma_addr_t dma_addr;
|
||||
|
||||
ret = artpec6_crypto_dma_map_single(common, dst, len,
|
||||
DMA_TO_DEVICE,
|
||||
&dma_addr);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = artpec6_crypto_dma_map_single(common, dst, len, DMA_TO_DEVICE,
|
||||
&dma_addr);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return artpec6_crypto_setup_out_descr_phys(common, dma_addr,
|
||||
len, eop);
|
||||
}
|
||||
return artpec6_crypto_setup_out_descr_phys(common, dma_addr, len, eop);
|
||||
}
|
||||
|
||||
/** artpec6_crypto_setup_in_descr_phys - Setup an in channel with a
|
||||
|
||||
@@ -4698,9 +4698,9 @@ static void bcm_spu_remove(struct platform_device *pdev)
|
||||
|
||||
static struct platform_driver bcm_spu_pdriver = {
|
||||
.driver = {
|
||||
.name = "brcm-spu-crypto",
|
||||
.of_match_table = of_match_ptr(bcm_spu_dt_ids),
|
||||
},
|
||||
.name = "brcm-spu-crypto",
|
||||
.of_match_table = bcm_spu_dt_ids,
|
||||
},
|
||||
.probe = bcm_spu_probe,
|
||||
.remove = bcm_spu_remove,
|
||||
};
|
||||
|
||||
@@ -603,7 +603,7 @@ static int aead_setkey(struct crypto_aead *aead,
|
||||
dev_dbg(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
|
||||
keys.authkeylen + keys.enckeylen, keys.enckeylen,
|
||||
keys.authkeylen);
|
||||
print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
/*
|
||||
@@ -639,7 +639,7 @@ static int aead_setkey(struct crypto_aead *aead,
|
||||
dma_sync_single_for_device(jrdev, ctx->key_dma, ctx->adata.keylen_pad +
|
||||
keys.enckeylen, ctx->dir);
|
||||
|
||||
print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("ctx.key@"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
|
||||
ctx->adata.keylen_pad + keys.enckeylen, 1);
|
||||
|
||||
@@ -680,7 +680,7 @@ static int gcm_setkey(struct crypto_aead *aead,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -701,7 +701,7 @@ static int rfc4106_setkey(struct crypto_aead *aead,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -727,7 +727,7 @@ static int rfc4543_setkey(struct crypto_aead *aead,
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -754,7 +754,7 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
|
||||
u32 *desc;
|
||||
const bool is_rfc3686 = alg->caam.rfc3686;
|
||||
|
||||
print_hex_dump_debug("key in @"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
/* Here keylen is actual key length */
|
||||
|
||||
@@ -212,7 +212,7 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
|
||||
dev_dbg(jrdev, "keylen %d enckeylen %d authkeylen %d\n",
|
||||
keys.authkeylen + keys.enckeylen, keys.enckeylen,
|
||||
keys.authkeylen);
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
/*
|
||||
@@ -248,7 +248,7 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
|
||||
ctx->adata.keylen_pad + keys.enckeylen,
|
||||
ctx->dir);
|
||||
|
||||
print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
|
||||
ctx->adata.keylen_pad + keys.enckeylen, 1);
|
||||
|
||||
@@ -371,7 +371,7 @@ static int gcm_setkey(struct crypto_aead *aead,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -475,7 +475,7 @@ static int rfc4106_setkey(struct crypto_aead *aead,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -581,7 +581,7 @@ static int rfc4543_setkey(struct crypto_aead *aead,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -631,7 +631,7 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
|
||||
const bool is_rfc3686 = alg->caam.rfc3686;
|
||||
int ret = 0;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
ctx->cdata.keylen = keylen;
|
||||
|
||||
@@ -301,7 +301,7 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
|
||||
dev_dbg(dev, "keylen %d enckeylen %d authkeylen %d\n",
|
||||
keys.authkeylen + keys.enckeylen, keys.enckeylen,
|
||||
keys.authkeylen);
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
ctx->adata.keylen = keys.authkeylen;
|
||||
@@ -315,7 +315,7 @@ static int aead_setkey(struct crypto_aead *aead, const u8 *key,
|
||||
memcpy(ctx->key + ctx->adata.keylen_pad, keys.enckey, keys.enckeylen);
|
||||
dma_sync_single_for_device(dev, ctx->key_dma, ctx->adata.keylen_pad +
|
||||
keys.enckeylen, ctx->dir);
|
||||
print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, ctx->key,
|
||||
ctx->adata.keylen_pad + keys.enckeylen, 1);
|
||||
|
||||
@@ -732,7 +732,7 @@ static int gcm_setkey(struct crypto_aead *aead,
|
||||
ret = aes_check_keylen(keylen);
|
||||
if (ret)
|
||||
return ret;
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -828,7 +828,7 @@ static int rfc4106_setkey(struct crypto_aead *aead,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -927,7 +927,7 @@ static int rfc4543_setkey(struct crypto_aead *aead,
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
memcpy(ctx->key, key, keylen);
|
||||
@@ -955,7 +955,7 @@ static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
|
||||
u32 *desc;
|
||||
const bool is_rfc3686 = alg->caam.rfc3686;
|
||||
|
||||
print_hex_dump_debug("key in @" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("key in @" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
ctx->cdata.keylen = keylen;
|
||||
|
||||
@@ -505,7 +505,7 @@ static int axcbc_setkey(struct crypto_ahash *ahash, const u8 *key,
|
||||
DMA_TO_DEVICE);
|
||||
ctx->adata.keylen = keylen;
|
||||
|
||||
print_hex_dump_debug("axcbc ctx.key@" __stringify(__LINE__)" : ",
|
||||
print_hex_dump_devel("axcbc ctx.key@" __stringify(__LINE__)" : ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, ctx->key, keylen, 1);
|
||||
|
||||
return axcbc_set_sh_desc(ahash);
|
||||
@@ -525,7 +525,7 @@ static int acmac_setkey(struct crypto_ahash *ahash, const u8 *key,
|
||||
ctx->adata.key_virt = key;
|
||||
ctx->adata.keylen = keylen;
|
||||
|
||||
print_hex_dump_debug("acmac ctx.key@" __stringify(__LINE__)" : ",
|
||||
print_hex_dump_devel("acmac ctx.key@" __stringify(__LINE__)" : ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1);
|
||||
|
||||
return acmac_set_sh_desc(ahash);
|
||||
|
||||
@@ -58,7 +58,7 @@ int gen_split_key(struct device *jrdev, u8 *key_out,
|
||||
|
||||
dev_dbg(jrdev, "split keylen %d split keylen padded %d\n",
|
||||
adata->keylen, adata->keylen_pad);
|
||||
print_hex_dump_debug("ctx.key@" __stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("ctx.key@" __stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key_in, keylen, 1);
|
||||
|
||||
if (local_max > max_keylen)
|
||||
@@ -113,7 +113,7 @@ int gen_split_key(struct device *jrdev, u8 *key_out,
|
||||
wait_for_completion(&result.completion);
|
||||
ret = result.err;
|
||||
|
||||
print_hex_dump_debug("ctx.key@"__stringify(__LINE__)": ",
|
||||
print_hex_dump_devel("ctx.key@"__stringify(__LINE__)": ",
|
||||
DUMP_PREFIX_ADDRESS, 16, 4, key_out,
|
||||
adata->keylen_pad, 1);
|
||||
}
|
||||
|
||||
@@ -651,6 +651,7 @@ static const struct pci_device_id cpt_id_table[] = {
|
||||
{ PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, CPT_81XX_PCI_PF_DEVICE_ID) },
|
||||
{ 0, } /* end of table */
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, cpt_id_table);
|
||||
|
||||
static struct pci_driver cpt_pci_driver = {
|
||||
.name = DRV_NAME,
|
||||
@@ -666,4 +667,3 @@ MODULE_AUTHOR("George Cherian <george.cherian@cavium.com>");
|
||||
MODULE_DESCRIPTION("Cavium Thunder CPT Physical Function Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_VERSION(DRV_VERSION);
|
||||
MODULE_DEVICE_TABLE(pci, cpt_id_table);
|
||||
|
||||
@@ -835,9 +835,10 @@ static void cptvf_shutdown(struct pci_dev *pdev)
|
||||
|
||||
/* Supported devices */
|
||||
static const struct pci_device_id cptvf_id_table[] = {
|
||||
{PCI_VDEVICE(CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID), 0},
|
||||
{ 0, } /* end of table */
|
||||
{ PCI_VDEVICE(CAVIUM, CPT_81XX_PCI_VF_DEVICE_ID) },
|
||||
{ } /* end of table */
|
||||
};
|
||||
MODULE_DEVICE_TABLE(pci, cptvf_id_table);
|
||||
|
||||
static struct pci_driver cptvf_pci_driver = {
|
||||
.name = DRV_NAME,
|
||||
@@ -853,4 +854,3 @@ MODULE_AUTHOR("George Cherian <george.cherian@cavium.com>");
|
||||
MODULE_DESCRIPTION("Cavium Thunder CPT Virtual Function Driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
MODULE_VERSION(DRV_VERSION);
|
||||
MODULE_DEVICE_TABLE(pci, cptvf_id_table);
|
||||
|
||||
@@ -108,8 +108,8 @@ static int setup_sgio_components(struct cpt_vf *cptvf, struct buf_ptr *list,
|
||||
sg_cleanup:
|
||||
for (j = 0; j < i; j++) {
|
||||
if (list[j].dma_addr) {
|
||||
dma_unmap_single(&pdev->dev, list[i].dma_addr,
|
||||
list[i].size, DMA_BIDIRECTIONAL);
|
||||
dma_unmap_single(&pdev->dev, list[j].dma_addr,
|
||||
list[j].size, DMA_BIDIRECTIONAL);
|
||||
}
|
||||
|
||||
list[j].dma_addr = 0;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user