{"id":420,"date":"2017-11-01T16:05:56","date_gmt":"2017-11-01T08:05:56","guid":{"rendered":"http:\/\/www.freezhongzi.info\/?p=420"},"modified":"2017-11-01T16:05:56","modified_gmt":"2017-11-01T08:05:56","slug":"mtk7688-aes%e7%a1%ac%e4%bb%b6%e5%8a%a0%e9%80%9f","status":"publish","type":"post","link":"https:\/\/bl4kraven.com\/index.php\/2017\/11\/01\/mtk7688-aes%e7%a1%ac%e4%bb%b6%e5%8a%a0%e9%80%9f\/","title":{"rendered":"MT7688 AES\u786c\u4ef6\u52a0\u901f"},"content":{"rendered":"<p>\u6700\u8fd1\u6211\u65e0\u804a\u7ffb\u7ffbMT7688\u7684datasheet\uff0c\u6ce8\u610f\u5230\u5c45\u7136\u652f\u6301AES\u52a0\u901f\uff0c\u8d76\u7d27\u641cgithub\u627e\u5230\u4e86\u4e00\u4e2a\u80fd\u7528\u7684OpenWRT\u9a71\u52a8<a href=\"https:\/\/github.com\/vschagen\/mtk_aes\">MTK_AES<\/a>\u3002<\/p>\n<p>\u8d76\u7d27\u5f00\u641e\uff0c\u4e00\u8def\u641e\u597d\u597d\u51e0\u5929\u624d\u6162\u6162\u6478\u7d22\u51falinux\u7684\u521d\u6b65\u52a0\u5bc6\u6846\u67b6\u3002\u5185\u6838\u7684\u52a0\u5bc6\u6846\u67b6\u7684\u5e94\u7528\u5c42\u63a5\u53e3\u662fAF_ALG \u5957\u63a5\u5b57\u5f62\u5f0f\uff0c\u4f46\u662f\u6709\u4e00\u4e2a\u4e13\u95e8\u7684\u9a71\u52a8\u6a21\u5757<a href=\"http:\/\/cryptodev-linux.org\/index.html\">crpytodev<\/a>\u62bd\u8c61\u51fa\u4e00\u4e2a\/dev\/crypto\u8bbe\u5907\uff0c\u91c7\u7528ioctl\u63a5\u53e3\uff0c\u800c\u4e14\u6839\u636e<a href=\"http:\/\/cryptodev-linux.org\/comparison.html\">\u5b98\u7f51\u6570\u636e\u5bf9\u6bd4<\/a>\u6027\u80fd\u66f4\u597d\u3002<\/p>\n<p>\u4e8e\u662f\u9009\u4e2dOpenWRT\u81ea\u5e26\u7684kmod-cryptodev\u6a21\u5757\uff0c\u9ed8\u8ba4\u4f1a\u9009\u4e2dkmod-crypto-core\u7b49\u4e00\u5927\u5806\u4f9d\u8d56\uff0c\u5176\u5b9e\u6700\u7ec8\u53ea\u4f9d\u8d56aead.ko\uff0c\u7f16\u8bd1\u597d\u540e\u5168\u90e8\u52a0\u8f7d\u9a71\u52a8\u3002\u7531\u4e8e\u7cfb\u7edf\u5e93\u7684\u52a0\u5bc6\u662fopenssl\u63d0\u4f9b\u7684libcrypto\u52a0\u5bc6\u5e93\uff0c\u6240\u4ee5\u9700\u8981\u5f00\u542fopenssl\u5e93\u7684\u786c\u4ef6\u52a0\u5bc6\u9009\u9879 &#8220;Crypto acceleration support&#8221;\uff08Libraries>SSL>libopenssl) \uff0c\u987a\u4fbf\u9009\u4e2dopenssl-util\u5de5\u5177\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n<ul>\n<li>\n<p>\u6d4b\u8bd5\u672a\u5f00\u542fAES\u786c\u4ef6\u52a0\u901f<\/p>\n<pre><code>root@:\/# openssl speed -evp aes-128-cbc\nDoing aes-128-cbc for 3s on 16 size blocks: 1242779 aes-128-cbc's in 2.96s\nDoing aes-128-cbc for 3s on 64 size blocks: 359528 aes-128-cbc's in 2.95s\nDoing aes-128-cbc for 3s on 256 size blocks: 93663 aes-128-cbc's in 2.95s\nDoing aes-128-cbc for 3s on 1024 size blocks: 23499 aes-128-cbc's in 2.92s\nDoing aes-128-cbc for 3s on 8192 size blocks: 2953 aes-128-cbc's in 2.96s\nbala...bala...\nThe 'numbers' are in 1000s of bytes per second processed.\ntype             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes\naes-128-cbc       6717.72k     7799.93k     8128.04k     8240.75k   \n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u5f00\u542fAES\u786c\u4ef6\u52a0\u901f<\/p>\n<pre><code>root@:\/# openssl speed -evp aes-128-cbc\nDoing aes-128-cbc for 3s on 16 size blocks: 276231 aes-128-cbc's in 0.65s\nDoing aes-128-cbc for 3s on 64 size blocks: 270678 aes-128-cbc's in 0.45s\nDoing aes-128-cbc for 3s on 256 size blocks: 243448 aes-128-cbc's in 0.29s\nDoing aes-128-cbc for 3s on 1024 size blocks: 179638 aes-128-cbc's in 0.34s\nDoing aes-128-cbc for 3s on 8192 size blocks: 45879 aes-128-cbc's in 0.11s\nbala...bala...\ntype             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes\naes-128-cbc       6799.53k    38496.43k   214905.82k   541027.39k  3416734.25k\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u4e3b\u8981\u662f\u770b\u6700\u540e\u4e00\u884c\u7684\u541e\u5410\u91cf\u6d4b\u8bd5\uff0c\u6548\u679c\u60ca\u4eba\u554a\uff01\uff01\uff01\uff01<\/p>\n<p>\u4e0d\u5f00\u542f\u52a0\u901f\u65f6\u6570\u636e\u541e\u5410\u91cf\u53d8\u5316\u4e0d\u5927\uff0c\u6bd5\u7adf\u8fd9\u91cc\u7684\u6027\u80fd\u74f6\u9888\u662f\u5728AES\u8f6f\u4ef6\u5b9e\u73b0\u8fd9\u5757\uff0c\u800c\u5f00\u542f\u786c\u4ef6\u52a0\u901f\u540e\uff0c\u6570\u636e\u5757\u8d8a\u5927\u6548\u679c\u8d8a\u597d\uff0c\u6700\u540e\u76848192\u5b57\u8282\u5757\u6548\u679c\u5c31\u63d0\u5347\u4e86414\u500d\u3002<\/p>\n<p>\u8fd9\u91ccopenssl\u9700\u8981\u5f00\u542f-evp\u9009\u9879\uff0c\u8fd9\u6837\u5e95\u5c42\u7684crpyto\u5e93\u4f1a\u4f18\u5148\u9009\u62e9\u786c\u4ef6\u52a0\u901f\u3002openssl\u91cc\u7684cryptodev\u5f15\u64ce\u662fEVP\u63a5\u53e3\u5f62\u5f0f\u63d0\u4f9b\u7684\uff0c\u6240\u4ee5\u5982\u679c\u4f7f\u7528openssl\u5e93\u9700\u8981\u52a0\u901f\uff0c\u5fc5\u987b\u7528EVP\u63a5\u53e3\u3002\u4e0d\u8fc7openssl\u6d4b\u8bd5\u5de5\u5177\u9ed8\u8ba4\u7684\u52a0\u5bc6\u5f15\u64ceengine\u4f1a\u81ea\u52a8\u9009\u62e9cryptodev\uff0c\u4e0d\u7528\u518d\u624b\u52a8\u6307\u5b9a-engine cryptodev\u4e86\u3002<\/p>\n<p>\u8fd9\u91cc\u6bd4\u8f83\u90c1\u95f7\u7684\u662fmtk_aes\u652f\u6301AES\u7684ECB\u548cCBC\uff0c\u4f46\u662fopenssl\u7684libcrypto\u5e93\u7684enc_cryptodev.c\u91cc\u53ea\u652f\u6301CBC\uff0c\u6240\u6709\u6700\u7ec8\u80fd\u52a0\u901f\u7684\u53ea\u80fd\u662fAES\u7684CBC\u4e86\uff0c\u4f30\u8ba1ECB\u4e0d\u592a\u5b89\u5168\u5427\uff0c\u8fdeCBC\u4e5f\u4e0d\u662f\u5f88\u5b89\u5168\uff0c\u73b0\u5728\u666e\u904d\u7528CTR\u5427\u3002CBC\u53ea\u662f\u6bd4ECB\u591a\u4e86\u4e2aIV\u77e9\u9635\uff0c\u4fdd\u8bc1\u6bcf\u6b21\u52a0\u5bc6\u4e0d\u91cd\u6837\u3002<\/p>\n<pre><code>static struct {\n    int id;\n    int nid;\n    int ivmax;\n    int keylen;\n} ciphers[] = {\n    {\n        CRYPTO_ARC4, NID_rc4, 0, 16,\n    },\n    {\n        CRYPTO_DES_CBC, NID_des_cbc, 8, 8,\n    },\n    {\n        CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24,\n    },\n    {\n        CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16,\n    },\n    {\n        CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24,\n    },\n    {\n        CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32,\n    },\n# ifdef CRYPTO_AES_CTR\n    {\n        CRYPTO_AES_CTR, NID_aes_128_ctr, 14, 16,\n    },\n    {\n        CRYPTO_AES_CTR, NID_aes_192_ctr, 14, 24,\n    },\n    {\n        CRYPTO_AES_CTR, NID_aes_256_ctr, 14, 32,\n    },\n# endif\n    {\n        CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16,\n    },\n    {\n        CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16,\n    },\n    {\n        CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0,\n    },\n    {\n        0, NID_undef, 0, 0,\n    },\n};\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u6765\u7528AES CBC\u52a0\u5bc6\u4e00\u4e2a20M\u7684\u6587\u4ef6\uff1a<\/p>\n<pre><code>root@:\/tmp# head -c 20m \/dev\/zero &gt;test\n\nroot@:\/tmp# time openssl enc -e -aes-128-cbc -in test -out test.out -kfile pgrade_pass \nreal 0m 0.74s\nuser 0m 0.10s \nsys 0m 0.63s\n\nroot@:\/tmp# rmmod mtk_aes \nroot@:\/tmp# time openssl enc -e -aes-128-cbc -in test -out test.out -kfile upgrade_pass \nreal 0m 3.33s\nuser 0m 2.93s \nsys 0m 0.38s\n<\/code><\/pre>\n<p>\u63d0\u5347\u4e865\u500d\u3002<\/p>\n<p>\u6211\u8fd9\u91cc\u7684openssl\u7684\u7248\u672c\u662f1.0.2e\uff0c\u6700\u65b0\u76841.1\u7248\u672c\u652f\u6301AES\u7684ECB\u7684\uff0c\u6211\u6ca1\u8bd5\u8fc7\uff0cCryptodev\u662f1.7\u7248\u672c\u3002\u73b0\u5728\u5e94\u7528\u5c31\u662f\u4ee5\u540e\u52a0\u89e3\u5bc6\u6587\u4ef6\u6709\u70b9\u7528\uff0c\u5982\u679c\u662f\u4f18\u5316ssh\u548cscp\u4f30\u8ba1\u4e5f\u4e0d\u662f\u5f88\u597d\uff0c\u6bd4\u8f83\u8fd9\u4e9b\u5e94\u7528\u74f6\u9888\u5f80\u5f80\u662f\u7f51\u901f\uff0c\u5e76\u4e14\u5982\u679c\u662f\u5c0f\u6570\u636e\u52a0\u5bc6\u7684\u8bdd\u6548\u679c\u5dee\u522b\u4e0d\u5927\uff0c\u53ea\u5728\u5927\u6570\u636e\u541e\u5410\u65f6\u624d\u6709\u5dee\u522b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u6211\u65e0\u804a\u7ffb\u7ffbMT7688\u7684datasheet\uff0c\u6ce8\u610f\u5230\u5c45\u7136\u652f\u6301AES\u52a0\u901f\uff0c\u8d76\u7d27\u641c &hellip; <a href=\"https:\/\/bl4kraven.com\/index.php\/2017\/11\/01\/mtk7688-aes%e7%a1%ac%e4%bb%b6%e5%8a%a0%e9%80%9f\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a> <a href=\"https:\/\/bl4kraven.com\/index.php\/2017\/11\/01\/mtk7688-aes%e7%a1%ac%e4%bb%b6%e5%8a%a0%e9%80%9f\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[6,8,9],"class_list":["post-420","post","type-post","status-publish","format-standard","hentry","category-openwrt","category-program","tag-aes","tag-mt7688","tag-openwrt"],"_links":{"self":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/comments?post=420"}],"version-history":[{"count":0,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/posts\/420\/revisions"}],"wp:attachment":[{"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/media?parent=420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/categories?post=420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bl4kraven.com\/index.php\/wp-json\/wp\/v2\/tags?post=420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}