VIA Padlock
The VIA C7-M ULV CPU in the A110 supports the so-called VIA Padlock hardware crypto functionality, i.e. it has cryptography silicon on-die.
On Windows there's not that much software supporting VIA Padlock, but VIA offers Java code tools to improve on this situation. On Linux, kernel support is better. To see quick results, just boot a pentoo USB-pendrive, which has latest kernel asf..
Contents |
Linux kernel modules / dm-crypt
The mainline 2.6.25 kernel already contains two modules which make use of the VIA Padlock functionality.
$ modprobe padlock-sha padlock: Using VIA PadLock ACE for SHA1/SHA256 algorithms.
$ modprobe padlock-aes padlock: Using VIA PadLock ACE for AES algorithm.
This will bring speedups for SHA-1/SHA-256 and AES kernel operations.
Setup
In order to use the padlock-aes and padlock-sha modules for your encrypted disk you need to make them available in the initrd (before your root file system is mounted).
On a Debian system you would add the following lines to /etc/initramfs-tools/modules:
padlock-aes padlock-sha
Then run
$ update-initramfs -u
and reboot.
Benchmarks
First test-run on an A110 (uses dm-crypt with 256bit AES, cbc-essiv:sha256) without VIA Padlock support:
$ hdparm -tT /dev/mapper/hdc2_crypt /dev/mapper/hdc2_crypt: Timing cached reads: 448 MB in 2.00 seconds = 223.47 MB/sec Timing buffered disk reads: 22 MB in 3.07 seconds = 7.17 MB/sec
After the above setup procedure for VIA Padlock and a reboot:
$ hdparm -tT /dev/mapper/hdc2_crypt /dev/mapper/hdc2_crypt: Timing cached reads: 502 MB in 2.00 seconds = 250.41 MB/sec Timing buffered disk reads: 90 MB in 3.07 seconds = 29.36 MB/sec
This is about the native speed of the SSD, so it's possible to use dm-crypt without the loss of speed.
OpenSSL
OpenSSL is a widely-used general purpose cryptography library.
Checking if OpenSSL supports VIA Padlock
In order to check whether your OpenSSL package supports VIA Padlock you can run:
$ openssl engine (padlock) VIA PadLock (no-RNG, ACE) (dynamic) Dynamic engine loading support
Configuring OpenSSL to use VIA Padlock all the time
As written in the Ubuntu Forums one has to modify /etc/ssl/openssl.cnf to make use of the VIA Padlock engine.
openssl_conf = openssl_def [openssl_def] engines = openssl_engines [openssl_engines] padlock = padlock_engine [padlock_engine] default_algorithms = ALL
All of this has to be added to the top of /etc/ssl/openssl.cnf (before any other [foo] sections). After that, the VIA Padlock engine will be used per default.
Benchmarks
All tests were performed on an A110 with kernel 2.6.25 and Debian's OpenSSL 0.9.8g-10.1. The first run was done with the usual OpenSSL (software) engine, the second with VIA Padlock acceleration (-engine padlock option).
The numbers are in 1000s of bytes per second processed.
AES-128
$ openssl speed -evp aes-128-ecb [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-128-ecb 13165.31k 14063.63k 14382.38k 14431.09k 14486.47k aes-128-ecb 66893.17k 243815.73k 646595.40k 1062664.01k 1310274.18k $ openssl speed -evp aes-128-cbc [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-128-cbc 11679.47k 14241.55k 15096.16k 15333.88k 15405.98k aes-128-cbc 48817.00k 163821.98k 384200.79k 582693.84k 689496.12k $ openssl speed -evp aes-128-cfb [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-128-cfb 10208.43k 10855.12k 11108.83k 11125.73k 11174.12k aes-128-cfb 47502.62k 159484.99k 378716.76k 580048.95k 686690.91k $ openssl speed -evp aes-128-ofb [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-128-ofb 9831.44k 10515.20k 10678.79k 10730.75k 10741.24k aes-128-ofb 44704.63k 133363.87k 266780.15k 352995.17k 390594.56k
AES-256
$ openssl speed -evp aes-256-ecb [-engine padlock] aes-256-ecb 9981.53k 10501.48k 10664.49k 10707.42k 10722.05k aes-256-ecb 66893.65k 243553.37k 591055.14k 912505.69k 1087003.17k $ openssl speed -evp aes-256-cbc [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-256-cbc 9187.18k 10572.28k 11054.32k 11179.36k 11218.02k aes-256-cbc 47955.92k 150619.73k 325730.73k 458320.11k 520520.79k $ openssl speed -evp aes-256-cfb [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-256-cfb 7948.75k 8705.65k 8819.42k 8853.42k 8864.52k aes-256-cfb 46673.53k 147797.36k 321382.75k 454835.20k 518500.66k $ openssl speed -evp aes-256-ofb [-engine padlock] type 16 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes aes-256-ofb 7994.11k 8399.96k 8537.91k 8570.25k 8603.01k aes-256-ofb 43163.88k 131377.82k 263398.05k 352037.96k 390224.38k
Modified OpenSSL/OpenSSH packages
Even though VIA Padlock support should be in OpenSSH >= 4.4 there seem to be issues. According to that bug report, this has been fixed in OpenSSH 4.9/4.9p1.
For the preinstalled Ubuntu please check the OpenSSL+OpenSSH Bugfix in the Ubuntu Forum and www.logix.cz. If you apply both patches and rebuild OpenSSL and OpenSSH, VIA Padlock will be used by default for every program relying on the OpenSSL library (including OpenSSH).
Rebuilding OpenSSL/OpenSSH from source
These instructions work for the preinstalled Ubuntu 8.04 on the A110, as well as for the current Debian unstable distribution.
It's recommended (but not required) to rebuild the packages on another (faster) system to reduce compile time.
$ sudo apt-get install build-essential fakeroot $ sudo apt-get build-dep openssl openssh $ apt-get source openssl openssh $ cd openssl-0.9.8g $ wget -q -O - http://launchpadlibrarian.net/13798833/bug119295.patch | patch -p1 $ wget -q -O - http://www.logix.cz/michal/devel/padlock/contrib/openssl-0.9.8e-engine.diff | patch -p1 $ fakeroot debian/rules binary $ cd ../openssh-4.7p1 $ wget -q --no-check-certificate -O - https://bugzilla.mindrot.org/attachment.cgi?id=1458 | patch -p0 -N $ fakeroot debian/rules binary
You can now copy the packages to your A110 and install them, at least the following ones:
$ dpkg -i openssh-client*.deb openssh-server*deb libssl*.deb openssl*deb
Binary DEB packages for the preinstalled Ubuntu
For convenience, the following tarball contains pre-built *.deb packages created by Christian Rothländer for both OpenSSL and OpenSSH for the preinstalled Ubuntu on the A110.
Install them as follows:
$ wget http://www.a110wiki.de/wiki/images/b/b6/Openssh_openssl_patched.tar.bz2 $ tar xfvj Openssh_openssl_patched.tar.bz2 $ dpkg -i openssh_openssl_patched/*.deb
OpenSSH
See this section first, most OpenSSH packages you're likely to use will not yet have VIA Padlock support out of the box.
Benchmarks
The following tests were done on an A110 with a 160 MB file.
AES-128-CBC
Without VIA Padlock support:
$ scp -c aes128-cbc bigfile.dat localhost:/dev/null bigfile.dat 100% 159MB 4.8MB/s 00:33
With VIA Padlock support:
$ scp -c aes128-cbc bigfile.dat localhost:/dev/null bigfile.dat 100% 159MB 12.2MB/s 00:13
AES-256-CBC
Without VIA Padlock support:
$ scp -c aes256-cbc bigfile.dat localhost:/dev/null bigfile.dat 100% 159MB 5.9MB/s 00:27
With VIA Padlock support:
$ scp -c aes256-cbc bigfile.dat localhost:/dev/null bigfile.dat 100% 159MB 14.5MB/s 00:11
OpenVPN
Check if OpenVPN is aware of the VIA Padlock engine support in OpenSSL:
$ openvpn --show-engines OpenSSL Crypto Engines VIA PadLock (no-RNG, ACE) [padlock] Dynamic engine loading support [dynamic]
OpenVPN automatically makes use of VIA Padlock support in OpenSSL after you performed these steps to patch and configure OpenSSL.
However, as VIA Padlock only accelerates AES (but not Blowfish, which is the default cipher used in OpenVPN), you'll have to explicitly choose AES with a certain key length in both the OpenVPN server and client config files. For example:
On the OpenVPN server:
$ grep AES /etc/openvpn/server.conf ;cipher AES-128-CBC cipher AES-256-CBC
On all clients:
$ grep AES /etc/openvpn/client.conf ;cipher AES-128-CBC cipher AES-256-CBC
Benchmarks
TODO.
CPU load
Using the VIA Padlock support in OpenSSL not only accelerates crypto functions, it'll also reduce the CPU load of the programs using OpenSSL's VIA Padlock support.
In the case of OpenVPN, where the (A110) client downloads a big file:
AES-128-CBC:
- Without VIA Padlock: 16% CPU load
- With VIA Padlock: 7% CPU load
AES-256-CBC:
- Without VIA Padlock: 20% CPU load
- With VIA Padlock: 8% CPU load
loop-aes
TODO.
sha1sum / phe_sum
Michal Ludvig has written the phe_sum tool which is intended as a fast sha1sum (part of coreutils) replacement which uses VIA Padlock.
Building phe_sum
$ wget http://www.logix.cz/michal/devel/padlock/phe_sum.c $ gcc phe_sum.c -o phe_sum
Please note that you should not use the -O2 (or similar) compiler option, or else the generated code will be incorrect!
Benchmarks
This benchmark was run on the A110 using a 160 MB file.
$ time sha1sum bigfile.dat real 0m6.511s user 0m5.864s sys 0m0.412s
$ time ./phe_sum bigfile.dat real 0m1.149s user 0m0.704s sys 0m0.424s
VIA JAVA Cryptographic Service Provider (VIA JCP)
Just copy viajcp.dll (or the Linux equivalent) and viajcp.jar to their directory in java and add
security.provider.1=com.centaur.padlock.VIAPadLockProvider
to the java.security file to override all software crypto-providers as #1. The javax.crypto.cipher object now uses VIA Padlock whenever possible, without further application modifications. Freenet should be accelerated during hashing. Now all Java programs use VIA Padlock via the Java Cryptography Architecture API.
Once you've done that you are in a position do do some serious cryptography, possibly using portecle to generate certs or using jasypt to encrypt and decrypt via .cmd batch files.
VIA SDK C++ sources
Alternatively, you can use the VIA SDK C++ sources for C++ applications.