{"id":603,"date":"2011-03-17T10:59:46","date_gmt":"2011-03-17T02:59:46","guid":{"rendered":"http:\/\/www.strongd.net\/?p=603"},"modified":"2011-03-17T10:59:46","modified_gmt":"2011-03-17T02:59:46","slug":"linux-2-6-38-user-space-interface-for-crypto-api","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=603","title":{"rendered":"Linux 2.6.38 User-space interface for Crypto API"},"content":{"rendered":"<p>Linux\u5185\u6838\u91cc\u9762\u81ea\u5e26\u975e\u5e38\u591a\u7684\u52a0\u5bc6\u6a21\u5757,\u8fd9\u662f\u6a21\u5757\u7ecf\u8fc7\u8c03\u4f18\u6027\u80fd\u975e\u5e38\u9ad8, \u800c\u4e14\u73b0\u5728\u53c8\u5f88\u591a\u786c\u4ef6\u672c\u8eab\u652f\u6301\u52a0\u5bc6\u529f\u80fd,\u6bd4\u5982intel\u7684CPU\u652f\u6301AES\u52a0\u5bc6\u6307\u4ee4,\u90a3\u4e9b\u5185\u6838\u7684\u90a3\u5e2e\u4eba\u77e5\u9053\u66f4\u597d\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u786c\u4ef6\u66f4\u5feb\u7684\u5b8c\u6210\u52a0\u5bc6\u529f\u80fd\u7684, \u4ed6\u4eec\u5199\u7684\u8fd9\u4e9b\u786c\u4ef6\u7684\u9a71\u52a8\u5728drivers\/crypto\u76ee\u5f55\u91cc. \u6240\u4ee5\u5982\u679c\u6211\u4eec\u80fd\u5728\u7528\u6237\u7a7a\u95f4\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7528\u5230\u8fd9\u4e9b\u52a0\u5bc6\u5e93\u6709\u4e8c\u4e2a\u597d\u5904: 1. \u65e0\u987b\u518d\u9020\u8f6e\u5b50. 2. \u6027\u80fd\u9ad8.<\/p>\n<p>\u5e78\u8fd0\u7684\u662f2.6.38\u7684\u5185\u6838\u7ed9\u6211\u4eec\u5e26\u6765\u4e86\u8fd9\u4e9b\u529f\u80fd. \u8fd9\u4e9b\u529f\u80fd\u662f\u901a\u8fc7socket\u65b9\u5f0f\u66b4\u9732\u7684,\u601d\u8def\u975e\u5e38\u72ec\u7279\u4f18\u96c5,\u540c\u65f6\u7531\u4e8e\u652f\u6301gather write, scatter read, \u65e0\u987b\u62f7\u8d1d\u6570\u636e,\u6027\u80fd\u5e94\u8be5\u975e\u5e38\u9ad8.<\/p>\n<p>\u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u5e95\u4e0b\u6750\u6599:<br \/>\nUser-space interface for Crypto API :\u00a0<a href=\"http:\/\/kernelnewbies.org\/LinuxChanges#head-42965823d837a3a60f8fafe482406f93fd4351c4\">\u8fd9\u91cc<\/a>,\u00a0<a href=\"http:\/\/permalink.gmane.org\/gmane.linux.kernel.cryptoapi\/5286\">\u8fd9\u91cc<\/a><\/p>\n<p>\u5728ubuntu10.10\u4e0b\u5b89\u88c5\u65b0\u7684\u5185\u68382.6.38, \u53c2\u8003<a href=\"http:\/\/wenku.baidu.com\/view\/78bad93467ec102de2bd89ed.html\">\u8fd9\u91cc<\/a><\/p>\n<p>\u5b89\u88c5\u5b8c\u4e86\u7cfb\u7edf,\u6211\u4eec\u53ef\u4ee5\u6f14\u793a\u4e0b\u5982\u4f55\u4f7f\u7528\u65b0\u7684API\u8c03\u7528:<\/p>\n<div>\n<div id=\"highlighter_513928\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<div>\n<div><code>$ <\/code><code>uname<\/code> <code>-r<\/code><\/div>\n<div><code>2.6.38-yufeng<\/code><\/div>\n<div><code>$ <\/code><code>cat<\/code> <code>\/etc\/lsb-release<\/code><\/div>\n<div><code>DISTRIB_ID=Ubuntu<\/code><\/div>\n<div><code>DISTRIB_RELEASE=10.10<\/code><\/div>\n<div><code>DISTRIB_CODENAME=maverick<\/code><\/div>\n<div><code>DISTRIB_DESCRIPTION=<\/code><code>\"Ubuntu 10.10\"<\/code><\/div>\n<div><code>$ <\/code><code>cat<\/code> <code>&gt; example.c<\/code><\/div>\n<div><code>#include &lt;stdio.h&gt;<\/code><\/div>\n<div><code>#include &lt;sys\/socket.h&gt;<\/code><\/div>\n<div><code>#include &lt;linux\/if_alg.h&gt;<\/code><\/div>\n<div><code>#ifndef AF_ALG<\/code><\/div>\n<div><code>#define AF_ALG 38<\/code><\/div>\n<div><code>#define SOL_ALG 279<\/code><\/div>\n<div><code>#endif<\/code><\/div>\n<div><code>int main(void)<\/code><\/div>\n<div><code>{<\/code><\/div>\n<div><code> <\/code><code>int opfd;<\/code><\/div>\n<div><code> <\/code><code>int tfmfd;<\/code><\/div>\n<div><code> <\/code><code>struct sockaddr_alg sa = {<\/code><\/div>\n<div><code> <\/code><code>.salg_family = AF_ALG,<\/code><\/div>\n<div><code> <\/code><code>.salg_type = <\/code><code>\"hash\"<\/code><code>,<\/code><\/div>\n<div><code> <\/code><code>.salg_name = <\/code><code>\"sha1\"<\/code><\/div>\n<div><code> <\/code><code>};<\/code><\/div>\n<div><code> <\/code><code>char buf[20];<\/code><\/div>\n<div><code> <\/code><code>int i;<\/code><\/div>\n<div><code> <\/code><code>tfmfd = socket(AF_ALG, SOCK_SEQPACKET, 0);<\/code><\/div>\n<div><code> <\/code><code>bind(tfmfd, (struct sockaddr *)&amp;sa, sizeof(sa));<\/code><\/div>\n<div><code> <\/code><code>opfd = accept(tfmfd, NULL, 0);<\/code><\/div>\n<div><code> <\/code><code>write(opfd, <\/code><code>\"abc\"<\/code><code>, 3);<\/code><\/div>\n<div><code> <\/code><code>read<\/code><code>(opfd, buf, 20);<\/code><\/div>\n<div><code> <\/code><code>for<\/code> <code>(i = 0; i &lt; 20; i++) {<\/code><\/div>\n<div><code> <\/code><code>printf<\/code><code>(<\/code><code>\"%02x\"<\/code><code>, (unsigned char)buf[i]);<\/code><\/div>\n<div><code> <\/code><code>}<\/code><\/div>\n<div><code> <\/code><code>printf<\/code><code>(<\/code><code>\"\\n\"<\/code><code>);<\/code><\/div>\n<div><code> <\/code><code>close(opfd);<\/code><\/div>\n<div><code> <\/code><code>close(tfmfd);<\/code><\/div>\n<div><code> <\/code><code>return<\/code> <code>0;<\/code><\/div>\n<div><code>}<\/code><\/div>\n<div><code>CTRL+D<\/code><\/div>\n<div><code>$ <\/code><code>mkdir<\/code> <code>-p linux &amp;&amp; <\/code><code>cp<\/code> <code>\/usr\/src\/linux-2<\/code><code>.6.38<\/code><code>\/include\/linux\/if_alg<\/code><code>.h linux\/<\/code><\/div>\n<div><code>$ gcc -I linux example.c<\/code><\/div>\n<div><code>$ .<\/code><code>\/a<\/code><code>.out<\/code><\/div>\n<div><code>687b37ba3c7f0000100940000000000000000000<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u5185\u6838\u91cc\u9762\u81ea\u5e26\u975e\u5e38\u591a\u7684\u52a0\u5bc6\u6a21\u5757,\u8fd9\u662f\u6a21\u5757\u7ecf\u8fc7\u8c03\u4f18\u6027\u80fd\u975e\u5e38\u9ad8, \u800c\u4e14\u73b0\u5728\u53c8\u5f88\u591a\u786c\u4ef6\u672c\u8eab\u652f\u6301\u52a0\u5bc6\u529f\u80fd,\u6bd4\u5982intel\u7684CPU\u652f\u6301AES\u52a0\u5bc6\u6307\u4ee4,\u90a3\u4e9b\u5185\u6838\u7684\u90a3\u5e2e\u4eba\u77e5\u9053\u66f4\u597d\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u786c\u4ef6\u66f4\u5feb\u7684\u5b8c\u6210\u52a0\u5bc6\u529f\u80fd\u7684, \u4ed6\u4eec\u5199\u7684\u8fd9\u4e9b\u786c\u4ef6\u7684\u9a71\u52a8\u5728drivers\/crypto\u76ee\u5f55\u91cc. \u6240\u4ee5\u5982\u679c\u6211\u4eec\u80fd\u5728\u7528\u6237\u7a7a\u95f4\u7684\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7528\u5230\u8fd9\u4e9b\u52a0\u5bc6\u5e93\u6709\u4e8c\u4e2a\u597d\u5904: 1. \u65e0\u987b\u518d\u9020\u8f6e\u5b50. 2. \u6027\u80fd\u9ad8. \u5e78\u8fd0\u7684\u662f2.6.38\u7684\u5185\u6838\u7ed9\u6211\u4eec\u5e26\u6765\u4e86\u8fd9\u4e9b\u529f\u80fd. \u8fd9\u4e9b\u529f\u80fd\u662f\u901a\u8fc7socket\u65b9\u5f0f\u66b4\u9732\u7684,\u601d\u8def\u975e\u5e38\u72ec\u7279\u4f18\u96c5,\u540c\u65f6\u7531\u4e8e\u652f\u6301gather write, scatter read, \u65e0\u987b\u62f7\u8d1d\u6570\u636e,\u6027\u80fd\u5e94\u8be5\u975e\u5e38\u9ad8. \u5177\u4f53\u53ef\u4ee5\u53c2\u8003\u5e95\u4e0b\u6750\u6599: User-space interface for Crypto API :\u00a0\u8fd9\u91cc,\u00a0\u8fd9\u91cc \u5728ubuntu10.10\u4e0b\u5b89\u88c5\u65b0\u7684\u5185\u68382.6.38, \u53c2\u8003\u8fd9\u91cc \u5b89\u88c5\u5b8c\u4e86\u7cfb\u7edf,\u6211\u4eec\u53ef\u4ee5\u6f14\u793a\u4e0b\u5982\u4f55\u4f7f\u7528\u65b0\u7684API\u8c03\u7528: $ uname -r 2.6.38-yufeng $ cat \/etc\/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.10 DISTRIB_CODENAME=maverick DISTRIB_DESCRIPTION=&#8221;Ubuntu 10.10&#8243; $ cat &gt; example.c #include &lt;stdio.h&gt; #include &lt;sys\/socket.h&gt; #include &lt;linux\/if_alg.h&gt; #ifndef AF_ALG #define AF_ALG 38 #define SOL_ALG 279 #endif &hellip; <a href=\"https:\/\/www.strongd.net\/?p=603\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Linux 2.6.38 User-space interface for Crypto API<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-603","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=603"}],"version-history":[{"count":2,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/603\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/603\/revisions\/605"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}