dm-crypt 使用 cryptodev 模組進行 cryptsetup

dm-crypt 使用 cryptodev 模組進行 cryptsetup

我介紹過使用cryptsetup來加密一部分磁碟空間,但是寫入速度很慢。我發現有一個模組可以直接利用硬體進行加密操作,使用模組 cryptodev。
我已經安裝了 cryptodev 並且正在運行

openssl speed -evp aes-128-cbc -engine cryptodev  

我測試了寫入速度

time dd bs=5000k count=1 if=/dev/zero of=/home/... conv=fsync  

在包含 cryptodev 模組之前和之後,使用此控制項我看不到任何改進。還需要為 cryptsetup 定義其他內容才能使用該引擎嗎?謝謝

[編輯] - - - - - - - - - - - - - - - - - - - - - - -

$ cryptsetup luksDump DISK --debug
# cryptsetup 1.7.0 processing "cryptsetup luksDump DISK --debug"
# Running command luksDump.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating crypt device DISK context.
# Trying to open and read device DISK with direct-io.
# Initialising device-mapper backend library.
# Trying to load LUKS1 crypt type from device DISK.
# Crypto backend (OpenSSL 1.0.2h  3 May 2016) initialized in cryptsetup library version 1.7.0.
# Detected kernel Linux 4.1.15-xuelk-2.0.1-dirty armv7l.
# Reading LUKS header of size 1024 from device DISK
# Key length 32, device size 204800 sectors, header size 2050 sectors.
LUKS header information for DISK

Version:        1
Cipher name:    aes
Cipher mode:    cbc-essiv:sha256
Hash spec:      sha256
Payload offset: 4096
MK bits:        256
MK digest:      00 a6 fb a5 64 1d 08 47 9d ea 76 d3 34 f2 19 cf 66 b7 e7 94 
MK salt:        8c 14 4e 3a 97 d6 d7 18 ca 46 f9 f0 47 d5 44 3f 
                46 0c c5 4e d7 35 1d 46 ca 2b fc af 13 14 d1 98 
MK iterations:  13500
UUID:           a808c328-0c0e-43a7-9057-b6b9a49afeb9

Key Slot 0: ENABLED
        Iterations:             108472
        Salt:                   76 be 3e a1 5f 37 9b bc 1b 84 69 9e 36 db 5f ba 
                                43 93 96 34 57 02 59 df 2c 19 f4 df 1a 09 53 7a 
        Key material offset:    8
        AF stripes:             4000

答案1

該命令cryptsetup基本上只是配置dm-crypt內核模組。這意味著磁碟的加密/解密發生在核心內部。核心根本不使用 openssl。

您可以透過以下方式可靠地測試目前硬碟加密效能:

cryptsetup benchmark

cryptsetup 預設值為 aes-xts、256b,在建立加密裝置時cryptsetup luksCreate(請參閱cryptsetup luksDump輸出)。

中等規模硬體的一些實驗結果:

CPU                       cryptsetup benchmark
AMD Phenom 9750 2.4 GHz   aes-xts   256b   146.7 MiB/s   148.5 MiB/s
Intel Atom C3758 2.2 GHz  aes-xts   256b   874.0 MiB/s   875.4 MiB/s
Intel i5-4250U 1.3 GHz    aes-xts   256b  1703.3 MiB/s  1723.1 MiB/s
Intel i7-6600U 2.6 GHz    aes-xts   256b  2978.0 MiB/s  3117.5 MiB/s

Linux 核心包含多個可加速加密操作的硬體驅動程式。通常,它們預設載入並由核心的加密子系統使用。

例如,較新的 Intel CPU 配備了AES-NI指令集顯著加速 AES - 你可以檢查 CPU 是否支援它們,如下所示:

tr ' ' '\n' < /proc/cpuinfo | grep aes

有些系統甚至配備了加密協處理器(參見例如英特爾 QuickAssist - QAT)。它們可能會加快速度,但也可能會減慢速度 - 因此,在進行基準測試時,檢查啟動日誌是否由內核配置了此類特殊硬體以及是否加載了必要的模組/韌體是有意義的。如果存在此類硬件,則有必要檢查協處理器啟用與停用的效能(例如,透過將相關*qat*模組列入黑名單)。

相關內容